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")
359 if (status
< PPD_OK
|| status
> PPD_ILLEGAL_WHITESPACE
)
360 return (_cupsLangString(cupsLangDefault(), _("Unknown")));
362 return (_cupsLangString(cupsLangDefault(), messages
[status
]));
367 * '_ppdGetEncoding()' - Get the CUPS encoding value for the given
371 cups_encoding_t
/* O - CUPS encoding value */
372 _ppdGetEncoding(const char *name
) /* I - LanguageEncoding string */
374 if (!strcasecmp(name
, "ISOLatin1"))
375 return (CUPS_ISO8859_1
);
376 else if (!strcasecmp(name
, "ISOLatin2"))
377 return (CUPS_ISO8859_2
);
378 else if (!strcasecmp(name
, "ISOLatin5"))
379 return (CUPS_ISO8859_5
);
380 else if (!strcasecmp(name
, "JIS83-RKSJ"))
381 return (CUPS_JIS_X0213
);
382 else if (!strcasecmp(name
, "MacStandard"))
383 return (CUPS_MAC_ROMAN
);
384 else if (!strcasecmp(name
, "WindowsANSI"))
385 return (CUPS_WINDOWS_1252
);
392 * 'ppdLastError()' - Return the status from the last ppdOpen*().
394 * @since CUPS 1.1.19/Mac OS X 10.3@
397 ppd_status_t
/* O - Status code */
398 ppdLastError(int *line
) /* O - Line number */
400 _cups_globals_t
*cg
= _cupsGlobals();
405 *line
= cg
->ppd_line
;
407 return (cg
->ppd_status
);
412 * 'ppdOpen()' - Read a PPD file into memory.
415 ppd_file_t
* /* O - PPD file record */
416 ppdOpen(FILE *fp
) /* I - File to read from */
418 ppd_file_t
*ppd
; /* PPD file record */
419 cups_file_t
*cf
; /* CUPS file */
423 * Reopen the stdio file as a CUPS file...
426 if ((cf
= cupsFileOpenFd(fileno(fp
), "r")) == NULL
)
430 * Load the PPD file using the newer API...
436 * Close the CUPS file and return the PPD...
446 * 'ppdOpen2()' - Read a PPD file into memory.
448 * @since CUPS 1.2/Mac OS X 10.5@
451 ppd_file_t
* /* O - PPD file record or @code NULL@ if the PPD file could not be opened. */
452 ppdOpen2(cups_file_t
*fp
) /* I - File to read from */
454 int i
, j
, k
; /* Looping vars */
455 int count
; /* Temporary count */
456 _ppd_line_t line
; /* Line buffer */
457 ppd_file_t
*ppd
; /* PPD file record */
458 ppd_group_t
*group
, /* Current group */
459 *subgroup
; /* Current sub-group */
460 ppd_option_t
*option
; /* Current option */
461 ppd_choice_t
*choice
; /* Current choice */
462 ppd_const_t
*constraint
; /* Current constraint */
463 ppd_size_t
*size
; /* Current page size */
464 int mask
; /* Line data mask */
465 char keyword
[PPD_MAX_NAME
],
466 /* Keyword from file */
468 /* Option from file */
470 /* Human-readable text from file */
471 *string
, /* Code/text from file */
472 *sptr
, /* Pointer into string */
473 *nameptr
, /* Pointer into name */
474 *temp
, /* Temporary string pointer */
475 **tempfonts
; /* Temporary fonts pointer */
476 float order
; /* Order dependency number */
477 ppd_section_t section
; /* Order dependency section */
478 ppd_profile_t
*profile
; /* Pointer to color profile */
479 char **filter
; /* Pointer to filter */
480 cups_lang_t
*language
; /* Default language */
481 struct lconv
*loc
; /* Locale data */
482 int ui_keyword
; /* Is this line a UI keyword? */
483 cups_encoding_t encoding
; /* Encoding of PPD file */
484 _cups_globals_t
*cg
= _cupsGlobals();
486 char custom_name
[PPD_MAX_NAME
];
487 /* CustomFoo attribute name */
488 ppd_attr_t
*custom_attr
; /* CustomFoo attribute */
489 static const char * const ui_keywords
[] =
491 #ifdef CUPS_USE_FULL_UI_KEYWORDS_LIST
493 * Adobe defines some 41 keywords as "UI", meaning that they are
494 * user interface elements and that they should be treated as such
495 * even if the PPD creator doesn't use Open/CloseUI around them.
497 * Since this can cause previously invisible options to appear and
498 * confuse users, the default is to only treat the PageSize and
499 * PageRegion keywords this way.
501 /* Boolean keywords */
511 /* PickOne keywords */
524 "JCLFrameBufferSize",
545 #else /* !CUPS_USE_FULL_UI_KEYWORDS_LIST */
548 #endif /* CUPS_USE_FULL_UI_KEYWORDS_LIST */
552 DEBUG_printf(("ppdOpen2(fp=%p)", fp
));
555 * Default to "OK" status...
558 cg
->ppd_status
= PPD_OK
;
562 * Range check input...
567 cg
->ppd_status
= PPD_NULL_FILE
;
572 * Grab the first line and make sure it reads '*PPD-Adobe: "major.minor"'...
578 mask
= ppd_read(fp
, &line
, keyword
, name
, text
, &string
, 0, cg
);
580 DEBUG_printf(("2ppdOpen2: mask=%x, keyword=\"%s\"...", mask
, keyword
));
583 strcmp(keyword
, "PPD-Adobe") ||
584 string
== NULL
|| string
[0] != '4')
587 * Either this is not a PPD file, or it is not a 4.x PPD file.
590 if (cg
->ppd_status
== PPD_OK
)
591 cg
->ppd_status
= PPD_MISSING_PPDADOBE4
;
593 _cupsStrFree(string
);
594 ppd_free(line
.buffer
);
599 DEBUG_printf(("2ppdOpen2: keyword=%s, string=%p", keyword
, string
));
601 _cupsStrFree(string
);
604 * Allocate memory for the PPD file record...
607 if ((ppd
= calloc(1, sizeof(ppd_file_t
))) == NULL
)
609 cg
->ppd_status
= PPD_ALLOC_ERROR
;
611 _cupsStrFree(string
);
612 ppd_free(line
.buffer
);
617 ppd
->language_level
= 2;
618 ppd
->color_device
= 0;
619 ppd
->colorspace
= PPD_CS_N
;
620 ppd
->landscape
= -90;
621 ppd
->coptions
= cupsArrayNew((cups_array_func_t
)ppd_compare_coptions
,
625 * Get the default language for the user...
628 language
= cupsLangDefault();
632 * Read lines from the PPD file and add them to the file record...
640 encoding
= CUPS_ISO8859_1
;
642 while ((mask
= ppd_read(fp
, &line
, keyword
, name
, text
, &string
, 1, cg
)) != 0)
644 DEBUG_printf(("2ppdOpen2: mask=%x, keyword=\"%s\", name=\"%s\", "
645 "text=\"%s\", string=%d chars...", mask
, keyword
, name
, text
,
646 string
? (int)strlen(string
) : 0));
648 if (strncmp(keyword
, "Default", 7) && !string
&&
649 cg
->ppd_conform
!= PPD_CONFORM_RELAXED
)
652 * Need a string value!
655 cg
->ppd_status
= PPD_MISSING_VALUE
;
661 * Certain main keywords (as defined by the PPD spec) may be used
662 * without the usual OpenUI/CloseUI stuff. Presumably this is just
663 * so that Adobe wouldn't completely break compatibility with PPD
664 * files prior to v4.0 of the spec, but it is hopelessly
665 * inconsistent... Catch these main keywords and automatically
666 * create the corresponding option, as needed...
672 * Previous line was a UI keyword...
679 if (option
== NULL
&&
680 (mask
& (PPD_KEYWORD
| PPD_OPTION
| PPD_STRING
)) ==
681 (PPD_KEYWORD
| PPD_OPTION
| PPD_STRING
))
683 for (i
= 0; i
< (int)(sizeof(ui_keywords
) / sizeof(ui_keywords
[0])); i
++)
684 if (!strcmp(keyword
, ui_keywords
[i
]))
687 if (i
< (int)(sizeof(ui_keywords
) / sizeof(ui_keywords
[0])))
690 * Create the option in the appropriate group...
695 DEBUG_printf(("2ppdOpen2: FOUND ADOBE UI KEYWORD %s WITHOUT OPENUI!",
700 if ((group
= ppd_get_group(ppd
, "General", _("General"), cg
,
704 DEBUG_printf(("2ppdOpen2: Adding to group %s...", group
->text
));
705 option
= ppd_get_option(group
, keyword
);
709 option
= ppd_get_option(group
, keyword
);
713 cg
->ppd_status
= PPD_ALLOC_ERROR
;
719 * Now fill in the initial information for the option...
722 if (!strncmp(keyword
, "JCL", 3))
723 option
->section
= PPD_ORDER_JCL
;
725 option
->section
= PPD_ORDER_ANY
;
727 option
->order
= 10.0f
;
730 option
->ui
= PPD_UI_BOOLEAN
;
732 option
->ui
= PPD_UI_PICKONE
;
734 for (j
= 0; j
< ppd
->num_attrs
; j
++)
735 if (!strncmp(ppd
->attrs
[j
]->name
, "Default", 7) &&
736 !strcmp(ppd
->attrs
[j
]->name
+ 7, keyword
) &&
737 ppd
->attrs
[j
]->value
)
739 DEBUG_printf(("2ppdOpen2: Setting Default%s to %s via attribute...",
740 option
->keyword
, ppd
->attrs
[j
]->value
));
741 strlcpy(option
->defchoice
, ppd
->attrs
[j
]->value
,
742 sizeof(option
->defchoice
));
746 if (!strcmp(keyword
, "PageSize"))
747 strlcpy(option
->text
, _("Media Size"), sizeof(option
->text
));
748 else if (!strcmp(keyword
, "MediaType"))
749 strlcpy(option
->text
, _("Media Type"), sizeof(option
->text
));
750 else if (!strcmp(keyword
, "InputSlot"))
751 strlcpy(option
->text
, _("Media Source"), sizeof(option
->text
));
752 else if (!strcmp(keyword
, "ColorModel"))
753 strlcpy(option
->text
, _("Output Mode"), sizeof(option
->text
));
754 else if (!strcmp(keyword
, "Resolution"))
755 strlcpy(option
->text
, _("Resolution"), sizeof(option
->text
));
757 strlcpy(option
->text
, keyword
, sizeof(option
->text
));
761 if (!strcmp(keyword
, "LanguageLevel"))
762 ppd
->language_level
= atoi(string
);
763 else if (!strcmp(keyword
, "LanguageEncoding"))
766 * Say all PPD files are UTF-8, since we convert to UTF-8...
769 ppd
->lang_encoding
= _cupsStrAlloc("UTF-8");
770 encoding
= _ppdGetEncoding(string
);
772 else if (!strcmp(keyword
, "LanguageVersion"))
773 ppd
->lang_version
= string
;
774 else if (!strcmp(keyword
, "Manufacturer"))
775 ppd
->manufacturer
= string
;
776 else if (!strcmp(keyword
, "ModelName"))
777 ppd
->modelname
= string
;
778 else if (!strcmp(keyword
, "Protocols"))
779 ppd
->protocols
= string
;
780 else if (!strcmp(keyword
, "PCFileName"))
781 ppd
->pcfilename
= string
;
782 else if (!strcmp(keyword
, "NickName"))
784 if (encoding
!= CUPS_UTF8
)
786 cups_utf8_t utf8
[256]; /* UTF-8 version of NickName */
789 cupsCharsetToUTF8(utf8
, string
, sizeof(utf8
), encoding
);
790 ppd
->nickname
= _cupsStrAlloc((char *)utf8
);
793 ppd
->nickname
= _cupsStrAlloc(string
);
795 else if (!strcmp(keyword
, "Product"))
796 ppd
->product
= string
;
797 else if (!strcmp(keyword
, "ShortNickName"))
798 ppd
->shortnickname
= string
;
799 else if (!strcmp(keyword
, "TTRasterizer"))
800 ppd
->ttrasterizer
= string
;
801 else if (!strcmp(keyword
, "JCLBegin"))
803 ppd
->jcl_begin
= _cupsStrAlloc(string
);
804 ppd_decode(ppd
->jcl_begin
); /* Decode quoted string */
806 else if (!strcmp(keyword
, "JCLEnd"))
808 ppd
->jcl_end
= _cupsStrAlloc(string
);
809 ppd_decode(ppd
->jcl_end
); /* Decode quoted string */
811 else if (!strcmp(keyword
, "JCLToPSInterpreter"))
813 ppd
->jcl_ps
= _cupsStrAlloc(string
);
814 ppd_decode(ppd
->jcl_ps
); /* Decode quoted string */
816 else if (!strcmp(keyword
, "AccurateScreensSupport"))
817 ppd
->accurate_screens
= !strcmp(string
, "True");
818 else if (!strcmp(keyword
, "ColorDevice"))
819 ppd
->color_device
= !strcmp(string
, "True");
820 else if (!strcmp(keyword
, "ContoneOnly"))
821 ppd
->contone_only
= !strcmp(string
, "True");
822 else if (!strcmp(keyword
, "cupsFlipDuplex"))
823 ppd
->flip_duplex
= !strcmp(string
, "True");
824 else if (!strcmp(keyword
, "cupsManualCopies"))
825 ppd
->manual_copies
= !strcmp(string
, "True");
826 else if (!strcmp(keyword
, "cupsModelNumber"))
827 ppd
->model_number
= atoi(string
);
828 else if (!strcmp(keyword
, "cupsColorProfile"))
830 if (ppd
->num_profiles
== 0)
831 profile
= malloc(sizeof(ppd_profile_t
));
833 profile
= realloc(ppd
->profiles
, sizeof(ppd_profile_t
) *
834 (ppd
->num_profiles
+ 1));
838 cg
->ppd_status
= PPD_ALLOC_ERROR
;
843 ppd
->profiles
= profile
;
844 profile
+= ppd
->num_profiles
;
845 ppd
->num_profiles
++;
847 memset(profile
, 0, sizeof(ppd_profile_t
));
848 strlcpy(profile
->resolution
, name
, sizeof(profile
->resolution
));
849 strlcpy(profile
->media_type
, text
, sizeof(profile
->media_type
));
851 profile
->density
= (float)_cupsStrScand(string
, &sptr
, loc
);
852 profile
->gamma
= (float)_cupsStrScand(sptr
, &sptr
, loc
);
853 profile
->matrix
[0][0] = (float)_cupsStrScand(sptr
, &sptr
, loc
);
854 profile
->matrix
[0][1] = (float)_cupsStrScand(sptr
, &sptr
, loc
);
855 profile
->matrix
[0][2] = (float)_cupsStrScand(sptr
, &sptr
, loc
);
856 profile
->matrix
[1][0] = (float)_cupsStrScand(sptr
, &sptr
, loc
);
857 profile
->matrix
[1][1] = (float)_cupsStrScand(sptr
, &sptr
, loc
);
858 profile
->matrix
[1][2] = (float)_cupsStrScand(sptr
, &sptr
, loc
);
859 profile
->matrix
[2][0] = (float)_cupsStrScand(sptr
, &sptr
, loc
);
860 profile
->matrix
[2][1] = (float)_cupsStrScand(sptr
, &sptr
, loc
);
861 profile
->matrix
[2][2] = (float)_cupsStrScand(sptr
, &sptr
, loc
);
863 else if (!strcmp(keyword
, "cupsFilter"))
865 if (ppd
->num_filters
== 0)
866 filter
= malloc(sizeof(char *));
868 filter
= realloc(ppd
->filters
, sizeof(char *) * (ppd
->num_filters
+ 1));
872 cg
->ppd_status
= PPD_ALLOC_ERROR
;
877 ppd
->filters
= filter
;
878 filter
+= ppd
->num_filters
;
882 * Copy filter string and prevent it from being freed below...
888 else if (!strcmp(keyword
, "Throughput"))
889 ppd
->throughput
= atoi(string
);
890 else if (!strcmp(keyword
, "Font"))
893 * Add this font to the list of available fonts...
896 if (ppd
->num_fonts
== 0)
897 tempfonts
= (char **)malloc(sizeof(char *));
899 tempfonts
= (char **)realloc(ppd
->fonts
,
900 sizeof(char *) * (ppd
->num_fonts
+ 1));
902 if (tempfonts
== NULL
)
904 cg
->ppd_status
= PPD_ALLOC_ERROR
;
909 ppd
->fonts
= tempfonts
;
910 ppd
->fonts
[ppd
->num_fonts
] = _cupsStrAlloc(name
);
913 else if (!strncmp(keyword
, "ParamCustom", 11))
915 ppd_coption_t
*coption
; /* Custom option */
916 ppd_cparam_t
*cparam
; /* Custom parameter */
917 int corder
; /* Order number */
918 char ctype
[33], /* Data type */
919 cminimum
[65], /* Minimum value */
920 cmaximum
[65]; /* Maximum value */
924 * Get the custom option and parameter...
927 if ((coption
= ppd_get_coption(ppd
, keyword
+ 11)) == NULL
)
929 cg
->ppd_status
= PPD_ALLOC_ERROR
;
934 if ((cparam
= ppd_get_cparam(coption
, name
, text
)) == NULL
)
936 cg
->ppd_status
= PPD_ALLOC_ERROR
;
942 * Get the parameter data...
945 if (sscanf(string
, "%d%32s%64s%64s", &corder
, ctype
, cminimum
,
948 cg
->ppd_status
= PPD_BAD_CUSTOM_PARAM
;
953 cparam
->order
= corder
;
955 if (!strcmp(ctype
, "curve"))
957 cparam
->type
= PPD_CUSTOM_CURVE
;
958 cparam
->minimum
.custom_curve
= (float)_cupsStrScand(cminimum
, NULL
, loc
);
959 cparam
->maximum
.custom_curve
= (float)_cupsStrScand(cmaximum
, NULL
, loc
);
961 else if (!strcmp(ctype
, "int"))
963 cparam
->type
= PPD_CUSTOM_INT
;
964 cparam
->minimum
.custom_int
= atoi(cminimum
);
965 cparam
->maximum
.custom_int
= atoi(cmaximum
);
967 else if (!strcmp(ctype
, "invcurve"))
969 cparam
->type
= PPD_CUSTOM_INVCURVE
;
970 cparam
->minimum
.custom_invcurve
= (float)_cupsStrScand(cminimum
, NULL
, loc
);
971 cparam
->maximum
.custom_invcurve
= (float)_cupsStrScand(cmaximum
, NULL
, loc
);
973 else if (!strcmp(ctype
, "passcode"))
975 cparam
->type
= PPD_CUSTOM_PASSCODE
;
976 cparam
->minimum
.custom_passcode
= atoi(cminimum
);
977 cparam
->maximum
.custom_passcode
= atoi(cmaximum
);
979 else if (!strcmp(ctype
, "password"))
981 cparam
->type
= PPD_CUSTOM_PASSWORD
;
982 cparam
->minimum
.custom_password
= atoi(cminimum
);
983 cparam
->maximum
.custom_password
= atoi(cmaximum
);
985 else if (!strcmp(ctype
, "points"))
987 cparam
->type
= PPD_CUSTOM_POINTS
;
988 cparam
->minimum
.custom_points
= (float)_cupsStrScand(cminimum
, NULL
, loc
);
989 cparam
->maximum
.custom_points
= (float)_cupsStrScand(cmaximum
, NULL
, loc
);
991 else if (!strcmp(ctype
, "real"))
993 cparam
->type
= PPD_CUSTOM_REAL
;
994 cparam
->minimum
.custom_real
= (float)_cupsStrScand(cminimum
, NULL
, loc
);
995 cparam
->maximum
.custom_real
= (float)_cupsStrScand(cmaximum
, NULL
, loc
);
997 else if (!strcmp(ctype
, "string"))
999 cparam
->type
= PPD_CUSTOM_STRING
;
1000 cparam
->minimum
.custom_string
= atoi(cminimum
);
1001 cparam
->maximum
.custom_string
= atoi(cmaximum
);
1005 cg
->ppd_status
= PPD_BAD_CUSTOM_PARAM
;
1011 * Now special-case for CustomPageSize...
1014 if (!strcmp(coption
->keyword
, "PageSize"))
1016 if (!strcmp(name
, "Width"))
1018 ppd
->custom_min
[0] = cparam
->minimum
.custom_points
;
1019 ppd
->custom_max
[0] = cparam
->maximum
.custom_points
;
1021 else if (!strcmp(name
, "Height"))
1023 ppd
->custom_min
[1] = cparam
->minimum
.custom_points
;
1024 ppd
->custom_max
[1] = cparam
->maximum
.custom_points
;
1028 else if (!strcmp(keyword
, "HWMargins"))
1030 for (i
= 0, sptr
= string
; i
< 4; i
++)
1031 ppd
->custom_margins
[i
] = (float)_cupsStrScand(sptr
, &sptr
, loc
);
1033 else if (!strncmp(keyword
, "Custom", 6) && !strcmp(name
, "True") && !option
)
1035 ppd_option_t
*custom_option
; /* Custom option */
1037 DEBUG_puts("2ppdOpen2: Processing Custom option...");
1040 * Get the option and custom option...
1043 if (!ppd_get_coption(ppd
, keyword
+ 6))
1045 cg
->ppd_status
= PPD_ALLOC_ERROR
;
1050 if (option
&& !strcasecmp(option
->keyword
, keyword
+ 6))
1051 custom_option
= option
;
1053 custom_option
= ppdFindOption(ppd
, keyword
+ 6);
1058 * Add the "custom" option...
1061 if ((choice
= ppdFindChoice(custom_option
, "Custom")) == NULL
)
1062 if ((choice
= ppd_add_choice(custom_option
, "Custom")) == NULL
)
1064 DEBUG_puts("1ppdOpen2: Unable to add Custom choice!");
1066 cg
->ppd_status
= PPD_ALLOC_ERROR
;
1071 strlcpy(choice
->text
, text
[0] ? text
: _("Custom"),
1072 sizeof(choice
->text
));
1074 choice
->code
= _cupsStrAlloc(string
);
1076 if (custom_option
->section
== PPD_ORDER_JCL
)
1077 ppd_decode(choice
->code
);
1081 * Now process custom page sizes specially...
1084 if (!strcmp(keyword
, "CustomPageSize"))
1087 * Add a "Custom" page size entry...
1090 ppd
->variable_sizes
= 1;
1092 ppd_add_size(ppd
, "Custom");
1094 if (option
&& !strcasecmp(option
->keyword
, "PageRegion"))
1095 custom_option
= option
;
1097 custom_option
= ppdFindOption(ppd
, "PageRegion");
1101 if ((choice
= ppdFindChoice(custom_option
, "Custom")) == NULL
)
1102 if ((choice
= ppd_add_choice(custom_option
, "Custom")) == NULL
)
1104 DEBUG_puts("1ppdOpen2: Unable to add Custom choice!");
1106 cg
->ppd_status
= PPD_ALLOC_ERROR
;
1111 strlcpy(choice
->text
, text
[0] ? text
: _("Custom"),
1112 sizeof(choice
->text
));
1116 else if (!strcmp(keyword
, "LandscapeOrientation"))
1118 if (!strcmp(string
, "Minus90"))
1119 ppd
->landscape
= -90;
1120 else if (!strcmp(string
, "Plus90"))
1121 ppd
->landscape
= 90;
1123 else if (!strcmp(keyword
, "Emulators") && string
)
1125 for (count
= 1, sptr
= string
; sptr
!= NULL
;)
1126 if ((sptr
= strchr(sptr
, ' ')) != NULL
)
1129 while (*sptr
== ' ')
1133 ppd
->num_emulations
= count
;
1134 if ((ppd
->emulations
= calloc(count
, sizeof(ppd_emul_t
))) == NULL
)
1136 cg
->ppd_status
= PPD_ALLOC_ERROR
;
1141 for (i
= 0, sptr
= string
; i
< count
; i
++)
1143 for (nameptr
= ppd
->emulations
[i
].name
;
1144 *sptr
!= '\0' && *sptr
!= ' ';
1146 if (nameptr
< (ppd
->emulations
[i
].name
+ sizeof(ppd
->emulations
[i
].name
) - 1))
1151 while (*sptr
== ' ')
1155 else if (!strncmp(keyword
, "StartEmulator_", 14))
1159 for (i
= 0; i
< ppd
->num_emulations
; i
++)
1160 if (!strcmp(keyword
+ 14, ppd
->emulations
[i
].name
))
1162 ppd
->emulations
[i
].start
= string
;
1166 else if (!strncmp(keyword
, "StopEmulator_", 13))
1170 for (i
= 0; i
< ppd
->num_emulations
; i
++)
1171 if (!strcmp(keyword
+ 13, ppd
->emulations
[i
].name
))
1173 ppd
->emulations
[i
].stop
= string
;
1177 else if (!strcmp(keyword
, "JobPatchFile"))
1179 if (ppd
->patches
== NULL
)
1180 ppd
->patches
= strdup(string
);
1183 temp
= realloc(ppd
->patches
, strlen(ppd
->patches
) +
1184 strlen(string
) + 1);
1187 cg
->ppd_status
= PPD_ALLOC_ERROR
;
1192 ppd
->patches
= temp
;
1194 strcpy(ppd
->patches
+ strlen(ppd
->patches
), string
);
1197 else if (!strcmp(keyword
, "OpenUI"))
1200 * Don't allow nesting of options...
1203 if (option
&& cg
->ppd_conform
== PPD_CONFORM_STRICT
)
1205 cg
->ppd_status
= PPD_NESTED_OPEN_UI
;
1211 * Add an option record to the current sub-group, group, or file...
1214 DEBUG_printf(("2ppdOpen2: name=\"%s\" (%d)", name
, (int)strlen(name
)));
1217 _cups_strcpy(name
, name
+ 1); /* Eliminate leading asterisk */
1219 for (i
= (int)strlen(name
) - 1; i
> 0 && isspace(name
[i
] & 255); i
--)
1220 name
[i
] = '\0'; /* Eliminate trailing spaces */
1222 DEBUG_printf(("2ppdOpen2: OpenUI of %s in group %s...", name
,
1223 group
? group
->text
: "(null)"));
1225 if (subgroup
!= NULL
)
1226 option
= ppd_get_option(subgroup
, name
);
1227 else if (group
== NULL
)
1229 if ((group
= ppd_get_group(ppd
, "General", _("General"), cg
,
1233 DEBUG_printf(("2ppdOpen2: Adding to group %s...", group
->text
));
1234 option
= ppd_get_option(group
, name
);
1238 option
= ppd_get_option(group
, name
);
1242 cg
->ppd_status
= PPD_ALLOC_ERROR
;
1248 * Now fill in the initial information for the option...
1251 if (string
&& !strcmp(string
, "PickMany"))
1252 option
->ui
= PPD_UI_PICKMANY
;
1253 else if (string
&& !strcmp(string
, "Boolean"))
1254 option
->ui
= PPD_UI_BOOLEAN
;
1255 else if (string
&& !strcmp(string
, "PickOne"))
1256 option
->ui
= PPD_UI_PICKONE
;
1257 else if (cg
->ppd_conform
== PPD_CONFORM_STRICT
)
1259 cg
->ppd_status
= PPD_BAD_OPEN_UI
;
1264 option
->ui
= PPD_UI_PICKONE
;
1266 for (j
= 0; j
< ppd
->num_attrs
; j
++)
1267 if (!strncmp(ppd
->attrs
[j
]->name
, "Default", 7) &&
1268 !strcmp(ppd
->attrs
[j
]->name
+ 7, name
) &&
1269 ppd
->attrs
[j
]->value
)
1271 DEBUG_printf(("2ppdOpen2: Setting Default%s to %s via attribute...",
1272 option
->keyword
, ppd
->attrs
[j
]->value
));
1273 strlcpy(option
->defchoice
, ppd
->attrs
[j
]->value
,
1274 sizeof(option
->defchoice
));
1279 cupsCharsetToUTF8((cups_utf8_t
*)option
->text
, text
,
1280 sizeof(option
->text
), encoding
);
1283 if (!strcmp(name
, "PageSize"))
1284 strlcpy(option
->text
, _("Media Size"), sizeof(option
->text
));
1285 else if (!strcmp(name
, "MediaType"))
1286 strlcpy(option
->text
, _("Media Type"), sizeof(option
->text
));
1287 else if (!strcmp(name
, "InputSlot"))
1288 strlcpy(option
->text
, _("Media Source"), sizeof(option
->text
));
1289 else if (!strcmp(name
, "ColorModel"))
1290 strlcpy(option
->text
, _("Output Mode"), sizeof(option
->text
));
1291 else if (!strcmp(name
, "Resolution"))
1292 strlcpy(option
->text
, _("Resolution"), sizeof(option
->text
));
1294 strlcpy(option
->text
, name
, sizeof(option
->text
));
1297 option
->section
= PPD_ORDER_ANY
;
1299 _cupsStrFree(string
);
1303 * Add a custom option choice if we have already seen a CustomFoo
1307 if (!strcasecmp(name
, "PageRegion"))
1308 strcpy(custom_name
, "CustomPageSize");
1310 snprintf(custom_name
, sizeof(custom_name
), "Custom%s", name
);
1312 if ((custom_attr
= ppdFindAttr(ppd
, custom_name
, "True")) != NULL
)
1314 if ((choice
= ppdFindChoice(option
, "Custom")) == NULL
)
1315 if ((choice
= ppd_add_choice(option
, "Custom")) == NULL
)
1317 DEBUG_puts("1ppdOpen2: Unable to add Custom choice!");
1319 cg
->ppd_status
= PPD_ALLOC_ERROR
;
1324 strlcpy(choice
->text
,
1325 custom_attr
->text
[0] ? custom_attr
->text
: _("Custom"),
1326 sizeof(choice
->text
));
1327 choice
->code
= _cupsStrRetain(custom_attr
->value
);
1330 else if (!strcmp(keyword
, "JCLOpenUI"))
1333 * Don't allow nesting of options...
1336 if (option
&& cg
->ppd_conform
== PPD_CONFORM_STRICT
)
1338 cg
->ppd_status
= PPD_NESTED_OPEN_UI
;
1344 * Find the JCL group, and add if needed...
1347 group
= ppd_get_group(ppd
, "JCL", _("JCL"), cg
, encoding
);
1353 * Add an option record to the current JCLs...
1357 _cups_strcpy(name
, name
+ 1);
1359 option
= ppd_get_option(group
, name
);
1363 cg
->ppd_status
= PPD_ALLOC_ERROR
;
1369 * Now fill in the initial information for the option...
1372 if (string
&& !strcmp(string
, "PickMany"))
1373 option
->ui
= PPD_UI_PICKMANY
;
1374 else if (string
&& !strcmp(string
, "Boolean"))
1375 option
->ui
= PPD_UI_BOOLEAN
;
1376 else if (string
&& !strcmp(string
, "PickOne"))
1377 option
->ui
= PPD_UI_PICKONE
;
1380 cg
->ppd_status
= PPD_BAD_OPEN_UI
;
1385 for (j
= 0; j
< ppd
->num_attrs
; j
++)
1386 if (!strncmp(ppd
->attrs
[j
]->name
, "Default", 7) &&
1387 !strcmp(ppd
->attrs
[j
]->name
+ 7, name
) &&
1388 ppd
->attrs
[j
]->value
)
1390 DEBUG_printf(("2ppdOpen2: Setting Default%s to %s via attribute...",
1391 option
->keyword
, ppd
->attrs
[j
]->value
));
1392 strlcpy(option
->defchoice
, ppd
->attrs
[j
]->value
,
1393 sizeof(option
->defchoice
));
1398 cupsCharsetToUTF8((cups_utf8_t
*)option
->text
, text
,
1399 sizeof(option
->text
), encoding
);
1401 strlcpy(option
->text
, name
, sizeof(option
->text
));
1403 option
->section
= PPD_ORDER_JCL
;
1406 _cupsStrFree(string
);
1410 * Add a custom option choice if we have already seen a CustomFoo
1414 snprintf(custom_name
, sizeof(custom_name
), "Custom%s", name
);
1416 if ((custom_attr
= ppdFindAttr(ppd
, custom_name
, "True")) != NULL
)
1418 if ((choice
= ppd_add_choice(option
, "Custom")) == NULL
)
1420 DEBUG_puts("1ppdOpen2: Unable to add Custom choice!");
1422 cg
->ppd_status
= PPD_ALLOC_ERROR
;
1427 strlcpy(choice
->text
,
1428 custom_attr
->text
[0] ? custom_attr
->text
: _("Custom"),
1429 sizeof(choice
->text
));
1430 choice
->code
= _cupsStrRetain(custom_attr
->value
);
1433 else if (!strcmp(keyword
, "CloseUI") || !strcmp(keyword
, "JCLCloseUI"))
1437 _cupsStrFree(string
);
1440 else if (!strcmp(keyword
, "OpenGroup"))
1443 * Open a new group...
1448 cg
->ppd_status
= PPD_NESTED_OPEN_GROUP
;
1455 cg
->ppd_status
= PPD_BAD_OPEN_GROUP
;
1461 * Separate the group name from the text (name/text)...
1464 if ((sptr
= strchr(string
, '/')) != NULL
)
1470 * Fix up the text...
1476 * Find/add the group...
1479 group
= ppd_get_group(ppd
, string
, sptr
, cg
, encoding
);
1484 _cupsStrFree(string
);
1487 else if (!strcmp(keyword
, "CloseGroup"))
1491 _cupsStrFree(string
);
1494 else if (!strcmp(keyword
, "OrderDependency"))
1496 order
= (float)_cupsStrScand(string
, &sptr
, loc
);
1498 if (!sptr
|| sscanf(sptr
, "%40s%40s", name
, keyword
) != 2)
1500 cg
->ppd_status
= PPD_BAD_ORDER_DEPENDENCY
;
1505 if (keyword
[0] == '*')
1506 _cups_strcpy(keyword
, keyword
+ 1);
1508 if (!strcmp(name
, "ExitServer"))
1509 section
= PPD_ORDER_EXIT
;
1510 else if (!strcmp(name
, "Prolog"))
1511 section
= PPD_ORDER_PROLOG
;
1512 else if (!strcmp(name
, "DocumentSetup"))
1513 section
= PPD_ORDER_DOCUMENT
;
1514 else if (!strcmp(name
, "PageSetup"))
1515 section
= PPD_ORDER_PAGE
;
1516 else if (!strcmp(name
, "JCLSetup"))
1517 section
= PPD_ORDER_JCL
;
1519 section
= PPD_ORDER_ANY
;
1527 * Only valid for Non-UI options...
1530 for (i
= ppd
->num_groups
, gtemp
= ppd
->groups
; i
> 0; i
--, gtemp
++)
1531 if (gtemp
->text
[0] == '\0')
1535 for (i
= 0; i
< gtemp
->num_options
; i
++)
1536 if (!strcmp(keyword
, gtemp
->options
[i
].keyword
))
1538 gtemp
->options
[i
].section
= section
;
1539 gtemp
->options
[i
].order
= order
;
1545 option
->section
= section
;
1546 option
->order
= order
;
1549 _cupsStrFree(string
);
1552 else if (!strncmp(keyword
, "Default", 7))
1558 * Drop UI text, if any, from value...
1561 if (strchr(string
, '/') != NULL
)
1562 *strchr(string
, '/') = '\0';
1565 * Assign the default value as appropriate...
1568 if (!strcmp(keyword
, "DefaultColorSpace"))
1571 * Set default colorspace...
1574 if (!strcmp(string
, "CMY"))
1575 ppd
->colorspace
= PPD_CS_CMY
;
1576 else if (!strcmp(string
, "CMYK"))
1577 ppd
->colorspace
= PPD_CS_CMYK
;
1578 else if (!strcmp(string
, "RGB"))
1579 ppd
->colorspace
= PPD_CS_RGB
;
1580 else if (!strcmp(string
, "RGBK"))
1581 ppd
->colorspace
= PPD_CS_RGBK
;
1582 else if (!strcmp(string
, "N"))
1583 ppd
->colorspace
= PPD_CS_N
;
1585 ppd
->colorspace
= PPD_CS_GRAY
;
1587 else if (option
&& !strcmp(keyword
+ 7, option
->keyword
))
1590 * Set the default as part of the current option...
1593 DEBUG_printf(("2ppdOpen2: Setting %s to %s...", keyword
, string
));
1595 strlcpy(option
->defchoice
, string
, sizeof(option
->defchoice
));
1597 DEBUG_printf(("2ppdOpen2: %s is now %s...", keyword
, option
->defchoice
));
1602 * Lookup option and set if it has been defined...
1605 ppd_option_t
*toption
; /* Temporary option */
1608 if ((toption
= ppdFindOption(ppd
, keyword
+ 7)) != NULL
)
1610 DEBUG_printf(("2ppdOpen2: Setting %s to %s...", keyword
, string
));
1611 strlcpy(toption
->defchoice
, string
, sizeof(toption
->defchoice
));
1615 else if (!strcmp(keyword
, "UIConstraints") ||
1616 !strcmp(keyword
, "NonUIConstraints"))
1618 if (ppd
->num_consts
== 0)
1619 constraint
= calloc(2, sizeof(ppd_const_t
));
1621 constraint
= realloc(ppd
->consts
,
1622 (ppd
->num_consts
+ 2) * sizeof(ppd_const_t
));
1624 if (constraint
== NULL
)
1626 cg
->ppd_status
= PPD_ALLOC_ERROR
;
1631 ppd
->consts
= constraint
;
1632 constraint
+= ppd
->num_consts
;
1635 switch (sscanf(string
, "%40s%40s%40s%40s", constraint
->option1
,
1636 constraint
->choice1
, constraint
->option2
,
1637 constraint
->choice2
))
1639 case 0 : /* Error */
1640 case 1 : /* Error */
1641 cg
->ppd_status
= PPD_BAD_UI_CONSTRAINTS
;
1644 case 2 : /* Two options... */
1646 * Check for broken constraints like "* Option"...
1649 if (cg
->ppd_conform
== PPD_CONFORM_STRICT
&&
1650 (!strcmp(constraint
->option1
, "*") ||
1651 !strcmp(constraint
->choice1
, "*")))
1653 cg
->ppd_status
= PPD_BAD_UI_CONSTRAINTS
;
1658 * The following strcpy's are safe, as optionN and
1659 * choiceN are all the same size (size defined by PPD spec...)
1662 if (constraint
->option1
[0] == '*')
1663 _cups_strcpy(constraint
->option1
, constraint
->option1
+ 1);
1664 else if (cg
->ppd_conform
== PPD_CONFORM_STRICT
)
1666 cg
->ppd_status
= PPD_BAD_UI_CONSTRAINTS
;
1670 if (constraint
->choice1
[0] == '*')
1671 _cups_strcpy(constraint
->option2
, constraint
->choice1
+ 1);
1672 else if (cg
->ppd_conform
== PPD_CONFORM_STRICT
)
1674 cg
->ppd_status
= PPD_BAD_UI_CONSTRAINTS
;
1678 constraint
->choice1
[0] = '\0';
1679 constraint
->choice2
[0] = '\0';
1682 case 3 : /* Two options, one choice... */
1684 * Check for broken constraints like "* Option"...
1687 if (cg
->ppd_conform
== PPD_CONFORM_STRICT
&&
1688 (!strcmp(constraint
->option1
, "*") ||
1689 !strcmp(constraint
->choice1
, "*") ||
1690 !strcmp(constraint
->option2
, "*")))
1692 cg
->ppd_status
= PPD_BAD_UI_CONSTRAINTS
;
1697 * The following _cups_strcpy's are safe, as optionN and
1698 * choiceN are all the same size (size defined by PPD spec...)
1701 if (constraint
->option1
[0] == '*')
1702 _cups_strcpy(constraint
->option1
, constraint
->option1
+ 1);
1703 else if (cg
->ppd_conform
== PPD_CONFORM_STRICT
)
1705 cg
->ppd_status
= PPD_BAD_UI_CONSTRAINTS
;
1709 if (constraint
->choice1
[0] == '*')
1711 if (cg
->ppd_conform
== PPD_CONFORM_STRICT
&&
1712 constraint
->option2
[0] == '*')
1714 cg
->ppd_status
= PPD_BAD_UI_CONSTRAINTS
;
1718 _cups_strcpy(constraint
->choice2
, constraint
->option2
);
1719 _cups_strcpy(constraint
->option2
, constraint
->choice1
+ 1);
1720 constraint
->choice1
[0] = '\0';
1724 if (constraint
->option2
[0] == '*')
1725 _cups_strcpy(constraint
->option2
, constraint
->option2
+ 1);
1726 else if (cg
->ppd_conform
== PPD_CONFORM_STRICT
)
1728 cg
->ppd_status
= PPD_BAD_UI_CONSTRAINTS
;
1732 constraint
->choice2
[0] = '\0';
1736 case 4 : /* Two options, two choices... */
1738 * Check for broken constraints like "* Option"...
1741 if (cg
->ppd_conform
== PPD_CONFORM_STRICT
&&
1742 (!strcmp(constraint
->option1
, "*") ||
1743 !strcmp(constraint
->choice1
, "*") ||
1744 !strcmp(constraint
->option2
, "*") ||
1745 !strcmp(constraint
->choice2
, "*")))
1747 cg
->ppd_status
= PPD_BAD_UI_CONSTRAINTS
;
1751 if (constraint
->option1
[0] == '*')
1752 _cups_strcpy(constraint
->option1
, constraint
->option1
+ 1);
1753 else if (cg
->ppd_conform
== PPD_CONFORM_STRICT
)
1755 cg
->ppd_status
= PPD_BAD_UI_CONSTRAINTS
;
1759 if (cg
->ppd_conform
== PPD_CONFORM_STRICT
&&
1760 constraint
->choice1
[0] == '*')
1762 cg
->ppd_status
= PPD_BAD_UI_CONSTRAINTS
;
1766 if (constraint
->option2
[0] == '*')
1767 _cups_strcpy(constraint
->option2
, constraint
->option2
+ 1);
1768 else if (cg
->ppd_conform
== PPD_CONFORM_STRICT
)
1770 cg
->ppd_status
= PPD_BAD_UI_CONSTRAINTS
;
1774 if (cg
->ppd_conform
== PPD_CONFORM_STRICT
&&
1775 constraint
->choice2
[0] == '*')
1777 cg
->ppd_status
= PPD_BAD_UI_CONSTRAINTS
;
1784 * Don't add this one as an attribute...
1787 _cupsStrFree(string
);
1790 else if (!strcmp(keyword
, "PaperDimension"))
1792 if ((size
= ppdPageSize(ppd
, name
)) == NULL
)
1793 size
= ppd_add_size(ppd
, name
);
1798 * Unable to add or find size!
1801 cg
->ppd_status
= PPD_ALLOC_ERROR
;
1806 size
->width
= (float)_cupsStrScand(string
, &sptr
, loc
);
1807 size
->length
= (float)_cupsStrScand(sptr
, NULL
, loc
);
1809 _cupsStrFree(string
);
1812 else if (!strcmp(keyword
, "ImageableArea"))
1814 if ((size
= ppdPageSize(ppd
, name
)) == NULL
)
1815 size
= ppd_add_size(ppd
, name
);
1820 * Unable to add or find size!
1823 cg
->ppd_status
= PPD_ALLOC_ERROR
;
1828 size
->left
= (float)_cupsStrScand(string
, &sptr
, loc
);
1829 size
->bottom
= (float)_cupsStrScand(sptr
, &sptr
, loc
);
1830 size
->right
= (float)_cupsStrScand(sptr
, &sptr
, loc
);
1831 size
->top
= (float)_cupsStrScand(sptr
, NULL
, loc
);
1833 _cupsStrFree(string
);
1836 else if (option
!= NULL
&&
1837 (mask
& (PPD_KEYWORD
| PPD_OPTION
| PPD_STRING
)) ==
1838 (PPD_KEYWORD
| PPD_OPTION
| PPD_STRING
) &&
1839 !strcmp(keyword
, option
->keyword
))
1841 DEBUG_printf(("2ppdOpen2: group=%p, subgroup=%p", group
, subgroup
));
1843 if (!strcmp(keyword
, "PageSize"))
1846 * Add a page size...
1849 if (ppdPageSize(ppd
, name
) == NULL
)
1850 ppd_add_size(ppd
, name
);
1854 * Add the option choice...
1857 if ((choice
= ppd_add_choice(option
, name
)) == NULL
)
1859 cg
->ppd_status
= PPD_ALLOC_ERROR
;
1865 cupsCharsetToUTF8((cups_utf8_t
*)choice
->text
, text
,
1866 sizeof(choice
->text
), encoding
);
1867 else if (!strcmp(name
, "True"))
1868 strcpy(choice
->text
, _("Yes"));
1869 else if (!strcmp(name
, "False"))
1870 strcpy(choice
->text
, _("No"));
1872 strlcpy(choice
->text
, name
, sizeof(choice
->text
));
1874 if (option
->section
== PPD_ORDER_JCL
)
1875 ppd_decode(string
); /* Decode quoted string */
1877 choice
->code
= string
;
1878 string
= NULL
; /* Don't add as an attribute below */
1882 * Add remaining lines with keywords and string values as attributes...
1886 (mask
& (PPD_KEYWORD
| PPD_STRING
)) == (PPD_KEYWORD
| PPD_STRING
))
1887 ppd_add_attr(ppd
, keyword
, name
, text
, string
);
1889 _cupsStrFree(string
);
1892 ppd_free(line
.buffer
);
1895 * Reset language preferences...
1898 cupsLangFree(language
);
1901 if (!cupsFileEOF(fp
))
1902 DEBUG_printf(("1ppdOpen2: Premature EOF at %lu...\n",
1903 (unsigned long)cupsFileTell(fp
)));
1906 if (cg
->ppd_status
!= PPD_OK
)
1909 * Had an error reading the PPD file, cannot continue!
1918 * Create the sorted options array and set the option back-pointer for
1919 * each choice and custom option...
1922 ppd
->options
= cupsArrayNew2((cups_array_func_t
)ppd_compare_options
, NULL
,
1923 (cups_ahash_func_t
)ppd_hash_option
,
1926 for (i
= ppd
->num_groups
, group
= ppd
->groups
;
1930 for (j
= group
->num_options
, option
= group
->options
;
1934 ppd_coption_t
*coption
; /* Custom option */
1937 cupsArrayAdd(ppd
->options
, option
);
1939 for (k
= 0; k
< option
->num_choices
; k
++)
1940 option
->choices
[k
].option
= option
;
1942 if ((coption
= ppdFindCustomOption(ppd
, option
->keyword
)) != NULL
)
1943 coption
->option
= option
;
1948 * Create an array to track the marked choices...
1951 ppd
->marked
= cupsArrayNew((cups_array_func_t
)ppd_compare_choices
, NULL
);
1954 * Return the PPD file structure...
1960 * Common exit point for errors to save code size...
1965 _cupsStrFree(string
);
1966 ppd_free(line
.buffer
);
1970 cupsLangFree(language
);
1977 * 'ppdOpenFd()' - Read a PPD file into memory.
1980 ppd_file_t
* /* O - PPD file record or @code NULL@ if the PPD file could not be opened. */
1981 ppdOpenFd(int fd
) /* I - File to read from */
1983 cups_file_t
*fp
; /* CUPS file pointer */
1984 ppd_file_t
*ppd
; /* PPD file record */
1985 _cups_globals_t
*cg
= _cupsGlobals();
1990 * Set the line number to 0...
1996 * Range check input...
2001 cg
->ppd_status
= PPD_NULL_FILE
;
2007 * Try to open the file and parse it...
2010 if ((fp
= cupsFileOpenFd(fd
, "r")) != NULL
)
2018 cg
->ppd_status
= PPD_FILE_OPEN_ERROR
;
2027 * 'ppdOpenFile()' - Read a PPD file into memory.
2030 ppd_file_t
* /* O - PPD file record or @code NULL@ if the PPD file could not be opened. */
2031 ppdOpenFile(const char *filename
) /* I - File to read from */
2033 cups_file_t
*fp
; /* File pointer */
2034 ppd_file_t
*ppd
; /* PPD file record */
2035 _cups_globals_t
*cg
= _cupsGlobals();
2040 * Set the line number to 0...
2046 * Range check input...
2049 if (filename
== NULL
)
2051 cg
->ppd_status
= PPD_NULL_FILE
;
2057 * Try to open the file and parse it...
2060 if ((fp
= cupsFileOpen(filename
, "r")) != NULL
)
2068 cg
->ppd_status
= PPD_FILE_OPEN_ERROR
;
2077 * 'ppdSetConformance()' - Set the conformance level for PPD files.
2079 * @since CUPS 1.1.20/Mac OS X 10.4@
2083 ppdSetConformance(ppd_conform_t c
) /* I - Conformance level */
2085 _cups_globals_t
*cg
= _cupsGlobals();
2089 cg
->ppd_conform
= c
;
2094 * 'ppd_add_attr()' - Add an attribute to the PPD data.
2097 static ppd_attr_t
* /* O - New attribute */
2098 ppd_add_attr(ppd_file_t
*ppd
, /* I - PPD file data */
2099 const char *name
, /* I - Attribute name */
2100 const char *spec
, /* I - Specifier string, if any */
2101 const char *text
, /* I - Text string, if any */
2102 const char *value
) /* I - Value of attribute */
2104 ppd_attr_t
**ptr
, /* New array */
2105 *temp
; /* New attribute */
2109 * Range check input...
2112 if (ppd
== NULL
|| name
== NULL
|| spec
== NULL
)
2116 * Create the array as needed...
2119 if (!ppd
->sorted_attrs
)
2120 ppd
->sorted_attrs
= cupsArrayNew((cups_array_func_t
)ppd_compare_attrs
,
2124 * Allocate memory for the new attribute...
2127 if (ppd
->num_attrs
== 0)
2128 ptr
= malloc(sizeof(ppd_attr_t
*));
2130 ptr
= realloc(ppd
->attrs
, (ppd
->num_attrs
+ 1) * sizeof(ppd_attr_t
*));
2136 ptr
+= ppd
->num_attrs
;
2138 if ((temp
= calloc(1, sizeof(ppd_attr_t
))) == NULL
)
2149 strlcpy(temp
->name
, name
, sizeof(temp
->name
));
2150 strlcpy(temp
->spec
, spec
, sizeof(temp
->spec
));
2151 strlcpy(temp
->text
, text
, sizeof(temp
->text
));
2152 temp
->value
= (char *)value
;
2155 * Add the attribute to the sorted array...
2158 cupsArrayAdd(ppd
->sorted_attrs
, temp
);
2161 * Return the attribute...
2169 * 'ppd_add_choice()' - Add a choice to an option.
2172 static ppd_choice_t
* /* O - Named choice */
2173 ppd_add_choice(ppd_option_t
*option
, /* I - Option */
2174 const char *name
) /* I - Name of choice */
2176 ppd_choice_t
*choice
; /* Choice */
2179 if (option
->num_choices
== 0)
2180 choice
= malloc(sizeof(ppd_choice_t
));
2182 choice
= realloc(option
->choices
,
2183 sizeof(ppd_choice_t
) * (option
->num_choices
+ 1));
2188 option
->choices
= choice
;
2189 choice
+= option
->num_choices
;
2190 option
->num_choices
++;
2192 memset(choice
, 0, sizeof(ppd_choice_t
));
2193 strlcpy(choice
->choice
, name
, sizeof(choice
->choice
));
2200 * 'ppd_add_size()' - Add a page size.
2203 static ppd_size_t
* /* O - Named size */
2204 ppd_add_size(ppd_file_t
*ppd
, /* I - PPD file */
2205 const char *name
) /* I - Name of size */
2207 ppd_size_t
*size
; /* Size */
2210 if (ppd
->num_sizes
== 0)
2211 size
= malloc(sizeof(ppd_size_t
));
2213 size
= realloc(ppd
->sizes
, sizeof(ppd_size_t
) * (ppd
->num_sizes
+ 1));
2219 size
+= ppd
->num_sizes
;
2222 memset(size
, 0, sizeof(ppd_size_t
));
2223 strlcpy(size
->name
, name
, sizeof(size
->name
));
2230 * 'ppd_compare_attrs()' - Compare two attributes.
2233 static int /* O - Result of comparison */
2234 ppd_compare_attrs(ppd_attr_t
*a
, /* I - First attribute */
2235 ppd_attr_t
*b
) /* I - Second attribute */
2237 return (strcasecmp(a
->name
, b
->name
));
2242 * 'ppd_compare_choices()' - Compare two choices...
2245 static int /* O - Result of comparison */
2246 ppd_compare_choices(ppd_choice_t
*a
, /* I - First choice */
2247 ppd_choice_t
*b
) /* I - Second choice */
2249 return (strcmp(a
->option
->keyword
, b
->option
->keyword
));
2254 * 'ppd_compare_coptions()' - Compare two custom options.
2257 static int /* O - Result of comparison */
2258 ppd_compare_coptions(ppd_coption_t
*a
, /* I - First option */
2259 ppd_coption_t
*b
) /* I - Second option */
2261 return (strcasecmp(a
->keyword
, b
->keyword
));
2266 * 'ppd_compare_cparams()' - Compare two custom parameters.
2269 static int /* O - Result of comparison */
2270 ppd_compare_cparams(ppd_cparam_t
*a
, /* I - First parameter */
2271 ppd_cparam_t
*b
) /* I - Second parameter */
2273 return (strcasecmp(a
->name
, b
->name
));
2278 * 'ppd_compare_options()' - Compare two options.
2281 static int /* O - Result of comparison */
2282 ppd_compare_options(ppd_option_t
*a
, /* I - First option */
2283 ppd_option_t
*b
) /* I - Second option */
2285 return (strcasecmp(a
->keyword
, b
->keyword
));
2290 * 'ppd_decode()' - Decode a string value...
2293 static int /* O - Length of decoded string */
2294 ppd_decode(char *string
) /* I - String to decode */
2296 char *inptr
, /* Input pointer */
2297 *outptr
; /* Output pointer */
2303 while (*inptr
!= '\0')
2304 if (*inptr
== '<' && isxdigit(inptr
[1] & 255))
2307 * Convert hex to 8-bit values...
2311 while (isxdigit(*inptr
& 255))
2313 if (isalpha(*inptr
))
2314 *outptr
= (tolower(*inptr
) - 'a' + 10) << 4;
2316 *outptr
= (*inptr
- '0') << 4;
2320 if (!isxdigit(*inptr
& 255))
2323 if (isalpha(*inptr
))
2324 *outptr
|= tolower(*inptr
) - 'a' + 10;
2326 *outptr
|= *inptr
- '0';
2332 while (*inptr
!= '>' && *inptr
!= '\0')
2334 while (*inptr
== '>')
2338 *outptr
++ = *inptr
++;
2342 return ((int)(outptr
- string
));
2347 * 'ppd_free_group()' - Free a single UI group.
2351 ppd_free_group(ppd_group_t
*group
) /* I - Group to free */
2353 int i
; /* Looping var */
2354 ppd_option_t
*option
; /* Current option */
2355 ppd_group_t
*subgroup
; /* Current sub-group */
2358 if (group
->num_options
> 0)
2360 for (i
= group
->num_options
, option
= group
->options
;
2363 ppd_free_option(option
);
2365 ppd_free(group
->options
);
2368 if (group
->num_subgroups
> 0)
2370 for (i
= group
->num_subgroups
, subgroup
= group
->subgroups
;
2373 ppd_free_group(subgroup
);
2375 ppd_free(group
->subgroups
);
2381 * 'ppd_free_option()' - Free a single option.
2385 ppd_free_option(ppd_option_t
*option
) /* I - Option to free */
2387 int i
; /* Looping var */
2388 ppd_choice_t
*choice
; /* Current choice */
2391 if (option
->num_choices
> 0)
2393 for (i
= option
->num_choices
, choice
= option
->choices
;
2397 _cupsStrFree(choice
->code
);
2400 ppd_free(option
->choices
);
2406 * 'ppd_get_coption()' - Get a custom option record.
2409 static ppd_coption_t
* /* O - Custom option... */
2410 ppd_get_coption(ppd_file_t
*ppd
, /* I - PPD file */
2411 const char *name
) /* I - Name of option */
2413 ppd_coption_t
*copt
; /* New custom option */
2417 * See if the option already exists...
2420 if ((copt
= ppdFindCustomOption(ppd
, name
)) != NULL
)
2424 * Not found, so create the custom option record...
2427 if ((copt
= calloc(1, sizeof(ppd_coption_t
))) == NULL
)
2430 strlcpy(copt
->keyword
, name
, sizeof(copt
->keyword
));
2432 copt
->params
= cupsArrayNew((cups_array_func_t
)ppd_compare_cparams
, NULL
);
2434 cupsArrayAdd(ppd
->coptions
, copt
);
2437 * Return the new record...
2445 * 'ppd_get_cparam()' - Get a custom parameter record.
2448 static ppd_cparam_t
* /* O - Extended option... */
2449 ppd_get_cparam(ppd_coption_t
*opt
, /* I - PPD file */
2450 const char *param
, /* I - Name of parameter */
2451 const char *text
) /* I - Human-readable text */
2453 ppd_cparam_t
*cparam
; /* New custom parameter */
2457 * See if the parameter already exists...
2460 if ((cparam
= ppdFindCustomParam(opt
, param
)) != NULL
)
2464 * Not found, so create the custom parameter record...
2467 if ((cparam
= calloc(1, sizeof(ppd_cparam_t
))) == NULL
)
2470 strlcpy(cparam
->name
, param
, sizeof(cparam
->name
));
2471 strlcpy(cparam
->text
, text
[0] ? text
: param
, sizeof(cparam
->text
));
2474 * Add this record to the array...
2477 cupsArrayAdd(opt
->params
, cparam
);
2480 * Return the new record...
2488 * 'ppd_get_group()' - Find or create the named group as needed.
2491 static ppd_group_t
* /* O - Named group */
2492 ppd_get_group(ppd_file_t
*ppd
, /* I - PPD file */
2493 const char *name
, /* I - Name of group */
2494 const char *text
, /* I - Text for group */
2495 _cups_globals_t
*cg
, /* I - Global data */
2496 cups_encoding_t encoding
) /* I - Encoding of text */
2498 int i
; /* Looping var */
2499 ppd_group_t
*group
; /* Group */
2502 DEBUG_printf(("7ppd_get_group(ppd=%p, name=\"%s\", text=\"%s\", cg=%p)",
2503 ppd
, name
, text
, cg
));
2505 for (i
= ppd
->num_groups
, group
= ppd
->groups
; i
> 0; i
--, group
++)
2506 if (!strcmp(group
->name
, name
))
2511 DEBUG_printf(("8ppd_get_group: Adding group %s...", name
));
2513 if (cg
->ppd_conform
== PPD_CONFORM_STRICT
&& strlen(text
) >= sizeof(group
->text
))
2515 cg
->ppd_status
= PPD_ILLEGAL_TRANSLATION
;
2520 if (ppd
->num_groups
== 0)
2521 group
= malloc(sizeof(ppd_group_t
));
2523 group
= realloc(ppd
->groups
,
2524 (ppd
->num_groups
+ 1) * sizeof(ppd_group_t
));
2528 cg
->ppd_status
= PPD_ALLOC_ERROR
;
2533 ppd
->groups
= group
;
2534 group
+= ppd
->num_groups
;
2537 memset(group
, 0, sizeof(ppd_group_t
));
2538 strlcpy(group
->name
, name
, sizeof(group
->name
));
2540 cupsCharsetToUTF8((cups_utf8_t
*)group
->text
, text
,
2541 sizeof(group
->text
), encoding
);
2549 * 'ppd_get_option()' - Find or create the named option as needed.
2552 static ppd_option_t
* /* O - Named option */
2553 ppd_get_option(ppd_group_t
*group
, /* I - Group */
2554 const char *name
) /* I - Name of option */
2556 int i
; /* Looping var */
2557 ppd_option_t
*option
; /* Option */
2560 DEBUG_printf(("7ppd_get_option(group=%p(\"%s\"), name=\"%s\")",
2561 group
, group
->name
, name
));
2563 for (i
= group
->num_options
, option
= group
->options
; i
> 0; i
--, option
++)
2564 if (!strcmp(option
->keyword
, name
))
2569 if (group
->num_options
== 0)
2570 option
= malloc(sizeof(ppd_option_t
));
2572 option
= realloc(group
->options
,
2573 (group
->num_options
+ 1) * sizeof(ppd_option_t
));
2578 group
->options
= option
;
2579 option
+= group
->num_options
;
2580 group
->num_options
++;
2582 memset(option
, 0, sizeof(ppd_option_t
));
2583 strlcpy(option
->keyword
, name
, sizeof(option
->keyword
));
2591 * 'ppd_hash_option()' - Generate a hash of the option name...
2594 static int /* O - Hash index */
2595 ppd_hash_option(ppd_option_t
*option
) /* I - Option */
2597 int hash
= 0; /* Hash index */
2598 const char *k
; /* Pointer into keyword */
2601 for (hash
= option
->keyword
[0], k
= option
->keyword
+ 1; *k
;)
2602 hash
= 33 * hash
+ *k
++;
2604 return (hash
& 511);
2609 * 'ppd_read()' - Read a line from a PPD file, skipping comment lines as
2613 static int /* O - Bitmask of fields read */
2614 ppd_read(cups_file_t
*fp
, /* I - File to read from */
2615 _ppd_line_t
*line
, /* I - Line buffer */
2616 char *keyword
, /* O - Keyword from line */
2617 char *option
, /* O - Option from line */
2618 char *text
, /* O - Human-readable text from line */
2619 char **string
, /* O - Code/string data */
2620 int ignoreblank
, /* I - Ignore blank lines? */
2621 _cups_globals_t
*cg
) /* I - Global data */
2623 int ch
, /* Character from file */
2624 col
, /* Column in line */
2625 colon
, /* Colon seen? */
2626 endquote
, /* Waiting for an end quote */
2627 mask
, /* Mask to be returned */
2628 startline
, /* Start line */
2629 textlen
; /* Length of text */
2630 char *keyptr
, /* Keyword pointer */
2631 *optptr
, /* Option pointer */
2632 *textptr
, /* Text pointer */
2633 *strptr
, /* Pointer into string */
2634 *lineptr
; /* Current position in line buffer */
2638 * Now loop until we have a valid line...
2643 startline
= cg
->ppd_line
+ 1;
2647 line
->bufsize
= 1024;
2648 line
->buffer
= malloc(1024);
2660 lineptr
= line
->buffer
;
2664 while ((ch
= cupsFileGetChar(fp
)) != EOF
)
2666 if (lineptr
>= (line
->buffer
+ line
->bufsize
- 1))
2669 * Expand the line buffer...
2672 char *temp
; /* Temporary line pointer */
2675 line
->bufsize
+= 1024;
2676 if (line
->bufsize
> 262144)
2679 * Don't allow lines longer than 256k!
2682 cg
->ppd_line
= startline
;
2683 cg
->ppd_status
= PPD_LINE_TOO_LONG
;
2688 temp
= realloc(line
->buffer
, line
->bufsize
);
2691 cg
->ppd_line
= startline
;
2692 cg
->ppd_status
= PPD_LINE_TOO_LONG
;
2697 lineptr
= temp
+ (lineptr
- line
->buffer
);
2698 line
->buffer
= temp
;
2701 if (ch
== '\r' || ch
== '\n')
2704 * Line feed or carriage return...
2713 * Check for a trailing line feed...
2716 if ((ch
= cupsFilePeekChar(fp
)) == EOF
)
2723 cupsFileGetChar(fp
);
2726 if (lineptr
== line
->buffer
&& ignoreblank
)
2727 continue; /* Skip blank lines */
2731 if (!endquote
) /* Continue for multi-line text */
2736 else if (ch
< ' ' && ch
!= '\t' && cg
->ppd_conform
== PPD_CONFORM_STRICT
)
2739 * Other control characters...
2742 cg
->ppd_line
= startline
;
2743 cg
->ppd_status
= PPD_ILLEGAL_CHARACTER
;
2747 else if (ch
!= 0x1a)
2750 * Any other character...
2756 if (col
> (PPD_MAX_LINE
- 1))
2759 * Line is too long...
2762 cg
->ppd_line
= startline
;
2763 cg
->ppd_status
= PPD_LINE_TOO_LONG
;
2768 if (ch
== ':' && strncmp(line
->buffer
, "*%", 2) != 0)
2771 if (ch
== '\"' && colon
)
2772 endquote
= !endquote
;
2779 * Didn't finish this quoted string...
2782 while ((ch
= cupsFileGetChar(fp
)) != EOF
)
2785 else if (ch
== '\r' || ch
== '\n')
2793 * Check for a trailing line feed...
2796 if ((ch
= cupsFilePeekChar(fp
)) == EOF
)
2799 cupsFileGetChar(fp
);
2802 else if (ch
< ' ' && ch
!= '\t' && cg
->ppd_conform
== PPD_CONFORM_STRICT
)
2805 * Other control characters...
2808 cg
->ppd_line
= startline
;
2809 cg
->ppd_status
= PPD_ILLEGAL_CHARACTER
;
2813 else if (ch
!= 0x1a)
2817 if (col
> (PPD_MAX_LINE
- 1))
2820 * Line is too long...
2823 cg
->ppd_line
= startline
;
2824 cg
->ppd_status
= PPD_LINE_TOO_LONG
;
2834 * Didn't finish this line...
2837 while ((ch
= cupsFileGetChar(fp
)) != EOF
)
2838 if (ch
== '\r' || ch
== '\n')
2841 * Line feed or carriage return...
2850 * Check for a trailing line feed...
2853 if ((ch
= cupsFilePeekChar(fp
)) == EOF
)
2856 cupsFileGetChar(fp
);
2861 else if (ch
< ' ' && ch
!= '\t' && cg
->ppd_conform
== PPD_CONFORM_STRICT
)
2864 * Other control characters...
2867 cg
->ppd_line
= startline
;
2868 cg
->ppd_status
= PPD_ILLEGAL_CHARACTER
;
2872 else if (ch
!= 0x1a)
2876 if (col
> (PPD_MAX_LINE
- 1))
2879 * Line is too long...
2882 cg
->ppd_line
= startline
;
2883 cg
->ppd_status
= PPD_LINE_TOO_LONG
;
2890 if (lineptr
> line
->buffer
&& lineptr
[-1] == '\n')
2895 DEBUG_printf(("9ppd_read: LINE=\"%s\"", line
->buffer
));
2898 * The dynamically created PPDs for older style Mac OS X
2899 * drivers include a large blob of data inserted as comments
2900 * at the end of the file. As an optimization we can stop
2901 * reading the PPD when we get to the start of this data.
2904 if (!strcmp(line
->buffer
, "*%APLWORKSET START"))
2907 if (ch
== EOF
&& lineptr
== line
->buffer
)
2915 lineptr
= line
->buffer
+ 1;
2922 if ((!line
->buffer
[0] || /* Blank line */
2923 !strncmp(line
->buffer
, "*%", 2) || /* Comment line */
2924 !strcmp(line
->buffer
, "*End")) && /* End of multi-line string */
2925 ignoreblank
) /* Ignore these? */
2927 startline
= cg
->ppd_line
+ 1;
2931 if (!strcmp(line
->buffer
, "*")) /* (Bad) comment line */
2933 if (cg
->ppd_conform
== PPD_CONFORM_RELAXED
)
2935 startline
= cg
->ppd_line
+ 1;
2940 cg
->ppd_line
= startline
;
2941 cg
->ppd_status
= PPD_ILLEGAL_MAIN_KEYWORD
;
2947 if (line
->buffer
[0] != '*') /* All lines start with an asterisk */
2950 * Allow lines consisting of just whitespace...
2953 for (lineptr
= line
->buffer
; *lineptr
; lineptr
++)
2954 if (!isspace(*lineptr
& 255))
2959 cg
->ppd_status
= PPD_MISSING_ASTERISK
;
2962 else if (ignoreblank
)
2974 while (*lineptr
!= '\0' && *lineptr
!= ':' && !isspace(*lineptr
& 255))
2976 if (*lineptr
<= ' ' || *lineptr
> 126 || *lineptr
== '/' ||
2977 (keyptr
- keyword
) >= (PPD_MAX_NAME
- 1))
2979 cg
->ppd_status
= PPD_ILLEGAL_MAIN_KEYWORD
;
2983 *keyptr
++ = *lineptr
++;
2988 if (!strcmp(keyword
, "End"))
2991 mask
|= PPD_KEYWORD
;
2993 if (isspace(*lineptr
& 255))
2996 * Get an option name...
2999 while (isspace(*lineptr
& 255))
3004 while (*lineptr
!= '\0' && !isspace(*lineptr
& 255) && *lineptr
!= ':' &&
3007 if (*lineptr
<= ' ' || *lineptr
> 126 ||
3008 (optptr
- option
) >= (PPD_MAX_NAME
- 1))
3010 cg
->ppd_status
= PPD_ILLEGAL_OPTION_KEYWORD
;
3014 *optptr
++ = *lineptr
++;
3019 if (isspace(*lineptr
& 255) && cg
->ppd_conform
== PPD_CONFORM_STRICT
)
3021 cg
->ppd_status
= PPD_ILLEGAL_WHITESPACE
;
3025 while (isspace(*lineptr
& 255))
3030 if (*lineptr
== '/')
3033 * Get human-readable text...
3040 while (*lineptr
!= '\0' && *lineptr
!= '\n' && *lineptr
!= ':')
3042 if (((unsigned char)*lineptr
< ' ' && *lineptr
!= '\t') ||
3043 (textptr
- text
) >= (PPD_MAX_LINE
- 1))
3045 cg
->ppd_status
= PPD_ILLEGAL_TRANSLATION
;
3049 *textptr
++ = *lineptr
++;
3053 textlen
= ppd_decode(text
);
3055 if (textlen
> PPD_MAX_TEXT
&& cg
->ppd_conform
== PPD_CONFORM_STRICT
)
3057 cg
->ppd_status
= PPD_ILLEGAL_TRANSLATION
;
3065 if (isspace(*lineptr
& 255) && cg
->ppd_conform
== PPD_CONFORM_STRICT
)
3067 cg
->ppd_status
= PPD_ILLEGAL_WHITESPACE
;
3071 while (isspace(*lineptr
& 255))
3074 if (*lineptr
== ':')
3077 * Get string after triming leading and trailing whitespace...
3081 while (isspace(*lineptr
& 255))
3084 strptr
= lineptr
+ strlen(lineptr
) - 1;
3085 while (strptr
>= lineptr
&& isspace(*strptr
& 255))
3088 if (*strptr
== '\"')
3091 * Quoted string by itself, remove quotes...
3098 *string
= _cupsStrAlloc(lineptr
);
3110 * End of "$Id: ppd.c 7906 2008-09-03 20:19:43Z mike $".