-output_read_configuration (const struct string_map *macros_,
- const struct string_set *driver_names_)
-{
- struct string_map macros = STRING_MAP_INITIALIZER (macros);
- struct string_set driver_names = STRING_SET_INITIALIZER (driver_names);
- char *devices_file_name = NULL;
- FILE *devices_file = NULL;
- struct string line = DS_EMPTY_INITIALIZER;
- int line_number;
-
- ds_init_empty (&line);
-
- devices_file_name = fn_search_path ("devices", config_path);
- if (devices_file_name == NULL)
- {
- error (0, 0, _("cannot find output initialization file "
- "(use `-vv' to view search path)"));
- goto exit;
- }
- devices_file = fopen (devices_file_name, "r");
- if (devices_file == NULL)
- {
- error (0, errno, _("cannot open \"%s\""), devices_file_name);
- goto exit;
- }
-
- string_map_replace_map (¯os, macros_);
- string_set_union (&driver_names, driver_names_);
- if (string_set_is_empty (&driver_names))
- string_set_insert (&driver_names, "default");
-
- line_number = 0;
- for (;;)
- {
- char *cp, *delimiter, *name;
-
- if (!ds_read_config_line (&line, &line_number, devices_file))
- {
- if (ferror (devices_file))
- error (0, errno, _("reading \"%s\""), devices_file_name);
- break;
- }
-
- cp = ds_cstr (&line);
- cp += strspn (cp, CC_SPACES);
-
- if (*cp == '\0')
- continue;
- else if (!strncmp ("define", cp, 6) && isspace ((unsigned char) cp[6]))
- {
- if (!output_define_macro (&cp[7], ¯os))
- error_at_line (0, 0, devices_file_name, line_number,
- _("\"%s\" is not a valid macro definition"),
- &cp[7]);
- continue;
- }
-
- delimiter = cp + strcspn (cp, ":=");
- name = xmemdup0 (cp, delimiter - cp);
- if (*delimiter == '=')
- {
- if (string_set_delete (&driver_names, name))
- add_driver_names (delimiter + 1, &driver_names);
- }
- else if (*delimiter == ':')
- {
- if (string_set_delete (&driver_names, name))
- {
- fn_interp_vars (ds_ss (&line), expand_macro, ¯os, &line);
- output_configure_driver (ds_cstr (&line));
- }
- }
- else
- error_at_line (0, 0, devices_file_name, line_number,
- _("syntax error"));
- free (name);
- }
-
- warn_unused_drivers (&driver_names, driver_names_);
-
-exit:
- if (devices_file != NULL)
- fclose (devices_file);
- free (devices_file_name);
- ds_destroy (&line);
- string_set_destroy (&driver_names);
- string_map_destroy (¯os);
-
- if (n_drivers == 0)
- {
- error (0, 0, _("no active output drivers"));
- init_default_drivers ();
- }
-}
-
-/* Obtains a token from S and advances its position. Errors are
- reported against the given DRIVER_NAME.
- The token is stored in TOKEN. Returns true if successful,
- false on syntax error.
-
- Caller is responsible for skipping leading spaces. */
-static bool
-get_option_token (char **s_, const char *driver_name,
- struct string *token)