/*
- * "$Id: ppd.c 4990 2006-01-26 02:21:45Z mike $"
+ * "$Id: ppd.c 5119 2006-02-16 15:52:06Z mike $"
*
* PPD file routines for the Common UNIX Printing System (CUPS).
*
*
* Contents:
*
- * _ppd_attr_compare() - Compare two attributes.
* ppdClose() - Free all memory used by the PPD file.
* ppdErrorString() - Returns the text assocated with a status.
* ppdLastError() - Return the status from the last ppdOpen*().
* ppdOpen() - Read a PPD file into memory.
+ * ppdOpen2() - Read a PPD file into memory.
* ppdOpenFd() - Read a PPD file into memory.
* ppdOpenFile() - Read a PPD file into memory.
* ppdSetConformance() - Set the conformance level for PPD files.
* ppd_add_attr() - Add an attribute to the PPD data.
* ppd_add_choice() - Add a choice to an option.
* ppd_add_size() - Add a page size.
+ * ppd_compare_attrs() - Compare two attributes.
* ppd_compare_coptions() - Compare two custom options.
* ppd_compare_cparams() - Compare two custom parameters.
* ppd_compare_options() - Compare two options.
const char *value);
static ppd_choice_t *ppd_add_choice(ppd_option_t *option, const char *name);
static ppd_size_t *ppd_add_size(ppd_file_t *ppd, const char *name);
-static int ppd_compare_coptions(ppd_coption_t *a, ppd_coption_t *b);
+static int ppd_compare_attrs(ppd_attr_t *a, ppd_attr_t *b);
+static int ppd_compare_coptions(ppd_coption_t *a,
+ ppd_coption_t *b);
static int ppd_compare_cparams(ppd_cparam_t *a, ppd_cparam_t *b);
static int ppd_compare_options(ppd_option_t *a, ppd_option_t *b);
static int ppd_decode(char *string);
_cups_globals_t *cg);
-/*
- * '_ppd_attr_compare()' - Compare two attributes.
- */
-
-int /* O - Result of comparison */
-_ppd_attr_compare(ppd_attr_t **a, /* I - First attribute */
- ppd_attr_t **b) /* I - Second attribute */
-{
- int ret; /* Result of comparison */
-
-
- if ((ret = strcasecmp((*a)->name, (*b)->name)) != 0)
- return (ret);
- else if ((*a)->spec[0] && (*b)->spec[0])
- return (strcasecmp((*a)->spec, (*b)->spec));
- else
- return (0);
-}
-
-
/*
* 'ppdClose()' - Free all memory used by the PPD file.
*/
/* Global data */
static const char * const ui_keywords[] =
{
+#ifdef CUPS_USE_FULL_UI_KEYWORDS_LIST
+ /*
+ * Adobe defines some 41 keywords as "UI", meaning that they are
+ * user interface elements and that they should be treated as such
+ * even if the PPD creator doesn't use Open/CloseUI around them.
+ *
+ * Since this can cause previously invisible options to appear and
+ * confuse users, the default is to only treat the PageSize and
+ * PageRegion keywords this way.
+ */
/* Boolean keywords */
"BlackSubstitution",
"Booklet",
"StapleWhen",
"StapleX",
"StapleY"
+#else /* !CUPS_USE_FULL_UI_KEYWORDS_LIST */
+ "PageRegion",
+ "PageSize"
+#endif /* CUPS_USE_FULL_UI_KEYWORDS_LIST */
};
if (!group)
{
- if (strcmp(keyword, "Collate") && strcmp(keyword, "Duplex") &&
- strcmp(keyword, "InputSlot") && strcmp(keyword, "ManualFeed") &&
- strcmp(keyword, "MediaType") && strcmp(keyword, "MediaColor") &&
- strcmp(keyword, "MediaWeight") && strcmp(keyword, "OutputBin") &&
- strcmp(keyword, "OutputMode") && strcmp(keyword, "OutputOrder") &&
- strcmp(keyword, "PageSize") && strcmp(keyword, "PageRegion"))
- group = ppd_get_group(ppd, "Extra", _("Extra"), cg);
- else
- group = ppd_get_group(ppd, "General", _("General"), cg);
-
- if (group == NULL)
+ if ((group = ppd_get_group(ppd, "General", _("General"), cg)) == NULL)
goto error;
DEBUG_printf(("Adding to group %s...\n", group->text));
option = ppd_get_option(subgroup, name);
else if (group == NULL)
{
- if (strcmp(name, "Collate") && strcmp(name, "Duplex") &&
- strcmp(name, "InputSlot") && strcmp(name, "ManualFeed") &&
- strcmp(name, "MediaType") && strcmp(name, "MediaColor") &&
- strcmp(name, "MediaWeight") && strcmp(name, "OutputBin") &&
- strcmp(name, "OutputMode") && strcmp(name, "OutputOrder") &&
- strcmp(name, "PageSize") && strcmp(name, "PageRegion"))
- group = ppd_get_group(ppd, "Extra", _("Extra"), cg);
- else
- group = ppd_get_group(ppd, "General", _("General"), cg);
-
- if (group == NULL)
+ if ((group = ppd_get_group(ppd, "General", _("General"), cg)) == NULL)
goto error;
DEBUG_printf(("Adding to group %s...\n", group->text));
}
}
- /*
- * Sort the attributes...
- */
-
- if (ppd->num_attrs > 1)
- qsort(ppd->attrs, ppd->num_attrs, sizeof(ppd_attr_t *),
- (int (*)(const void *, const void *))_ppd_attr_compare);
-
/*
* Return the PPD file structure...
*/
if (ppd == NULL || name == NULL || spec == NULL)
return (NULL);
+ /*
+ * Create the array as needed...
+ */
+
+ if (!ppd->sorted_attrs)
+ ppd->sorted_attrs = cupsArrayNew((cups_array_func_t)ppd_compare_attrs,
+ NULL);
+
/*
* Allocate memory for the new attribute...
*/
strlcpy(temp->text, text, sizeof(temp->text));
temp->value = (char *)value;
+ /*
+ * Add the attribute to the sorted array...
+ */
+
+ cupsArrayAdd(ppd->sorted_attrs, temp);
+
/*
* Return the attribute...
*/
}
+/*
+ * 'ppd_compare_attrs()' - Compare two attributes.
+ */
+
+static int /* O - Result of comparison */
+ppd_compare_attrs(ppd_attr_t *a, /* I - First attribute */
+ ppd_attr_t *b) /* I - Second attribute */
+{
+ int ret; /* Result of comparison */
+
+
+ if ((ret = strcasecmp(a->name, b->name)) != 0)
+ return (ret);
+ else if (a->spec[0] && b->spec[0])
+ return (strcasecmp(a->spec, b->spec));
+ else
+ return (0);
+}
+
+
/*
* 'ppd_compare_coptions()' - Compare two custom options.
*/
DEBUG_printf(("LINE = \"%s\"\n", line));
+ /*
+ * The dynamically created PPDs for older style Mac OS X
+ * drivers include a large blob of data inserted as comments
+ * at the end of the file. As an optimization we can stop
+ * reading the PPD when we get to the start of this data.
+ */
+
+ if (!strcmp(line, "*%APLWORKSET START"))
+ {
+ free(line);
+ return (0);
+ }
+
if (ch == EOF && lineptr == line)
{
free(line);
/*
- * End of "$Id: ppd.c 4990 2006-01-26 02:21:45Z mike $".
+ * End of "$Id: ppd.c 5119 2006-02-16 15:52:06Z mike $".
*/