2 * "$Id: ppd.c 7552 2008-05-12 17:42:15Z mike $"
4 * PPD file routines for the Common UNIX Printing System (CUPS).
6 * Copyright 2007-2008 by Apple Inc.
7 * Copyright 1997-2007 by Easy Software Products, all rights reserved.
9 * These coded instructions, statements, and computer programs are the
10 * property of Apple Inc. and are protected by Federal copyright
11 * law. Distribution and use rights are outlined in the file "LICENSE.txt"
12 * which should have been included with this file. If this file is
13 * file is missing or damaged, see the license at "http://www.cups.org/".
15 * PostScript is a trademark of Adobe Systems, Inc.
17 * This code and any derivative of it may be used and distributed
18 * freely under the terms of the GNU General Public License when
19 * used with GNU Ghostscript or its derivatives. Use of the code
20 * (or any derivative of it) with software other than GNU
21 * GhostScript (or its derivatives) is governed by the CUPS license
24 * This file is subject to the Apple OS-Developed Software exception.
28 * ppdClose() - Free all memory used by the PPD file.
29 * ppdErrorString() - Returns the text assocated with a status.
30 * _ppdGetEncoding() - Get the CUPS encoding value for the given
32 * ppdLastError() - Return the status from the last ppdOpen*().
33 * ppdOpen() - Read a PPD file into memory.
34 * ppdOpen2() - Read a PPD file into memory.
35 * ppdOpenFd() - Read a PPD file into memory.
36 * ppdOpenFile() - Read a PPD file into memory.
37 * ppdSetConformance() - Set the conformance level for PPD files.
38 * ppd_add_attr() - Add an attribute to the PPD data.
39 * ppd_add_choice() - Add a choice to an option.
40 * ppd_add_size() - Add a page size.
41 * ppd_compare_attrs() - Compare two attributes.
42 * ppd_compare_choices() - Compare two choices...
43 * ppd_compare_coptions() - Compare two custom options.
44 * ppd_compare_cparams() - Compare two custom parameters.
45 * ppd_compare_options() - Compare two options.
46 * ppd_decode() - Decode a string value...
47 * ppd_free_group() - Free a single UI group.
48 * ppd_free_option() - Free a single option.
49 * ppd_get_coption() - Get a custom option record.
50 * ppd_get_cparam() - Get a custom parameter record.
51 * ppd_get_group() - Find or create the named group as needed.
52 * ppd_get_option() - Find or create the named option as needed.
53 * ppd_hash_option() - Generate a hash of the option name...
54 * ppd_read() - Read a line from a PPD file, skipping comment
59 * Include necessary headers.
62 #include "ppd-private.h"
72 #if defined(WIN32) || defined(__EMX__)
73 # define READ_BINARY "rb" /* Open a binary file for reading */
74 # define WRITE_BINARY "wb" /* Open a binary file for writing */
76 # define READ_BINARY "r" /* Open a binary file for reading */
77 # define WRITE_BINARY "w" /* Open a binary file for writing */
78 #endif /* WIN32 || __EMX__ */
80 #define ppd_free(p) if (p) free(p) /* Safe free macro */
82 #define PPD_KEYWORD 1 /* Line contained a keyword */
83 #define PPD_OPTION 2 /* Line contained an option name */
84 #define PPD_TEXT 4 /* Line contained human-readable text */
85 #define PPD_STRING 8 /* Line contained a string or code */
87 #define PPD_HASHSIZE 512 /* Size of hash */
91 * Line buffer structure...
94 typedef struct _ppd_line_s
96 char *buffer
; /* Pointer to buffer */
97 size_t bufsize
; /* Size of the buffer */
105 static ppd_attr_t
*ppd_add_attr(ppd_file_t
*ppd
, const char *name
,
106 const char *spec
, const char *text
,
108 static ppd_choice_t
*ppd_add_choice(ppd_option_t
*option
, const char *name
);
109 static ppd_size_t
*ppd_add_size(ppd_file_t
*ppd
, const char *name
);
110 static int ppd_compare_attrs(ppd_attr_t
*a
, ppd_attr_t
*b
);
111 static int ppd_compare_choices(ppd_choice_t
*a
, ppd_choice_t
*b
);
112 static int ppd_compare_coptions(ppd_coption_t
*a
,
114 static int ppd_compare_cparams(ppd_cparam_t
*a
, ppd_cparam_t
*b
);
115 static int ppd_compare_options(ppd_option_t
*a
, ppd_option_t
*b
);
116 static int ppd_decode(char *string
);
117 static void ppd_free_group(ppd_group_t
*group
);
118 static void ppd_free_option(ppd_option_t
*option
);
119 static ppd_coption_t
*ppd_get_coption(ppd_file_t
*ppd
, const char *name
);
120 static ppd_cparam_t
*ppd_get_cparam(ppd_coption_t
*opt
,
123 static ppd_group_t
*ppd_get_group(ppd_file_t
*ppd
, const char *name
,
124 const char *text
, _cups_globals_t
*cg
,
125 cups_encoding_t encoding
);
126 static ppd_option_t
*ppd_get_option(ppd_group_t
*group
, const char *name
);
127 static int ppd_hash_option(ppd_option_t
*option
);
128 static int ppd_read(cups_file_t
*fp
, _ppd_line_t
*line
,
129 char *keyword
, char *option
, char *text
,
130 char **string
, int ignoreblank
,
131 _cups_globals_t
*cg
);
135 * 'ppdClose()' - Free all memory used by the PPD file.
139 ppdClose(ppd_file_t
*ppd
) /* I - PPD file record */
141 int i
; /* Looping var */
142 ppd_emul_t
*emul
; /* Current emulation */
143 ppd_group_t
*group
; /* Current group */
144 char **font
; /* Current font */
145 char **filter
; /* Current filter */
146 ppd_attr_t
**attr
; /* Current attribute */
147 ppd_coption_t
*coption
; /* Current custom option */
148 ppd_cparam_t
*cparam
; /* Current custom parameter */
152 * Range check arguments...
159 * Free all strings at the top level...
162 _cupsStrFree(ppd
->lang_encoding
);
163 _cupsStrFree(ppd
->nickname
);
164 _cupsStrFree(ppd
->patches
);
165 _cupsStrFree(ppd
->jcl_begin
);
166 _cupsStrFree(ppd
->jcl_end
);
167 _cupsStrFree(ppd
->jcl_ps
);
170 * Free any emulations...
173 if (ppd
->num_emulations
> 0)
175 for (i
= ppd
->num_emulations
, emul
= ppd
->emulations
; i
> 0; i
--, emul
++)
177 _cupsStrFree(emul
->start
);
178 _cupsStrFree(emul
->stop
);
181 ppd_free(ppd
->emulations
);
185 * Free any UI groups, subgroups, and options...
188 if (ppd
->num_groups
> 0)
190 for (i
= ppd
->num_groups
, group
= ppd
->groups
; i
> 0; i
--, group
++)
191 ppd_free_group(group
);
193 ppd_free(ppd
->groups
);
196 cupsArrayDelete(ppd
->options
);
197 cupsArrayDelete(ppd
->marked
);
200 * Free any page sizes...
203 if (ppd
->num_sizes
> 0)
204 ppd_free(ppd
->sizes
);
207 * Free any constraints...
210 if (ppd
->num_consts
> 0)
211 ppd_free(ppd
->consts
);
214 * Free any filters...
217 if (ppd
->num_filters
> 0)
219 for (i
= ppd
->num_filters
, filter
= ppd
->filters
; i
> 0; i
--, filter
++)
220 _cupsStrFree(*filter
);
222 ppd_free(ppd
->filters
);
229 if (ppd
->num_fonts
> 0)
231 for (i
= ppd
->num_fonts
, font
= ppd
->fonts
; i
> 0; i
--, font
++)
234 ppd_free(ppd
->fonts
);
238 * Free any profiles...
241 if (ppd
->num_profiles
> 0)
242 ppd_free(ppd
->profiles
);
245 * Free any attributes...
248 if (ppd
->num_attrs
> 0)
250 for (i
= ppd
->num_attrs
, attr
= ppd
->attrs
; i
> 0; i
--, attr
++)
252 _cupsStrFree((*attr
)->value
);
256 ppd_free(ppd
->attrs
);
259 cupsArrayDelete(ppd
->sorted_attrs
);
262 * Free custom options...
265 for (coption
= (ppd_coption_t
*)cupsArrayFirst(ppd
->coptions
);
267 coption
= (ppd_coption_t
*)cupsArrayNext(ppd
->coptions
))
269 for (cparam
= (ppd_cparam_t
*)cupsArrayFirst(coption
->params
);
271 cparam
= (ppd_cparam_t
*)cupsArrayNext(coption
->params
))
273 switch (cparam
->type
)
275 case PPD_CUSTOM_PASSCODE
:
276 case PPD_CUSTOM_PASSWORD
:
277 case PPD_CUSTOM_STRING
:
278 _cupsStrFree(cparam
->current
.custom_string
);
288 cupsArrayDelete(coption
->params
);
293 cupsArrayDelete(ppd
->coptions
);
296 * Free constraints...
299 if (ppd
->cups_uiconstraints
)
301 _ppd_cups_uiconsts_t
*consts
; /* Current constraints */
304 for (consts
= (_ppd_cups_uiconsts_t
*)cupsArrayFirst(ppd
->cups_uiconstraints
);
306 consts
= (_ppd_cups_uiconsts_t
*)cupsArrayNext(ppd
->cups_uiconstraints
))
308 free(consts
->constraints
);
312 cupsArrayDelete(ppd
->cups_uiconstraints
);
316 * Free the whole record...
324 * 'ppdErrorString()' - Returns the text assocated with a status.
326 * @since CUPS 1.1.19@
329 const char * /* O - Status string */
330 ppdErrorString(ppd_status_t status
) /* I - PPD status */
332 static const char * const messages
[] =/* Status messages */
335 _("Unable to open PPD file"),
336 _("NULL PPD file pointer"),
337 _("Memory allocation error"),
338 _("Missing PPD-Adobe-4.x header"),
339 _("Missing value string"),
342 _("OpenGroup without a CloseGroup first"),
343 _("Bad OpenUI/JCLOpenUI"),
344 _("OpenUI/JCLOpenUI without a CloseUI/JCLCloseUI first"),
345 _("Bad OrderDependency"),
346 _("Bad UIConstraints"),
347 _("Missing asterisk in column 1"),
348 _("Line longer than the maximum allowed (255 characters)"),
349 _("Illegal control character"),
350 _("Illegal main keyword string"),
351 _("Illegal option keyword string"),
352 _("Illegal translation string"),
353 _("Illegal whitespace character"),
354 _("Bad custom parameter")
358 if (status
< PPD_OK
|| status
> PPD_ILLEGAL_WHITESPACE
)
359 return (_cupsLangString(cupsLangDefault(), _("Unknown")));
361 return (_cupsLangString(cupsLangDefault(), messages
[status
]));
366 * '_ppdGetEncoding()' - Get the CUPS encoding value for the given
370 cups_encoding_t
/* O - CUPS encoding value */
371 _ppdGetEncoding(const char *name
) /* I - LanguageEncoding string */
373 if (!strcasecmp(name
, "ISOLatin1"))
374 return (CUPS_ISO8859_1
);
375 else if (!strcasecmp(name
, "ISOLatin2"))
376 return (CUPS_ISO8859_2
);
377 else if (!strcasecmp(name
, "ISOLatin5"))
378 return (CUPS_ISO8859_5
);
379 else if (!strcasecmp(name
, "JIS83-RKSJ"))
380 return (CUPS_WINDOWS_932
);
381 else if (!strcasecmp(name
, "MacStandard"))
382 return (CUPS_MAC_ROMAN
);
383 else if (!strcasecmp(name
, "WindowsANSI"))
384 return (CUPS_WINDOWS_1252
);
391 * 'ppdLastError()' - Return the status from the last ppdOpen*().
393 * @since CUPS 1.1.19@
396 ppd_status_t
/* O - Status code */
397 ppdLastError(int *line
) /* O - Line number */
399 _cups_globals_t
*cg
= _cupsGlobals();
404 *line
= cg
->ppd_line
;
406 return (cg
->ppd_status
);
411 * 'ppdOpen()' - Read a PPD file into memory.
414 ppd_file_t
* /* O - PPD file record */
415 ppdOpen(FILE *fp
) /* I - File to read from */
417 ppd_file_t
*ppd
; /* PPD file record */
418 cups_file_t
*cf
; /* CUPS file */
422 * Reopen the stdio file as a CUPS file...
425 if ((cf
= cupsFileOpenFd(fileno(fp
), "r")) == NULL
)
429 * Load the PPD file using the newer API...
435 * Close the CUPS file and return the PPD...
445 * 'ppdOpen2()' - Read a PPD file into memory.
450 ppd_file_t
* /* O - PPD file record or @code NULL@ if the PPD file could not be opened. */
451 ppdOpen2(cups_file_t
*fp
) /* I - File to read from */
453 int i
, j
, k
; /* Looping vars */
454 int count
; /* Temporary count */
455 _ppd_line_t line
; /* Line buffer */
456 ppd_file_t
*ppd
; /* PPD file record */
457 ppd_group_t
*group
, /* Current group */
458 *subgroup
; /* Current sub-group */
459 ppd_option_t
*option
; /* Current option */
460 ppd_choice_t
*choice
; /* Current choice */
461 ppd_const_t
*constraint
; /* Current constraint */
462 ppd_size_t
*size
; /* Current page size */
463 int mask
; /* Line data mask */
464 char keyword
[PPD_MAX_NAME
],
465 /* Keyword from file */
467 /* Option from file */
469 /* Human-readable text from file */
470 *string
, /* Code/text from file */
471 *sptr
, /* Pointer into string */
472 *nameptr
, /* Pointer into name */
473 *temp
, /* Temporary string pointer */
474 **tempfonts
; /* Temporary fonts pointer */
475 float order
; /* Order dependency number */
476 ppd_section_t section
; /* Order dependency section */
477 ppd_profile_t
*profile
; /* Pointer to color profile */
478 char **filter
; /* Pointer to filter */
479 cups_lang_t
*language
; /* Default language */
480 struct lconv
*loc
; /* Locale data */
481 int ui_keyword
; /* Is this line a UI keyword? */
482 cups_encoding_t encoding
; /* Encoding of PPD file */
483 _cups_globals_t
*cg
= _cupsGlobals();
485 char custom_name
[PPD_MAX_NAME
];
486 /* CustomFoo attribute name */
487 ppd_attr_t
*custom_attr
; /* CustomFoo attribute */
488 static const char * const ui_keywords
[] =
490 #ifdef CUPS_USE_FULL_UI_KEYWORDS_LIST
492 * Adobe defines some 41 keywords as "UI", meaning that they are
493 * user interface elements and that they should be treated as such
494 * even if the PPD creator doesn't use Open/CloseUI around them.
496 * Since this can cause previously invisible options to appear and
497 * confuse users, the default is to only treat the PageSize and
498 * PageRegion keywords this way.
500 /* Boolean keywords */
510 /* PickOne keywords */
523 "JCLFrameBufferSize",
544 #else /* !CUPS_USE_FULL_UI_KEYWORDS_LIST */
547 #endif /* CUPS_USE_FULL_UI_KEYWORDS_LIST */
552 * Default to "OK" status...
555 cg
->ppd_status
= PPD_OK
;
559 * Range check input...
564 cg
->ppd_status
= PPD_NULL_FILE
;
569 * Grab the first line and make sure it reads '*PPD-Adobe: "major.minor"'...
575 mask
= ppd_read(fp
, &line
, keyword
, name
, text
, &string
, 0, cg
);
577 DEBUG_printf(("mask=%x, keyword=\"%s\"...\n", mask
, keyword
));
580 strcmp(keyword
, "PPD-Adobe") ||
581 string
== NULL
|| string
[0] != '4')
584 * Either this is not a PPD file, or it is not a 4.x PPD file.
587 if (cg
->ppd_status
== PPD_OK
)
588 cg
->ppd_status
= PPD_MISSING_PPDADOBE4
;
590 _cupsStrFree(string
);
595 DEBUG_printf(("ppdOpen: keyword = %s, string = %p\n", keyword
, string
));
597 _cupsStrFree(string
);
600 * Allocate memory for the PPD file record...
603 if ((ppd
= calloc(1, sizeof(ppd_file_t
))) == NULL
)
605 cg
->ppd_status
= PPD_ALLOC_ERROR
;
610 ppd
->language_level
= 2;
611 ppd
->color_device
= 0;
612 ppd
->colorspace
= PPD_CS_N
;
613 ppd
->landscape
= -90;
614 ppd
->coptions
= cupsArrayNew((cups_array_func_t
)ppd_compare_coptions
,
618 * Get the default language for the user...
621 language
= cupsLangDefault();
625 * Read lines from the PPD file and add them to the file record...
633 encoding
= CUPS_ISO8859_1
;
635 while ((mask
= ppd_read(fp
, &line
, keyword
, name
, text
, &string
, 1, cg
)) != 0)
637 DEBUG_printf(("mask=%x, keyword=\"%s\", name=\"%s\", text=\"%s\", "
638 "string=%d chars...", mask
, keyword
, name
, text
,
639 string
? (int)strlen(string
) : 0));
641 if (strncmp(keyword
, "Default", 7) && !string
)
644 * Need a string value!
647 cg
->ppd_status
= PPD_MISSING_VALUE
;
653 * Certain main keywords (as defined by the PPD spec) may be used
654 * without the usual OpenUI/CloseUI stuff. Presumably this is just
655 * so that Adobe wouldn't completely break compatibility with PPD
656 * files prior to v4.0 of the spec, but it is hopelessly
657 * inconsistent... Catch these main keywords and automatically
658 * create the corresponding option, as needed...
664 * Previous line was a UI keyword...
671 if (option
== NULL
&&
672 (mask
& (PPD_KEYWORD
| PPD_OPTION
| PPD_STRING
)) ==
673 (PPD_KEYWORD
| PPD_OPTION
| PPD_STRING
))
675 for (i
= 0; i
< (int)(sizeof(ui_keywords
) / sizeof(ui_keywords
[0])); i
++)
676 if (!strcmp(keyword
, ui_keywords
[i
]))
679 if (i
< (int)(sizeof(ui_keywords
) / sizeof(ui_keywords
[0])))
682 * Create the option in the appropriate group...
687 DEBUG_printf(("**** FOUND ADOBE UI KEYWORD %s WITHOUT OPENUI!\n",
692 if ((group
= ppd_get_group(ppd
, "General", _("General"), cg
,
696 DEBUG_printf(("Adding to group %s...\n", group
->text
));
697 option
= ppd_get_option(group
, keyword
);
701 option
= ppd_get_option(group
, keyword
);
705 cg
->ppd_status
= PPD_ALLOC_ERROR
;
711 * Now fill in the initial information for the option...
714 if (!strncmp(keyword
, "JCL", 3))
715 option
->section
= PPD_ORDER_JCL
;
717 option
->section
= PPD_ORDER_ANY
;
719 option
->order
= 10.0f
;
722 option
->ui
= PPD_UI_BOOLEAN
;
724 option
->ui
= PPD_UI_PICKONE
;
726 for (j
= 0; j
< ppd
->num_attrs
; j
++)
727 if (!strncmp(ppd
->attrs
[j
]->name
, "Default", 7) &&
728 !strcmp(ppd
->attrs
[j
]->name
+ 7, keyword
) &&
729 ppd
->attrs
[j
]->value
)
731 DEBUG_printf(("Setting Default%s to %s via attribute...\n",
732 option
->keyword
, ppd
->attrs
[j
]->value
));
733 strlcpy(option
->defchoice
, ppd
->attrs
[j
]->value
,
734 sizeof(option
->defchoice
));
738 if (!strcmp(keyword
, "PageSize"))
739 strlcpy(option
->text
, _("Media Size"), sizeof(option
->text
));
740 else if (!strcmp(keyword
, "MediaType"))
741 strlcpy(option
->text
, _("Media Type"), sizeof(option
->text
));
742 else if (!strcmp(keyword
, "InputSlot"))
743 strlcpy(option
->text
, _("Media Source"), sizeof(option
->text
));
744 else if (!strcmp(keyword
, "ColorModel"))
745 strlcpy(option
->text
, _("Output Mode"), sizeof(option
->text
));
746 else if (!strcmp(keyword
, "Resolution"))
747 strlcpy(option
->text
, _("Resolution"), sizeof(option
->text
));
749 strlcpy(option
->text
, keyword
, sizeof(option
->text
));
753 if (!strcmp(keyword
, "LanguageLevel"))
754 ppd
->language_level
= atoi(string
);
755 else if (!strcmp(keyword
, "LanguageEncoding"))
758 * Say all PPD files are UTF-8, since we convert to UTF-8...
761 ppd
->lang_encoding
= _cupsStrAlloc("UTF-8");
762 encoding
= _ppdGetEncoding(string
);
764 else if (!strcmp(keyword
, "LanguageVersion"))
765 ppd
->lang_version
= string
;
766 else if (!strcmp(keyword
, "Manufacturer"))
767 ppd
->manufacturer
= string
;
768 else if (!strcmp(keyword
, "ModelName"))
769 ppd
->modelname
= string
;
770 else if (!strcmp(keyword
, "Protocols"))
771 ppd
->protocols
= string
;
772 else if (!strcmp(keyword
, "PCFileName"))
773 ppd
->pcfilename
= string
;
774 else if (!strcmp(keyword
, "NickName"))
776 if (encoding
!= CUPS_UTF8
)
778 cups_utf8_t utf8
[256]; /* UTF-8 version of NickName */
781 cupsCharsetToUTF8(utf8
, string
, sizeof(utf8
), encoding
);
782 ppd
->nickname
= _cupsStrAlloc((char *)utf8
);
785 ppd
->nickname
= _cupsStrAlloc(string
);
787 else if (!strcmp(keyword
, "Product"))
788 ppd
->product
= string
;
789 else if (!strcmp(keyword
, "ShortNickName"))
790 ppd
->shortnickname
= string
;
791 else if (!strcmp(keyword
, "TTRasterizer"))
792 ppd
->ttrasterizer
= string
;
793 else if (!strcmp(keyword
, "JCLBegin"))
795 ppd
->jcl_begin
= _cupsStrAlloc(string
);
796 ppd_decode(ppd
->jcl_begin
); /* Decode quoted string */
798 else if (!strcmp(keyword
, "JCLEnd"))
800 ppd
->jcl_end
= _cupsStrAlloc(string
);
801 ppd_decode(ppd
->jcl_end
); /* Decode quoted string */
803 else if (!strcmp(keyword
, "JCLToPSInterpreter"))
805 ppd
->jcl_ps
= _cupsStrAlloc(string
);
806 ppd_decode(ppd
->jcl_ps
); /* Decode quoted string */
808 else if (!strcmp(keyword
, "AccurateScreensSupport"))
809 ppd
->accurate_screens
= !strcmp(string
, "True");
810 else if (!strcmp(keyword
, "ColorDevice"))
811 ppd
->color_device
= !strcmp(string
, "True");
812 else if (!strcmp(keyword
, "ContoneOnly"))
813 ppd
->contone_only
= !strcmp(string
, "True");
814 else if (!strcmp(keyword
, "cupsFlipDuplex"))
815 ppd
->flip_duplex
= !strcmp(string
, "True");
816 else if (!strcmp(keyword
, "cupsManualCopies"))
817 ppd
->manual_copies
= !strcmp(string
, "True");
818 else if (!strcmp(keyword
, "cupsModelNumber"))
819 ppd
->model_number
= atoi(string
);
820 else if (!strcmp(keyword
, "cupsColorProfile"))
822 if (ppd
->num_profiles
== 0)
823 profile
= malloc(sizeof(ppd_profile_t
));
825 profile
= realloc(ppd
->profiles
, sizeof(ppd_profile_t
) *
826 (ppd
->num_profiles
+ 1));
830 cg
->ppd_status
= PPD_ALLOC_ERROR
;
835 ppd
->profiles
= profile
;
836 profile
+= ppd
->num_profiles
;
837 ppd
->num_profiles
++;
839 memset(profile
, 0, sizeof(ppd_profile_t
));
840 strlcpy(profile
->resolution
, name
, sizeof(profile
->resolution
));
841 strlcpy(profile
->media_type
, text
, sizeof(profile
->media_type
));
843 profile
->density
= (float)_cupsStrScand(string
, &sptr
, loc
);
844 profile
->gamma
= (float)_cupsStrScand(sptr
, &sptr
, loc
);
845 profile
->matrix
[0][0] = (float)_cupsStrScand(sptr
, &sptr
, loc
);
846 profile
->matrix
[0][1] = (float)_cupsStrScand(sptr
, &sptr
, loc
);
847 profile
->matrix
[0][2] = (float)_cupsStrScand(sptr
, &sptr
, loc
);
848 profile
->matrix
[1][0] = (float)_cupsStrScand(sptr
, &sptr
, loc
);
849 profile
->matrix
[1][1] = (float)_cupsStrScand(sptr
, &sptr
, loc
);
850 profile
->matrix
[1][2] = (float)_cupsStrScand(sptr
, &sptr
, loc
);
851 profile
->matrix
[2][0] = (float)_cupsStrScand(sptr
, &sptr
, loc
);
852 profile
->matrix
[2][1] = (float)_cupsStrScand(sptr
, &sptr
, loc
);
853 profile
->matrix
[2][2] = (float)_cupsStrScand(sptr
, &sptr
, loc
);
855 else if (!strcmp(keyword
, "cupsFilter"))
857 if (ppd
->num_filters
== 0)
858 filter
= malloc(sizeof(char *));
860 filter
= realloc(ppd
->filters
, sizeof(char *) * (ppd
->num_filters
+ 1));
864 cg
->ppd_status
= PPD_ALLOC_ERROR
;
869 ppd
->filters
= filter
;
870 filter
+= ppd
->num_filters
;
874 * Copy filter string and prevent it from being freed below...
880 else if (!strcmp(keyword
, "Throughput"))
881 ppd
->throughput
= atoi(string
);
882 else if (!strcmp(keyword
, "Font"))
885 * Add this font to the list of available fonts...
888 if (ppd
->num_fonts
== 0)
889 tempfonts
= (char **)malloc(sizeof(char *));
891 tempfonts
= (char **)realloc(ppd
->fonts
,
892 sizeof(char *) * (ppd
->num_fonts
+ 1));
894 if (tempfonts
== NULL
)
896 cg
->ppd_status
= PPD_ALLOC_ERROR
;
901 ppd
->fonts
= tempfonts
;
902 ppd
->fonts
[ppd
->num_fonts
] = _cupsStrAlloc(name
);
905 else if (!strncmp(keyword
, "ParamCustom", 11))
907 ppd_coption_t
*coption
; /* Custom option */
908 ppd_cparam_t
*cparam
; /* Custom parameter */
909 int corder
; /* Order number */
910 char ctype
[33], /* Data type */
911 cminimum
[65], /* Minimum value */
912 cmaximum
[65]; /* Maximum value */
916 * Get the custom option and parameter...
919 if ((coption
= ppd_get_coption(ppd
, keyword
+ 11)) == NULL
)
921 cg
->ppd_status
= PPD_ALLOC_ERROR
;
926 if ((cparam
= ppd_get_cparam(coption
, name
, text
)) == NULL
)
928 cg
->ppd_status
= PPD_ALLOC_ERROR
;
934 * Get the parameter data...
937 if (sscanf(string
, "%d%32s%64s%64s", &corder
, ctype
, cminimum
,
940 cg
->ppd_status
= PPD_BAD_CUSTOM_PARAM
;
945 cparam
->order
= corder
;
947 if (!strcmp(ctype
, "curve"))
949 cparam
->type
= PPD_CUSTOM_CURVE
;
950 cparam
->minimum
.custom_curve
= (float)_cupsStrScand(cminimum
, NULL
, loc
);
951 cparam
->maximum
.custom_curve
= (float)_cupsStrScand(cmaximum
, NULL
, loc
);
953 else if (!strcmp(ctype
, "int"))
955 cparam
->type
= PPD_CUSTOM_INT
;
956 cparam
->minimum
.custom_int
= atoi(cminimum
);
957 cparam
->maximum
.custom_int
= atoi(cmaximum
);
959 else if (!strcmp(ctype
, "invcurve"))
961 cparam
->type
= PPD_CUSTOM_INVCURVE
;
962 cparam
->minimum
.custom_invcurve
= (float)_cupsStrScand(cminimum
, NULL
, loc
);
963 cparam
->maximum
.custom_invcurve
= (float)_cupsStrScand(cmaximum
, NULL
, loc
);
965 else if (!strcmp(ctype
, "passcode"))
967 cparam
->type
= PPD_CUSTOM_PASSCODE
;
968 cparam
->minimum
.custom_passcode
= atoi(cminimum
);
969 cparam
->maximum
.custom_passcode
= atoi(cmaximum
);
971 else if (!strcmp(ctype
, "password"))
973 cparam
->type
= PPD_CUSTOM_PASSWORD
;
974 cparam
->minimum
.custom_password
= atoi(cminimum
);
975 cparam
->maximum
.custom_password
= atoi(cmaximum
);
977 else if (!strcmp(ctype
, "points"))
979 cparam
->type
= PPD_CUSTOM_POINTS
;
980 cparam
->minimum
.custom_points
= (float)_cupsStrScand(cminimum
, NULL
, loc
);
981 cparam
->maximum
.custom_points
= (float)_cupsStrScand(cmaximum
, NULL
, loc
);
983 else if (!strcmp(ctype
, "real"))
985 cparam
->type
= PPD_CUSTOM_REAL
;
986 cparam
->minimum
.custom_real
= (float)_cupsStrScand(cminimum
, NULL
, loc
);
987 cparam
->maximum
.custom_real
= (float)_cupsStrScand(cmaximum
, NULL
, loc
);
989 else if (!strcmp(ctype
, "string"))
991 cparam
->type
= PPD_CUSTOM_STRING
;
992 cparam
->minimum
.custom_string
= atoi(cminimum
);
993 cparam
->maximum
.custom_string
= atoi(cmaximum
);
997 cg
->ppd_status
= PPD_BAD_CUSTOM_PARAM
;
1003 * Now special-case for CustomPageSize...
1006 if (!strcmp(coption
->keyword
, "PageSize"))
1008 if (!strcmp(name
, "Width"))
1010 ppd
->custom_min
[0] = cparam
->minimum
.custom_points
;
1011 ppd
->custom_max
[0] = cparam
->maximum
.custom_points
;
1013 else if (!strcmp(name
, "Height"))
1015 ppd
->custom_min
[1] = cparam
->minimum
.custom_points
;
1016 ppd
->custom_max
[1] = cparam
->maximum
.custom_points
;
1020 else if (!strcmp(keyword
, "HWMargins"))
1022 for (i
= 0, sptr
= string
; i
< 4; i
++)
1023 ppd
->custom_margins
[i
] = (float)_cupsStrScand(sptr
, &sptr
, loc
);
1025 else if (!strncmp(keyword
, "Custom", 6) && !strcmp(name
, "True") && !option
)
1027 ppd_option_t
*custom_option
; /* Custom option */
1029 DEBUG_puts("Processing Custom option...");
1032 * Get the option and custom option...
1035 if (!ppd_get_coption(ppd
, keyword
+ 6))
1037 cg
->ppd_status
= PPD_ALLOC_ERROR
;
1042 if (option
&& !strcasecmp(option
->keyword
, keyword
+ 6))
1043 custom_option
= option
;
1045 custom_option
= ppdFindOption(ppd
, keyword
+ 6);
1050 * Add the "custom" option...
1053 if ((choice
= ppdFindChoice(custom_option
, "Custom")) == NULL
)
1054 if ((choice
= ppd_add_choice(custom_option
, "Custom")) == NULL
)
1056 DEBUG_puts("Unable to add Custom choice!");
1058 cg
->ppd_status
= PPD_ALLOC_ERROR
;
1063 strlcpy(choice
->text
, text
[0] ? text
: _("Custom"),
1064 sizeof(choice
->text
));
1066 choice
->code
= _cupsStrAlloc(string
);
1068 if (custom_option
->section
== PPD_ORDER_JCL
)
1069 ppd_decode(choice
->code
);
1073 * Now process custom page sizes specially...
1076 if (!strcmp(keyword
, "CustomPageSize"))
1079 * Add a "Custom" page size entry...
1082 ppd
->variable_sizes
= 1;
1084 ppd_add_size(ppd
, "Custom");
1086 if (option
&& !strcasecmp(option
->keyword
, "PageRegion"))
1087 custom_option
= option
;
1089 custom_option
= ppdFindOption(ppd
, "PageRegion");
1093 if ((choice
= ppdFindChoice(custom_option
, "Custom")) == NULL
)
1094 if ((choice
= ppd_add_choice(custom_option
, "Custom")) == NULL
)
1096 DEBUG_puts("Unable to add Custom choice!");
1098 cg
->ppd_status
= PPD_ALLOC_ERROR
;
1103 strlcpy(choice
->text
, text
[0] ? text
: _("Custom"),
1104 sizeof(choice
->text
));
1108 else if (!strcmp(keyword
, "LandscapeOrientation"))
1110 if (!strcmp(string
, "Minus90"))
1111 ppd
->landscape
= -90;
1112 else if (!strcmp(string
, "Plus90"))
1113 ppd
->landscape
= 90;
1115 else if (!strcmp(keyword
, "Emulators") && string
)
1117 for (count
= 1, sptr
= string
; sptr
!= NULL
;)
1118 if ((sptr
= strchr(sptr
, ' ')) != NULL
)
1121 while (*sptr
== ' ')
1125 ppd
->num_emulations
= count
;
1126 if ((ppd
->emulations
= calloc(count
, sizeof(ppd_emul_t
))) == NULL
)
1128 cg
->ppd_status
= PPD_ALLOC_ERROR
;
1133 for (i
= 0, sptr
= string
; i
< count
; i
++)
1135 for (nameptr
= ppd
->emulations
[i
].name
;
1136 *sptr
!= '\0' && *sptr
!= ' ';
1138 if (nameptr
< (ppd
->emulations
[i
].name
+ sizeof(ppd
->emulations
[i
].name
) - 1))
1143 while (*sptr
== ' ')
1147 else if (!strncmp(keyword
, "StartEmulator_", 14))
1151 for (i
= 0; i
< ppd
->num_emulations
; i
++)
1152 if (!strcmp(keyword
+ 14, ppd
->emulations
[i
].name
))
1154 ppd
->emulations
[i
].start
= string
;
1158 else if (!strncmp(keyword
, "StopEmulator_", 13))
1162 for (i
= 0; i
< ppd
->num_emulations
; i
++)
1163 if (!strcmp(keyword
+ 13, ppd
->emulations
[i
].name
))
1165 ppd
->emulations
[i
].stop
= string
;
1169 else if (!strcmp(keyword
, "JobPatchFile"))
1171 if (ppd
->patches
== NULL
)
1172 ppd
->patches
= _cupsStrAlloc(string
);
1175 temp
= realloc(ppd
->patches
, strlen(ppd
->patches
) +
1176 strlen(string
) + 1);
1179 cg
->ppd_status
= PPD_ALLOC_ERROR
;
1184 ppd
->patches
= temp
;
1186 strcpy(ppd
->patches
+ strlen(ppd
->patches
), string
);
1189 else if (!strcmp(keyword
, "OpenUI"))
1192 * Don't allow nesting of options...
1195 if (option
&& cg
->ppd_conform
== PPD_CONFORM_STRICT
)
1197 cg
->ppd_status
= PPD_NESTED_OPEN_UI
;
1203 * Add an option record to the current sub-group, group, or file...
1206 DEBUG_printf(("name=\"%s\" (%d)\n", name
, (int)strlen(name
)));
1209 _cups_strcpy(name
, name
+ 1); /* Eliminate leading asterisk */
1211 for (i
= (int)strlen(name
) - 1; i
> 0 && isspace(name
[i
] & 255); i
--)
1212 name
[i
] = '\0'; /* Eliminate trailing spaces */
1214 DEBUG_printf(("OpenUI of %s in group %s...\n", name
,
1215 group
? group
->text
: "(null)"));
1217 if (subgroup
!= NULL
)
1218 option
= ppd_get_option(subgroup
, name
);
1219 else if (group
== NULL
)
1221 if ((group
= ppd_get_group(ppd
, "General", _("General"), cg
,
1225 DEBUG_printf(("Adding to group %s...\n", group
->text
));
1226 option
= ppd_get_option(group
, name
);
1230 option
= ppd_get_option(group
, name
);
1234 cg
->ppd_status
= PPD_ALLOC_ERROR
;
1240 * Now fill in the initial information for the option...
1243 if (string
&& !strcmp(string
, "PickMany"))
1244 option
->ui
= PPD_UI_PICKMANY
;
1245 else if (string
&& !strcmp(string
, "Boolean"))
1246 option
->ui
= PPD_UI_BOOLEAN
;
1247 else if (string
&& !strcmp(string
, "PickOne"))
1248 option
->ui
= PPD_UI_PICKONE
;
1249 else if (cg
->ppd_conform
== PPD_CONFORM_STRICT
)
1251 cg
->ppd_status
= PPD_BAD_OPEN_UI
;
1256 option
->ui
= PPD_UI_PICKONE
;
1258 for (j
= 0; j
< ppd
->num_attrs
; j
++)
1259 if (!strncmp(ppd
->attrs
[j
]->name
, "Default", 7) &&
1260 !strcmp(ppd
->attrs
[j
]->name
+ 7, name
) &&
1261 ppd
->attrs
[j
]->value
)
1263 DEBUG_printf(("Setting Default%s to %s via attribute...\n",
1264 option
->keyword
, ppd
->attrs
[j
]->value
));
1265 strlcpy(option
->defchoice
, ppd
->attrs
[j
]->value
,
1266 sizeof(option
->defchoice
));
1271 cupsCharsetToUTF8((cups_utf8_t
*)option
->text
, text
,
1272 sizeof(option
->text
), encoding
);
1275 if (!strcmp(name
, "PageSize"))
1276 strlcpy(option
->text
, _("Media Size"), sizeof(option
->text
));
1277 else if (!strcmp(name
, "MediaType"))
1278 strlcpy(option
->text
, _("Media Type"), sizeof(option
->text
));
1279 else if (!strcmp(name
, "InputSlot"))
1280 strlcpy(option
->text
, _("Media Source"), sizeof(option
->text
));
1281 else if (!strcmp(name
, "ColorModel"))
1282 strlcpy(option
->text
, _("Output Mode"), sizeof(option
->text
));
1283 else if (!strcmp(name
, "Resolution"))
1284 strlcpy(option
->text
, _("Resolution"), sizeof(option
->text
));
1286 strlcpy(option
->text
, name
, sizeof(option
->text
));
1289 option
->section
= PPD_ORDER_ANY
;
1291 _cupsStrFree(string
);
1295 * Add a custom option choice if we have already seen a CustomFoo
1299 if (!strcasecmp(name
, "PageRegion"))
1300 strcpy(custom_name
, "CustomPageSize");
1302 snprintf(custom_name
, sizeof(custom_name
), "Custom%s", name
);
1304 if ((custom_attr
= ppdFindAttr(ppd
, custom_name
, "True")) != NULL
)
1306 if ((choice
= ppdFindChoice(option
, "Custom")) == NULL
)
1307 if ((choice
= ppd_add_choice(option
, "Custom")) == NULL
)
1309 DEBUG_puts("Unable to add Custom choice!");
1311 cg
->ppd_status
= PPD_ALLOC_ERROR
;
1316 strlcpy(choice
->text
,
1317 custom_attr
->text
[0] ? custom_attr
->text
: _("Custom"),
1318 sizeof(choice
->text
));
1319 choice
->code
= _cupsStrAlloc(custom_attr
->value
);
1322 else if (!strcmp(keyword
, "JCLOpenUI"))
1325 * Don't allow nesting of options...
1328 if (option
&& cg
->ppd_conform
== PPD_CONFORM_STRICT
)
1330 cg
->ppd_status
= PPD_NESTED_OPEN_UI
;
1336 * Find the JCL group, and add if needed...
1339 group
= ppd_get_group(ppd
, "JCL", _("JCL"), cg
, encoding
);
1345 * Add an option record to the current JCLs...
1349 _cups_strcpy(name
, name
+ 1);
1351 option
= ppd_get_option(group
, name
);
1355 cg
->ppd_status
= PPD_ALLOC_ERROR
;
1361 * Now fill in the initial information for the option...
1364 if (string
&& !strcmp(string
, "PickMany"))
1365 option
->ui
= PPD_UI_PICKMANY
;
1366 else if (string
&& !strcmp(string
, "Boolean"))
1367 option
->ui
= PPD_UI_BOOLEAN
;
1368 else if (string
&& !strcmp(string
, "PickOne"))
1369 option
->ui
= PPD_UI_PICKONE
;
1372 cg
->ppd_status
= PPD_BAD_OPEN_UI
;
1377 for (j
= 0; j
< ppd
->num_attrs
; j
++)
1378 if (!strncmp(ppd
->attrs
[j
]->name
, "Default", 7) &&
1379 !strcmp(ppd
->attrs
[j
]->name
+ 7, name
) &&
1380 ppd
->attrs
[j
]->value
)
1382 DEBUG_printf(("Setting Default%s to %s via attribute...\n",
1383 option
->keyword
, ppd
->attrs
[j
]->value
));
1384 strlcpy(option
->defchoice
, ppd
->attrs
[j
]->value
,
1385 sizeof(option
->defchoice
));
1390 cupsCharsetToUTF8((cups_utf8_t
*)option
->text
, text
,
1391 sizeof(option
->text
), encoding
);
1393 strlcpy(option
->text
, name
, sizeof(option
->text
));
1395 option
->section
= PPD_ORDER_JCL
;
1398 _cupsStrFree(string
);
1402 * Add a custom option choice if we have already seen a CustomFoo
1406 snprintf(custom_name
, sizeof(custom_name
), "Custom%s", name
);
1408 if ((custom_attr
= ppdFindAttr(ppd
, custom_name
, "True")) != NULL
)
1410 if ((choice
= ppd_add_choice(option
, "Custom")) == NULL
)
1412 DEBUG_puts("Unable to add Custom choice!");
1414 cg
->ppd_status
= PPD_ALLOC_ERROR
;
1419 strlcpy(choice
->text
,
1420 custom_attr
->text
[0] ? custom_attr
->text
: _("Custom"),
1421 sizeof(choice
->text
));
1422 choice
->code
= _cupsStrAlloc(custom_attr
->value
);
1425 else if (!strcmp(keyword
, "CloseUI") || !strcmp(keyword
, "JCLCloseUI"))
1429 _cupsStrFree(string
);
1432 else if (!strcmp(keyword
, "OpenGroup"))
1435 * Open a new group...
1440 cg
->ppd_status
= PPD_NESTED_OPEN_GROUP
;
1447 cg
->ppd_status
= PPD_BAD_OPEN_GROUP
;
1453 * Separate the group name from the text (name/text)...
1456 if ((sptr
= strchr(string
, '/')) != NULL
)
1462 * Fix up the text...
1468 * Find/add the group...
1471 group
= ppd_get_group(ppd
, string
, sptr
, cg
, encoding
);
1476 _cupsStrFree(string
);
1479 else if (!strcmp(keyword
, "CloseGroup"))
1483 _cupsStrFree(string
);
1486 else if (!strcmp(keyword
, "OrderDependency"))
1488 order
= (float)_cupsStrScand(string
, &sptr
, loc
);
1490 if (!sptr
|| sscanf(sptr
, "%40s%40s", name
, keyword
) != 2)
1492 cg
->ppd_status
= PPD_BAD_ORDER_DEPENDENCY
;
1497 if (keyword
[0] == '*')
1498 _cups_strcpy(keyword
, keyword
+ 1);
1500 if (!strcmp(name
, "ExitServer"))
1501 section
= PPD_ORDER_EXIT
;
1502 else if (!strcmp(name
, "Prolog"))
1503 section
= PPD_ORDER_PROLOG
;
1504 else if (!strcmp(name
, "DocumentSetup"))
1505 section
= PPD_ORDER_DOCUMENT
;
1506 else if (!strcmp(name
, "PageSetup"))
1507 section
= PPD_ORDER_PAGE
;
1508 else if (!strcmp(name
, "JCLSetup"))
1509 section
= PPD_ORDER_JCL
;
1511 section
= PPD_ORDER_ANY
;
1519 * Only valid for Non-UI options...
1522 for (i
= ppd
->num_groups
, gtemp
= ppd
->groups
; i
> 0; i
--, gtemp
++)
1523 if (gtemp
->text
[0] == '\0')
1527 for (i
= 0; i
< gtemp
->num_options
; i
++)
1528 if (!strcmp(keyword
, gtemp
->options
[i
].keyword
))
1530 gtemp
->options
[i
].section
= section
;
1531 gtemp
->options
[i
].order
= order
;
1537 option
->section
= section
;
1538 option
->order
= order
;
1541 _cupsStrFree(string
);
1544 else if (!strncmp(keyword
, "Default", 7))
1550 * Drop UI text, if any, from value...
1553 if (strchr(string
, '/') != NULL
)
1554 *strchr(string
, '/') = '\0';
1557 * Assign the default value as appropriate...
1560 if (!strcmp(keyword
, "DefaultColorSpace"))
1563 * Set default colorspace...
1566 if (!strcmp(string
, "CMY"))
1567 ppd
->colorspace
= PPD_CS_CMY
;
1568 else if (!strcmp(string
, "CMYK"))
1569 ppd
->colorspace
= PPD_CS_CMYK
;
1570 else if (!strcmp(string
, "RGB"))
1571 ppd
->colorspace
= PPD_CS_RGB
;
1572 else if (!strcmp(string
, "RGBK"))
1573 ppd
->colorspace
= PPD_CS_RGBK
;
1574 else if (!strcmp(string
, "N"))
1575 ppd
->colorspace
= PPD_CS_N
;
1577 ppd
->colorspace
= PPD_CS_GRAY
;
1579 else if (option
&& !strcmp(keyword
+ 7, option
->keyword
))
1582 * Set the default as part of the current option...
1585 DEBUG_printf(("Setting %s to %s...\n", keyword
, string
));
1587 strlcpy(option
->defchoice
, string
, sizeof(option
->defchoice
));
1589 DEBUG_printf(("%s is now %s...\n", keyword
, option
->defchoice
));
1594 * Lookup option and set if it has been defined...
1597 ppd_option_t
*toption
; /* Temporary option */
1600 if ((toption
= ppdFindOption(ppd
, keyword
+ 7)) != NULL
)
1602 DEBUG_printf(("Setting %s to %s...\n", keyword
, string
));
1603 strlcpy(toption
->defchoice
, string
, sizeof(toption
->defchoice
));
1607 else if (!strcmp(keyword
, "UIConstraints") ||
1608 !strcmp(keyword
, "NonUIConstraints"))
1610 if (ppd
->num_consts
== 0)
1611 constraint
= calloc(2, sizeof(ppd_const_t
));
1613 constraint
= realloc(ppd
->consts
,
1614 (ppd
->num_consts
+ 2) * sizeof(ppd_const_t
));
1616 if (constraint
== NULL
)
1618 cg
->ppd_status
= PPD_ALLOC_ERROR
;
1623 ppd
->consts
= constraint
;
1624 constraint
+= ppd
->num_consts
;
1627 switch (sscanf(string
, "%40s%40s%40s%40s", constraint
->option1
,
1628 constraint
->choice1
, constraint
->option2
,
1629 constraint
->choice2
))
1631 case 0 : /* Error */
1632 case 1 : /* Error */
1633 cg
->ppd_status
= PPD_BAD_UI_CONSTRAINTS
;
1636 case 2 : /* Two options... */
1638 * Check for broken constraints like "* Option"...
1641 if (cg
->ppd_conform
== PPD_CONFORM_STRICT
&&
1642 (!strcmp(constraint
->option1
, "*") ||
1643 !strcmp(constraint
->choice1
, "*")))
1645 cg
->ppd_status
= PPD_BAD_UI_CONSTRAINTS
;
1650 * The following strcpy's are safe, as optionN and
1651 * choiceN are all the same size (size defined by PPD spec...)
1654 if (constraint
->option1
[0] == '*')
1655 _cups_strcpy(constraint
->option1
, constraint
->option1
+ 1);
1656 else if (cg
->ppd_conform
== PPD_CONFORM_STRICT
)
1658 cg
->ppd_status
= PPD_BAD_UI_CONSTRAINTS
;
1662 if (constraint
->choice1
[0] == '*')
1663 _cups_strcpy(constraint
->option2
, constraint
->choice1
+ 1);
1664 else if (cg
->ppd_conform
== PPD_CONFORM_STRICT
)
1666 cg
->ppd_status
= PPD_BAD_UI_CONSTRAINTS
;
1670 constraint
->choice1
[0] = '\0';
1671 constraint
->choice2
[0] = '\0';
1674 case 3 : /* Two options, one choice... */
1676 * Check for broken constraints like "* Option"...
1679 if (cg
->ppd_conform
== PPD_CONFORM_STRICT
&&
1680 (!strcmp(constraint
->option1
, "*") ||
1681 !strcmp(constraint
->choice1
, "*") ||
1682 !strcmp(constraint
->option2
, "*")))
1684 cg
->ppd_status
= PPD_BAD_UI_CONSTRAINTS
;
1689 * The following _cups_strcpy's are safe, as optionN and
1690 * choiceN are all the same size (size defined by PPD spec...)
1693 if (constraint
->option1
[0] == '*')
1694 _cups_strcpy(constraint
->option1
, constraint
->option1
+ 1);
1695 else if (cg
->ppd_conform
== PPD_CONFORM_STRICT
)
1697 cg
->ppd_status
= PPD_BAD_UI_CONSTRAINTS
;
1701 if (constraint
->choice1
[0] == '*')
1703 if (cg
->ppd_conform
== PPD_CONFORM_STRICT
&&
1704 constraint
->option2
[0] == '*')
1706 cg
->ppd_status
= PPD_BAD_UI_CONSTRAINTS
;
1710 _cups_strcpy(constraint
->choice2
, constraint
->option2
);
1711 _cups_strcpy(constraint
->option2
, constraint
->choice1
+ 1);
1712 constraint
->choice1
[0] = '\0';
1716 if (constraint
->option2
[0] == '*')
1717 _cups_strcpy(constraint
->option2
, constraint
->option2
+ 1);
1718 else if (cg
->ppd_conform
== PPD_CONFORM_STRICT
)
1720 cg
->ppd_status
= PPD_BAD_UI_CONSTRAINTS
;
1724 constraint
->choice2
[0] = '\0';
1728 case 4 : /* Two options, two choices... */
1730 * Check for broken constraints like "* Option"...
1733 if (cg
->ppd_conform
== PPD_CONFORM_STRICT
&&
1734 (!strcmp(constraint
->option1
, "*") ||
1735 !strcmp(constraint
->choice1
, "*") ||
1736 !strcmp(constraint
->option2
, "*") ||
1737 !strcmp(constraint
->choice2
, "*")))
1739 cg
->ppd_status
= PPD_BAD_UI_CONSTRAINTS
;
1743 if (constraint
->option1
[0] == '*')
1744 _cups_strcpy(constraint
->option1
, constraint
->option1
+ 1);
1745 else if (cg
->ppd_conform
== PPD_CONFORM_STRICT
)
1747 cg
->ppd_status
= PPD_BAD_UI_CONSTRAINTS
;
1751 if (cg
->ppd_conform
== PPD_CONFORM_STRICT
&&
1752 constraint
->choice1
[0] == '*')
1754 cg
->ppd_status
= PPD_BAD_UI_CONSTRAINTS
;
1758 if (constraint
->option2
[0] == '*')
1759 _cups_strcpy(constraint
->option2
, constraint
->option2
+ 1);
1760 else if (cg
->ppd_conform
== PPD_CONFORM_STRICT
)
1762 cg
->ppd_status
= PPD_BAD_UI_CONSTRAINTS
;
1766 if (cg
->ppd_conform
== PPD_CONFORM_STRICT
&&
1767 constraint
->choice2
[0] == '*')
1769 cg
->ppd_status
= PPD_BAD_UI_CONSTRAINTS
;
1776 * Don't add this one as an attribute...
1779 _cupsStrFree(string
);
1782 else if (!strcmp(keyword
, "PaperDimension"))
1784 if ((size
= ppdPageSize(ppd
, name
)) == NULL
)
1785 size
= ppd_add_size(ppd
, name
);
1790 * Unable to add or find size!
1793 cg
->ppd_status
= PPD_ALLOC_ERROR
;
1798 size
->width
= (float)_cupsStrScand(string
, &sptr
, loc
);
1799 size
->length
= (float)_cupsStrScand(sptr
, NULL
, loc
);
1801 _cupsStrFree(string
);
1804 else if (!strcmp(keyword
, "ImageableArea"))
1806 if ((size
= ppdPageSize(ppd
, name
)) == NULL
)
1807 size
= ppd_add_size(ppd
, name
);
1812 * Unable to add or find size!
1815 cg
->ppd_status
= PPD_ALLOC_ERROR
;
1820 size
->left
= (float)_cupsStrScand(string
, &sptr
, loc
);
1821 size
->bottom
= (float)_cupsStrScand(sptr
, &sptr
, loc
);
1822 size
->right
= (float)_cupsStrScand(sptr
, &sptr
, loc
);
1823 size
->top
= (float)_cupsStrScand(sptr
, NULL
, loc
);
1825 _cupsStrFree(string
);
1828 else if (option
!= NULL
&&
1829 (mask
& (PPD_KEYWORD
| PPD_OPTION
| PPD_STRING
)) ==
1830 (PPD_KEYWORD
| PPD_OPTION
| PPD_STRING
) &&
1831 !strcmp(keyword
, option
->keyword
))
1833 DEBUG_printf(("group = %p, subgroup = %p\n", group
, subgroup
));
1835 if (!strcmp(keyword
, "PageSize"))
1838 * Add a page size...
1841 if (ppdPageSize(ppd
, name
) == NULL
)
1842 ppd_add_size(ppd
, name
);
1846 * Add the option choice...
1849 if ((choice
= ppd_add_choice(option
, name
)) == NULL
)
1851 cg
->ppd_status
= PPD_ALLOC_ERROR
;
1857 cupsCharsetToUTF8((cups_utf8_t
*)choice
->text
, text
,
1858 sizeof(choice
->text
), encoding
);
1859 else if (!strcmp(name
, "True"))
1860 strcpy(choice
->text
, _("Yes"));
1861 else if (!strcmp(name
, "False"))
1862 strcpy(choice
->text
, _("No"));
1864 strlcpy(choice
->text
, name
, sizeof(choice
->text
));
1866 if (option
->section
== PPD_ORDER_JCL
)
1867 ppd_decode(string
); /* Decode quoted string */
1869 choice
->code
= string
;
1870 string
= NULL
; /* Don't add as an attribute below */
1874 * Add remaining lines with keywords and string values as attributes...
1878 (mask
& (PPD_KEYWORD
| PPD_STRING
)) == (PPD_KEYWORD
| PPD_STRING
))
1879 ppd_add_attr(ppd
, keyword
, name
, text
, string
);
1881 _cupsStrFree(string
);
1888 * Reset language preferences...
1891 cupsLangFree(language
);
1894 if (!cupsFileEOF(fp
))
1895 DEBUG_printf(("Premature EOF at %lu...\n",
1896 (unsigned long)cupsFileTell(fp
)));
1899 if (cg
->ppd_status
!= PPD_OK
)
1902 * Had an error reading the PPD file, cannot continue!
1911 * Create the sorted options array and set the option back-pointer for
1912 * each choice and custom option...
1915 ppd
->options
= cupsArrayNew2((cups_array_func_t
)ppd_compare_options
, NULL
,
1916 (cups_ahash_func_t
)ppd_hash_option
,
1919 for (i
= ppd
->num_groups
, group
= ppd
->groups
;
1923 for (j
= group
->num_options
, option
= group
->options
;
1927 ppd_coption_t
*coption
; /* Custom option */
1930 cupsArrayAdd(ppd
->options
, option
);
1932 for (k
= 0; k
< option
->num_choices
; k
++)
1933 option
->choices
[k
].option
= option
;
1935 if ((coption
= ppdFindCustomOption(ppd
, option
->keyword
)) != NULL
)
1936 coption
->option
= option
;
1941 * Create an array to track the marked choices...
1944 ppd
->marked
= cupsArrayNew((cups_array_func_t
)ppd_compare_choices
, NULL
);
1947 * Return the PPD file structure...
1953 * Common exit point for errors to save code size...
1961 _cupsStrFree(string
);
1965 cupsLangFree(language
);
1972 * 'ppdOpenFd()' - Read a PPD file into memory.
1975 ppd_file_t
* /* O - PPD file record or @code NULL@ if the PPD file could not be opened. */
1976 ppdOpenFd(int fd
) /* I - File to read from */
1978 cups_file_t
*fp
; /* CUPS file pointer */
1979 ppd_file_t
*ppd
; /* PPD file record */
1980 _cups_globals_t
*cg
= _cupsGlobals();
1985 * Set the line number to 0...
1991 * Range check input...
1996 cg
->ppd_status
= PPD_NULL_FILE
;
2002 * Try to open the file and parse it...
2005 if ((fp
= cupsFileOpenFd(fd
, "r")) != NULL
)
2013 cg
->ppd_status
= PPD_FILE_OPEN_ERROR
;
2022 * 'ppdOpenFile()' - Read a PPD file into memory.
2025 ppd_file_t
* /* O - PPD file record or @code NULL@ if the PPD file could not be opened. */
2026 ppdOpenFile(const char *filename
) /* I - File to read from */
2028 cups_file_t
*fp
; /* File pointer */
2029 ppd_file_t
*ppd
; /* PPD file record */
2030 _cups_globals_t
*cg
= _cupsGlobals();
2035 * Set the line number to 0...
2041 * Range check input...
2044 if (filename
== NULL
)
2046 cg
->ppd_status
= PPD_NULL_FILE
;
2052 * Try to open the file and parse it...
2055 if ((fp
= cupsFileOpen(filename
, "r")) != NULL
)
2063 cg
->ppd_status
= PPD_FILE_OPEN_ERROR
;
2072 * 'ppdSetConformance()' - Set the conformance level for PPD files.
2074 * @since CUPS 1.1.20@
2078 ppdSetConformance(ppd_conform_t c
) /* I - Conformance level */
2080 _cups_globals_t
*cg
= _cupsGlobals();
2084 cg
->ppd_conform
= c
;
2089 * 'ppd_add_attr()' - Add an attribute to the PPD data.
2092 static ppd_attr_t
* /* O - New attribute */
2093 ppd_add_attr(ppd_file_t
*ppd
, /* I - PPD file data */
2094 const char *name
, /* I - Attribute name */
2095 const char *spec
, /* I - Specifier string, if any */
2096 const char *text
, /* I - Text string, if any */
2097 const char *value
) /* I - Value of attribute */
2099 ppd_attr_t
**ptr
, /* New array */
2100 *temp
; /* New attribute */
2104 * Range check input...
2107 if (ppd
== NULL
|| name
== NULL
|| spec
== NULL
)
2111 * Create the array as needed...
2114 if (!ppd
->sorted_attrs
)
2115 ppd
->sorted_attrs
= cupsArrayNew((cups_array_func_t
)ppd_compare_attrs
,
2119 * Allocate memory for the new attribute...
2122 if (ppd
->num_attrs
== 0)
2123 ptr
= malloc(sizeof(ppd_attr_t
*));
2125 ptr
= realloc(ppd
->attrs
, (ppd
->num_attrs
+ 1) * sizeof(ppd_attr_t
*));
2131 ptr
+= ppd
->num_attrs
;
2133 if ((temp
= calloc(1, sizeof(ppd_attr_t
))) == NULL
)
2144 strlcpy(temp
->name
, name
, sizeof(temp
->name
));
2145 strlcpy(temp
->spec
, spec
, sizeof(temp
->spec
));
2146 strlcpy(temp
->text
, text
, sizeof(temp
->text
));
2147 temp
->value
= (char *)value
;
2150 * Add the attribute to the sorted array...
2153 cupsArrayAdd(ppd
->sorted_attrs
, temp
);
2156 * Return the attribute...
2164 * 'ppd_add_choice()' - Add a choice to an option.
2167 static ppd_choice_t
* /* O - Named choice */
2168 ppd_add_choice(ppd_option_t
*option
, /* I - Option */
2169 const char *name
) /* I - Name of choice */
2171 ppd_choice_t
*choice
; /* Choice */
2174 if (option
->num_choices
== 0)
2175 choice
= malloc(sizeof(ppd_choice_t
));
2177 choice
= realloc(option
->choices
,
2178 sizeof(ppd_choice_t
) * (option
->num_choices
+ 1));
2183 option
->choices
= choice
;
2184 choice
+= option
->num_choices
;
2185 option
->num_choices
++;
2187 memset(choice
, 0, sizeof(ppd_choice_t
));
2188 strlcpy(choice
->choice
, name
, sizeof(choice
->choice
));
2195 * 'ppd_add_size()' - Add a page size.
2198 static ppd_size_t
* /* O - Named size */
2199 ppd_add_size(ppd_file_t
*ppd
, /* I - PPD file */
2200 const char *name
) /* I - Name of size */
2202 ppd_size_t
*size
; /* Size */
2205 if (ppd
->num_sizes
== 0)
2206 size
= malloc(sizeof(ppd_size_t
));
2208 size
= realloc(ppd
->sizes
, sizeof(ppd_size_t
) * (ppd
->num_sizes
+ 1));
2214 size
+= ppd
->num_sizes
;
2217 memset(size
, 0, sizeof(ppd_size_t
));
2218 strlcpy(size
->name
, name
, sizeof(size
->name
));
2225 * 'ppd_compare_attrs()' - Compare two attributes.
2228 static int /* O - Result of comparison */
2229 ppd_compare_attrs(ppd_attr_t
*a
, /* I - First attribute */
2230 ppd_attr_t
*b
) /* I - Second attribute */
2232 int ret
; /* Result of comparison */
2235 if ((ret
= strcasecmp(a
->name
, b
->name
)) != 0)
2238 return (strcasecmp(a
->spec
, b
->spec
));
2243 * 'ppd_compare_choices()' - Compare two choices...
2246 static int /* O - Result of comparison */
2247 ppd_compare_choices(ppd_choice_t
*a
, /* I - First choice */
2248 ppd_choice_t
*b
) /* I - Second choice */
2250 return (strcmp(a
->option
->keyword
, b
->option
->keyword
));
2255 * 'ppd_compare_coptions()' - Compare two custom options.
2258 static int /* O - Result of comparison */
2259 ppd_compare_coptions(ppd_coption_t
*a
, /* I - First option */
2260 ppd_coption_t
*b
) /* I - Second option */
2262 return (strcasecmp(a
->keyword
, b
->keyword
));
2267 * 'ppd_compare_cparams()' - Compare two custom parameters.
2270 static int /* O - Result of comparison */
2271 ppd_compare_cparams(ppd_cparam_t
*a
, /* I - First parameter */
2272 ppd_cparam_t
*b
) /* I - Second parameter */
2274 return (strcasecmp(a
->name
, b
->name
));
2279 * 'ppd_compare_options()' - Compare two options.
2282 static int /* O - Result of comparison */
2283 ppd_compare_options(ppd_option_t
*a
, /* I - First option */
2284 ppd_option_t
*b
) /* I - Second option */
2286 return (strcasecmp(a
->keyword
, b
->keyword
));
2291 * 'ppd_decode()' - Decode a string value...
2294 static int /* O - Length of decoded string */
2295 ppd_decode(char *string
) /* I - String to decode */
2297 char *inptr
, /* Input pointer */
2298 *outptr
; /* Output pointer */
2304 while (*inptr
!= '\0')
2305 if (*inptr
== '<' && isxdigit(inptr
[1] & 255))
2308 * Convert hex to 8-bit values...
2312 while (isxdigit(*inptr
& 255))
2314 if (isalpha(*inptr
))
2315 *outptr
= (tolower(*inptr
) - 'a' + 10) << 4;
2317 *outptr
= (*inptr
- '0') << 4;
2321 if (!isxdigit(*inptr
& 255))
2324 if (isalpha(*inptr
))
2325 *outptr
|= tolower(*inptr
) - 'a' + 10;
2327 *outptr
|= *inptr
- '0';
2333 while (*inptr
!= '>' && *inptr
!= '\0')
2335 while (*inptr
== '>')
2339 *outptr
++ = *inptr
++;
2343 return ((int)(outptr
- string
));
2348 * 'ppd_free_group()' - Free a single UI group.
2352 ppd_free_group(ppd_group_t
*group
) /* I - Group to free */
2354 int i
; /* Looping var */
2355 ppd_option_t
*option
; /* Current option */
2356 ppd_group_t
*subgroup
; /* Current sub-group */
2359 if (group
->num_options
> 0)
2361 for (i
= group
->num_options
, option
= group
->options
;
2364 ppd_free_option(option
);
2366 ppd_free(group
->options
);
2369 if (group
->num_subgroups
> 0)
2371 for (i
= group
->num_subgroups
, subgroup
= group
->subgroups
;
2374 ppd_free_group(subgroup
);
2376 ppd_free(group
->subgroups
);
2382 * 'ppd_free_option()' - Free a single option.
2386 ppd_free_option(ppd_option_t
*option
) /* I - Option to free */
2388 int i
; /* Looping var */
2389 ppd_choice_t
*choice
; /* Current choice */
2392 if (option
->num_choices
> 0)
2394 for (i
= option
->num_choices
, choice
= option
->choices
;
2398 _cupsStrFree(choice
->code
);
2401 ppd_free(option
->choices
);
2407 * 'ppd_get_coption()' - Get a custom option record.
2410 static ppd_coption_t
* /* O - Custom option... */
2411 ppd_get_coption(ppd_file_t
*ppd
, /* I - PPD file */
2412 const char *name
) /* I - Name of option */
2414 ppd_coption_t
*copt
; /* New custom option */
2418 * See if the option already exists...
2421 if ((copt
= ppdFindCustomOption(ppd
, name
)) != NULL
)
2425 * Not found, so create the custom option record...
2428 if ((copt
= calloc(1, sizeof(ppd_coption_t
))) == NULL
)
2431 strlcpy(copt
->keyword
, name
, sizeof(copt
->keyword
));
2433 copt
->params
= cupsArrayNew((cups_array_func_t
)ppd_compare_cparams
, NULL
);
2435 cupsArrayAdd(ppd
->coptions
, copt
);
2438 * Return the new record...
2446 * 'ppd_get_cparam()' - Get a custom parameter record.
2449 static ppd_cparam_t
* /* O - Extended option... */
2450 ppd_get_cparam(ppd_coption_t
*opt
, /* I - PPD file */
2451 const char *param
, /* I - Name of parameter */
2452 const char *text
) /* I - Human-readable text */
2454 ppd_cparam_t
*cparam
; /* New custom parameter */
2458 * See if the parameter already exists...
2461 if ((cparam
= ppdFindCustomParam(opt
, param
)) != NULL
)
2465 * Not found, so create the custom parameter record...
2468 if ((cparam
= calloc(1, sizeof(ppd_cparam_t
))) == NULL
)
2471 strlcpy(cparam
->name
, param
, sizeof(cparam
->name
));
2472 strlcpy(cparam
->text
, text
[0] ? text
: param
, sizeof(cparam
->text
));
2475 * Add this record to the array...
2478 cupsArrayAdd(opt
->params
, cparam
);
2481 * Return the new record...
2489 * 'ppd_get_group()' - Find or create the named group as needed.
2492 static ppd_group_t
* /* O - Named group */
2493 ppd_get_group(ppd_file_t
*ppd
, /* I - PPD file */
2494 const char *name
, /* I - Name of group */
2495 const char *text
, /* I - Text for group */
2496 _cups_globals_t
*cg
, /* I - Global data */
2497 cups_encoding_t encoding
) /* I - Encoding of text */
2499 int i
; /* Looping var */
2500 ppd_group_t
*group
; /* Group */
2503 DEBUG_printf(("ppd_get_group(ppd=%p, name=\"%s\", text=\"%s\", cg=%p)\n",
2504 ppd
, name
, text
, cg
));
2506 for (i
= ppd
->num_groups
, group
= ppd
->groups
; i
> 0; i
--, group
++)
2507 if (!strcmp(group
->name
, name
))
2512 DEBUG_printf(("Adding group %s...\n", name
));
2514 if (cg
->ppd_conform
== PPD_CONFORM_STRICT
&& strlen(text
) >= sizeof(group
->text
))
2516 cg
->ppd_status
= PPD_ILLEGAL_TRANSLATION
;
2521 if (ppd
->num_groups
== 0)
2522 group
= malloc(sizeof(ppd_group_t
));
2524 group
= realloc(ppd
->groups
,
2525 (ppd
->num_groups
+ 1) * sizeof(ppd_group_t
));
2529 cg
->ppd_status
= PPD_ALLOC_ERROR
;
2534 ppd
->groups
= group
;
2535 group
+= ppd
->num_groups
;
2538 memset(group
, 0, sizeof(ppd_group_t
));
2539 strlcpy(group
->name
, name
, sizeof(group
->name
));
2541 cupsCharsetToUTF8((cups_utf8_t
*)group
->text
, text
,
2542 sizeof(group
->text
), encoding
);
2550 * 'ppd_get_option()' - Find or create the named option as needed.
2553 static ppd_option_t
* /* O - Named option */
2554 ppd_get_option(ppd_group_t
*group
, /* I - Group */
2555 const char *name
) /* I - Name of option */
2557 int i
; /* Looping var */
2558 ppd_option_t
*option
; /* Option */
2561 DEBUG_printf(("ppd_get_option(group=%p(\"%s\"), name=\"%s\")\n",
2562 group
, group
->name
, name
));
2564 for (i
= group
->num_options
, option
= group
->options
; i
> 0; i
--, option
++)
2565 if (!strcmp(option
->keyword
, name
))
2570 if (group
->num_options
== 0)
2571 option
= malloc(sizeof(ppd_option_t
));
2573 option
= realloc(group
->options
,
2574 (group
->num_options
+ 1) * sizeof(ppd_option_t
));
2579 group
->options
= option
;
2580 option
+= group
->num_options
;
2581 group
->num_options
++;
2583 memset(option
, 0, sizeof(ppd_option_t
));
2584 strlcpy(option
->keyword
, name
, sizeof(option
->keyword
));
2592 * 'ppd_hash_option()' - Generate a hash of the option name...
2595 static int /* O - Hash index */
2596 ppd_hash_option(ppd_option_t
*option
) /* I - Option */
2598 int hash
= 0; /* Hash index */
2599 const char *k
; /* Pointer into keyword */
2602 for (hash
= option
->keyword
[0], k
= option
->keyword
+ 1; *k
;)
2603 hash
= 33 * hash
+ *k
++;
2605 return (hash
& 511);
2610 * 'ppd_read()' - Read a line from a PPD file, skipping comment lines as
2614 static int /* O - Bitmask of fields read */
2615 ppd_read(cups_file_t
*fp
, /* I - File to read from */
2616 _ppd_line_t
*line
, /* I - Line buffer */
2617 char *keyword
, /* O - Keyword from line */
2618 char *option
, /* O - Option from line */
2619 char *text
, /* O - Human-readable text from line */
2620 char **string
, /* O - Code/string data */
2621 int ignoreblank
, /* I - Ignore blank lines? */
2622 _cups_globals_t
*cg
) /* I - Global data */
2624 int ch
, /* Character from file */
2625 col
, /* Column in line */
2626 colon
, /* Colon seen? */
2627 endquote
, /* Waiting for an end quote */
2628 mask
, /* Mask to be returned */
2629 startline
, /* Start line */
2630 textlen
; /* Length of text */
2631 char *keyptr
, /* Keyword pointer */
2632 *optptr
, /* Option pointer */
2633 *textptr
, /* Text pointer */
2634 *strptr
, /* Pointer into string */
2635 *lineptr
; /* Current position in line buffer */
2639 * Now loop until we have a valid line...
2644 startline
= cg
->ppd_line
+ 1;
2648 line
->bufsize
= 1024;
2649 line
->buffer
= malloc(1024);
2661 lineptr
= line
->buffer
;
2665 while ((ch
= cupsFileGetChar(fp
)) != EOF
)
2667 if (lineptr
>= (line
->buffer
+ line
->bufsize
- 1))
2670 * Expand the line buffer...
2673 char *temp
; /* Temporary line pointer */
2676 line
->bufsize
+= 1024;
2677 if (line
->bufsize
> 262144)
2680 * Don't allow lines longer than 256k!
2683 cg
->ppd_line
= startline
;
2684 cg
->ppd_status
= PPD_LINE_TOO_LONG
;
2689 temp
= realloc(line
->buffer
, line
->bufsize
);
2692 cg
->ppd_line
= startline
;
2693 cg
->ppd_status
= PPD_LINE_TOO_LONG
;
2698 lineptr
= temp
+ (lineptr
- line
->buffer
);
2699 line
->buffer
= temp
;
2702 if (ch
== '\r' || ch
== '\n')
2705 * Line feed or carriage return...
2714 * Check for a trailing line feed...
2717 if ((ch
= cupsFilePeekChar(fp
)) == EOF
)
2724 cupsFileGetChar(fp
);
2727 if (lineptr
== line
->buffer
&& ignoreblank
)
2728 continue; /* Skip blank lines */
2732 if (!endquote
) /* Continue for multi-line text */
2737 else if (ch
< ' ' && ch
!= '\t' && cg
->ppd_conform
== PPD_CONFORM_STRICT
)
2740 * Other control characters...
2743 cg
->ppd_line
= startline
;
2744 cg
->ppd_status
= PPD_ILLEGAL_CHARACTER
;
2748 else if (ch
!= 0x1a)
2751 * Any other character...
2757 if (col
> (PPD_MAX_LINE
- 1))
2760 * Line is too long...
2763 cg
->ppd_line
= startline
;
2764 cg
->ppd_status
= PPD_LINE_TOO_LONG
;
2769 if (ch
== ':' && strncmp(line
->buffer
, "*%", 2) != 0)
2772 if (ch
== '\"' && colon
)
2773 endquote
= !endquote
;
2780 * Didn't finish this quoted string...
2783 while ((ch
= cupsFileGetChar(fp
)) != EOF
)
2786 else if (ch
== '\r' || ch
== '\n')
2794 * Check for a trailing line feed...
2797 if ((ch
= cupsFilePeekChar(fp
)) == EOF
)
2800 cupsFileGetChar(fp
);
2803 else if (ch
< ' ' && ch
!= '\t' && cg
->ppd_conform
== PPD_CONFORM_STRICT
)
2806 * Other control characters...
2809 cg
->ppd_line
= startline
;
2810 cg
->ppd_status
= PPD_ILLEGAL_CHARACTER
;
2814 else if (ch
!= 0x1a)
2818 if (col
> (PPD_MAX_LINE
- 1))
2821 * Line is too long...
2824 cg
->ppd_line
= startline
;
2825 cg
->ppd_status
= PPD_LINE_TOO_LONG
;
2835 * Didn't finish this line...
2838 while ((ch
= cupsFileGetChar(fp
)) != EOF
)
2839 if (ch
== '\r' || ch
== '\n')
2842 * Line feed or carriage return...
2851 * Check for a trailing line feed...
2854 if ((ch
= cupsFilePeekChar(fp
)) == EOF
)
2857 cupsFileGetChar(fp
);
2862 else if (ch
< ' ' && ch
!= '\t' && cg
->ppd_conform
== PPD_CONFORM_STRICT
)
2865 * Other control characters...
2868 cg
->ppd_line
= startline
;
2869 cg
->ppd_status
= PPD_ILLEGAL_CHARACTER
;
2873 else if (ch
!= 0x1a)
2877 if (col
> (PPD_MAX_LINE
- 1))
2880 * Line is too long...
2883 cg
->ppd_line
= startline
;
2884 cg
->ppd_status
= PPD_LINE_TOO_LONG
;
2891 if (lineptr
> line
->buffer
&& lineptr
[-1] == '\n')
2896 DEBUG_printf(("LINE=\"%s\"\n", line
->buffer
));
2899 * The dynamically created PPDs for older style Mac OS X
2900 * drivers include a large blob of data inserted as comments
2901 * at the end of the file. As an optimization we can stop
2902 * reading the PPD when we get to the start of this data.
2905 if (!strcmp(line
->buffer
, "*%APLWORKSET START"))
2908 if (ch
== EOF
&& lineptr
== line
->buffer
)
2916 lineptr
= line
->buffer
+ 1;
2923 if ((!line
->buffer
[0] || /* Blank line */
2924 !strncmp(line
->buffer
, "*%", 2) || /* Comment line */
2925 !strcmp(line
->buffer
, "*End")) && /* End of multi-line string */
2926 ignoreblank
) /* Ignore these? */
2928 startline
= cg
->ppd_line
+ 1;
2932 if (!strcmp(line
->buffer
, "*")) /* (Bad) comment line */
2934 if (cg
->ppd_conform
== PPD_CONFORM_RELAXED
)
2936 startline
= cg
->ppd_line
+ 1;
2941 cg
->ppd_line
= startline
;
2942 cg
->ppd_status
= PPD_ILLEGAL_MAIN_KEYWORD
;
2948 if (line
->buffer
[0] != '*') /* All lines start with an asterisk */
2951 * Allow lines consisting of just whitespace...
2954 for (lineptr
= line
->buffer
; *lineptr
; lineptr
++)
2955 if (!isspace(*lineptr
& 255))
2960 cg
->ppd_status
= PPD_MISSING_ASTERISK
;
2963 else if (ignoreblank
)
2975 while (*lineptr
!= '\0' && *lineptr
!= ':' && !isspace(*lineptr
& 255))
2977 if (*lineptr
<= ' ' || *lineptr
> 126 || *lineptr
== '/' ||
2978 (keyptr
- keyword
) >= (PPD_MAX_NAME
- 1))
2980 cg
->ppd_status
= PPD_ILLEGAL_MAIN_KEYWORD
;
2984 *keyptr
++ = *lineptr
++;
2989 if (!strcmp(keyword
, "End"))
2992 mask
|= PPD_KEYWORD
;
2994 /* DEBUG_printf(("keyword = \"%s\", lineptr = \"%s\"\n", keyword, lineptr));*/
2996 if (isspace(*lineptr
& 255))
2999 * Get an option name...
3002 while (isspace(*lineptr
& 255))
3007 while (*lineptr
!= '\0' && !isspace(*lineptr
& 255) && *lineptr
!= ':' &&
3010 if (*lineptr
<= ' ' || *lineptr
> 126 ||
3011 (optptr
- option
) >= (PPD_MAX_NAME
- 1))
3013 cg
->ppd_status
= PPD_ILLEGAL_OPTION_KEYWORD
;
3017 *optptr
++ = *lineptr
++;
3022 if (isspace(*lineptr
& 255) && cg
->ppd_conform
== PPD_CONFORM_STRICT
)
3024 cg
->ppd_status
= PPD_ILLEGAL_WHITESPACE
;
3028 while (isspace(*lineptr
& 255))
3033 /* DEBUG_printf(("option = \"%s\", lineptr = \"%s\"\n", option, lineptr));*/
3035 if (*lineptr
== '/')
3038 * Get human-readable text...
3045 while (*lineptr
!= '\0' && *lineptr
!= '\n' && *lineptr
!= ':')
3047 if (((unsigned char)*lineptr
< ' ' && *lineptr
!= '\t') ||
3048 (textptr
- text
) >= (PPD_MAX_LINE
- 1))
3050 cg
->ppd_status
= PPD_ILLEGAL_TRANSLATION
;
3054 *textptr
++ = *lineptr
++;
3058 textlen
= ppd_decode(text
);
3060 if (textlen
> PPD_MAX_TEXT
&& cg
->ppd_conform
== PPD_CONFORM_STRICT
)
3062 cg
->ppd_status
= PPD_ILLEGAL_TRANSLATION
;
3069 /* DEBUG_printf(("text = \"%s\", lineptr = \"%s\"\n", text, lineptr));*/
3072 if (isspace(*lineptr
& 255) && cg
->ppd_conform
== PPD_CONFORM_STRICT
)
3074 cg
->ppd_status
= PPD_ILLEGAL_WHITESPACE
;
3078 while (isspace(*lineptr
& 255))
3081 if (*lineptr
== ':')
3084 * Get string after triming leading and trailing whitespace...
3088 while (isspace(*lineptr
& 255))
3091 strptr
= lineptr
+ strlen(lineptr
) - 1;
3092 while (strptr
>= lineptr
&& isspace(*strptr
& 255))
3095 if (*strptr
== '\"')
3098 * Quoted string by itself, remove quotes...
3105 *string
= _cupsStrAlloc(lineptr
);
3107 /* DEBUG_printf(("string = \"%s\", lineptr = \"%s\"\n", *string, lineptr));*/
3119 * End of "$Id: ppd.c 7552 2008-05-12 17:42:15Z mike $".