2 * "$Id: ppd.c 7906 2008-09-03 20:19:43Z mike $"
4 * PPD file routines for the Common UNIX Printing System (CUPS).
6 * Copyright 2007-2008 by Apple Inc.
7 * Copyright 1997-2007 by Easy Software Products, all rights reserved.
9 * These coded instructions, statements, and computer programs are the
10 * property of Apple Inc. and are protected by Federal copyright
11 * law. Distribution and use rights are outlined in the file "LICENSE.txt"
12 * which should have been included with this file. If this file is
13 * file is missing or damaged, see the license at "http://www.cups.org/".
15 * PostScript is a trademark of Adobe Systems, Inc.
17 * This code and any derivative of it may be used and distributed
18 * freely under the terms of the GNU General Public License when
19 * used with GNU Ghostscript or its derivatives. Use of the code
20 * (or any derivative of it) with software other than GNU
21 * GhostScript (or its derivatives) is governed by the CUPS license
24 * This file is subject to the Apple OS-Developed Software exception.
28 * ppdClose() - Free all memory used by the PPD file.
29 * ppdErrorString() - Returns the text assocated with a status.
30 * _ppdGetEncoding() - Get the CUPS encoding value for the given
32 * ppdLastError() - Return the status from the last ppdOpen*().
33 * ppdOpen() - Read a PPD file into memory.
34 * ppdOpen2() - Read a PPD file into memory.
35 * ppdOpenFd() - Read a PPD file into memory.
36 * ppdOpenFile() - Read a PPD file into memory.
37 * ppdSetConformance() - Set the conformance level for PPD files.
38 * ppd_add_attr() - Add an attribute to the PPD data.
39 * ppd_add_choice() - Add a choice to an option.
40 * ppd_add_size() - Add a page size.
41 * ppd_compare_attrs() - Compare two attributes.
42 * ppd_compare_choices() - Compare two choices...
43 * ppd_compare_coptions() - Compare two custom options.
44 * ppd_compare_cparams() - Compare two custom parameters.
45 * ppd_compare_options() - Compare two options.
46 * ppd_decode() - Decode a string value...
47 * ppd_free_group() - Free a single UI group.
48 * ppd_free_option() - Free a single option.
49 * ppd_get_coption() - Get a custom option record.
50 * ppd_get_cparam() - Get a custom parameter record.
51 * ppd_get_group() - Find or create the named group as needed.
52 * ppd_get_option() - Find or create the named option as needed.
53 * ppd_hash_option() - Generate a hash of the option name...
54 * ppd_read() - Read a line from a PPD file, skipping comment
59 * Include necessary headers.
62 #include "ppd-private.h"
72 #if defined(WIN32) || defined(__EMX__)
73 # define READ_BINARY "rb" /* Open a binary file for reading */
74 # define WRITE_BINARY "wb" /* Open a binary file for writing */
76 # define READ_BINARY "r" /* Open a binary file for reading */
77 # define WRITE_BINARY "w" /* Open a binary file for writing */
78 #endif /* WIN32 || __EMX__ */
80 #define ppd_free(p) if (p) free(p) /* Safe free macro */
82 #define PPD_KEYWORD 1 /* Line contained a keyword */
83 #define PPD_OPTION 2 /* Line contained an option name */
84 #define PPD_TEXT 4 /* Line contained human-readable text */
85 #define PPD_STRING 8 /* Line contained a string or code */
87 #define PPD_HASHSIZE 512 /* Size of hash */
91 * Line buffer structure...
94 typedef struct _ppd_line_s
96 char *buffer
; /* Pointer to buffer */
97 size_t bufsize
; /* Size of the buffer */
105 static ppd_attr_t
*ppd_add_attr(ppd_file_t
*ppd
, const char *name
,
106 const char *spec
, const char *text
,
108 static ppd_choice_t
*ppd_add_choice(ppd_option_t
*option
, const char *name
);
109 static ppd_size_t
*ppd_add_size(ppd_file_t
*ppd
, const char *name
);
110 static int ppd_compare_attrs(ppd_attr_t
*a
, ppd_attr_t
*b
);
111 static int ppd_compare_choices(ppd_choice_t
*a
, ppd_choice_t
*b
);
112 static int ppd_compare_coptions(ppd_coption_t
*a
,
114 static int ppd_compare_cparams(ppd_cparam_t
*a
, ppd_cparam_t
*b
);
115 static int ppd_compare_options(ppd_option_t
*a
, ppd_option_t
*b
);
116 static int ppd_decode(char *string
);
117 static void ppd_free_group(ppd_group_t
*group
);
118 static void ppd_free_option(ppd_option_t
*option
);
119 static ppd_coption_t
*ppd_get_coption(ppd_file_t
*ppd
, const char *name
);
120 static ppd_cparam_t
*ppd_get_cparam(ppd_coption_t
*opt
,
123 static ppd_group_t
*ppd_get_group(ppd_file_t
*ppd
, const char *name
,
124 const char *text
, _cups_globals_t
*cg
,
125 cups_encoding_t encoding
);
126 static ppd_option_t
*ppd_get_option(ppd_group_t
*group
, const char *name
);
127 static int ppd_hash_option(ppd_option_t
*option
);
128 static int ppd_read(cups_file_t
*fp
, _ppd_line_t
*line
,
129 char *keyword
, char *option
, char *text
,
130 char **string
, int ignoreblank
,
131 _cups_globals_t
*cg
);
135 * 'ppdClose()' - Free all memory used by the PPD file.
139 ppdClose(ppd_file_t
*ppd
) /* I - PPD file record */
141 int i
; /* Looping var */
142 ppd_emul_t
*emul
; /* Current emulation */
143 ppd_group_t
*group
; /* Current group */
144 char **font
; /* Current font */
145 char **filter
; /* Current filter */
146 ppd_attr_t
**attr
; /* Current attribute */
147 ppd_coption_t
*coption
; /* Current custom option */
148 ppd_cparam_t
*cparam
; /* Current custom parameter */
152 * Range check arguments...
159 * Free all strings at the top level...
162 _cupsStrFree(ppd
->lang_encoding
);
163 _cupsStrFree(ppd
->nickname
);
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 */
553 * Default to "OK" status...
556 cg
->ppd_status
= PPD_OK
;
560 * Range check input...
565 cg
->ppd_status
= PPD_NULL_FILE
;
570 * Grab the first line and make sure it reads '*PPD-Adobe: "major.minor"'...
576 mask
= ppd_read(fp
, &line
, keyword
, name
, text
, &string
, 0, cg
);
578 DEBUG_printf(("mask=%x, keyword=\"%s\"...\n", mask
, keyword
));
581 strcmp(keyword
, "PPD-Adobe") ||
582 string
== NULL
|| string
[0] != '4')
585 * Either this is not a PPD file, or it is not a 4.x PPD file.
588 if (cg
->ppd_status
== PPD_OK
)
589 cg
->ppd_status
= PPD_MISSING_PPDADOBE4
;
591 _cupsStrFree(string
);
592 ppd_free(line
.buffer
);
597 DEBUG_printf(("ppdOpen: keyword = %s, string = %p\n", keyword
, string
));
599 _cupsStrFree(string
);
602 * Allocate memory for the PPD file record...
605 if ((ppd
= calloc(1, sizeof(ppd_file_t
))) == NULL
)
607 cg
->ppd_status
= PPD_ALLOC_ERROR
;
609 _cupsStrFree(string
);
610 ppd_free(line
.buffer
);
615 ppd
->language_level
= 2;
616 ppd
->color_device
= 0;
617 ppd
->colorspace
= PPD_CS_N
;
618 ppd
->landscape
= -90;
619 ppd
->coptions
= cupsArrayNew((cups_array_func_t
)ppd_compare_coptions
,
623 * Get the default language for the user...
626 language
= cupsLangDefault();
630 * Read lines from the PPD file and add them to the file record...
638 encoding
= CUPS_ISO8859_1
;
640 while ((mask
= ppd_read(fp
, &line
, keyword
, name
, text
, &string
, 1, cg
)) != 0)
642 DEBUG_printf(("mask=%x, keyword=\"%s\", name=\"%s\", text=\"%s\", "
643 "string=%d chars...", mask
, keyword
, name
, text
,
644 string
? (int)strlen(string
) : 0));
646 if (strncmp(keyword
, "Default", 7) && !string
&&
647 cg
->ppd_conform
!= PPD_CONFORM_RELAXED
)
650 * Need a string value!
653 cg
->ppd_status
= PPD_MISSING_VALUE
;
659 * Certain main keywords (as defined by the PPD spec) may be used
660 * without the usual OpenUI/CloseUI stuff. Presumably this is just
661 * so that Adobe wouldn't completely break compatibility with PPD
662 * files prior to v4.0 of the spec, but it is hopelessly
663 * inconsistent... Catch these main keywords and automatically
664 * create the corresponding option, as needed...
670 * Previous line was a UI keyword...
677 if (option
== NULL
&&
678 (mask
& (PPD_KEYWORD
| PPD_OPTION
| PPD_STRING
)) ==
679 (PPD_KEYWORD
| PPD_OPTION
| PPD_STRING
))
681 for (i
= 0; i
< (int)(sizeof(ui_keywords
) / sizeof(ui_keywords
[0])); i
++)
682 if (!strcmp(keyword
, ui_keywords
[i
]))
685 if (i
< (int)(sizeof(ui_keywords
) / sizeof(ui_keywords
[0])))
688 * Create the option in the appropriate group...
693 DEBUG_printf(("**** FOUND ADOBE UI KEYWORD %s WITHOUT OPENUI!\n",
698 if ((group
= ppd_get_group(ppd
, "General", _("General"), cg
,
702 DEBUG_printf(("Adding to group %s...\n", group
->text
));
703 option
= ppd_get_option(group
, keyword
);
707 option
= ppd_get_option(group
, keyword
);
711 cg
->ppd_status
= PPD_ALLOC_ERROR
;
717 * Now fill in the initial information for the option...
720 if (!strncmp(keyword
, "JCL", 3))
721 option
->section
= PPD_ORDER_JCL
;
723 option
->section
= PPD_ORDER_ANY
;
725 option
->order
= 10.0f
;
728 option
->ui
= PPD_UI_BOOLEAN
;
730 option
->ui
= PPD_UI_PICKONE
;
732 for (j
= 0; j
< ppd
->num_attrs
; j
++)
733 if (!strncmp(ppd
->attrs
[j
]->name
, "Default", 7) &&
734 !strcmp(ppd
->attrs
[j
]->name
+ 7, keyword
) &&
735 ppd
->attrs
[j
]->value
)
737 DEBUG_printf(("Setting Default%s to %s via attribute...\n",
738 option
->keyword
, ppd
->attrs
[j
]->value
));
739 strlcpy(option
->defchoice
, ppd
->attrs
[j
]->value
,
740 sizeof(option
->defchoice
));
744 if (!strcmp(keyword
, "PageSize"))
745 strlcpy(option
->text
, _("Media Size"), sizeof(option
->text
));
746 else if (!strcmp(keyword
, "MediaType"))
747 strlcpy(option
->text
, _("Media Type"), sizeof(option
->text
));
748 else if (!strcmp(keyword
, "InputSlot"))
749 strlcpy(option
->text
, _("Media Source"), sizeof(option
->text
));
750 else if (!strcmp(keyword
, "ColorModel"))
751 strlcpy(option
->text
, _("Output Mode"), sizeof(option
->text
));
752 else if (!strcmp(keyword
, "Resolution"))
753 strlcpy(option
->text
, _("Resolution"), sizeof(option
->text
));
755 strlcpy(option
->text
, keyword
, sizeof(option
->text
));
759 if (!strcmp(keyword
, "LanguageLevel"))
760 ppd
->language_level
= atoi(string
);
761 else if (!strcmp(keyword
, "LanguageEncoding"))
764 * Say all PPD files are UTF-8, since we convert to UTF-8...
767 ppd
->lang_encoding
= _cupsStrAlloc("UTF-8");
768 encoding
= _ppdGetEncoding(string
);
770 else if (!strcmp(keyword
, "LanguageVersion"))
771 ppd
->lang_version
= string
;
772 else if (!strcmp(keyword
, "Manufacturer"))
773 ppd
->manufacturer
= string
;
774 else if (!strcmp(keyword
, "ModelName"))
775 ppd
->modelname
= string
;
776 else if (!strcmp(keyword
, "Protocols"))
777 ppd
->protocols
= string
;
778 else if (!strcmp(keyword
, "PCFileName"))
779 ppd
->pcfilename
= string
;
780 else if (!strcmp(keyword
, "NickName"))
782 if (encoding
!= CUPS_UTF8
)
784 cups_utf8_t utf8
[256]; /* UTF-8 version of NickName */
787 cupsCharsetToUTF8(utf8
, string
, sizeof(utf8
), encoding
);
788 ppd
->nickname
= _cupsStrAlloc((char *)utf8
);
791 ppd
->nickname
= _cupsStrAlloc(string
);
793 else if (!strcmp(keyword
, "Product"))
794 ppd
->product
= string
;
795 else if (!strcmp(keyword
, "ShortNickName"))
796 ppd
->shortnickname
= string
;
797 else if (!strcmp(keyword
, "TTRasterizer"))
798 ppd
->ttrasterizer
= string
;
799 else if (!strcmp(keyword
, "JCLBegin"))
801 ppd
->jcl_begin
= _cupsStrAlloc(string
);
802 ppd_decode(ppd
->jcl_begin
); /* Decode quoted string */
804 else if (!strcmp(keyword
, "JCLEnd"))
806 ppd
->jcl_end
= _cupsStrAlloc(string
);
807 ppd_decode(ppd
->jcl_end
); /* Decode quoted string */
809 else if (!strcmp(keyword
, "JCLToPSInterpreter"))
811 ppd
->jcl_ps
= _cupsStrAlloc(string
);
812 ppd_decode(ppd
->jcl_ps
); /* Decode quoted string */
814 else if (!strcmp(keyword
, "AccurateScreensSupport"))
815 ppd
->accurate_screens
= !strcmp(string
, "True");
816 else if (!strcmp(keyword
, "ColorDevice"))
817 ppd
->color_device
= !strcmp(string
, "True");
818 else if (!strcmp(keyword
, "ContoneOnly"))
819 ppd
->contone_only
= !strcmp(string
, "True");
820 else if (!strcmp(keyword
, "cupsFlipDuplex"))
821 ppd
->flip_duplex
= !strcmp(string
, "True");
822 else if (!strcmp(keyword
, "cupsManualCopies"))
823 ppd
->manual_copies
= !strcmp(string
, "True");
824 else if (!strcmp(keyword
, "cupsModelNumber"))
825 ppd
->model_number
= atoi(string
);
826 else if (!strcmp(keyword
, "cupsColorProfile"))
828 if (ppd
->num_profiles
== 0)
829 profile
= malloc(sizeof(ppd_profile_t
));
831 profile
= realloc(ppd
->profiles
, sizeof(ppd_profile_t
) *
832 (ppd
->num_profiles
+ 1));
836 cg
->ppd_status
= PPD_ALLOC_ERROR
;
841 ppd
->profiles
= profile
;
842 profile
+= ppd
->num_profiles
;
843 ppd
->num_profiles
++;
845 memset(profile
, 0, sizeof(ppd_profile_t
));
846 strlcpy(profile
->resolution
, name
, sizeof(profile
->resolution
));
847 strlcpy(profile
->media_type
, text
, sizeof(profile
->media_type
));
849 profile
->density
= (float)_cupsStrScand(string
, &sptr
, loc
);
850 profile
->gamma
= (float)_cupsStrScand(sptr
, &sptr
, loc
);
851 profile
->matrix
[0][0] = (float)_cupsStrScand(sptr
, &sptr
, loc
);
852 profile
->matrix
[0][1] = (float)_cupsStrScand(sptr
, &sptr
, loc
);
853 profile
->matrix
[0][2] = (float)_cupsStrScand(sptr
, &sptr
, loc
);
854 profile
->matrix
[1][0] = (float)_cupsStrScand(sptr
, &sptr
, loc
);
855 profile
->matrix
[1][1] = (float)_cupsStrScand(sptr
, &sptr
, loc
);
856 profile
->matrix
[1][2] = (float)_cupsStrScand(sptr
, &sptr
, loc
);
857 profile
->matrix
[2][0] = (float)_cupsStrScand(sptr
, &sptr
, loc
);
858 profile
->matrix
[2][1] = (float)_cupsStrScand(sptr
, &sptr
, loc
);
859 profile
->matrix
[2][2] = (float)_cupsStrScand(sptr
, &sptr
, loc
);
861 else if (!strcmp(keyword
, "cupsFilter"))
863 if (ppd
->num_filters
== 0)
864 filter
= malloc(sizeof(char *));
866 filter
= realloc(ppd
->filters
, sizeof(char *) * (ppd
->num_filters
+ 1));
870 cg
->ppd_status
= PPD_ALLOC_ERROR
;
875 ppd
->filters
= filter
;
876 filter
+= ppd
->num_filters
;
880 * Copy filter string and prevent it from being freed below...
886 else if (!strcmp(keyword
, "Throughput"))
887 ppd
->throughput
= atoi(string
);
888 else if (!strcmp(keyword
, "Font"))
891 * Add this font to the list of available fonts...
894 if (ppd
->num_fonts
== 0)
895 tempfonts
= (char **)malloc(sizeof(char *));
897 tempfonts
= (char **)realloc(ppd
->fonts
,
898 sizeof(char *) * (ppd
->num_fonts
+ 1));
900 if (tempfonts
== NULL
)
902 cg
->ppd_status
= PPD_ALLOC_ERROR
;
907 ppd
->fonts
= tempfonts
;
908 ppd
->fonts
[ppd
->num_fonts
] = _cupsStrAlloc(name
);
911 else if (!strncmp(keyword
, "ParamCustom", 11))
913 ppd_coption_t
*coption
; /* Custom option */
914 ppd_cparam_t
*cparam
; /* Custom parameter */
915 int corder
; /* Order number */
916 char ctype
[33], /* Data type */
917 cminimum
[65], /* Minimum value */
918 cmaximum
[65]; /* Maximum value */
922 * Get the custom option and parameter...
925 if ((coption
= ppd_get_coption(ppd
, keyword
+ 11)) == NULL
)
927 cg
->ppd_status
= PPD_ALLOC_ERROR
;
932 if ((cparam
= ppd_get_cparam(coption
, name
, text
)) == NULL
)
934 cg
->ppd_status
= PPD_ALLOC_ERROR
;
940 * Get the parameter data...
943 if (sscanf(string
, "%d%32s%64s%64s", &corder
, ctype
, cminimum
,
946 cg
->ppd_status
= PPD_BAD_CUSTOM_PARAM
;
951 cparam
->order
= corder
;
953 if (!strcmp(ctype
, "curve"))
955 cparam
->type
= PPD_CUSTOM_CURVE
;
956 cparam
->minimum
.custom_curve
= (float)_cupsStrScand(cminimum
, NULL
, loc
);
957 cparam
->maximum
.custom_curve
= (float)_cupsStrScand(cmaximum
, NULL
, loc
);
959 else if (!strcmp(ctype
, "int"))
961 cparam
->type
= PPD_CUSTOM_INT
;
962 cparam
->minimum
.custom_int
= atoi(cminimum
);
963 cparam
->maximum
.custom_int
= atoi(cmaximum
);
965 else if (!strcmp(ctype
, "invcurve"))
967 cparam
->type
= PPD_CUSTOM_INVCURVE
;
968 cparam
->minimum
.custom_invcurve
= (float)_cupsStrScand(cminimum
, NULL
, loc
);
969 cparam
->maximum
.custom_invcurve
= (float)_cupsStrScand(cmaximum
, NULL
, loc
);
971 else if (!strcmp(ctype
, "passcode"))
973 cparam
->type
= PPD_CUSTOM_PASSCODE
;
974 cparam
->minimum
.custom_passcode
= atoi(cminimum
);
975 cparam
->maximum
.custom_passcode
= atoi(cmaximum
);
977 else if (!strcmp(ctype
, "password"))
979 cparam
->type
= PPD_CUSTOM_PASSWORD
;
980 cparam
->minimum
.custom_password
= atoi(cminimum
);
981 cparam
->maximum
.custom_password
= atoi(cmaximum
);
983 else if (!strcmp(ctype
, "points"))
985 cparam
->type
= PPD_CUSTOM_POINTS
;
986 cparam
->minimum
.custom_points
= (float)_cupsStrScand(cminimum
, NULL
, loc
);
987 cparam
->maximum
.custom_points
= (float)_cupsStrScand(cmaximum
, NULL
, loc
);
989 else if (!strcmp(ctype
, "real"))
991 cparam
->type
= PPD_CUSTOM_REAL
;
992 cparam
->minimum
.custom_real
= (float)_cupsStrScand(cminimum
, NULL
, loc
);
993 cparam
->maximum
.custom_real
= (float)_cupsStrScand(cmaximum
, NULL
, loc
);
995 else if (!strcmp(ctype
, "string"))
997 cparam
->type
= PPD_CUSTOM_STRING
;
998 cparam
->minimum
.custom_string
= atoi(cminimum
);
999 cparam
->maximum
.custom_string
= atoi(cmaximum
);
1003 cg
->ppd_status
= PPD_BAD_CUSTOM_PARAM
;
1009 * Now special-case for CustomPageSize...
1012 if (!strcmp(coption
->keyword
, "PageSize"))
1014 if (!strcmp(name
, "Width"))
1016 ppd
->custom_min
[0] = cparam
->minimum
.custom_points
;
1017 ppd
->custom_max
[0] = cparam
->maximum
.custom_points
;
1019 else if (!strcmp(name
, "Height"))
1021 ppd
->custom_min
[1] = cparam
->minimum
.custom_points
;
1022 ppd
->custom_max
[1] = cparam
->maximum
.custom_points
;
1026 else if (!strcmp(keyword
, "HWMargins"))
1028 for (i
= 0, sptr
= string
; i
< 4; i
++)
1029 ppd
->custom_margins
[i
] = (float)_cupsStrScand(sptr
, &sptr
, loc
);
1031 else if (!strncmp(keyword
, "Custom", 6) && !strcmp(name
, "True") && !option
)
1033 ppd_option_t
*custom_option
; /* Custom option */
1035 DEBUG_puts("Processing Custom option...");
1038 * Get the option and custom option...
1041 if (!ppd_get_coption(ppd
, keyword
+ 6))
1043 cg
->ppd_status
= PPD_ALLOC_ERROR
;
1048 if (option
&& !strcasecmp(option
->keyword
, keyword
+ 6))
1049 custom_option
= option
;
1051 custom_option
= ppdFindOption(ppd
, keyword
+ 6);
1056 * Add the "custom" option...
1059 if ((choice
= ppdFindChoice(custom_option
, "Custom")) == NULL
)
1060 if ((choice
= ppd_add_choice(custom_option
, "Custom")) == NULL
)
1062 DEBUG_puts("Unable to add Custom choice!");
1064 cg
->ppd_status
= PPD_ALLOC_ERROR
;
1069 strlcpy(choice
->text
, text
[0] ? text
: _("Custom"),
1070 sizeof(choice
->text
));
1072 choice
->code
= _cupsStrAlloc(string
);
1074 if (custom_option
->section
== PPD_ORDER_JCL
)
1075 ppd_decode(choice
->code
);
1079 * Now process custom page sizes specially...
1082 if (!strcmp(keyword
, "CustomPageSize"))
1085 * Add a "Custom" page size entry...
1088 ppd
->variable_sizes
= 1;
1090 ppd_add_size(ppd
, "Custom");
1092 if (option
&& !strcasecmp(option
->keyword
, "PageRegion"))
1093 custom_option
= option
;
1095 custom_option
= ppdFindOption(ppd
, "PageRegion");
1099 if ((choice
= ppdFindChoice(custom_option
, "Custom")) == NULL
)
1100 if ((choice
= ppd_add_choice(custom_option
, "Custom")) == NULL
)
1102 DEBUG_puts("Unable to add Custom choice!");
1104 cg
->ppd_status
= PPD_ALLOC_ERROR
;
1109 strlcpy(choice
->text
, text
[0] ? text
: _("Custom"),
1110 sizeof(choice
->text
));
1114 else if (!strcmp(keyword
, "LandscapeOrientation"))
1116 if (!strcmp(string
, "Minus90"))
1117 ppd
->landscape
= -90;
1118 else if (!strcmp(string
, "Plus90"))
1119 ppd
->landscape
= 90;
1121 else if (!strcmp(keyword
, "Emulators") && string
)
1123 for (count
= 1, sptr
= string
; sptr
!= NULL
;)
1124 if ((sptr
= strchr(sptr
, ' ')) != NULL
)
1127 while (*sptr
== ' ')
1131 ppd
->num_emulations
= count
;
1132 if ((ppd
->emulations
= calloc(count
, sizeof(ppd_emul_t
))) == NULL
)
1134 cg
->ppd_status
= PPD_ALLOC_ERROR
;
1139 for (i
= 0, sptr
= string
; i
< count
; i
++)
1141 for (nameptr
= ppd
->emulations
[i
].name
;
1142 *sptr
!= '\0' && *sptr
!= ' ';
1144 if (nameptr
< (ppd
->emulations
[i
].name
+ sizeof(ppd
->emulations
[i
].name
) - 1))
1149 while (*sptr
== ' ')
1153 else if (!strncmp(keyword
, "StartEmulator_", 14))
1157 for (i
= 0; i
< ppd
->num_emulations
; i
++)
1158 if (!strcmp(keyword
+ 14, ppd
->emulations
[i
].name
))
1160 ppd
->emulations
[i
].start
= string
;
1164 else if (!strncmp(keyword
, "StopEmulator_", 13))
1168 for (i
= 0; i
< ppd
->num_emulations
; i
++)
1169 if (!strcmp(keyword
+ 13, ppd
->emulations
[i
].name
))
1171 ppd
->emulations
[i
].stop
= string
;
1175 else if (!strcmp(keyword
, "JobPatchFile"))
1177 if (ppd
->patches
== NULL
)
1178 ppd
->patches
= strdup(string
);
1181 temp
= realloc(ppd
->patches
, strlen(ppd
->patches
) +
1182 strlen(string
) + 1);
1185 cg
->ppd_status
= PPD_ALLOC_ERROR
;
1190 ppd
->patches
= temp
;
1192 strcpy(ppd
->patches
+ strlen(ppd
->patches
), string
);
1195 else if (!strcmp(keyword
, "OpenUI"))
1198 * Don't allow nesting of options...
1201 if (option
&& cg
->ppd_conform
== PPD_CONFORM_STRICT
)
1203 cg
->ppd_status
= PPD_NESTED_OPEN_UI
;
1209 * Add an option record to the current sub-group, group, or file...
1212 DEBUG_printf(("name=\"%s\" (%d)\n", name
, (int)strlen(name
)));
1215 _cups_strcpy(name
, name
+ 1); /* Eliminate leading asterisk */
1217 for (i
= (int)strlen(name
) - 1; i
> 0 && isspace(name
[i
] & 255); i
--)
1218 name
[i
] = '\0'; /* Eliminate trailing spaces */
1220 DEBUG_printf(("OpenUI of %s in group %s...\n", name
,
1221 group
? group
->text
: "(null)"));
1223 if (subgroup
!= NULL
)
1224 option
= ppd_get_option(subgroup
, name
);
1225 else if (group
== NULL
)
1227 if ((group
= ppd_get_group(ppd
, "General", _("General"), cg
,
1231 DEBUG_printf(("Adding to group %s...\n", group
->text
));
1232 option
= ppd_get_option(group
, name
);
1236 option
= ppd_get_option(group
, name
);
1240 cg
->ppd_status
= PPD_ALLOC_ERROR
;
1246 * Now fill in the initial information for the option...
1249 if (string
&& !strcmp(string
, "PickMany"))
1250 option
->ui
= PPD_UI_PICKMANY
;
1251 else if (string
&& !strcmp(string
, "Boolean"))
1252 option
->ui
= PPD_UI_BOOLEAN
;
1253 else if (string
&& !strcmp(string
, "PickOne"))
1254 option
->ui
= PPD_UI_PICKONE
;
1255 else if (cg
->ppd_conform
== PPD_CONFORM_STRICT
)
1257 cg
->ppd_status
= PPD_BAD_OPEN_UI
;
1262 option
->ui
= PPD_UI_PICKONE
;
1264 for (j
= 0; j
< ppd
->num_attrs
; j
++)
1265 if (!strncmp(ppd
->attrs
[j
]->name
, "Default", 7) &&
1266 !strcmp(ppd
->attrs
[j
]->name
+ 7, name
) &&
1267 ppd
->attrs
[j
]->value
)
1269 DEBUG_printf(("Setting Default%s to %s via attribute...\n",
1270 option
->keyword
, ppd
->attrs
[j
]->value
));
1271 strlcpy(option
->defchoice
, ppd
->attrs
[j
]->value
,
1272 sizeof(option
->defchoice
));
1277 cupsCharsetToUTF8((cups_utf8_t
*)option
->text
, text
,
1278 sizeof(option
->text
), encoding
);
1281 if (!strcmp(name
, "PageSize"))
1282 strlcpy(option
->text
, _("Media Size"), sizeof(option
->text
));
1283 else if (!strcmp(name
, "MediaType"))
1284 strlcpy(option
->text
, _("Media Type"), sizeof(option
->text
));
1285 else if (!strcmp(name
, "InputSlot"))
1286 strlcpy(option
->text
, _("Media Source"), sizeof(option
->text
));
1287 else if (!strcmp(name
, "ColorModel"))
1288 strlcpy(option
->text
, _("Output Mode"), sizeof(option
->text
));
1289 else if (!strcmp(name
, "Resolution"))
1290 strlcpy(option
->text
, _("Resolution"), sizeof(option
->text
));
1292 strlcpy(option
->text
, name
, sizeof(option
->text
));
1295 option
->section
= PPD_ORDER_ANY
;
1297 _cupsStrFree(string
);
1301 * Add a custom option choice if we have already seen a CustomFoo
1305 if (!strcasecmp(name
, "PageRegion"))
1306 strcpy(custom_name
, "CustomPageSize");
1308 snprintf(custom_name
, sizeof(custom_name
), "Custom%s", name
);
1310 if ((custom_attr
= ppdFindAttr(ppd
, custom_name
, "True")) != NULL
)
1312 if ((choice
= ppdFindChoice(option
, "Custom")) == NULL
)
1313 if ((choice
= ppd_add_choice(option
, "Custom")) == NULL
)
1315 DEBUG_puts("Unable to add Custom choice!");
1317 cg
->ppd_status
= PPD_ALLOC_ERROR
;
1322 strlcpy(choice
->text
,
1323 custom_attr
->text
[0] ? custom_attr
->text
: _("Custom"),
1324 sizeof(choice
->text
));
1325 choice
->code
= _cupsStrRetain(custom_attr
->value
);
1328 else if (!strcmp(keyword
, "JCLOpenUI"))
1331 * Don't allow nesting of options...
1334 if (option
&& cg
->ppd_conform
== PPD_CONFORM_STRICT
)
1336 cg
->ppd_status
= PPD_NESTED_OPEN_UI
;
1342 * Find the JCL group, and add if needed...
1345 group
= ppd_get_group(ppd
, "JCL", _("JCL"), cg
, encoding
);
1351 * Add an option record to the current JCLs...
1355 _cups_strcpy(name
, name
+ 1);
1357 option
= ppd_get_option(group
, name
);
1361 cg
->ppd_status
= PPD_ALLOC_ERROR
;
1367 * Now fill in the initial information for the option...
1370 if (string
&& !strcmp(string
, "PickMany"))
1371 option
->ui
= PPD_UI_PICKMANY
;
1372 else if (string
&& !strcmp(string
, "Boolean"))
1373 option
->ui
= PPD_UI_BOOLEAN
;
1374 else if (string
&& !strcmp(string
, "PickOne"))
1375 option
->ui
= PPD_UI_PICKONE
;
1378 cg
->ppd_status
= PPD_BAD_OPEN_UI
;
1383 for (j
= 0; j
< ppd
->num_attrs
; j
++)
1384 if (!strncmp(ppd
->attrs
[j
]->name
, "Default", 7) &&
1385 !strcmp(ppd
->attrs
[j
]->name
+ 7, name
) &&
1386 ppd
->attrs
[j
]->value
)
1388 DEBUG_printf(("Setting Default%s to %s via attribute...\n",
1389 option
->keyword
, ppd
->attrs
[j
]->value
));
1390 strlcpy(option
->defchoice
, ppd
->attrs
[j
]->value
,
1391 sizeof(option
->defchoice
));
1396 cupsCharsetToUTF8((cups_utf8_t
*)option
->text
, text
,
1397 sizeof(option
->text
), encoding
);
1399 strlcpy(option
->text
, name
, sizeof(option
->text
));
1401 option
->section
= PPD_ORDER_JCL
;
1404 _cupsStrFree(string
);
1408 * Add a custom option choice if we have already seen a CustomFoo
1412 snprintf(custom_name
, sizeof(custom_name
), "Custom%s", name
);
1414 if ((custom_attr
= ppdFindAttr(ppd
, custom_name
, "True")) != NULL
)
1416 if ((choice
= ppd_add_choice(option
, "Custom")) == NULL
)
1418 DEBUG_puts("Unable to add Custom choice!");
1420 cg
->ppd_status
= PPD_ALLOC_ERROR
;
1425 strlcpy(choice
->text
,
1426 custom_attr
->text
[0] ? custom_attr
->text
: _("Custom"),
1427 sizeof(choice
->text
));
1428 choice
->code
= _cupsStrRetain(custom_attr
->value
);
1431 else if (!strcmp(keyword
, "CloseUI") || !strcmp(keyword
, "JCLCloseUI"))
1435 _cupsStrFree(string
);
1438 else if (!strcmp(keyword
, "OpenGroup"))
1441 * Open a new group...
1446 cg
->ppd_status
= PPD_NESTED_OPEN_GROUP
;
1453 cg
->ppd_status
= PPD_BAD_OPEN_GROUP
;
1459 * Separate the group name from the text (name/text)...
1462 if ((sptr
= strchr(string
, '/')) != NULL
)
1468 * Fix up the text...
1474 * Find/add the group...
1477 group
= ppd_get_group(ppd
, string
, sptr
, cg
, encoding
);
1482 _cupsStrFree(string
);
1485 else if (!strcmp(keyword
, "CloseGroup"))
1489 _cupsStrFree(string
);
1492 else if (!strcmp(keyword
, "OrderDependency"))
1494 order
= (float)_cupsStrScand(string
, &sptr
, loc
);
1496 if (!sptr
|| sscanf(sptr
, "%40s%40s", name
, keyword
) != 2)
1498 cg
->ppd_status
= PPD_BAD_ORDER_DEPENDENCY
;
1503 if (keyword
[0] == '*')
1504 _cups_strcpy(keyword
, keyword
+ 1);
1506 if (!strcmp(name
, "ExitServer"))
1507 section
= PPD_ORDER_EXIT
;
1508 else if (!strcmp(name
, "Prolog"))
1509 section
= PPD_ORDER_PROLOG
;
1510 else if (!strcmp(name
, "DocumentSetup"))
1511 section
= PPD_ORDER_DOCUMENT
;
1512 else if (!strcmp(name
, "PageSetup"))
1513 section
= PPD_ORDER_PAGE
;
1514 else if (!strcmp(name
, "JCLSetup"))
1515 section
= PPD_ORDER_JCL
;
1517 section
= PPD_ORDER_ANY
;
1525 * Only valid for Non-UI options...
1528 for (i
= ppd
->num_groups
, gtemp
= ppd
->groups
; i
> 0; i
--, gtemp
++)
1529 if (gtemp
->text
[0] == '\0')
1533 for (i
= 0; i
< gtemp
->num_options
; i
++)
1534 if (!strcmp(keyword
, gtemp
->options
[i
].keyword
))
1536 gtemp
->options
[i
].section
= section
;
1537 gtemp
->options
[i
].order
= order
;
1543 option
->section
= section
;
1544 option
->order
= order
;
1547 _cupsStrFree(string
);
1550 else if (!strncmp(keyword
, "Default", 7))
1556 * Drop UI text, if any, from value...
1559 if (strchr(string
, '/') != NULL
)
1560 *strchr(string
, '/') = '\0';
1563 * Assign the default value as appropriate...
1566 if (!strcmp(keyword
, "DefaultColorSpace"))
1569 * Set default colorspace...
1572 if (!strcmp(string
, "CMY"))
1573 ppd
->colorspace
= PPD_CS_CMY
;
1574 else if (!strcmp(string
, "CMYK"))
1575 ppd
->colorspace
= PPD_CS_CMYK
;
1576 else if (!strcmp(string
, "RGB"))
1577 ppd
->colorspace
= PPD_CS_RGB
;
1578 else if (!strcmp(string
, "RGBK"))
1579 ppd
->colorspace
= PPD_CS_RGBK
;
1580 else if (!strcmp(string
, "N"))
1581 ppd
->colorspace
= PPD_CS_N
;
1583 ppd
->colorspace
= PPD_CS_GRAY
;
1585 else if (option
&& !strcmp(keyword
+ 7, option
->keyword
))
1588 * Set the default as part of the current option...
1591 DEBUG_printf(("Setting %s to %s...\n", keyword
, string
));
1593 strlcpy(option
->defchoice
, string
, sizeof(option
->defchoice
));
1595 DEBUG_printf(("%s is now %s...\n", keyword
, option
->defchoice
));
1600 * Lookup option and set if it has been defined...
1603 ppd_option_t
*toption
; /* Temporary option */
1606 if ((toption
= ppdFindOption(ppd
, keyword
+ 7)) != NULL
)
1608 DEBUG_printf(("Setting %s to %s...\n", keyword
, string
));
1609 strlcpy(toption
->defchoice
, string
, sizeof(toption
->defchoice
));
1613 else if (!strcmp(keyword
, "UIConstraints") ||
1614 !strcmp(keyword
, "NonUIConstraints"))
1616 if (ppd
->num_consts
== 0)
1617 constraint
= calloc(2, sizeof(ppd_const_t
));
1619 constraint
= realloc(ppd
->consts
,
1620 (ppd
->num_consts
+ 2) * sizeof(ppd_const_t
));
1622 if (constraint
== NULL
)
1624 cg
->ppd_status
= PPD_ALLOC_ERROR
;
1629 ppd
->consts
= constraint
;
1630 constraint
+= ppd
->num_consts
;
1633 switch (sscanf(string
, "%40s%40s%40s%40s", constraint
->option1
,
1634 constraint
->choice1
, constraint
->option2
,
1635 constraint
->choice2
))
1637 case 0 : /* Error */
1638 case 1 : /* Error */
1639 cg
->ppd_status
= PPD_BAD_UI_CONSTRAINTS
;
1642 case 2 : /* Two options... */
1644 * Check for broken constraints like "* Option"...
1647 if (cg
->ppd_conform
== PPD_CONFORM_STRICT
&&
1648 (!strcmp(constraint
->option1
, "*") ||
1649 !strcmp(constraint
->choice1
, "*")))
1651 cg
->ppd_status
= PPD_BAD_UI_CONSTRAINTS
;
1656 * The following strcpy's are safe, as optionN and
1657 * choiceN are all the same size (size defined by PPD spec...)
1660 if (constraint
->option1
[0] == '*')
1661 _cups_strcpy(constraint
->option1
, constraint
->option1
+ 1);
1662 else if (cg
->ppd_conform
== PPD_CONFORM_STRICT
)
1664 cg
->ppd_status
= PPD_BAD_UI_CONSTRAINTS
;
1668 if (constraint
->choice1
[0] == '*')
1669 _cups_strcpy(constraint
->option2
, constraint
->choice1
+ 1);
1670 else if (cg
->ppd_conform
== PPD_CONFORM_STRICT
)
1672 cg
->ppd_status
= PPD_BAD_UI_CONSTRAINTS
;
1676 constraint
->choice1
[0] = '\0';
1677 constraint
->choice2
[0] = '\0';
1680 case 3 : /* Two options, one choice... */
1682 * Check for broken constraints like "* Option"...
1685 if (cg
->ppd_conform
== PPD_CONFORM_STRICT
&&
1686 (!strcmp(constraint
->option1
, "*") ||
1687 !strcmp(constraint
->choice1
, "*") ||
1688 !strcmp(constraint
->option2
, "*")))
1690 cg
->ppd_status
= PPD_BAD_UI_CONSTRAINTS
;
1695 * The following _cups_strcpy's are safe, as optionN and
1696 * choiceN are all the same size (size defined by PPD spec...)
1699 if (constraint
->option1
[0] == '*')
1700 _cups_strcpy(constraint
->option1
, constraint
->option1
+ 1);
1701 else if (cg
->ppd_conform
== PPD_CONFORM_STRICT
)
1703 cg
->ppd_status
= PPD_BAD_UI_CONSTRAINTS
;
1707 if (constraint
->choice1
[0] == '*')
1709 if (cg
->ppd_conform
== PPD_CONFORM_STRICT
&&
1710 constraint
->option2
[0] == '*')
1712 cg
->ppd_status
= PPD_BAD_UI_CONSTRAINTS
;
1716 _cups_strcpy(constraint
->choice2
, constraint
->option2
);
1717 _cups_strcpy(constraint
->option2
, constraint
->choice1
+ 1);
1718 constraint
->choice1
[0] = '\0';
1722 if (constraint
->option2
[0] == '*')
1723 _cups_strcpy(constraint
->option2
, constraint
->option2
+ 1);
1724 else if (cg
->ppd_conform
== PPD_CONFORM_STRICT
)
1726 cg
->ppd_status
= PPD_BAD_UI_CONSTRAINTS
;
1730 constraint
->choice2
[0] = '\0';
1734 case 4 : /* Two options, two choices... */
1736 * Check for broken constraints like "* Option"...
1739 if (cg
->ppd_conform
== PPD_CONFORM_STRICT
&&
1740 (!strcmp(constraint
->option1
, "*") ||
1741 !strcmp(constraint
->choice1
, "*") ||
1742 !strcmp(constraint
->option2
, "*") ||
1743 !strcmp(constraint
->choice2
, "*")))
1745 cg
->ppd_status
= PPD_BAD_UI_CONSTRAINTS
;
1749 if (constraint
->option1
[0] == '*')
1750 _cups_strcpy(constraint
->option1
, constraint
->option1
+ 1);
1751 else if (cg
->ppd_conform
== PPD_CONFORM_STRICT
)
1753 cg
->ppd_status
= PPD_BAD_UI_CONSTRAINTS
;
1757 if (cg
->ppd_conform
== PPD_CONFORM_STRICT
&&
1758 constraint
->choice1
[0] == '*')
1760 cg
->ppd_status
= PPD_BAD_UI_CONSTRAINTS
;
1764 if (constraint
->option2
[0] == '*')
1765 _cups_strcpy(constraint
->option2
, constraint
->option2
+ 1);
1766 else if (cg
->ppd_conform
== PPD_CONFORM_STRICT
)
1768 cg
->ppd_status
= PPD_BAD_UI_CONSTRAINTS
;
1772 if (cg
->ppd_conform
== PPD_CONFORM_STRICT
&&
1773 constraint
->choice2
[0] == '*')
1775 cg
->ppd_status
= PPD_BAD_UI_CONSTRAINTS
;
1782 * Don't add this one as an attribute...
1785 _cupsStrFree(string
);
1788 else if (!strcmp(keyword
, "PaperDimension"))
1790 if ((size
= ppdPageSize(ppd
, name
)) == NULL
)
1791 size
= ppd_add_size(ppd
, name
);
1796 * Unable to add or find size!
1799 cg
->ppd_status
= PPD_ALLOC_ERROR
;
1804 size
->width
= (float)_cupsStrScand(string
, &sptr
, loc
);
1805 size
->length
= (float)_cupsStrScand(sptr
, NULL
, loc
);
1807 _cupsStrFree(string
);
1810 else if (!strcmp(keyword
, "ImageableArea"))
1812 if ((size
= ppdPageSize(ppd
, name
)) == NULL
)
1813 size
= ppd_add_size(ppd
, name
);
1818 * Unable to add or find size!
1821 cg
->ppd_status
= PPD_ALLOC_ERROR
;
1826 size
->left
= (float)_cupsStrScand(string
, &sptr
, loc
);
1827 size
->bottom
= (float)_cupsStrScand(sptr
, &sptr
, loc
);
1828 size
->right
= (float)_cupsStrScand(sptr
, &sptr
, loc
);
1829 size
->top
= (float)_cupsStrScand(sptr
, NULL
, loc
);
1831 _cupsStrFree(string
);
1834 else if (option
!= NULL
&&
1835 (mask
& (PPD_KEYWORD
| PPD_OPTION
| PPD_STRING
)) ==
1836 (PPD_KEYWORD
| PPD_OPTION
| PPD_STRING
) &&
1837 !strcmp(keyword
, option
->keyword
))
1839 DEBUG_printf(("group = %p, subgroup = %p\n", group
, subgroup
));
1841 if (!strcmp(keyword
, "PageSize"))
1844 * Add a page size...
1847 if (ppdPageSize(ppd
, name
) == NULL
)
1848 ppd_add_size(ppd
, name
);
1852 * Add the option choice...
1855 if ((choice
= ppd_add_choice(option
, name
)) == NULL
)
1857 cg
->ppd_status
= PPD_ALLOC_ERROR
;
1863 cupsCharsetToUTF8((cups_utf8_t
*)choice
->text
, text
,
1864 sizeof(choice
->text
), encoding
);
1865 else if (!strcmp(name
, "True"))
1866 strcpy(choice
->text
, _("Yes"));
1867 else if (!strcmp(name
, "False"))
1868 strcpy(choice
->text
, _("No"));
1870 strlcpy(choice
->text
, name
, sizeof(choice
->text
));
1872 if (option
->section
== PPD_ORDER_JCL
)
1873 ppd_decode(string
); /* Decode quoted string */
1875 choice
->code
= string
;
1876 string
= NULL
; /* Don't add as an attribute below */
1880 * Add remaining lines with keywords and string values as attributes...
1884 (mask
& (PPD_KEYWORD
| PPD_STRING
)) == (PPD_KEYWORD
| PPD_STRING
))
1885 ppd_add_attr(ppd
, keyword
, name
, text
, string
);
1887 _cupsStrFree(string
);
1890 ppd_free(line
.buffer
);
1893 * Reset language preferences...
1896 cupsLangFree(language
);
1899 if (!cupsFileEOF(fp
))
1900 DEBUG_printf(("Premature EOF at %lu...\n",
1901 (unsigned long)cupsFileTell(fp
)));
1904 if (cg
->ppd_status
!= PPD_OK
)
1907 * Had an error reading the PPD file, cannot continue!
1916 * Create the sorted options array and set the option back-pointer for
1917 * each choice and custom option...
1920 ppd
->options
= cupsArrayNew2((cups_array_func_t
)ppd_compare_options
, NULL
,
1921 (cups_ahash_func_t
)ppd_hash_option
,
1924 for (i
= ppd
->num_groups
, group
= ppd
->groups
;
1928 for (j
= group
->num_options
, option
= group
->options
;
1932 ppd_coption_t
*coption
; /* Custom option */
1935 cupsArrayAdd(ppd
->options
, option
);
1937 for (k
= 0; k
< option
->num_choices
; k
++)
1938 option
->choices
[k
].option
= option
;
1940 if ((coption
= ppdFindCustomOption(ppd
, option
->keyword
)) != NULL
)
1941 coption
->option
= option
;
1946 * Create an array to track the marked choices...
1949 ppd
->marked
= cupsArrayNew((cups_array_func_t
)ppd_compare_choices
, NULL
);
1952 * Return the PPD file structure...
1958 * Common exit point for errors to save code size...
1963 _cupsStrFree(string
);
1964 ppd_free(line
.buffer
);
1968 cupsLangFree(language
);
1975 * 'ppdOpenFd()' - Read a PPD file into memory.
1978 ppd_file_t
* /* O - PPD file record or @code NULL@ if the PPD file could not be opened. */
1979 ppdOpenFd(int fd
) /* I - File to read from */
1981 cups_file_t
*fp
; /* CUPS file pointer */
1982 ppd_file_t
*ppd
; /* PPD file record */
1983 _cups_globals_t
*cg
= _cupsGlobals();
1988 * Set the line number to 0...
1994 * Range check input...
1999 cg
->ppd_status
= PPD_NULL_FILE
;
2005 * Try to open the file and parse it...
2008 if ((fp
= cupsFileOpenFd(fd
, "r")) != NULL
)
2016 cg
->ppd_status
= PPD_FILE_OPEN_ERROR
;
2025 * 'ppdOpenFile()' - Read a PPD file into memory.
2028 ppd_file_t
* /* O - PPD file record or @code NULL@ if the PPD file could not be opened. */
2029 ppdOpenFile(const char *filename
) /* I - File to read from */
2031 cups_file_t
*fp
; /* File pointer */
2032 ppd_file_t
*ppd
; /* PPD file record */
2033 _cups_globals_t
*cg
= _cupsGlobals();
2038 * Set the line number to 0...
2044 * Range check input...
2047 if (filename
== NULL
)
2049 cg
->ppd_status
= PPD_NULL_FILE
;
2055 * Try to open the file and parse it...
2058 if ((fp
= cupsFileOpen(filename
, "r")) != NULL
)
2066 cg
->ppd_status
= PPD_FILE_OPEN_ERROR
;
2075 * 'ppdSetConformance()' - Set the conformance level for PPD files.
2077 * @since CUPS 1.1.20/Mac OS X 10.4@
2081 ppdSetConformance(ppd_conform_t c
) /* I - Conformance level */
2083 _cups_globals_t
*cg
= _cupsGlobals();
2087 cg
->ppd_conform
= c
;
2092 * 'ppd_add_attr()' - Add an attribute to the PPD data.
2095 static ppd_attr_t
* /* O - New attribute */
2096 ppd_add_attr(ppd_file_t
*ppd
, /* I - PPD file data */
2097 const char *name
, /* I - Attribute name */
2098 const char *spec
, /* I - Specifier string, if any */
2099 const char *text
, /* I - Text string, if any */
2100 const char *value
) /* I - Value of attribute */
2102 ppd_attr_t
**ptr
, /* New array */
2103 *temp
; /* New attribute */
2107 * Range check input...
2110 if (ppd
== NULL
|| name
== NULL
|| spec
== NULL
)
2114 * Create the array as needed...
2117 if (!ppd
->sorted_attrs
)
2118 ppd
->sorted_attrs
= cupsArrayNew((cups_array_func_t
)ppd_compare_attrs
,
2122 * Allocate memory for the new attribute...
2125 if (ppd
->num_attrs
== 0)
2126 ptr
= malloc(sizeof(ppd_attr_t
*));
2128 ptr
= realloc(ppd
->attrs
, (ppd
->num_attrs
+ 1) * sizeof(ppd_attr_t
*));
2134 ptr
+= ppd
->num_attrs
;
2136 if ((temp
= calloc(1, sizeof(ppd_attr_t
))) == NULL
)
2147 strlcpy(temp
->name
, name
, sizeof(temp
->name
));
2148 strlcpy(temp
->spec
, spec
, sizeof(temp
->spec
));
2149 strlcpy(temp
->text
, text
, sizeof(temp
->text
));
2150 temp
->value
= (char *)value
;
2153 * Add the attribute to the sorted array...
2156 cupsArrayAdd(ppd
->sorted_attrs
, temp
);
2159 * Return the attribute...
2167 * 'ppd_add_choice()' - Add a choice to an option.
2170 static ppd_choice_t
* /* O - Named choice */
2171 ppd_add_choice(ppd_option_t
*option
, /* I - Option */
2172 const char *name
) /* I - Name of choice */
2174 ppd_choice_t
*choice
; /* Choice */
2177 if (option
->num_choices
== 0)
2178 choice
= malloc(sizeof(ppd_choice_t
));
2180 choice
= realloc(option
->choices
,
2181 sizeof(ppd_choice_t
) * (option
->num_choices
+ 1));
2186 option
->choices
= choice
;
2187 choice
+= option
->num_choices
;
2188 option
->num_choices
++;
2190 memset(choice
, 0, sizeof(ppd_choice_t
));
2191 strlcpy(choice
->choice
, name
, sizeof(choice
->choice
));
2198 * 'ppd_add_size()' - Add a page size.
2201 static ppd_size_t
* /* O - Named size */
2202 ppd_add_size(ppd_file_t
*ppd
, /* I - PPD file */
2203 const char *name
) /* I - Name of size */
2205 ppd_size_t
*size
; /* Size */
2208 if (ppd
->num_sizes
== 0)
2209 size
= malloc(sizeof(ppd_size_t
));
2211 size
= realloc(ppd
->sizes
, sizeof(ppd_size_t
) * (ppd
->num_sizes
+ 1));
2217 size
+= ppd
->num_sizes
;
2220 memset(size
, 0, sizeof(ppd_size_t
));
2221 strlcpy(size
->name
, name
, sizeof(size
->name
));
2228 * 'ppd_compare_attrs()' - Compare two attributes.
2231 static int /* O - Result of comparison */
2232 ppd_compare_attrs(ppd_attr_t
*a
, /* I - First attribute */
2233 ppd_attr_t
*b
) /* I - Second attribute */
2235 return (strcasecmp(a
->name
, b
->name
));
2240 * 'ppd_compare_choices()' - Compare two choices...
2243 static int /* O - Result of comparison */
2244 ppd_compare_choices(ppd_choice_t
*a
, /* I - First choice */
2245 ppd_choice_t
*b
) /* I - Second choice */
2247 return (strcmp(a
->option
->keyword
, b
->option
->keyword
));
2252 * 'ppd_compare_coptions()' - Compare two custom options.
2255 static int /* O - Result of comparison */
2256 ppd_compare_coptions(ppd_coption_t
*a
, /* I - First option */
2257 ppd_coption_t
*b
) /* I - Second option */
2259 return (strcasecmp(a
->keyword
, b
->keyword
));
2264 * 'ppd_compare_cparams()' - Compare two custom parameters.
2267 static int /* O - Result of comparison */
2268 ppd_compare_cparams(ppd_cparam_t
*a
, /* I - First parameter */
2269 ppd_cparam_t
*b
) /* I - Second parameter */
2271 return (strcasecmp(a
->name
, b
->name
));
2276 * 'ppd_compare_options()' - Compare two options.
2279 static int /* O - Result of comparison */
2280 ppd_compare_options(ppd_option_t
*a
, /* I - First option */
2281 ppd_option_t
*b
) /* I - Second option */
2283 return (strcasecmp(a
->keyword
, b
->keyword
));
2288 * 'ppd_decode()' - Decode a string value...
2291 static int /* O - Length of decoded string */
2292 ppd_decode(char *string
) /* I - String to decode */
2294 char *inptr
, /* Input pointer */
2295 *outptr
; /* Output pointer */
2301 while (*inptr
!= '\0')
2302 if (*inptr
== '<' && isxdigit(inptr
[1] & 255))
2305 * Convert hex to 8-bit values...
2309 while (isxdigit(*inptr
& 255))
2311 if (isalpha(*inptr
))
2312 *outptr
= (tolower(*inptr
) - 'a' + 10) << 4;
2314 *outptr
= (*inptr
- '0') << 4;
2318 if (!isxdigit(*inptr
& 255))
2321 if (isalpha(*inptr
))
2322 *outptr
|= tolower(*inptr
) - 'a' + 10;
2324 *outptr
|= *inptr
- '0';
2330 while (*inptr
!= '>' && *inptr
!= '\0')
2332 while (*inptr
== '>')
2336 *outptr
++ = *inptr
++;
2340 return ((int)(outptr
- string
));
2345 * 'ppd_free_group()' - Free a single UI group.
2349 ppd_free_group(ppd_group_t
*group
) /* I - Group to free */
2351 int i
; /* Looping var */
2352 ppd_option_t
*option
; /* Current option */
2353 ppd_group_t
*subgroup
; /* Current sub-group */
2356 if (group
->num_options
> 0)
2358 for (i
= group
->num_options
, option
= group
->options
;
2361 ppd_free_option(option
);
2363 ppd_free(group
->options
);
2366 if (group
->num_subgroups
> 0)
2368 for (i
= group
->num_subgroups
, subgroup
= group
->subgroups
;
2371 ppd_free_group(subgroup
);
2373 ppd_free(group
->subgroups
);
2379 * 'ppd_free_option()' - Free a single option.
2383 ppd_free_option(ppd_option_t
*option
) /* I - Option to free */
2385 int i
; /* Looping var */
2386 ppd_choice_t
*choice
; /* Current choice */
2389 if (option
->num_choices
> 0)
2391 for (i
= option
->num_choices
, choice
= option
->choices
;
2395 _cupsStrFree(choice
->code
);
2398 ppd_free(option
->choices
);
2404 * 'ppd_get_coption()' - Get a custom option record.
2407 static ppd_coption_t
* /* O - Custom option... */
2408 ppd_get_coption(ppd_file_t
*ppd
, /* I - PPD file */
2409 const char *name
) /* I - Name of option */
2411 ppd_coption_t
*copt
; /* New custom option */
2415 * See if the option already exists...
2418 if ((copt
= ppdFindCustomOption(ppd
, name
)) != NULL
)
2422 * Not found, so create the custom option record...
2425 if ((copt
= calloc(1, sizeof(ppd_coption_t
))) == NULL
)
2428 strlcpy(copt
->keyword
, name
, sizeof(copt
->keyword
));
2430 copt
->params
= cupsArrayNew((cups_array_func_t
)ppd_compare_cparams
, NULL
);
2432 cupsArrayAdd(ppd
->coptions
, copt
);
2435 * Return the new record...
2443 * 'ppd_get_cparam()' - Get a custom parameter record.
2446 static ppd_cparam_t
* /* O - Extended option... */
2447 ppd_get_cparam(ppd_coption_t
*opt
, /* I - PPD file */
2448 const char *param
, /* I - Name of parameter */
2449 const char *text
) /* I - Human-readable text */
2451 ppd_cparam_t
*cparam
; /* New custom parameter */
2455 * See if the parameter already exists...
2458 if ((cparam
= ppdFindCustomParam(opt
, param
)) != NULL
)
2462 * Not found, so create the custom parameter record...
2465 if ((cparam
= calloc(1, sizeof(ppd_cparam_t
))) == NULL
)
2468 strlcpy(cparam
->name
, param
, sizeof(cparam
->name
));
2469 strlcpy(cparam
->text
, text
[0] ? text
: param
, sizeof(cparam
->text
));
2472 * Add this record to the array...
2475 cupsArrayAdd(opt
->params
, cparam
);
2478 * Return the new record...
2486 * 'ppd_get_group()' - Find or create the named group as needed.
2489 static ppd_group_t
* /* O - Named group */
2490 ppd_get_group(ppd_file_t
*ppd
, /* I - PPD file */
2491 const char *name
, /* I - Name of group */
2492 const char *text
, /* I - Text for group */
2493 _cups_globals_t
*cg
, /* I - Global data */
2494 cups_encoding_t encoding
) /* I - Encoding of text */
2496 int i
; /* Looping var */
2497 ppd_group_t
*group
; /* Group */
2500 DEBUG_printf(("ppd_get_group(ppd=%p, name=\"%s\", text=\"%s\", cg=%p)\n",
2501 ppd
, name
, text
, cg
));
2503 for (i
= ppd
->num_groups
, group
= ppd
->groups
; i
> 0; i
--, group
++)
2504 if (!strcmp(group
->name
, name
))
2509 DEBUG_printf(("Adding group %s...\n", name
));
2511 if (cg
->ppd_conform
== PPD_CONFORM_STRICT
&& strlen(text
) >= sizeof(group
->text
))
2513 cg
->ppd_status
= PPD_ILLEGAL_TRANSLATION
;
2518 if (ppd
->num_groups
== 0)
2519 group
= malloc(sizeof(ppd_group_t
));
2521 group
= realloc(ppd
->groups
,
2522 (ppd
->num_groups
+ 1) * sizeof(ppd_group_t
));
2526 cg
->ppd_status
= PPD_ALLOC_ERROR
;
2531 ppd
->groups
= group
;
2532 group
+= ppd
->num_groups
;
2535 memset(group
, 0, sizeof(ppd_group_t
));
2536 strlcpy(group
->name
, name
, sizeof(group
->name
));
2538 cupsCharsetToUTF8((cups_utf8_t
*)group
->text
, text
,
2539 sizeof(group
->text
), encoding
);
2547 * 'ppd_get_option()' - Find or create the named option as needed.
2550 static ppd_option_t
* /* O - Named option */
2551 ppd_get_option(ppd_group_t
*group
, /* I - Group */
2552 const char *name
) /* I - Name of option */
2554 int i
; /* Looping var */
2555 ppd_option_t
*option
; /* Option */
2558 DEBUG_printf(("ppd_get_option(group=%p(\"%s\"), name=\"%s\")\n",
2559 group
, group
->name
, name
));
2561 for (i
= group
->num_options
, option
= group
->options
; i
> 0; i
--, option
++)
2562 if (!strcmp(option
->keyword
, name
))
2567 if (group
->num_options
== 0)
2568 option
= malloc(sizeof(ppd_option_t
));
2570 option
= realloc(group
->options
,
2571 (group
->num_options
+ 1) * sizeof(ppd_option_t
));
2576 group
->options
= option
;
2577 option
+= group
->num_options
;
2578 group
->num_options
++;
2580 memset(option
, 0, sizeof(ppd_option_t
));
2581 strlcpy(option
->keyword
, name
, sizeof(option
->keyword
));
2589 * 'ppd_hash_option()' - Generate a hash of the option name...
2592 static int /* O - Hash index */
2593 ppd_hash_option(ppd_option_t
*option
) /* I - Option */
2595 int hash
= 0; /* Hash index */
2596 const char *k
; /* Pointer into keyword */
2599 for (hash
= option
->keyword
[0], k
= option
->keyword
+ 1; *k
;)
2600 hash
= 33 * hash
+ *k
++;
2602 return (hash
& 511);
2607 * 'ppd_read()' - Read a line from a PPD file, skipping comment lines as
2611 static int /* O - Bitmask of fields read */
2612 ppd_read(cups_file_t
*fp
, /* I - File to read from */
2613 _ppd_line_t
*line
, /* I - Line buffer */
2614 char *keyword
, /* O - Keyword from line */
2615 char *option
, /* O - Option from line */
2616 char *text
, /* O - Human-readable text from line */
2617 char **string
, /* O - Code/string data */
2618 int ignoreblank
, /* I - Ignore blank lines? */
2619 _cups_globals_t
*cg
) /* I - Global data */
2621 int ch
, /* Character from file */
2622 col
, /* Column in line */
2623 colon
, /* Colon seen? */
2624 endquote
, /* Waiting for an end quote */
2625 mask
, /* Mask to be returned */
2626 startline
, /* Start line */
2627 textlen
; /* Length of text */
2628 char *keyptr
, /* Keyword pointer */
2629 *optptr
, /* Option pointer */
2630 *textptr
, /* Text pointer */
2631 *strptr
, /* Pointer into string */
2632 *lineptr
; /* Current position in line buffer */
2636 * Now loop until we have a valid line...
2641 startline
= cg
->ppd_line
+ 1;
2645 line
->bufsize
= 1024;
2646 line
->buffer
= malloc(1024);
2658 lineptr
= line
->buffer
;
2662 while ((ch
= cupsFileGetChar(fp
)) != EOF
)
2664 if (lineptr
>= (line
->buffer
+ line
->bufsize
- 1))
2667 * Expand the line buffer...
2670 char *temp
; /* Temporary line pointer */
2673 line
->bufsize
+= 1024;
2674 if (line
->bufsize
> 262144)
2677 * Don't allow lines longer than 256k!
2680 cg
->ppd_line
= startline
;
2681 cg
->ppd_status
= PPD_LINE_TOO_LONG
;
2686 temp
= realloc(line
->buffer
, line
->bufsize
);
2689 cg
->ppd_line
= startline
;
2690 cg
->ppd_status
= PPD_LINE_TOO_LONG
;
2695 lineptr
= temp
+ (lineptr
- line
->buffer
);
2696 line
->buffer
= temp
;
2699 if (ch
== '\r' || ch
== '\n')
2702 * Line feed or carriage return...
2711 * Check for a trailing line feed...
2714 if ((ch
= cupsFilePeekChar(fp
)) == EOF
)
2721 cupsFileGetChar(fp
);
2724 if (lineptr
== line
->buffer
&& ignoreblank
)
2725 continue; /* Skip blank lines */
2729 if (!endquote
) /* Continue for multi-line text */
2734 else if (ch
< ' ' && ch
!= '\t' && cg
->ppd_conform
== PPD_CONFORM_STRICT
)
2737 * Other control characters...
2740 cg
->ppd_line
= startline
;
2741 cg
->ppd_status
= PPD_ILLEGAL_CHARACTER
;
2745 else if (ch
!= 0x1a)
2748 * Any other character...
2754 if (col
> (PPD_MAX_LINE
- 1))
2757 * Line is too long...
2760 cg
->ppd_line
= startline
;
2761 cg
->ppd_status
= PPD_LINE_TOO_LONG
;
2766 if (ch
== ':' && strncmp(line
->buffer
, "*%", 2) != 0)
2769 if (ch
== '\"' && colon
)
2770 endquote
= !endquote
;
2777 * Didn't finish this quoted string...
2780 while ((ch
= cupsFileGetChar(fp
)) != EOF
)
2783 else if (ch
== '\r' || ch
== '\n')
2791 * Check for a trailing line feed...
2794 if ((ch
= cupsFilePeekChar(fp
)) == EOF
)
2797 cupsFileGetChar(fp
);
2800 else if (ch
< ' ' && ch
!= '\t' && cg
->ppd_conform
== PPD_CONFORM_STRICT
)
2803 * Other control characters...
2806 cg
->ppd_line
= startline
;
2807 cg
->ppd_status
= PPD_ILLEGAL_CHARACTER
;
2811 else if (ch
!= 0x1a)
2815 if (col
> (PPD_MAX_LINE
- 1))
2818 * Line is too long...
2821 cg
->ppd_line
= startline
;
2822 cg
->ppd_status
= PPD_LINE_TOO_LONG
;
2832 * Didn't finish this line...
2835 while ((ch
= cupsFileGetChar(fp
)) != EOF
)
2836 if (ch
== '\r' || ch
== '\n')
2839 * Line feed or carriage return...
2848 * Check for a trailing line feed...
2851 if ((ch
= cupsFilePeekChar(fp
)) == EOF
)
2854 cupsFileGetChar(fp
);
2859 else if (ch
< ' ' && ch
!= '\t' && cg
->ppd_conform
== PPD_CONFORM_STRICT
)
2862 * Other control characters...
2865 cg
->ppd_line
= startline
;
2866 cg
->ppd_status
= PPD_ILLEGAL_CHARACTER
;
2870 else if (ch
!= 0x1a)
2874 if (col
> (PPD_MAX_LINE
- 1))
2877 * Line is too long...
2880 cg
->ppd_line
= startline
;
2881 cg
->ppd_status
= PPD_LINE_TOO_LONG
;
2888 if (lineptr
> line
->buffer
&& lineptr
[-1] == '\n')
2893 DEBUG_printf(("LINE=\"%s\"\n", line
->buffer
));
2896 * The dynamically created PPDs for older style Mac OS X
2897 * drivers include a large blob of data inserted as comments
2898 * at the end of the file. As an optimization we can stop
2899 * reading the PPD when we get to the start of this data.
2902 if (!strcmp(line
->buffer
, "*%APLWORKSET START"))
2905 if (ch
== EOF
&& lineptr
== line
->buffer
)
2913 lineptr
= line
->buffer
+ 1;
2920 if ((!line
->buffer
[0] || /* Blank line */
2921 !strncmp(line
->buffer
, "*%", 2) || /* Comment line */
2922 !strcmp(line
->buffer
, "*End")) && /* End of multi-line string */
2923 ignoreblank
) /* Ignore these? */
2925 startline
= cg
->ppd_line
+ 1;
2929 if (!strcmp(line
->buffer
, "*")) /* (Bad) comment line */
2931 if (cg
->ppd_conform
== PPD_CONFORM_RELAXED
)
2933 startline
= cg
->ppd_line
+ 1;
2938 cg
->ppd_line
= startline
;
2939 cg
->ppd_status
= PPD_ILLEGAL_MAIN_KEYWORD
;
2945 if (line
->buffer
[0] != '*') /* All lines start with an asterisk */
2948 * Allow lines consisting of just whitespace...
2951 for (lineptr
= line
->buffer
; *lineptr
; lineptr
++)
2952 if (!isspace(*lineptr
& 255))
2957 cg
->ppd_status
= PPD_MISSING_ASTERISK
;
2960 else if (ignoreblank
)
2972 while (*lineptr
!= '\0' && *lineptr
!= ':' && !isspace(*lineptr
& 255))
2974 if (*lineptr
<= ' ' || *lineptr
> 126 || *lineptr
== '/' ||
2975 (keyptr
- keyword
) >= (PPD_MAX_NAME
- 1))
2977 cg
->ppd_status
= PPD_ILLEGAL_MAIN_KEYWORD
;
2981 *keyptr
++ = *lineptr
++;
2986 if (!strcmp(keyword
, "End"))
2989 mask
|= PPD_KEYWORD
;
2991 /* DEBUG_printf(("keyword = \"%s\", lineptr = \"%s\"\n", keyword, lineptr));*/
2993 if (isspace(*lineptr
& 255))
2996 * Get an option name...
2999 while (isspace(*lineptr
& 255))
3004 while (*lineptr
!= '\0' && !isspace(*lineptr
& 255) && *lineptr
!= ':' &&
3007 if (*lineptr
<= ' ' || *lineptr
> 126 ||
3008 (optptr
- option
) >= (PPD_MAX_NAME
- 1))
3010 cg
->ppd_status
= PPD_ILLEGAL_OPTION_KEYWORD
;
3014 *optptr
++ = *lineptr
++;
3019 if (isspace(*lineptr
& 255) && cg
->ppd_conform
== PPD_CONFORM_STRICT
)
3021 cg
->ppd_status
= PPD_ILLEGAL_WHITESPACE
;
3025 while (isspace(*lineptr
& 255))
3030 /* DEBUG_printf(("option = \"%s\", lineptr = \"%s\"\n", option, lineptr));*/
3032 if (*lineptr
== '/')
3035 * Get human-readable text...
3042 while (*lineptr
!= '\0' && *lineptr
!= '\n' && *lineptr
!= ':')
3044 if (((unsigned char)*lineptr
< ' ' && *lineptr
!= '\t') ||
3045 (textptr
- text
) >= (PPD_MAX_LINE
- 1))
3047 cg
->ppd_status
= PPD_ILLEGAL_TRANSLATION
;
3051 *textptr
++ = *lineptr
++;
3055 textlen
= ppd_decode(text
);
3057 if (textlen
> PPD_MAX_TEXT
&& cg
->ppd_conform
== PPD_CONFORM_STRICT
)
3059 cg
->ppd_status
= PPD_ILLEGAL_TRANSLATION
;
3066 /* DEBUG_printf(("text = \"%s\", lineptr = \"%s\"\n", text, lineptr));*/
3069 if (isspace(*lineptr
& 255) && cg
->ppd_conform
== PPD_CONFORM_STRICT
)
3071 cg
->ppd_status
= PPD_ILLEGAL_WHITESPACE
;
3075 while (isspace(*lineptr
& 255))
3078 if (*lineptr
== ':')
3081 * Get string after triming leading and trailing whitespace...
3085 while (isspace(*lineptr
& 255))
3088 strptr
= lineptr
+ strlen(lineptr
) - 1;
3089 while (strptr
>= lineptr
&& isspace(*strptr
& 255))
3092 if (*strptr
== '\"')
3095 * Quoted string by itself, remove quotes...
3102 *string
= _cupsStrAlloc(lineptr
);
3104 /* DEBUG_printf(("string = \"%s\", lineptr = \"%s\"\n", *string, lineptr));*/
3116 * End of "$Id: ppd.c 7906 2008-09-03 20:19:43Z mike $".