/*
- * "$Id: ppd.c 6937 2007-09-10 21:13:31Z mike $"
+ * "$Id: ppd.c 7552 2008-05-12 17:42:15Z mike $"
*
* PPD file routines for the Common UNIX Printing System (CUPS).
*
- * Copyright 2007 by Apple Inc.
+ * Copyright 2007-2008 by Apple Inc.
* Copyright 1997-2007 by Easy Software Products, all rights reserved.
*
* These coded instructions, statements, and computer programs are the
* ppd_add_size() - Add a page size.
* ppd_compare_attrs() - Compare two attributes.
* ppd_compare_choices() - Compare two choices...
- * ppd_compare_consts() - Compare two constraints.
* ppd_compare_coptions() - Compare two custom options.
* ppd_compare_cparams() - Compare two custom parameters.
* ppd_compare_options() - Compare two options.
* Include necessary headers.
*/
+#include "ppd-private.h"
#include "globals.h"
#include "debug.h"
#include <stdlib.h>
static ppd_size_t *ppd_add_size(ppd_file_t *ppd, const char *name);
static int ppd_compare_attrs(ppd_attr_t *a, ppd_attr_t *b);
static int ppd_compare_choices(ppd_choice_t *a, ppd_choice_t *b);
-static int ppd_compare_consts(ppd_const_t *a, ppd_const_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);
cupsArrayDelete(ppd->coptions);
+ /*
+ * Free constraints...
+ */
+
+ if (ppd->cups_uiconstraints)
+ {
+ _ppd_cups_uiconsts_t *consts; /* Current constraints */
+
+
+ for (consts = (_ppd_cups_uiconsts_t *)cupsArrayFirst(ppd->cups_uiconstraints);
+ consts;
+ consts = (_ppd_cups_uiconsts_t *)cupsArrayNext(ppd->cups_uiconstraints))
+ {
+ free(consts->constraints);
+ free(consts);
+ }
+
+ cupsArrayDelete(ppd->cups_uiconstraints);
+ }
+
/*
* Free the whole record...
*/
* @since CUPS 1.2@
*/
-ppd_file_t * /* O - PPD file record */
+ppd_file_t * /* O - PPD file record or @code NULL@ if the PPD file could not be opened. */
ppdOpen2(cups_file_t *fp) /* I - File to read from */
{
int i, j, k; /* Looping vars */
cg->ppd_status = PPD_MISSING_PPDADOBE4;
_cupsStrFree(string);
+ ppd_free(line.buffer);
return (NULL);
}
{
cg->ppd_status = PPD_ALLOC_ERROR;
+ _cupsStrFree(string);
+ ppd_free(line.buffer);
+
return (NULL);
}
ppd->language_level = 2;
ppd->color_device = 0;
- ppd->colorspace = PPD_CS_GRAY;
+ ppd->colorspace = PPD_CS_N;
ppd->landscape = -90;
ppd->coptions = cupsArrayNew((cups_array_func_t)ppd_compare_coptions,
NULL);
while ((mask = ppd_read(fp, &line, keyword, name, text, &string, 1, cg)) != 0)
{
-#ifdef DEBUG
- printf("mask = %x, keyword = \"%s\"", mask, keyword);
+ DEBUG_printf(("mask=%x, keyword=\"%s\", name=\"%s\", text=\"%s\", "
+ "string=%d chars...", mask, keyword, name, text,
+ string ? (int)strlen(string) : 0));
- if (name[0] != '\0')
- printf(", name = \"%s\"", name);
-
- if (text[0] != '\0')
- printf(", text = \"%s\"", text);
-
- if (string != NULL)
- {
- if (strlen(string) > 40)
- printf(", string = %p", string);
- else
- printf(", string = \"%s\"", string);
- }
-
- puts("");
-#endif /* DEBUG */
-
- if (strcmp(keyword, "CloseUI") && strcmp(keyword, "CloseGroup") &&
- strcmp(keyword, "CloseSubGroup") && strncmp(keyword, "Default", 7) &&
- strcmp(keyword, "JCLCloseUI") && strcmp(keyword, "JCLOpenUI") &&
- strcmp(keyword, "OpenUI") && strcmp(keyword, "OpenGroup") &&
- strcmp(keyword, "OpenSubGroup") && string == NULL)
+ if (strncmp(keyword, "Default", 7) && !string)
{
/*
* Need a string value!
profile = realloc(ppd->profiles, sizeof(ppd_profile_t) *
(ppd->num_profiles + 1));
+ if (!profile)
+ {
+ cg->ppd_status = PPD_ALLOC_ERROR;
+
+ goto error;
+ }
+
ppd->profiles = profile;
profile += ppd->num_profiles;
ppd->num_profiles ++;
* Add the "custom" option...
*/
- if ((choice = ppd_add_choice(custom_option, "Custom")) == NULL)
- {
- DEBUG_puts("Unable to add Custom choice!");
+ if ((choice = ppdFindChoice(custom_option, "Custom")) == NULL)
+ if ((choice = ppd_add_choice(custom_option, "Custom")) == NULL)
+ {
+ DEBUG_puts("Unable to add Custom choice!");
- cg->ppd_status = PPD_ALLOC_ERROR;
+ cg->ppd_status = PPD_ALLOC_ERROR;
- goto error;
- }
+ goto error;
+ }
strlcpy(choice->text, text[0] ? text : _("Custom"),
sizeof(choice->text));
choice->code = _cupsStrAlloc(string);
+
+ if (custom_option->section == PPD_ORDER_JCL)
+ ppd_decode(choice->code);
}
/*
if (custom_option)
{
- if ((choice = ppd_add_choice(custom_option, "Custom")) == NULL)
- {
- DEBUG_puts("Unable to add Custom choice!");
+ if ((choice = ppdFindChoice(custom_option, "Custom")) == NULL)
+ if ((choice = ppd_add_choice(custom_option, "Custom")) == NULL)
+ {
+ DEBUG_puts("Unable to add Custom choice!");
- cg->ppd_status = PPD_ALLOC_ERROR;
+ cg->ppd_status = PPD_ALLOC_ERROR;
- goto error;
- }
+ goto error;
+ }
strlcpy(choice->text, text[0] ? text : _("Custom"),
sizeof(choice->text));
else if (!strcmp(string, "Plus90"))
ppd->landscape = 90;
}
- else if (!strcmp(keyword, "Emulators"))
+ else if (!strcmp(keyword, "Emulators") && string)
{
for (count = 1, sptr = string; sptr != NULL;)
if ((sptr = strchr(sptr, ' ')) != NULL)
}
ppd->num_emulations = count;
- ppd->emulations = calloc(count, sizeof(ppd_emul_t));
+ if ((ppd->emulations = calloc(count, sizeof(ppd_emul_t))) == NULL)
+ {
+ cg->ppd_status = PPD_ALLOC_ERROR;
+
+ goto error;
+ }
for (i = 0, sptr = string; i < count; i ++)
{
* Add an option record to the current sub-group, group, or file...
*/
- DEBUG_printf(("name=\"%s\" (%d)\n", name, strlen(name)));
+ DEBUG_printf(("name=\"%s\" (%d)\n", name, (int)strlen(name)));
if (name[0] == '*')
_cups_strcpy(name, name + 1); /* Eliminate leading asterisk */
if ((custom_attr = ppdFindAttr(ppd, custom_name, "True")) != NULL)
{
- if ((choice = ppd_add_choice(option, "Custom")) == NULL)
- {
- DEBUG_puts("Unable to add Custom choice!");
+ if ((choice = ppdFindChoice(option, "Custom")) == NULL)
+ if ((choice = ppd_add_choice(option, "Custom")) == NULL)
+ {
+ DEBUG_puts("Unable to add Custom choice!");
- cg->ppd_status = PPD_ALLOC_ERROR;
+ cg->ppd_status = PPD_ALLOC_ERROR;
- goto error;
- }
+ goto error;
+ }
strlcpy(choice->text,
custom_attr->text[0] ? custom_attr->text : _("Custom"),
break;
}
- /*
- * For CustomPageSize and InputSlot/ManualFeed, create a duplicate
- * constraint for PageRegion...
- */
-
- if (!strcasecmp(constraint->option1, "CustomPageSize") &&
- (!strcasecmp(constraint->option2, "InputSlot") ||
- !strcasecmp(constraint->option2, "ManualFeed")))
- {
- ppd->num_consts ++;
-
- strcpy(constraint[1].option1, "PageRegion");
- strcpy(constraint[1].choice1, "Custom");
- strcpy(constraint[1].option2, constraint->option2);
- strcpy(constraint[1].choice2, constraint->choice2);
- }
- else if (!strcasecmp(constraint->option2, "CustomPageSize") &&
- (!strcasecmp(constraint->option1, "InputSlot") ||
- !strcasecmp(constraint->option1, "ManualFeed")))
- {
- ppd->num_consts ++;
-
- strcpy(constraint[1].option1, constraint->option1);
- strcpy(constraint[1].choice1, constraint->choice1);
- strcpy(constraint[1].option2, "PageRegion");
- strcpy(constraint[1].choice2, "Custom");
- }
-
- /*
- * Handle CustomFoo option constraints...
- */
-
- if (!strncasecmp(constraint->option1, "Custom", 6) &&
- !strcasecmp(constraint->choice1, "True"))
- {
- _cups_strcpy(constraint->option1, constraint->option1 + 6);
- strcpy(constraint->choice1, "Custom");
- }
-
- if (!strncasecmp(constraint->option2, "Custom", 6) &&
- !strcasecmp(constraint->choice2, "True"))
- {
- _cups_strcpy(constraint->option2, constraint->option2 + 6);
- strcpy(constraint->choice2, "Custom");
- }
-
/*
* Don't add this one as an attribute...
*/
* Add the option choice...
*/
- choice = ppd_add_choice(option, name);
+ if ((choice = ppd_add_choice(option, name)) == NULL)
+ {
+ cg->ppd_status = PPD_ALLOC_ERROR;
+
+ goto error;
+ }
if (text[0])
cupsCharsetToUTF8((cups_utf8_t *)choice->text, text,
_cupsStrFree(string);
}
- if (line.buffer)
- free(line.buffer);
+ ppd_free(line.buffer);
/*
* Reset language preferences...
#ifdef DEBUG
if (!cupsFileEOF(fp))
- printf("Premature EOF at %lu...\n", (unsigned long)cupsFileTell(fp));
+ DEBUG_printf(("Premature EOF at %lu...\n",
+ (unsigned long)cupsFileTell(fp)));
#endif /* DEBUG */
if (cg->ppd_status != PPD_OK)
}
}
- /*
- * Sort the constraints...
- */
-
- if (ppd->num_consts > 1)
- qsort(ppd->consts, ppd->num_consts, sizeof(ppd_const_t),
- (int (*)(const void *, const void *))ppd_compare_consts);
-
/*
* Create an array to track the marked choices...
*/
error:
- if (line.buffer)
- free(line.buffer);
-
_cupsStrFree(string);
+ ppd_free(line.buffer);
ppdClose(ppd);
* 'ppdOpenFd()' - Read a PPD file into memory.
*/
-ppd_file_t * /* O - PPD file record */
+ppd_file_t * /* O - PPD file record or @code NULL@ if the PPD file could not be opened. */
ppdOpenFd(int fd) /* I - File to read from */
{
cups_file_t *fp; /* CUPS file pointer */
* 'ppdOpenFile()' - Read a PPD file into memory.
*/
-ppd_file_t * /* O - PPD file record */
+ppd_file_t * /* O - PPD file record or @code NULL@ if the PPD file could not be opened. */
ppdOpenFile(const char *filename) /* I - File to read from */
{
cups_file_t *fp; /* File pointer */
}
-/*
- * 'ppd_compare_consts()' - Compare two constraints.
- */
-
-static int /* O - Result of comparison */
-ppd_compare_consts(ppd_const_t *a, /* I - First constraint */
- ppd_const_t *b) /* I - Second constraint */
-{
- int ret; /* Result of comparison */
-
-
- if ((ret = strcmp(a->option1, b->option1)) != 0)
- return (ret);
- else if ((ret = strcmp(a->choice1, b->choice1)) != 0)
- return (ret);
- else if ((ret = strcmp(a->option2, b->option2)) != 0)
- return (ret);
- else
- return (strcmp(a->choice2, b->choice2));
-}
-
-
/*
* 'ppd_compare_coptions()' - Compare two custom options.
*/
if (ch == 0x0a)
cupsFileGetChar(fp);
}
-
- ch = '\n';
}
else if (ch < ' ' && ch != '\t' && cg->ppd_conform == PPD_CONFORM_STRICT)
{
*lineptr = '\0';
- DEBUG_printf(("LINE = \"%s\"\n", line));
+ DEBUG_printf(("LINE=\"%s\"\n", line->buffer));
/*
* The dynamically created PPDs for older style Mac OS X
/*
- * End of "$Id: ppd.c 6937 2007-09-10 21:13:31Z mike $".
+ * End of "$Id: ppd.c 7552 2008-05-12 17:42:15Z mike $".
*/