2 * "$Id: ppd.c 7552 2008-05-12 17:42:15Z mike $"
4 * PPD file routines for the Common UNIX Printing System (CUPS).
6 * Copyright 2007-2008 by Apple Inc.
7 * Copyright 1997-2007 by Easy Software Products, all rights reserved.
9 * These coded instructions, statements, and computer programs are the
10 * property of Apple Inc. and are protected by Federal copyright
11 * law. Distribution and use rights are outlined in the file "LICENSE.txt"
12 * which should have been included with this file. If this file is
13 * file is missing or damaged, see the license at "http://www.cups.org/".
15 * PostScript is a trademark of Adobe Systems, Inc.
17 * This code and any derivative of it may be used and distributed
18 * freely under the terms of the GNU General Public License when
19 * used with GNU Ghostscript or its derivatives. Use of the code
20 * (or any derivative of it) with software other than GNU
21 * GhostScript (or its derivatives) is governed by the CUPS license
24 * This file is subject to the Apple OS-Developed Software exception.
28 * ppdClose() - Free all memory used by the PPD file.
29 * ppdErrorString() - Returns the text assocated with a status.
30 * _ppdGetEncoding() - Get the CUPS encoding value for the given
32 * ppdLastError() - Return the status from the last ppdOpen*().
33 * ppdOpen() - Read a PPD file into memory.
34 * ppdOpen2() - Read a PPD file into memory.
35 * ppdOpenFd() - Read a PPD file into memory.
36 * ppdOpenFile() - Read a PPD file into memory.
37 * ppdSetConformance() - Set the conformance level for PPD files.
38 * ppd_add_attr() - Add an attribute to the PPD data.
39 * ppd_add_choice() - Add a choice to an option.
40 * ppd_add_size() - Add a page size.
41 * ppd_compare_attrs() - Compare two attributes.
42 * ppd_compare_choices() - Compare two choices...
43 * ppd_compare_coptions() - Compare two custom options.
44 * ppd_compare_cparams() - Compare two custom parameters.
45 * ppd_compare_options() - Compare two options.
46 * ppd_decode() - Decode a string value...
47 * ppd_free_group() - Free a single UI group.
48 * ppd_free_option() - Free a single option.
49 * ppd_get_coption() - Get a custom option record.
50 * ppd_get_cparam() - Get a custom parameter record.
51 * ppd_get_group() - Find or create the named group as needed.
52 * ppd_get_option() - Find or create the named option as needed.
53 * ppd_hash_option() - Generate a hash of the option name...
54 * ppd_read() - Read a line from a PPD file, skipping comment
59 * Include necessary headers.
62 #include "ppd-private.h"
72 #if defined(WIN32) || defined(__EMX__)
73 # define READ_BINARY "rb" /* Open a binary file for reading */
74 # define WRITE_BINARY "wb" /* Open a binary file for writing */
76 # define READ_BINARY "r" /* Open a binary file for reading */
77 # define WRITE_BINARY "w" /* Open a binary file for writing */
78 #endif /* WIN32 || __EMX__ */
80 #define ppd_free(p) if (p) free(p) /* Safe free macro */
82 #define PPD_KEYWORD 1 /* Line contained a keyword */
83 #define PPD_OPTION 2 /* Line contained an option name */
84 #define PPD_TEXT 4 /* Line contained human-readable text */
85 #define PPD_STRING 8 /* Line contained a string or code */
87 #define PPD_HASHSIZE 512 /* Size of hash */
91 * Line buffer structure...
94 typedef struct _ppd_line_s
96 char *buffer
; /* Pointer to buffer */
97 size_t bufsize
; /* Size of the buffer */
105 static ppd_attr_t
*ppd_add_attr(ppd_file_t
*ppd
, const char *name
,
106 const char *spec
, const char *text
,
108 static ppd_choice_t
*ppd_add_choice(ppd_option_t
*option
, const char *name
);
109 static ppd_size_t
*ppd_add_size(ppd_file_t
*ppd
, const char *name
);
110 static int ppd_compare_attrs(ppd_attr_t
*a
, ppd_attr_t
*b
);
111 static int ppd_compare_choices(ppd_choice_t
*a
, ppd_choice_t
*b
);
112 static int ppd_compare_coptions(ppd_coption_t
*a
,
114 static int ppd_compare_cparams(ppd_cparam_t
*a
, ppd_cparam_t
*b
);
115 static int ppd_compare_options(ppd_option_t
*a
, ppd_option_t
*b
);
116 static int ppd_decode(char *string
);
117 static void ppd_free_group(ppd_group_t
*group
);
118 static void ppd_free_option(ppd_option_t
*option
);
119 static ppd_coption_t
*ppd_get_coption(ppd_file_t
*ppd
, const char *name
);
120 static ppd_cparam_t
*ppd_get_cparam(ppd_coption_t
*opt
,
123 static ppd_group_t
*ppd_get_group(ppd_file_t
*ppd
, const char *name
,
124 const char *text
, _cups_globals_t
*cg
,
125 cups_encoding_t encoding
);
126 static ppd_option_t
*ppd_get_option(ppd_group_t
*group
, const char *name
);
127 static int ppd_hash_option(ppd_option_t
*option
);
128 static int ppd_read(cups_file_t
*fp
, _ppd_line_t
*line
,
129 char *keyword
, char *option
, char *text
,
130 char **string
, int ignoreblank
,
131 _cups_globals_t
*cg
);
135 * 'ppdClose()' - Free all memory used by the PPD file.
139 ppdClose(ppd_file_t
*ppd
) /* I - PPD file record */
141 int i
; /* Looping var */
142 ppd_emul_t
*emul
; /* Current emulation */
143 ppd_group_t
*group
; /* Current group */
144 char **font
; /* Current font */
145 char **filter
; /* Current filter */
146 ppd_attr_t
**attr
; /* Current attribute */
147 ppd_coption_t
*coption
; /* Current custom option */
148 ppd_cparam_t
*cparam
; /* Current custom parameter */
152 * Range check arguments...
159 * Free all strings at the top level...
162 _cupsStrFree(ppd
->lang_encoding
);
163 _cupsStrFree(ppd
->nickname
);
164 _cupsStrFree(ppd
->patches
);
165 _cupsStrFree(ppd
->jcl_begin
);
166 _cupsStrFree(ppd
->jcl_end
);
167 _cupsStrFree(ppd
->jcl_ps
);
170 * Free any emulations...
173 if (ppd
->num_emulations
> 0)
175 for (i
= ppd
->num_emulations
, emul
= ppd
->emulations
; i
> 0; i
--, emul
++)
177 _cupsStrFree(emul
->start
);
178 _cupsStrFree(emul
->stop
);
181 ppd_free(ppd
->emulations
);
185 * Free any UI groups, subgroups, and options...
188 if (ppd
->num_groups
> 0)
190 for (i
= ppd
->num_groups
, group
= ppd
->groups
; i
> 0; i
--, group
++)
191 ppd_free_group(group
);
193 ppd_free(ppd
->groups
);
196 cupsArrayDelete(ppd
->options
);
197 cupsArrayDelete(ppd
->marked
);
200 * Free any page sizes...
203 if (ppd
->num_sizes
> 0)
204 ppd_free(ppd
->sizes
);
207 * Free any constraints...
210 if (ppd
->num_consts
> 0)
211 ppd_free(ppd
->consts
);
214 * Free any filters...
217 if (ppd
->num_filters
> 0)
219 for (i
= ppd
->num_filters
, filter
= ppd
->filters
; i
> 0; i
--, filter
++)
220 _cupsStrFree(*filter
);
222 ppd_free(ppd
->filters
);
229 if (ppd
->num_fonts
> 0)
231 for (i
= ppd
->num_fonts
, font
= ppd
->fonts
; i
> 0; i
--, font
++)
234 ppd_free(ppd
->fonts
);
238 * Free any profiles...
241 if (ppd
->num_profiles
> 0)
242 ppd_free(ppd
->profiles
);
245 * Free any attributes...
248 if (ppd
->num_attrs
> 0)
250 for (i
= ppd
->num_attrs
, attr
= ppd
->attrs
; i
> 0; i
--, attr
++)
252 _cupsStrFree((*attr
)->value
);
256 ppd_free(ppd
->attrs
);
259 cupsArrayDelete(ppd
->sorted_attrs
);
262 * Free custom options...
265 for (coption
= (ppd_coption_t
*)cupsArrayFirst(ppd
->coptions
);
267 coption
= (ppd_coption_t
*)cupsArrayNext(ppd
->coptions
))
269 for (cparam
= (ppd_cparam_t
*)cupsArrayFirst(coption
->params
);
271 cparam
= (ppd_cparam_t
*)cupsArrayNext(coption
->params
))
273 switch (cparam
->type
)
275 case PPD_CUSTOM_PASSCODE
:
276 case PPD_CUSTOM_PASSWORD
:
277 case PPD_CUSTOM_STRING
:
278 _cupsStrFree(cparam
->current
.custom_string
);
288 cupsArrayDelete(coption
->params
);
293 cupsArrayDelete(ppd
->coptions
);
296 * Free constraints...
299 if (ppd
->cups_uiconstraints
)
301 _ppd_cups_uiconsts_t
*consts
; /* Current constraints */
304 for (consts
= (_ppd_cups_uiconsts_t
*)cupsArrayFirst(ppd
->cups_uiconstraints
);
306 consts
= (_ppd_cups_uiconsts_t
*)cupsArrayNext(ppd
->cups_uiconstraints
))
308 free(consts
->constraints
);
312 cupsArrayDelete(ppd
->cups_uiconstraints
);
316 * Free the whole record...
324 * 'ppdErrorString()' - Returns the text assocated with a status.
326 * @since CUPS 1.1.19@
329 const char * /* O - Status string */
330 ppdErrorString(ppd_status_t status
) /* I - PPD status */
332 static const char * const messages
[] =/* Status messages */
335 _("Unable to open PPD file"),
336 _("NULL PPD file pointer"),
337 _("Memory allocation error"),
338 _("Missing PPD-Adobe-4.x header"),
339 _("Missing value string"),
342 _("OpenGroup without a CloseGroup first"),
343 _("Bad OpenUI/JCLOpenUI"),
344 _("OpenUI/JCLOpenUI without a CloseUI/JCLCloseUI first"),
345 _("Bad OrderDependency"),
346 _("Bad UIConstraints"),
347 _("Missing asterisk in column 1"),
348 _("Line longer than the maximum allowed (255 characters)"),
349 _("Illegal control character"),
350 _("Illegal main keyword string"),
351 _("Illegal option keyword string"),
352 _("Illegal translation string"),
353 _("Illegal whitespace character"),
354 _("Bad custom parameter")
358 if (status
< PPD_OK
|| status
> PPD_ILLEGAL_WHITESPACE
)
359 return (_cupsLangString(cupsLangDefault(), _("Unknown")));
361 return (_cupsLangString(cupsLangDefault(), messages
[status
]));
366 * '_ppdGetEncoding()' - Get the CUPS encoding value for the given
370 cups_encoding_t
/* O - CUPS encoding value */
371 _ppdGetEncoding(const char *name
) /* I - LanguageEncoding string */
373 if (!strcasecmp(name
, "ISOLatin1"))
374 return (CUPS_ISO8859_1
);
375 else if (!strcasecmp(name
, "ISOLatin2"))
376 return (CUPS_ISO8859_2
);
377 else if (!strcasecmp(name
, "ISOLatin5"))
378 return (CUPS_ISO8859_5
);
379 else if (!strcasecmp(name
, "JIS83-RKSJ"))
380 return (CUPS_WINDOWS_932
);
381 else if (!strcasecmp(name
, "MacStandard"))
382 return (CUPS_MAC_ROMAN
);
383 else if (!strcasecmp(name
, "WindowsANSI"))
384 return (CUPS_WINDOWS_1252
);
391 * 'ppdLastError()' - Return the status from the last ppdOpen*().
393 * @since CUPS 1.1.19@
396 ppd_status_t
/* O - Status code */
397 ppdLastError(int *line
) /* O - Line number */
399 _cups_globals_t
*cg
= _cupsGlobals();
404 *line
= cg
->ppd_line
;
406 return (cg
->ppd_status
);
411 * 'ppdOpen()' - Read a PPD file into memory.
414 ppd_file_t
* /* O - PPD file record */
415 ppdOpen(FILE *fp
) /* I - File to read from */
417 ppd_file_t
*ppd
; /* PPD file record */
418 cups_file_t
*cf
; /* CUPS file */
422 * Reopen the stdio file as a CUPS file...
425 if ((cf
= cupsFileOpenFd(fileno(fp
), "r")) == NULL
)
429 * Load the PPD file using the newer API...
435 * Close the CUPS file and return the PPD...
445 * 'ppdOpen2()' - Read a PPD file into memory.
450 ppd_file_t
* /* O - PPD file record or @code NULL@ if the PPD file could not be opened. */
451 ppdOpen2(cups_file_t
*fp
) /* I - File to read from */
453 int i
, j
, k
; /* Looping vars */
454 int count
; /* Temporary count */
455 _ppd_line_t line
; /* Line buffer */
456 ppd_file_t
*ppd
; /* PPD file record */
457 ppd_group_t
*group
, /* Current group */
458 *subgroup
; /* Current sub-group */
459 ppd_option_t
*option
; /* Current option */
460 ppd_choice_t
*choice
; /* Current choice */
461 ppd_const_t
*constraint
; /* Current constraint */
462 ppd_size_t
*size
; /* Current page size */
463 int mask
; /* Line data mask */
464 char keyword
[PPD_MAX_NAME
],
465 /* Keyword from file */
467 /* Option from file */
469 /* Human-readable text from file */
470 *string
, /* Code/text from file */
471 *sptr
, /* Pointer into string */
472 *nameptr
, /* Pointer into name */
473 *temp
, /* Temporary string pointer */
474 **tempfonts
; /* Temporary fonts pointer */
475 float order
; /* Order dependency number */
476 ppd_section_t section
; /* Order dependency section */
477 ppd_profile_t
*profile
; /* Pointer to color profile */
478 char **filter
; /* Pointer to filter */
479 cups_lang_t
*language
; /* Default language */
480 struct lconv
*loc
; /* Locale data */
481 int ui_keyword
; /* Is this line a UI keyword? */
482 cups_encoding_t encoding
; /* Encoding of PPD file */
483 _cups_globals_t
*cg
= _cupsGlobals();
485 char custom_name
[PPD_MAX_NAME
];
486 /* CustomFoo attribute name */
487 ppd_attr_t
*custom_attr
; /* CustomFoo attribute */
488 static const char * const ui_keywords
[] =
490 #ifdef CUPS_USE_FULL_UI_KEYWORDS_LIST
492 * Adobe defines some 41 keywords as "UI", meaning that they are
493 * user interface elements and that they should be treated as such
494 * even if the PPD creator doesn't use Open/CloseUI around them.
496 * Since this can cause previously invisible options to appear and
497 * confuse users, the default is to only treat the PageSize and
498 * PageRegion keywords this way.
500 /* Boolean keywords */
510 /* PickOne keywords */
523 "JCLFrameBufferSize",
544 #else /* !CUPS_USE_FULL_UI_KEYWORDS_LIST */
547 #endif /* CUPS_USE_FULL_UI_KEYWORDS_LIST */
552 * Default to "OK" status...
555 cg
->ppd_status
= PPD_OK
;
559 * Range check input...
564 cg
->ppd_status
= PPD_NULL_FILE
;
569 * Grab the first line and make sure it reads '*PPD-Adobe: "major.minor"'...
575 mask
= ppd_read(fp
, &line
, keyword
, name
, text
, &string
, 0, cg
);
577 DEBUG_printf(("mask=%x, keyword=\"%s\"...\n", mask
, keyword
));
580 strcmp(keyword
, "PPD-Adobe") ||
581 string
== NULL
|| string
[0] != '4')
584 * Either this is not a PPD file, or it is not a 4.x PPD file.
587 if (cg
->ppd_status
== PPD_OK
)
588 cg
->ppd_status
= PPD_MISSING_PPDADOBE4
;
590 _cupsStrFree(string
);
591 ppd_free(line
.buffer
);
596 DEBUG_printf(("ppdOpen: keyword = %s, string = %p\n", keyword
, string
));
598 _cupsStrFree(string
);
601 * Allocate memory for the PPD file record...
604 if ((ppd
= calloc(1, sizeof(ppd_file_t
))) == NULL
)
606 cg
->ppd_status
= PPD_ALLOC_ERROR
;
608 _cupsStrFree(string
);
609 ppd_free(line
.buffer
);
614 ppd
->language_level
= 2;
615 ppd
->color_device
= 0;
616 ppd
->colorspace
= PPD_CS_N
;
617 ppd
->landscape
= -90;
618 ppd
->coptions
= cupsArrayNew((cups_array_func_t
)ppd_compare_coptions
,
622 * Get the default language for the user...
625 language
= cupsLangDefault();
629 * Read lines from the PPD file and add them to the file record...
637 encoding
= CUPS_ISO8859_1
;
639 while ((mask
= ppd_read(fp
, &line
, keyword
, name
, text
, &string
, 1, cg
)) != 0)
641 DEBUG_printf(("mask=%x, keyword=\"%s\", name=\"%s\", text=\"%s\", "
642 "string=%d chars...", mask
, keyword
, name
, text
,
643 string
? (int)strlen(string
) : 0));
645 if (strncmp(keyword
, "Default", 7) && !string
)
648 * Need a string value!
651 cg
->ppd_status
= PPD_MISSING_VALUE
;
657 * Certain main keywords (as defined by the PPD spec) may be used
658 * without the usual OpenUI/CloseUI stuff. Presumably this is just
659 * so that Adobe wouldn't completely break compatibility with PPD
660 * files prior to v4.0 of the spec, but it is hopelessly
661 * inconsistent... Catch these main keywords and automatically
662 * create the corresponding option, as needed...
668 * Previous line was a UI keyword...
675 if (option
== NULL
&&
676 (mask
& (PPD_KEYWORD
| PPD_OPTION
| PPD_STRING
)) ==
677 (PPD_KEYWORD
| PPD_OPTION
| PPD_STRING
))
679 for (i
= 0; i
< (int)(sizeof(ui_keywords
) / sizeof(ui_keywords
[0])); i
++)
680 if (!strcmp(keyword
, ui_keywords
[i
]))
683 if (i
< (int)(sizeof(ui_keywords
) / sizeof(ui_keywords
[0])))
686 * Create the option in the appropriate group...
691 DEBUG_printf(("**** FOUND ADOBE UI KEYWORD %s WITHOUT OPENUI!\n",
696 if ((group
= ppd_get_group(ppd
, "General", _("General"), cg
,
700 DEBUG_printf(("Adding to group %s...\n", group
->text
));
701 option
= ppd_get_option(group
, keyword
);
705 option
= ppd_get_option(group
, keyword
);
709 cg
->ppd_status
= PPD_ALLOC_ERROR
;
715 * Now fill in the initial information for the option...
718 if (!strncmp(keyword
, "JCL", 3))
719 option
->section
= PPD_ORDER_JCL
;
721 option
->section
= PPD_ORDER_ANY
;
723 option
->order
= 10.0f
;
726 option
->ui
= PPD_UI_BOOLEAN
;
728 option
->ui
= PPD_UI_PICKONE
;
730 for (j
= 0; j
< ppd
->num_attrs
; j
++)
731 if (!strncmp(ppd
->attrs
[j
]->name
, "Default", 7) &&
732 !strcmp(ppd
->attrs
[j
]->name
+ 7, keyword
) &&
733 ppd
->attrs
[j
]->value
)
735 DEBUG_printf(("Setting Default%s to %s via attribute...\n",
736 option
->keyword
, ppd
->attrs
[j
]->value
));
737 strlcpy(option
->defchoice
, ppd
->attrs
[j
]->value
,
738 sizeof(option
->defchoice
));
742 if (!strcmp(keyword
, "PageSize"))
743 strlcpy(option
->text
, _("Media Size"), sizeof(option
->text
));
744 else if (!strcmp(keyword
, "MediaType"))
745 strlcpy(option
->text
, _("Media Type"), sizeof(option
->text
));
746 else if (!strcmp(keyword
, "InputSlot"))
747 strlcpy(option
->text
, _("Media Source"), sizeof(option
->text
));
748 else if (!strcmp(keyword
, "ColorModel"))
749 strlcpy(option
->text
, _("Output Mode"), sizeof(option
->text
));
750 else if (!strcmp(keyword
, "Resolution"))
751 strlcpy(option
->text
, _("Resolution"), sizeof(option
->text
));
753 strlcpy(option
->text
, keyword
, sizeof(option
->text
));
757 if (!strcmp(keyword
, "LanguageLevel"))
758 ppd
->language_level
= atoi(string
);
759 else if (!strcmp(keyword
, "LanguageEncoding"))
762 * Say all PPD files are UTF-8, since we convert to UTF-8...
765 ppd
->lang_encoding
= _cupsStrAlloc("UTF-8");
766 encoding
= _ppdGetEncoding(string
);
768 else if (!strcmp(keyword
, "LanguageVersion"))
769 ppd
->lang_version
= string
;
770 else if (!strcmp(keyword
, "Manufacturer"))
771 ppd
->manufacturer
= string
;
772 else if (!strcmp(keyword
, "ModelName"))
773 ppd
->modelname
= string
;
774 else if (!strcmp(keyword
, "Protocols"))
775 ppd
->protocols
= string
;
776 else if (!strcmp(keyword
, "PCFileName"))
777 ppd
->pcfilename
= string
;
778 else if (!strcmp(keyword
, "NickName"))
780 if (encoding
!= CUPS_UTF8
)
782 cups_utf8_t utf8
[256]; /* UTF-8 version of NickName */
785 cupsCharsetToUTF8(utf8
, string
, sizeof(utf8
), encoding
);
786 ppd
->nickname
= _cupsStrAlloc((char *)utf8
);
789 ppd
->nickname
= _cupsStrAlloc(string
);
791 else if (!strcmp(keyword
, "Product"))
792 ppd
->product
= string
;
793 else if (!strcmp(keyword
, "ShortNickName"))
794 ppd
->shortnickname
= string
;
795 else if (!strcmp(keyword
, "TTRasterizer"))
796 ppd
->ttrasterizer
= string
;
797 else if (!strcmp(keyword
, "JCLBegin"))
799 ppd
->jcl_begin
= _cupsStrAlloc(string
);
800 ppd_decode(ppd
->jcl_begin
); /* Decode quoted string */
802 else if (!strcmp(keyword
, "JCLEnd"))
804 ppd
->jcl_end
= _cupsStrAlloc(string
);
805 ppd_decode(ppd
->jcl_end
); /* Decode quoted string */
807 else if (!strcmp(keyword
, "JCLToPSInterpreter"))
809 ppd
->jcl_ps
= _cupsStrAlloc(string
);
810 ppd_decode(ppd
->jcl_ps
); /* Decode quoted string */
812 else if (!strcmp(keyword
, "AccurateScreensSupport"))
813 ppd
->accurate_screens
= !strcmp(string
, "True");
814 else if (!strcmp(keyword
, "ColorDevice"))
815 ppd
->color_device
= !strcmp(string
, "True");
816 else if (!strcmp(keyword
, "ContoneOnly"))
817 ppd
->contone_only
= !strcmp(string
, "True");
818 else if (!strcmp(keyword
, "cupsFlipDuplex"))
819 ppd
->flip_duplex
= !strcmp(string
, "True");
820 else if (!strcmp(keyword
, "cupsManualCopies"))
821 ppd
->manual_copies
= !strcmp(string
, "True");
822 else if (!strcmp(keyword
, "cupsModelNumber"))
823 ppd
->model_number
= atoi(string
);
824 else if (!strcmp(keyword
, "cupsColorProfile"))
826 if (ppd
->num_profiles
== 0)
827 profile
= malloc(sizeof(ppd_profile_t
));
829 profile
= realloc(ppd
->profiles
, sizeof(ppd_profile_t
) *
830 (ppd
->num_profiles
+ 1));
834 cg
->ppd_status
= PPD_ALLOC_ERROR
;
839 ppd
->profiles
= profile
;
840 profile
+= ppd
->num_profiles
;
841 ppd
->num_profiles
++;
843 memset(profile
, 0, sizeof(ppd_profile_t
));
844 strlcpy(profile
->resolution
, name
, sizeof(profile
->resolution
));
845 strlcpy(profile
->media_type
, text
, sizeof(profile
->media_type
));
847 profile
->density
= (float)_cupsStrScand(string
, &sptr
, loc
);
848 profile
->gamma
= (float)_cupsStrScand(sptr
, &sptr
, loc
);
849 profile
->matrix
[0][0] = (float)_cupsStrScand(sptr
, &sptr
, loc
);
850 profile
->matrix
[0][1] = (float)_cupsStrScand(sptr
, &sptr
, loc
);
851 profile
->matrix
[0][2] = (float)_cupsStrScand(sptr
, &sptr
, loc
);
852 profile
->matrix
[1][0] = (float)_cupsStrScand(sptr
, &sptr
, loc
);
853 profile
->matrix
[1][1] = (float)_cupsStrScand(sptr
, &sptr
, loc
);
854 profile
->matrix
[1][2] = (float)_cupsStrScand(sptr
, &sptr
, loc
);
855 profile
->matrix
[2][0] = (float)_cupsStrScand(sptr
, &sptr
, loc
);
856 profile
->matrix
[2][1] = (float)_cupsStrScand(sptr
, &sptr
, loc
);
857 profile
->matrix
[2][2] = (float)_cupsStrScand(sptr
, &sptr
, loc
);
859 else if (!strcmp(keyword
, "cupsFilter"))
861 if (ppd
->num_filters
== 0)
862 filter
= malloc(sizeof(char *));
864 filter
= realloc(ppd
->filters
, sizeof(char *) * (ppd
->num_filters
+ 1));
868 cg
->ppd_status
= PPD_ALLOC_ERROR
;
873 ppd
->filters
= filter
;
874 filter
+= ppd
->num_filters
;
878 * Copy filter string and prevent it from being freed below...
884 else if (!strcmp(keyword
, "Throughput"))
885 ppd
->throughput
= atoi(string
);
886 else if (!strcmp(keyword
, "Font"))
889 * Add this font to the list of available fonts...
892 if (ppd
->num_fonts
== 0)
893 tempfonts
= (char **)malloc(sizeof(char *));
895 tempfonts
= (char **)realloc(ppd
->fonts
,
896 sizeof(char *) * (ppd
->num_fonts
+ 1));
898 if (tempfonts
== NULL
)
900 cg
->ppd_status
= PPD_ALLOC_ERROR
;
905 ppd
->fonts
= tempfonts
;
906 ppd
->fonts
[ppd
->num_fonts
] = _cupsStrAlloc(name
);
909 else if (!strncmp(keyword
, "ParamCustom", 11))
911 ppd_coption_t
*coption
; /* Custom option */
912 ppd_cparam_t
*cparam
; /* Custom parameter */
913 int corder
; /* Order number */
914 char ctype
[33], /* Data type */
915 cminimum
[65], /* Minimum value */
916 cmaximum
[65]; /* Maximum value */
920 * Get the custom option and parameter...
923 if ((coption
= ppd_get_coption(ppd
, keyword
+ 11)) == NULL
)
925 cg
->ppd_status
= PPD_ALLOC_ERROR
;
930 if ((cparam
= ppd_get_cparam(coption
, name
, text
)) == NULL
)
932 cg
->ppd_status
= PPD_ALLOC_ERROR
;
938 * Get the parameter data...
941 if (sscanf(string
, "%d%32s%64s%64s", &corder
, ctype
, cminimum
,
944 cg
->ppd_status
= PPD_BAD_CUSTOM_PARAM
;
949 cparam
->order
= corder
;
951 if (!strcmp(ctype
, "curve"))
953 cparam
->type
= PPD_CUSTOM_CURVE
;
954 cparam
->minimum
.custom_curve
= (float)_cupsStrScand(cminimum
, NULL
, loc
);
955 cparam
->maximum
.custom_curve
= (float)_cupsStrScand(cmaximum
, NULL
, loc
);
957 else if (!strcmp(ctype
, "int"))
959 cparam
->type
= PPD_CUSTOM_INT
;
960 cparam
->minimum
.custom_int
= atoi(cminimum
);
961 cparam
->maximum
.custom_int
= atoi(cmaximum
);
963 else if (!strcmp(ctype
, "invcurve"))
965 cparam
->type
= PPD_CUSTOM_INVCURVE
;
966 cparam
->minimum
.custom_invcurve
= (float)_cupsStrScand(cminimum
, NULL
, loc
);
967 cparam
->maximum
.custom_invcurve
= (float)_cupsStrScand(cmaximum
, NULL
, loc
);
969 else if (!strcmp(ctype
, "passcode"))
971 cparam
->type
= PPD_CUSTOM_PASSCODE
;
972 cparam
->minimum
.custom_passcode
= atoi(cminimum
);
973 cparam
->maximum
.custom_passcode
= atoi(cmaximum
);
975 else if (!strcmp(ctype
, "password"))
977 cparam
->type
= PPD_CUSTOM_PASSWORD
;
978 cparam
->minimum
.custom_password
= atoi(cminimum
);
979 cparam
->maximum
.custom_password
= atoi(cmaximum
);
981 else if (!strcmp(ctype
, "points"))
983 cparam
->type
= PPD_CUSTOM_POINTS
;
984 cparam
->minimum
.custom_points
= (float)_cupsStrScand(cminimum
, NULL
, loc
);
985 cparam
->maximum
.custom_points
= (float)_cupsStrScand(cmaximum
, NULL
, loc
);
987 else if (!strcmp(ctype
, "real"))
989 cparam
->type
= PPD_CUSTOM_REAL
;
990 cparam
->minimum
.custom_real
= (float)_cupsStrScand(cminimum
, NULL
, loc
);
991 cparam
->maximum
.custom_real
= (float)_cupsStrScand(cmaximum
, NULL
, loc
);
993 else if (!strcmp(ctype
, "string"))
995 cparam
->type
= PPD_CUSTOM_STRING
;
996 cparam
->minimum
.custom_string
= atoi(cminimum
);
997 cparam
->maximum
.custom_string
= atoi(cmaximum
);
1001 cg
->ppd_status
= PPD_BAD_CUSTOM_PARAM
;
1007 * Now special-case for CustomPageSize...
1010 if (!strcmp(coption
->keyword
, "PageSize"))
1012 if (!strcmp(name
, "Width"))
1014 ppd
->custom_min
[0] = cparam
->minimum
.custom_points
;
1015 ppd
->custom_max
[0] = cparam
->maximum
.custom_points
;
1017 else if (!strcmp(name
, "Height"))
1019 ppd
->custom_min
[1] = cparam
->minimum
.custom_points
;
1020 ppd
->custom_max
[1] = cparam
->maximum
.custom_points
;
1024 else if (!strcmp(keyword
, "HWMargins"))
1026 for (i
= 0, sptr
= string
; i
< 4; i
++)
1027 ppd
->custom_margins
[i
] = (float)_cupsStrScand(sptr
, &sptr
, loc
);
1029 else if (!strncmp(keyword
, "Custom", 6) && !strcmp(name
, "True") && !option
)
1031 ppd_option_t
*custom_option
; /* Custom option */
1033 DEBUG_puts("Processing Custom option...");
1036 * Get the option and custom option...
1039 if (!ppd_get_coption(ppd
, keyword
+ 6))
1041 cg
->ppd_status
= PPD_ALLOC_ERROR
;
1046 if (option
&& !strcasecmp(option
->keyword
, keyword
+ 6))
1047 custom_option
= option
;
1049 custom_option
= ppdFindOption(ppd
, keyword
+ 6);
1054 * Add the "custom" option...
1057 if ((choice
= ppdFindChoice(custom_option
, "Custom")) == NULL
)
1058 if ((choice
= ppd_add_choice(custom_option
, "Custom")) == NULL
)
1060 DEBUG_puts("Unable to add Custom choice!");
1062 cg
->ppd_status
= PPD_ALLOC_ERROR
;
1067 strlcpy(choice
->text
, text
[0] ? text
: _("Custom"),
1068 sizeof(choice
->text
));
1070 choice
->code
= _cupsStrAlloc(string
);
1072 if (custom_option
->section
== PPD_ORDER_JCL
)
1073 ppd_decode(choice
->code
);
1077 * Now process custom page sizes specially...
1080 if (!strcmp(keyword
, "CustomPageSize"))
1083 * Add a "Custom" page size entry...
1086 ppd
->variable_sizes
= 1;
1088 ppd_add_size(ppd
, "Custom");
1090 if (option
&& !strcasecmp(option
->keyword
, "PageRegion"))
1091 custom_option
= option
;
1093 custom_option
= ppdFindOption(ppd
, "PageRegion");
1097 if ((choice
= ppdFindChoice(custom_option
, "Custom")) == NULL
)
1098 if ((choice
= ppd_add_choice(custom_option
, "Custom")) == NULL
)
1100 DEBUG_puts("Unable to add Custom choice!");
1102 cg
->ppd_status
= PPD_ALLOC_ERROR
;
1107 strlcpy(choice
->text
, text
[0] ? text
: _("Custom"),
1108 sizeof(choice
->text
));
1112 else if (!strcmp(keyword
, "LandscapeOrientation"))
1114 if (!strcmp(string
, "Minus90"))
1115 ppd
->landscape
= -90;
1116 else if (!strcmp(string
, "Plus90"))
1117 ppd
->landscape
= 90;
1119 else if (!strcmp(keyword
, "Emulators") && string
)
1121 for (count
= 1, sptr
= string
; sptr
!= NULL
;)
1122 if ((sptr
= strchr(sptr
, ' ')) != NULL
)
1125 while (*sptr
== ' ')
1129 ppd
->num_emulations
= count
;
1130 if ((ppd
->emulations
= calloc(count
, sizeof(ppd_emul_t
))) == NULL
)
1132 cg
->ppd_status
= PPD_ALLOC_ERROR
;
1137 for (i
= 0, sptr
= string
; i
< count
; i
++)
1139 for (nameptr
= ppd
->emulations
[i
].name
;
1140 *sptr
!= '\0' && *sptr
!= ' ';
1142 if (nameptr
< (ppd
->emulations
[i
].name
+ sizeof(ppd
->emulations
[i
].name
) - 1))
1147 while (*sptr
== ' ')
1151 else if (!strncmp(keyword
, "StartEmulator_", 14))
1155 for (i
= 0; i
< ppd
->num_emulations
; i
++)
1156 if (!strcmp(keyword
+ 14, ppd
->emulations
[i
].name
))
1158 ppd
->emulations
[i
].start
= string
;
1162 else if (!strncmp(keyword
, "StopEmulator_", 13))
1166 for (i
= 0; i
< ppd
->num_emulations
; i
++)
1167 if (!strcmp(keyword
+ 13, ppd
->emulations
[i
].name
))
1169 ppd
->emulations
[i
].stop
= string
;
1173 else if (!strcmp(keyword
, "JobPatchFile"))
1175 if (ppd
->patches
== NULL
)
1176 ppd
->patches
= _cupsStrAlloc(string
);
1179 temp
= realloc(ppd
->patches
, strlen(ppd
->patches
) +
1180 strlen(string
) + 1);
1183 cg
->ppd_status
= PPD_ALLOC_ERROR
;
1188 ppd
->patches
= temp
;
1190 strcpy(ppd
->patches
+ strlen(ppd
->patches
), string
);
1193 else if (!strcmp(keyword
, "OpenUI"))
1196 * Don't allow nesting of options...
1199 if (option
&& cg
->ppd_conform
== PPD_CONFORM_STRICT
)
1201 cg
->ppd_status
= PPD_NESTED_OPEN_UI
;
1207 * Add an option record to the current sub-group, group, or file...
1210 DEBUG_printf(("name=\"%s\" (%d)\n", name
, (int)strlen(name
)));
1213 _cups_strcpy(name
, name
+ 1); /* Eliminate leading asterisk */
1215 for (i
= (int)strlen(name
) - 1; i
> 0 && isspace(name
[i
] & 255); i
--)
1216 name
[i
] = '\0'; /* Eliminate trailing spaces */
1218 DEBUG_printf(("OpenUI of %s in group %s...\n", name
,
1219 group
? group
->text
: "(null)"));
1221 if (subgroup
!= NULL
)
1222 option
= ppd_get_option(subgroup
, name
);
1223 else if (group
== NULL
)
1225 if ((group
= ppd_get_group(ppd
, "General", _("General"), cg
,
1229 DEBUG_printf(("Adding to group %s...\n", group
->text
));
1230 option
= ppd_get_option(group
, name
);
1234 option
= ppd_get_option(group
, name
);
1238 cg
->ppd_status
= PPD_ALLOC_ERROR
;
1244 * Now fill in the initial information for the option...
1247 if (string
&& !strcmp(string
, "PickMany"))
1248 option
->ui
= PPD_UI_PICKMANY
;
1249 else if (string
&& !strcmp(string
, "Boolean"))
1250 option
->ui
= PPD_UI_BOOLEAN
;
1251 else if (string
&& !strcmp(string
, "PickOne"))
1252 option
->ui
= PPD_UI_PICKONE
;
1253 else if (cg
->ppd_conform
== PPD_CONFORM_STRICT
)
1255 cg
->ppd_status
= PPD_BAD_OPEN_UI
;
1260 option
->ui
= PPD_UI_PICKONE
;
1262 for (j
= 0; j
< ppd
->num_attrs
; j
++)
1263 if (!strncmp(ppd
->attrs
[j
]->name
, "Default", 7) &&
1264 !strcmp(ppd
->attrs
[j
]->name
+ 7, name
) &&
1265 ppd
->attrs
[j
]->value
)
1267 DEBUG_printf(("Setting Default%s to %s via attribute...\n",
1268 option
->keyword
, ppd
->attrs
[j
]->value
));
1269 strlcpy(option
->defchoice
, ppd
->attrs
[j
]->value
,
1270 sizeof(option
->defchoice
));
1275 cupsCharsetToUTF8((cups_utf8_t
*)option
->text
, text
,
1276 sizeof(option
->text
), encoding
);
1279 if (!strcmp(name
, "PageSize"))
1280 strlcpy(option
->text
, _("Media Size"), sizeof(option
->text
));
1281 else if (!strcmp(name
, "MediaType"))
1282 strlcpy(option
->text
, _("Media Type"), sizeof(option
->text
));
1283 else if (!strcmp(name
, "InputSlot"))
1284 strlcpy(option
->text
, _("Media Source"), sizeof(option
->text
));
1285 else if (!strcmp(name
, "ColorModel"))
1286 strlcpy(option
->text
, _("Output Mode"), sizeof(option
->text
));
1287 else if (!strcmp(name
, "Resolution"))
1288 strlcpy(option
->text
, _("Resolution"), sizeof(option
->text
));
1290 strlcpy(option
->text
, name
, sizeof(option
->text
));
1293 option
->section
= PPD_ORDER_ANY
;
1295 _cupsStrFree(string
);
1299 * Add a custom option choice if we have already seen a CustomFoo
1303 if (!strcasecmp(name
, "PageRegion"))
1304 strcpy(custom_name
, "CustomPageSize");
1306 snprintf(custom_name
, sizeof(custom_name
), "Custom%s", name
);
1308 if ((custom_attr
= ppdFindAttr(ppd
, custom_name
, "True")) != NULL
)
1310 if ((choice
= ppdFindChoice(option
, "Custom")) == NULL
)
1311 if ((choice
= ppd_add_choice(option
, "Custom")) == NULL
)
1313 DEBUG_puts("Unable to add Custom choice!");
1315 cg
->ppd_status
= PPD_ALLOC_ERROR
;
1320 strlcpy(choice
->text
,
1321 custom_attr
->text
[0] ? custom_attr
->text
: _("Custom"),
1322 sizeof(choice
->text
));
1323 choice
->code
= _cupsStrAlloc(custom_attr
->value
);
1326 else if (!strcmp(keyword
, "JCLOpenUI"))
1329 * Don't allow nesting of options...
1332 if (option
&& cg
->ppd_conform
== PPD_CONFORM_STRICT
)
1334 cg
->ppd_status
= PPD_NESTED_OPEN_UI
;
1340 * Find the JCL group, and add if needed...
1343 group
= ppd_get_group(ppd
, "JCL", _("JCL"), cg
, encoding
);
1349 * Add an option record to the current JCLs...
1353 _cups_strcpy(name
, name
+ 1);
1355 option
= ppd_get_option(group
, name
);
1359 cg
->ppd_status
= PPD_ALLOC_ERROR
;
1365 * Now fill in the initial information for the option...
1368 if (string
&& !strcmp(string
, "PickMany"))
1369 option
->ui
= PPD_UI_PICKMANY
;
1370 else if (string
&& !strcmp(string
, "Boolean"))
1371 option
->ui
= PPD_UI_BOOLEAN
;
1372 else if (string
&& !strcmp(string
, "PickOne"))
1373 option
->ui
= PPD_UI_PICKONE
;
1376 cg
->ppd_status
= PPD_BAD_OPEN_UI
;
1381 for (j
= 0; j
< ppd
->num_attrs
; j
++)
1382 if (!strncmp(ppd
->attrs
[j
]->name
, "Default", 7) &&
1383 !strcmp(ppd
->attrs
[j
]->name
+ 7, name
) &&
1384 ppd
->attrs
[j
]->value
)
1386 DEBUG_printf(("Setting Default%s to %s via attribute...\n",
1387 option
->keyword
, ppd
->attrs
[j
]->value
));
1388 strlcpy(option
->defchoice
, ppd
->attrs
[j
]->value
,
1389 sizeof(option
->defchoice
));
1394 cupsCharsetToUTF8((cups_utf8_t
*)option
->text
, text
,
1395 sizeof(option
->text
), encoding
);
1397 strlcpy(option
->text
, name
, sizeof(option
->text
));
1399 option
->section
= PPD_ORDER_JCL
;
1402 _cupsStrFree(string
);
1406 * Add a custom option choice if we have already seen a CustomFoo
1410 snprintf(custom_name
, sizeof(custom_name
), "Custom%s", name
);
1412 if ((custom_attr
= ppdFindAttr(ppd
, custom_name
, "True")) != NULL
)
1414 if ((choice
= ppd_add_choice(option
, "Custom")) == NULL
)
1416 DEBUG_puts("Unable to add Custom choice!");
1418 cg
->ppd_status
= PPD_ALLOC_ERROR
;
1423 strlcpy(choice
->text
,
1424 custom_attr
->text
[0] ? custom_attr
->text
: _("Custom"),
1425 sizeof(choice
->text
));
1426 choice
->code
= _cupsStrAlloc(custom_attr
->value
);
1429 else if (!strcmp(keyword
, "CloseUI") || !strcmp(keyword
, "JCLCloseUI"))
1433 _cupsStrFree(string
);
1436 else if (!strcmp(keyword
, "OpenGroup"))
1439 * Open a new group...
1444 cg
->ppd_status
= PPD_NESTED_OPEN_GROUP
;
1451 cg
->ppd_status
= PPD_BAD_OPEN_GROUP
;
1457 * Separate the group name from the text (name/text)...
1460 if ((sptr
= strchr(string
, '/')) != NULL
)
1466 * Fix up the text...
1472 * Find/add the group...
1475 group
= ppd_get_group(ppd
, string
, sptr
, cg
, encoding
);
1480 _cupsStrFree(string
);
1483 else if (!strcmp(keyword
, "CloseGroup"))
1487 _cupsStrFree(string
);
1490 else if (!strcmp(keyword
, "OrderDependency"))
1492 order
= (float)_cupsStrScand(string
, &sptr
, loc
);
1494 if (!sptr
|| sscanf(sptr
, "%40s%40s", name
, keyword
) != 2)
1496 cg
->ppd_status
= PPD_BAD_ORDER_DEPENDENCY
;
1501 if (keyword
[0] == '*')
1502 _cups_strcpy(keyword
, keyword
+ 1);
1504 if (!strcmp(name
, "ExitServer"))
1505 section
= PPD_ORDER_EXIT
;
1506 else if (!strcmp(name
, "Prolog"))
1507 section
= PPD_ORDER_PROLOG
;
1508 else if (!strcmp(name
, "DocumentSetup"))
1509 section
= PPD_ORDER_DOCUMENT
;
1510 else if (!strcmp(name
, "PageSetup"))
1511 section
= PPD_ORDER_PAGE
;
1512 else if (!strcmp(name
, "JCLSetup"))
1513 section
= PPD_ORDER_JCL
;
1515 section
= PPD_ORDER_ANY
;
1523 * Only valid for Non-UI options...
1526 for (i
= ppd
->num_groups
, gtemp
= ppd
->groups
; i
> 0; i
--, gtemp
++)
1527 if (gtemp
->text
[0] == '\0')
1531 for (i
= 0; i
< gtemp
->num_options
; i
++)
1532 if (!strcmp(keyword
, gtemp
->options
[i
].keyword
))
1534 gtemp
->options
[i
].section
= section
;
1535 gtemp
->options
[i
].order
= order
;
1541 option
->section
= section
;
1542 option
->order
= order
;
1545 _cupsStrFree(string
);
1548 else if (!strncmp(keyword
, "Default", 7))
1554 * Drop UI text, if any, from value...
1557 if (strchr(string
, '/') != NULL
)
1558 *strchr(string
, '/') = '\0';
1561 * Assign the default value as appropriate...
1564 if (!strcmp(keyword
, "DefaultColorSpace"))
1567 * Set default colorspace...
1570 if (!strcmp(string
, "CMY"))
1571 ppd
->colorspace
= PPD_CS_CMY
;
1572 else if (!strcmp(string
, "CMYK"))
1573 ppd
->colorspace
= PPD_CS_CMYK
;
1574 else if (!strcmp(string
, "RGB"))
1575 ppd
->colorspace
= PPD_CS_RGB
;
1576 else if (!strcmp(string
, "RGBK"))
1577 ppd
->colorspace
= PPD_CS_RGBK
;
1578 else if (!strcmp(string
, "N"))
1579 ppd
->colorspace
= PPD_CS_N
;
1581 ppd
->colorspace
= PPD_CS_GRAY
;
1583 else if (option
&& !strcmp(keyword
+ 7, option
->keyword
))
1586 * Set the default as part of the current option...
1589 DEBUG_printf(("Setting %s to %s...\n", keyword
, string
));
1591 strlcpy(option
->defchoice
, string
, sizeof(option
->defchoice
));
1593 DEBUG_printf(("%s is now %s...\n", keyword
, option
->defchoice
));
1598 * Lookup option and set if it has been defined...
1601 ppd_option_t
*toption
; /* Temporary option */
1604 if ((toption
= ppdFindOption(ppd
, keyword
+ 7)) != NULL
)
1606 DEBUG_printf(("Setting %s to %s...\n", keyword
, string
));
1607 strlcpy(toption
->defchoice
, string
, sizeof(toption
->defchoice
));
1611 else if (!strcmp(keyword
, "UIConstraints") ||
1612 !strcmp(keyword
, "NonUIConstraints"))
1614 if (ppd
->num_consts
== 0)
1615 constraint
= calloc(2, sizeof(ppd_const_t
));
1617 constraint
= realloc(ppd
->consts
,
1618 (ppd
->num_consts
+ 2) * sizeof(ppd_const_t
));
1620 if (constraint
== NULL
)
1622 cg
->ppd_status
= PPD_ALLOC_ERROR
;
1627 ppd
->consts
= constraint
;
1628 constraint
+= ppd
->num_consts
;
1631 switch (sscanf(string
, "%40s%40s%40s%40s", constraint
->option1
,
1632 constraint
->choice1
, constraint
->option2
,
1633 constraint
->choice2
))
1635 case 0 : /* Error */
1636 case 1 : /* Error */
1637 cg
->ppd_status
= PPD_BAD_UI_CONSTRAINTS
;
1640 case 2 : /* Two options... */
1642 * Check for broken constraints like "* Option"...
1645 if (cg
->ppd_conform
== PPD_CONFORM_STRICT
&&
1646 (!strcmp(constraint
->option1
, "*") ||
1647 !strcmp(constraint
->choice1
, "*")))
1649 cg
->ppd_status
= PPD_BAD_UI_CONSTRAINTS
;
1654 * The following strcpy's are safe, as optionN and
1655 * choiceN are all the same size (size defined by PPD spec...)
1658 if (constraint
->option1
[0] == '*')
1659 _cups_strcpy(constraint
->option1
, constraint
->option1
+ 1);
1660 else if (cg
->ppd_conform
== PPD_CONFORM_STRICT
)
1662 cg
->ppd_status
= PPD_BAD_UI_CONSTRAINTS
;
1666 if (constraint
->choice1
[0] == '*')
1667 _cups_strcpy(constraint
->option2
, constraint
->choice1
+ 1);
1668 else if (cg
->ppd_conform
== PPD_CONFORM_STRICT
)
1670 cg
->ppd_status
= PPD_BAD_UI_CONSTRAINTS
;
1674 constraint
->choice1
[0] = '\0';
1675 constraint
->choice2
[0] = '\0';
1678 case 3 : /* Two options, one choice... */
1680 * Check for broken constraints like "* Option"...
1683 if (cg
->ppd_conform
== PPD_CONFORM_STRICT
&&
1684 (!strcmp(constraint
->option1
, "*") ||
1685 !strcmp(constraint
->choice1
, "*") ||
1686 !strcmp(constraint
->option2
, "*")))
1688 cg
->ppd_status
= PPD_BAD_UI_CONSTRAINTS
;
1693 * The following _cups_strcpy's are safe, as optionN and
1694 * choiceN are all the same size (size defined by PPD spec...)
1697 if (constraint
->option1
[0] == '*')
1698 _cups_strcpy(constraint
->option1
, constraint
->option1
+ 1);
1699 else if (cg
->ppd_conform
== PPD_CONFORM_STRICT
)
1701 cg
->ppd_status
= PPD_BAD_UI_CONSTRAINTS
;
1705 if (constraint
->choice1
[0] == '*')
1707 if (cg
->ppd_conform
== PPD_CONFORM_STRICT
&&
1708 constraint
->option2
[0] == '*')
1710 cg
->ppd_status
= PPD_BAD_UI_CONSTRAINTS
;
1714 _cups_strcpy(constraint
->choice2
, constraint
->option2
);
1715 _cups_strcpy(constraint
->option2
, constraint
->choice1
+ 1);
1716 constraint
->choice1
[0] = '\0';
1720 if (constraint
->option2
[0] == '*')
1721 _cups_strcpy(constraint
->option2
, constraint
->option2
+ 1);
1722 else if (cg
->ppd_conform
== PPD_CONFORM_STRICT
)
1724 cg
->ppd_status
= PPD_BAD_UI_CONSTRAINTS
;
1728 constraint
->choice2
[0] = '\0';
1732 case 4 : /* Two options, two choices... */
1734 * Check for broken constraints like "* Option"...
1737 if (cg
->ppd_conform
== PPD_CONFORM_STRICT
&&
1738 (!strcmp(constraint
->option1
, "*") ||
1739 !strcmp(constraint
->choice1
, "*") ||
1740 !strcmp(constraint
->option2
, "*") ||
1741 !strcmp(constraint
->choice2
, "*")))
1743 cg
->ppd_status
= PPD_BAD_UI_CONSTRAINTS
;
1747 if (constraint
->option1
[0] == '*')
1748 _cups_strcpy(constraint
->option1
, constraint
->option1
+ 1);
1749 else if (cg
->ppd_conform
== PPD_CONFORM_STRICT
)
1751 cg
->ppd_status
= PPD_BAD_UI_CONSTRAINTS
;
1755 if (cg
->ppd_conform
== PPD_CONFORM_STRICT
&&
1756 constraint
->choice1
[0] == '*')
1758 cg
->ppd_status
= PPD_BAD_UI_CONSTRAINTS
;
1762 if (constraint
->option2
[0] == '*')
1763 _cups_strcpy(constraint
->option2
, constraint
->option2
+ 1);
1764 else if (cg
->ppd_conform
== PPD_CONFORM_STRICT
)
1766 cg
->ppd_status
= PPD_BAD_UI_CONSTRAINTS
;
1770 if (cg
->ppd_conform
== PPD_CONFORM_STRICT
&&
1771 constraint
->choice2
[0] == '*')
1773 cg
->ppd_status
= PPD_BAD_UI_CONSTRAINTS
;
1780 * Don't add this one as an attribute...
1783 _cupsStrFree(string
);
1786 else if (!strcmp(keyword
, "PaperDimension"))
1788 if ((size
= ppdPageSize(ppd
, name
)) == NULL
)
1789 size
= ppd_add_size(ppd
, name
);
1794 * Unable to add or find size!
1797 cg
->ppd_status
= PPD_ALLOC_ERROR
;
1802 size
->width
= (float)_cupsStrScand(string
, &sptr
, loc
);
1803 size
->length
= (float)_cupsStrScand(sptr
, NULL
, loc
);
1805 _cupsStrFree(string
);
1808 else if (!strcmp(keyword
, "ImageableArea"))
1810 if ((size
= ppdPageSize(ppd
, name
)) == NULL
)
1811 size
= ppd_add_size(ppd
, name
);
1816 * Unable to add or find size!
1819 cg
->ppd_status
= PPD_ALLOC_ERROR
;
1824 size
->left
= (float)_cupsStrScand(string
, &sptr
, loc
);
1825 size
->bottom
= (float)_cupsStrScand(sptr
, &sptr
, loc
);
1826 size
->right
= (float)_cupsStrScand(sptr
, &sptr
, loc
);
1827 size
->top
= (float)_cupsStrScand(sptr
, NULL
, loc
);
1829 _cupsStrFree(string
);
1832 else if (option
!= NULL
&&
1833 (mask
& (PPD_KEYWORD
| PPD_OPTION
| PPD_STRING
)) ==
1834 (PPD_KEYWORD
| PPD_OPTION
| PPD_STRING
) &&
1835 !strcmp(keyword
, option
->keyword
))
1837 DEBUG_printf(("group = %p, subgroup = %p\n", group
, subgroup
));
1839 if (!strcmp(keyword
, "PageSize"))
1842 * Add a page size...
1845 if (ppdPageSize(ppd
, name
) == NULL
)
1846 ppd_add_size(ppd
, name
);
1850 * Add the option choice...
1853 if ((choice
= ppd_add_choice(option
, name
)) == NULL
)
1855 cg
->ppd_status
= PPD_ALLOC_ERROR
;
1861 cupsCharsetToUTF8((cups_utf8_t
*)choice
->text
, text
,
1862 sizeof(choice
->text
), encoding
);
1863 else if (!strcmp(name
, "True"))
1864 strcpy(choice
->text
, _("Yes"));
1865 else if (!strcmp(name
, "False"))
1866 strcpy(choice
->text
, _("No"));
1868 strlcpy(choice
->text
, name
, sizeof(choice
->text
));
1870 if (option
->section
== PPD_ORDER_JCL
)
1871 ppd_decode(string
); /* Decode quoted string */
1873 choice
->code
= string
;
1874 string
= NULL
; /* Don't add as an attribute below */
1878 * Add remaining lines with keywords and string values as attributes...
1882 (mask
& (PPD_KEYWORD
| PPD_STRING
)) == (PPD_KEYWORD
| PPD_STRING
))
1883 ppd_add_attr(ppd
, keyword
, name
, text
, string
);
1885 _cupsStrFree(string
);
1888 ppd_free(line
.buffer
);
1891 * Reset language preferences...
1894 cupsLangFree(language
);
1897 if (!cupsFileEOF(fp
))
1898 DEBUG_printf(("Premature EOF at %lu...\n",
1899 (unsigned long)cupsFileTell(fp
)));
1902 if (cg
->ppd_status
!= PPD_OK
)
1905 * Had an error reading the PPD file, cannot continue!
1914 * Create the sorted options array and set the option back-pointer for
1915 * each choice and custom option...
1918 ppd
->options
= cupsArrayNew2((cups_array_func_t
)ppd_compare_options
, NULL
,
1919 (cups_ahash_func_t
)ppd_hash_option
,
1922 for (i
= ppd
->num_groups
, group
= ppd
->groups
;
1926 for (j
= group
->num_options
, option
= group
->options
;
1930 ppd_coption_t
*coption
; /* Custom option */
1933 cupsArrayAdd(ppd
->options
, option
);
1935 for (k
= 0; k
< option
->num_choices
; k
++)
1936 option
->choices
[k
].option
= option
;
1938 if ((coption
= ppdFindCustomOption(ppd
, option
->keyword
)) != NULL
)
1939 coption
->option
= option
;
1944 * Create an array to track the marked choices...
1947 ppd
->marked
= cupsArrayNew((cups_array_func_t
)ppd_compare_choices
, NULL
);
1950 * Return the PPD file structure...
1956 * Common exit point for errors to save code size...
1961 _cupsStrFree(string
);
1962 ppd_free(line
.buffer
);
1966 cupsLangFree(language
);
1973 * 'ppdOpenFd()' - Read a PPD file into memory.
1976 ppd_file_t
* /* O - PPD file record or @code NULL@ if the PPD file could not be opened. */
1977 ppdOpenFd(int fd
) /* I - File to read from */
1979 cups_file_t
*fp
; /* CUPS file pointer */
1980 ppd_file_t
*ppd
; /* PPD file record */
1981 _cups_globals_t
*cg
= _cupsGlobals();
1986 * Set the line number to 0...
1992 * Range check input...
1997 cg
->ppd_status
= PPD_NULL_FILE
;
2003 * Try to open the file and parse it...
2006 if ((fp
= cupsFileOpenFd(fd
, "r")) != NULL
)
2014 cg
->ppd_status
= PPD_FILE_OPEN_ERROR
;
2023 * 'ppdOpenFile()' - Read a PPD file into memory.
2026 ppd_file_t
* /* O - PPD file record or @code NULL@ if the PPD file could not be opened. */
2027 ppdOpenFile(const char *filename
) /* I - File to read from */
2029 cups_file_t
*fp
; /* File pointer */
2030 ppd_file_t
*ppd
; /* PPD file record */
2031 _cups_globals_t
*cg
= _cupsGlobals();
2036 * Set the line number to 0...
2042 * Range check input...
2045 if (filename
== NULL
)
2047 cg
->ppd_status
= PPD_NULL_FILE
;
2053 * Try to open the file and parse it...
2056 if ((fp
= cupsFileOpen(filename
, "r")) != NULL
)
2064 cg
->ppd_status
= PPD_FILE_OPEN_ERROR
;
2073 * 'ppdSetConformance()' - Set the conformance level for PPD files.
2075 * @since CUPS 1.1.20@
2079 ppdSetConformance(ppd_conform_t c
) /* I - Conformance level */
2081 _cups_globals_t
*cg
= _cupsGlobals();
2085 cg
->ppd_conform
= c
;
2090 * 'ppd_add_attr()' - Add an attribute to the PPD data.
2093 static ppd_attr_t
* /* O - New attribute */
2094 ppd_add_attr(ppd_file_t
*ppd
, /* I - PPD file data */
2095 const char *name
, /* I - Attribute name */
2096 const char *spec
, /* I - Specifier string, if any */
2097 const char *text
, /* I - Text string, if any */
2098 const char *value
) /* I - Value of attribute */
2100 ppd_attr_t
**ptr
, /* New array */
2101 *temp
; /* New attribute */
2105 * Range check input...
2108 if (ppd
== NULL
|| name
== NULL
|| spec
== NULL
)
2112 * Create the array as needed...
2115 if (!ppd
->sorted_attrs
)
2116 ppd
->sorted_attrs
= cupsArrayNew((cups_array_func_t
)ppd_compare_attrs
,
2120 * Allocate memory for the new attribute...
2123 if (ppd
->num_attrs
== 0)
2124 ptr
= malloc(sizeof(ppd_attr_t
*));
2126 ptr
= realloc(ppd
->attrs
, (ppd
->num_attrs
+ 1) * sizeof(ppd_attr_t
*));
2132 ptr
+= ppd
->num_attrs
;
2134 if ((temp
= calloc(1, sizeof(ppd_attr_t
))) == NULL
)
2145 strlcpy(temp
->name
, name
, sizeof(temp
->name
));
2146 strlcpy(temp
->spec
, spec
, sizeof(temp
->spec
));
2147 strlcpy(temp
->text
, text
, sizeof(temp
->text
));
2148 temp
->value
= (char *)value
;
2151 * Add the attribute to the sorted array...
2154 cupsArrayAdd(ppd
->sorted_attrs
, temp
);
2157 * Return the attribute...
2165 * 'ppd_add_choice()' - Add a choice to an option.
2168 static ppd_choice_t
* /* O - Named choice */
2169 ppd_add_choice(ppd_option_t
*option
, /* I - Option */
2170 const char *name
) /* I - Name of choice */
2172 ppd_choice_t
*choice
; /* Choice */
2175 if (option
->num_choices
== 0)
2176 choice
= malloc(sizeof(ppd_choice_t
));
2178 choice
= realloc(option
->choices
,
2179 sizeof(ppd_choice_t
) * (option
->num_choices
+ 1));
2184 option
->choices
= choice
;
2185 choice
+= option
->num_choices
;
2186 option
->num_choices
++;
2188 memset(choice
, 0, sizeof(ppd_choice_t
));
2189 strlcpy(choice
->choice
, name
, sizeof(choice
->choice
));
2196 * 'ppd_add_size()' - Add a page size.
2199 static ppd_size_t
* /* O - Named size */
2200 ppd_add_size(ppd_file_t
*ppd
, /* I - PPD file */
2201 const char *name
) /* I - Name of size */
2203 ppd_size_t
*size
; /* Size */
2206 if (ppd
->num_sizes
== 0)
2207 size
= malloc(sizeof(ppd_size_t
));
2209 size
= realloc(ppd
->sizes
, sizeof(ppd_size_t
) * (ppd
->num_sizes
+ 1));
2215 size
+= ppd
->num_sizes
;
2218 memset(size
, 0, sizeof(ppd_size_t
));
2219 strlcpy(size
->name
, name
, sizeof(size
->name
));
2226 * 'ppd_compare_attrs()' - Compare two attributes.
2229 static int /* O - Result of comparison */
2230 ppd_compare_attrs(ppd_attr_t
*a
, /* I - First attribute */
2231 ppd_attr_t
*b
) /* I - Second attribute */
2233 int ret
; /* Result of comparison */
2236 if ((ret
= strcasecmp(a
->name
, b
->name
)) != 0)
2239 return (strcasecmp(a
->spec
, b
->spec
));
2244 * 'ppd_compare_choices()' - Compare two choices...
2247 static int /* O - Result of comparison */
2248 ppd_compare_choices(ppd_choice_t
*a
, /* I - First choice */
2249 ppd_choice_t
*b
) /* I - Second choice */
2251 return (strcmp(a
->option
->keyword
, b
->option
->keyword
));
2256 * 'ppd_compare_coptions()' - Compare two custom options.
2259 static int /* O - Result of comparison */
2260 ppd_compare_coptions(ppd_coption_t
*a
, /* I - First option */
2261 ppd_coption_t
*b
) /* I - Second option */
2263 return (strcasecmp(a
->keyword
, b
->keyword
));
2268 * 'ppd_compare_cparams()' - Compare two custom parameters.
2271 static int /* O - Result of comparison */
2272 ppd_compare_cparams(ppd_cparam_t
*a
, /* I - First parameter */
2273 ppd_cparam_t
*b
) /* I - Second parameter */
2275 return (strcasecmp(a
->name
, b
->name
));
2280 * 'ppd_compare_options()' - Compare two options.
2283 static int /* O - Result of comparison */
2284 ppd_compare_options(ppd_option_t
*a
, /* I - First option */
2285 ppd_option_t
*b
) /* I - Second option */
2287 return (strcasecmp(a
->keyword
, b
->keyword
));
2292 * 'ppd_decode()' - Decode a string value...
2295 static int /* O - Length of decoded string */
2296 ppd_decode(char *string
) /* I - String to decode */
2298 char *inptr
, /* Input pointer */
2299 *outptr
; /* Output pointer */
2305 while (*inptr
!= '\0')
2306 if (*inptr
== '<' && isxdigit(inptr
[1] & 255))
2309 * Convert hex to 8-bit values...
2313 while (isxdigit(*inptr
& 255))
2315 if (isalpha(*inptr
))
2316 *outptr
= (tolower(*inptr
) - 'a' + 10) << 4;
2318 *outptr
= (*inptr
- '0') << 4;
2322 if (!isxdigit(*inptr
& 255))
2325 if (isalpha(*inptr
))
2326 *outptr
|= tolower(*inptr
) - 'a' + 10;
2328 *outptr
|= *inptr
- '0';
2334 while (*inptr
!= '>' && *inptr
!= '\0')
2336 while (*inptr
== '>')
2340 *outptr
++ = *inptr
++;
2344 return ((int)(outptr
- string
));
2349 * 'ppd_free_group()' - Free a single UI group.
2353 ppd_free_group(ppd_group_t
*group
) /* I - Group to free */
2355 int i
; /* Looping var */
2356 ppd_option_t
*option
; /* Current option */
2357 ppd_group_t
*subgroup
; /* Current sub-group */
2360 if (group
->num_options
> 0)
2362 for (i
= group
->num_options
, option
= group
->options
;
2365 ppd_free_option(option
);
2367 ppd_free(group
->options
);
2370 if (group
->num_subgroups
> 0)
2372 for (i
= group
->num_subgroups
, subgroup
= group
->subgroups
;
2375 ppd_free_group(subgroup
);
2377 ppd_free(group
->subgroups
);
2383 * 'ppd_free_option()' - Free a single option.
2387 ppd_free_option(ppd_option_t
*option
) /* I - Option to free */
2389 int i
; /* Looping var */
2390 ppd_choice_t
*choice
; /* Current choice */
2393 if (option
->num_choices
> 0)
2395 for (i
= option
->num_choices
, choice
= option
->choices
;
2399 _cupsStrFree(choice
->code
);
2402 ppd_free(option
->choices
);
2408 * 'ppd_get_coption()' - Get a custom option record.
2411 static ppd_coption_t
* /* O - Custom option... */
2412 ppd_get_coption(ppd_file_t
*ppd
, /* I - PPD file */
2413 const char *name
) /* I - Name of option */
2415 ppd_coption_t
*copt
; /* New custom option */
2419 * See if the option already exists...
2422 if ((copt
= ppdFindCustomOption(ppd
, name
)) != NULL
)
2426 * Not found, so create the custom option record...
2429 if ((copt
= calloc(1, sizeof(ppd_coption_t
))) == NULL
)
2432 strlcpy(copt
->keyword
, name
, sizeof(copt
->keyword
));
2434 copt
->params
= cupsArrayNew((cups_array_func_t
)ppd_compare_cparams
, NULL
);
2436 cupsArrayAdd(ppd
->coptions
, copt
);
2439 * Return the new record...
2447 * 'ppd_get_cparam()' - Get a custom parameter record.
2450 static ppd_cparam_t
* /* O - Extended option... */
2451 ppd_get_cparam(ppd_coption_t
*opt
, /* I - PPD file */
2452 const char *param
, /* I - Name of parameter */
2453 const char *text
) /* I - Human-readable text */
2455 ppd_cparam_t
*cparam
; /* New custom parameter */
2459 * See if the parameter already exists...
2462 if ((cparam
= ppdFindCustomParam(opt
, param
)) != NULL
)
2466 * Not found, so create the custom parameter record...
2469 if ((cparam
= calloc(1, sizeof(ppd_cparam_t
))) == NULL
)
2472 strlcpy(cparam
->name
, param
, sizeof(cparam
->name
));
2473 strlcpy(cparam
->text
, text
[0] ? text
: param
, sizeof(cparam
->text
));
2476 * Add this record to the array...
2479 cupsArrayAdd(opt
->params
, cparam
);
2482 * Return the new record...
2490 * 'ppd_get_group()' - Find or create the named group as needed.
2493 static ppd_group_t
* /* O - Named group */
2494 ppd_get_group(ppd_file_t
*ppd
, /* I - PPD file */
2495 const char *name
, /* I - Name of group */
2496 const char *text
, /* I - Text for group */
2497 _cups_globals_t
*cg
, /* I - Global data */
2498 cups_encoding_t encoding
) /* I - Encoding of text */
2500 int i
; /* Looping var */
2501 ppd_group_t
*group
; /* Group */
2504 DEBUG_printf(("ppd_get_group(ppd=%p, name=\"%s\", text=\"%s\", cg=%p)\n",
2505 ppd
, name
, text
, cg
));
2507 for (i
= ppd
->num_groups
, group
= ppd
->groups
; i
> 0; i
--, group
++)
2508 if (!strcmp(group
->name
, name
))
2513 DEBUG_printf(("Adding group %s...\n", name
));
2515 if (cg
->ppd_conform
== PPD_CONFORM_STRICT
&& strlen(text
) >= sizeof(group
->text
))
2517 cg
->ppd_status
= PPD_ILLEGAL_TRANSLATION
;
2522 if (ppd
->num_groups
== 0)
2523 group
= malloc(sizeof(ppd_group_t
));
2525 group
= realloc(ppd
->groups
,
2526 (ppd
->num_groups
+ 1) * sizeof(ppd_group_t
));
2530 cg
->ppd_status
= PPD_ALLOC_ERROR
;
2535 ppd
->groups
= group
;
2536 group
+= ppd
->num_groups
;
2539 memset(group
, 0, sizeof(ppd_group_t
));
2540 strlcpy(group
->name
, name
, sizeof(group
->name
));
2542 cupsCharsetToUTF8((cups_utf8_t
*)group
->text
, text
,
2543 sizeof(group
->text
), encoding
);
2551 * 'ppd_get_option()' - Find or create the named option as needed.
2554 static ppd_option_t
* /* O - Named option */
2555 ppd_get_option(ppd_group_t
*group
, /* I - Group */
2556 const char *name
) /* I - Name of option */
2558 int i
; /* Looping var */
2559 ppd_option_t
*option
; /* Option */
2562 DEBUG_printf(("ppd_get_option(group=%p(\"%s\"), name=\"%s\")\n",
2563 group
, group
->name
, name
));
2565 for (i
= group
->num_options
, option
= group
->options
; i
> 0; i
--, option
++)
2566 if (!strcmp(option
->keyword
, name
))
2571 if (group
->num_options
== 0)
2572 option
= malloc(sizeof(ppd_option_t
));
2574 option
= realloc(group
->options
,
2575 (group
->num_options
+ 1) * sizeof(ppd_option_t
));
2580 group
->options
= option
;
2581 option
+= group
->num_options
;
2582 group
->num_options
++;
2584 memset(option
, 0, sizeof(ppd_option_t
));
2585 strlcpy(option
->keyword
, name
, sizeof(option
->keyword
));
2593 * 'ppd_hash_option()' - Generate a hash of the option name...
2596 static int /* O - Hash index */
2597 ppd_hash_option(ppd_option_t
*option
) /* I - Option */
2599 int hash
= 0; /* Hash index */
2600 const char *k
; /* Pointer into keyword */
2603 for (hash
= option
->keyword
[0], k
= option
->keyword
+ 1; *k
;)
2604 hash
= 33 * hash
+ *k
++;
2606 return (hash
& 511);
2611 * 'ppd_read()' - Read a line from a PPD file, skipping comment lines as
2615 static int /* O - Bitmask of fields read */
2616 ppd_read(cups_file_t
*fp
, /* I - File to read from */
2617 _ppd_line_t
*line
, /* I - Line buffer */
2618 char *keyword
, /* O - Keyword from line */
2619 char *option
, /* O - Option from line */
2620 char *text
, /* O - Human-readable text from line */
2621 char **string
, /* O - Code/string data */
2622 int ignoreblank
, /* I - Ignore blank lines? */
2623 _cups_globals_t
*cg
) /* I - Global data */
2625 int ch
, /* Character from file */
2626 col
, /* Column in line */
2627 colon
, /* Colon seen? */
2628 endquote
, /* Waiting for an end quote */
2629 mask
, /* Mask to be returned */
2630 startline
, /* Start line */
2631 textlen
; /* Length of text */
2632 char *keyptr
, /* Keyword pointer */
2633 *optptr
, /* Option pointer */
2634 *textptr
, /* Text pointer */
2635 *strptr
, /* Pointer into string */
2636 *lineptr
; /* Current position in line buffer */
2640 * Now loop until we have a valid line...
2645 startline
= cg
->ppd_line
+ 1;
2649 line
->bufsize
= 1024;
2650 line
->buffer
= malloc(1024);
2662 lineptr
= line
->buffer
;
2666 while ((ch
= cupsFileGetChar(fp
)) != EOF
)
2668 if (lineptr
>= (line
->buffer
+ line
->bufsize
- 1))
2671 * Expand the line buffer...
2674 char *temp
; /* Temporary line pointer */
2677 line
->bufsize
+= 1024;
2678 if (line
->bufsize
> 262144)
2681 * Don't allow lines longer than 256k!
2684 cg
->ppd_line
= startline
;
2685 cg
->ppd_status
= PPD_LINE_TOO_LONG
;
2690 temp
= realloc(line
->buffer
, line
->bufsize
);
2693 cg
->ppd_line
= startline
;
2694 cg
->ppd_status
= PPD_LINE_TOO_LONG
;
2699 lineptr
= temp
+ (lineptr
- line
->buffer
);
2700 line
->buffer
= temp
;
2703 if (ch
== '\r' || ch
== '\n')
2706 * Line feed or carriage return...
2715 * Check for a trailing line feed...
2718 if ((ch
= cupsFilePeekChar(fp
)) == EOF
)
2725 cupsFileGetChar(fp
);
2728 if (lineptr
== line
->buffer
&& ignoreblank
)
2729 continue; /* Skip blank lines */
2733 if (!endquote
) /* Continue for multi-line text */
2738 else if (ch
< ' ' && ch
!= '\t' && cg
->ppd_conform
== PPD_CONFORM_STRICT
)
2741 * Other control characters...
2744 cg
->ppd_line
= startline
;
2745 cg
->ppd_status
= PPD_ILLEGAL_CHARACTER
;
2749 else if (ch
!= 0x1a)
2752 * Any other character...
2758 if (col
> (PPD_MAX_LINE
- 1))
2761 * Line is too long...
2764 cg
->ppd_line
= startline
;
2765 cg
->ppd_status
= PPD_LINE_TOO_LONG
;
2770 if (ch
== ':' && strncmp(line
->buffer
, "*%", 2) != 0)
2773 if (ch
== '\"' && colon
)
2774 endquote
= !endquote
;
2781 * Didn't finish this quoted string...
2784 while ((ch
= cupsFileGetChar(fp
)) != EOF
)
2787 else if (ch
== '\r' || ch
== '\n')
2795 * Check for a trailing line feed...
2798 if ((ch
= cupsFilePeekChar(fp
)) == EOF
)
2801 cupsFileGetChar(fp
);
2804 else if (ch
< ' ' && ch
!= '\t' && cg
->ppd_conform
== PPD_CONFORM_STRICT
)
2807 * Other control characters...
2810 cg
->ppd_line
= startline
;
2811 cg
->ppd_status
= PPD_ILLEGAL_CHARACTER
;
2815 else if (ch
!= 0x1a)
2819 if (col
> (PPD_MAX_LINE
- 1))
2822 * Line is too long...
2825 cg
->ppd_line
= startline
;
2826 cg
->ppd_status
= PPD_LINE_TOO_LONG
;
2836 * Didn't finish this line...
2839 while ((ch
= cupsFileGetChar(fp
)) != EOF
)
2840 if (ch
== '\r' || ch
== '\n')
2843 * Line feed or carriage return...
2852 * Check for a trailing line feed...
2855 if ((ch
= cupsFilePeekChar(fp
)) == EOF
)
2858 cupsFileGetChar(fp
);
2863 else if (ch
< ' ' && ch
!= '\t' && cg
->ppd_conform
== PPD_CONFORM_STRICT
)
2866 * Other control characters...
2869 cg
->ppd_line
= startline
;
2870 cg
->ppd_status
= PPD_ILLEGAL_CHARACTER
;
2874 else if (ch
!= 0x1a)
2878 if (col
> (PPD_MAX_LINE
- 1))
2881 * Line is too long...
2884 cg
->ppd_line
= startline
;
2885 cg
->ppd_status
= PPD_LINE_TOO_LONG
;
2892 if (lineptr
> line
->buffer
&& lineptr
[-1] == '\n')
2897 DEBUG_printf(("LINE=\"%s\"\n", line
->buffer
));
2900 * The dynamically created PPDs for older style Mac OS X
2901 * drivers include a large blob of data inserted as comments
2902 * at the end of the file. As an optimization we can stop
2903 * reading the PPD when we get to the start of this data.
2906 if (!strcmp(line
->buffer
, "*%APLWORKSET START"))
2909 if (ch
== EOF
&& lineptr
== line
->buffer
)
2917 lineptr
= line
->buffer
+ 1;
2924 if ((!line
->buffer
[0] || /* Blank line */
2925 !strncmp(line
->buffer
, "*%", 2) || /* Comment line */
2926 !strcmp(line
->buffer
, "*End")) && /* End of multi-line string */
2927 ignoreblank
) /* Ignore these? */
2929 startline
= cg
->ppd_line
+ 1;
2933 if (!strcmp(line
->buffer
, "*")) /* (Bad) comment line */
2935 if (cg
->ppd_conform
== PPD_CONFORM_RELAXED
)
2937 startline
= cg
->ppd_line
+ 1;
2942 cg
->ppd_line
= startline
;
2943 cg
->ppd_status
= PPD_ILLEGAL_MAIN_KEYWORD
;
2949 if (line
->buffer
[0] != '*') /* All lines start with an asterisk */
2952 * Allow lines consisting of just whitespace...
2955 for (lineptr
= line
->buffer
; *lineptr
; lineptr
++)
2956 if (!isspace(*lineptr
& 255))
2961 cg
->ppd_status
= PPD_MISSING_ASTERISK
;
2964 else if (ignoreblank
)
2976 while (*lineptr
!= '\0' && *lineptr
!= ':' && !isspace(*lineptr
& 255))
2978 if (*lineptr
<= ' ' || *lineptr
> 126 || *lineptr
== '/' ||
2979 (keyptr
- keyword
) >= (PPD_MAX_NAME
- 1))
2981 cg
->ppd_status
= PPD_ILLEGAL_MAIN_KEYWORD
;
2985 *keyptr
++ = *lineptr
++;
2990 if (!strcmp(keyword
, "End"))
2993 mask
|= PPD_KEYWORD
;
2995 /* DEBUG_printf(("keyword = \"%s\", lineptr = \"%s\"\n", keyword, lineptr));*/
2997 if (isspace(*lineptr
& 255))
3000 * Get an option name...
3003 while (isspace(*lineptr
& 255))
3008 while (*lineptr
!= '\0' && !isspace(*lineptr
& 255) && *lineptr
!= ':' &&
3011 if (*lineptr
<= ' ' || *lineptr
> 126 ||
3012 (optptr
- option
) >= (PPD_MAX_NAME
- 1))
3014 cg
->ppd_status
= PPD_ILLEGAL_OPTION_KEYWORD
;
3018 *optptr
++ = *lineptr
++;
3023 if (isspace(*lineptr
& 255) && cg
->ppd_conform
== PPD_CONFORM_STRICT
)
3025 cg
->ppd_status
= PPD_ILLEGAL_WHITESPACE
;
3029 while (isspace(*lineptr
& 255))
3034 /* DEBUG_printf(("option = \"%s\", lineptr = \"%s\"\n", option, lineptr));*/
3036 if (*lineptr
== '/')
3039 * Get human-readable text...
3046 while (*lineptr
!= '\0' && *lineptr
!= '\n' && *lineptr
!= ':')
3048 if (((unsigned char)*lineptr
< ' ' && *lineptr
!= '\t') ||
3049 (textptr
- text
) >= (PPD_MAX_LINE
- 1))
3051 cg
->ppd_status
= PPD_ILLEGAL_TRANSLATION
;
3055 *textptr
++ = *lineptr
++;
3059 textlen
= ppd_decode(text
);
3061 if (textlen
> PPD_MAX_TEXT
&& cg
->ppd_conform
== PPD_CONFORM_STRICT
)
3063 cg
->ppd_status
= PPD_ILLEGAL_TRANSLATION
;
3070 /* DEBUG_printf(("text = \"%s\", lineptr = \"%s\"\n", text, lineptr));*/
3073 if (isspace(*lineptr
& 255) && cg
->ppd_conform
== PPD_CONFORM_STRICT
)
3075 cg
->ppd_status
= PPD_ILLEGAL_WHITESPACE
;
3079 while (isspace(*lineptr
& 255))
3082 if (*lineptr
== ':')
3085 * Get string after triming leading and trailing whitespace...
3089 while (isspace(*lineptr
& 255))
3092 strptr
= lineptr
+ strlen(lineptr
) - 1;
3093 while (strptr
>= lineptr
&& isspace(*strptr
& 255))
3096 if (*strptr
== '\"')
3099 * Quoted string by itself, remove quotes...
3106 *string
= _cupsStrAlloc(lineptr
);
3108 /* DEBUG_printf(("string = \"%s\", lineptr = \"%s\"\n", *string, lineptr));*/
3120 * End of "$Id: ppd.c 7552 2008-05-12 17:42:15Z mike $".