2 * "$Id: ppd.c 7906 2008-09-03 20:19:43Z 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
);
591 ppd_free(line
.buffer
);
596 DEBUG_printf(("ppdOpen: keyword = %s, string = %p\n", keyword
, string
));
598 _cupsStrFree(string
);
601 * Allocate memory for the PPD file record...
604 if ((ppd
= calloc(1, sizeof(ppd_file_t
))) == NULL
)
606 cg
->ppd_status
= PPD_ALLOC_ERROR
;
608 _cupsStrFree(string
);
609 ppd_free(line
.buffer
);
614 ppd
->language_level
= 2;
615 ppd
->color_device
= 0;
616 ppd
->colorspace
= PPD_CS_N
;
617 ppd
->landscape
= -90;
618 ppd
->coptions
= cupsArrayNew((cups_array_func_t
)ppd_compare_coptions
,
622 * Get the default language for the user...
625 language
= cupsLangDefault();
629 * Read lines from the PPD file and add them to the file record...
637 encoding
= CUPS_ISO8859_1
;
639 while ((mask
= ppd_read(fp
, &line
, keyword
, name
, text
, &string
, 1, cg
)) != 0)
641 DEBUG_printf(("mask=%x, keyword=\"%s\", name=\"%s\", text=\"%s\", "
642 "string=%d chars...", mask
, keyword
, name
, text
,
643 string
? (int)strlen(string
) : 0));
645 if (strncmp(keyword
, "Default", 7) && !string
&&
646 cg
->ppd_conform
!= PPD_CONFORM_RELAXED
)
649 * Need a string value!
652 cg
->ppd_status
= PPD_MISSING_VALUE
;
658 * Certain main keywords (as defined by the PPD spec) may be used
659 * without the usual OpenUI/CloseUI stuff. Presumably this is just
660 * so that Adobe wouldn't completely break compatibility with PPD
661 * files prior to v4.0 of the spec, but it is hopelessly
662 * inconsistent... Catch these main keywords and automatically
663 * create the corresponding option, as needed...
669 * Previous line was a UI keyword...
676 if (option
== NULL
&&
677 (mask
& (PPD_KEYWORD
| PPD_OPTION
| PPD_STRING
)) ==
678 (PPD_KEYWORD
| PPD_OPTION
| PPD_STRING
))
680 for (i
= 0; i
< (int)(sizeof(ui_keywords
) / sizeof(ui_keywords
[0])); i
++)
681 if (!strcmp(keyword
, ui_keywords
[i
]))
684 if (i
< (int)(sizeof(ui_keywords
) / sizeof(ui_keywords
[0])))
687 * Create the option in the appropriate group...
692 DEBUG_printf(("**** FOUND ADOBE UI KEYWORD %s WITHOUT OPENUI!\n",
697 if ((group
= ppd_get_group(ppd
, "General", _("General"), cg
,
701 DEBUG_printf(("Adding to group %s...\n", group
->text
));
702 option
= ppd_get_option(group
, keyword
);
706 option
= ppd_get_option(group
, keyword
);
710 cg
->ppd_status
= PPD_ALLOC_ERROR
;
716 * Now fill in the initial information for the option...
719 if (!strncmp(keyword
, "JCL", 3))
720 option
->section
= PPD_ORDER_JCL
;
722 option
->section
= PPD_ORDER_ANY
;
724 option
->order
= 10.0f
;
727 option
->ui
= PPD_UI_BOOLEAN
;
729 option
->ui
= PPD_UI_PICKONE
;
731 for (j
= 0; j
< ppd
->num_attrs
; j
++)
732 if (!strncmp(ppd
->attrs
[j
]->name
, "Default", 7) &&
733 !strcmp(ppd
->attrs
[j
]->name
+ 7, keyword
) &&
734 ppd
->attrs
[j
]->value
)
736 DEBUG_printf(("Setting Default%s to %s via attribute...\n",
737 option
->keyword
, ppd
->attrs
[j
]->value
));
738 strlcpy(option
->defchoice
, ppd
->attrs
[j
]->value
,
739 sizeof(option
->defchoice
));
743 if (!strcmp(keyword
, "PageSize"))
744 strlcpy(option
->text
, _("Media Size"), sizeof(option
->text
));
745 else if (!strcmp(keyword
, "MediaType"))
746 strlcpy(option
->text
, _("Media Type"), sizeof(option
->text
));
747 else if (!strcmp(keyword
, "InputSlot"))
748 strlcpy(option
->text
, _("Media Source"), sizeof(option
->text
));
749 else if (!strcmp(keyword
, "ColorModel"))
750 strlcpy(option
->text
, _("Output Mode"), sizeof(option
->text
));
751 else if (!strcmp(keyword
, "Resolution"))
752 strlcpy(option
->text
, _("Resolution"), sizeof(option
->text
));
754 strlcpy(option
->text
, keyword
, sizeof(option
->text
));
758 if (!strcmp(keyword
, "LanguageLevel"))
759 ppd
->language_level
= atoi(string
);
760 else if (!strcmp(keyword
, "LanguageEncoding"))
763 * Say all PPD files are UTF-8, since we convert to UTF-8...
766 ppd
->lang_encoding
= _cupsStrAlloc("UTF-8");
767 encoding
= _ppdGetEncoding(string
);
769 else if (!strcmp(keyword
, "LanguageVersion"))
770 ppd
->lang_version
= string
;
771 else if (!strcmp(keyword
, "Manufacturer"))
772 ppd
->manufacturer
= string
;
773 else if (!strcmp(keyword
, "ModelName"))
774 ppd
->modelname
= string
;
775 else if (!strcmp(keyword
, "Protocols"))
776 ppd
->protocols
= string
;
777 else if (!strcmp(keyword
, "PCFileName"))
778 ppd
->pcfilename
= string
;
779 else if (!strcmp(keyword
, "NickName"))
781 if (encoding
!= CUPS_UTF8
)
783 cups_utf8_t utf8
[256]; /* UTF-8 version of NickName */
786 cupsCharsetToUTF8(utf8
, string
, sizeof(utf8
), encoding
);
787 ppd
->nickname
= _cupsStrAlloc((char *)utf8
);
790 ppd
->nickname
= _cupsStrAlloc(string
);
792 else if (!strcmp(keyword
, "Product"))
793 ppd
->product
= string
;
794 else if (!strcmp(keyword
, "ShortNickName"))
795 ppd
->shortnickname
= string
;
796 else if (!strcmp(keyword
, "TTRasterizer"))
797 ppd
->ttrasterizer
= string
;
798 else if (!strcmp(keyword
, "JCLBegin"))
800 ppd
->jcl_begin
= _cupsStrAlloc(string
);
801 ppd_decode(ppd
->jcl_begin
); /* Decode quoted string */
803 else if (!strcmp(keyword
, "JCLEnd"))
805 ppd
->jcl_end
= _cupsStrAlloc(string
);
806 ppd_decode(ppd
->jcl_end
); /* Decode quoted string */
808 else if (!strcmp(keyword
, "JCLToPSInterpreter"))
810 ppd
->jcl_ps
= _cupsStrAlloc(string
);
811 ppd_decode(ppd
->jcl_ps
); /* Decode quoted string */
813 else if (!strcmp(keyword
, "AccurateScreensSupport"))
814 ppd
->accurate_screens
= !strcmp(string
, "True");
815 else if (!strcmp(keyword
, "ColorDevice"))
816 ppd
->color_device
= !strcmp(string
, "True");
817 else if (!strcmp(keyword
, "ContoneOnly"))
818 ppd
->contone_only
= !strcmp(string
, "True");
819 else if (!strcmp(keyword
, "cupsFlipDuplex"))
820 ppd
->flip_duplex
= !strcmp(string
, "True");
821 else if (!strcmp(keyword
, "cupsManualCopies"))
822 ppd
->manual_copies
= !strcmp(string
, "True");
823 else if (!strcmp(keyword
, "cupsModelNumber"))
824 ppd
->model_number
= atoi(string
);
825 else if (!strcmp(keyword
, "cupsColorProfile"))
827 if (ppd
->num_profiles
== 0)
828 profile
= malloc(sizeof(ppd_profile_t
));
830 profile
= realloc(ppd
->profiles
, sizeof(ppd_profile_t
) *
831 (ppd
->num_profiles
+ 1));
835 cg
->ppd_status
= PPD_ALLOC_ERROR
;
840 ppd
->profiles
= profile
;
841 profile
+= ppd
->num_profiles
;
842 ppd
->num_profiles
++;
844 memset(profile
, 0, sizeof(ppd_profile_t
));
845 strlcpy(profile
->resolution
, name
, sizeof(profile
->resolution
));
846 strlcpy(profile
->media_type
, text
, sizeof(profile
->media_type
));
848 profile
->density
= (float)_cupsStrScand(string
, &sptr
, loc
);
849 profile
->gamma
= (float)_cupsStrScand(sptr
, &sptr
, loc
);
850 profile
->matrix
[0][0] = (float)_cupsStrScand(sptr
, &sptr
, loc
);
851 profile
->matrix
[0][1] = (float)_cupsStrScand(sptr
, &sptr
, loc
);
852 profile
->matrix
[0][2] = (float)_cupsStrScand(sptr
, &sptr
, loc
);
853 profile
->matrix
[1][0] = (float)_cupsStrScand(sptr
, &sptr
, loc
);
854 profile
->matrix
[1][1] = (float)_cupsStrScand(sptr
, &sptr
, loc
);
855 profile
->matrix
[1][2] = (float)_cupsStrScand(sptr
, &sptr
, loc
);
856 profile
->matrix
[2][0] = (float)_cupsStrScand(sptr
, &sptr
, loc
);
857 profile
->matrix
[2][1] = (float)_cupsStrScand(sptr
, &sptr
, loc
);
858 profile
->matrix
[2][2] = (float)_cupsStrScand(sptr
, &sptr
, loc
);
860 else if (!strcmp(keyword
, "cupsFilter"))
862 if (ppd
->num_filters
== 0)
863 filter
= malloc(sizeof(char *));
865 filter
= realloc(ppd
->filters
, sizeof(char *) * (ppd
->num_filters
+ 1));
869 cg
->ppd_status
= PPD_ALLOC_ERROR
;
874 ppd
->filters
= filter
;
875 filter
+= ppd
->num_filters
;
879 * Copy filter string and prevent it from being freed below...
885 else if (!strcmp(keyword
, "Throughput"))
886 ppd
->throughput
= atoi(string
);
887 else if (!strcmp(keyword
, "Font"))
890 * Add this font to the list of available fonts...
893 if (ppd
->num_fonts
== 0)
894 tempfonts
= (char **)malloc(sizeof(char *));
896 tempfonts
= (char **)realloc(ppd
->fonts
,
897 sizeof(char *) * (ppd
->num_fonts
+ 1));
899 if (tempfonts
== NULL
)
901 cg
->ppd_status
= PPD_ALLOC_ERROR
;
906 ppd
->fonts
= tempfonts
;
907 ppd
->fonts
[ppd
->num_fonts
] = _cupsStrAlloc(name
);
910 else if (!strncmp(keyword
, "ParamCustom", 11))
912 ppd_coption_t
*coption
; /* Custom option */
913 ppd_cparam_t
*cparam
; /* Custom parameter */
914 int corder
; /* Order number */
915 char ctype
[33], /* Data type */
916 cminimum
[65], /* Minimum value */
917 cmaximum
[65]; /* Maximum value */
921 * Get the custom option and parameter...
924 if ((coption
= ppd_get_coption(ppd
, keyword
+ 11)) == NULL
)
926 cg
->ppd_status
= PPD_ALLOC_ERROR
;
931 if ((cparam
= ppd_get_cparam(coption
, name
, text
)) == NULL
)
933 cg
->ppd_status
= PPD_ALLOC_ERROR
;
939 * Get the parameter data...
942 if (sscanf(string
, "%d%32s%64s%64s", &corder
, ctype
, cminimum
,
945 cg
->ppd_status
= PPD_BAD_CUSTOM_PARAM
;
950 cparam
->order
= corder
;
952 if (!strcmp(ctype
, "curve"))
954 cparam
->type
= PPD_CUSTOM_CURVE
;
955 cparam
->minimum
.custom_curve
= (float)_cupsStrScand(cminimum
, NULL
, loc
);
956 cparam
->maximum
.custom_curve
= (float)_cupsStrScand(cmaximum
, NULL
, loc
);
958 else if (!strcmp(ctype
, "int"))
960 cparam
->type
= PPD_CUSTOM_INT
;
961 cparam
->minimum
.custom_int
= atoi(cminimum
);
962 cparam
->maximum
.custom_int
= atoi(cmaximum
);
964 else if (!strcmp(ctype
, "invcurve"))
966 cparam
->type
= PPD_CUSTOM_INVCURVE
;
967 cparam
->minimum
.custom_invcurve
= (float)_cupsStrScand(cminimum
, NULL
, loc
);
968 cparam
->maximum
.custom_invcurve
= (float)_cupsStrScand(cmaximum
, NULL
, loc
);
970 else if (!strcmp(ctype
, "passcode"))
972 cparam
->type
= PPD_CUSTOM_PASSCODE
;
973 cparam
->minimum
.custom_passcode
= atoi(cminimum
);
974 cparam
->maximum
.custom_passcode
= atoi(cmaximum
);
976 else if (!strcmp(ctype
, "password"))
978 cparam
->type
= PPD_CUSTOM_PASSWORD
;
979 cparam
->minimum
.custom_password
= atoi(cminimum
);
980 cparam
->maximum
.custom_password
= atoi(cmaximum
);
982 else if (!strcmp(ctype
, "points"))
984 cparam
->type
= PPD_CUSTOM_POINTS
;
985 cparam
->minimum
.custom_points
= (float)_cupsStrScand(cminimum
, NULL
, loc
);
986 cparam
->maximum
.custom_points
= (float)_cupsStrScand(cmaximum
, NULL
, loc
);
988 else if (!strcmp(ctype
, "real"))
990 cparam
->type
= PPD_CUSTOM_REAL
;
991 cparam
->minimum
.custom_real
= (float)_cupsStrScand(cminimum
, NULL
, loc
);
992 cparam
->maximum
.custom_real
= (float)_cupsStrScand(cmaximum
, NULL
, loc
);
994 else if (!strcmp(ctype
, "string"))
996 cparam
->type
= PPD_CUSTOM_STRING
;
997 cparam
->minimum
.custom_string
= atoi(cminimum
);
998 cparam
->maximum
.custom_string
= atoi(cmaximum
);
1002 cg
->ppd_status
= PPD_BAD_CUSTOM_PARAM
;
1008 * Now special-case for CustomPageSize...
1011 if (!strcmp(coption
->keyword
, "PageSize"))
1013 if (!strcmp(name
, "Width"))
1015 ppd
->custom_min
[0] = cparam
->minimum
.custom_points
;
1016 ppd
->custom_max
[0] = cparam
->maximum
.custom_points
;
1018 else if (!strcmp(name
, "Height"))
1020 ppd
->custom_min
[1] = cparam
->minimum
.custom_points
;
1021 ppd
->custom_max
[1] = cparam
->maximum
.custom_points
;
1025 else if (!strcmp(keyword
, "HWMargins"))
1027 for (i
= 0, sptr
= string
; i
< 4; i
++)
1028 ppd
->custom_margins
[i
] = (float)_cupsStrScand(sptr
, &sptr
, loc
);
1030 else if (!strncmp(keyword
, "Custom", 6) && !strcmp(name
, "True") && !option
)
1032 ppd_option_t
*custom_option
; /* Custom option */
1034 DEBUG_puts("Processing Custom option...");
1037 * Get the option and custom option...
1040 if (!ppd_get_coption(ppd
, keyword
+ 6))
1042 cg
->ppd_status
= PPD_ALLOC_ERROR
;
1047 if (option
&& !strcasecmp(option
->keyword
, keyword
+ 6))
1048 custom_option
= option
;
1050 custom_option
= ppdFindOption(ppd
, keyword
+ 6);
1055 * Add the "custom" option...
1058 if ((choice
= ppdFindChoice(custom_option
, "Custom")) == NULL
)
1059 if ((choice
= ppd_add_choice(custom_option
, "Custom")) == NULL
)
1061 DEBUG_puts("Unable to add Custom choice!");
1063 cg
->ppd_status
= PPD_ALLOC_ERROR
;
1068 strlcpy(choice
->text
, text
[0] ? text
: _("Custom"),
1069 sizeof(choice
->text
));
1071 choice
->code
= _cupsStrAlloc(string
);
1073 if (custom_option
->section
== PPD_ORDER_JCL
)
1074 ppd_decode(choice
->code
);
1078 * Now process custom page sizes specially...
1081 if (!strcmp(keyword
, "CustomPageSize"))
1084 * Add a "Custom" page size entry...
1087 ppd
->variable_sizes
= 1;
1089 ppd_add_size(ppd
, "Custom");
1091 if (option
&& !strcasecmp(option
->keyword
, "PageRegion"))
1092 custom_option
= option
;
1094 custom_option
= ppdFindOption(ppd
, "PageRegion");
1098 if ((choice
= ppdFindChoice(custom_option
, "Custom")) == NULL
)
1099 if ((choice
= ppd_add_choice(custom_option
, "Custom")) == NULL
)
1101 DEBUG_puts("Unable to add Custom choice!");
1103 cg
->ppd_status
= PPD_ALLOC_ERROR
;
1108 strlcpy(choice
->text
, text
[0] ? text
: _("Custom"),
1109 sizeof(choice
->text
));
1113 else if (!strcmp(keyword
, "LandscapeOrientation"))
1115 if (!strcmp(string
, "Minus90"))
1116 ppd
->landscape
= -90;
1117 else if (!strcmp(string
, "Plus90"))
1118 ppd
->landscape
= 90;
1120 else if (!strcmp(keyword
, "Emulators") && string
)
1122 for (count
= 1, sptr
= string
; sptr
!= NULL
;)
1123 if ((sptr
= strchr(sptr
, ' ')) != NULL
)
1126 while (*sptr
== ' ')
1130 ppd
->num_emulations
= count
;
1131 if ((ppd
->emulations
= calloc(count
, sizeof(ppd_emul_t
))) == NULL
)
1133 cg
->ppd_status
= PPD_ALLOC_ERROR
;
1138 for (i
= 0, sptr
= string
; i
< count
; i
++)
1140 for (nameptr
= ppd
->emulations
[i
].name
;
1141 *sptr
!= '\0' && *sptr
!= ' ';
1143 if (nameptr
< (ppd
->emulations
[i
].name
+ sizeof(ppd
->emulations
[i
].name
) - 1))
1148 while (*sptr
== ' ')
1152 else if (!strncmp(keyword
, "StartEmulator_", 14))
1156 for (i
= 0; i
< ppd
->num_emulations
; i
++)
1157 if (!strcmp(keyword
+ 14, ppd
->emulations
[i
].name
))
1159 ppd
->emulations
[i
].start
= string
;
1163 else if (!strncmp(keyword
, "StopEmulator_", 13))
1167 for (i
= 0; i
< ppd
->num_emulations
; i
++)
1168 if (!strcmp(keyword
+ 13, ppd
->emulations
[i
].name
))
1170 ppd
->emulations
[i
].stop
= string
;
1174 else if (!strcmp(keyword
, "JobPatchFile"))
1176 if (ppd
->patches
== NULL
)
1177 ppd
->patches
= _cupsStrAlloc(string
);
1180 temp
= realloc(ppd
->patches
, strlen(ppd
->patches
) +
1181 strlen(string
) + 1);
1184 cg
->ppd_status
= PPD_ALLOC_ERROR
;
1189 ppd
->patches
= temp
;
1191 strcpy(ppd
->patches
+ strlen(ppd
->patches
), string
);
1194 else if (!strcmp(keyword
, "OpenUI"))
1197 * Don't allow nesting of options...
1200 if (option
&& cg
->ppd_conform
== PPD_CONFORM_STRICT
)
1202 cg
->ppd_status
= PPD_NESTED_OPEN_UI
;
1208 * Add an option record to the current sub-group, group, or file...
1211 DEBUG_printf(("name=\"%s\" (%d)\n", name
, (int)strlen(name
)));
1214 _cups_strcpy(name
, name
+ 1); /* Eliminate leading asterisk */
1216 for (i
= (int)strlen(name
) - 1; i
> 0 && isspace(name
[i
] & 255); i
--)
1217 name
[i
] = '\0'; /* Eliminate trailing spaces */
1219 DEBUG_printf(("OpenUI of %s in group %s...\n", name
,
1220 group
? group
->text
: "(null)"));
1222 if (subgroup
!= NULL
)
1223 option
= ppd_get_option(subgroup
, name
);
1224 else if (group
== NULL
)
1226 if ((group
= ppd_get_group(ppd
, "General", _("General"), cg
,
1230 DEBUG_printf(("Adding to group %s...\n", group
->text
));
1231 option
= ppd_get_option(group
, name
);
1235 option
= ppd_get_option(group
, name
);
1239 cg
->ppd_status
= PPD_ALLOC_ERROR
;
1245 * Now fill in the initial information for the option...
1248 if (string
&& !strcmp(string
, "PickMany"))
1249 option
->ui
= PPD_UI_PICKMANY
;
1250 else if (string
&& !strcmp(string
, "Boolean"))
1251 option
->ui
= PPD_UI_BOOLEAN
;
1252 else if (string
&& !strcmp(string
, "PickOne"))
1253 option
->ui
= PPD_UI_PICKONE
;
1254 else if (cg
->ppd_conform
== PPD_CONFORM_STRICT
)
1256 cg
->ppd_status
= PPD_BAD_OPEN_UI
;
1261 option
->ui
= PPD_UI_PICKONE
;
1263 for (j
= 0; j
< ppd
->num_attrs
; j
++)
1264 if (!strncmp(ppd
->attrs
[j
]->name
, "Default", 7) &&
1265 !strcmp(ppd
->attrs
[j
]->name
+ 7, name
) &&
1266 ppd
->attrs
[j
]->value
)
1268 DEBUG_printf(("Setting Default%s to %s via attribute...\n",
1269 option
->keyword
, ppd
->attrs
[j
]->value
));
1270 strlcpy(option
->defchoice
, ppd
->attrs
[j
]->value
,
1271 sizeof(option
->defchoice
));
1276 cupsCharsetToUTF8((cups_utf8_t
*)option
->text
, text
,
1277 sizeof(option
->text
), encoding
);
1280 if (!strcmp(name
, "PageSize"))
1281 strlcpy(option
->text
, _("Media Size"), sizeof(option
->text
));
1282 else if (!strcmp(name
, "MediaType"))
1283 strlcpy(option
->text
, _("Media Type"), sizeof(option
->text
));
1284 else if (!strcmp(name
, "InputSlot"))
1285 strlcpy(option
->text
, _("Media Source"), sizeof(option
->text
));
1286 else if (!strcmp(name
, "ColorModel"))
1287 strlcpy(option
->text
, _("Output Mode"), sizeof(option
->text
));
1288 else if (!strcmp(name
, "Resolution"))
1289 strlcpy(option
->text
, _("Resolution"), sizeof(option
->text
));
1291 strlcpy(option
->text
, name
, sizeof(option
->text
));
1294 option
->section
= PPD_ORDER_ANY
;
1296 _cupsStrFree(string
);
1300 * Add a custom option choice if we have already seen a CustomFoo
1304 if (!strcasecmp(name
, "PageRegion"))
1305 strcpy(custom_name
, "CustomPageSize");
1307 snprintf(custom_name
, sizeof(custom_name
), "Custom%s", name
);
1309 if ((custom_attr
= ppdFindAttr(ppd
, custom_name
, "True")) != NULL
)
1311 if ((choice
= ppdFindChoice(option
, "Custom")) == NULL
)
1312 if ((choice
= ppd_add_choice(option
, "Custom")) == NULL
)
1314 DEBUG_puts("Unable to add Custom choice!");
1316 cg
->ppd_status
= PPD_ALLOC_ERROR
;
1321 strlcpy(choice
->text
,
1322 custom_attr
->text
[0] ? custom_attr
->text
: _("Custom"),
1323 sizeof(choice
->text
));
1324 choice
->code
= _cupsStrAlloc(custom_attr
->value
);
1327 else if (!strcmp(keyword
, "JCLOpenUI"))
1330 * Don't allow nesting of options...
1333 if (option
&& cg
->ppd_conform
== PPD_CONFORM_STRICT
)
1335 cg
->ppd_status
= PPD_NESTED_OPEN_UI
;
1341 * Find the JCL group, and add if needed...
1344 group
= ppd_get_group(ppd
, "JCL", _("JCL"), cg
, encoding
);
1350 * Add an option record to the current JCLs...
1354 _cups_strcpy(name
, name
+ 1);
1356 option
= ppd_get_option(group
, name
);
1360 cg
->ppd_status
= PPD_ALLOC_ERROR
;
1366 * Now fill in the initial information for the option...
1369 if (string
&& !strcmp(string
, "PickMany"))
1370 option
->ui
= PPD_UI_PICKMANY
;
1371 else if (string
&& !strcmp(string
, "Boolean"))
1372 option
->ui
= PPD_UI_BOOLEAN
;
1373 else if (string
&& !strcmp(string
, "PickOne"))
1374 option
->ui
= PPD_UI_PICKONE
;
1377 cg
->ppd_status
= PPD_BAD_OPEN_UI
;
1382 for (j
= 0; j
< ppd
->num_attrs
; j
++)
1383 if (!strncmp(ppd
->attrs
[j
]->name
, "Default", 7) &&
1384 !strcmp(ppd
->attrs
[j
]->name
+ 7, name
) &&
1385 ppd
->attrs
[j
]->value
)
1387 DEBUG_printf(("Setting Default%s to %s via attribute...\n",
1388 option
->keyword
, ppd
->attrs
[j
]->value
));
1389 strlcpy(option
->defchoice
, ppd
->attrs
[j
]->value
,
1390 sizeof(option
->defchoice
));
1395 cupsCharsetToUTF8((cups_utf8_t
*)option
->text
, text
,
1396 sizeof(option
->text
), encoding
);
1398 strlcpy(option
->text
, name
, sizeof(option
->text
));
1400 option
->section
= PPD_ORDER_JCL
;
1403 _cupsStrFree(string
);
1407 * Add a custom option choice if we have already seen a CustomFoo
1411 snprintf(custom_name
, sizeof(custom_name
), "Custom%s", name
);
1413 if ((custom_attr
= ppdFindAttr(ppd
, custom_name
, "True")) != NULL
)
1415 if ((choice
= ppd_add_choice(option
, "Custom")) == NULL
)
1417 DEBUG_puts("Unable to add Custom choice!");
1419 cg
->ppd_status
= PPD_ALLOC_ERROR
;
1424 strlcpy(choice
->text
,
1425 custom_attr
->text
[0] ? custom_attr
->text
: _("Custom"),
1426 sizeof(choice
->text
));
1427 choice
->code
= _cupsStrAlloc(custom_attr
->value
);
1430 else if (!strcmp(keyword
, "CloseUI") || !strcmp(keyword
, "JCLCloseUI"))
1434 _cupsStrFree(string
);
1437 else if (!strcmp(keyword
, "OpenGroup"))
1440 * Open a new group...
1445 cg
->ppd_status
= PPD_NESTED_OPEN_GROUP
;
1452 cg
->ppd_status
= PPD_BAD_OPEN_GROUP
;
1458 * Separate the group name from the text (name/text)...
1461 if ((sptr
= strchr(string
, '/')) != NULL
)
1467 * Fix up the text...
1473 * Find/add the group...
1476 group
= ppd_get_group(ppd
, string
, sptr
, cg
, encoding
);
1481 _cupsStrFree(string
);
1484 else if (!strcmp(keyword
, "CloseGroup"))
1488 _cupsStrFree(string
);
1491 else if (!strcmp(keyword
, "OrderDependency"))
1493 order
= (float)_cupsStrScand(string
, &sptr
, loc
);
1495 if (!sptr
|| sscanf(sptr
, "%40s%40s", name
, keyword
) != 2)
1497 cg
->ppd_status
= PPD_BAD_ORDER_DEPENDENCY
;
1502 if (keyword
[0] == '*')
1503 _cups_strcpy(keyword
, keyword
+ 1);
1505 if (!strcmp(name
, "ExitServer"))
1506 section
= PPD_ORDER_EXIT
;
1507 else if (!strcmp(name
, "Prolog"))
1508 section
= PPD_ORDER_PROLOG
;
1509 else if (!strcmp(name
, "DocumentSetup"))
1510 section
= PPD_ORDER_DOCUMENT
;
1511 else if (!strcmp(name
, "PageSetup"))
1512 section
= PPD_ORDER_PAGE
;
1513 else if (!strcmp(name
, "JCLSetup"))
1514 section
= PPD_ORDER_JCL
;
1516 section
= PPD_ORDER_ANY
;
1524 * Only valid for Non-UI options...
1527 for (i
= ppd
->num_groups
, gtemp
= ppd
->groups
; i
> 0; i
--, gtemp
++)
1528 if (gtemp
->text
[0] == '\0')
1532 for (i
= 0; i
< gtemp
->num_options
; i
++)
1533 if (!strcmp(keyword
, gtemp
->options
[i
].keyword
))
1535 gtemp
->options
[i
].section
= section
;
1536 gtemp
->options
[i
].order
= order
;
1542 option
->section
= section
;
1543 option
->order
= order
;
1546 _cupsStrFree(string
);
1549 else if (!strncmp(keyword
, "Default", 7))
1555 * Drop UI text, if any, from value...
1558 if (strchr(string
, '/') != NULL
)
1559 *strchr(string
, '/') = '\0';
1562 * Assign the default value as appropriate...
1565 if (!strcmp(keyword
, "DefaultColorSpace"))
1568 * Set default colorspace...
1571 if (!strcmp(string
, "CMY"))
1572 ppd
->colorspace
= PPD_CS_CMY
;
1573 else if (!strcmp(string
, "CMYK"))
1574 ppd
->colorspace
= PPD_CS_CMYK
;
1575 else if (!strcmp(string
, "RGB"))
1576 ppd
->colorspace
= PPD_CS_RGB
;
1577 else if (!strcmp(string
, "RGBK"))
1578 ppd
->colorspace
= PPD_CS_RGBK
;
1579 else if (!strcmp(string
, "N"))
1580 ppd
->colorspace
= PPD_CS_N
;
1582 ppd
->colorspace
= PPD_CS_GRAY
;
1584 else if (option
&& !strcmp(keyword
+ 7, option
->keyword
))
1587 * Set the default as part of the current option...
1590 DEBUG_printf(("Setting %s to %s...\n", keyword
, string
));
1592 strlcpy(option
->defchoice
, string
, sizeof(option
->defchoice
));
1594 DEBUG_printf(("%s is now %s...\n", keyword
, option
->defchoice
));
1599 * Lookup option and set if it has been defined...
1602 ppd_option_t
*toption
; /* Temporary option */
1605 if ((toption
= ppdFindOption(ppd
, keyword
+ 7)) != NULL
)
1607 DEBUG_printf(("Setting %s to %s...\n", keyword
, string
));
1608 strlcpy(toption
->defchoice
, string
, sizeof(toption
->defchoice
));
1612 else if (!strcmp(keyword
, "UIConstraints") ||
1613 !strcmp(keyword
, "NonUIConstraints"))
1615 if (ppd
->num_consts
== 0)
1616 constraint
= calloc(2, sizeof(ppd_const_t
));
1618 constraint
= realloc(ppd
->consts
,
1619 (ppd
->num_consts
+ 2) * sizeof(ppd_const_t
));
1621 if (constraint
== NULL
)
1623 cg
->ppd_status
= PPD_ALLOC_ERROR
;
1628 ppd
->consts
= constraint
;
1629 constraint
+= ppd
->num_consts
;
1632 switch (sscanf(string
, "%40s%40s%40s%40s", constraint
->option1
,
1633 constraint
->choice1
, constraint
->option2
,
1634 constraint
->choice2
))
1636 case 0 : /* Error */
1637 case 1 : /* Error */
1638 cg
->ppd_status
= PPD_BAD_UI_CONSTRAINTS
;
1641 case 2 : /* Two options... */
1643 * Check for broken constraints like "* Option"...
1646 if (cg
->ppd_conform
== PPD_CONFORM_STRICT
&&
1647 (!strcmp(constraint
->option1
, "*") ||
1648 !strcmp(constraint
->choice1
, "*")))
1650 cg
->ppd_status
= PPD_BAD_UI_CONSTRAINTS
;
1655 * The following strcpy's are safe, as optionN and
1656 * choiceN are all the same size (size defined by PPD spec...)
1659 if (constraint
->option1
[0] == '*')
1660 _cups_strcpy(constraint
->option1
, constraint
->option1
+ 1);
1661 else if (cg
->ppd_conform
== PPD_CONFORM_STRICT
)
1663 cg
->ppd_status
= PPD_BAD_UI_CONSTRAINTS
;
1667 if (constraint
->choice1
[0] == '*')
1668 _cups_strcpy(constraint
->option2
, constraint
->choice1
+ 1);
1669 else if (cg
->ppd_conform
== PPD_CONFORM_STRICT
)
1671 cg
->ppd_status
= PPD_BAD_UI_CONSTRAINTS
;
1675 constraint
->choice1
[0] = '\0';
1676 constraint
->choice2
[0] = '\0';
1679 case 3 : /* Two options, one choice... */
1681 * Check for broken constraints like "* Option"...
1684 if (cg
->ppd_conform
== PPD_CONFORM_STRICT
&&
1685 (!strcmp(constraint
->option1
, "*") ||
1686 !strcmp(constraint
->choice1
, "*") ||
1687 !strcmp(constraint
->option2
, "*")))
1689 cg
->ppd_status
= PPD_BAD_UI_CONSTRAINTS
;
1694 * The following _cups_strcpy's are safe, as optionN and
1695 * choiceN are all the same size (size defined by PPD spec...)
1698 if (constraint
->option1
[0] == '*')
1699 _cups_strcpy(constraint
->option1
, constraint
->option1
+ 1);
1700 else if (cg
->ppd_conform
== PPD_CONFORM_STRICT
)
1702 cg
->ppd_status
= PPD_BAD_UI_CONSTRAINTS
;
1706 if (constraint
->choice1
[0] == '*')
1708 if (cg
->ppd_conform
== PPD_CONFORM_STRICT
&&
1709 constraint
->option2
[0] == '*')
1711 cg
->ppd_status
= PPD_BAD_UI_CONSTRAINTS
;
1715 _cups_strcpy(constraint
->choice2
, constraint
->option2
);
1716 _cups_strcpy(constraint
->option2
, constraint
->choice1
+ 1);
1717 constraint
->choice1
[0] = '\0';
1721 if (constraint
->option2
[0] == '*')
1722 _cups_strcpy(constraint
->option2
, constraint
->option2
+ 1);
1723 else if (cg
->ppd_conform
== PPD_CONFORM_STRICT
)
1725 cg
->ppd_status
= PPD_BAD_UI_CONSTRAINTS
;
1729 constraint
->choice2
[0] = '\0';
1733 case 4 : /* Two options, two choices... */
1735 * Check for broken constraints like "* Option"...
1738 if (cg
->ppd_conform
== PPD_CONFORM_STRICT
&&
1739 (!strcmp(constraint
->option1
, "*") ||
1740 !strcmp(constraint
->choice1
, "*") ||
1741 !strcmp(constraint
->option2
, "*") ||
1742 !strcmp(constraint
->choice2
, "*")))
1744 cg
->ppd_status
= PPD_BAD_UI_CONSTRAINTS
;
1748 if (constraint
->option1
[0] == '*')
1749 _cups_strcpy(constraint
->option1
, constraint
->option1
+ 1);
1750 else if (cg
->ppd_conform
== PPD_CONFORM_STRICT
)
1752 cg
->ppd_status
= PPD_BAD_UI_CONSTRAINTS
;
1756 if (cg
->ppd_conform
== PPD_CONFORM_STRICT
&&
1757 constraint
->choice1
[0] == '*')
1759 cg
->ppd_status
= PPD_BAD_UI_CONSTRAINTS
;
1763 if (constraint
->option2
[0] == '*')
1764 _cups_strcpy(constraint
->option2
, constraint
->option2
+ 1);
1765 else if (cg
->ppd_conform
== PPD_CONFORM_STRICT
)
1767 cg
->ppd_status
= PPD_BAD_UI_CONSTRAINTS
;
1771 if (cg
->ppd_conform
== PPD_CONFORM_STRICT
&&
1772 constraint
->choice2
[0] == '*')
1774 cg
->ppd_status
= PPD_BAD_UI_CONSTRAINTS
;
1781 * Don't add this one as an attribute...
1784 _cupsStrFree(string
);
1787 else if (!strcmp(keyword
, "PaperDimension"))
1789 if ((size
= ppdPageSize(ppd
, name
)) == NULL
)
1790 size
= ppd_add_size(ppd
, name
);
1795 * Unable to add or find size!
1798 cg
->ppd_status
= PPD_ALLOC_ERROR
;
1803 size
->width
= (float)_cupsStrScand(string
, &sptr
, loc
);
1804 size
->length
= (float)_cupsStrScand(sptr
, NULL
, loc
);
1806 _cupsStrFree(string
);
1809 else if (!strcmp(keyword
, "ImageableArea"))
1811 if ((size
= ppdPageSize(ppd
, name
)) == NULL
)
1812 size
= ppd_add_size(ppd
, name
);
1817 * Unable to add or find size!
1820 cg
->ppd_status
= PPD_ALLOC_ERROR
;
1825 size
->left
= (float)_cupsStrScand(string
, &sptr
, loc
);
1826 size
->bottom
= (float)_cupsStrScand(sptr
, &sptr
, loc
);
1827 size
->right
= (float)_cupsStrScand(sptr
, &sptr
, loc
);
1828 size
->top
= (float)_cupsStrScand(sptr
, NULL
, loc
);
1830 _cupsStrFree(string
);
1833 else if (option
!= NULL
&&
1834 (mask
& (PPD_KEYWORD
| PPD_OPTION
| PPD_STRING
)) ==
1835 (PPD_KEYWORD
| PPD_OPTION
| PPD_STRING
) &&
1836 !strcmp(keyword
, option
->keyword
))
1838 DEBUG_printf(("group = %p, subgroup = %p\n", group
, subgroup
));
1840 if (!strcmp(keyword
, "PageSize"))
1843 * Add a page size...
1846 if (ppdPageSize(ppd
, name
) == NULL
)
1847 ppd_add_size(ppd
, name
);
1851 * Add the option choice...
1854 if ((choice
= ppd_add_choice(option
, name
)) == NULL
)
1856 cg
->ppd_status
= PPD_ALLOC_ERROR
;
1862 cupsCharsetToUTF8((cups_utf8_t
*)choice
->text
, text
,
1863 sizeof(choice
->text
), encoding
);
1864 else if (!strcmp(name
, "True"))
1865 strcpy(choice
->text
, _("Yes"));
1866 else if (!strcmp(name
, "False"))
1867 strcpy(choice
->text
, _("No"));
1869 strlcpy(choice
->text
, name
, sizeof(choice
->text
));
1871 if (option
->section
== PPD_ORDER_JCL
)
1872 ppd_decode(string
); /* Decode quoted string */
1874 choice
->code
= string
;
1875 string
= NULL
; /* Don't add as an attribute below */
1879 * Add remaining lines with keywords and string values as attributes...
1883 (mask
& (PPD_KEYWORD
| PPD_STRING
)) == (PPD_KEYWORD
| PPD_STRING
))
1884 ppd_add_attr(ppd
, keyword
, name
, text
, string
);
1886 _cupsStrFree(string
);
1889 ppd_free(line
.buffer
);
1892 * Reset language preferences...
1895 cupsLangFree(language
);
1898 if (!cupsFileEOF(fp
))
1899 DEBUG_printf(("Premature EOF at %lu...\n",
1900 (unsigned long)cupsFileTell(fp
)));
1903 if (cg
->ppd_status
!= PPD_OK
)
1906 * Had an error reading the PPD file, cannot continue!
1915 * Create the sorted options array and set the option back-pointer for
1916 * each choice and custom option...
1919 ppd
->options
= cupsArrayNew2((cups_array_func_t
)ppd_compare_options
, NULL
,
1920 (cups_ahash_func_t
)ppd_hash_option
,
1923 for (i
= ppd
->num_groups
, group
= ppd
->groups
;
1927 for (j
= group
->num_options
, option
= group
->options
;
1931 ppd_coption_t
*coption
; /* Custom option */
1934 cupsArrayAdd(ppd
->options
, option
);
1936 for (k
= 0; k
< option
->num_choices
; k
++)
1937 option
->choices
[k
].option
= option
;
1939 if ((coption
= ppdFindCustomOption(ppd
, option
->keyword
)) != NULL
)
1940 coption
->option
= option
;
1945 * Create an array to track the marked choices...
1948 ppd
->marked
= cupsArrayNew((cups_array_func_t
)ppd_compare_choices
, NULL
);
1951 * Return the PPD file structure...
1957 * Common exit point for errors to save code size...
1962 _cupsStrFree(string
);
1963 ppd_free(line
.buffer
);
1967 cupsLangFree(language
);
1974 * 'ppdOpenFd()' - Read a PPD file into memory.
1977 ppd_file_t
* /* O - PPD file record or @code NULL@ if the PPD file could not be opened. */
1978 ppdOpenFd(int fd
) /* I - File to read from */
1980 cups_file_t
*fp
; /* CUPS file pointer */
1981 ppd_file_t
*ppd
; /* PPD file record */
1982 _cups_globals_t
*cg
= _cupsGlobals();
1987 * Set the line number to 0...
1993 * Range check input...
1998 cg
->ppd_status
= PPD_NULL_FILE
;
2004 * Try to open the file and parse it...
2007 if ((fp
= cupsFileOpenFd(fd
, "r")) != NULL
)
2015 cg
->ppd_status
= PPD_FILE_OPEN_ERROR
;
2024 * 'ppdOpenFile()' - Read a PPD file into memory.
2027 ppd_file_t
* /* O - PPD file record or @code NULL@ if the PPD file could not be opened. */
2028 ppdOpenFile(const char *filename
) /* I - File to read from */
2030 cups_file_t
*fp
; /* File pointer */
2031 ppd_file_t
*ppd
; /* PPD file record */
2032 _cups_globals_t
*cg
= _cupsGlobals();
2037 * Set the line number to 0...
2043 * Range check input...
2046 if (filename
== NULL
)
2048 cg
->ppd_status
= PPD_NULL_FILE
;
2054 * Try to open the file and parse it...
2057 if ((fp
= cupsFileOpen(filename
, "r")) != NULL
)
2065 cg
->ppd_status
= PPD_FILE_OPEN_ERROR
;
2074 * 'ppdSetConformance()' - Set the conformance level for PPD files.
2076 * @since CUPS 1.1.20@
2080 ppdSetConformance(ppd_conform_t c
) /* I - Conformance level */
2082 _cups_globals_t
*cg
= _cupsGlobals();
2086 cg
->ppd_conform
= c
;
2091 * 'ppd_add_attr()' - Add an attribute to the PPD data.
2094 static ppd_attr_t
* /* O - New attribute */
2095 ppd_add_attr(ppd_file_t
*ppd
, /* I - PPD file data */
2096 const char *name
, /* I - Attribute name */
2097 const char *spec
, /* I - Specifier string, if any */
2098 const char *text
, /* I - Text string, if any */
2099 const char *value
) /* I - Value of attribute */
2101 ppd_attr_t
**ptr
, /* New array */
2102 *temp
; /* New attribute */
2106 * Range check input...
2109 if (ppd
== NULL
|| name
== NULL
|| spec
== NULL
)
2113 * Create the array as needed...
2116 if (!ppd
->sorted_attrs
)
2117 ppd
->sorted_attrs
= cupsArrayNew((cups_array_func_t
)ppd_compare_attrs
,
2121 * Allocate memory for the new attribute...
2124 if (ppd
->num_attrs
== 0)
2125 ptr
= malloc(sizeof(ppd_attr_t
*));
2127 ptr
= realloc(ppd
->attrs
, (ppd
->num_attrs
+ 1) * sizeof(ppd_attr_t
*));
2133 ptr
+= ppd
->num_attrs
;
2135 if ((temp
= calloc(1, sizeof(ppd_attr_t
))) == NULL
)
2146 strlcpy(temp
->name
, name
, sizeof(temp
->name
));
2147 strlcpy(temp
->spec
, spec
, sizeof(temp
->spec
));
2148 strlcpy(temp
->text
, text
, sizeof(temp
->text
));
2149 temp
->value
= (char *)value
;
2152 * Add the attribute to the sorted array...
2155 cupsArrayAdd(ppd
->sorted_attrs
, temp
);
2158 * Return the attribute...
2166 * 'ppd_add_choice()' - Add a choice to an option.
2169 static ppd_choice_t
* /* O - Named choice */
2170 ppd_add_choice(ppd_option_t
*option
, /* I - Option */
2171 const char *name
) /* I - Name of choice */
2173 ppd_choice_t
*choice
; /* Choice */
2176 if (option
->num_choices
== 0)
2177 choice
= malloc(sizeof(ppd_choice_t
));
2179 choice
= realloc(option
->choices
,
2180 sizeof(ppd_choice_t
) * (option
->num_choices
+ 1));
2185 option
->choices
= choice
;
2186 choice
+= option
->num_choices
;
2187 option
->num_choices
++;
2189 memset(choice
, 0, sizeof(ppd_choice_t
));
2190 strlcpy(choice
->choice
, name
, sizeof(choice
->choice
));
2197 * 'ppd_add_size()' - Add a page size.
2200 static ppd_size_t
* /* O - Named size */
2201 ppd_add_size(ppd_file_t
*ppd
, /* I - PPD file */
2202 const char *name
) /* I - Name of size */
2204 ppd_size_t
*size
; /* Size */
2207 if (ppd
->num_sizes
== 0)
2208 size
= malloc(sizeof(ppd_size_t
));
2210 size
= realloc(ppd
->sizes
, sizeof(ppd_size_t
) * (ppd
->num_sizes
+ 1));
2216 size
+= ppd
->num_sizes
;
2219 memset(size
, 0, sizeof(ppd_size_t
));
2220 strlcpy(size
->name
, name
, sizeof(size
->name
));
2227 * 'ppd_compare_attrs()' - Compare two attributes.
2230 static int /* O - Result of comparison */
2231 ppd_compare_attrs(ppd_attr_t
*a
, /* I - First attribute */
2232 ppd_attr_t
*b
) /* I - Second attribute */
2234 int ret
; /* Result of comparison */
2237 if ((ret
= strcasecmp(a
->name
, b
->name
)) != 0)
2240 return (strcasecmp(a
->spec
, b
->spec
));
2245 * 'ppd_compare_choices()' - Compare two choices...
2248 static int /* O - Result of comparison */
2249 ppd_compare_choices(ppd_choice_t
*a
, /* I - First choice */
2250 ppd_choice_t
*b
) /* I - Second choice */
2252 return (strcmp(a
->option
->keyword
, b
->option
->keyword
));
2257 * 'ppd_compare_coptions()' - Compare two custom options.
2260 static int /* O - Result of comparison */
2261 ppd_compare_coptions(ppd_coption_t
*a
, /* I - First option */
2262 ppd_coption_t
*b
) /* I - Second option */
2264 return (strcasecmp(a
->keyword
, b
->keyword
));
2269 * 'ppd_compare_cparams()' - Compare two custom parameters.
2272 static int /* O - Result of comparison */
2273 ppd_compare_cparams(ppd_cparam_t
*a
, /* I - First parameter */
2274 ppd_cparam_t
*b
) /* I - Second parameter */
2276 return (strcasecmp(a
->name
, b
->name
));
2281 * 'ppd_compare_options()' - Compare two options.
2284 static int /* O - Result of comparison */
2285 ppd_compare_options(ppd_option_t
*a
, /* I - First option */
2286 ppd_option_t
*b
) /* I - Second option */
2288 return (strcasecmp(a
->keyword
, b
->keyword
));
2293 * 'ppd_decode()' - Decode a string value...
2296 static int /* O - Length of decoded string */
2297 ppd_decode(char *string
) /* I - String to decode */
2299 char *inptr
, /* Input pointer */
2300 *outptr
; /* Output pointer */
2306 while (*inptr
!= '\0')
2307 if (*inptr
== '<' && isxdigit(inptr
[1] & 255))
2310 * Convert hex to 8-bit values...
2314 while (isxdigit(*inptr
& 255))
2316 if (isalpha(*inptr
))
2317 *outptr
= (tolower(*inptr
) - 'a' + 10) << 4;
2319 *outptr
= (*inptr
- '0') << 4;
2323 if (!isxdigit(*inptr
& 255))
2326 if (isalpha(*inptr
))
2327 *outptr
|= tolower(*inptr
) - 'a' + 10;
2329 *outptr
|= *inptr
- '0';
2335 while (*inptr
!= '>' && *inptr
!= '\0')
2337 while (*inptr
== '>')
2341 *outptr
++ = *inptr
++;
2345 return ((int)(outptr
- string
));
2350 * 'ppd_free_group()' - Free a single UI group.
2354 ppd_free_group(ppd_group_t
*group
) /* I - Group to free */
2356 int i
; /* Looping var */
2357 ppd_option_t
*option
; /* Current option */
2358 ppd_group_t
*subgroup
; /* Current sub-group */
2361 if (group
->num_options
> 0)
2363 for (i
= group
->num_options
, option
= group
->options
;
2366 ppd_free_option(option
);
2368 ppd_free(group
->options
);
2371 if (group
->num_subgroups
> 0)
2373 for (i
= group
->num_subgroups
, subgroup
= group
->subgroups
;
2376 ppd_free_group(subgroup
);
2378 ppd_free(group
->subgroups
);
2384 * 'ppd_free_option()' - Free a single option.
2388 ppd_free_option(ppd_option_t
*option
) /* I - Option to free */
2390 int i
; /* Looping var */
2391 ppd_choice_t
*choice
; /* Current choice */
2394 if (option
->num_choices
> 0)
2396 for (i
= option
->num_choices
, choice
= option
->choices
;
2400 _cupsStrFree(choice
->code
);
2403 ppd_free(option
->choices
);
2409 * 'ppd_get_coption()' - Get a custom option record.
2412 static ppd_coption_t
* /* O - Custom option... */
2413 ppd_get_coption(ppd_file_t
*ppd
, /* I - PPD file */
2414 const char *name
) /* I - Name of option */
2416 ppd_coption_t
*copt
; /* New custom option */
2420 * See if the option already exists...
2423 if ((copt
= ppdFindCustomOption(ppd
, name
)) != NULL
)
2427 * Not found, so create the custom option record...
2430 if ((copt
= calloc(1, sizeof(ppd_coption_t
))) == NULL
)
2433 strlcpy(copt
->keyword
, name
, sizeof(copt
->keyword
));
2435 copt
->params
= cupsArrayNew((cups_array_func_t
)ppd_compare_cparams
, NULL
);
2437 cupsArrayAdd(ppd
->coptions
, copt
);
2440 * Return the new record...
2448 * 'ppd_get_cparam()' - Get a custom parameter record.
2451 static ppd_cparam_t
* /* O - Extended option... */
2452 ppd_get_cparam(ppd_coption_t
*opt
, /* I - PPD file */
2453 const char *param
, /* I - Name of parameter */
2454 const char *text
) /* I - Human-readable text */
2456 ppd_cparam_t
*cparam
; /* New custom parameter */
2460 * See if the parameter already exists...
2463 if ((cparam
= ppdFindCustomParam(opt
, param
)) != NULL
)
2467 * Not found, so create the custom parameter record...
2470 if ((cparam
= calloc(1, sizeof(ppd_cparam_t
))) == NULL
)
2473 strlcpy(cparam
->name
, param
, sizeof(cparam
->name
));
2474 strlcpy(cparam
->text
, text
[0] ? text
: param
, sizeof(cparam
->text
));
2477 * Add this record to the array...
2480 cupsArrayAdd(opt
->params
, cparam
);
2483 * Return the new record...
2491 * 'ppd_get_group()' - Find or create the named group as needed.
2494 static ppd_group_t
* /* O - Named group */
2495 ppd_get_group(ppd_file_t
*ppd
, /* I - PPD file */
2496 const char *name
, /* I - Name of group */
2497 const char *text
, /* I - Text for group */
2498 _cups_globals_t
*cg
, /* I - Global data */
2499 cups_encoding_t encoding
) /* I - Encoding of text */
2501 int i
; /* Looping var */
2502 ppd_group_t
*group
; /* Group */
2505 DEBUG_printf(("ppd_get_group(ppd=%p, name=\"%s\", text=\"%s\", cg=%p)\n",
2506 ppd
, name
, text
, cg
));
2508 for (i
= ppd
->num_groups
, group
= ppd
->groups
; i
> 0; i
--, group
++)
2509 if (!strcmp(group
->name
, name
))
2514 DEBUG_printf(("Adding group %s...\n", name
));
2516 if (cg
->ppd_conform
== PPD_CONFORM_STRICT
&& strlen(text
) >= sizeof(group
->text
))
2518 cg
->ppd_status
= PPD_ILLEGAL_TRANSLATION
;
2523 if (ppd
->num_groups
== 0)
2524 group
= malloc(sizeof(ppd_group_t
));
2526 group
= realloc(ppd
->groups
,
2527 (ppd
->num_groups
+ 1) * sizeof(ppd_group_t
));
2531 cg
->ppd_status
= PPD_ALLOC_ERROR
;
2536 ppd
->groups
= group
;
2537 group
+= ppd
->num_groups
;
2540 memset(group
, 0, sizeof(ppd_group_t
));
2541 strlcpy(group
->name
, name
, sizeof(group
->name
));
2543 cupsCharsetToUTF8((cups_utf8_t
*)group
->text
, text
,
2544 sizeof(group
->text
), encoding
);
2552 * 'ppd_get_option()' - Find or create the named option as needed.
2555 static ppd_option_t
* /* O - Named option */
2556 ppd_get_option(ppd_group_t
*group
, /* I - Group */
2557 const char *name
) /* I - Name of option */
2559 int i
; /* Looping var */
2560 ppd_option_t
*option
; /* Option */
2563 DEBUG_printf(("ppd_get_option(group=%p(\"%s\"), name=\"%s\")\n",
2564 group
, group
->name
, name
));
2566 for (i
= group
->num_options
, option
= group
->options
; i
> 0; i
--, option
++)
2567 if (!strcmp(option
->keyword
, name
))
2572 if (group
->num_options
== 0)
2573 option
= malloc(sizeof(ppd_option_t
));
2575 option
= realloc(group
->options
,
2576 (group
->num_options
+ 1) * sizeof(ppd_option_t
));
2581 group
->options
= option
;
2582 option
+= group
->num_options
;
2583 group
->num_options
++;
2585 memset(option
, 0, sizeof(ppd_option_t
));
2586 strlcpy(option
->keyword
, name
, sizeof(option
->keyword
));
2594 * 'ppd_hash_option()' - Generate a hash of the option name...
2597 static int /* O - Hash index */
2598 ppd_hash_option(ppd_option_t
*option
) /* I - Option */
2600 int hash
= 0; /* Hash index */
2601 const char *k
; /* Pointer into keyword */
2604 for (hash
= option
->keyword
[0], k
= option
->keyword
+ 1; *k
;)
2605 hash
= 33 * hash
+ *k
++;
2607 return (hash
& 511);
2612 * 'ppd_read()' - Read a line from a PPD file, skipping comment lines as
2616 static int /* O - Bitmask of fields read */
2617 ppd_read(cups_file_t
*fp
, /* I - File to read from */
2618 _ppd_line_t
*line
, /* I - Line buffer */
2619 char *keyword
, /* O - Keyword from line */
2620 char *option
, /* O - Option from line */
2621 char *text
, /* O - Human-readable text from line */
2622 char **string
, /* O - Code/string data */
2623 int ignoreblank
, /* I - Ignore blank lines? */
2624 _cups_globals_t
*cg
) /* I - Global data */
2626 int ch
, /* Character from file */
2627 col
, /* Column in line */
2628 colon
, /* Colon seen? */
2629 endquote
, /* Waiting for an end quote */
2630 mask
, /* Mask to be returned */
2631 startline
, /* Start line */
2632 textlen
; /* Length of text */
2633 char *keyptr
, /* Keyword pointer */
2634 *optptr
, /* Option pointer */
2635 *textptr
, /* Text pointer */
2636 *strptr
, /* Pointer into string */
2637 *lineptr
; /* Current position in line buffer */
2641 * Now loop until we have a valid line...
2646 startline
= cg
->ppd_line
+ 1;
2650 line
->bufsize
= 1024;
2651 line
->buffer
= malloc(1024);
2663 lineptr
= line
->buffer
;
2667 while ((ch
= cupsFileGetChar(fp
)) != EOF
)
2669 if (lineptr
>= (line
->buffer
+ line
->bufsize
- 1))
2672 * Expand the line buffer...
2675 char *temp
; /* Temporary line pointer */
2678 line
->bufsize
+= 1024;
2679 if (line
->bufsize
> 262144)
2682 * Don't allow lines longer than 256k!
2685 cg
->ppd_line
= startline
;
2686 cg
->ppd_status
= PPD_LINE_TOO_LONG
;
2691 temp
= realloc(line
->buffer
, line
->bufsize
);
2694 cg
->ppd_line
= startline
;
2695 cg
->ppd_status
= PPD_LINE_TOO_LONG
;
2700 lineptr
= temp
+ (lineptr
- line
->buffer
);
2701 line
->buffer
= temp
;
2704 if (ch
== '\r' || ch
== '\n')
2707 * Line feed or carriage return...
2716 * Check for a trailing line feed...
2719 if ((ch
= cupsFilePeekChar(fp
)) == EOF
)
2726 cupsFileGetChar(fp
);
2729 if (lineptr
== line
->buffer
&& ignoreblank
)
2730 continue; /* Skip blank lines */
2734 if (!endquote
) /* Continue for multi-line text */
2739 else if (ch
< ' ' && ch
!= '\t' && cg
->ppd_conform
== PPD_CONFORM_STRICT
)
2742 * Other control characters...
2745 cg
->ppd_line
= startline
;
2746 cg
->ppd_status
= PPD_ILLEGAL_CHARACTER
;
2750 else if (ch
!= 0x1a)
2753 * Any other character...
2759 if (col
> (PPD_MAX_LINE
- 1))
2762 * Line is too long...
2765 cg
->ppd_line
= startline
;
2766 cg
->ppd_status
= PPD_LINE_TOO_LONG
;
2771 if (ch
== ':' && strncmp(line
->buffer
, "*%", 2) != 0)
2774 if (ch
== '\"' && colon
)
2775 endquote
= !endquote
;
2782 * Didn't finish this quoted string...
2785 while ((ch
= cupsFileGetChar(fp
)) != EOF
)
2788 else if (ch
== '\r' || ch
== '\n')
2796 * Check for a trailing line feed...
2799 if ((ch
= cupsFilePeekChar(fp
)) == EOF
)
2802 cupsFileGetChar(fp
);
2805 else if (ch
< ' ' && ch
!= '\t' && cg
->ppd_conform
== PPD_CONFORM_STRICT
)
2808 * Other control characters...
2811 cg
->ppd_line
= startline
;
2812 cg
->ppd_status
= PPD_ILLEGAL_CHARACTER
;
2816 else if (ch
!= 0x1a)
2820 if (col
> (PPD_MAX_LINE
- 1))
2823 * Line is too long...
2826 cg
->ppd_line
= startline
;
2827 cg
->ppd_status
= PPD_LINE_TOO_LONG
;
2837 * Didn't finish this line...
2840 while ((ch
= cupsFileGetChar(fp
)) != EOF
)
2841 if (ch
== '\r' || ch
== '\n')
2844 * Line feed or carriage return...
2853 * Check for a trailing line feed...
2856 if ((ch
= cupsFilePeekChar(fp
)) == EOF
)
2859 cupsFileGetChar(fp
);
2864 else if (ch
< ' ' && ch
!= '\t' && cg
->ppd_conform
== PPD_CONFORM_STRICT
)
2867 * Other control characters...
2870 cg
->ppd_line
= startline
;
2871 cg
->ppd_status
= PPD_ILLEGAL_CHARACTER
;
2875 else if (ch
!= 0x1a)
2879 if (col
> (PPD_MAX_LINE
- 1))
2882 * Line is too long...
2885 cg
->ppd_line
= startline
;
2886 cg
->ppd_status
= PPD_LINE_TOO_LONG
;
2893 if (lineptr
> line
->buffer
&& lineptr
[-1] == '\n')
2898 DEBUG_printf(("LINE=\"%s\"\n", line
->buffer
));
2901 * The dynamically created PPDs for older style Mac OS X
2902 * drivers include a large blob of data inserted as comments
2903 * at the end of the file. As an optimization we can stop
2904 * reading the PPD when we get to the start of this data.
2907 if (!strcmp(line
->buffer
, "*%APLWORKSET START"))
2910 if (ch
== EOF
&& lineptr
== line
->buffer
)
2918 lineptr
= line
->buffer
+ 1;
2925 if ((!line
->buffer
[0] || /* Blank line */
2926 !strncmp(line
->buffer
, "*%", 2) || /* Comment line */
2927 !strcmp(line
->buffer
, "*End")) && /* End of multi-line string */
2928 ignoreblank
) /* Ignore these? */
2930 startline
= cg
->ppd_line
+ 1;
2934 if (!strcmp(line
->buffer
, "*")) /* (Bad) comment line */
2936 if (cg
->ppd_conform
== PPD_CONFORM_RELAXED
)
2938 startline
= cg
->ppd_line
+ 1;
2943 cg
->ppd_line
= startline
;
2944 cg
->ppd_status
= PPD_ILLEGAL_MAIN_KEYWORD
;
2950 if (line
->buffer
[0] != '*') /* All lines start with an asterisk */
2953 * Allow lines consisting of just whitespace...
2956 for (lineptr
= line
->buffer
; *lineptr
; lineptr
++)
2957 if (!isspace(*lineptr
& 255))
2962 cg
->ppd_status
= PPD_MISSING_ASTERISK
;
2965 else if (ignoreblank
)
2977 while (*lineptr
!= '\0' && *lineptr
!= ':' && !isspace(*lineptr
& 255))
2979 if (*lineptr
<= ' ' || *lineptr
> 126 || *lineptr
== '/' ||
2980 (keyptr
- keyword
) >= (PPD_MAX_NAME
- 1))
2982 cg
->ppd_status
= PPD_ILLEGAL_MAIN_KEYWORD
;
2986 *keyptr
++ = *lineptr
++;
2991 if (!strcmp(keyword
, "End"))
2994 mask
|= PPD_KEYWORD
;
2996 /* DEBUG_printf(("keyword = \"%s\", lineptr = \"%s\"\n", keyword, lineptr));*/
2998 if (isspace(*lineptr
& 255))
3001 * Get an option name...
3004 while (isspace(*lineptr
& 255))
3009 while (*lineptr
!= '\0' && !isspace(*lineptr
& 255) && *lineptr
!= ':' &&
3012 if (*lineptr
<= ' ' || *lineptr
> 126 ||
3013 (optptr
- option
) >= (PPD_MAX_NAME
- 1))
3015 cg
->ppd_status
= PPD_ILLEGAL_OPTION_KEYWORD
;
3019 *optptr
++ = *lineptr
++;
3024 if (isspace(*lineptr
& 255) && cg
->ppd_conform
== PPD_CONFORM_STRICT
)
3026 cg
->ppd_status
= PPD_ILLEGAL_WHITESPACE
;
3030 while (isspace(*lineptr
& 255))
3035 /* DEBUG_printf(("option = \"%s\", lineptr = \"%s\"\n", option, lineptr));*/
3037 if (*lineptr
== '/')
3040 * Get human-readable text...
3047 while (*lineptr
!= '\0' && *lineptr
!= '\n' && *lineptr
!= ':')
3049 if (((unsigned char)*lineptr
< ' ' && *lineptr
!= '\t') ||
3050 (textptr
- text
) >= (PPD_MAX_LINE
- 1))
3052 cg
->ppd_status
= PPD_ILLEGAL_TRANSLATION
;
3056 *textptr
++ = *lineptr
++;
3060 textlen
= ppd_decode(text
);
3062 if (textlen
> PPD_MAX_TEXT
&& cg
->ppd_conform
== PPD_CONFORM_STRICT
)
3064 cg
->ppd_status
= PPD_ILLEGAL_TRANSLATION
;
3071 /* DEBUG_printf(("text = \"%s\", lineptr = \"%s\"\n", text, lineptr));*/
3074 if (isspace(*lineptr
& 255) && cg
->ppd_conform
== PPD_CONFORM_STRICT
)
3076 cg
->ppd_status
= PPD_ILLEGAL_WHITESPACE
;
3080 while (isspace(*lineptr
& 255))
3083 if (*lineptr
== ':')
3086 * Get string after triming leading and trailing whitespace...
3090 while (isspace(*lineptr
& 255))
3093 strptr
= lineptr
+ strlen(lineptr
) - 1;
3094 while (strptr
>= lineptr
&& isspace(*strptr
& 255))
3097 if (*strptr
== '\"')
3100 * Quoted string by itself, remove quotes...
3107 *string
= _cupsStrAlloc(lineptr
);
3109 /* DEBUG_printf(("string = \"%s\", lineptr = \"%s\"\n", *string, lineptr));*/
3121 * End of "$Id: ppd.c 7906 2008-09-03 20:19:43Z mike $".