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...
946 sscanf(string
, "%d%32s%64s%64s", &corder
, ctype
, cminimum
,
949 cg
->ppd_status
= PPD_BAD_CUSTOM_PARAM
;
954 cparam
->order
= corder
;
956 if (!strcmp(ctype
, "curve"))
958 cparam
->type
= PPD_CUSTOM_CURVE
;
959 cparam
->minimum
.custom_curve
= (float)_cupsStrScand(cminimum
, NULL
, loc
);
960 cparam
->maximum
.custom_curve
= (float)_cupsStrScand(cmaximum
, NULL
, loc
);
962 else if (!strcmp(ctype
, "int"))
964 cparam
->type
= PPD_CUSTOM_INT
;
965 cparam
->minimum
.custom_int
= atoi(cminimum
);
966 cparam
->maximum
.custom_int
= atoi(cmaximum
);
968 else if (!strcmp(ctype
, "invcurve"))
970 cparam
->type
= PPD_CUSTOM_INVCURVE
;
971 cparam
->minimum
.custom_invcurve
= (float)_cupsStrScand(cminimum
, NULL
, loc
);
972 cparam
->maximum
.custom_invcurve
= (float)_cupsStrScand(cmaximum
, NULL
, loc
);
974 else if (!strcmp(ctype
, "passcode"))
976 cparam
->type
= PPD_CUSTOM_PASSCODE
;
977 cparam
->minimum
.custom_passcode
= atoi(cminimum
);
978 cparam
->maximum
.custom_passcode
= atoi(cmaximum
);
980 else if (!strcmp(ctype
, "password"))
982 cparam
->type
= PPD_CUSTOM_PASSWORD
;
983 cparam
->minimum
.custom_password
= atoi(cminimum
);
984 cparam
->maximum
.custom_password
= atoi(cmaximum
);
986 else if (!strcmp(ctype
, "points"))
988 cparam
->type
= PPD_CUSTOM_POINTS
;
989 cparam
->minimum
.custom_points
= (float)_cupsStrScand(cminimum
, NULL
, loc
);
990 cparam
->maximum
.custom_points
= (float)_cupsStrScand(cmaximum
, NULL
, loc
);
992 else if (!strcmp(ctype
, "real"))
994 cparam
->type
= PPD_CUSTOM_REAL
;
995 cparam
->minimum
.custom_real
= (float)_cupsStrScand(cminimum
, NULL
, loc
);
996 cparam
->maximum
.custom_real
= (float)_cupsStrScand(cmaximum
, NULL
, loc
);
998 else if (!strcmp(ctype
, "string"))
1000 cparam
->type
= PPD_CUSTOM_STRING
;
1001 cparam
->minimum
.custom_string
= atoi(cminimum
);
1002 cparam
->maximum
.custom_string
= atoi(cmaximum
);
1006 cg
->ppd_status
= PPD_BAD_CUSTOM_PARAM
;
1012 * Now special-case for CustomPageSize...
1015 if (!strcmp(coption
->keyword
, "PageSize"))
1017 if (!strcmp(name
, "Width"))
1019 ppd
->custom_min
[0] = cparam
->minimum
.custom_points
;
1020 ppd
->custom_max
[0] = cparam
->maximum
.custom_points
;
1022 else if (!strcmp(name
, "Height"))
1024 ppd
->custom_min
[1] = cparam
->minimum
.custom_points
;
1025 ppd
->custom_max
[1] = cparam
->maximum
.custom_points
;
1029 else if (!strcmp(keyword
, "HWMargins"))
1031 for (i
= 0, sptr
= string
; i
< 4; i
++)
1032 ppd
->custom_margins
[i
] = (float)_cupsStrScand(sptr
, &sptr
, loc
);
1034 else if (!strncmp(keyword
, "Custom", 6) && !strcmp(name
, "True") && !option
)
1036 ppd_option_t
*custom_option
; /* Custom option */
1038 DEBUG_puts("2ppdOpen2: Processing Custom option...");
1041 * Get the option and custom option...
1044 if (!ppd_get_coption(ppd
, keyword
+ 6))
1046 cg
->ppd_status
= PPD_ALLOC_ERROR
;
1051 if (option
&& !strcasecmp(option
->keyword
, keyword
+ 6))
1052 custom_option
= option
;
1054 custom_option
= ppdFindOption(ppd
, keyword
+ 6);
1059 * Add the "custom" option...
1062 if ((choice
= ppdFindChoice(custom_option
, "Custom")) == NULL
)
1063 if ((choice
= ppd_add_choice(custom_option
, "Custom")) == NULL
)
1065 DEBUG_puts("1ppdOpen2: Unable to add Custom choice!");
1067 cg
->ppd_status
= PPD_ALLOC_ERROR
;
1072 strlcpy(choice
->text
, text
[0] ? text
: _("Custom"),
1073 sizeof(choice
->text
));
1075 choice
->code
= _cupsStrAlloc(string
);
1077 if (custom_option
->section
== PPD_ORDER_JCL
)
1078 ppd_decode(choice
->code
);
1082 * Now process custom page sizes specially...
1085 if (!strcmp(keyword
, "CustomPageSize"))
1088 * Add a "Custom" page size entry...
1091 ppd
->variable_sizes
= 1;
1093 ppd_add_size(ppd
, "Custom");
1095 if (option
&& !strcasecmp(option
->keyword
, "PageRegion"))
1096 custom_option
= option
;
1098 custom_option
= ppdFindOption(ppd
, "PageRegion");
1102 if ((choice
= ppdFindChoice(custom_option
, "Custom")) == NULL
)
1103 if ((choice
= ppd_add_choice(custom_option
, "Custom")) == NULL
)
1105 DEBUG_puts("1ppdOpen2: Unable to add Custom choice!");
1107 cg
->ppd_status
= PPD_ALLOC_ERROR
;
1112 strlcpy(choice
->text
, text
[0] ? text
: _("Custom"),
1113 sizeof(choice
->text
));
1117 else if (!strcmp(keyword
, "LandscapeOrientation"))
1119 if (!strcmp(string
, "Minus90"))
1120 ppd
->landscape
= -90;
1121 else if (!strcmp(string
, "Plus90"))
1122 ppd
->landscape
= 90;
1124 else if (!strcmp(keyword
, "Emulators") && string
)
1126 for (count
= 1, sptr
= string
; sptr
!= NULL
;)
1127 if ((sptr
= strchr(sptr
, ' ')) != NULL
)
1130 while (*sptr
== ' ')
1134 ppd
->num_emulations
= count
;
1135 if ((ppd
->emulations
= calloc(count
, sizeof(ppd_emul_t
))) == NULL
)
1137 cg
->ppd_status
= PPD_ALLOC_ERROR
;
1142 for (i
= 0, sptr
= string
; i
< count
; i
++)
1144 for (nameptr
= ppd
->emulations
[i
].name
;
1145 *sptr
!= '\0' && *sptr
!= ' ';
1147 if (nameptr
< (ppd
->emulations
[i
].name
+ sizeof(ppd
->emulations
[i
].name
) - 1))
1152 while (*sptr
== ' ')
1156 else if (!strncmp(keyword
, "StartEmulator_", 14))
1160 for (i
= 0; i
< ppd
->num_emulations
; i
++)
1161 if (!strcmp(keyword
+ 14, ppd
->emulations
[i
].name
))
1163 ppd
->emulations
[i
].start
= string
;
1167 else if (!strncmp(keyword
, "StopEmulator_", 13))
1171 for (i
= 0; i
< ppd
->num_emulations
; i
++)
1172 if (!strcmp(keyword
+ 13, ppd
->emulations
[i
].name
))
1174 ppd
->emulations
[i
].stop
= string
;
1178 else if (!strcmp(keyword
, "JobPatchFile"))
1180 if (ppd
->patches
== NULL
)
1181 ppd
->patches
= strdup(string
);
1184 temp
= realloc(ppd
->patches
, strlen(ppd
->patches
) +
1185 strlen(string
) + 1);
1188 cg
->ppd_status
= PPD_ALLOC_ERROR
;
1193 ppd
->patches
= temp
;
1195 strcpy(ppd
->patches
+ strlen(ppd
->patches
), string
);
1198 else if (!strcmp(keyword
, "OpenUI"))
1201 * Don't allow nesting of options...
1204 if (option
&& cg
->ppd_conform
== PPD_CONFORM_STRICT
)
1206 cg
->ppd_status
= PPD_NESTED_OPEN_UI
;
1212 * Add an option record to the current sub-group, group, or file...
1215 DEBUG_printf(("2ppdOpen2: name=\"%s\" (%d)", name
, (int)strlen(name
)));
1218 _cups_strcpy(name
, name
+ 1); /* Eliminate leading asterisk */
1220 for (i
= (int)strlen(name
) - 1; i
> 0 && isspace(name
[i
] & 255); i
--)
1221 name
[i
] = '\0'; /* Eliminate trailing spaces */
1223 DEBUG_printf(("2ppdOpen2: OpenUI of %s in group %s...", name
,
1224 group
? group
->text
: "(null)"));
1226 if (subgroup
!= NULL
)
1227 option
= ppd_get_option(subgroup
, name
);
1228 else if (group
== NULL
)
1230 if ((group
= ppd_get_group(ppd
, "General", _("General"), cg
,
1234 DEBUG_printf(("2ppdOpen2: Adding to group %s...", group
->text
));
1235 option
= ppd_get_option(group
, name
);
1239 option
= ppd_get_option(group
, name
);
1243 cg
->ppd_status
= PPD_ALLOC_ERROR
;
1249 * Now fill in the initial information for the option...
1252 if (string
&& !strcmp(string
, "PickMany"))
1253 option
->ui
= PPD_UI_PICKMANY
;
1254 else if (string
&& !strcmp(string
, "Boolean"))
1255 option
->ui
= PPD_UI_BOOLEAN
;
1256 else if (string
&& !strcmp(string
, "PickOne"))
1257 option
->ui
= PPD_UI_PICKONE
;
1258 else if (cg
->ppd_conform
== PPD_CONFORM_STRICT
)
1260 cg
->ppd_status
= PPD_BAD_OPEN_UI
;
1265 option
->ui
= PPD_UI_PICKONE
;
1267 for (j
= 0; j
< ppd
->num_attrs
; j
++)
1268 if (!strncmp(ppd
->attrs
[j
]->name
, "Default", 7) &&
1269 !strcmp(ppd
->attrs
[j
]->name
+ 7, name
) &&
1270 ppd
->attrs
[j
]->value
)
1272 DEBUG_printf(("2ppdOpen2: Setting Default%s to %s via attribute...",
1273 option
->keyword
, ppd
->attrs
[j
]->value
));
1274 strlcpy(option
->defchoice
, ppd
->attrs
[j
]->value
,
1275 sizeof(option
->defchoice
));
1280 cupsCharsetToUTF8((cups_utf8_t
*)option
->text
, text
,
1281 sizeof(option
->text
), encoding
);
1284 if (!strcmp(name
, "PageSize"))
1285 strlcpy(option
->text
, _("Media Size"), sizeof(option
->text
));
1286 else if (!strcmp(name
, "MediaType"))
1287 strlcpy(option
->text
, _("Media Type"), sizeof(option
->text
));
1288 else if (!strcmp(name
, "InputSlot"))
1289 strlcpy(option
->text
, _("Media Source"), sizeof(option
->text
));
1290 else if (!strcmp(name
, "ColorModel"))
1291 strlcpy(option
->text
, _("Output Mode"), sizeof(option
->text
));
1292 else if (!strcmp(name
, "Resolution"))
1293 strlcpy(option
->text
, _("Resolution"), sizeof(option
->text
));
1295 strlcpy(option
->text
, name
, sizeof(option
->text
));
1298 option
->section
= PPD_ORDER_ANY
;
1300 _cupsStrFree(string
);
1304 * Add a custom option choice if we have already seen a CustomFoo
1308 if (!strcasecmp(name
, "PageRegion"))
1309 strcpy(custom_name
, "CustomPageSize");
1311 snprintf(custom_name
, sizeof(custom_name
), "Custom%s", name
);
1313 if ((custom_attr
= ppdFindAttr(ppd
, custom_name
, "True")) != NULL
)
1315 if ((choice
= ppdFindChoice(option
, "Custom")) == NULL
)
1316 if ((choice
= ppd_add_choice(option
, "Custom")) == NULL
)
1318 DEBUG_puts("1ppdOpen2: Unable to add Custom choice!");
1320 cg
->ppd_status
= PPD_ALLOC_ERROR
;
1325 strlcpy(choice
->text
,
1326 custom_attr
->text
[0] ? custom_attr
->text
: _("Custom"),
1327 sizeof(choice
->text
));
1328 choice
->code
= _cupsStrRetain(custom_attr
->value
);
1331 else if (!strcmp(keyword
, "JCLOpenUI"))
1334 * Don't allow nesting of options...
1337 if (option
&& cg
->ppd_conform
== PPD_CONFORM_STRICT
)
1339 cg
->ppd_status
= PPD_NESTED_OPEN_UI
;
1345 * Find the JCL group, and add if needed...
1348 group
= ppd_get_group(ppd
, "JCL", _("JCL"), cg
, encoding
);
1354 * Add an option record to the current JCLs...
1358 _cups_strcpy(name
, name
+ 1);
1360 option
= ppd_get_option(group
, name
);
1364 cg
->ppd_status
= PPD_ALLOC_ERROR
;
1370 * Now fill in the initial information for the option...
1373 if (string
&& !strcmp(string
, "PickMany"))
1374 option
->ui
= PPD_UI_PICKMANY
;
1375 else if (string
&& !strcmp(string
, "Boolean"))
1376 option
->ui
= PPD_UI_BOOLEAN
;
1377 else if (string
&& !strcmp(string
, "PickOne"))
1378 option
->ui
= PPD_UI_PICKONE
;
1381 cg
->ppd_status
= PPD_BAD_OPEN_UI
;
1386 for (j
= 0; j
< ppd
->num_attrs
; j
++)
1387 if (!strncmp(ppd
->attrs
[j
]->name
, "Default", 7) &&
1388 !strcmp(ppd
->attrs
[j
]->name
+ 7, name
) &&
1389 ppd
->attrs
[j
]->value
)
1391 DEBUG_printf(("2ppdOpen2: Setting Default%s to %s via attribute...",
1392 option
->keyword
, ppd
->attrs
[j
]->value
));
1393 strlcpy(option
->defchoice
, ppd
->attrs
[j
]->value
,
1394 sizeof(option
->defchoice
));
1399 cupsCharsetToUTF8((cups_utf8_t
*)option
->text
, text
,
1400 sizeof(option
->text
), encoding
);
1402 strlcpy(option
->text
, name
, sizeof(option
->text
));
1404 option
->section
= PPD_ORDER_JCL
;
1407 _cupsStrFree(string
);
1411 * Add a custom option choice if we have already seen a CustomFoo
1415 snprintf(custom_name
, sizeof(custom_name
), "Custom%s", name
);
1417 if ((custom_attr
= ppdFindAttr(ppd
, custom_name
, "True")) != NULL
)
1419 if ((choice
= ppd_add_choice(option
, "Custom")) == NULL
)
1421 DEBUG_puts("1ppdOpen2: Unable to add Custom choice!");
1423 cg
->ppd_status
= PPD_ALLOC_ERROR
;
1428 strlcpy(choice
->text
,
1429 custom_attr
->text
[0] ? custom_attr
->text
: _("Custom"),
1430 sizeof(choice
->text
));
1431 choice
->code
= _cupsStrRetain(custom_attr
->value
);
1434 else if (!strcmp(keyword
, "CloseUI") || !strcmp(keyword
, "JCLCloseUI"))
1438 _cupsStrFree(string
);
1441 else if (!strcmp(keyword
, "OpenGroup"))
1444 * Open a new group...
1449 cg
->ppd_status
= PPD_NESTED_OPEN_GROUP
;
1456 cg
->ppd_status
= PPD_BAD_OPEN_GROUP
;
1462 * Separate the group name from the text (name/text)...
1465 if ((sptr
= strchr(string
, '/')) != NULL
)
1471 * Fix up the text...
1477 * Find/add the group...
1480 group
= ppd_get_group(ppd
, string
, sptr
, cg
, encoding
);
1485 _cupsStrFree(string
);
1488 else if (!strcmp(keyword
, "CloseGroup"))
1492 _cupsStrFree(string
);
1495 else if (!strcmp(keyword
, "OrderDependency"))
1497 order
= (float)_cupsStrScand(string
, &sptr
, loc
);
1499 if (!sptr
|| sscanf(sptr
, "%40s%40s", name
, keyword
) != 2)
1501 cg
->ppd_status
= PPD_BAD_ORDER_DEPENDENCY
;
1506 if (keyword
[0] == '*')
1507 _cups_strcpy(keyword
, keyword
+ 1);
1509 if (!strcmp(name
, "ExitServer"))
1510 section
= PPD_ORDER_EXIT
;
1511 else if (!strcmp(name
, "Prolog"))
1512 section
= PPD_ORDER_PROLOG
;
1513 else if (!strcmp(name
, "DocumentSetup"))
1514 section
= PPD_ORDER_DOCUMENT
;
1515 else if (!strcmp(name
, "PageSetup"))
1516 section
= PPD_ORDER_PAGE
;
1517 else if (!strcmp(name
, "JCLSetup"))
1518 section
= PPD_ORDER_JCL
;
1520 section
= PPD_ORDER_ANY
;
1528 * Only valid for Non-UI options...
1531 for (i
= ppd
->num_groups
, gtemp
= ppd
->groups
; i
> 0; i
--, gtemp
++)
1532 if (gtemp
->text
[0] == '\0')
1536 for (i
= 0; i
< gtemp
->num_options
; i
++)
1537 if (!strcmp(keyword
, gtemp
->options
[i
].keyword
))
1539 gtemp
->options
[i
].section
= section
;
1540 gtemp
->options
[i
].order
= order
;
1546 option
->section
= section
;
1547 option
->order
= order
;
1550 _cupsStrFree(string
);
1553 else if (!strncmp(keyword
, "Default", 7))
1559 * Drop UI text, if any, from value...
1562 if (strchr(string
, '/') != NULL
)
1563 *strchr(string
, '/') = '\0';
1566 * Assign the default value as appropriate...
1569 if (!strcmp(keyword
, "DefaultColorSpace"))
1572 * Set default colorspace...
1575 if (!strcmp(string
, "CMY"))
1576 ppd
->colorspace
= PPD_CS_CMY
;
1577 else if (!strcmp(string
, "CMYK"))
1578 ppd
->colorspace
= PPD_CS_CMYK
;
1579 else if (!strcmp(string
, "RGB"))
1580 ppd
->colorspace
= PPD_CS_RGB
;
1581 else if (!strcmp(string
, "RGBK"))
1582 ppd
->colorspace
= PPD_CS_RGBK
;
1583 else if (!strcmp(string
, "N"))
1584 ppd
->colorspace
= PPD_CS_N
;
1586 ppd
->colorspace
= PPD_CS_GRAY
;
1588 else if (option
&& !strcmp(keyword
+ 7, option
->keyword
))
1591 * Set the default as part of the current option...
1594 DEBUG_printf(("2ppdOpen2: Setting %s to %s...", keyword
, string
));
1596 strlcpy(option
->defchoice
, string
, sizeof(option
->defchoice
));
1598 DEBUG_printf(("2ppdOpen2: %s is now %s...", keyword
, option
->defchoice
));
1603 * Lookup option and set if it has been defined...
1606 ppd_option_t
*toption
; /* Temporary option */
1609 if ((toption
= ppdFindOption(ppd
, keyword
+ 7)) != NULL
)
1611 DEBUG_printf(("2ppdOpen2: Setting %s to %s...", keyword
, string
));
1612 strlcpy(toption
->defchoice
, string
, sizeof(toption
->defchoice
));
1616 else if (!strcmp(keyword
, "UIConstraints") ||
1617 !strcmp(keyword
, "NonUIConstraints"))
1621 cg
->ppd_status
= PPD_BAD_UI_CONSTRAINTS
;
1625 if (ppd
->num_consts
== 0)
1626 constraint
= calloc(2, sizeof(ppd_const_t
));
1628 constraint
= realloc(ppd
->consts
,
1629 (ppd
->num_consts
+ 2) * sizeof(ppd_const_t
));
1631 if (constraint
== NULL
)
1633 cg
->ppd_status
= PPD_ALLOC_ERROR
;
1638 ppd
->consts
= constraint
;
1639 constraint
+= ppd
->num_consts
;
1642 switch (sscanf(string
, "%40s%40s%40s%40s", constraint
->option1
,
1643 constraint
->choice1
, constraint
->option2
,
1644 constraint
->choice2
))
1646 case 0 : /* Error */
1647 case 1 : /* Error */
1648 cg
->ppd_status
= PPD_BAD_UI_CONSTRAINTS
;
1651 case 2 : /* Two options... */
1653 * Check for broken constraints like "* Option"...
1656 if (cg
->ppd_conform
== PPD_CONFORM_STRICT
&&
1657 (!strcmp(constraint
->option1
, "*") ||
1658 !strcmp(constraint
->choice1
, "*")))
1660 cg
->ppd_status
= PPD_BAD_UI_CONSTRAINTS
;
1665 * The following strcpy's are safe, as optionN and
1666 * choiceN are all the same size (size defined by PPD spec...)
1669 if (constraint
->option1
[0] == '*')
1670 _cups_strcpy(constraint
->option1
, constraint
->option1
+ 1);
1671 else if (cg
->ppd_conform
== PPD_CONFORM_STRICT
)
1673 cg
->ppd_status
= PPD_BAD_UI_CONSTRAINTS
;
1677 if (constraint
->choice1
[0] == '*')
1678 _cups_strcpy(constraint
->option2
, constraint
->choice1
+ 1);
1679 else if (cg
->ppd_conform
== PPD_CONFORM_STRICT
)
1681 cg
->ppd_status
= PPD_BAD_UI_CONSTRAINTS
;
1685 constraint
->choice1
[0] = '\0';
1686 constraint
->choice2
[0] = '\0';
1689 case 3 : /* Two options, one choice... */
1691 * Check for broken constraints like "* Option"...
1694 if (cg
->ppd_conform
== PPD_CONFORM_STRICT
&&
1695 (!strcmp(constraint
->option1
, "*") ||
1696 !strcmp(constraint
->choice1
, "*") ||
1697 !strcmp(constraint
->option2
, "*")))
1699 cg
->ppd_status
= PPD_BAD_UI_CONSTRAINTS
;
1704 * The following _cups_strcpy's are safe, as optionN and
1705 * choiceN are all the same size (size defined by PPD spec...)
1708 if (constraint
->option1
[0] == '*')
1709 _cups_strcpy(constraint
->option1
, constraint
->option1
+ 1);
1710 else if (cg
->ppd_conform
== PPD_CONFORM_STRICT
)
1712 cg
->ppd_status
= PPD_BAD_UI_CONSTRAINTS
;
1716 if (constraint
->choice1
[0] == '*')
1718 if (cg
->ppd_conform
== PPD_CONFORM_STRICT
&&
1719 constraint
->option2
[0] == '*')
1721 cg
->ppd_status
= PPD_BAD_UI_CONSTRAINTS
;
1725 _cups_strcpy(constraint
->choice2
, constraint
->option2
);
1726 _cups_strcpy(constraint
->option2
, constraint
->choice1
+ 1);
1727 constraint
->choice1
[0] = '\0';
1731 if (constraint
->option2
[0] == '*')
1732 _cups_strcpy(constraint
->option2
, constraint
->option2
+ 1);
1733 else if (cg
->ppd_conform
== PPD_CONFORM_STRICT
)
1735 cg
->ppd_status
= PPD_BAD_UI_CONSTRAINTS
;
1739 constraint
->choice2
[0] = '\0';
1743 case 4 : /* Two options, two choices... */
1745 * Check for broken constraints like "* Option"...
1748 if (cg
->ppd_conform
== PPD_CONFORM_STRICT
&&
1749 (!strcmp(constraint
->option1
, "*") ||
1750 !strcmp(constraint
->choice1
, "*") ||
1751 !strcmp(constraint
->option2
, "*") ||
1752 !strcmp(constraint
->choice2
, "*")))
1754 cg
->ppd_status
= PPD_BAD_UI_CONSTRAINTS
;
1758 if (constraint
->option1
[0] == '*')
1759 _cups_strcpy(constraint
->option1
, constraint
->option1
+ 1);
1760 else if (cg
->ppd_conform
== PPD_CONFORM_STRICT
)
1762 cg
->ppd_status
= PPD_BAD_UI_CONSTRAINTS
;
1766 if (cg
->ppd_conform
== PPD_CONFORM_STRICT
&&
1767 constraint
->choice1
[0] == '*')
1769 cg
->ppd_status
= PPD_BAD_UI_CONSTRAINTS
;
1773 if (constraint
->option2
[0] == '*')
1774 _cups_strcpy(constraint
->option2
, constraint
->option2
+ 1);
1775 else if (cg
->ppd_conform
== PPD_CONFORM_STRICT
)
1777 cg
->ppd_status
= PPD_BAD_UI_CONSTRAINTS
;
1781 if (cg
->ppd_conform
== PPD_CONFORM_STRICT
&&
1782 constraint
->choice2
[0] == '*')
1784 cg
->ppd_status
= PPD_BAD_UI_CONSTRAINTS
;
1791 * Don't add this one as an attribute...
1794 _cupsStrFree(string
);
1797 else if (!strcmp(keyword
, "PaperDimension"))
1799 if ((size
= ppdPageSize(ppd
, name
)) == NULL
)
1800 size
= ppd_add_size(ppd
, name
);
1805 * Unable to add or find size!
1808 cg
->ppd_status
= PPD_ALLOC_ERROR
;
1813 size
->width
= (float)_cupsStrScand(string
, &sptr
, loc
);
1814 size
->length
= (float)_cupsStrScand(sptr
, NULL
, loc
);
1816 _cupsStrFree(string
);
1819 else if (!strcmp(keyword
, "ImageableArea"))
1821 if ((size
= ppdPageSize(ppd
, name
)) == NULL
)
1822 size
= ppd_add_size(ppd
, name
);
1827 * Unable to add or find size!
1830 cg
->ppd_status
= PPD_ALLOC_ERROR
;
1835 size
->left
= (float)_cupsStrScand(string
, &sptr
, loc
);
1836 size
->bottom
= (float)_cupsStrScand(sptr
, &sptr
, loc
);
1837 size
->right
= (float)_cupsStrScand(sptr
, &sptr
, loc
);
1838 size
->top
= (float)_cupsStrScand(sptr
, NULL
, loc
);
1840 _cupsStrFree(string
);
1843 else if (option
!= NULL
&&
1844 (mask
& (PPD_KEYWORD
| PPD_OPTION
| PPD_STRING
)) ==
1845 (PPD_KEYWORD
| PPD_OPTION
| PPD_STRING
) &&
1846 !strcmp(keyword
, option
->keyword
))
1848 DEBUG_printf(("2ppdOpen2: group=%p, subgroup=%p", group
, subgroup
));
1850 if (!strcmp(keyword
, "PageSize"))
1853 * Add a page size...
1856 if (ppdPageSize(ppd
, name
) == NULL
)
1857 ppd_add_size(ppd
, name
);
1861 * Add the option choice...
1864 if ((choice
= ppd_add_choice(option
, name
)) == NULL
)
1866 cg
->ppd_status
= PPD_ALLOC_ERROR
;
1872 cupsCharsetToUTF8((cups_utf8_t
*)choice
->text
, text
,
1873 sizeof(choice
->text
), encoding
);
1874 else if (!strcmp(name
, "True"))
1875 strcpy(choice
->text
, _("Yes"));
1876 else if (!strcmp(name
, "False"))
1877 strcpy(choice
->text
, _("No"));
1879 strlcpy(choice
->text
, name
, sizeof(choice
->text
));
1881 if (option
->section
== PPD_ORDER_JCL
)
1882 ppd_decode(string
); /* Decode quoted string */
1884 choice
->code
= string
;
1885 string
= NULL
; /* Don't add as an attribute below */
1889 * Add remaining lines with keywords and string values as attributes...
1893 (mask
& (PPD_KEYWORD
| PPD_STRING
)) == (PPD_KEYWORD
| PPD_STRING
))
1894 ppd_add_attr(ppd
, keyword
, name
, text
, string
);
1896 _cupsStrFree(string
);
1899 ppd_free(line
.buffer
);
1902 * Reset language preferences...
1905 cupsLangFree(language
);
1908 if (!cupsFileEOF(fp
))
1909 DEBUG_printf(("1ppdOpen2: Premature EOF at %lu...\n",
1910 (unsigned long)cupsFileTell(fp
)));
1913 if (cg
->ppd_status
!= PPD_OK
)
1916 * Had an error reading the PPD file, cannot continue!
1925 * Create the sorted options array and set the option back-pointer for
1926 * each choice and custom option...
1929 ppd
->options
= cupsArrayNew2((cups_array_func_t
)ppd_compare_options
, NULL
,
1930 (cups_ahash_func_t
)ppd_hash_option
,
1933 for (i
= ppd
->num_groups
, group
= ppd
->groups
;
1937 for (j
= group
->num_options
, option
= group
->options
;
1941 ppd_coption_t
*coption
; /* Custom option */
1944 cupsArrayAdd(ppd
->options
, option
);
1946 for (k
= 0; k
< option
->num_choices
; k
++)
1947 option
->choices
[k
].option
= option
;
1949 if ((coption
= ppdFindCustomOption(ppd
, option
->keyword
)) != NULL
)
1950 coption
->option
= option
;
1955 * Create an array to track the marked choices...
1958 ppd
->marked
= cupsArrayNew((cups_array_func_t
)ppd_compare_choices
, NULL
);
1961 * Return the PPD file structure...
1967 * Common exit point for errors to save code size...
1972 _cupsStrFree(string
);
1973 ppd_free(line
.buffer
);
1977 cupsLangFree(language
);
1984 * 'ppdOpenFd()' - Read a PPD file into memory.
1987 ppd_file_t
* /* O - PPD file record or @code NULL@ if the PPD file could not be opened. */
1988 ppdOpenFd(int fd
) /* I - File to read from */
1990 cups_file_t
*fp
; /* CUPS file pointer */
1991 ppd_file_t
*ppd
; /* PPD file record */
1992 _cups_globals_t
*cg
= _cupsGlobals();
1997 * Set the line number to 0...
2003 * Range check input...
2008 cg
->ppd_status
= PPD_NULL_FILE
;
2014 * Try to open the file and parse it...
2017 if ((fp
= cupsFileOpenFd(fd
, "r")) != NULL
)
2025 cg
->ppd_status
= PPD_FILE_OPEN_ERROR
;
2034 * 'ppdOpenFile()' - Read a PPD file into memory.
2037 ppd_file_t
* /* O - PPD file record or @code NULL@ if the PPD file could not be opened. */
2038 ppdOpenFile(const char *filename
) /* I - File to read from */
2040 cups_file_t
*fp
; /* File pointer */
2041 ppd_file_t
*ppd
; /* PPD file record */
2042 _cups_globals_t
*cg
= _cupsGlobals();
2047 * Set the line number to 0...
2053 * Range check input...
2056 if (filename
== NULL
)
2058 cg
->ppd_status
= PPD_NULL_FILE
;
2064 * Try to open the file and parse it...
2067 if ((fp
= cupsFileOpen(filename
, "r")) != NULL
)
2075 cg
->ppd_status
= PPD_FILE_OPEN_ERROR
;
2084 * 'ppdSetConformance()' - Set the conformance level for PPD files.
2086 * @since CUPS 1.1.20/Mac OS X 10.4@
2090 ppdSetConformance(ppd_conform_t c
) /* I - Conformance level */
2092 _cups_globals_t
*cg
= _cupsGlobals();
2096 cg
->ppd_conform
= c
;
2101 * 'ppd_add_attr()' - Add an attribute to the PPD data.
2104 static ppd_attr_t
* /* O - New attribute */
2105 ppd_add_attr(ppd_file_t
*ppd
, /* I - PPD file data */
2106 const char *name
, /* I - Attribute name */
2107 const char *spec
, /* I - Specifier string, if any */
2108 const char *text
, /* I - Text string, if any */
2109 const char *value
) /* I - Value of attribute */
2111 ppd_attr_t
**ptr
, /* New array */
2112 *temp
; /* New attribute */
2116 * Range check input...
2119 if (ppd
== NULL
|| name
== NULL
|| spec
== NULL
)
2123 * Create the array as needed...
2126 if (!ppd
->sorted_attrs
)
2127 ppd
->sorted_attrs
= cupsArrayNew((cups_array_func_t
)ppd_compare_attrs
,
2131 * Allocate memory for the new attribute...
2134 if (ppd
->num_attrs
== 0)
2135 ptr
= malloc(sizeof(ppd_attr_t
*));
2137 ptr
= realloc(ppd
->attrs
, (ppd
->num_attrs
+ 1) * sizeof(ppd_attr_t
*));
2143 ptr
+= ppd
->num_attrs
;
2145 if ((temp
= calloc(1, sizeof(ppd_attr_t
))) == NULL
)
2156 strlcpy(temp
->name
, name
, sizeof(temp
->name
));
2157 strlcpy(temp
->spec
, spec
, sizeof(temp
->spec
));
2158 strlcpy(temp
->text
, text
, sizeof(temp
->text
));
2159 temp
->value
= (char *)value
;
2162 * Add the attribute to the sorted array...
2165 cupsArrayAdd(ppd
->sorted_attrs
, temp
);
2168 * Return the attribute...
2176 * 'ppd_add_choice()' - Add a choice to an option.
2179 static ppd_choice_t
* /* O - Named choice */
2180 ppd_add_choice(ppd_option_t
*option
, /* I - Option */
2181 const char *name
) /* I - Name of choice */
2183 ppd_choice_t
*choice
; /* Choice */
2186 if (option
->num_choices
== 0)
2187 choice
= malloc(sizeof(ppd_choice_t
));
2189 choice
= realloc(option
->choices
,
2190 sizeof(ppd_choice_t
) * (option
->num_choices
+ 1));
2195 option
->choices
= choice
;
2196 choice
+= option
->num_choices
;
2197 option
->num_choices
++;
2199 memset(choice
, 0, sizeof(ppd_choice_t
));
2200 strlcpy(choice
->choice
, name
, sizeof(choice
->choice
));
2207 * 'ppd_add_size()' - Add a page size.
2210 static ppd_size_t
* /* O - Named size */
2211 ppd_add_size(ppd_file_t
*ppd
, /* I - PPD file */
2212 const char *name
) /* I - Name of size */
2214 ppd_size_t
*size
; /* Size */
2217 if (ppd
->num_sizes
== 0)
2218 size
= malloc(sizeof(ppd_size_t
));
2220 size
= realloc(ppd
->sizes
, sizeof(ppd_size_t
) * (ppd
->num_sizes
+ 1));
2226 size
+= ppd
->num_sizes
;
2229 memset(size
, 0, sizeof(ppd_size_t
));
2230 strlcpy(size
->name
, name
, sizeof(size
->name
));
2237 * 'ppd_compare_attrs()' - Compare two attributes.
2240 static int /* O - Result of comparison */
2241 ppd_compare_attrs(ppd_attr_t
*a
, /* I - First attribute */
2242 ppd_attr_t
*b
) /* I - Second attribute */
2244 return (strcasecmp(a
->name
, b
->name
));
2249 * 'ppd_compare_choices()' - Compare two choices...
2252 static int /* O - Result of comparison */
2253 ppd_compare_choices(ppd_choice_t
*a
, /* I - First choice */
2254 ppd_choice_t
*b
) /* I - Second choice */
2256 return (strcmp(a
->option
->keyword
, b
->option
->keyword
));
2261 * 'ppd_compare_coptions()' - Compare two custom options.
2264 static int /* O - Result of comparison */
2265 ppd_compare_coptions(ppd_coption_t
*a
, /* I - First option */
2266 ppd_coption_t
*b
) /* I - Second option */
2268 return (strcasecmp(a
->keyword
, b
->keyword
));
2273 * 'ppd_compare_cparams()' - Compare two custom parameters.
2276 static int /* O - Result of comparison */
2277 ppd_compare_cparams(ppd_cparam_t
*a
, /* I - First parameter */
2278 ppd_cparam_t
*b
) /* I - Second parameter */
2280 return (strcasecmp(a
->name
, b
->name
));
2285 * 'ppd_compare_options()' - Compare two options.
2288 static int /* O - Result of comparison */
2289 ppd_compare_options(ppd_option_t
*a
, /* I - First option */
2290 ppd_option_t
*b
) /* I - Second option */
2292 return (strcasecmp(a
->keyword
, b
->keyword
));
2297 * 'ppd_decode()' - Decode a string value...
2300 static int /* O - Length of decoded string */
2301 ppd_decode(char *string
) /* I - String to decode */
2303 char *inptr
, /* Input pointer */
2304 *outptr
; /* Output pointer */
2310 while (*inptr
!= '\0')
2311 if (*inptr
== '<' && isxdigit(inptr
[1] & 255))
2314 * Convert hex to 8-bit values...
2318 while (isxdigit(*inptr
& 255))
2320 if (isalpha(*inptr
))
2321 *outptr
= (tolower(*inptr
) - 'a' + 10) << 4;
2323 *outptr
= (*inptr
- '0') << 4;
2327 if (!isxdigit(*inptr
& 255))
2330 if (isalpha(*inptr
))
2331 *outptr
|= tolower(*inptr
) - 'a' + 10;
2333 *outptr
|= *inptr
- '0';
2339 while (*inptr
!= '>' && *inptr
!= '\0')
2341 while (*inptr
== '>')
2345 *outptr
++ = *inptr
++;
2349 return ((int)(outptr
- string
));
2354 * 'ppd_free_group()' - Free a single UI group.
2358 ppd_free_group(ppd_group_t
*group
) /* I - Group to free */
2360 int i
; /* Looping var */
2361 ppd_option_t
*option
; /* Current option */
2362 ppd_group_t
*subgroup
; /* Current sub-group */
2365 if (group
->num_options
> 0)
2367 for (i
= group
->num_options
, option
= group
->options
;
2370 ppd_free_option(option
);
2372 ppd_free(group
->options
);
2375 if (group
->num_subgroups
> 0)
2377 for (i
= group
->num_subgroups
, subgroup
= group
->subgroups
;
2380 ppd_free_group(subgroup
);
2382 ppd_free(group
->subgroups
);
2388 * 'ppd_free_option()' - Free a single option.
2392 ppd_free_option(ppd_option_t
*option
) /* I - Option to free */
2394 int i
; /* Looping var */
2395 ppd_choice_t
*choice
; /* Current choice */
2398 if (option
->num_choices
> 0)
2400 for (i
= option
->num_choices
, choice
= option
->choices
;
2404 _cupsStrFree(choice
->code
);
2407 ppd_free(option
->choices
);
2413 * 'ppd_get_coption()' - Get a custom option record.
2416 static ppd_coption_t
* /* O - Custom option... */
2417 ppd_get_coption(ppd_file_t
*ppd
, /* I - PPD file */
2418 const char *name
) /* I - Name of option */
2420 ppd_coption_t
*copt
; /* New custom option */
2424 * See if the option already exists...
2427 if ((copt
= ppdFindCustomOption(ppd
, name
)) != NULL
)
2431 * Not found, so create the custom option record...
2434 if ((copt
= calloc(1, sizeof(ppd_coption_t
))) == NULL
)
2437 strlcpy(copt
->keyword
, name
, sizeof(copt
->keyword
));
2439 copt
->params
= cupsArrayNew((cups_array_func_t
)ppd_compare_cparams
, NULL
);
2441 cupsArrayAdd(ppd
->coptions
, copt
);
2444 * Return the new record...
2452 * 'ppd_get_cparam()' - Get a custom parameter record.
2455 static ppd_cparam_t
* /* O - Extended option... */
2456 ppd_get_cparam(ppd_coption_t
*opt
, /* I - PPD file */
2457 const char *param
, /* I - Name of parameter */
2458 const char *text
) /* I - Human-readable text */
2460 ppd_cparam_t
*cparam
; /* New custom parameter */
2464 * See if the parameter already exists...
2467 if ((cparam
= ppdFindCustomParam(opt
, param
)) != NULL
)
2471 * Not found, so create the custom parameter record...
2474 if ((cparam
= calloc(1, sizeof(ppd_cparam_t
))) == NULL
)
2477 strlcpy(cparam
->name
, param
, sizeof(cparam
->name
));
2478 strlcpy(cparam
->text
, text
[0] ? text
: param
, sizeof(cparam
->text
));
2481 * Add this record to the array...
2484 cupsArrayAdd(opt
->params
, cparam
);
2487 * Return the new record...
2495 * 'ppd_get_group()' - Find or create the named group as needed.
2498 static ppd_group_t
* /* O - Named group */
2499 ppd_get_group(ppd_file_t
*ppd
, /* I - PPD file */
2500 const char *name
, /* I - Name of group */
2501 const char *text
, /* I - Text for group */
2502 _cups_globals_t
*cg
, /* I - Global data */
2503 cups_encoding_t encoding
) /* I - Encoding of text */
2505 int i
; /* Looping var */
2506 ppd_group_t
*group
; /* Group */
2509 DEBUG_printf(("7ppd_get_group(ppd=%p, name=\"%s\", text=\"%s\", cg=%p)",
2510 ppd
, name
, text
, cg
));
2512 for (i
= ppd
->num_groups
, group
= ppd
->groups
; i
> 0; i
--, group
++)
2513 if (!strcmp(group
->name
, name
))
2518 DEBUG_printf(("8ppd_get_group: Adding group %s...", name
));
2520 if (cg
->ppd_conform
== PPD_CONFORM_STRICT
&& strlen(text
) >= sizeof(group
->text
))
2522 cg
->ppd_status
= PPD_ILLEGAL_TRANSLATION
;
2527 if (ppd
->num_groups
== 0)
2528 group
= malloc(sizeof(ppd_group_t
));
2530 group
= realloc(ppd
->groups
,
2531 (ppd
->num_groups
+ 1) * sizeof(ppd_group_t
));
2535 cg
->ppd_status
= PPD_ALLOC_ERROR
;
2540 ppd
->groups
= group
;
2541 group
+= ppd
->num_groups
;
2544 memset(group
, 0, sizeof(ppd_group_t
));
2545 strlcpy(group
->name
, name
, sizeof(group
->name
));
2547 cupsCharsetToUTF8((cups_utf8_t
*)group
->text
, text
,
2548 sizeof(group
->text
), encoding
);
2556 * 'ppd_get_option()' - Find or create the named option as needed.
2559 static ppd_option_t
* /* O - Named option */
2560 ppd_get_option(ppd_group_t
*group
, /* I - Group */
2561 const char *name
) /* I - Name of option */
2563 int i
; /* Looping var */
2564 ppd_option_t
*option
; /* Option */
2567 DEBUG_printf(("7ppd_get_option(group=%p(\"%s\"), name=\"%s\")",
2568 group
, group
->name
, name
));
2570 for (i
= group
->num_options
, option
= group
->options
; i
> 0; i
--, option
++)
2571 if (!strcmp(option
->keyword
, name
))
2576 if (group
->num_options
== 0)
2577 option
= malloc(sizeof(ppd_option_t
));
2579 option
= realloc(group
->options
,
2580 (group
->num_options
+ 1) * sizeof(ppd_option_t
));
2585 group
->options
= option
;
2586 option
+= group
->num_options
;
2587 group
->num_options
++;
2589 memset(option
, 0, sizeof(ppd_option_t
));
2590 strlcpy(option
->keyword
, name
, sizeof(option
->keyword
));
2598 * 'ppd_hash_option()' - Generate a hash of the option name...
2601 static int /* O - Hash index */
2602 ppd_hash_option(ppd_option_t
*option
) /* I - Option */
2604 int hash
= 0; /* Hash index */
2605 const char *k
; /* Pointer into keyword */
2608 for (hash
= option
->keyword
[0], k
= option
->keyword
+ 1; *k
;)
2609 hash
= 33 * hash
+ *k
++;
2611 return (hash
& 511);
2616 * 'ppd_read()' - Read a line from a PPD file, skipping comment lines as
2620 static int /* O - Bitmask of fields read */
2621 ppd_read(cups_file_t
*fp
, /* I - File to read from */
2622 _ppd_line_t
*line
, /* I - Line buffer */
2623 char *keyword
, /* O - Keyword from line */
2624 char *option
, /* O - Option from line */
2625 char *text
, /* O - Human-readable text from line */
2626 char **string
, /* O - Code/string data */
2627 int ignoreblank
, /* I - Ignore blank lines? */
2628 _cups_globals_t
*cg
) /* I - Global data */
2630 int ch
, /* Character from file */
2631 col
, /* Column in line */
2632 colon
, /* Colon seen? */
2633 endquote
, /* Waiting for an end quote */
2634 mask
, /* Mask to be returned */
2635 startline
, /* Start line */
2636 textlen
; /* Length of text */
2637 char *keyptr
, /* Keyword pointer */
2638 *optptr
, /* Option pointer */
2639 *textptr
, /* Text pointer */
2640 *strptr
, /* Pointer into string */
2641 *lineptr
; /* Current position in line buffer */
2645 * Now loop until we have a valid line...
2650 startline
= cg
->ppd_line
+ 1;
2654 line
->bufsize
= 1024;
2655 line
->buffer
= malloc(1024);
2667 lineptr
= line
->buffer
;
2671 while ((ch
= cupsFileGetChar(fp
)) != EOF
)
2673 if (lineptr
>= (line
->buffer
+ line
->bufsize
- 1))
2676 * Expand the line buffer...
2679 char *temp
; /* Temporary line pointer */
2682 line
->bufsize
+= 1024;
2683 if (line
->bufsize
> 262144)
2686 * Don't allow lines longer than 256k!
2689 cg
->ppd_line
= startline
;
2690 cg
->ppd_status
= PPD_LINE_TOO_LONG
;
2695 temp
= realloc(line
->buffer
, line
->bufsize
);
2698 cg
->ppd_line
= startline
;
2699 cg
->ppd_status
= PPD_LINE_TOO_LONG
;
2704 lineptr
= temp
+ (lineptr
- line
->buffer
);
2705 line
->buffer
= temp
;
2708 if (ch
== '\r' || ch
== '\n')
2711 * Line feed or carriage return...
2720 * Check for a trailing line feed...
2723 if ((ch
= cupsFilePeekChar(fp
)) == EOF
)
2730 cupsFileGetChar(fp
);
2733 if (lineptr
== line
->buffer
&& ignoreblank
)
2734 continue; /* Skip blank lines */
2738 if (!endquote
) /* Continue for multi-line text */
2743 else if (ch
< ' ' && ch
!= '\t' && cg
->ppd_conform
== PPD_CONFORM_STRICT
)
2746 * Other control characters...
2749 cg
->ppd_line
= startline
;
2750 cg
->ppd_status
= PPD_ILLEGAL_CHARACTER
;
2754 else if (ch
!= 0x1a)
2757 * Any other character...
2763 if (col
> (PPD_MAX_LINE
- 1))
2766 * Line is too long...
2769 cg
->ppd_line
= startline
;
2770 cg
->ppd_status
= PPD_LINE_TOO_LONG
;
2775 if (ch
== ':' && strncmp(line
->buffer
, "*%", 2) != 0)
2778 if (ch
== '\"' && colon
)
2779 endquote
= !endquote
;
2786 * Didn't finish this quoted string...
2789 while ((ch
= cupsFileGetChar(fp
)) != EOF
)
2792 else if (ch
== '\r' || ch
== '\n')
2800 * Check for a trailing line feed...
2803 if ((ch
= cupsFilePeekChar(fp
)) == EOF
)
2806 cupsFileGetChar(fp
);
2809 else if (ch
< ' ' && ch
!= '\t' && cg
->ppd_conform
== PPD_CONFORM_STRICT
)
2812 * Other control characters...
2815 cg
->ppd_line
= startline
;
2816 cg
->ppd_status
= PPD_ILLEGAL_CHARACTER
;
2820 else if (ch
!= 0x1a)
2824 if (col
> (PPD_MAX_LINE
- 1))
2827 * Line is too long...
2830 cg
->ppd_line
= startline
;
2831 cg
->ppd_status
= PPD_LINE_TOO_LONG
;
2841 * Didn't finish this line...
2844 while ((ch
= cupsFileGetChar(fp
)) != EOF
)
2845 if (ch
== '\r' || ch
== '\n')
2848 * Line feed or carriage return...
2857 * Check for a trailing line feed...
2860 if ((ch
= cupsFilePeekChar(fp
)) == EOF
)
2863 cupsFileGetChar(fp
);
2868 else if (ch
< ' ' && ch
!= '\t' && cg
->ppd_conform
== PPD_CONFORM_STRICT
)
2871 * Other control characters...
2874 cg
->ppd_line
= startline
;
2875 cg
->ppd_status
= PPD_ILLEGAL_CHARACTER
;
2879 else if (ch
!= 0x1a)
2883 if (col
> (PPD_MAX_LINE
- 1))
2886 * Line is too long...
2889 cg
->ppd_line
= startline
;
2890 cg
->ppd_status
= PPD_LINE_TOO_LONG
;
2897 if (lineptr
> line
->buffer
&& lineptr
[-1] == '\n')
2902 DEBUG_printf(("9ppd_read: LINE=\"%s\"", line
->buffer
));
2905 * The dynamically created PPDs for older style Mac OS X
2906 * drivers include a large blob of data inserted as comments
2907 * at the end of the file. As an optimization we can stop
2908 * reading the PPD when we get to the start of this data.
2911 if (!strcmp(line
->buffer
, "*%APLWORKSET START"))
2914 if (ch
== EOF
&& lineptr
== line
->buffer
)
2922 lineptr
= line
->buffer
+ 1;
2929 if ((!line
->buffer
[0] || /* Blank line */
2930 !strncmp(line
->buffer
, "*%", 2) || /* Comment line */
2931 !strcmp(line
->buffer
, "*End")) && /* End of multi-line string */
2932 ignoreblank
) /* Ignore these? */
2934 startline
= cg
->ppd_line
+ 1;
2938 if (!strcmp(line
->buffer
, "*")) /* (Bad) comment line */
2940 if (cg
->ppd_conform
== PPD_CONFORM_RELAXED
)
2942 startline
= cg
->ppd_line
+ 1;
2947 cg
->ppd_line
= startline
;
2948 cg
->ppd_status
= PPD_ILLEGAL_MAIN_KEYWORD
;
2954 if (line
->buffer
[0] != '*') /* All lines start with an asterisk */
2957 * Allow lines consisting of just whitespace...
2960 for (lineptr
= line
->buffer
; *lineptr
; lineptr
++)
2961 if (!isspace(*lineptr
& 255))
2966 cg
->ppd_status
= PPD_MISSING_ASTERISK
;
2969 else if (ignoreblank
)
2981 while (*lineptr
!= '\0' && *lineptr
!= ':' && !isspace(*lineptr
& 255))
2983 if (*lineptr
<= ' ' || *lineptr
> 126 || *lineptr
== '/' ||
2984 (keyptr
- keyword
) >= (PPD_MAX_NAME
- 1))
2986 cg
->ppd_status
= PPD_ILLEGAL_MAIN_KEYWORD
;
2990 *keyptr
++ = *lineptr
++;
2995 if (!strcmp(keyword
, "End"))
2998 mask
|= PPD_KEYWORD
;
3000 if (isspace(*lineptr
& 255))
3003 * Get an option name...
3006 while (isspace(*lineptr
& 255))
3011 while (*lineptr
!= '\0' && !isspace(*lineptr
& 255) && *lineptr
!= ':' &&
3014 if (*lineptr
<= ' ' || *lineptr
> 126 ||
3015 (optptr
- option
) >= (PPD_MAX_NAME
- 1))
3017 cg
->ppd_status
= PPD_ILLEGAL_OPTION_KEYWORD
;
3021 *optptr
++ = *lineptr
++;
3026 if (isspace(*lineptr
& 255) && cg
->ppd_conform
== PPD_CONFORM_STRICT
)
3028 cg
->ppd_status
= PPD_ILLEGAL_WHITESPACE
;
3032 while (isspace(*lineptr
& 255))
3037 if (*lineptr
== '/')
3040 * Get human-readable text...
3047 while (*lineptr
!= '\0' && *lineptr
!= '\n' && *lineptr
!= ':')
3049 if (((unsigned char)*lineptr
< ' ' && *lineptr
!= '\t') ||
3050 (textptr
- text
) >= (PPD_MAX_LINE
- 1))
3052 cg
->ppd_status
= PPD_ILLEGAL_TRANSLATION
;
3056 *textptr
++ = *lineptr
++;
3060 textlen
= ppd_decode(text
);
3062 if (textlen
> PPD_MAX_TEXT
&& cg
->ppd_conform
== PPD_CONFORM_STRICT
)
3064 cg
->ppd_status
= PPD_ILLEGAL_TRANSLATION
;
3072 if (isspace(*lineptr
& 255) && cg
->ppd_conform
== PPD_CONFORM_STRICT
)
3074 cg
->ppd_status
= PPD_ILLEGAL_WHITESPACE
;
3078 while (isspace(*lineptr
& 255))
3081 if (*lineptr
== ':')
3084 * Get string after triming leading and trailing whitespace...
3088 while (isspace(*lineptr
& 255))
3091 strptr
= lineptr
+ strlen(lineptr
) - 1;
3092 while (strptr
>= lineptr
&& isspace(*strptr
& 255))
3095 if (*strptr
== '\"')
3098 * Quoted string by itself, remove quotes...
3105 *string
= _cupsStrAlloc(lineptr
);
3117 * End of "$Id: ppd.c 7906 2008-09-03 20:19:43Z mike $".