2 * "$Id: ppd.c 7906 2008-09-03 20:19:43Z mike $"
4 * PPD file routines for CUPS.
6 * Copyright 2007-2010 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 "cups-private.h"
63 #include "ppd-private.h"
70 #if defined(WIN32) || defined(__EMX__)
71 # define READ_BINARY "rb" /* Open a binary file for reading */
72 # define WRITE_BINARY "wb" /* Open a binary file for writing */
74 # define READ_BINARY "r" /* Open a binary file for reading */
75 # define WRITE_BINARY "w" /* Open a binary file for writing */
76 #endif /* WIN32 || __EMX__ */
78 #define ppd_free(p) if (p) free(p) /* Safe free macro */
80 #define PPD_KEYWORD 1 /* Line contained a keyword */
81 #define PPD_OPTION 2 /* Line contained an option name */
82 #define PPD_TEXT 4 /* Line contained human-readable text */
83 #define PPD_STRING 8 /* Line contained a string or code */
85 #define PPD_HASHSIZE 512 /* Size of hash */
89 * Line buffer structure...
92 typedef struct _ppd_line_s
94 char *buffer
; /* Pointer to buffer */
95 size_t bufsize
; /* Size of the buffer */
103 static ppd_attr_t
*ppd_add_attr(ppd_file_t
*ppd
, const char *name
,
104 const char *spec
, const char *text
,
106 static ppd_choice_t
*ppd_add_choice(ppd_option_t
*option
, const char *name
);
107 static ppd_size_t
*ppd_add_size(ppd_file_t
*ppd
, const char *name
);
108 static int ppd_compare_attrs(ppd_attr_t
*a
, ppd_attr_t
*b
);
109 static int ppd_compare_choices(ppd_choice_t
*a
, ppd_choice_t
*b
);
110 static int ppd_compare_coptions(ppd_coption_t
*a
,
112 static int ppd_compare_cparams(ppd_cparam_t
*a
, ppd_cparam_t
*b
);
113 static int ppd_compare_options(ppd_option_t
*a
, ppd_option_t
*b
);
114 static int ppd_decode(char *string
);
115 static void ppd_free_group(ppd_group_t
*group
);
116 static void ppd_free_option(ppd_option_t
*option
);
117 static ppd_coption_t
*ppd_get_coption(ppd_file_t
*ppd
, const char *name
);
118 static ppd_cparam_t
*ppd_get_cparam(ppd_coption_t
*opt
,
121 static ppd_group_t
*ppd_get_group(ppd_file_t
*ppd
, const char *name
,
122 const char *text
, _cups_globals_t
*cg
,
123 cups_encoding_t encoding
);
124 static ppd_option_t
*ppd_get_option(ppd_group_t
*group
, const char *name
);
125 static int ppd_hash_option(ppd_option_t
*option
);
126 static int ppd_read(cups_file_t
*fp
, _ppd_line_t
*line
,
127 char *keyword
, char *option
, char *text
,
128 char **string
, int ignoreblank
,
129 _cups_globals_t
*cg
);
133 * 'ppdClose()' - Free all memory used by the PPD file.
137 ppdClose(ppd_file_t
*ppd
) /* I - PPD file record */
139 int i
; /* Looping var */
140 ppd_emul_t
*emul
; /* Current emulation */
141 ppd_group_t
*group
; /* Current group */
142 char **font
; /* Current font */
143 char **filter
; /* Current filter */
144 ppd_attr_t
**attr
; /* Current attribute */
145 ppd_coption_t
*coption
; /* Current custom option */
146 ppd_cparam_t
*cparam
; /* Current custom parameter */
150 * Range check arguments...
157 * Free all strings at the top level...
160 _cupsStrFree(ppd
->lang_encoding
);
161 _cupsStrFree(ppd
->nickname
);
164 _cupsStrFree(ppd
->jcl_begin
);
165 _cupsStrFree(ppd
->jcl_end
);
166 _cupsStrFree(ppd
->jcl_ps
);
169 * Free any emulations...
172 if (ppd
->num_emulations
> 0)
174 for (i
= ppd
->num_emulations
, emul
= ppd
->emulations
; i
> 0; i
--, emul
++)
176 _cupsStrFree(emul
->start
);
177 _cupsStrFree(emul
->stop
);
180 ppd_free(ppd
->emulations
);
184 * Free any UI groups, subgroups, and options...
187 if (ppd
->num_groups
> 0)
189 for (i
= ppd
->num_groups
, group
= ppd
->groups
; i
> 0; i
--, group
++)
190 ppd_free_group(group
);
192 ppd_free(ppd
->groups
);
195 cupsArrayDelete(ppd
->options
);
196 cupsArrayDelete(ppd
->marked
);
199 * Free any page sizes...
202 if (ppd
->num_sizes
> 0)
203 ppd_free(ppd
->sizes
);
206 * Free any constraints...
209 if (ppd
->num_consts
> 0)
210 ppd_free(ppd
->consts
);
213 * Free any filters...
216 if (ppd
->num_filters
> 0)
218 for (i
= ppd
->num_filters
, filter
= ppd
->filters
; i
> 0; i
--, filter
++)
219 _cupsStrFree(*filter
);
221 ppd_free(ppd
->filters
);
228 if (ppd
->num_fonts
> 0)
230 for (i
= ppd
->num_fonts
, font
= ppd
->fonts
; i
> 0; i
--, font
++)
233 ppd_free(ppd
->fonts
);
237 * Free any profiles...
240 if (ppd
->num_profiles
> 0)
241 ppd_free(ppd
->profiles
);
244 * Free any attributes...
247 if (ppd
->num_attrs
> 0)
249 for (i
= ppd
->num_attrs
, attr
= ppd
->attrs
; i
> 0; i
--, attr
++)
251 _cupsStrFree((*attr
)->value
);
255 ppd_free(ppd
->attrs
);
258 cupsArrayDelete(ppd
->sorted_attrs
);
261 * Free custom options...
264 for (coption
= (ppd_coption_t
*)cupsArrayFirst(ppd
->coptions
);
266 coption
= (ppd_coption_t
*)cupsArrayNext(ppd
->coptions
))
268 for (cparam
= (ppd_cparam_t
*)cupsArrayFirst(coption
->params
);
270 cparam
= (ppd_cparam_t
*)cupsArrayNext(coption
->params
))
272 switch (cparam
->type
)
274 case PPD_CUSTOM_PASSCODE
:
275 case PPD_CUSTOM_PASSWORD
:
276 case PPD_CUSTOM_STRING
:
277 _cupsStrFree(cparam
->current
.custom_string
);
287 cupsArrayDelete(coption
->params
);
292 cupsArrayDelete(ppd
->coptions
);
295 * Free constraints...
298 if (ppd
->cups_uiconstraints
)
300 _ppd_cups_uiconsts_t
*consts
; /* Current constraints */
303 for (consts
= (_ppd_cups_uiconsts_t
*)cupsArrayFirst(ppd
->cups_uiconstraints
);
305 consts
= (_ppd_cups_uiconsts_t
*)cupsArrayNext(ppd
->cups_uiconstraints
))
307 free(consts
->constraints
);
311 cupsArrayDelete(ppd
->cups_uiconstraints
);
315 * Free any PWG mapping data...
319 _pwgDestroy((_pwg_t
*)ppd
->pwg
);
322 * Free the whole record...
330 * 'ppdErrorString()' - Returns the text assocated with a status.
332 * @since CUPS 1.1.19/Mac OS X 10.3@
335 const char * /* O - Status string */
336 ppdErrorString(ppd_status_t status
) /* I - PPD status */
338 static const char * const messages
[] =/* Status messages */
341 _("Unable to open PPD file"),
342 _("NULL PPD file pointer"),
343 _("Memory allocation error"),
344 _("Missing PPD-Adobe-4.x header"),
345 _("Missing value string"),
348 _("OpenGroup without a CloseGroup first"),
349 _("Bad OpenUI/JCLOpenUI"),
350 _("OpenUI/JCLOpenUI without a CloseUI/JCLCloseUI first"),
351 _("Bad OrderDependency"),
352 _("Bad UIConstraints"),
353 _("Missing asterisk in column 1"),
354 _("Line longer than the maximum allowed (255 characters)"),
355 _("Illegal control character"),
356 _("Illegal main keyword string"),
357 _("Illegal option keyword string"),
358 _("Illegal translation string"),
359 _("Illegal whitespace character"),
360 _("Bad custom parameter"),
361 _("Missing option keyword"),
362 _("Bad value string")
366 if (status
< PPD_OK
|| status
>= PPD_MAX_STATUS
)
367 return (_cupsLangString(cupsLangDefault(), _("Unknown")));
369 return (_cupsLangString(cupsLangDefault(), messages
[status
]));
374 * '_ppdGetEncoding()' - Get the CUPS encoding value for the given
378 cups_encoding_t
/* O - CUPS encoding value */
379 _ppdGetEncoding(const char *name
) /* I - LanguageEncoding string */
381 if (!strcasecmp(name
, "ISOLatin1"))
382 return (CUPS_ISO8859_1
);
383 else if (!strcasecmp(name
, "ISOLatin2"))
384 return (CUPS_ISO8859_2
);
385 else if (!strcasecmp(name
, "ISOLatin5"))
386 return (CUPS_ISO8859_5
);
387 else if (!strcasecmp(name
, "JIS83-RKSJ"))
388 return (CUPS_JIS_X0213
);
389 else if (!strcasecmp(name
, "MacStandard"))
390 return (CUPS_MAC_ROMAN
);
391 else if (!strcasecmp(name
, "WindowsANSI"))
392 return (CUPS_WINDOWS_1252
);
399 * 'ppdLastError()' - Return the status from the last ppdOpen*().
401 * @since CUPS 1.1.19/Mac OS X 10.3@
404 ppd_status_t
/* O - Status code */
405 ppdLastError(int *line
) /* O - Line number */
407 _cups_globals_t
*cg
= _cupsGlobals();
412 *line
= cg
->ppd_line
;
414 return (cg
->ppd_status
);
419 * 'ppdOpen()' - Read a PPD file into memory.
422 ppd_file_t
* /* O - PPD file record */
423 ppdOpen(FILE *fp
) /* I - File to read from */
425 ppd_file_t
*ppd
; /* PPD file record */
426 cups_file_t
*cf
; /* CUPS file */
430 * Reopen the stdio file as a CUPS file...
433 if ((cf
= cupsFileOpenFd(fileno(fp
), "r")) == NULL
)
437 * Load the PPD file using the newer API...
443 * Close the CUPS file and return the PPD...
453 * 'ppdOpen2()' - Read a PPD file into memory.
455 * @since CUPS 1.2/Mac OS X 10.5@
458 ppd_file_t
* /* O - PPD file record or @code NULL@ if the PPD file could not be opened. */
459 ppdOpen2(cups_file_t
*fp
) /* I - File to read from */
461 int i
, j
, k
; /* Looping vars */
462 int count
; /* Temporary count */
463 _ppd_line_t line
; /* Line buffer */
464 ppd_file_t
*ppd
; /* PPD file record */
465 ppd_group_t
*group
, /* Current group */
466 *subgroup
; /* Current sub-group */
467 ppd_option_t
*option
; /* Current option */
468 ppd_choice_t
*choice
; /* Current choice */
469 ppd_const_t
*constraint
; /* Current constraint */
470 ppd_size_t
*size
; /* Current page size */
471 int mask
; /* Line data mask */
472 char keyword
[PPD_MAX_NAME
],
473 /* Keyword from file */
475 /* Option from file */
477 /* Human-readable text from file */
478 *string
, /* Code/text from file */
479 *sptr
, /* Pointer into string */
480 *nameptr
, /* Pointer into name */
481 *temp
, /* Temporary string pointer */
482 **tempfonts
; /* Temporary fonts pointer */
483 float order
; /* Order dependency number */
484 ppd_section_t section
; /* Order dependency section */
485 ppd_profile_t
*profile
; /* Pointer to color profile */
486 char **filter
; /* Pointer to filter */
487 cups_lang_t
*language
; /* Default language */
488 struct lconv
*loc
; /* Locale data */
489 int ui_keyword
; /* Is this line a UI keyword? */
490 cups_encoding_t encoding
; /* Encoding of PPD file */
491 _cups_globals_t
*cg
= _cupsGlobals();
493 char custom_name
[PPD_MAX_NAME
];
494 /* CustomFoo attribute name */
495 ppd_attr_t
*custom_attr
; /* CustomFoo attribute */
496 static const char * const ui_keywords
[] =
498 #ifdef CUPS_USE_FULL_UI_KEYWORDS_LIST
500 * Adobe defines some 41 keywords as "UI", meaning that they are
501 * user interface elements and that they should be treated as such
502 * even if the PPD creator doesn't use Open/CloseUI around them.
504 * Since this can cause previously invisible options to appear and
505 * confuse users, the default is to only treat the PageSize and
506 * PageRegion keywords this way.
508 /* Boolean keywords */
518 /* PickOne keywords */
531 "JCLFrameBufferSize",
552 #else /* !CUPS_USE_FULL_UI_KEYWORDS_LIST */
555 #endif /* CUPS_USE_FULL_UI_KEYWORDS_LIST */
559 DEBUG_printf(("ppdOpen2(fp=%p)", fp
));
562 * Default to "OK" status...
565 cg
->ppd_status
= PPD_OK
;
569 * Range check input...
574 cg
->ppd_status
= PPD_NULL_FILE
;
579 * Grab the first line and make sure it reads '*PPD-Adobe: "major.minor"'...
585 mask
= ppd_read(fp
, &line
, keyword
, name
, text
, &string
, 0, cg
);
587 DEBUG_printf(("2ppdOpen2: mask=%x, keyword=\"%s\"...", mask
, keyword
));
590 strcmp(keyword
, "PPD-Adobe") ||
591 string
== NULL
|| string
[0] != '4')
594 * Either this is not a PPD file, or it is not a 4.x PPD file.
597 if (cg
->ppd_status
== PPD_OK
)
598 cg
->ppd_status
= PPD_MISSING_PPDADOBE4
;
600 _cupsStrFree(string
);
601 ppd_free(line
.buffer
);
606 DEBUG_printf(("2ppdOpen2: keyword=%s, string=%p", keyword
, string
));
608 _cupsStrFree(string
);
611 * Allocate memory for the PPD file record...
614 if ((ppd
= calloc(1, sizeof(ppd_file_t
))) == NULL
)
616 cg
->ppd_status
= PPD_ALLOC_ERROR
;
618 _cupsStrFree(string
);
619 ppd_free(line
.buffer
);
624 ppd
->language_level
= 2;
625 ppd
->color_device
= 0;
626 ppd
->colorspace
= PPD_CS_N
;
627 ppd
->landscape
= -90;
628 ppd
->coptions
= cupsArrayNew((cups_array_func_t
)ppd_compare_coptions
,
632 * Get the default language for the user...
635 language
= cupsLangDefault();
639 * Read lines from the PPD file and add them to the file record...
647 encoding
= CUPS_ISO8859_1
;
649 while ((mask
= ppd_read(fp
, &line
, keyword
, name
, text
, &string
, 1, cg
)) != 0)
651 DEBUG_printf(("2ppdOpen2: mask=%x, keyword=\"%s\", name=\"%s\", "
652 "text=\"%s\", string=%d chars...", mask
, keyword
, name
, text
,
653 string
? (int)strlen(string
) : 0));
655 if (strncmp(keyword
, "Default", 7) && !string
&&
656 cg
->ppd_conform
!= PPD_CONFORM_RELAXED
)
659 * Need a string value!
662 cg
->ppd_status
= PPD_MISSING_VALUE
;
668 * Certain main keywords (as defined by the PPD spec) may be used
669 * without the usual OpenUI/CloseUI stuff. Presumably this is just
670 * so that Adobe wouldn't completely break compatibility with PPD
671 * files prior to v4.0 of the spec, but it is hopelessly
672 * inconsistent... Catch these main keywords and automatically
673 * create the corresponding option, as needed...
679 * Previous line was a UI keyword...
686 if (option
== NULL
&&
687 (mask
& (PPD_KEYWORD
| PPD_OPTION
| PPD_STRING
)) ==
688 (PPD_KEYWORD
| PPD_OPTION
| PPD_STRING
))
690 for (i
= 0; i
< (int)(sizeof(ui_keywords
) / sizeof(ui_keywords
[0])); i
++)
691 if (!strcmp(keyword
, ui_keywords
[i
]))
694 if (i
< (int)(sizeof(ui_keywords
) / sizeof(ui_keywords
[0])))
697 * Create the option in the appropriate group...
702 DEBUG_printf(("2ppdOpen2: FOUND ADOBE UI KEYWORD %s WITHOUT OPENUI!",
707 if ((group
= ppd_get_group(ppd
, "General", _("General"), cg
,
711 DEBUG_printf(("2ppdOpen2: Adding to group %s...", group
->text
));
712 option
= ppd_get_option(group
, keyword
);
716 option
= ppd_get_option(group
, keyword
);
720 cg
->ppd_status
= PPD_ALLOC_ERROR
;
726 * Now fill in the initial information for the option...
729 if (!strncmp(keyword
, "JCL", 3))
730 option
->section
= PPD_ORDER_JCL
;
732 option
->section
= PPD_ORDER_ANY
;
734 option
->order
= 10.0f
;
737 option
->ui
= PPD_UI_BOOLEAN
;
739 option
->ui
= PPD_UI_PICKONE
;
741 for (j
= 0; j
< ppd
->num_attrs
; j
++)
742 if (!strncmp(ppd
->attrs
[j
]->name
, "Default", 7) &&
743 !strcmp(ppd
->attrs
[j
]->name
+ 7, keyword
) &&
744 ppd
->attrs
[j
]->value
)
746 DEBUG_printf(("2ppdOpen2: Setting Default%s to %s via attribute...",
747 option
->keyword
, ppd
->attrs
[j
]->value
));
748 strlcpy(option
->defchoice
, ppd
->attrs
[j
]->value
,
749 sizeof(option
->defchoice
));
753 if (!strcmp(keyword
, "PageSize"))
754 strlcpy(option
->text
, _("Media Size"), sizeof(option
->text
));
755 else if (!strcmp(keyword
, "MediaType"))
756 strlcpy(option
->text
, _("Media Type"), sizeof(option
->text
));
757 else if (!strcmp(keyword
, "InputSlot"))
758 strlcpy(option
->text
, _("Media Source"), sizeof(option
->text
));
759 else if (!strcmp(keyword
, "ColorModel"))
760 strlcpy(option
->text
, _("Output Mode"), sizeof(option
->text
));
761 else if (!strcmp(keyword
, "Resolution"))
762 strlcpy(option
->text
, _("Resolution"), sizeof(option
->text
));
764 strlcpy(option
->text
, keyword
, sizeof(option
->text
));
768 if (!strcmp(keyword
, "LanguageLevel"))
769 ppd
->language_level
= atoi(string
);
770 else if (!strcmp(keyword
, "LanguageEncoding"))
773 * Say all PPD files are UTF-8, since we convert to UTF-8...
776 ppd
->lang_encoding
= _cupsStrAlloc("UTF-8");
777 encoding
= _ppdGetEncoding(string
);
779 else if (!strcmp(keyword
, "LanguageVersion"))
780 ppd
->lang_version
= string
;
781 else if (!strcmp(keyword
, "Manufacturer"))
782 ppd
->manufacturer
= string
;
783 else if (!strcmp(keyword
, "ModelName"))
784 ppd
->modelname
= string
;
785 else if (!strcmp(keyword
, "Protocols"))
786 ppd
->protocols
= string
;
787 else if (!strcmp(keyword
, "PCFileName"))
788 ppd
->pcfilename
= string
;
789 else if (!strcmp(keyword
, "NickName"))
791 if (encoding
!= CUPS_UTF8
)
793 cups_utf8_t utf8
[256]; /* UTF-8 version of NickName */
796 cupsCharsetToUTF8(utf8
, string
, sizeof(utf8
), encoding
);
797 ppd
->nickname
= _cupsStrAlloc((char *)utf8
);
800 ppd
->nickname
= _cupsStrAlloc(string
);
802 else if (!strcmp(keyword
, "Product"))
803 ppd
->product
= string
;
804 else if (!strcmp(keyword
, "ShortNickName"))
805 ppd
->shortnickname
= string
;
806 else if (!strcmp(keyword
, "TTRasterizer"))
807 ppd
->ttrasterizer
= string
;
808 else if (!strcmp(keyword
, "JCLBegin"))
810 ppd
->jcl_begin
= _cupsStrAlloc(string
);
811 ppd_decode(ppd
->jcl_begin
); /* Decode quoted string */
813 else if (!strcmp(keyword
, "JCLEnd"))
815 ppd
->jcl_end
= _cupsStrAlloc(string
);
816 ppd_decode(ppd
->jcl_end
); /* Decode quoted string */
818 else if (!strcmp(keyword
, "JCLToPSInterpreter"))
820 ppd
->jcl_ps
= _cupsStrAlloc(string
);
821 ppd_decode(ppd
->jcl_ps
); /* Decode quoted string */
823 else if (!strcmp(keyword
, "AccurateScreensSupport"))
824 ppd
->accurate_screens
= !strcmp(string
, "True");
825 else if (!strcmp(keyword
, "ColorDevice"))
826 ppd
->color_device
= !strcmp(string
, "True");
827 else if (!strcmp(keyword
, "ContoneOnly"))
828 ppd
->contone_only
= !strcmp(string
, "True");
829 else if (!strcmp(keyword
, "cupsFlipDuplex"))
830 ppd
->flip_duplex
= !strcmp(string
, "True");
831 else if (!strcmp(keyword
, "cupsManualCopies"))
832 ppd
->manual_copies
= !strcmp(string
, "True");
833 else if (!strcmp(keyword
, "cupsModelNumber"))
834 ppd
->model_number
= atoi(string
);
835 else if (!strcmp(keyword
, "cupsColorProfile"))
837 if (ppd
->num_profiles
== 0)
838 profile
= malloc(sizeof(ppd_profile_t
));
840 profile
= realloc(ppd
->profiles
, sizeof(ppd_profile_t
) *
841 (ppd
->num_profiles
+ 1));
845 cg
->ppd_status
= PPD_ALLOC_ERROR
;
850 ppd
->profiles
= profile
;
851 profile
+= ppd
->num_profiles
;
852 ppd
->num_profiles
++;
854 memset(profile
, 0, sizeof(ppd_profile_t
));
855 strlcpy(profile
->resolution
, name
, sizeof(profile
->resolution
));
856 strlcpy(profile
->media_type
, text
, sizeof(profile
->media_type
));
858 profile
->density
= (float)_cupsStrScand(string
, &sptr
, loc
);
859 profile
->gamma
= (float)_cupsStrScand(sptr
, &sptr
, loc
);
860 profile
->matrix
[0][0] = (float)_cupsStrScand(sptr
, &sptr
, loc
);
861 profile
->matrix
[0][1] = (float)_cupsStrScand(sptr
, &sptr
, loc
);
862 profile
->matrix
[0][2] = (float)_cupsStrScand(sptr
, &sptr
, loc
);
863 profile
->matrix
[1][0] = (float)_cupsStrScand(sptr
, &sptr
, loc
);
864 profile
->matrix
[1][1] = (float)_cupsStrScand(sptr
, &sptr
, loc
);
865 profile
->matrix
[1][2] = (float)_cupsStrScand(sptr
, &sptr
, loc
);
866 profile
->matrix
[2][0] = (float)_cupsStrScand(sptr
, &sptr
, loc
);
867 profile
->matrix
[2][1] = (float)_cupsStrScand(sptr
, &sptr
, loc
);
868 profile
->matrix
[2][2] = (float)_cupsStrScand(sptr
, &sptr
, loc
);
870 else if (!strcmp(keyword
, "cupsFilter"))
872 if (ppd
->num_filters
== 0)
873 filter
= malloc(sizeof(char *));
875 filter
= realloc(ppd
->filters
, sizeof(char *) * (ppd
->num_filters
+ 1));
879 cg
->ppd_status
= PPD_ALLOC_ERROR
;
884 ppd
->filters
= filter
;
885 filter
+= ppd
->num_filters
;
889 * Copy filter string and prevent it from being freed below...
895 else if (!strcmp(keyword
, "Throughput"))
896 ppd
->throughput
= atoi(string
);
897 else if (!strcmp(keyword
, "Font"))
900 * Add this font to the list of available fonts...
903 if (ppd
->num_fonts
== 0)
904 tempfonts
= (char **)malloc(sizeof(char *));
906 tempfonts
= (char **)realloc(ppd
->fonts
,
907 sizeof(char *) * (ppd
->num_fonts
+ 1));
909 if (tempfonts
== NULL
)
911 cg
->ppd_status
= PPD_ALLOC_ERROR
;
916 ppd
->fonts
= tempfonts
;
917 ppd
->fonts
[ppd
->num_fonts
] = _cupsStrAlloc(name
);
920 else if (!strncmp(keyword
, "ParamCustom", 11))
922 ppd_coption_t
*coption
; /* Custom option */
923 ppd_cparam_t
*cparam
; /* Custom parameter */
924 int corder
; /* Order number */
925 char ctype
[33], /* Data type */
926 cminimum
[65], /* Minimum value */
927 cmaximum
[65]; /* Maximum value */
931 * Get the custom option and parameter...
934 if ((coption
= ppd_get_coption(ppd
, keyword
+ 11)) == NULL
)
936 cg
->ppd_status
= PPD_ALLOC_ERROR
;
941 if ((cparam
= ppd_get_cparam(coption
, name
, text
)) == NULL
)
943 cg
->ppd_status
= PPD_ALLOC_ERROR
;
949 * Get the parameter data...
953 sscanf(string
, "%d%32s%64s%64s", &corder
, ctype
, cminimum
,
956 cg
->ppd_status
= PPD_BAD_CUSTOM_PARAM
;
961 cparam
->order
= corder
;
963 if (!strcmp(ctype
, "curve"))
965 cparam
->type
= PPD_CUSTOM_CURVE
;
966 cparam
->minimum
.custom_curve
= (float)_cupsStrScand(cminimum
, NULL
, loc
);
967 cparam
->maximum
.custom_curve
= (float)_cupsStrScand(cmaximum
, NULL
, loc
);
969 else if (!strcmp(ctype
, "int"))
971 cparam
->type
= PPD_CUSTOM_INT
;
972 cparam
->minimum
.custom_int
= atoi(cminimum
);
973 cparam
->maximum
.custom_int
= atoi(cmaximum
);
975 else if (!strcmp(ctype
, "invcurve"))
977 cparam
->type
= PPD_CUSTOM_INVCURVE
;
978 cparam
->minimum
.custom_invcurve
= (float)_cupsStrScand(cminimum
, NULL
, loc
);
979 cparam
->maximum
.custom_invcurve
= (float)_cupsStrScand(cmaximum
, NULL
, loc
);
981 else if (!strcmp(ctype
, "passcode"))
983 cparam
->type
= PPD_CUSTOM_PASSCODE
;
984 cparam
->minimum
.custom_passcode
= atoi(cminimum
);
985 cparam
->maximum
.custom_passcode
= atoi(cmaximum
);
987 else if (!strcmp(ctype
, "password"))
989 cparam
->type
= PPD_CUSTOM_PASSWORD
;
990 cparam
->minimum
.custom_password
= atoi(cminimum
);
991 cparam
->maximum
.custom_password
= atoi(cmaximum
);
993 else if (!strcmp(ctype
, "points"))
995 cparam
->type
= PPD_CUSTOM_POINTS
;
996 cparam
->minimum
.custom_points
= (float)_cupsStrScand(cminimum
, NULL
, loc
);
997 cparam
->maximum
.custom_points
= (float)_cupsStrScand(cmaximum
, NULL
, loc
);
999 else if (!strcmp(ctype
, "real"))
1001 cparam
->type
= PPD_CUSTOM_REAL
;
1002 cparam
->minimum
.custom_real
= (float)_cupsStrScand(cminimum
, NULL
, loc
);
1003 cparam
->maximum
.custom_real
= (float)_cupsStrScand(cmaximum
, NULL
, loc
);
1005 else if (!strcmp(ctype
, "string"))
1007 cparam
->type
= PPD_CUSTOM_STRING
;
1008 cparam
->minimum
.custom_string
= atoi(cminimum
);
1009 cparam
->maximum
.custom_string
= atoi(cmaximum
);
1013 cg
->ppd_status
= PPD_BAD_CUSTOM_PARAM
;
1019 * Now special-case for CustomPageSize...
1022 if (!strcmp(coption
->keyword
, "PageSize"))
1024 if (!strcmp(name
, "Width"))
1026 ppd
->custom_min
[0] = cparam
->minimum
.custom_points
;
1027 ppd
->custom_max
[0] = cparam
->maximum
.custom_points
;
1029 else if (!strcmp(name
, "Height"))
1031 ppd
->custom_min
[1] = cparam
->minimum
.custom_points
;
1032 ppd
->custom_max
[1] = cparam
->maximum
.custom_points
;
1036 else if (!strcmp(keyword
, "HWMargins"))
1038 for (i
= 0, sptr
= string
; i
< 4; i
++)
1039 ppd
->custom_margins
[i
] = (float)_cupsStrScand(sptr
, &sptr
, loc
);
1041 else if (!strncmp(keyword
, "Custom", 6) && !strcmp(name
, "True") && !option
)
1043 ppd_option_t
*custom_option
; /* Custom option */
1045 DEBUG_puts("2ppdOpen2: Processing Custom option...");
1048 * Get the option and custom option...
1051 if (!ppd_get_coption(ppd
, keyword
+ 6))
1053 cg
->ppd_status
= PPD_ALLOC_ERROR
;
1058 if (option
&& !strcasecmp(option
->keyword
, keyword
+ 6))
1059 custom_option
= option
;
1061 custom_option
= ppdFindOption(ppd
, keyword
+ 6);
1066 * Add the "custom" option...
1069 if ((choice
= ppdFindChoice(custom_option
, "Custom")) == NULL
)
1070 if ((choice
= ppd_add_choice(custom_option
, "Custom")) == NULL
)
1072 DEBUG_puts("1ppdOpen2: Unable to add Custom choice!");
1074 cg
->ppd_status
= PPD_ALLOC_ERROR
;
1079 strlcpy(choice
->text
, text
[0] ? text
: _("Custom"),
1080 sizeof(choice
->text
));
1082 choice
->code
= _cupsStrAlloc(string
);
1084 if (custom_option
->section
== PPD_ORDER_JCL
)
1085 ppd_decode(choice
->code
);
1089 * Now process custom page sizes specially...
1092 if (!strcmp(keyword
, "CustomPageSize"))
1095 * Add a "Custom" page size entry...
1098 ppd
->variable_sizes
= 1;
1100 ppd_add_size(ppd
, "Custom");
1102 if (option
&& !strcasecmp(option
->keyword
, "PageRegion"))
1103 custom_option
= option
;
1105 custom_option
= ppdFindOption(ppd
, "PageRegion");
1109 if ((choice
= ppdFindChoice(custom_option
, "Custom")) == NULL
)
1110 if ((choice
= ppd_add_choice(custom_option
, "Custom")) == NULL
)
1112 DEBUG_puts("1ppdOpen2: Unable to add Custom choice!");
1114 cg
->ppd_status
= PPD_ALLOC_ERROR
;
1119 strlcpy(choice
->text
, text
[0] ? text
: _("Custom"),
1120 sizeof(choice
->text
));
1124 else if (!strcmp(keyword
, "LandscapeOrientation"))
1126 if (!strcmp(string
, "Minus90"))
1127 ppd
->landscape
= -90;
1128 else if (!strcmp(string
, "Plus90"))
1129 ppd
->landscape
= 90;
1131 else if (!strcmp(keyword
, "Emulators") && string
)
1133 for (count
= 1, sptr
= string
; sptr
!= NULL
;)
1134 if ((sptr
= strchr(sptr
, ' ')) != NULL
)
1137 while (*sptr
== ' ')
1141 ppd
->num_emulations
= count
;
1142 if ((ppd
->emulations
= calloc(count
, sizeof(ppd_emul_t
))) == NULL
)
1144 cg
->ppd_status
= PPD_ALLOC_ERROR
;
1149 for (i
= 0, sptr
= string
; i
< count
; i
++)
1151 for (nameptr
= ppd
->emulations
[i
].name
;
1152 *sptr
!= '\0' && *sptr
!= ' ';
1154 if (nameptr
< (ppd
->emulations
[i
].name
+ sizeof(ppd
->emulations
[i
].name
) - 1))
1159 while (*sptr
== ' ')
1163 else if (!strncmp(keyword
, "StartEmulator_", 14))
1167 for (i
= 0; i
< ppd
->num_emulations
; i
++)
1168 if (!strcmp(keyword
+ 14, ppd
->emulations
[i
].name
))
1170 ppd
->emulations
[i
].start
= string
;
1174 else if (!strncmp(keyword
, "StopEmulator_", 13))
1178 for (i
= 0; i
< ppd
->num_emulations
; i
++)
1179 if (!strcmp(keyword
+ 13, ppd
->emulations
[i
].name
))
1181 ppd
->emulations
[i
].stop
= string
;
1185 else if (!strcmp(keyword
, "JobPatchFile"))
1188 * CUPS STR #3421: Check for "*JobPatchFile: int: string"
1191 if (isdigit(*string
& 255))
1193 for (sptr
= string
+ 1; isdigit(*sptr
& 255); sptr
++);
1198 * Found "*JobPatchFile: int: string"...
1201 cg
->ppd_status
= PPD_BAD_VALUE
;
1210 * Found "*JobPatchFile: string"...
1213 cg
->ppd_status
= PPD_MISSING_OPTION_KEYWORD
;
1218 if (ppd
->patches
== NULL
)
1219 ppd
->patches
= strdup(string
);
1222 temp
= realloc(ppd
->patches
, strlen(ppd
->patches
) +
1223 strlen(string
) + 1);
1226 cg
->ppd_status
= PPD_ALLOC_ERROR
;
1231 ppd
->patches
= temp
;
1233 strcpy(ppd
->patches
+ strlen(ppd
->patches
), string
);
1236 else if (!strcmp(keyword
, "OpenUI"))
1239 * Don't allow nesting of options...
1242 if (option
&& cg
->ppd_conform
== PPD_CONFORM_STRICT
)
1244 cg
->ppd_status
= PPD_NESTED_OPEN_UI
;
1250 * Add an option record to the current sub-group, group, or file...
1253 DEBUG_printf(("2ppdOpen2: name=\"%s\" (%d)", name
, (int)strlen(name
)));
1256 _cups_strcpy(name
, name
+ 1); /* Eliminate leading asterisk */
1258 for (i
= (int)strlen(name
) - 1; i
> 0 && isspace(name
[i
] & 255); i
--)
1259 name
[i
] = '\0'; /* Eliminate trailing spaces */
1261 DEBUG_printf(("2ppdOpen2: OpenUI of %s in group %s...", name
,
1262 group
? group
->text
: "(null)"));
1264 if (subgroup
!= NULL
)
1265 option
= ppd_get_option(subgroup
, name
);
1266 else if (group
== NULL
)
1268 if ((group
= ppd_get_group(ppd
, "General", _("General"), cg
,
1272 DEBUG_printf(("2ppdOpen2: Adding to group %s...", group
->text
));
1273 option
= ppd_get_option(group
, name
);
1277 option
= ppd_get_option(group
, name
);
1281 cg
->ppd_status
= PPD_ALLOC_ERROR
;
1287 * Now fill in the initial information for the option...
1290 if (string
&& !strcmp(string
, "PickMany"))
1291 option
->ui
= PPD_UI_PICKMANY
;
1292 else if (string
&& !strcmp(string
, "Boolean"))
1293 option
->ui
= PPD_UI_BOOLEAN
;
1294 else if (string
&& !strcmp(string
, "PickOne"))
1295 option
->ui
= PPD_UI_PICKONE
;
1296 else if (cg
->ppd_conform
== PPD_CONFORM_STRICT
)
1298 cg
->ppd_status
= PPD_BAD_OPEN_UI
;
1303 option
->ui
= PPD_UI_PICKONE
;
1305 for (j
= 0; j
< ppd
->num_attrs
; j
++)
1306 if (!strncmp(ppd
->attrs
[j
]->name
, "Default", 7) &&
1307 !strcmp(ppd
->attrs
[j
]->name
+ 7, name
) &&
1308 ppd
->attrs
[j
]->value
)
1310 DEBUG_printf(("2ppdOpen2: Setting Default%s to %s via attribute...",
1311 option
->keyword
, ppd
->attrs
[j
]->value
));
1312 strlcpy(option
->defchoice
, ppd
->attrs
[j
]->value
,
1313 sizeof(option
->defchoice
));
1318 cupsCharsetToUTF8((cups_utf8_t
*)option
->text
, text
,
1319 sizeof(option
->text
), encoding
);
1322 if (!strcmp(name
, "PageSize"))
1323 strlcpy(option
->text
, _("Media Size"), sizeof(option
->text
));
1324 else if (!strcmp(name
, "MediaType"))
1325 strlcpy(option
->text
, _("Media Type"), sizeof(option
->text
));
1326 else if (!strcmp(name
, "InputSlot"))
1327 strlcpy(option
->text
, _("Media Source"), sizeof(option
->text
));
1328 else if (!strcmp(name
, "ColorModel"))
1329 strlcpy(option
->text
, _("Output Mode"), sizeof(option
->text
));
1330 else if (!strcmp(name
, "Resolution"))
1331 strlcpy(option
->text
, _("Resolution"), sizeof(option
->text
));
1333 strlcpy(option
->text
, name
, sizeof(option
->text
));
1336 option
->section
= PPD_ORDER_ANY
;
1338 _cupsStrFree(string
);
1342 * Add a custom option choice if we have already seen a CustomFoo
1346 if (!strcasecmp(name
, "PageRegion"))
1347 strcpy(custom_name
, "CustomPageSize");
1349 snprintf(custom_name
, sizeof(custom_name
), "Custom%s", name
);
1351 if ((custom_attr
= ppdFindAttr(ppd
, custom_name
, "True")) != NULL
)
1353 if ((choice
= ppdFindChoice(option
, "Custom")) == NULL
)
1354 if ((choice
= ppd_add_choice(option
, "Custom")) == NULL
)
1356 DEBUG_puts("1ppdOpen2: Unable to add Custom choice!");
1358 cg
->ppd_status
= PPD_ALLOC_ERROR
;
1363 strlcpy(choice
->text
,
1364 custom_attr
->text
[0] ? custom_attr
->text
: _("Custom"),
1365 sizeof(choice
->text
));
1366 choice
->code
= _cupsStrRetain(custom_attr
->value
);
1369 else if (!strcmp(keyword
, "JCLOpenUI"))
1372 * Don't allow nesting of options...
1375 if (option
&& cg
->ppd_conform
== PPD_CONFORM_STRICT
)
1377 cg
->ppd_status
= PPD_NESTED_OPEN_UI
;
1383 * Find the JCL group, and add if needed...
1386 group
= ppd_get_group(ppd
, "JCL", _("JCL"), cg
, encoding
);
1392 * Add an option record to the current JCLs...
1396 _cups_strcpy(name
, name
+ 1);
1398 option
= ppd_get_option(group
, name
);
1402 cg
->ppd_status
= PPD_ALLOC_ERROR
;
1408 * Now fill in the initial information for the option...
1411 if (string
&& !strcmp(string
, "PickMany"))
1412 option
->ui
= PPD_UI_PICKMANY
;
1413 else if (string
&& !strcmp(string
, "Boolean"))
1414 option
->ui
= PPD_UI_BOOLEAN
;
1415 else if (string
&& !strcmp(string
, "PickOne"))
1416 option
->ui
= PPD_UI_PICKONE
;
1419 cg
->ppd_status
= PPD_BAD_OPEN_UI
;
1424 for (j
= 0; j
< ppd
->num_attrs
; j
++)
1425 if (!strncmp(ppd
->attrs
[j
]->name
, "Default", 7) &&
1426 !strcmp(ppd
->attrs
[j
]->name
+ 7, name
) &&
1427 ppd
->attrs
[j
]->value
)
1429 DEBUG_printf(("2ppdOpen2: Setting Default%s to %s via attribute...",
1430 option
->keyword
, ppd
->attrs
[j
]->value
));
1431 strlcpy(option
->defchoice
, ppd
->attrs
[j
]->value
,
1432 sizeof(option
->defchoice
));
1437 cupsCharsetToUTF8((cups_utf8_t
*)option
->text
, text
,
1438 sizeof(option
->text
), encoding
);
1440 strlcpy(option
->text
, name
, sizeof(option
->text
));
1442 option
->section
= PPD_ORDER_JCL
;
1445 _cupsStrFree(string
);
1449 * Add a custom option choice if we have already seen a CustomFoo
1453 snprintf(custom_name
, sizeof(custom_name
), "Custom%s", name
);
1455 if ((custom_attr
= ppdFindAttr(ppd
, custom_name
, "True")) != NULL
)
1457 if ((choice
= ppd_add_choice(option
, "Custom")) == NULL
)
1459 DEBUG_puts("1ppdOpen2: Unable to add Custom choice!");
1461 cg
->ppd_status
= PPD_ALLOC_ERROR
;
1466 strlcpy(choice
->text
,
1467 custom_attr
->text
[0] ? custom_attr
->text
: _("Custom"),
1468 sizeof(choice
->text
));
1469 choice
->code
= _cupsStrRetain(custom_attr
->value
);
1472 else if (!strcmp(keyword
, "CloseUI") || !strcmp(keyword
, "JCLCloseUI"))
1476 _cupsStrFree(string
);
1479 else if (!strcmp(keyword
, "OpenGroup"))
1482 * Open a new group...
1487 cg
->ppd_status
= PPD_NESTED_OPEN_GROUP
;
1494 cg
->ppd_status
= PPD_BAD_OPEN_GROUP
;
1500 * Separate the group name from the text (name/text)...
1503 if ((sptr
= strchr(string
, '/')) != NULL
)
1509 * Fix up the text...
1515 * Find/add the group...
1518 group
= ppd_get_group(ppd
, string
, sptr
, cg
, encoding
);
1523 _cupsStrFree(string
);
1526 else if (!strcmp(keyword
, "CloseGroup"))
1530 _cupsStrFree(string
);
1533 else if (!strcmp(keyword
, "OrderDependency"))
1535 order
= (float)_cupsStrScand(string
, &sptr
, loc
);
1537 if (!sptr
|| sscanf(sptr
, "%40s%40s", name
, keyword
) != 2)
1539 cg
->ppd_status
= PPD_BAD_ORDER_DEPENDENCY
;
1544 if (keyword
[0] == '*')
1545 _cups_strcpy(keyword
, keyword
+ 1);
1547 if (!strcmp(name
, "ExitServer"))
1548 section
= PPD_ORDER_EXIT
;
1549 else if (!strcmp(name
, "Prolog"))
1550 section
= PPD_ORDER_PROLOG
;
1551 else if (!strcmp(name
, "DocumentSetup"))
1552 section
= PPD_ORDER_DOCUMENT
;
1553 else if (!strcmp(name
, "PageSetup"))
1554 section
= PPD_ORDER_PAGE
;
1555 else if (!strcmp(name
, "JCLSetup"))
1556 section
= PPD_ORDER_JCL
;
1558 section
= PPD_ORDER_ANY
;
1566 * Only valid for Non-UI options...
1569 for (i
= ppd
->num_groups
, gtemp
= ppd
->groups
; i
> 0; i
--, gtemp
++)
1570 if (gtemp
->text
[0] == '\0')
1574 for (i
= 0; i
< gtemp
->num_options
; i
++)
1575 if (!strcmp(keyword
, gtemp
->options
[i
].keyword
))
1577 gtemp
->options
[i
].section
= section
;
1578 gtemp
->options
[i
].order
= order
;
1584 option
->section
= section
;
1585 option
->order
= order
;
1588 _cupsStrFree(string
);
1591 else if (!strncmp(keyword
, "Default", 7))
1597 * Drop UI text, if any, from value...
1600 if (strchr(string
, '/') != NULL
)
1601 *strchr(string
, '/') = '\0';
1604 * Assign the default value as appropriate...
1607 if (!strcmp(keyword
, "DefaultColorSpace"))
1610 * Set default colorspace...
1613 if (!strcmp(string
, "CMY"))
1614 ppd
->colorspace
= PPD_CS_CMY
;
1615 else if (!strcmp(string
, "CMYK"))
1616 ppd
->colorspace
= PPD_CS_CMYK
;
1617 else if (!strcmp(string
, "RGB"))
1618 ppd
->colorspace
= PPD_CS_RGB
;
1619 else if (!strcmp(string
, "RGBK"))
1620 ppd
->colorspace
= PPD_CS_RGBK
;
1621 else if (!strcmp(string
, "N"))
1622 ppd
->colorspace
= PPD_CS_N
;
1624 ppd
->colorspace
= PPD_CS_GRAY
;
1626 else if (option
&& !strcmp(keyword
+ 7, option
->keyword
))
1629 * Set the default as part of the current option...
1632 DEBUG_printf(("2ppdOpen2: Setting %s to %s...", keyword
, string
));
1634 strlcpy(option
->defchoice
, string
, sizeof(option
->defchoice
));
1636 DEBUG_printf(("2ppdOpen2: %s is now %s...", keyword
, option
->defchoice
));
1641 * Lookup option and set if it has been defined...
1644 ppd_option_t
*toption
; /* Temporary option */
1647 if ((toption
= ppdFindOption(ppd
, keyword
+ 7)) != NULL
)
1649 DEBUG_printf(("2ppdOpen2: Setting %s to %s...", keyword
, string
));
1650 strlcpy(toption
->defchoice
, string
, sizeof(toption
->defchoice
));
1654 else if (!strcmp(keyword
, "UIConstraints") ||
1655 !strcmp(keyword
, "NonUIConstraints"))
1659 cg
->ppd_status
= PPD_BAD_UI_CONSTRAINTS
;
1663 if (ppd
->num_consts
== 0)
1664 constraint
= calloc(2, sizeof(ppd_const_t
));
1666 constraint
= realloc(ppd
->consts
,
1667 (ppd
->num_consts
+ 2) * sizeof(ppd_const_t
));
1669 if (constraint
== NULL
)
1671 cg
->ppd_status
= PPD_ALLOC_ERROR
;
1676 ppd
->consts
= constraint
;
1677 constraint
+= ppd
->num_consts
;
1680 switch (sscanf(string
, "%40s%40s%40s%40s", constraint
->option1
,
1681 constraint
->choice1
, constraint
->option2
,
1682 constraint
->choice2
))
1684 case 0 : /* Error */
1685 case 1 : /* Error */
1686 cg
->ppd_status
= PPD_BAD_UI_CONSTRAINTS
;
1689 case 2 : /* Two options... */
1691 * Check for broken constraints like "* Option"...
1694 if (cg
->ppd_conform
== PPD_CONFORM_STRICT
&&
1695 (!strcmp(constraint
->option1
, "*") ||
1696 !strcmp(constraint
->choice1
, "*")))
1698 cg
->ppd_status
= PPD_BAD_UI_CONSTRAINTS
;
1703 * The following strcpy's are safe, as optionN and
1704 * choiceN are all the same size (size defined by PPD spec...)
1707 if (constraint
->option1
[0] == '*')
1708 _cups_strcpy(constraint
->option1
, constraint
->option1
+ 1);
1709 else if (cg
->ppd_conform
== PPD_CONFORM_STRICT
)
1711 cg
->ppd_status
= PPD_BAD_UI_CONSTRAINTS
;
1715 if (constraint
->choice1
[0] == '*')
1716 _cups_strcpy(constraint
->option2
, constraint
->choice1
+ 1);
1717 else if (cg
->ppd_conform
== PPD_CONFORM_STRICT
)
1719 cg
->ppd_status
= PPD_BAD_UI_CONSTRAINTS
;
1723 constraint
->choice1
[0] = '\0';
1724 constraint
->choice2
[0] = '\0';
1727 case 3 : /* Two options, one choice... */
1729 * Check for broken constraints like "* Option"...
1732 if (cg
->ppd_conform
== PPD_CONFORM_STRICT
&&
1733 (!strcmp(constraint
->option1
, "*") ||
1734 !strcmp(constraint
->choice1
, "*") ||
1735 !strcmp(constraint
->option2
, "*")))
1737 cg
->ppd_status
= PPD_BAD_UI_CONSTRAINTS
;
1742 * The following _cups_strcpy's are safe, as optionN and
1743 * choiceN are all the same size (size defined by PPD spec...)
1746 if (constraint
->option1
[0] == '*')
1747 _cups_strcpy(constraint
->option1
, constraint
->option1
+ 1);
1748 else if (cg
->ppd_conform
== PPD_CONFORM_STRICT
)
1750 cg
->ppd_status
= PPD_BAD_UI_CONSTRAINTS
;
1754 if (constraint
->choice1
[0] == '*')
1756 if (cg
->ppd_conform
== PPD_CONFORM_STRICT
&&
1757 constraint
->option2
[0] == '*')
1759 cg
->ppd_status
= PPD_BAD_UI_CONSTRAINTS
;
1763 _cups_strcpy(constraint
->choice2
, constraint
->option2
);
1764 _cups_strcpy(constraint
->option2
, constraint
->choice1
+ 1);
1765 constraint
->choice1
[0] = '\0';
1769 if (constraint
->option2
[0] == '*')
1770 _cups_strcpy(constraint
->option2
, constraint
->option2
+ 1);
1771 else if (cg
->ppd_conform
== PPD_CONFORM_STRICT
)
1773 cg
->ppd_status
= PPD_BAD_UI_CONSTRAINTS
;
1777 constraint
->choice2
[0] = '\0';
1781 case 4 : /* Two options, two choices... */
1783 * Check for broken constraints like "* Option"...
1786 if (cg
->ppd_conform
== PPD_CONFORM_STRICT
&&
1787 (!strcmp(constraint
->option1
, "*") ||
1788 !strcmp(constraint
->choice1
, "*") ||
1789 !strcmp(constraint
->option2
, "*") ||
1790 !strcmp(constraint
->choice2
, "*")))
1792 cg
->ppd_status
= PPD_BAD_UI_CONSTRAINTS
;
1796 if (constraint
->option1
[0] == '*')
1797 _cups_strcpy(constraint
->option1
, constraint
->option1
+ 1);
1798 else if (cg
->ppd_conform
== PPD_CONFORM_STRICT
)
1800 cg
->ppd_status
= PPD_BAD_UI_CONSTRAINTS
;
1804 if (cg
->ppd_conform
== PPD_CONFORM_STRICT
&&
1805 constraint
->choice1
[0] == '*')
1807 cg
->ppd_status
= PPD_BAD_UI_CONSTRAINTS
;
1811 if (constraint
->option2
[0] == '*')
1812 _cups_strcpy(constraint
->option2
, constraint
->option2
+ 1);
1813 else if (cg
->ppd_conform
== PPD_CONFORM_STRICT
)
1815 cg
->ppd_status
= PPD_BAD_UI_CONSTRAINTS
;
1819 if (cg
->ppd_conform
== PPD_CONFORM_STRICT
&&
1820 constraint
->choice2
[0] == '*')
1822 cg
->ppd_status
= PPD_BAD_UI_CONSTRAINTS
;
1829 * Don't add this one as an attribute...
1832 _cupsStrFree(string
);
1835 else if (!strcmp(keyword
, "PaperDimension"))
1837 if ((size
= ppdPageSize(ppd
, name
)) == NULL
)
1838 size
= ppd_add_size(ppd
, name
);
1843 * Unable to add or find size!
1846 cg
->ppd_status
= PPD_ALLOC_ERROR
;
1851 size
->width
= (float)_cupsStrScand(string
, &sptr
, loc
);
1852 size
->length
= (float)_cupsStrScand(sptr
, NULL
, loc
);
1854 _cupsStrFree(string
);
1857 else if (!strcmp(keyword
, "ImageableArea"))
1859 if ((size
= ppdPageSize(ppd
, name
)) == NULL
)
1860 size
= ppd_add_size(ppd
, name
);
1865 * Unable to add or find size!
1868 cg
->ppd_status
= PPD_ALLOC_ERROR
;
1873 size
->left
= (float)_cupsStrScand(string
, &sptr
, loc
);
1874 size
->bottom
= (float)_cupsStrScand(sptr
, &sptr
, loc
);
1875 size
->right
= (float)_cupsStrScand(sptr
, &sptr
, loc
);
1876 size
->top
= (float)_cupsStrScand(sptr
, NULL
, loc
);
1878 _cupsStrFree(string
);
1881 else if (option
!= NULL
&&
1882 (mask
& (PPD_KEYWORD
| PPD_OPTION
| PPD_STRING
)) ==
1883 (PPD_KEYWORD
| PPD_OPTION
| PPD_STRING
) &&
1884 !strcmp(keyword
, option
->keyword
))
1886 DEBUG_printf(("2ppdOpen2: group=%p, subgroup=%p", group
, subgroup
));
1888 if (!strcmp(keyword
, "PageSize"))
1891 * Add a page size...
1894 if (ppdPageSize(ppd
, name
) == NULL
)
1895 ppd_add_size(ppd
, name
);
1899 * Add the option choice...
1902 if ((choice
= ppd_add_choice(option
, name
)) == NULL
)
1904 cg
->ppd_status
= PPD_ALLOC_ERROR
;
1910 cupsCharsetToUTF8((cups_utf8_t
*)choice
->text
, text
,
1911 sizeof(choice
->text
), encoding
);
1912 else if (!strcmp(name
, "True"))
1913 strcpy(choice
->text
, _("Yes"));
1914 else if (!strcmp(name
, "False"))
1915 strcpy(choice
->text
, _("No"));
1917 strlcpy(choice
->text
, name
, sizeof(choice
->text
));
1919 if (option
->section
== PPD_ORDER_JCL
)
1920 ppd_decode(string
); /* Decode quoted string */
1922 choice
->code
= string
;
1923 string
= NULL
; /* Don't add as an attribute below */
1927 * Add remaining lines with keywords and string values as attributes...
1931 (mask
& (PPD_KEYWORD
| PPD_STRING
)) == (PPD_KEYWORD
| PPD_STRING
))
1932 ppd_add_attr(ppd
, keyword
, name
, text
, string
);
1934 _cupsStrFree(string
);
1937 ppd_free(line
.buffer
);
1940 * Reset language preferences...
1943 cupsLangFree(language
);
1946 if (!cupsFileEOF(fp
))
1947 DEBUG_printf(("1ppdOpen2: Premature EOF at %lu...\n",
1948 (unsigned long)cupsFileTell(fp
)));
1951 if (cg
->ppd_status
!= PPD_OK
)
1954 * Had an error reading the PPD file, cannot continue!
1963 * Create the sorted options array and set the option back-pointer for
1964 * each choice and custom option...
1967 ppd
->options
= cupsArrayNew2((cups_array_func_t
)ppd_compare_options
, NULL
,
1968 (cups_ahash_func_t
)ppd_hash_option
,
1971 for (i
= ppd
->num_groups
, group
= ppd
->groups
;
1975 for (j
= group
->num_options
, option
= group
->options
;
1979 ppd_coption_t
*coption
; /* Custom option */
1982 cupsArrayAdd(ppd
->options
, option
);
1984 for (k
= 0; k
< option
->num_choices
; k
++)
1985 option
->choices
[k
].option
= option
;
1987 if ((coption
= ppdFindCustomOption(ppd
, option
->keyword
)) != NULL
)
1988 coption
->option
= option
;
1993 * Create an array to track the marked choices...
1996 ppd
->marked
= cupsArrayNew((cups_array_func_t
)ppd_compare_choices
, NULL
);
1999 * Return the PPD file structure...
2005 * Common exit point for errors to save code size...
2010 _cupsStrFree(string
);
2011 ppd_free(line
.buffer
);
2015 cupsLangFree(language
);
2022 * 'ppdOpenFd()' - Read a PPD file into memory.
2025 ppd_file_t
* /* O - PPD file record or @code NULL@ if the PPD file could not be opened. */
2026 ppdOpenFd(int fd
) /* I - File to read from */
2028 cups_file_t
*fp
; /* CUPS file pointer */
2029 ppd_file_t
*ppd
; /* PPD file record */
2030 _cups_globals_t
*cg
= _cupsGlobals();
2035 * Set the line number to 0...
2041 * Range check input...
2046 cg
->ppd_status
= PPD_NULL_FILE
;
2052 * Try to open the file and parse it...
2055 if ((fp
= cupsFileOpenFd(fd
, "r")) != NULL
)
2063 cg
->ppd_status
= PPD_FILE_OPEN_ERROR
;
2072 * 'ppdOpenFile()' - Read a PPD file into memory.
2075 ppd_file_t
* /* O - PPD file record or @code NULL@ if the PPD file could not be opened. */
2076 ppdOpenFile(const char *filename
) /* I - File to read from */
2078 cups_file_t
*fp
; /* File pointer */
2079 ppd_file_t
*ppd
; /* PPD file record */
2080 _cups_globals_t
*cg
= _cupsGlobals();
2085 * Set the line number to 0...
2091 * Range check input...
2094 if (filename
== NULL
)
2096 cg
->ppd_status
= PPD_NULL_FILE
;
2102 * Try to open the file and parse it...
2105 if ((fp
= cupsFileOpen(filename
, "r")) != NULL
)
2113 cg
->ppd_status
= PPD_FILE_OPEN_ERROR
;
2122 * 'ppdSetConformance()' - Set the conformance level for PPD files.
2124 * @since CUPS 1.1.20/Mac OS X 10.4@
2128 ppdSetConformance(ppd_conform_t c
) /* I - Conformance level */
2130 _cups_globals_t
*cg
= _cupsGlobals();
2134 cg
->ppd_conform
= c
;
2139 * 'ppd_add_attr()' - Add an attribute to the PPD data.
2142 static ppd_attr_t
* /* O - New attribute */
2143 ppd_add_attr(ppd_file_t
*ppd
, /* I - PPD file data */
2144 const char *name
, /* I - Attribute name */
2145 const char *spec
, /* I - Specifier string, if any */
2146 const char *text
, /* I - Text string, if any */
2147 const char *value
) /* I - Value of attribute */
2149 ppd_attr_t
**ptr
, /* New array */
2150 *temp
; /* New attribute */
2154 * Range check input...
2157 if (ppd
== NULL
|| name
== NULL
|| spec
== NULL
)
2161 * Create the array as needed...
2164 if (!ppd
->sorted_attrs
)
2165 ppd
->sorted_attrs
= cupsArrayNew((cups_array_func_t
)ppd_compare_attrs
,
2169 * Allocate memory for the new attribute...
2172 if (ppd
->num_attrs
== 0)
2173 ptr
= malloc(sizeof(ppd_attr_t
*));
2175 ptr
= realloc(ppd
->attrs
, (ppd
->num_attrs
+ 1) * sizeof(ppd_attr_t
*));
2181 ptr
+= ppd
->num_attrs
;
2183 if ((temp
= calloc(1, sizeof(ppd_attr_t
))) == NULL
)
2194 strlcpy(temp
->name
, name
, sizeof(temp
->name
));
2195 strlcpy(temp
->spec
, spec
, sizeof(temp
->spec
));
2196 strlcpy(temp
->text
, text
, sizeof(temp
->text
));
2197 temp
->value
= (char *)value
;
2200 * Add the attribute to the sorted array...
2203 cupsArrayAdd(ppd
->sorted_attrs
, temp
);
2206 * Return the attribute...
2214 * 'ppd_add_choice()' - Add a choice to an option.
2217 static ppd_choice_t
* /* O - Named choice */
2218 ppd_add_choice(ppd_option_t
*option
, /* I - Option */
2219 const char *name
) /* I - Name of choice */
2221 ppd_choice_t
*choice
; /* Choice */
2224 if (option
->num_choices
== 0)
2225 choice
= malloc(sizeof(ppd_choice_t
));
2227 choice
= realloc(option
->choices
,
2228 sizeof(ppd_choice_t
) * (option
->num_choices
+ 1));
2233 option
->choices
= choice
;
2234 choice
+= option
->num_choices
;
2235 option
->num_choices
++;
2237 memset(choice
, 0, sizeof(ppd_choice_t
));
2238 strlcpy(choice
->choice
, name
, sizeof(choice
->choice
));
2245 * 'ppd_add_size()' - Add a page size.
2248 static ppd_size_t
* /* O - Named size */
2249 ppd_add_size(ppd_file_t
*ppd
, /* I - PPD file */
2250 const char *name
) /* I - Name of size */
2252 ppd_size_t
*size
; /* Size */
2255 if (ppd
->num_sizes
== 0)
2256 size
= malloc(sizeof(ppd_size_t
));
2258 size
= realloc(ppd
->sizes
, sizeof(ppd_size_t
) * (ppd
->num_sizes
+ 1));
2264 size
+= ppd
->num_sizes
;
2267 memset(size
, 0, sizeof(ppd_size_t
));
2268 strlcpy(size
->name
, name
, sizeof(size
->name
));
2275 * 'ppd_compare_attrs()' - Compare two attributes.
2278 static int /* O - Result of comparison */
2279 ppd_compare_attrs(ppd_attr_t
*a
, /* I - First attribute */
2280 ppd_attr_t
*b
) /* I - Second attribute */
2282 return (strcasecmp(a
->name
, b
->name
));
2287 * 'ppd_compare_choices()' - Compare two choices...
2290 static int /* O - Result of comparison */
2291 ppd_compare_choices(ppd_choice_t
*a
, /* I - First choice */
2292 ppd_choice_t
*b
) /* I - Second choice */
2294 return (strcmp(a
->option
->keyword
, b
->option
->keyword
));
2299 * 'ppd_compare_coptions()' - Compare two custom options.
2302 static int /* O - Result of comparison */
2303 ppd_compare_coptions(ppd_coption_t
*a
, /* I - First option */
2304 ppd_coption_t
*b
) /* I - Second option */
2306 return (strcasecmp(a
->keyword
, b
->keyword
));
2311 * 'ppd_compare_cparams()' - Compare two custom parameters.
2314 static int /* O - Result of comparison */
2315 ppd_compare_cparams(ppd_cparam_t
*a
, /* I - First parameter */
2316 ppd_cparam_t
*b
) /* I - Second parameter */
2318 return (strcasecmp(a
->name
, b
->name
));
2323 * 'ppd_compare_options()' - Compare two options.
2326 static int /* O - Result of comparison */
2327 ppd_compare_options(ppd_option_t
*a
, /* I - First option */
2328 ppd_option_t
*b
) /* I - Second option */
2330 return (strcasecmp(a
->keyword
, b
->keyword
));
2335 * 'ppd_decode()' - Decode a string value...
2338 static int /* O - Length of decoded string */
2339 ppd_decode(char *string
) /* I - String to decode */
2341 char *inptr
, /* Input pointer */
2342 *outptr
; /* Output pointer */
2348 while (*inptr
!= '\0')
2349 if (*inptr
== '<' && isxdigit(inptr
[1] & 255))
2352 * Convert hex to 8-bit values...
2356 while (isxdigit(*inptr
& 255))
2358 if (isalpha(*inptr
))
2359 *outptr
= (tolower(*inptr
) - 'a' + 10) << 4;
2361 *outptr
= (*inptr
- '0') << 4;
2365 if (!isxdigit(*inptr
& 255))
2368 if (isalpha(*inptr
))
2369 *outptr
|= tolower(*inptr
) - 'a' + 10;
2371 *outptr
|= *inptr
- '0';
2377 while (*inptr
!= '>' && *inptr
!= '\0')
2379 while (*inptr
== '>')
2383 *outptr
++ = *inptr
++;
2387 return ((int)(outptr
- string
));
2392 * 'ppd_free_group()' - Free a single UI group.
2396 ppd_free_group(ppd_group_t
*group
) /* I - Group to free */
2398 int i
; /* Looping var */
2399 ppd_option_t
*option
; /* Current option */
2400 ppd_group_t
*subgroup
; /* Current sub-group */
2403 if (group
->num_options
> 0)
2405 for (i
= group
->num_options
, option
= group
->options
;
2408 ppd_free_option(option
);
2410 ppd_free(group
->options
);
2413 if (group
->num_subgroups
> 0)
2415 for (i
= group
->num_subgroups
, subgroup
= group
->subgroups
;
2418 ppd_free_group(subgroup
);
2420 ppd_free(group
->subgroups
);
2426 * 'ppd_free_option()' - Free a single option.
2430 ppd_free_option(ppd_option_t
*option
) /* I - Option to free */
2432 int i
; /* Looping var */
2433 ppd_choice_t
*choice
; /* Current choice */
2436 if (option
->num_choices
> 0)
2438 for (i
= option
->num_choices
, choice
= option
->choices
;
2442 _cupsStrFree(choice
->code
);
2445 ppd_free(option
->choices
);
2451 * 'ppd_get_coption()' - Get a custom option record.
2454 static ppd_coption_t
* /* O - Custom option... */
2455 ppd_get_coption(ppd_file_t
*ppd
, /* I - PPD file */
2456 const char *name
) /* I - Name of option */
2458 ppd_coption_t
*copt
; /* New custom option */
2462 * See if the option already exists...
2465 if ((copt
= ppdFindCustomOption(ppd
, name
)) != NULL
)
2469 * Not found, so create the custom option record...
2472 if ((copt
= calloc(1, sizeof(ppd_coption_t
))) == NULL
)
2475 strlcpy(copt
->keyword
, name
, sizeof(copt
->keyword
));
2477 copt
->params
= cupsArrayNew((cups_array_func_t
)ppd_compare_cparams
, NULL
);
2479 cupsArrayAdd(ppd
->coptions
, copt
);
2482 * Return the new record...
2490 * 'ppd_get_cparam()' - Get a custom parameter record.
2493 static ppd_cparam_t
* /* O - Extended option... */
2494 ppd_get_cparam(ppd_coption_t
*opt
, /* I - PPD file */
2495 const char *param
, /* I - Name of parameter */
2496 const char *text
) /* I - Human-readable text */
2498 ppd_cparam_t
*cparam
; /* New custom parameter */
2502 * See if the parameter already exists...
2505 if ((cparam
= ppdFindCustomParam(opt
, param
)) != NULL
)
2509 * Not found, so create the custom parameter record...
2512 if ((cparam
= calloc(1, sizeof(ppd_cparam_t
))) == NULL
)
2515 strlcpy(cparam
->name
, param
, sizeof(cparam
->name
));
2516 strlcpy(cparam
->text
, text
[0] ? text
: param
, sizeof(cparam
->text
));
2519 * Add this record to the array...
2522 cupsArrayAdd(opt
->params
, cparam
);
2525 * Return the new record...
2533 * 'ppd_get_group()' - Find or create the named group as needed.
2536 static ppd_group_t
* /* O - Named group */
2537 ppd_get_group(ppd_file_t
*ppd
, /* I - PPD file */
2538 const char *name
, /* I - Name of group */
2539 const char *text
, /* I - Text for group */
2540 _cups_globals_t
*cg
, /* I - Global data */
2541 cups_encoding_t encoding
) /* I - Encoding of text */
2543 int i
; /* Looping var */
2544 ppd_group_t
*group
; /* Group */
2547 DEBUG_printf(("7ppd_get_group(ppd=%p, name=\"%s\", text=\"%s\", cg=%p)",
2548 ppd
, name
, text
, cg
));
2550 for (i
= ppd
->num_groups
, group
= ppd
->groups
; i
> 0; i
--, group
++)
2551 if (!strcmp(group
->name
, name
))
2556 DEBUG_printf(("8ppd_get_group: Adding group %s...", name
));
2558 if (cg
->ppd_conform
== PPD_CONFORM_STRICT
&& strlen(text
) >= sizeof(group
->text
))
2560 cg
->ppd_status
= PPD_ILLEGAL_TRANSLATION
;
2565 if (ppd
->num_groups
== 0)
2566 group
= malloc(sizeof(ppd_group_t
));
2568 group
= realloc(ppd
->groups
,
2569 (ppd
->num_groups
+ 1) * sizeof(ppd_group_t
));
2573 cg
->ppd_status
= PPD_ALLOC_ERROR
;
2578 ppd
->groups
= group
;
2579 group
+= ppd
->num_groups
;
2582 memset(group
, 0, sizeof(ppd_group_t
));
2583 strlcpy(group
->name
, name
, sizeof(group
->name
));
2585 cupsCharsetToUTF8((cups_utf8_t
*)group
->text
, text
,
2586 sizeof(group
->text
), encoding
);
2594 * 'ppd_get_option()' - Find or create the named option as needed.
2597 static ppd_option_t
* /* O - Named option */
2598 ppd_get_option(ppd_group_t
*group
, /* I - Group */
2599 const char *name
) /* I - Name of option */
2601 int i
; /* Looping var */
2602 ppd_option_t
*option
; /* Option */
2605 DEBUG_printf(("7ppd_get_option(group=%p(\"%s\"), name=\"%s\")",
2606 group
, group
->name
, name
));
2608 for (i
= group
->num_options
, option
= group
->options
; i
> 0; i
--, option
++)
2609 if (!strcmp(option
->keyword
, name
))
2614 if (group
->num_options
== 0)
2615 option
= malloc(sizeof(ppd_option_t
));
2617 option
= realloc(group
->options
,
2618 (group
->num_options
+ 1) * sizeof(ppd_option_t
));
2623 group
->options
= option
;
2624 option
+= group
->num_options
;
2625 group
->num_options
++;
2627 memset(option
, 0, sizeof(ppd_option_t
));
2628 strlcpy(option
->keyword
, name
, sizeof(option
->keyword
));
2636 * 'ppd_hash_option()' - Generate a hash of the option name...
2639 static int /* O - Hash index */
2640 ppd_hash_option(ppd_option_t
*option
) /* I - Option */
2642 int hash
= 0; /* Hash index */
2643 const char *k
; /* Pointer into keyword */
2646 for (hash
= option
->keyword
[0], k
= option
->keyword
+ 1; *k
;)
2647 hash
= 33 * hash
+ *k
++;
2649 return (hash
& 511);
2654 * 'ppd_read()' - Read a line from a PPD file, skipping comment lines as
2658 static int /* O - Bitmask of fields read */
2659 ppd_read(cups_file_t
*fp
, /* I - File to read from */
2660 _ppd_line_t
*line
, /* I - Line buffer */
2661 char *keyword
, /* O - Keyword from line */
2662 char *option
, /* O - Option from line */
2663 char *text
, /* O - Human-readable text from line */
2664 char **string
, /* O - Code/string data */
2665 int ignoreblank
, /* I - Ignore blank lines? */
2666 _cups_globals_t
*cg
) /* I - Global data */
2668 int ch
, /* Character from file */
2669 col
, /* Column in line */
2670 colon
, /* Colon seen? */
2671 endquote
, /* Waiting for an end quote */
2672 mask
, /* Mask to be returned */
2673 startline
, /* Start line */
2674 textlen
; /* Length of text */
2675 char *keyptr
, /* Keyword pointer */
2676 *optptr
, /* Option pointer */
2677 *textptr
, /* Text pointer */
2678 *strptr
, /* Pointer into string */
2679 *lineptr
; /* Current position in line buffer */
2683 * Now loop until we have a valid line...
2688 startline
= cg
->ppd_line
+ 1;
2692 line
->bufsize
= 1024;
2693 line
->buffer
= malloc(1024);
2705 lineptr
= line
->buffer
;
2709 while ((ch
= cupsFileGetChar(fp
)) != EOF
)
2711 if (lineptr
>= (line
->buffer
+ line
->bufsize
- 1))
2714 * Expand the line buffer...
2717 char *temp
; /* Temporary line pointer */
2720 line
->bufsize
+= 1024;
2721 if (line
->bufsize
> 262144)
2724 * Don't allow lines longer than 256k!
2727 cg
->ppd_line
= startline
;
2728 cg
->ppd_status
= PPD_LINE_TOO_LONG
;
2733 temp
= realloc(line
->buffer
, line
->bufsize
);
2736 cg
->ppd_line
= startline
;
2737 cg
->ppd_status
= PPD_LINE_TOO_LONG
;
2742 lineptr
= temp
+ (lineptr
- line
->buffer
);
2743 line
->buffer
= temp
;
2746 if (ch
== '\r' || ch
== '\n')
2749 * Line feed or carriage return...
2758 * Check for a trailing line feed...
2761 if ((ch
= cupsFilePeekChar(fp
)) == EOF
)
2768 cupsFileGetChar(fp
);
2771 if (lineptr
== line
->buffer
&& ignoreblank
)
2772 continue; /* Skip blank lines */
2776 if (!endquote
) /* Continue for multi-line text */
2781 else if (ch
< ' ' && ch
!= '\t' && cg
->ppd_conform
== PPD_CONFORM_STRICT
)
2784 * Other control characters...
2787 cg
->ppd_line
= startline
;
2788 cg
->ppd_status
= PPD_ILLEGAL_CHARACTER
;
2792 else if (ch
!= 0x1a)
2795 * Any other character...
2801 if (col
> (PPD_MAX_LINE
- 1))
2804 * Line is too long...
2807 cg
->ppd_line
= startline
;
2808 cg
->ppd_status
= PPD_LINE_TOO_LONG
;
2813 if (ch
== ':' && strncmp(line
->buffer
, "*%", 2) != 0)
2816 if (ch
== '\"' && colon
)
2817 endquote
= !endquote
;
2824 * Didn't finish this quoted string...
2827 while ((ch
= cupsFileGetChar(fp
)) != EOF
)
2830 else if (ch
== '\r' || ch
== '\n')
2838 * Check for a trailing line feed...
2841 if ((ch
= cupsFilePeekChar(fp
)) == EOF
)
2844 cupsFileGetChar(fp
);
2847 else if (ch
< ' ' && ch
!= '\t' && cg
->ppd_conform
== PPD_CONFORM_STRICT
)
2850 * Other control characters...
2853 cg
->ppd_line
= startline
;
2854 cg
->ppd_status
= PPD_ILLEGAL_CHARACTER
;
2858 else if (ch
!= 0x1a)
2862 if (col
> (PPD_MAX_LINE
- 1))
2865 * Line is too long...
2868 cg
->ppd_line
= startline
;
2869 cg
->ppd_status
= PPD_LINE_TOO_LONG
;
2879 * Didn't finish this line...
2882 while ((ch
= cupsFileGetChar(fp
)) != EOF
)
2883 if (ch
== '\r' || ch
== '\n')
2886 * Line feed or carriage return...
2895 * Check for a trailing line feed...
2898 if ((ch
= cupsFilePeekChar(fp
)) == EOF
)
2901 cupsFileGetChar(fp
);
2906 else if (ch
< ' ' && ch
!= '\t' && cg
->ppd_conform
== PPD_CONFORM_STRICT
)
2909 * Other control characters...
2912 cg
->ppd_line
= startline
;
2913 cg
->ppd_status
= PPD_ILLEGAL_CHARACTER
;
2917 else if (ch
!= 0x1a)
2921 if (col
> (PPD_MAX_LINE
- 1))
2924 * Line is too long...
2927 cg
->ppd_line
= startline
;
2928 cg
->ppd_status
= PPD_LINE_TOO_LONG
;
2935 if (lineptr
> line
->buffer
&& lineptr
[-1] == '\n')
2940 DEBUG_printf(("9ppd_read: LINE=\"%s\"", line
->buffer
));
2943 * The dynamically created PPDs for older style Mac OS X
2944 * drivers include a large blob of data inserted as comments
2945 * at the end of the file. As an optimization we can stop
2946 * reading the PPD when we get to the start of this data.
2949 if (!strcmp(line
->buffer
, "*%APLWORKSET START"))
2952 if (ch
== EOF
&& lineptr
== line
->buffer
)
2960 lineptr
= line
->buffer
+ 1;
2967 if ((!line
->buffer
[0] || /* Blank line */
2968 !strncmp(line
->buffer
, "*%", 2) || /* Comment line */
2969 !strcmp(line
->buffer
, "*End")) && /* End of multi-line string */
2970 ignoreblank
) /* Ignore these? */
2972 startline
= cg
->ppd_line
+ 1;
2976 if (!strcmp(line
->buffer
, "*")) /* (Bad) comment line */
2978 if (cg
->ppd_conform
== PPD_CONFORM_RELAXED
)
2980 startline
= cg
->ppd_line
+ 1;
2985 cg
->ppd_line
= startline
;
2986 cg
->ppd_status
= PPD_ILLEGAL_MAIN_KEYWORD
;
2992 if (line
->buffer
[0] != '*') /* All lines start with an asterisk */
2995 * Allow lines consisting of just whitespace...
2998 for (lineptr
= line
->buffer
; *lineptr
; lineptr
++)
2999 if (!isspace(*lineptr
& 255))
3004 cg
->ppd_status
= PPD_MISSING_ASTERISK
;
3007 else if (ignoreblank
)
3019 while (*lineptr
!= '\0' && *lineptr
!= ':' && !isspace(*lineptr
& 255))
3021 if (*lineptr
<= ' ' || *lineptr
> 126 || *lineptr
== '/' ||
3022 (keyptr
- keyword
) >= (PPD_MAX_NAME
- 1))
3024 cg
->ppd_status
= PPD_ILLEGAL_MAIN_KEYWORD
;
3028 *keyptr
++ = *lineptr
++;
3033 if (!strcmp(keyword
, "End"))
3036 mask
|= PPD_KEYWORD
;
3038 if (isspace(*lineptr
& 255))
3041 * Get an option name...
3044 while (isspace(*lineptr
& 255))
3049 while (*lineptr
!= '\0' && !isspace(*lineptr
& 255) && *lineptr
!= ':' &&
3052 if (*lineptr
<= ' ' || *lineptr
> 126 ||
3053 (optptr
- option
) >= (PPD_MAX_NAME
- 1))
3055 cg
->ppd_status
= PPD_ILLEGAL_OPTION_KEYWORD
;
3059 *optptr
++ = *lineptr
++;
3064 if (isspace(*lineptr
& 255) && cg
->ppd_conform
== PPD_CONFORM_STRICT
)
3066 cg
->ppd_status
= PPD_ILLEGAL_WHITESPACE
;
3070 while (isspace(*lineptr
& 255))
3075 if (*lineptr
== '/')
3078 * Get human-readable text...
3085 while (*lineptr
!= '\0' && *lineptr
!= '\n' && *lineptr
!= ':')
3087 if (((unsigned char)*lineptr
< ' ' && *lineptr
!= '\t') ||
3088 (textptr
- text
) >= (PPD_MAX_LINE
- 1))
3090 cg
->ppd_status
= PPD_ILLEGAL_TRANSLATION
;
3094 *textptr
++ = *lineptr
++;
3098 textlen
= ppd_decode(text
);
3100 if (textlen
> PPD_MAX_TEXT
&& cg
->ppd_conform
== PPD_CONFORM_STRICT
)
3102 cg
->ppd_status
= PPD_ILLEGAL_TRANSLATION
;
3110 if (isspace(*lineptr
& 255) && cg
->ppd_conform
== PPD_CONFORM_STRICT
)
3112 cg
->ppd_status
= PPD_ILLEGAL_WHITESPACE
;
3116 while (isspace(*lineptr
& 255))
3119 if (*lineptr
== ':')
3122 * Get string after triming leading and trailing whitespace...
3126 while (isspace(*lineptr
& 255))
3129 strptr
= lineptr
+ strlen(lineptr
) - 1;
3130 while (strptr
>= lineptr
&& isspace(*strptr
& 255))
3133 if (*strptr
== '\"')
3136 * Quoted string by itself, remove quotes...
3143 *string
= _cupsStrAlloc(lineptr
);
3155 * End of "$Id: ppd.c 7906 2008-09-03 20:19:43Z mike $".