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-2009 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
);
166 _cupsStrFree(ppd
->jcl_begin
);
167 _cupsStrFree(ppd
->jcl_end
);
168 _cupsStrFree(ppd
->jcl_ps
);
171 * Free any emulations...
174 if (ppd
->num_emulations
> 0)
176 for (i
= ppd
->num_emulations
, emul
= ppd
->emulations
; i
> 0; i
--, emul
++)
178 _cupsStrFree(emul
->start
);
179 _cupsStrFree(emul
->stop
);
182 ppd_free(ppd
->emulations
);
186 * Free any UI groups, subgroups, and options...
189 if (ppd
->num_groups
> 0)
191 for (i
= ppd
->num_groups
, group
= ppd
->groups
; i
> 0; i
--, group
++)
192 ppd_free_group(group
);
194 ppd_free(ppd
->groups
);
197 cupsArrayDelete(ppd
->options
);
198 cupsArrayDelete(ppd
->marked
);
201 * Free any page sizes...
204 if (ppd
->num_sizes
> 0)
205 ppd_free(ppd
->sizes
);
208 * Free any constraints...
211 if (ppd
->num_consts
> 0)
212 ppd_free(ppd
->consts
);
215 * Free any filters...
218 if (ppd
->num_filters
> 0)
220 for (i
= ppd
->num_filters
, filter
= ppd
->filters
; i
> 0; i
--, filter
++)
221 _cupsStrFree(*filter
);
223 ppd_free(ppd
->filters
);
230 if (ppd
->num_fonts
> 0)
232 for (i
= ppd
->num_fonts
, font
= ppd
->fonts
; i
> 0; i
--, font
++)
235 ppd_free(ppd
->fonts
);
239 * Free any profiles...
242 if (ppd
->num_profiles
> 0)
243 ppd_free(ppd
->profiles
);
246 * Free any attributes...
249 if (ppd
->num_attrs
> 0)
251 for (i
= ppd
->num_attrs
, attr
= ppd
->attrs
; i
> 0; i
--, attr
++)
253 _cupsStrFree((*attr
)->value
);
257 ppd_free(ppd
->attrs
);
260 cupsArrayDelete(ppd
->sorted_attrs
);
263 * Free custom options...
266 for (coption
= (ppd_coption_t
*)cupsArrayFirst(ppd
->coptions
);
268 coption
= (ppd_coption_t
*)cupsArrayNext(ppd
->coptions
))
270 for (cparam
= (ppd_cparam_t
*)cupsArrayFirst(coption
->params
);
272 cparam
= (ppd_cparam_t
*)cupsArrayNext(coption
->params
))
274 switch (cparam
->type
)
276 case PPD_CUSTOM_PASSCODE
:
277 case PPD_CUSTOM_PASSWORD
:
278 case PPD_CUSTOM_STRING
:
279 _cupsStrFree(cparam
->current
.custom_string
);
289 cupsArrayDelete(coption
->params
);
294 cupsArrayDelete(ppd
->coptions
);
297 * Free constraints...
300 if (ppd
->cups_uiconstraints
)
302 _ppd_cups_uiconsts_t
*consts
; /* Current constraints */
305 for (consts
= (_ppd_cups_uiconsts_t
*)cupsArrayFirst(ppd
->cups_uiconstraints
);
307 consts
= (_ppd_cups_uiconsts_t
*)cupsArrayNext(ppd
->cups_uiconstraints
))
309 free(consts
->constraints
);
313 cupsArrayDelete(ppd
->cups_uiconstraints
);
317 * Free the whole record...
325 * 'ppdErrorString()' - Returns the text assocated with a status.
327 * @since CUPS 1.1.19/Mac OS X 10.3@
330 const char * /* O - Status string */
331 ppdErrorString(ppd_status_t status
) /* I - PPD status */
333 static const char * const messages
[] =/* Status messages */
336 _("Unable to open PPD file"),
337 _("NULL PPD file pointer"),
338 _("Memory allocation error"),
339 _("Missing PPD-Adobe-4.x header"),
340 _("Missing value string"),
343 _("OpenGroup without a CloseGroup first"),
344 _("Bad OpenUI/JCLOpenUI"),
345 _("OpenUI/JCLOpenUI without a CloseUI/JCLCloseUI first"),
346 _("Bad OrderDependency"),
347 _("Bad UIConstraints"),
348 _("Missing asterisk in column 1"),
349 _("Line longer than the maximum allowed (255 characters)"),
350 _("Illegal control character"),
351 _("Illegal main keyword string"),
352 _("Illegal option keyword string"),
353 _("Illegal translation string"),
354 _("Illegal whitespace character"),
355 _("Bad custom parameter"),
356 _("Missing option keyword"),
357 _("Bad value string")
361 if (status
< PPD_OK
|| status
>= PPD_MAX_STATUS
)
362 return (_cupsLangString(cupsLangDefault(), _("Unknown")));
364 return (_cupsLangString(cupsLangDefault(), messages
[status
]));
369 * '_ppdGetEncoding()' - Get the CUPS encoding value for the given
373 cups_encoding_t
/* O - CUPS encoding value */
374 _ppdGetEncoding(const char *name
) /* I - LanguageEncoding string */
376 if (!strcasecmp(name
, "ISOLatin1"))
377 return (CUPS_ISO8859_1
);
378 else if (!strcasecmp(name
, "ISOLatin2"))
379 return (CUPS_ISO8859_2
);
380 else if (!strcasecmp(name
, "ISOLatin5"))
381 return (CUPS_ISO8859_5
);
382 else if (!strcasecmp(name
, "JIS83-RKSJ"))
383 return (CUPS_JIS_X0213
);
384 else if (!strcasecmp(name
, "MacStandard"))
385 return (CUPS_MAC_ROMAN
);
386 else if (!strcasecmp(name
, "WindowsANSI"))
387 return (CUPS_WINDOWS_1252
);
394 * 'ppdLastError()' - Return the status from the last ppdOpen*().
396 * @since CUPS 1.1.19/Mac OS X 10.3@
399 ppd_status_t
/* O - Status code */
400 ppdLastError(int *line
) /* O - Line number */
402 _cups_globals_t
*cg
= _cupsGlobals();
407 *line
= cg
->ppd_line
;
409 return (cg
->ppd_status
);
414 * 'ppdOpen()' - Read a PPD file into memory.
417 ppd_file_t
* /* O - PPD file record */
418 ppdOpen(FILE *fp
) /* I - File to read from */
420 ppd_file_t
*ppd
; /* PPD file record */
421 cups_file_t
*cf
; /* CUPS file */
425 * Reopen the stdio file as a CUPS file...
428 if ((cf
= cupsFileOpenFd(fileno(fp
), "r")) == NULL
)
432 * Load the PPD file using the newer API...
438 * Close the CUPS file and return the PPD...
448 * 'ppdOpen2()' - Read a PPD file into memory.
450 * @since CUPS 1.2/Mac OS X 10.5@
453 ppd_file_t
* /* O - PPD file record or @code NULL@ if the PPD file could not be opened. */
454 ppdOpen2(cups_file_t
*fp
) /* I - File to read from */
456 int i
, j
, k
; /* Looping vars */
457 int count
; /* Temporary count */
458 _ppd_line_t line
; /* Line buffer */
459 ppd_file_t
*ppd
; /* PPD file record */
460 ppd_group_t
*group
, /* Current group */
461 *subgroup
; /* Current sub-group */
462 ppd_option_t
*option
; /* Current option */
463 ppd_choice_t
*choice
; /* Current choice */
464 ppd_const_t
*constraint
; /* Current constraint */
465 ppd_size_t
*size
; /* Current page size */
466 int mask
; /* Line data mask */
467 char keyword
[PPD_MAX_NAME
],
468 /* Keyword from file */
470 /* Option from file */
472 /* Human-readable text from file */
473 *string
, /* Code/text from file */
474 *sptr
, /* Pointer into string */
475 *nameptr
, /* Pointer into name */
476 *temp
, /* Temporary string pointer */
477 **tempfonts
; /* Temporary fonts pointer */
478 float order
; /* Order dependency number */
479 ppd_section_t section
; /* Order dependency section */
480 ppd_profile_t
*profile
; /* Pointer to color profile */
481 char **filter
; /* Pointer to filter */
482 cups_lang_t
*language
; /* Default language */
483 struct lconv
*loc
; /* Locale data */
484 int ui_keyword
; /* Is this line a UI keyword? */
485 cups_encoding_t encoding
; /* Encoding of PPD file */
486 _cups_globals_t
*cg
= _cupsGlobals();
488 char custom_name
[PPD_MAX_NAME
];
489 /* CustomFoo attribute name */
490 ppd_attr_t
*custom_attr
; /* CustomFoo attribute */
491 static const char * const ui_keywords
[] =
493 #ifdef CUPS_USE_FULL_UI_KEYWORDS_LIST
495 * Adobe defines some 41 keywords as "UI", meaning that they are
496 * user interface elements and that they should be treated as such
497 * even if the PPD creator doesn't use Open/CloseUI around them.
499 * Since this can cause previously invisible options to appear and
500 * confuse users, the default is to only treat the PageSize and
501 * PageRegion keywords this way.
503 /* Boolean keywords */
513 /* PickOne keywords */
526 "JCLFrameBufferSize",
547 #else /* !CUPS_USE_FULL_UI_KEYWORDS_LIST */
550 #endif /* CUPS_USE_FULL_UI_KEYWORDS_LIST */
554 DEBUG_printf(("ppdOpen2(fp=%p)", fp
));
557 * Default to "OK" status...
560 cg
->ppd_status
= PPD_OK
;
564 * Range check input...
569 cg
->ppd_status
= PPD_NULL_FILE
;
574 * Grab the first line and make sure it reads '*PPD-Adobe: "major.minor"'...
580 mask
= ppd_read(fp
, &line
, keyword
, name
, text
, &string
, 0, cg
);
582 DEBUG_printf(("2ppdOpen2: mask=%x, keyword=\"%s\"...", mask
, keyword
));
585 strcmp(keyword
, "PPD-Adobe") ||
586 string
== NULL
|| string
[0] != '4')
589 * Either this is not a PPD file, or it is not a 4.x PPD file.
592 if (cg
->ppd_status
== PPD_OK
)
593 cg
->ppd_status
= PPD_MISSING_PPDADOBE4
;
595 _cupsStrFree(string
);
596 ppd_free(line
.buffer
);
601 DEBUG_printf(("2ppdOpen2: keyword=%s, string=%p", keyword
, string
));
603 _cupsStrFree(string
);
606 * Allocate memory for the PPD file record...
609 if ((ppd
= calloc(1, sizeof(ppd_file_t
))) == NULL
)
611 cg
->ppd_status
= PPD_ALLOC_ERROR
;
613 _cupsStrFree(string
);
614 ppd_free(line
.buffer
);
619 ppd
->language_level
= 2;
620 ppd
->color_device
= 0;
621 ppd
->colorspace
= PPD_CS_N
;
622 ppd
->landscape
= -90;
623 ppd
->coptions
= cupsArrayNew((cups_array_func_t
)ppd_compare_coptions
,
627 * Get the default language for the user...
630 language
= cupsLangDefault();
634 * Read lines from the PPD file and add them to the file record...
642 encoding
= CUPS_ISO8859_1
;
644 while ((mask
= ppd_read(fp
, &line
, keyword
, name
, text
, &string
, 1, cg
)) != 0)
646 DEBUG_printf(("2ppdOpen2: mask=%x, keyword=\"%s\", name=\"%s\", "
647 "text=\"%s\", string=%d chars...", mask
, keyword
, name
, text
,
648 string
? (int)strlen(string
) : 0));
650 if (strncmp(keyword
, "Default", 7) && !string
&&
651 cg
->ppd_conform
!= PPD_CONFORM_RELAXED
)
654 * Need a string value!
657 cg
->ppd_status
= PPD_MISSING_VALUE
;
663 * Certain main keywords (as defined by the PPD spec) may be used
664 * without the usual OpenUI/CloseUI stuff. Presumably this is just
665 * so that Adobe wouldn't completely break compatibility with PPD
666 * files prior to v4.0 of the spec, but it is hopelessly
667 * inconsistent... Catch these main keywords and automatically
668 * create the corresponding option, as needed...
674 * Previous line was a UI keyword...
681 if (option
== NULL
&&
682 (mask
& (PPD_KEYWORD
| PPD_OPTION
| PPD_STRING
)) ==
683 (PPD_KEYWORD
| PPD_OPTION
| PPD_STRING
))
685 for (i
= 0; i
< (int)(sizeof(ui_keywords
) / sizeof(ui_keywords
[0])); i
++)
686 if (!strcmp(keyword
, ui_keywords
[i
]))
689 if (i
< (int)(sizeof(ui_keywords
) / sizeof(ui_keywords
[0])))
692 * Create the option in the appropriate group...
697 DEBUG_printf(("2ppdOpen2: FOUND ADOBE UI KEYWORD %s WITHOUT OPENUI!",
702 if ((group
= ppd_get_group(ppd
, "General", _("General"), cg
,
706 DEBUG_printf(("2ppdOpen2: Adding to group %s...", group
->text
));
707 option
= ppd_get_option(group
, keyword
);
711 option
= ppd_get_option(group
, keyword
);
715 cg
->ppd_status
= PPD_ALLOC_ERROR
;
721 * Now fill in the initial information for the option...
724 if (!strncmp(keyword
, "JCL", 3))
725 option
->section
= PPD_ORDER_JCL
;
727 option
->section
= PPD_ORDER_ANY
;
729 option
->order
= 10.0f
;
732 option
->ui
= PPD_UI_BOOLEAN
;
734 option
->ui
= PPD_UI_PICKONE
;
736 for (j
= 0; j
< ppd
->num_attrs
; j
++)
737 if (!strncmp(ppd
->attrs
[j
]->name
, "Default", 7) &&
738 !strcmp(ppd
->attrs
[j
]->name
+ 7, keyword
) &&
739 ppd
->attrs
[j
]->value
)
741 DEBUG_printf(("2ppdOpen2: Setting Default%s to %s via attribute...",
742 option
->keyword
, ppd
->attrs
[j
]->value
));
743 strlcpy(option
->defchoice
, ppd
->attrs
[j
]->value
,
744 sizeof(option
->defchoice
));
748 if (!strcmp(keyword
, "PageSize"))
749 strlcpy(option
->text
, _("Media Size"), sizeof(option
->text
));
750 else if (!strcmp(keyword
, "MediaType"))
751 strlcpy(option
->text
, _("Media Type"), sizeof(option
->text
));
752 else if (!strcmp(keyword
, "InputSlot"))
753 strlcpy(option
->text
, _("Media Source"), sizeof(option
->text
));
754 else if (!strcmp(keyword
, "ColorModel"))
755 strlcpy(option
->text
, _("Output Mode"), sizeof(option
->text
));
756 else if (!strcmp(keyword
, "Resolution"))
757 strlcpy(option
->text
, _("Resolution"), sizeof(option
->text
));
759 strlcpy(option
->text
, keyword
, sizeof(option
->text
));
763 if (!strcmp(keyword
, "LanguageLevel"))
764 ppd
->language_level
= atoi(string
);
765 else if (!strcmp(keyword
, "LanguageEncoding"))
768 * Say all PPD files are UTF-8, since we convert to UTF-8...
771 ppd
->lang_encoding
= _cupsStrAlloc("UTF-8");
772 encoding
= _ppdGetEncoding(string
);
774 else if (!strcmp(keyword
, "LanguageVersion"))
775 ppd
->lang_version
= string
;
776 else if (!strcmp(keyword
, "Manufacturer"))
777 ppd
->manufacturer
= string
;
778 else if (!strcmp(keyword
, "ModelName"))
779 ppd
->modelname
= string
;
780 else if (!strcmp(keyword
, "Protocols"))
781 ppd
->protocols
= string
;
782 else if (!strcmp(keyword
, "PCFileName"))
783 ppd
->pcfilename
= string
;
784 else if (!strcmp(keyword
, "NickName"))
786 if (encoding
!= CUPS_UTF8
)
788 cups_utf8_t utf8
[256]; /* UTF-8 version of NickName */
791 cupsCharsetToUTF8(utf8
, string
, sizeof(utf8
), encoding
);
792 ppd
->nickname
= _cupsStrAlloc((char *)utf8
);
795 ppd
->nickname
= _cupsStrAlloc(string
);
797 else if (!strcmp(keyword
, "Product"))
798 ppd
->product
= string
;
799 else if (!strcmp(keyword
, "ShortNickName"))
800 ppd
->shortnickname
= string
;
801 else if (!strcmp(keyword
, "TTRasterizer"))
802 ppd
->ttrasterizer
= string
;
803 else if (!strcmp(keyword
, "JCLBegin"))
805 ppd
->jcl_begin
= _cupsStrAlloc(string
);
806 ppd_decode(ppd
->jcl_begin
); /* Decode quoted string */
808 else if (!strcmp(keyword
, "JCLEnd"))
810 ppd
->jcl_end
= _cupsStrAlloc(string
);
811 ppd_decode(ppd
->jcl_end
); /* Decode quoted string */
813 else if (!strcmp(keyword
, "JCLToPSInterpreter"))
815 ppd
->jcl_ps
= _cupsStrAlloc(string
);
816 ppd_decode(ppd
->jcl_ps
); /* Decode quoted string */
818 else if (!strcmp(keyword
, "AccurateScreensSupport"))
819 ppd
->accurate_screens
= !strcmp(string
, "True");
820 else if (!strcmp(keyword
, "ColorDevice"))
821 ppd
->color_device
= !strcmp(string
, "True");
822 else if (!strcmp(keyword
, "ContoneOnly"))
823 ppd
->contone_only
= !strcmp(string
, "True");
824 else if (!strcmp(keyword
, "cupsFlipDuplex"))
825 ppd
->flip_duplex
= !strcmp(string
, "True");
826 else if (!strcmp(keyword
, "cupsManualCopies"))
827 ppd
->manual_copies
= !strcmp(string
, "True");
828 else if (!strcmp(keyword
, "cupsModelNumber"))
829 ppd
->model_number
= atoi(string
);
830 else if (!strcmp(keyword
, "cupsColorProfile"))
832 if (ppd
->num_profiles
== 0)
833 profile
= malloc(sizeof(ppd_profile_t
));
835 profile
= realloc(ppd
->profiles
, sizeof(ppd_profile_t
) *
836 (ppd
->num_profiles
+ 1));
840 cg
->ppd_status
= PPD_ALLOC_ERROR
;
845 ppd
->profiles
= profile
;
846 profile
+= ppd
->num_profiles
;
847 ppd
->num_profiles
++;
849 memset(profile
, 0, sizeof(ppd_profile_t
));
850 strlcpy(profile
->resolution
, name
, sizeof(profile
->resolution
));
851 strlcpy(profile
->media_type
, text
, sizeof(profile
->media_type
));
853 profile
->density
= (float)_cupsStrScand(string
, &sptr
, loc
);
854 profile
->gamma
= (float)_cupsStrScand(sptr
, &sptr
, loc
);
855 profile
->matrix
[0][0] = (float)_cupsStrScand(sptr
, &sptr
, loc
);
856 profile
->matrix
[0][1] = (float)_cupsStrScand(sptr
, &sptr
, loc
);
857 profile
->matrix
[0][2] = (float)_cupsStrScand(sptr
, &sptr
, loc
);
858 profile
->matrix
[1][0] = (float)_cupsStrScand(sptr
, &sptr
, loc
);
859 profile
->matrix
[1][1] = (float)_cupsStrScand(sptr
, &sptr
, loc
);
860 profile
->matrix
[1][2] = (float)_cupsStrScand(sptr
, &sptr
, loc
);
861 profile
->matrix
[2][0] = (float)_cupsStrScand(sptr
, &sptr
, loc
);
862 profile
->matrix
[2][1] = (float)_cupsStrScand(sptr
, &sptr
, loc
);
863 profile
->matrix
[2][2] = (float)_cupsStrScand(sptr
, &sptr
, loc
);
865 else if (!strcmp(keyword
, "cupsFilter"))
867 if (ppd
->num_filters
== 0)
868 filter
= malloc(sizeof(char *));
870 filter
= realloc(ppd
->filters
, sizeof(char *) * (ppd
->num_filters
+ 1));
874 cg
->ppd_status
= PPD_ALLOC_ERROR
;
879 ppd
->filters
= filter
;
880 filter
+= ppd
->num_filters
;
884 * Copy filter string and prevent it from being freed below...
890 else if (!strcmp(keyword
, "Throughput"))
891 ppd
->throughput
= atoi(string
);
892 else if (!strcmp(keyword
, "Font"))
895 * Add this font to the list of available fonts...
898 if (ppd
->num_fonts
== 0)
899 tempfonts
= (char **)malloc(sizeof(char *));
901 tempfonts
= (char **)realloc(ppd
->fonts
,
902 sizeof(char *) * (ppd
->num_fonts
+ 1));
904 if (tempfonts
== NULL
)
906 cg
->ppd_status
= PPD_ALLOC_ERROR
;
911 ppd
->fonts
= tempfonts
;
912 ppd
->fonts
[ppd
->num_fonts
] = _cupsStrAlloc(name
);
915 else if (!strncmp(keyword
, "ParamCustom", 11))
917 ppd_coption_t
*coption
; /* Custom option */
918 ppd_cparam_t
*cparam
; /* Custom parameter */
919 int corder
; /* Order number */
920 char ctype
[33], /* Data type */
921 cminimum
[65], /* Minimum value */
922 cmaximum
[65]; /* Maximum value */
926 * Get the custom option and parameter...
929 if ((coption
= ppd_get_coption(ppd
, keyword
+ 11)) == NULL
)
931 cg
->ppd_status
= PPD_ALLOC_ERROR
;
936 if ((cparam
= ppd_get_cparam(coption
, name
, text
)) == NULL
)
938 cg
->ppd_status
= PPD_ALLOC_ERROR
;
944 * Get the parameter data...
948 sscanf(string
, "%d%32s%64s%64s", &corder
, ctype
, cminimum
,
951 cg
->ppd_status
= PPD_BAD_CUSTOM_PARAM
;
956 cparam
->order
= corder
;
958 if (!strcmp(ctype
, "curve"))
960 cparam
->type
= PPD_CUSTOM_CURVE
;
961 cparam
->minimum
.custom_curve
= (float)_cupsStrScand(cminimum
, NULL
, loc
);
962 cparam
->maximum
.custom_curve
= (float)_cupsStrScand(cmaximum
, NULL
, loc
);
964 else if (!strcmp(ctype
, "int"))
966 cparam
->type
= PPD_CUSTOM_INT
;
967 cparam
->minimum
.custom_int
= atoi(cminimum
);
968 cparam
->maximum
.custom_int
= atoi(cmaximum
);
970 else if (!strcmp(ctype
, "invcurve"))
972 cparam
->type
= PPD_CUSTOM_INVCURVE
;
973 cparam
->minimum
.custom_invcurve
= (float)_cupsStrScand(cminimum
, NULL
, loc
);
974 cparam
->maximum
.custom_invcurve
= (float)_cupsStrScand(cmaximum
, NULL
, loc
);
976 else if (!strcmp(ctype
, "passcode"))
978 cparam
->type
= PPD_CUSTOM_PASSCODE
;
979 cparam
->minimum
.custom_passcode
= atoi(cminimum
);
980 cparam
->maximum
.custom_passcode
= atoi(cmaximum
);
982 else if (!strcmp(ctype
, "password"))
984 cparam
->type
= PPD_CUSTOM_PASSWORD
;
985 cparam
->minimum
.custom_password
= atoi(cminimum
);
986 cparam
->maximum
.custom_password
= atoi(cmaximum
);
988 else if (!strcmp(ctype
, "points"))
990 cparam
->type
= PPD_CUSTOM_POINTS
;
991 cparam
->minimum
.custom_points
= (float)_cupsStrScand(cminimum
, NULL
, loc
);
992 cparam
->maximum
.custom_points
= (float)_cupsStrScand(cmaximum
, NULL
, loc
);
994 else if (!strcmp(ctype
, "real"))
996 cparam
->type
= PPD_CUSTOM_REAL
;
997 cparam
->minimum
.custom_real
= (float)_cupsStrScand(cminimum
, NULL
, loc
);
998 cparam
->maximum
.custom_real
= (float)_cupsStrScand(cmaximum
, NULL
, loc
);
1000 else if (!strcmp(ctype
, "string"))
1002 cparam
->type
= PPD_CUSTOM_STRING
;
1003 cparam
->minimum
.custom_string
= atoi(cminimum
);
1004 cparam
->maximum
.custom_string
= atoi(cmaximum
);
1008 cg
->ppd_status
= PPD_BAD_CUSTOM_PARAM
;
1014 * Now special-case for CustomPageSize...
1017 if (!strcmp(coption
->keyword
, "PageSize"))
1019 if (!strcmp(name
, "Width"))
1021 ppd
->custom_min
[0] = cparam
->minimum
.custom_points
;
1022 ppd
->custom_max
[0] = cparam
->maximum
.custom_points
;
1024 else if (!strcmp(name
, "Height"))
1026 ppd
->custom_min
[1] = cparam
->minimum
.custom_points
;
1027 ppd
->custom_max
[1] = cparam
->maximum
.custom_points
;
1031 else if (!strcmp(keyword
, "HWMargins"))
1033 for (i
= 0, sptr
= string
; i
< 4; i
++)
1034 ppd
->custom_margins
[i
] = (float)_cupsStrScand(sptr
, &sptr
, loc
);
1036 else if (!strncmp(keyword
, "Custom", 6) && !strcmp(name
, "True") && !option
)
1038 ppd_option_t
*custom_option
; /* Custom option */
1040 DEBUG_puts("2ppdOpen2: Processing Custom option...");
1043 * Get the option and custom option...
1046 if (!ppd_get_coption(ppd
, keyword
+ 6))
1048 cg
->ppd_status
= PPD_ALLOC_ERROR
;
1053 if (option
&& !strcasecmp(option
->keyword
, keyword
+ 6))
1054 custom_option
= option
;
1056 custom_option
= ppdFindOption(ppd
, keyword
+ 6);
1061 * Add the "custom" option...
1064 if ((choice
= ppdFindChoice(custom_option
, "Custom")) == NULL
)
1065 if ((choice
= ppd_add_choice(custom_option
, "Custom")) == NULL
)
1067 DEBUG_puts("1ppdOpen2: Unable to add Custom choice!");
1069 cg
->ppd_status
= PPD_ALLOC_ERROR
;
1074 strlcpy(choice
->text
, text
[0] ? text
: _("Custom"),
1075 sizeof(choice
->text
));
1077 choice
->code
= _cupsStrAlloc(string
);
1079 if (custom_option
->section
== PPD_ORDER_JCL
)
1080 ppd_decode(choice
->code
);
1084 * Now process custom page sizes specially...
1087 if (!strcmp(keyword
, "CustomPageSize"))
1090 * Add a "Custom" page size entry...
1093 ppd
->variable_sizes
= 1;
1095 ppd_add_size(ppd
, "Custom");
1097 if (option
&& !strcasecmp(option
->keyword
, "PageRegion"))
1098 custom_option
= option
;
1100 custom_option
= ppdFindOption(ppd
, "PageRegion");
1104 if ((choice
= ppdFindChoice(custom_option
, "Custom")) == NULL
)
1105 if ((choice
= ppd_add_choice(custom_option
, "Custom")) == NULL
)
1107 DEBUG_puts("1ppdOpen2: Unable to add Custom choice!");
1109 cg
->ppd_status
= PPD_ALLOC_ERROR
;
1114 strlcpy(choice
->text
, text
[0] ? text
: _("Custom"),
1115 sizeof(choice
->text
));
1119 else if (!strcmp(keyword
, "LandscapeOrientation"))
1121 if (!strcmp(string
, "Minus90"))
1122 ppd
->landscape
= -90;
1123 else if (!strcmp(string
, "Plus90"))
1124 ppd
->landscape
= 90;
1126 else if (!strcmp(keyword
, "Emulators") && string
)
1128 for (count
= 1, sptr
= string
; sptr
!= NULL
;)
1129 if ((sptr
= strchr(sptr
, ' ')) != NULL
)
1132 while (*sptr
== ' ')
1136 ppd
->num_emulations
= count
;
1137 if ((ppd
->emulations
= calloc(count
, sizeof(ppd_emul_t
))) == NULL
)
1139 cg
->ppd_status
= PPD_ALLOC_ERROR
;
1144 for (i
= 0, sptr
= string
; i
< count
; i
++)
1146 for (nameptr
= ppd
->emulations
[i
].name
;
1147 *sptr
!= '\0' && *sptr
!= ' ';
1149 if (nameptr
< (ppd
->emulations
[i
].name
+ sizeof(ppd
->emulations
[i
].name
) - 1))
1154 while (*sptr
== ' ')
1158 else if (!strncmp(keyword
, "StartEmulator_", 14))
1162 for (i
= 0; i
< ppd
->num_emulations
; i
++)
1163 if (!strcmp(keyword
+ 14, ppd
->emulations
[i
].name
))
1165 ppd
->emulations
[i
].start
= string
;
1169 else if (!strncmp(keyword
, "StopEmulator_", 13))
1173 for (i
= 0; i
< ppd
->num_emulations
; i
++)
1174 if (!strcmp(keyword
+ 13, ppd
->emulations
[i
].name
))
1176 ppd
->emulations
[i
].stop
= string
;
1180 else if (!strcmp(keyword
, "JobPatchFile"))
1183 * CUPS STR #3421: Check for "*JobPatchFile: int: string"
1186 if (isdigit(*string
& 255))
1188 for (sptr
= string
+ 1; isdigit(*sptr
& 255); sptr
++);
1193 * Found "*JobPatchFile: int: string"...
1196 cg
->ppd_status
= PPD_BAD_VALUE
;
1205 * Found "*JobPatchFile: string"...
1208 cg
->ppd_status
= PPD_MISSING_OPTION_KEYWORD
;
1213 if (ppd
->patches
== NULL
)
1214 ppd
->patches
= strdup(string
);
1217 temp
= realloc(ppd
->patches
, strlen(ppd
->patches
) +
1218 strlen(string
) + 1);
1221 cg
->ppd_status
= PPD_ALLOC_ERROR
;
1226 ppd
->patches
= temp
;
1228 strcpy(ppd
->patches
+ strlen(ppd
->patches
), string
);
1231 else if (!strcmp(keyword
, "OpenUI"))
1234 * Don't allow nesting of options...
1237 if (option
&& cg
->ppd_conform
== PPD_CONFORM_STRICT
)
1239 cg
->ppd_status
= PPD_NESTED_OPEN_UI
;
1245 * Add an option record to the current sub-group, group, or file...
1248 DEBUG_printf(("2ppdOpen2: name=\"%s\" (%d)", name
, (int)strlen(name
)));
1251 _cups_strcpy(name
, name
+ 1); /* Eliminate leading asterisk */
1253 for (i
= (int)strlen(name
) - 1; i
> 0 && isspace(name
[i
] & 255); i
--)
1254 name
[i
] = '\0'; /* Eliminate trailing spaces */
1256 DEBUG_printf(("2ppdOpen2: OpenUI of %s in group %s...", name
,
1257 group
? group
->text
: "(null)"));
1259 if (subgroup
!= NULL
)
1260 option
= ppd_get_option(subgroup
, name
);
1261 else if (group
== NULL
)
1263 if ((group
= ppd_get_group(ppd
, "General", _("General"), cg
,
1267 DEBUG_printf(("2ppdOpen2: Adding to group %s...", group
->text
));
1268 option
= ppd_get_option(group
, name
);
1272 option
= ppd_get_option(group
, name
);
1276 cg
->ppd_status
= PPD_ALLOC_ERROR
;
1282 * Now fill in the initial information for the option...
1285 if (string
&& !strcmp(string
, "PickMany"))
1286 option
->ui
= PPD_UI_PICKMANY
;
1287 else if (string
&& !strcmp(string
, "Boolean"))
1288 option
->ui
= PPD_UI_BOOLEAN
;
1289 else if (string
&& !strcmp(string
, "PickOne"))
1290 option
->ui
= PPD_UI_PICKONE
;
1291 else if (cg
->ppd_conform
== PPD_CONFORM_STRICT
)
1293 cg
->ppd_status
= PPD_BAD_OPEN_UI
;
1298 option
->ui
= PPD_UI_PICKONE
;
1300 for (j
= 0; j
< ppd
->num_attrs
; j
++)
1301 if (!strncmp(ppd
->attrs
[j
]->name
, "Default", 7) &&
1302 !strcmp(ppd
->attrs
[j
]->name
+ 7, name
) &&
1303 ppd
->attrs
[j
]->value
)
1305 DEBUG_printf(("2ppdOpen2: Setting Default%s to %s via attribute...",
1306 option
->keyword
, ppd
->attrs
[j
]->value
));
1307 strlcpy(option
->defchoice
, ppd
->attrs
[j
]->value
,
1308 sizeof(option
->defchoice
));
1313 cupsCharsetToUTF8((cups_utf8_t
*)option
->text
, text
,
1314 sizeof(option
->text
), encoding
);
1317 if (!strcmp(name
, "PageSize"))
1318 strlcpy(option
->text
, _("Media Size"), sizeof(option
->text
));
1319 else if (!strcmp(name
, "MediaType"))
1320 strlcpy(option
->text
, _("Media Type"), sizeof(option
->text
));
1321 else if (!strcmp(name
, "InputSlot"))
1322 strlcpy(option
->text
, _("Media Source"), sizeof(option
->text
));
1323 else if (!strcmp(name
, "ColorModel"))
1324 strlcpy(option
->text
, _("Output Mode"), sizeof(option
->text
));
1325 else if (!strcmp(name
, "Resolution"))
1326 strlcpy(option
->text
, _("Resolution"), sizeof(option
->text
));
1328 strlcpy(option
->text
, name
, sizeof(option
->text
));
1331 option
->section
= PPD_ORDER_ANY
;
1333 _cupsStrFree(string
);
1337 * Add a custom option choice if we have already seen a CustomFoo
1341 if (!strcasecmp(name
, "PageRegion"))
1342 strcpy(custom_name
, "CustomPageSize");
1344 snprintf(custom_name
, sizeof(custom_name
), "Custom%s", name
);
1346 if ((custom_attr
= ppdFindAttr(ppd
, custom_name
, "True")) != NULL
)
1348 if ((choice
= ppdFindChoice(option
, "Custom")) == NULL
)
1349 if ((choice
= ppd_add_choice(option
, "Custom")) == NULL
)
1351 DEBUG_puts("1ppdOpen2: Unable to add Custom choice!");
1353 cg
->ppd_status
= PPD_ALLOC_ERROR
;
1358 strlcpy(choice
->text
,
1359 custom_attr
->text
[0] ? custom_attr
->text
: _("Custom"),
1360 sizeof(choice
->text
));
1361 choice
->code
= _cupsStrRetain(custom_attr
->value
);
1364 else if (!strcmp(keyword
, "JCLOpenUI"))
1367 * Don't allow nesting of options...
1370 if (option
&& cg
->ppd_conform
== PPD_CONFORM_STRICT
)
1372 cg
->ppd_status
= PPD_NESTED_OPEN_UI
;
1378 * Find the JCL group, and add if needed...
1381 group
= ppd_get_group(ppd
, "JCL", _("JCL"), cg
, encoding
);
1387 * Add an option record to the current JCLs...
1391 _cups_strcpy(name
, name
+ 1);
1393 option
= ppd_get_option(group
, name
);
1397 cg
->ppd_status
= PPD_ALLOC_ERROR
;
1403 * Now fill in the initial information for the option...
1406 if (string
&& !strcmp(string
, "PickMany"))
1407 option
->ui
= PPD_UI_PICKMANY
;
1408 else if (string
&& !strcmp(string
, "Boolean"))
1409 option
->ui
= PPD_UI_BOOLEAN
;
1410 else if (string
&& !strcmp(string
, "PickOne"))
1411 option
->ui
= PPD_UI_PICKONE
;
1414 cg
->ppd_status
= PPD_BAD_OPEN_UI
;
1419 for (j
= 0; j
< ppd
->num_attrs
; j
++)
1420 if (!strncmp(ppd
->attrs
[j
]->name
, "Default", 7) &&
1421 !strcmp(ppd
->attrs
[j
]->name
+ 7, name
) &&
1422 ppd
->attrs
[j
]->value
)
1424 DEBUG_printf(("2ppdOpen2: Setting Default%s to %s via attribute...",
1425 option
->keyword
, ppd
->attrs
[j
]->value
));
1426 strlcpy(option
->defchoice
, ppd
->attrs
[j
]->value
,
1427 sizeof(option
->defchoice
));
1432 cupsCharsetToUTF8((cups_utf8_t
*)option
->text
, text
,
1433 sizeof(option
->text
), encoding
);
1435 strlcpy(option
->text
, name
, sizeof(option
->text
));
1437 option
->section
= PPD_ORDER_JCL
;
1440 _cupsStrFree(string
);
1444 * Add a custom option choice if we have already seen a CustomFoo
1448 snprintf(custom_name
, sizeof(custom_name
), "Custom%s", name
);
1450 if ((custom_attr
= ppdFindAttr(ppd
, custom_name
, "True")) != NULL
)
1452 if ((choice
= ppd_add_choice(option
, "Custom")) == NULL
)
1454 DEBUG_puts("1ppdOpen2: Unable to add Custom choice!");
1456 cg
->ppd_status
= PPD_ALLOC_ERROR
;
1461 strlcpy(choice
->text
,
1462 custom_attr
->text
[0] ? custom_attr
->text
: _("Custom"),
1463 sizeof(choice
->text
));
1464 choice
->code
= _cupsStrRetain(custom_attr
->value
);
1467 else if (!strcmp(keyword
, "CloseUI") || !strcmp(keyword
, "JCLCloseUI"))
1471 _cupsStrFree(string
);
1474 else if (!strcmp(keyword
, "OpenGroup"))
1477 * Open a new group...
1482 cg
->ppd_status
= PPD_NESTED_OPEN_GROUP
;
1489 cg
->ppd_status
= PPD_BAD_OPEN_GROUP
;
1495 * Separate the group name from the text (name/text)...
1498 if ((sptr
= strchr(string
, '/')) != NULL
)
1504 * Fix up the text...
1510 * Find/add the group...
1513 group
= ppd_get_group(ppd
, string
, sptr
, cg
, encoding
);
1518 _cupsStrFree(string
);
1521 else if (!strcmp(keyword
, "CloseGroup"))
1525 _cupsStrFree(string
);
1528 else if (!strcmp(keyword
, "OrderDependency"))
1530 order
= (float)_cupsStrScand(string
, &sptr
, loc
);
1532 if (!sptr
|| sscanf(sptr
, "%40s%40s", name
, keyword
) != 2)
1534 cg
->ppd_status
= PPD_BAD_ORDER_DEPENDENCY
;
1539 if (keyword
[0] == '*')
1540 _cups_strcpy(keyword
, keyword
+ 1);
1542 if (!strcmp(name
, "ExitServer"))
1543 section
= PPD_ORDER_EXIT
;
1544 else if (!strcmp(name
, "Prolog"))
1545 section
= PPD_ORDER_PROLOG
;
1546 else if (!strcmp(name
, "DocumentSetup"))
1547 section
= PPD_ORDER_DOCUMENT
;
1548 else if (!strcmp(name
, "PageSetup"))
1549 section
= PPD_ORDER_PAGE
;
1550 else if (!strcmp(name
, "JCLSetup"))
1551 section
= PPD_ORDER_JCL
;
1553 section
= PPD_ORDER_ANY
;
1561 * Only valid for Non-UI options...
1564 for (i
= ppd
->num_groups
, gtemp
= ppd
->groups
; i
> 0; i
--, gtemp
++)
1565 if (gtemp
->text
[0] == '\0')
1569 for (i
= 0; i
< gtemp
->num_options
; i
++)
1570 if (!strcmp(keyword
, gtemp
->options
[i
].keyword
))
1572 gtemp
->options
[i
].section
= section
;
1573 gtemp
->options
[i
].order
= order
;
1579 option
->section
= section
;
1580 option
->order
= order
;
1583 _cupsStrFree(string
);
1586 else if (!strncmp(keyword
, "Default", 7))
1592 * Drop UI text, if any, from value...
1595 if (strchr(string
, '/') != NULL
)
1596 *strchr(string
, '/') = '\0';
1599 * Assign the default value as appropriate...
1602 if (!strcmp(keyword
, "DefaultColorSpace"))
1605 * Set default colorspace...
1608 if (!strcmp(string
, "CMY"))
1609 ppd
->colorspace
= PPD_CS_CMY
;
1610 else if (!strcmp(string
, "CMYK"))
1611 ppd
->colorspace
= PPD_CS_CMYK
;
1612 else if (!strcmp(string
, "RGB"))
1613 ppd
->colorspace
= PPD_CS_RGB
;
1614 else if (!strcmp(string
, "RGBK"))
1615 ppd
->colorspace
= PPD_CS_RGBK
;
1616 else if (!strcmp(string
, "N"))
1617 ppd
->colorspace
= PPD_CS_N
;
1619 ppd
->colorspace
= PPD_CS_GRAY
;
1621 else if (option
&& !strcmp(keyword
+ 7, option
->keyword
))
1624 * Set the default as part of the current option...
1627 DEBUG_printf(("2ppdOpen2: Setting %s to %s...", keyword
, string
));
1629 strlcpy(option
->defchoice
, string
, sizeof(option
->defchoice
));
1631 DEBUG_printf(("2ppdOpen2: %s is now %s...", keyword
, option
->defchoice
));
1636 * Lookup option and set if it has been defined...
1639 ppd_option_t
*toption
; /* Temporary option */
1642 if ((toption
= ppdFindOption(ppd
, keyword
+ 7)) != NULL
)
1644 DEBUG_printf(("2ppdOpen2: Setting %s to %s...", keyword
, string
));
1645 strlcpy(toption
->defchoice
, string
, sizeof(toption
->defchoice
));
1649 else if (!strcmp(keyword
, "UIConstraints") ||
1650 !strcmp(keyword
, "NonUIConstraints"))
1654 cg
->ppd_status
= PPD_BAD_UI_CONSTRAINTS
;
1658 if (ppd
->num_consts
== 0)
1659 constraint
= calloc(2, sizeof(ppd_const_t
));
1661 constraint
= realloc(ppd
->consts
,
1662 (ppd
->num_consts
+ 2) * sizeof(ppd_const_t
));
1664 if (constraint
== NULL
)
1666 cg
->ppd_status
= PPD_ALLOC_ERROR
;
1671 ppd
->consts
= constraint
;
1672 constraint
+= ppd
->num_consts
;
1675 switch (sscanf(string
, "%40s%40s%40s%40s", constraint
->option1
,
1676 constraint
->choice1
, constraint
->option2
,
1677 constraint
->choice2
))
1679 case 0 : /* Error */
1680 case 1 : /* Error */
1681 cg
->ppd_status
= PPD_BAD_UI_CONSTRAINTS
;
1684 case 2 : /* Two options... */
1686 * Check for broken constraints like "* Option"...
1689 if (cg
->ppd_conform
== PPD_CONFORM_STRICT
&&
1690 (!strcmp(constraint
->option1
, "*") ||
1691 !strcmp(constraint
->choice1
, "*")))
1693 cg
->ppd_status
= PPD_BAD_UI_CONSTRAINTS
;
1698 * The following strcpy's are safe, as optionN and
1699 * choiceN are all the same size (size defined by PPD spec...)
1702 if (constraint
->option1
[0] == '*')
1703 _cups_strcpy(constraint
->option1
, constraint
->option1
+ 1);
1704 else if (cg
->ppd_conform
== PPD_CONFORM_STRICT
)
1706 cg
->ppd_status
= PPD_BAD_UI_CONSTRAINTS
;
1710 if (constraint
->choice1
[0] == '*')
1711 _cups_strcpy(constraint
->option2
, constraint
->choice1
+ 1);
1712 else if (cg
->ppd_conform
== PPD_CONFORM_STRICT
)
1714 cg
->ppd_status
= PPD_BAD_UI_CONSTRAINTS
;
1718 constraint
->choice1
[0] = '\0';
1719 constraint
->choice2
[0] = '\0';
1722 case 3 : /* Two options, one choice... */
1724 * Check for broken constraints like "* Option"...
1727 if (cg
->ppd_conform
== PPD_CONFORM_STRICT
&&
1728 (!strcmp(constraint
->option1
, "*") ||
1729 !strcmp(constraint
->choice1
, "*") ||
1730 !strcmp(constraint
->option2
, "*")))
1732 cg
->ppd_status
= PPD_BAD_UI_CONSTRAINTS
;
1737 * The following _cups_strcpy's are safe, as optionN and
1738 * choiceN are all the same size (size defined by PPD spec...)
1741 if (constraint
->option1
[0] == '*')
1742 _cups_strcpy(constraint
->option1
, constraint
->option1
+ 1);
1743 else if (cg
->ppd_conform
== PPD_CONFORM_STRICT
)
1745 cg
->ppd_status
= PPD_BAD_UI_CONSTRAINTS
;
1749 if (constraint
->choice1
[0] == '*')
1751 if (cg
->ppd_conform
== PPD_CONFORM_STRICT
&&
1752 constraint
->option2
[0] == '*')
1754 cg
->ppd_status
= PPD_BAD_UI_CONSTRAINTS
;
1758 _cups_strcpy(constraint
->choice2
, constraint
->option2
);
1759 _cups_strcpy(constraint
->option2
, constraint
->choice1
+ 1);
1760 constraint
->choice1
[0] = '\0';
1764 if (constraint
->option2
[0] == '*')
1765 _cups_strcpy(constraint
->option2
, constraint
->option2
+ 1);
1766 else if (cg
->ppd_conform
== PPD_CONFORM_STRICT
)
1768 cg
->ppd_status
= PPD_BAD_UI_CONSTRAINTS
;
1772 constraint
->choice2
[0] = '\0';
1776 case 4 : /* Two options, two choices... */
1778 * Check for broken constraints like "* Option"...
1781 if (cg
->ppd_conform
== PPD_CONFORM_STRICT
&&
1782 (!strcmp(constraint
->option1
, "*") ||
1783 !strcmp(constraint
->choice1
, "*") ||
1784 !strcmp(constraint
->option2
, "*") ||
1785 !strcmp(constraint
->choice2
, "*")))
1787 cg
->ppd_status
= PPD_BAD_UI_CONSTRAINTS
;
1791 if (constraint
->option1
[0] == '*')
1792 _cups_strcpy(constraint
->option1
, constraint
->option1
+ 1);
1793 else if (cg
->ppd_conform
== PPD_CONFORM_STRICT
)
1795 cg
->ppd_status
= PPD_BAD_UI_CONSTRAINTS
;
1799 if (cg
->ppd_conform
== PPD_CONFORM_STRICT
&&
1800 constraint
->choice1
[0] == '*')
1802 cg
->ppd_status
= PPD_BAD_UI_CONSTRAINTS
;
1806 if (constraint
->option2
[0] == '*')
1807 _cups_strcpy(constraint
->option2
, constraint
->option2
+ 1);
1808 else if (cg
->ppd_conform
== PPD_CONFORM_STRICT
)
1810 cg
->ppd_status
= PPD_BAD_UI_CONSTRAINTS
;
1814 if (cg
->ppd_conform
== PPD_CONFORM_STRICT
&&
1815 constraint
->choice2
[0] == '*')
1817 cg
->ppd_status
= PPD_BAD_UI_CONSTRAINTS
;
1824 * Don't add this one as an attribute...
1827 _cupsStrFree(string
);
1830 else if (!strcmp(keyword
, "PaperDimension"))
1832 if ((size
= ppdPageSize(ppd
, name
)) == NULL
)
1833 size
= ppd_add_size(ppd
, name
);
1838 * Unable to add or find size!
1841 cg
->ppd_status
= PPD_ALLOC_ERROR
;
1846 size
->width
= (float)_cupsStrScand(string
, &sptr
, loc
);
1847 size
->length
= (float)_cupsStrScand(sptr
, NULL
, loc
);
1849 _cupsStrFree(string
);
1852 else if (!strcmp(keyword
, "ImageableArea"))
1854 if ((size
= ppdPageSize(ppd
, name
)) == NULL
)
1855 size
= ppd_add_size(ppd
, name
);
1860 * Unable to add or find size!
1863 cg
->ppd_status
= PPD_ALLOC_ERROR
;
1868 size
->left
= (float)_cupsStrScand(string
, &sptr
, loc
);
1869 size
->bottom
= (float)_cupsStrScand(sptr
, &sptr
, loc
);
1870 size
->right
= (float)_cupsStrScand(sptr
, &sptr
, loc
);
1871 size
->top
= (float)_cupsStrScand(sptr
, NULL
, loc
);
1873 _cupsStrFree(string
);
1876 else if (option
!= NULL
&&
1877 (mask
& (PPD_KEYWORD
| PPD_OPTION
| PPD_STRING
)) ==
1878 (PPD_KEYWORD
| PPD_OPTION
| PPD_STRING
) &&
1879 !strcmp(keyword
, option
->keyword
))
1881 DEBUG_printf(("2ppdOpen2: group=%p, subgroup=%p", group
, subgroup
));
1883 if (!strcmp(keyword
, "PageSize"))
1886 * Add a page size...
1889 if (ppdPageSize(ppd
, name
) == NULL
)
1890 ppd_add_size(ppd
, name
);
1894 * Add the option choice...
1897 if ((choice
= ppd_add_choice(option
, name
)) == NULL
)
1899 cg
->ppd_status
= PPD_ALLOC_ERROR
;
1905 cupsCharsetToUTF8((cups_utf8_t
*)choice
->text
, text
,
1906 sizeof(choice
->text
), encoding
);
1907 else if (!strcmp(name
, "True"))
1908 strcpy(choice
->text
, _("Yes"));
1909 else if (!strcmp(name
, "False"))
1910 strcpy(choice
->text
, _("No"));
1912 strlcpy(choice
->text
, name
, sizeof(choice
->text
));
1914 if (option
->section
== PPD_ORDER_JCL
)
1915 ppd_decode(string
); /* Decode quoted string */
1917 choice
->code
= string
;
1918 string
= NULL
; /* Don't add as an attribute below */
1922 * Add remaining lines with keywords and string values as attributes...
1926 (mask
& (PPD_KEYWORD
| PPD_STRING
)) == (PPD_KEYWORD
| PPD_STRING
))
1927 ppd_add_attr(ppd
, keyword
, name
, text
, string
);
1929 _cupsStrFree(string
);
1932 ppd_free(line
.buffer
);
1935 * Reset language preferences...
1938 cupsLangFree(language
);
1941 if (!cupsFileEOF(fp
))
1942 DEBUG_printf(("1ppdOpen2: Premature EOF at %lu...\n",
1943 (unsigned long)cupsFileTell(fp
)));
1946 if (cg
->ppd_status
!= PPD_OK
)
1949 * Had an error reading the PPD file, cannot continue!
1958 * Create the sorted options array and set the option back-pointer for
1959 * each choice and custom option...
1962 ppd
->options
= cupsArrayNew2((cups_array_func_t
)ppd_compare_options
, NULL
,
1963 (cups_ahash_func_t
)ppd_hash_option
,
1966 for (i
= ppd
->num_groups
, group
= ppd
->groups
;
1970 for (j
= group
->num_options
, option
= group
->options
;
1974 ppd_coption_t
*coption
; /* Custom option */
1977 cupsArrayAdd(ppd
->options
, option
);
1979 for (k
= 0; k
< option
->num_choices
; k
++)
1980 option
->choices
[k
].option
= option
;
1982 if ((coption
= ppdFindCustomOption(ppd
, option
->keyword
)) != NULL
)
1983 coption
->option
= option
;
1988 * Create an array to track the marked choices...
1991 ppd
->marked
= cupsArrayNew((cups_array_func_t
)ppd_compare_choices
, NULL
);
1994 * Return the PPD file structure...
2000 * Common exit point for errors to save code size...
2005 _cupsStrFree(string
);
2006 ppd_free(line
.buffer
);
2010 cupsLangFree(language
);
2017 * 'ppdOpenFd()' - Read a PPD file into memory.
2020 ppd_file_t
* /* O - PPD file record or @code NULL@ if the PPD file could not be opened. */
2021 ppdOpenFd(int fd
) /* I - File to read from */
2023 cups_file_t
*fp
; /* CUPS file pointer */
2024 ppd_file_t
*ppd
; /* PPD file record */
2025 _cups_globals_t
*cg
= _cupsGlobals();
2030 * Set the line number to 0...
2036 * Range check input...
2041 cg
->ppd_status
= PPD_NULL_FILE
;
2047 * Try to open the file and parse it...
2050 if ((fp
= cupsFileOpenFd(fd
, "r")) != NULL
)
2058 cg
->ppd_status
= PPD_FILE_OPEN_ERROR
;
2067 * 'ppdOpenFile()' - Read a PPD file into memory.
2070 ppd_file_t
* /* O - PPD file record or @code NULL@ if the PPD file could not be opened. */
2071 ppdOpenFile(const char *filename
) /* I - File to read from */
2073 cups_file_t
*fp
; /* File pointer */
2074 ppd_file_t
*ppd
; /* PPD file record */
2075 _cups_globals_t
*cg
= _cupsGlobals();
2080 * Set the line number to 0...
2086 * Range check input...
2089 if (filename
== NULL
)
2091 cg
->ppd_status
= PPD_NULL_FILE
;
2097 * Try to open the file and parse it...
2100 if ((fp
= cupsFileOpen(filename
, "r")) != NULL
)
2108 cg
->ppd_status
= PPD_FILE_OPEN_ERROR
;
2117 * 'ppdSetConformance()' - Set the conformance level for PPD files.
2119 * @since CUPS 1.1.20/Mac OS X 10.4@
2123 ppdSetConformance(ppd_conform_t c
) /* I - Conformance level */
2125 _cups_globals_t
*cg
= _cupsGlobals();
2129 cg
->ppd_conform
= c
;
2134 * 'ppd_add_attr()' - Add an attribute to the PPD data.
2137 static ppd_attr_t
* /* O - New attribute */
2138 ppd_add_attr(ppd_file_t
*ppd
, /* I - PPD file data */
2139 const char *name
, /* I - Attribute name */
2140 const char *spec
, /* I - Specifier string, if any */
2141 const char *text
, /* I - Text string, if any */
2142 const char *value
) /* I - Value of attribute */
2144 ppd_attr_t
**ptr
, /* New array */
2145 *temp
; /* New attribute */
2149 * Range check input...
2152 if (ppd
== NULL
|| name
== NULL
|| spec
== NULL
)
2156 * Create the array as needed...
2159 if (!ppd
->sorted_attrs
)
2160 ppd
->sorted_attrs
= cupsArrayNew((cups_array_func_t
)ppd_compare_attrs
,
2164 * Allocate memory for the new attribute...
2167 if (ppd
->num_attrs
== 0)
2168 ptr
= malloc(sizeof(ppd_attr_t
*));
2170 ptr
= realloc(ppd
->attrs
, (ppd
->num_attrs
+ 1) * sizeof(ppd_attr_t
*));
2176 ptr
+= ppd
->num_attrs
;
2178 if ((temp
= calloc(1, sizeof(ppd_attr_t
))) == NULL
)
2189 strlcpy(temp
->name
, name
, sizeof(temp
->name
));
2190 strlcpy(temp
->spec
, spec
, sizeof(temp
->spec
));
2191 strlcpy(temp
->text
, text
, sizeof(temp
->text
));
2192 temp
->value
= (char *)value
;
2195 * Add the attribute to the sorted array...
2198 cupsArrayAdd(ppd
->sorted_attrs
, temp
);
2201 * Return the attribute...
2209 * 'ppd_add_choice()' - Add a choice to an option.
2212 static ppd_choice_t
* /* O - Named choice */
2213 ppd_add_choice(ppd_option_t
*option
, /* I - Option */
2214 const char *name
) /* I - Name of choice */
2216 ppd_choice_t
*choice
; /* Choice */
2219 if (option
->num_choices
== 0)
2220 choice
= malloc(sizeof(ppd_choice_t
));
2222 choice
= realloc(option
->choices
,
2223 sizeof(ppd_choice_t
) * (option
->num_choices
+ 1));
2228 option
->choices
= choice
;
2229 choice
+= option
->num_choices
;
2230 option
->num_choices
++;
2232 memset(choice
, 0, sizeof(ppd_choice_t
));
2233 strlcpy(choice
->choice
, name
, sizeof(choice
->choice
));
2240 * 'ppd_add_size()' - Add a page size.
2243 static ppd_size_t
* /* O - Named size */
2244 ppd_add_size(ppd_file_t
*ppd
, /* I - PPD file */
2245 const char *name
) /* I - Name of size */
2247 ppd_size_t
*size
; /* Size */
2250 if (ppd
->num_sizes
== 0)
2251 size
= malloc(sizeof(ppd_size_t
));
2253 size
= realloc(ppd
->sizes
, sizeof(ppd_size_t
) * (ppd
->num_sizes
+ 1));
2259 size
+= ppd
->num_sizes
;
2262 memset(size
, 0, sizeof(ppd_size_t
));
2263 strlcpy(size
->name
, name
, sizeof(size
->name
));
2270 * 'ppd_compare_attrs()' - Compare two attributes.
2273 static int /* O - Result of comparison */
2274 ppd_compare_attrs(ppd_attr_t
*a
, /* I - First attribute */
2275 ppd_attr_t
*b
) /* I - Second attribute */
2277 return (strcasecmp(a
->name
, b
->name
));
2282 * 'ppd_compare_choices()' - Compare two choices...
2285 static int /* O - Result of comparison */
2286 ppd_compare_choices(ppd_choice_t
*a
, /* I - First choice */
2287 ppd_choice_t
*b
) /* I - Second choice */
2289 return (strcmp(a
->option
->keyword
, b
->option
->keyword
));
2294 * 'ppd_compare_coptions()' - Compare two custom options.
2297 static int /* O - Result of comparison */
2298 ppd_compare_coptions(ppd_coption_t
*a
, /* I - First option */
2299 ppd_coption_t
*b
) /* I - Second option */
2301 return (strcasecmp(a
->keyword
, b
->keyword
));
2306 * 'ppd_compare_cparams()' - Compare two custom parameters.
2309 static int /* O - Result of comparison */
2310 ppd_compare_cparams(ppd_cparam_t
*a
, /* I - First parameter */
2311 ppd_cparam_t
*b
) /* I - Second parameter */
2313 return (strcasecmp(a
->name
, b
->name
));
2318 * 'ppd_compare_options()' - Compare two options.
2321 static int /* O - Result of comparison */
2322 ppd_compare_options(ppd_option_t
*a
, /* I - First option */
2323 ppd_option_t
*b
) /* I - Second option */
2325 return (strcasecmp(a
->keyword
, b
->keyword
));
2330 * 'ppd_decode()' - Decode a string value...
2333 static int /* O - Length of decoded string */
2334 ppd_decode(char *string
) /* I - String to decode */
2336 char *inptr
, /* Input pointer */
2337 *outptr
; /* Output pointer */
2343 while (*inptr
!= '\0')
2344 if (*inptr
== '<' && isxdigit(inptr
[1] & 255))
2347 * Convert hex to 8-bit values...
2351 while (isxdigit(*inptr
& 255))
2353 if (isalpha(*inptr
))
2354 *outptr
= (tolower(*inptr
) - 'a' + 10) << 4;
2356 *outptr
= (*inptr
- '0') << 4;
2360 if (!isxdigit(*inptr
& 255))
2363 if (isalpha(*inptr
))
2364 *outptr
|= tolower(*inptr
) - 'a' + 10;
2366 *outptr
|= *inptr
- '0';
2372 while (*inptr
!= '>' && *inptr
!= '\0')
2374 while (*inptr
== '>')
2378 *outptr
++ = *inptr
++;
2382 return ((int)(outptr
- string
));
2387 * 'ppd_free_group()' - Free a single UI group.
2391 ppd_free_group(ppd_group_t
*group
) /* I - Group to free */
2393 int i
; /* Looping var */
2394 ppd_option_t
*option
; /* Current option */
2395 ppd_group_t
*subgroup
; /* Current sub-group */
2398 if (group
->num_options
> 0)
2400 for (i
= group
->num_options
, option
= group
->options
;
2403 ppd_free_option(option
);
2405 ppd_free(group
->options
);
2408 if (group
->num_subgroups
> 0)
2410 for (i
= group
->num_subgroups
, subgroup
= group
->subgroups
;
2413 ppd_free_group(subgroup
);
2415 ppd_free(group
->subgroups
);
2421 * 'ppd_free_option()' - Free a single option.
2425 ppd_free_option(ppd_option_t
*option
) /* I - Option to free */
2427 int i
; /* Looping var */
2428 ppd_choice_t
*choice
; /* Current choice */
2431 if (option
->num_choices
> 0)
2433 for (i
= option
->num_choices
, choice
= option
->choices
;
2437 _cupsStrFree(choice
->code
);
2440 ppd_free(option
->choices
);
2446 * 'ppd_get_coption()' - Get a custom option record.
2449 static ppd_coption_t
* /* O - Custom option... */
2450 ppd_get_coption(ppd_file_t
*ppd
, /* I - PPD file */
2451 const char *name
) /* I - Name of option */
2453 ppd_coption_t
*copt
; /* New custom option */
2457 * See if the option already exists...
2460 if ((copt
= ppdFindCustomOption(ppd
, name
)) != NULL
)
2464 * Not found, so create the custom option record...
2467 if ((copt
= calloc(1, sizeof(ppd_coption_t
))) == NULL
)
2470 strlcpy(copt
->keyword
, name
, sizeof(copt
->keyword
));
2472 copt
->params
= cupsArrayNew((cups_array_func_t
)ppd_compare_cparams
, NULL
);
2474 cupsArrayAdd(ppd
->coptions
, copt
);
2477 * Return the new record...
2485 * 'ppd_get_cparam()' - Get a custom parameter record.
2488 static ppd_cparam_t
* /* O - Extended option... */
2489 ppd_get_cparam(ppd_coption_t
*opt
, /* I - PPD file */
2490 const char *param
, /* I - Name of parameter */
2491 const char *text
) /* I - Human-readable text */
2493 ppd_cparam_t
*cparam
; /* New custom parameter */
2497 * See if the parameter already exists...
2500 if ((cparam
= ppdFindCustomParam(opt
, param
)) != NULL
)
2504 * Not found, so create the custom parameter record...
2507 if ((cparam
= calloc(1, sizeof(ppd_cparam_t
))) == NULL
)
2510 strlcpy(cparam
->name
, param
, sizeof(cparam
->name
));
2511 strlcpy(cparam
->text
, text
[0] ? text
: param
, sizeof(cparam
->text
));
2514 * Add this record to the array...
2517 cupsArrayAdd(opt
->params
, cparam
);
2520 * Return the new record...
2528 * 'ppd_get_group()' - Find or create the named group as needed.
2531 static ppd_group_t
* /* O - Named group */
2532 ppd_get_group(ppd_file_t
*ppd
, /* I - PPD file */
2533 const char *name
, /* I - Name of group */
2534 const char *text
, /* I - Text for group */
2535 _cups_globals_t
*cg
, /* I - Global data */
2536 cups_encoding_t encoding
) /* I - Encoding of text */
2538 int i
; /* Looping var */
2539 ppd_group_t
*group
; /* Group */
2542 DEBUG_printf(("7ppd_get_group(ppd=%p, name=\"%s\", text=\"%s\", cg=%p)",
2543 ppd
, name
, text
, cg
));
2545 for (i
= ppd
->num_groups
, group
= ppd
->groups
; i
> 0; i
--, group
++)
2546 if (!strcmp(group
->name
, name
))
2551 DEBUG_printf(("8ppd_get_group: Adding group %s...", name
));
2553 if (cg
->ppd_conform
== PPD_CONFORM_STRICT
&& strlen(text
) >= sizeof(group
->text
))
2555 cg
->ppd_status
= PPD_ILLEGAL_TRANSLATION
;
2560 if (ppd
->num_groups
== 0)
2561 group
= malloc(sizeof(ppd_group_t
));
2563 group
= realloc(ppd
->groups
,
2564 (ppd
->num_groups
+ 1) * sizeof(ppd_group_t
));
2568 cg
->ppd_status
= PPD_ALLOC_ERROR
;
2573 ppd
->groups
= group
;
2574 group
+= ppd
->num_groups
;
2577 memset(group
, 0, sizeof(ppd_group_t
));
2578 strlcpy(group
->name
, name
, sizeof(group
->name
));
2580 cupsCharsetToUTF8((cups_utf8_t
*)group
->text
, text
,
2581 sizeof(group
->text
), encoding
);
2589 * 'ppd_get_option()' - Find or create the named option as needed.
2592 static ppd_option_t
* /* O - Named option */
2593 ppd_get_option(ppd_group_t
*group
, /* I - Group */
2594 const char *name
) /* I - Name of option */
2596 int i
; /* Looping var */
2597 ppd_option_t
*option
; /* Option */
2600 DEBUG_printf(("7ppd_get_option(group=%p(\"%s\"), name=\"%s\")",
2601 group
, group
->name
, name
));
2603 for (i
= group
->num_options
, option
= group
->options
; i
> 0; i
--, option
++)
2604 if (!strcmp(option
->keyword
, name
))
2609 if (group
->num_options
== 0)
2610 option
= malloc(sizeof(ppd_option_t
));
2612 option
= realloc(group
->options
,
2613 (group
->num_options
+ 1) * sizeof(ppd_option_t
));
2618 group
->options
= option
;
2619 option
+= group
->num_options
;
2620 group
->num_options
++;
2622 memset(option
, 0, sizeof(ppd_option_t
));
2623 strlcpy(option
->keyword
, name
, sizeof(option
->keyword
));
2631 * 'ppd_hash_option()' - Generate a hash of the option name...
2634 static int /* O - Hash index */
2635 ppd_hash_option(ppd_option_t
*option
) /* I - Option */
2637 int hash
= 0; /* Hash index */
2638 const char *k
; /* Pointer into keyword */
2641 for (hash
= option
->keyword
[0], k
= option
->keyword
+ 1; *k
;)
2642 hash
= 33 * hash
+ *k
++;
2644 return (hash
& 511);
2649 * 'ppd_read()' - Read a line from a PPD file, skipping comment lines as
2653 static int /* O - Bitmask of fields read */
2654 ppd_read(cups_file_t
*fp
, /* I - File to read from */
2655 _ppd_line_t
*line
, /* I - Line buffer */
2656 char *keyword
, /* O - Keyword from line */
2657 char *option
, /* O - Option from line */
2658 char *text
, /* O - Human-readable text from line */
2659 char **string
, /* O - Code/string data */
2660 int ignoreblank
, /* I - Ignore blank lines? */
2661 _cups_globals_t
*cg
) /* I - Global data */
2663 int ch
, /* Character from file */
2664 col
, /* Column in line */
2665 colon
, /* Colon seen? */
2666 endquote
, /* Waiting for an end quote */
2667 mask
, /* Mask to be returned */
2668 startline
, /* Start line */
2669 textlen
; /* Length of text */
2670 char *keyptr
, /* Keyword pointer */
2671 *optptr
, /* Option pointer */
2672 *textptr
, /* Text pointer */
2673 *strptr
, /* Pointer into string */
2674 *lineptr
; /* Current position in line buffer */
2678 * Now loop until we have a valid line...
2683 startline
= cg
->ppd_line
+ 1;
2687 line
->bufsize
= 1024;
2688 line
->buffer
= malloc(1024);
2700 lineptr
= line
->buffer
;
2704 while ((ch
= cupsFileGetChar(fp
)) != EOF
)
2706 if (lineptr
>= (line
->buffer
+ line
->bufsize
- 1))
2709 * Expand the line buffer...
2712 char *temp
; /* Temporary line pointer */
2715 line
->bufsize
+= 1024;
2716 if (line
->bufsize
> 262144)
2719 * Don't allow lines longer than 256k!
2722 cg
->ppd_line
= startline
;
2723 cg
->ppd_status
= PPD_LINE_TOO_LONG
;
2728 temp
= realloc(line
->buffer
, line
->bufsize
);
2731 cg
->ppd_line
= startline
;
2732 cg
->ppd_status
= PPD_LINE_TOO_LONG
;
2737 lineptr
= temp
+ (lineptr
- line
->buffer
);
2738 line
->buffer
= temp
;
2741 if (ch
== '\r' || ch
== '\n')
2744 * Line feed or carriage return...
2753 * Check for a trailing line feed...
2756 if ((ch
= cupsFilePeekChar(fp
)) == EOF
)
2763 cupsFileGetChar(fp
);
2766 if (lineptr
== line
->buffer
&& ignoreblank
)
2767 continue; /* Skip blank lines */
2771 if (!endquote
) /* Continue for multi-line text */
2776 else if (ch
< ' ' && ch
!= '\t' && cg
->ppd_conform
== PPD_CONFORM_STRICT
)
2779 * Other control characters...
2782 cg
->ppd_line
= startline
;
2783 cg
->ppd_status
= PPD_ILLEGAL_CHARACTER
;
2787 else if (ch
!= 0x1a)
2790 * Any other character...
2796 if (col
> (PPD_MAX_LINE
- 1))
2799 * Line is too long...
2802 cg
->ppd_line
= startline
;
2803 cg
->ppd_status
= PPD_LINE_TOO_LONG
;
2808 if (ch
== ':' && strncmp(line
->buffer
, "*%", 2) != 0)
2811 if (ch
== '\"' && colon
)
2812 endquote
= !endquote
;
2819 * Didn't finish this quoted string...
2822 while ((ch
= cupsFileGetChar(fp
)) != EOF
)
2825 else if (ch
== '\r' || ch
== '\n')
2833 * Check for a trailing line feed...
2836 if ((ch
= cupsFilePeekChar(fp
)) == EOF
)
2839 cupsFileGetChar(fp
);
2842 else if (ch
< ' ' && ch
!= '\t' && cg
->ppd_conform
== PPD_CONFORM_STRICT
)
2845 * Other control characters...
2848 cg
->ppd_line
= startline
;
2849 cg
->ppd_status
= PPD_ILLEGAL_CHARACTER
;
2853 else if (ch
!= 0x1a)
2857 if (col
> (PPD_MAX_LINE
- 1))
2860 * Line is too long...
2863 cg
->ppd_line
= startline
;
2864 cg
->ppd_status
= PPD_LINE_TOO_LONG
;
2874 * Didn't finish this line...
2877 while ((ch
= cupsFileGetChar(fp
)) != EOF
)
2878 if (ch
== '\r' || ch
== '\n')
2881 * Line feed or carriage return...
2890 * Check for a trailing line feed...
2893 if ((ch
= cupsFilePeekChar(fp
)) == EOF
)
2896 cupsFileGetChar(fp
);
2901 else if (ch
< ' ' && ch
!= '\t' && cg
->ppd_conform
== PPD_CONFORM_STRICT
)
2904 * Other control characters...
2907 cg
->ppd_line
= startline
;
2908 cg
->ppd_status
= PPD_ILLEGAL_CHARACTER
;
2912 else if (ch
!= 0x1a)
2916 if (col
> (PPD_MAX_LINE
- 1))
2919 * Line is too long...
2922 cg
->ppd_line
= startline
;
2923 cg
->ppd_status
= PPD_LINE_TOO_LONG
;
2930 if (lineptr
> line
->buffer
&& lineptr
[-1] == '\n')
2935 DEBUG_printf(("9ppd_read: LINE=\"%s\"", line
->buffer
));
2938 * The dynamically created PPDs for older style Mac OS X
2939 * drivers include a large blob of data inserted as comments
2940 * at the end of the file. As an optimization we can stop
2941 * reading the PPD when we get to the start of this data.
2944 if (!strcmp(line
->buffer
, "*%APLWORKSET START"))
2947 if (ch
== EOF
&& lineptr
== line
->buffer
)
2955 lineptr
= line
->buffer
+ 1;
2962 if ((!line
->buffer
[0] || /* Blank line */
2963 !strncmp(line
->buffer
, "*%", 2) || /* Comment line */
2964 !strcmp(line
->buffer
, "*End")) && /* End of multi-line string */
2965 ignoreblank
) /* Ignore these? */
2967 startline
= cg
->ppd_line
+ 1;
2971 if (!strcmp(line
->buffer
, "*")) /* (Bad) comment line */
2973 if (cg
->ppd_conform
== PPD_CONFORM_RELAXED
)
2975 startline
= cg
->ppd_line
+ 1;
2980 cg
->ppd_line
= startline
;
2981 cg
->ppd_status
= PPD_ILLEGAL_MAIN_KEYWORD
;
2987 if (line
->buffer
[0] != '*') /* All lines start with an asterisk */
2990 * Allow lines consisting of just whitespace...
2993 for (lineptr
= line
->buffer
; *lineptr
; lineptr
++)
2994 if (!isspace(*lineptr
& 255))
2999 cg
->ppd_status
= PPD_MISSING_ASTERISK
;
3002 else if (ignoreblank
)
3014 while (*lineptr
!= '\0' && *lineptr
!= ':' && !isspace(*lineptr
& 255))
3016 if (*lineptr
<= ' ' || *lineptr
> 126 || *lineptr
== '/' ||
3017 (keyptr
- keyword
) >= (PPD_MAX_NAME
- 1))
3019 cg
->ppd_status
= PPD_ILLEGAL_MAIN_KEYWORD
;
3023 *keyptr
++ = *lineptr
++;
3028 if (!strcmp(keyword
, "End"))
3031 mask
|= PPD_KEYWORD
;
3033 if (isspace(*lineptr
& 255))
3036 * Get an option name...
3039 while (isspace(*lineptr
& 255))
3044 while (*lineptr
!= '\0' && !isspace(*lineptr
& 255) && *lineptr
!= ':' &&
3047 if (*lineptr
<= ' ' || *lineptr
> 126 ||
3048 (optptr
- option
) >= (PPD_MAX_NAME
- 1))
3050 cg
->ppd_status
= PPD_ILLEGAL_OPTION_KEYWORD
;
3054 *optptr
++ = *lineptr
++;
3059 if (isspace(*lineptr
& 255) && cg
->ppd_conform
== PPD_CONFORM_STRICT
)
3061 cg
->ppd_status
= PPD_ILLEGAL_WHITESPACE
;
3065 while (isspace(*lineptr
& 255))
3070 if (*lineptr
== '/')
3073 * Get human-readable text...
3080 while (*lineptr
!= '\0' && *lineptr
!= '\n' && *lineptr
!= ':')
3082 if (((unsigned char)*lineptr
< ' ' && *lineptr
!= '\t') ||
3083 (textptr
- text
) >= (PPD_MAX_LINE
- 1))
3085 cg
->ppd_status
= PPD_ILLEGAL_TRANSLATION
;
3089 *textptr
++ = *lineptr
++;
3093 textlen
= ppd_decode(text
);
3095 if (textlen
> PPD_MAX_TEXT
&& cg
->ppd_conform
== PPD_CONFORM_STRICT
)
3097 cg
->ppd_status
= PPD_ILLEGAL_TRANSLATION
;
3105 if (isspace(*lineptr
& 255) && cg
->ppd_conform
== PPD_CONFORM_STRICT
)
3107 cg
->ppd_status
= PPD_ILLEGAL_WHITESPACE
;
3111 while (isspace(*lineptr
& 255))
3114 if (*lineptr
== ':')
3117 * Get string after triming leading and trailing whitespace...
3121 while (isspace(*lineptr
& 255))
3124 strptr
= lineptr
+ strlen(lineptr
) - 1;
3125 while (strptr
>= lineptr
&& isspace(*strptr
& 255))
3128 if (*strptr
== '\"')
3131 * Quoted string by itself, remove quotes...
3138 *string
= _cupsStrAlloc(lineptr
);
3150 * End of "$Id: ppd.c 7906 2008-09-03 20:19:43Z mike $".