From: mike Date: Fri, 28 Feb 2003 21:06:09 +0000 (+0000) Subject: Update PPD attribute API to return ppd_attr_t pointers and to separate X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=f0e7bfbdc6831c9048e883a836294b46857f9d5d;p=thirdparty%2Fcups.git Update PPD attribute API to return ppd_attr_t pointers and to separate the translation text from the option keyword (spec). git-svn-id: svn+ssh://src.apple.com/svn/cups/cups.org/trunk@3415 7a7537e8-13f0-0310-91df-b6672ffda945 --- diff --git a/cups/attr.c b/cups/attr.c index 9d79ca0199..942525e3de 100644 --- a/cups/attr.c +++ b/cups/attr.c @@ -1,5 +1,5 @@ /* - * "$Id: attr.c,v 1.3 2003/01/31 20:09:20 mike Exp $" + * "$Id: attr.c,v 1.4 2003/02/28 21:06:08 mike Exp $" * * PPD model-specific attribute routines for the Common UNIX Printing System * (CUPS). @@ -49,7 +49,7 @@ extern int _ppd_attr_compare(ppd_attr_t **a, ppd_attr_t **b); * 'ppdFindAttr()' - Find the first matching attribute... */ -const char * /* O - Value or NULL if not found */ +ppd_attr_t * /* O - Attribute or NULL if not found */ ppdFindAttr(ppd_file_t *ppd, /* I - PPD file data */ const char *name, /* I - Attribute name */ const char *spec) /* I - Specifier string or NULL */ @@ -111,10 +111,7 @@ ppdFindAttr(ppd_file_t *ppd, /* I - PPD file data */ ppd->cur_attr = match - ppd->attrs; - if ((*match)->value) - return ((*match)->value); - else - return (""); + return (*match); } @@ -122,7 +119,7 @@ ppdFindAttr(ppd_file_t *ppd, /* I - PPD file data */ * 'ppdFindNextAttr()' - Find the next matching attribute... */ -const char * /* O - Value or NULL if not found */ +ppd_attr_t * /* O - Attribute or NULL if not found */ ppdFindNextAttr(ppd_file_t *ppd, /* I - PPD file data */ const char *name, /* I - Attribute name */ const char *spec) /* I - Specifier string or NULL */ @@ -174,13 +171,10 @@ ppdFindNextAttr(ppd_file_t *ppd, /* I - PPD file data */ * Return the next attribute's value... */ - if ((*match)->value) - return ((*match)->value); - else - return (""); + return (*match); } /* - * End of "$Id: attr.c,v 1.3 2003/01/31 20:09:20 mike Exp $". + * End of "$Id: attr.c,v 1.4 2003/02/28 21:06:08 mike Exp $". */ diff --git a/cups/emit.c b/cups/emit.c index 2c2510ba40..451cd3ab3e 100644 --- a/cups/emit.c +++ b/cups/emit.c @@ -1,5 +1,5 @@ /* - * "$Id: emit.c,v 1.30 2003/02/18 22:23:38 mike Exp $" + * "$Id: emit.c,v 1.31 2003/02/28 21:06:08 mike Exp $" * * PPD code emission routines for the Common UNIX Printing System (CUPS). * @@ -488,7 +488,7 @@ ppd_handle_media(ppd_file_t *ppd) *input_slot, /* InputSlot choice, if any */ *page; /* PageSize/PageRegion */ ppd_size_t *size; /* Current media size */ - const char *rpr; /* RequiresPageRegion value */ + ppd_attr_t *rpr; /* RequiresPageRegion value */ /* @@ -533,7 +533,8 @@ ppd_handle_media(ppd_file_t *ppd) ppdMarkOption(ppd, "PageRegion", size->name); - if ((rpr && !strcmp(rpr, "False")) || (!rpr && !ppd->num_filters)) + if ((rpr && rpr->value && !strcmp(rpr->value, "False")) || + (!rpr && !ppd->num_filters)) { /* * Either the PPD file specifies no PageRegion code or the PPD file @@ -569,5 +570,5 @@ ppd_sort(ppd_choice_t **c1, /* I - First choice */ /* - * End of "$Id: emit.c,v 1.30 2003/02/18 22:23:38 mike Exp $". + * End of "$Id: emit.c,v 1.31 2003/02/28 21:06:08 mike Exp $". */ diff --git a/cups/ppd.c b/cups/ppd.c index 60bef9f82e..68108ac1e3 100644 --- a/cups/ppd.c +++ b/cups/ppd.c @@ -1,5 +1,5 @@ /* - * "$Id: ppd.c,v 1.100 2003/02/28 10:28:25 mike Exp $" + * "$Id: ppd.c,v 1.101 2003/02/28 21:06:08 mike Exp $" * * PPD file routines for the Common UNIX Printing System (CUPS). * @@ -103,7 +103,8 @@ static int ppd_line = 0; /* Current line number */ */ static ppd_attr_t *ppd_add_attr(ppd_file_t *ppd, const char *name, - const char *spec, const char *value); + const char *spec, const char *text, + 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); #ifndef __APPLE__ @@ -719,7 +720,7 @@ ppdOpen(FILE *fp) /* I - File to read from */ * Add each Product keyword as an attribute... */ - ppd_add_attr(ppd, keyword, "", string); + ppd_add_attr(ppd, keyword, "", "", string); /* * Save the last one in the product element... @@ -1663,7 +1664,7 @@ ppdOpen(FILE *fp) /* I - File to read from */ * Option not found; add this as an attribute... */ - ppd_add_attr(ppd, keyword, "", string); + ppd_add_attr(ppd, keyword, "", "", string); string = NULL; /* Don't free this string below */ } @@ -1676,7 +1677,7 @@ ppdOpen(FILE *fp) /* I - File to read from */ * Default doesn't match this option; add as an attribute... */ - ppd_add_attr(ppd, keyword, "", string); + ppd_add_attr(ppd, keyword, "", "", string); string = NULL; /* Don't free this string below */ } @@ -1880,15 +1881,7 @@ ppdOpen(FILE *fp) /* I - File to read from */ else if (strcmp(keyword, "OpenSubGroup") != 0 && strcmp(keyword, "CloseSubGroup") != 0) { - char spec[PPD_MAX_NAME + PPD_MAX_TEXT]; - - if (text[0]) - { - snprintf(spec, sizeof(spec), "%s/%s", name, text); - ppd_add_attr(ppd, keyword, spec, string); - } - else - ppd_add_attr(ppd, keyword, name, string); + ppd_add_attr(ppd, keyword, name, text, string); string = NULL; /* Don't free this string below */ } @@ -2123,6 +2116,7 @@ static ppd_attr_t * /* O - New attribute */ ppd_add_attr(ppd_file_t *ppd, /* I - PPD file data */ const char *name, /* I - Attribute name */ const char *spec, /* I - Specifier string, if any */ + const char *text, /* I - Text string, if any */ const char *value) /* I - Value of attribute */ { ppd_attr_t **ptr, /* New array */ @@ -2164,6 +2158,7 @@ ppd_add_attr(ppd_file_t *ppd, /* I - PPD file data */ strlcpy(temp->name, name, sizeof(temp->name)); strlcpy(temp->spec, spec, sizeof(temp->spec)); + strlcpy(temp->text, text, sizeof(temp->text)); temp->value = (char *)value; /* @@ -2979,5 +2974,5 @@ ppd_read(FILE *fp, /* I - File to read from */ /* - * End of "$Id: ppd.c,v 1.100 2003/02/28 10:28:25 mike Exp $". + * End of "$Id: ppd.c,v 1.101 2003/02/28 21:06:08 mike Exp $". */ diff --git a/cups/ppd.h b/cups/ppd.h index dcb079913e..167f96fe15 100644 --- a/cups/ppd.h +++ b/cups/ppd.h @@ -1,5 +1,5 @@ /* - * "$Id: ppd.h,v 1.32 2003/02/18 22:43:07 mike Exp $" + * "$Id: ppd.h,v 1.33 2003/02/28 21:06:08 mike Exp $" * * PostScript Printer Description definitions for the Common UNIX Printing * System (CUPS). @@ -127,8 +127,10 @@ typedef struct /**** PPD Attribute Structure ****/ { char name[PPD_MAX_NAME], /* Name of attribute (cupsXYZ) */ - spec[PPD_MAX_NAME + PPD_MAX_TEXT], + spec[PPD_MAX_NAME], /* Specifier string, if any */ + text[PPD_MAX_TEXT], + /* Human-readable text, if any */ *value; /* Value string */ } ppd_attr_t; @@ -305,9 +307,9 @@ extern float ppdPageWidth(ppd_file_t *ppd, const char *name); /**** New in CUPS 1.1.19 ****/ extern const char *ppdErrorString(ppd_status_t status); -extern const char *ppdFindAttr(ppd_file_t *ppd, const char *name, +extern ppd_attr_t *ppdFindAttr(ppd_file_t *ppd, const char *name, const char *spec); -extern const char *ppdFindNextAttr(ppd_file_t *ppd, const char *name, +extern ppd_attr_t *ppdFindNextAttr(ppd_file_t *ppd, const char *name, const char *spec); extern ppd_status_t ppdLastError(int *line); @@ -321,5 +323,5 @@ extern ppd_status_t ppdLastError(int *line); #endif /* !_CUPS_PPD_H_ */ /* - * End of "$Id: ppd.h,v 1.32 2003/02/18 22:43:07 mike Exp $". + * End of "$Id: ppd.h,v 1.33 2003/02/28 21:06:08 mike Exp $". */ diff --git a/systemv/cupstestppd.c b/systemv/cupstestppd.c index 6d8e6040f1..a972362f5b 100644 --- a/systemv/cupstestppd.c +++ b/systemv/cupstestppd.c @@ -1,5 +1,5 @@ /* - * "$Id: cupstestppd.c,v 1.19 2003/02/26 01:19:07 mike Exp $" + * "$Id: cupstestppd.c,v 1.20 2003/02/28 21:06:09 mike Exp $" * * PPD test program for the Common UNIX Printing System (CUPS). * @@ -79,6 +79,7 @@ main(int argc, /* I - Number of command-line arguments */ ppd_status_t error; /* Status of ppdOpen*() */ int line; /* Line number for error */ ppd_file_t *ppd; /* PPD file record */ + ppd_attr_t *attr; /* PPD attribute */ ppd_size_t *size; /* Size record */ ppd_group_t *group; /* UI group */ ppd_option_t *option; /* Standard UI option */ @@ -271,8 +272,9 @@ main(int argc, /* I - Number of command-line arguments */ if (verbose > 0) puts("\n DETAILED CONFORMANCE TEST RESULTS"); - if ((ptr = ppdFindAttr(ppd, "FormatVersion", NULL)) != NULL) - ppdversion = (int)(10 * atof(ptr) + 0.5); + if ((attr = ppdFindAttr(ppd, "FormatVersion", NULL)) != NULL && + attr->value) + ppdversion = (int)(10 * atof(attr->value) + 0.5); if (ppdFindAttr(ppd, "DefaultImageableArea", NULL) != NULL) { @@ -580,13 +582,14 @@ main(int argc, /* I - Number of command-line arguments */ errors ++; } - if ((ptr = ppdFindAttr(ppd, "PSVersion", NULL)) != NULL) + if ((attr = ppdFindAttr(ppd, "PSVersion", NULL)) != NULL && + attr->value != NULL) { char junkstr[255]; /* Temp string */ int junkint; /* Temp integer */ - if (sscanf(ptr, "(%[^)])%d", junkstr, &junkint) != 2) + if (sscanf(attr->value, "(%[^)])%d", junkstr, &junkint) != 2) { if (verbose >= 0) { @@ -657,8 +660,8 @@ main(int argc, /* I - Number of command-line arguments */ { if (ppdversion < 43) { - printf(" WARN Obsolete PPD version %s!\n", - ppdFindAttr(ppd, "FormatVersion", NULL)); + printf(" WARN Obsolete PPD version %.1f!\n", + 0.1f * ppdversion); puts(" REF: Page 42, section 5.2."); } @@ -868,5 +871,5 @@ usage(void) /* - * End of "$Id: cupstestppd.c,v 1.19 2003/02/26 01:19:07 mike Exp $". + * End of "$Id: cupstestppd.c,v 1.20 2003/02/28 21:06:09 mike Exp $". */