2 * "$Id: ppd.c 7906 2008-09-03 20:19:43Z mike $"
4 * PPD file routines for CUPS.
6 * Copyright 2007-2011 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_options() - Compare two options.
45 * ppd_decode() - Decode a string value...
46 * ppd_free_group() - Free a single UI group.
47 * ppd_free_option() - Free a single option.
48 * ppd_get_coption() - Get a custom option record.
49 * ppd_get_cparam() - Get a custom parameter record.
50 * ppd_get_group() - Find or create the named group as needed.
51 * ppd_get_option() - Find or create the named option as needed.
52 * ppd_hash_option() - Generate a hash of the option name...
53 * ppd_read() - Read a line from a PPD file, skipping comment
58 * Include necessary headers.
61 #include "cups-private.h"
62 #include "ppd-private.h"
69 #if defined(WIN32) || defined(__EMX__)
70 # define READ_BINARY "rb" /* Open a binary file for reading */
71 # define WRITE_BINARY "wb" /* Open a binary file for writing */
73 # define READ_BINARY "r" /* Open a binary file for reading */
74 # define WRITE_BINARY "w" /* Open a binary file for writing */
75 #endif /* WIN32 || __EMX__ */
77 #define ppd_free(p) if (p) free(p) /* Safe free macro */
79 #define PPD_KEYWORD 1 /* Line contained a keyword */
80 #define PPD_OPTION 2 /* Line contained an option name */
81 #define PPD_TEXT 4 /* Line contained human-readable text */
82 #define PPD_STRING 8 /* Line contained a string or code */
84 #define PPD_HASHSIZE 512 /* Size of hash */
88 * Line buffer structure...
91 typedef struct _ppd_line_s
93 char *buffer
; /* Pointer to buffer */
94 size_t bufsize
; /* Size of the buffer */
102 static ppd_attr_t
*ppd_add_attr(ppd_file_t
*ppd
, const char *name
,
103 const char *spec
, const char *text
,
105 static ppd_choice_t
*ppd_add_choice(ppd_option_t
*option
, const char *name
);
106 static ppd_size_t
*ppd_add_size(ppd_file_t
*ppd
, const char *name
);
107 static int ppd_compare_attrs(ppd_attr_t
*a
, ppd_attr_t
*b
);
108 static int ppd_compare_choices(ppd_choice_t
*a
, ppd_choice_t
*b
);
109 static int ppd_compare_coptions(ppd_coption_t
*a
,
111 static int ppd_compare_options(ppd_option_t
*a
, ppd_option_t
*b
);
112 static int ppd_decode(char *string
);
113 static void ppd_free_group(ppd_group_t
*group
);
114 static void ppd_free_option(ppd_option_t
*option
);
115 static ppd_coption_t
*ppd_get_coption(ppd_file_t
*ppd
, const char *name
);
116 static ppd_cparam_t
*ppd_get_cparam(ppd_coption_t
*opt
,
119 static ppd_group_t
*ppd_get_group(ppd_file_t
*ppd
, const char *name
,
120 const char *text
, _cups_globals_t
*cg
,
121 cups_encoding_t encoding
);
122 static ppd_option_t
*ppd_get_option(ppd_group_t
*group
, const char *name
);
123 static int ppd_hash_option(ppd_option_t
*option
);
124 static int ppd_read(cups_file_t
*fp
, _ppd_line_t
*line
,
125 char *keyword
, char *option
, char *text
,
126 char **string
, int ignoreblank
,
127 _cups_globals_t
*cg
);
131 * 'ppdClose()' - Free all memory used by the PPD file.
135 ppdClose(ppd_file_t
*ppd
) /* I - PPD file record */
137 int i
; /* Looping var */
138 ppd_emul_t
*emul
; /* Current emulation */
139 ppd_group_t
*group
; /* Current group */
140 char **font
; /* Current font */
141 char **filter
; /* Current filter */
142 ppd_attr_t
**attr
; /* Current attribute */
143 ppd_coption_t
*coption
; /* Current custom option */
144 ppd_cparam_t
*cparam
; /* Current custom parameter */
148 * Range check arguments...
155 * Free all strings at the top level...
158 _cupsStrFree(ppd
->lang_encoding
);
159 _cupsStrFree(ppd
->nickname
);
162 _cupsStrFree(ppd
->jcl_begin
);
163 _cupsStrFree(ppd
->jcl_end
);
164 _cupsStrFree(ppd
->jcl_ps
);
167 * Free any emulations...
170 if (ppd
->num_emulations
> 0)
172 for (i
= ppd
->num_emulations
, emul
= ppd
->emulations
; i
> 0; i
--, emul
++)
174 _cupsStrFree(emul
->start
);
175 _cupsStrFree(emul
->stop
);
178 ppd_free(ppd
->emulations
);
182 * Free any UI groups, subgroups, and options...
185 if (ppd
->num_groups
> 0)
187 for (i
= ppd
->num_groups
, group
= ppd
->groups
; i
> 0; i
--, group
++)
188 ppd_free_group(group
);
190 ppd_free(ppd
->groups
);
193 cupsArrayDelete(ppd
->options
);
194 cupsArrayDelete(ppd
->marked
);
197 * Free any page sizes...
200 if (ppd
->num_sizes
> 0)
201 ppd_free(ppd
->sizes
);
204 * Free any constraints...
207 if (ppd
->num_consts
> 0)
208 ppd_free(ppd
->consts
);
211 * Free any filters...
214 if (ppd
->num_filters
> 0)
216 for (i
= ppd
->num_filters
, filter
= ppd
->filters
; i
> 0; i
--, filter
++)
217 _cupsStrFree(*filter
);
219 ppd_free(ppd
->filters
);
226 if (ppd
->num_fonts
> 0)
228 for (i
= ppd
->num_fonts
, font
= ppd
->fonts
; i
> 0; i
--, font
++)
231 ppd_free(ppd
->fonts
);
235 * Free any profiles...
238 if (ppd
->num_profiles
> 0)
239 ppd_free(ppd
->profiles
);
242 * Free any attributes...
245 if (ppd
->num_attrs
> 0)
247 for (i
= ppd
->num_attrs
, attr
= ppd
->attrs
; i
> 0; i
--, attr
++)
249 _cupsStrFree((*attr
)->value
);
253 ppd_free(ppd
->attrs
);
256 cupsArrayDelete(ppd
->sorted_attrs
);
259 * Free custom options...
262 for (coption
= (ppd_coption_t
*)cupsArrayFirst(ppd
->coptions
);
264 coption
= (ppd_coption_t
*)cupsArrayNext(ppd
->coptions
))
266 for (cparam
= (ppd_cparam_t
*)cupsArrayFirst(coption
->params
);
268 cparam
= (ppd_cparam_t
*)cupsArrayNext(coption
->params
))
270 switch (cparam
->type
)
272 case PPD_CUSTOM_PASSCODE
:
273 case PPD_CUSTOM_PASSWORD
:
274 case PPD_CUSTOM_STRING
:
275 _cupsStrFree(cparam
->current
.custom_string
);
285 cupsArrayDelete(coption
->params
);
290 cupsArrayDelete(ppd
->coptions
);
293 * Free constraints...
296 if (ppd
->cups_uiconstraints
)
298 _ppd_cups_uiconsts_t
*consts
; /* Current constraints */
301 for (consts
= (_ppd_cups_uiconsts_t
*)cupsArrayFirst(ppd
->cups_uiconstraints
);
303 consts
= (_ppd_cups_uiconsts_t
*)cupsArrayNext(ppd
->cups_uiconstraints
))
305 free(consts
->constraints
);
309 cupsArrayDelete(ppd
->cups_uiconstraints
);
313 * Free any PPD cache/mapping data...
317 _ppdCacheDestroy(ppd
->cache
);
320 * Free the whole record...
328 * 'ppdErrorString()' - Returns the text assocated with a status.
330 * @since CUPS 1.1.19/Mac OS X 10.3@
333 const char * /* O - Status string */
334 ppdErrorString(ppd_status_t status
) /* I - PPD status */
336 static const char * const messages
[] =/* Status messages */
339 _("Unable to open PPD file"),
340 _("NULL PPD file pointer"),
341 _("Memory allocation error"),
342 _("Missing PPD-Adobe-4.x header"),
343 _("Missing value string"),
346 _("OpenGroup without a CloseGroup first"),
347 _("Bad OpenUI/JCLOpenUI"),
348 _("OpenUI/JCLOpenUI without a CloseUI/JCLCloseUI first"),
349 _("Bad OrderDependency"),
350 _("Bad UIConstraints"),
351 _("Missing asterisk in column 1"),
352 _("Line longer than the maximum allowed (255 characters)"),
353 _("Illegal control character"),
354 _("Illegal main keyword string"),
355 _("Illegal option keyword string"),
356 _("Illegal translation string"),
357 _("Illegal whitespace character"),
358 _("Bad custom parameter"),
359 _("Missing option keyword"),
360 _("Bad value string"),
361 _("Missing CloseGroup")
365 if (status
< PPD_OK
|| status
>= PPD_MAX_STATUS
)
366 return (_cupsLangString(cupsLangDefault(), _("Unknown")));
368 return (_cupsLangString(cupsLangDefault(), messages
[status
]));
373 * '_ppdGetEncoding()' - Get the CUPS encoding value for the given
377 cups_encoding_t
/* O - CUPS encoding value */
378 _ppdGetEncoding(const char *name
) /* I - LanguageEncoding string */
380 if (!_cups_strcasecmp(name
, "ISOLatin1"))
381 return (CUPS_ISO8859_1
);
382 else if (!_cups_strcasecmp(name
, "ISOLatin2"))
383 return (CUPS_ISO8859_2
);
384 else if (!_cups_strcasecmp(name
, "ISOLatin5"))
385 return (CUPS_ISO8859_5
);
386 else if (!_cups_strcasecmp(name
, "JIS83-RKSJ"))
387 return (CUPS_JIS_X0213
);
388 else if (!_cups_strcasecmp(name
, "MacStandard"))
389 return (CUPS_MAC_ROMAN
);
390 else if (!_cups_strcasecmp(name
, "WindowsANSI"))
391 return (CUPS_WINDOWS_1252
);
398 * 'ppdLastError()' - Return the status from the last ppdOpen*().
400 * @since CUPS 1.1.19/Mac OS X 10.3@
403 ppd_status_t
/* O - Status code */
404 ppdLastError(int *line
) /* O - Line number */
406 _cups_globals_t
*cg
= _cupsGlobals();
411 *line
= cg
->ppd_line
;
413 return (cg
->ppd_status
);
418 * 'ppdOpen()' - Read a PPD file into memory.
421 ppd_file_t
* /* O - PPD file record */
422 ppdOpen(FILE *fp
) /* I - File to read from */
424 ppd_file_t
*ppd
; /* PPD file record */
425 cups_file_t
*cf
; /* CUPS file */
429 * Reopen the stdio file as a CUPS file...
432 if ((cf
= cupsFileOpenFd(fileno(fp
), "r")) == NULL
)
436 * Load the PPD file using the newer API...
442 * Close the CUPS file and return the PPD...
452 * 'ppdOpen2()' - Read a PPD file into memory.
454 * @since CUPS 1.2/Mac OS X 10.5@
457 ppd_file_t
* /* O - PPD file record or @code NULL@ if the PPD file could not be opened. */
458 ppdOpen2(cups_file_t
*fp
) /* I - File to read from */
460 int i
, j
, k
; /* Looping vars */
461 int count
; /* Temporary count */
462 _ppd_line_t line
; /* Line buffer */
463 ppd_file_t
*ppd
; /* PPD file record */
464 ppd_group_t
*group
, /* Current group */
465 *subgroup
; /* Current sub-group */
466 ppd_option_t
*option
; /* Current option */
467 ppd_choice_t
*choice
; /* Current choice */
468 ppd_const_t
*constraint
; /* Current constraint */
469 ppd_size_t
*size
; /* Current page size */
470 int mask
; /* Line data mask */
471 char keyword
[PPD_MAX_NAME
],
472 /* Keyword from file */
474 /* Option from file */
476 /* Human-readable text from file */
477 *string
, /* Code/text from file */
478 *sptr
, /* Pointer into string */
479 *nameptr
, /* Pointer into name */
480 *temp
, /* Temporary string pointer */
481 **tempfonts
; /* Temporary fonts pointer */
482 float order
; /* Order dependency number */
483 ppd_section_t section
; /* Order dependency section */
484 ppd_profile_t
*profile
; /* Pointer to color profile */
485 char **filter
; /* Pointer to filter */
486 struct lconv
*loc
; /* Locale data */
487 int ui_keyword
; /* Is this line a UI keyword? */
488 cups_encoding_t encoding
; /* Encoding of PPD file */
489 _cups_globals_t
*cg
= _cupsGlobals();
491 char custom_name
[PPD_MAX_NAME
];
492 /* CustomFoo attribute name */
493 ppd_attr_t
*custom_attr
; /* CustomFoo attribute */
494 static const char * const ui_keywords
[] =
496 #ifdef CUPS_USE_FULL_UI_KEYWORDS_LIST
498 * Adobe defines some 41 keywords as "UI", meaning that they are
499 * user interface elements and that they should be treated as such
500 * even if the PPD creator doesn't use Open/CloseUI around them.
502 * Since this can cause previously invisible options to appear and
503 * confuse users, the default is to only treat the PageSize and
504 * PageRegion keywords this way.
506 /* Boolean keywords */
516 /* PickOne keywords */
529 "JCLFrameBufferSize",
550 #else /* !CUPS_USE_FULL_UI_KEYWORDS_LIST */
553 #endif /* CUPS_USE_FULL_UI_KEYWORDS_LIST */
557 DEBUG_printf(("ppdOpen2(fp=%p)", fp
));
560 * Default to "OK" status...
563 cg
->ppd_status
= PPD_OK
;
567 * Range check input...
572 cg
->ppd_status
= PPD_NULL_FILE
;
577 * Grab the first line and make sure it reads '*PPD-Adobe: "major.minor"'...
583 mask
= ppd_read(fp
, &line
, keyword
, name
, text
, &string
, 0, cg
);
585 DEBUG_printf(("2ppdOpen2: mask=%x, keyword=\"%s\"...", mask
, keyword
));
588 strcmp(keyword
, "PPD-Adobe") ||
589 string
== NULL
|| string
[0] != '4')
592 * Either this is not a PPD file, or it is not a 4.x PPD file.
595 if (cg
->ppd_status
== PPD_OK
)
596 cg
->ppd_status
= PPD_MISSING_PPDADOBE4
;
598 _cupsStrFree(string
);
599 ppd_free(line
.buffer
);
604 DEBUG_printf(("2ppdOpen2: keyword=%s, string=%p", keyword
, string
));
606 _cupsStrFree(string
);
609 * Allocate memory for the PPD file record...
612 if ((ppd
= calloc(1, sizeof(ppd_file_t
))) == NULL
)
614 cg
->ppd_status
= PPD_ALLOC_ERROR
;
616 _cupsStrFree(string
);
617 ppd_free(line
.buffer
);
622 ppd
->language_level
= 2;
623 ppd
->color_device
= 0;
624 ppd
->colorspace
= PPD_CS_N
;
625 ppd
->landscape
= -90;
626 ppd
->coptions
= cupsArrayNew((cups_array_func_t
)ppd_compare_coptions
,
630 * Read lines from the PPD file and add them to the file record...
638 encoding
= CUPS_ISO8859_1
;
641 while ((mask
= ppd_read(fp
, &line
, keyword
, name
, text
, &string
, 1, cg
)) != 0)
643 DEBUG_printf(("2ppdOpen2: mask=%x, keyword=\"%s\", name=\"%s\", "
644 "text=\"%s\", string=%d chars...", mask
, keyword
, name
, text
,
645 string
? (int)strlen(string
) : 0));
647 if (strncmp(keyword
, "Default", 7) && !string
&&
648 cg
->ppd_conform
!= PPD_CONFORM_RELAXED
)
651 * Need a string value!
654 cg
->ppd_status
= PPD_MISSING_VALUE
;
662 * Certain main keywords (as defined by the PPD spec) may be used
663 * without the usual OpenUI/CloseUI stuff. Presumably this is just
664 * so that Adobe wouldn't completely break compatibility with PPD
665 * files prior to v4.0 of the spec, but it is hopelessly
666 * inconsistent... Catch these main keywords and automatically
667 * create the corresponding option, as needed...
673 * Previous line was a UI keyword...
680 if (option
== NULL
&&
681 (mask
& (PPD_KEYWORD
| PPD_OPTION
| PPD_STRING
)) ==
682 (PPD_KEYWORD
| PPD_OPTION
| PPD_STRING
))
684 for (i
= 0; i
< (int)(sizeof(ui_keywords
) / sizeof(ui_keywords
[0])); i
++)
685 if (!strcmp(keyword
, ui_keywords
[i
]))
688 if (i
< (int)(sizeof(ui_keywords
) / sizeof(ui_keywords
[0])))
691 * Create the option in the appropriate group...
696 DEBUG_printf(("2ppdOpen2: FOUND ADOBE UI KEYWORD %s WITHOUT OPENUI!",
701 if ((group
= ppd_get_group(ppd
, "General", _("General"), cg
,
705 DEBUG_printf(("2ppdOpen2: Adding to group %s...", group
->text
));
706 option
= ppd_get_option(group
, keyword
);
710 option
= ppd_get_option(group
, keyword
);
714 cg
->ppd_status
= PPD_ALLOC_ERROR
;
720 * Now fill in the initial information for the option...
723 if (!strncmp(keyword
, "JCL", 3))
724 option
->section
= PPD_ORDER_JCL
;
726 option
->section
= PPD_ORDER_ANY
;
728 option
->order
= 10.0f
;
731 option
->ui
= PPD_UI_BOOLEAN
;
733 option
->ui
= PPD_UI_PICKONE
;
735 for (j
= 0; j
< ppd
->num_attrs
; j
++)
736 if (!strncmp(ppd
->attrs
[j
]->name
, "Default", 7) &&
737 !strcmp(ppd
->attrs
[j
]->name
+ 7, keyword
) &&
738 ppd
->attrs
[j
]->value
)
740 DEBUG_printf(("2ppdOpen2: Setting Default%s to %s via attribute...",
741 option
->keyword
, ppd
->attrs
[j
]->value
));
742 strlcpy(option
->defchoice
, ppd
->attrs
[j
]->value
,
743 sizeof(option
->defchoice
));
747 if (!strcmp(keyword
, "PageSize"))
748 strlcpy(option
->text
, _("Media Size"), sizeof(option
->text
));
749 else if (!strcmp(keyword
, "MediaType"))
750 strlcpy(option
->text
, _("Media Type"), sizeof(option
->text
));
751 else if (!strcmp(keyword
, "InputSlot"))
752 strlcpy(option
->text
, _("Media Source"), sizeof(option
->text
));
753 else if (!strcmp(keyword
, "ColorModel"))
754 strlcpy(option
->text
, _("Output Mode"), sizeof(option
->text
));
755 else if (!strcmp(keyword
, "Resolution"))
756 strlcpy(option
->text
, _("Resolution"), sizeof(option
->text
));
758 strlcpy(option
->text
, keyword
, sizeof(option
->text
));
762 if (!strcmp(keyword
, "LanguageLevel"))
763 ppd
->language_level
= atoi(string
);
764 else if (!strcmp(keyword
, "LanguageEncoding"))
767 * Say all PPD files are UTF-8, since we convert to UTF-8...
770 ppd
->lang_encoding
= _cupsStrAlloc("UTF-8");
771 encoding
= _ppdGetEncoding(string
);
773 else if (!strcmp(keyword
, "LanguageVersion"))
774 ppd
->lang_version
= string
;
775 else if (!strcmp(keyword
, "Manufacturer"))
776 ppd
->manufacturer
= string
;
777 else if (!strcmp(keyword
, "ModelName"))
778 ppd
->modelname
= string
;
779 else if (!strcmp(keyword
, "Protocols"))
780 ppd
->protocols
= string
;
781 else if (!strcmp(keyword
, "PCFileName"))
782 ppd
->pcfilename
= string
;
783 else if (!strcmp(keyword
, "NickName"))
785 if (encoding
!= CUPS_UTF8
)
787 cups_utf8_t utf8
[256]; /* UTF-8 version of NickName */
790 cupsCharsetToUTF8(utf8
, string
, sizeof(utf8
), encoding
);
791 ppd
->nickname
= _cupsStrAlloc((char *)utf8
);
794 ppd
->nickname
= _cupsStrAlloc(string
);
796 else if (!strcmp(keyword
, "Product"))
797 ppd
->product
= string
;
798 else if (!strcmp(keyword
, "ShortNickName"))
799 ppd
->shortnickname
= string
;
800 else if (!strcmp(keyword
, "TTRasterizer"))
801 ppd
->ttrasterizer
= string
;
802 else if (!strcmp(keyword
, "JCLBegin"))
804 ppd
->jcl_begin
= _cupsStrAlloc(string
);
805 ppd_decode(ppd
->jcl_begin
); /* Decode quoted string */
807 else if (!strcmp(keyword
, "JCLEnd"))
809 ppd
->jcl_end
= _cupsStrAlloc(string
);
810 ppd_decode(ppd
->jcl_end
); /* Decode quoted string */
812 else if (!strcmp(keyword
, "JCLToPSInterpreter"))
814 ppd
->jcl_ps
= _cupsStrAlloc(string
);
815 ppd_decode(ppd
->jcl_ps
); /* Decode quoted string */
817 else if (!strcmp(keyword
, "AccurateScreensSupport"))
818 ppd
->accurate_screens
= !strcmp(string
, "True");
819 else if (!strcmp(keyword
, "ColorDevice"))
820 ppd
->color_device
= !strcmp(string
, "True");
821 else if (!strcmp(keyword
, "ContoneOnly"))
822 ppd
->contone_only
= !strcmp(string
, "True");
823 else if (!strcmp(keyword
, "cupsFlipDuplex"))
824 ppd
->flip_duplex
= !strcmp(string
, "True");
825 else if (!strcmp(keyword
, "cupsManualCopies"))
826 ppd
->manual_copies
= !strcmp(string
, "True");
827 else if (!strcmp(keyword
, "cupsModelNumber"))
828 ppd
->model_number
= atoi(string
);
829 else if (!strcmp(keyword
, "cupsColorProfile"))
831 if (ppd
->num_profiles
== 0)
832 profile
= malloc(sizeof(ppd_profile_t
));
834 profile
= realloc(ppd
->profiles
, sizeof(ppd_profile_t
) *
835 (ppd
->num_profiles
+ 1));
839 cg
->ppd_status
= PPD_ALLOC_ERROR
;
844 ppd
->profiles
= profile
;
845 profile
+= ppd
->num_profiles
;
846 ppd
->num_profiles
++;
848 memset(profile
, 0, sizeof(ppd_profile_t
));
849 strlcpy(profile
->resolution
, name
, sizeof(profile
->resolution
));
850 strlcpy(profile
->media_type
, text
, sizeof(profile
->media_type
));
852 profile
->density
= (float)_cupsStrScand(string
, &sptr
, loc
);
853 profile
->gamma
= (float)_cupsStrScand(sptr
, &sptr
, loc
);
854 profile
->matrix
[0][0] = (float)_cupsStrScand(sptr
, &sptr
, loc
);
855 profile
->matrix
[0][1] = (float)_cupsStrScand(sptr
, &sptr
, loc
);
856 profile
->matrix
[0][2] = (float)_cupsStrScand(sptr
, &sptr
, loc
);
857 profile
->matrix
[1][0] = (float)_cupsStrScand(sptr
, &sptr
, loc
);
858 profile
->matrix
[1][1] = (float)_cupsStrScand(sptr
, &sptr
, loc
);
859 profile
->matrix
[1][2] = (float)_cupsStrScand(sptr
, &sptr
, loc
);
860 profile
->matrix
[2][0] = (float)_cupsStrScand(sptr
, &sptr
, loc
);
861 profile
->matrix
[2][1] = (float)_cupsStrScand(sptr
, &sptr
, loc
);
862 profile
->matrix
[2][2] = (float)_cupsStrScand(sptr
, &sptr
, loc
);
864 else if (!strcmp(keyword
, "cupsFilter"))
866 if (ppd
->num_filters
== 0)
867 filter
= malloc(sizeof(char *));
869 filter
= realloc(ppd
->filters
, sizeof(char *) * (ppd
->num_filters
+ 1));
873 cg
->ppd_status
= PPD_ALLOC_ERROR
;
878 ppd
->filters
= filter
;
879 filter
+= ppd
->num_filters
;
883 * Copy filter string and prevent it from being freed below...
889 else if (!strcmp(keyword
, "Throughput"))
890 ppd
->throughput
= atoi(string
);
891 else if (!strcmp(keyword
, "Font"))
894 * Add this font to the list of available fonts...
897 if (ppd
->num_fonts
== 0)
898 tempfonts
= (char **)malloc(sizeof(char *));
900 tempfonts
= (char **)realloc(ppd
->fonts
,
901 sizeof(char *) * (ppd
->num_fonts
+ 1));
903 if (tempfonts
== NULL
)
905 cg
->ppd_status
= PPD_ALLOC_ERROR
;
910 ppd
->fonts
= tempfonts
;
911 ppd
->fonts
[ppd
->num_fonts
] = _cupsStrAlloc(name
);
914 else if (!strncmp(keyword
, "ParamCustom", 11))
916 ppd_coption_t
*coption
; /* Custom option */
917 ppd_cparam_t
*cparam
; /* Custom parameter */
918 int corder
; /* Order number */
919 char ctype
[33], /* Data type */
920 cminimum
[65], /* Minimum value */
921 cmaximum
[65]; /* Maximum value */
925 * Get the custom option and parameter...
928 if ((coption
= ppd_get_coption(ppd
, keyword
+ 11)) == NULL
)
930 cg
->ppd_status
= PPD_ALLOC_ERROR
;
935 if ((cparam
= ppd_get_cparam(coption
, name
, text
)) == NULL
)
937 cg
->ppd_status
= PPD_ALLOC_ERROR
;
943 * Get the parameter data...
947 sscanf(string
, "%d%32s%64s%64s", &corder
, ctype
, cminimum
,
950 cg
->ppd_status
= PPD_BAD_CUSTOM_PARAM
;
955 cparam
->order
= corder
;
957 if (!strcmp(ctype
, "curve"))
959 cparam
->type
= PPD_CUSTOM_CURVE
;
960 cparam
->minimum
.custom_curve
= (float)_cupsStrScand(cminimum
, NULL
, loc
);
961 cparam
->maximum
.custom_curve
= (float)_cupsStrScand(cmaximum
, NULL
, loc
);
963 else if (!strcmp(ctype
, "int"))
965 cparam
->type
= PPD_CUSTOM_INT
;
966 cparam
->minimum
.custom_int
= atoi(cminimum
);
967 cparam
->maximum
.custom_int
= atoi(cmaximum
);
969 else if (!strcmp(ctype
, "invcurve"))
971 cparam
->type
= PPD_CUSTOM_INVCURVE
;
972 cparam
->minimum
.custom_invcurve
= (float)_cupsStrScand(cminimum
, NULL
, loc
);
973 cparam
->maximum
.custom_invcurve
= (float)_cupsStrScand(cmaximum
, NULL
, loc
);
975 else if (!strcmp(ctype
, "passcode"))
977 cparam
->type
= PPD_CUSTOM_PASSCODE
;
978 cparam
->minimum
.custom_passcode
= atoi(cminimum
);
979 cparam
->maximum
.custom_passcode
= atoi(cmaximum
);
981 else if (!strcmp(ctype
, "password"))
983 cparam
->type
= PPD_CUSTOM_PASSWORD
;
984 cparam
->minimum
.custom_password
= atoi(cminimum
);
985 cparam
->maximum
.custom_password
= atoi(cmaximum
);
987 else if (!strcmp(ctype
, "points"))
989 cparam
->type
= PPD_CUSTOM_POINTS
;
990 cparam
->minimum
.custom_points
= (float)_cupsStrScand(cminimum
, NULL
, loc
);
991 cparam
->maximum
.custom_points
= (float)_cupsStrScand(cmaximum
, NULL
, loc
);
993 else if (!strcmp(ctype
, "real"))
995 cparam
->type
= PPD_CUSTOM_REAL
;
996 cparam
->minimum
.custom_real
= (float)_cupsStrScand(cminimum
, NULL
, loc
);
997 cparam
->maximum
.custom_real
= (float)_cupsStrScand(cmaximum
, NULL
, loc
);
999 else if (!strcmp(ctype
, "string"))
1001 cparam
->type
= PPD_CUSTOM_STRING
;
1002 cparam
->minimum
.custom_string
= atoi(cminimum
);
1003 cparam
->maximum
.custom_string
= atoi(cmaximum
);
1007 cg
->ppd_status
= PPD_BAD_CUSTOM_PARAM
;
1013 * Now special-case for CustomPageSize...
1016 if (!strcmp(coption
->keyword
, "PageSize"))
1018 if (!strcmp(name
, "Width"))
1020 ppd
->custom_min
[0] = cparam
->minimum
.custom_points
;
1021 ppd
->custom_max
[0] = cparam
->maximum
.custom_points
;
1023 else if (!strcmp(name
, "Height"))
1025 ppd
->custom_min
[1] = cparam
->minimum
.custom_points
;
1026 ppd
->custom_max
[1] = cparam
->maximum
.custom_points
;
1030 else if (!strcmp(keyword
, "HWMargins"))
1032 for (i
= 0, sptr
= string
; i
< 4; i
++)
1033 ppd
->custom_margins
[i
] = (float)_cupsStrScand(sptr
, &sptr
, loc
);
1035 else if (!strncmp(keyword
, "Custom", 6) && !strcmp(name
, "True") && !option
)
1037 ppd_option_t
*custom_option
; /* Custom option */
1039 DEBUG_puts("2ppdOpen2: Processing Custom option...");
1042 * Get the option and custom option...
1045 if (!ppd_get_coption(ppd
, keyword
+ 6))
1047 cg
->ppd_status
= PPD_ALLOC_ERROR
;
1052 if (option
&& !_cups_strcasecmp(option
->keyword
, keyword
+ 6))
1053 custom_option
= option
;
1055 custom_option
= ppdFindOption(ppd
, keyword
+ 6);
1060 * Add the "custom" option...
1063 if ((choice
= ppdFindChoice(custom_option
, "Custom")) == NULL
)
1064 if ((choice
= ppd_add_choice(custom_option
, "Custom")) == NULL
)
1066 DEBUG_puts("1ppdOpen2: Unable to add Custom choice!");
1068 cg
->ppd_status
= PPD_ALLOC_ERROR
;
1073 strlcpy(choice
->text
, text
[0] ? text
: _("Custom"),
1074 sizeof(choice
->text
));
1076 choice
->code
= _cupsStrAlloc(string
);
1078 if (custom_option
->section
== PPD_ORDER_JCL
)
1079 ppd_decode(choice
->code
);
1083 * Now process custom page sizes specially...
1086 if (!strcmp(keyword
, "CustomPageSize"))
1089 * Add a "Custom" page size entry...
1092 ppd
->variable_sizes
= 1;
1094 ppd_add_size(ppd
, "Custom");
1096 if (option
&& !_cups_strcasecmp(option
->keyword
, "PageRegion"))
1097 custom_option
= option
;
1099 custom_option
= ppdFindOption(ppd
, "PageRegion");
1103 if ((choice
= ppdFindChoice(custom_option
, "Custom")) == NULL
)
1104 if ((choice
= ppd_add_choice(custom_option
, "Custom")) == NULL
)
1106 DEBUG_puts("1ppdOpen2: Unable to add Custom choice!");
1108 cg
->ppd_status
= PPD_ALLOC_ERROR
;
1113 strlcpy(choice
->text
, text
[0] ? text
: _("Custom"),
1114 sizeof(choice
->text
));
1118 else if (!strcmp(keyword
, "LandscapeOrientation"))
1120 if (!strcmp(string
, "Minus90"))
1121 ppd
->landscape
= -90;
1122 else if (!strcmp(string
, "Plus90"))
1123 ppd
->landscape
= 90;
1125 else if (!strcmp(keyword
, "Emulators") && string
)
1127 for (count
= 1, sptr
= string
; sptr
!= NULL
;)
1128 if ((sptr
= strchr(sptr
, ' ')) != NULL
)
1131 while (*sptr
== ' ')
1135 ppd
->num_emulations
= count
;
1136 if ((ppd
->emulations
= calloc(count
, sizeof(ppd_emul_t
))) == NULL
)
1138 cg
->ppd_status
= PPD_ALLOC_ERROR
;
1143 for (i
= 0, sptr
= string
; i
< count
; i
++)
1145 for (nameptr
= ppd
->emulations
[i
].name
;
1146 *sptr
!= '\0' && *sptr
!= ' ';
1148 if (nameptr
< (ppd
->emulations
[i
].name
+ sizeof(ppd
->emulations
[i
].name
) - 1))
1153 while (*sptr
== ' ')
1157 else if (!strncmp(keyword
, "StartEmulator_", 14))
1161 for (i
= 0; i
< ppd
->num_emulations
; i
++)
1162 if (!strcmp(keyword
+ 14, ppd
->emulations
[i
].name
))
1164 ppd
->emulations
[i
].start
= string
;
1168 else if (!strncmp(keyword
, "StopEmulator_", 13))
1172 for (i
= 0; i
< ppd
->num_emulations
; i
++)
1173 if (!strcmp(keyword
+ 13, ppd
->emulations
[i
].name
))
1175 ppd
->emulations
[i
].stop
= string
;
1179 else if (!strcmp(keyword
, "JobPatchFile"))
1182 * CUPS STR #3421: Check for "*JobPatchFile: int: string"
1185 if (isdigit(*string
& 255))
1187 for (sptr
= string
+ 1; isdigit(*sptr
& 255); sptr
++);
1192 * Found "*JobPatchFile: int: string"...
1195 cg
->ppd_status
= PPD_BAD_VALUE
;
1201 if (!name
[0] && cg
->ppd_conform
== PPD_CONFORM_STRICT
)
1204 * Found "*JobPatchFile: string"...
1207 cg
->ppd_status
= PPD_MISSING_OPTION_KEYWORD
;
1212 if (ppd
->patches
== NULL
)
1213 ppd
->patches
= strdup(string
);
1216 temp
= realloc(ppd
->patches
, strlen(ppd
->patches
) +
1217 strlen(string
) + 1);
1220 cg
->ppd_status
= PPD_ALLOC_ERROR
;
1225 ppd
->patches
= temp
;
1227 strcpy(ppd
->patches
+ strlen(ppd
->patches
), string
);
1230 else if (!strcmp(keyword
, "OpenUI"))
1233 * Don't allow nesting of options...
1236 if (option
&& cg
->ppd_conform
== PPD_CONFORM_STRICT
)
1238 cg
->ppd_status
= PPD_NESTED_OPEN_UI
;
1244 * Add an option record to the current sub-group, group, or file...
1247 DEBUG_printf(("2ppdOpen2: name=\"%s\" (%d)", name
, (int)strlen(name
)));
1250 _cups_strcpy(name
, name
+ 1); /* Eliminate leading asterisk */
1252 for (i
= (int)strlen(name
) - 1; i
> 0 && _cups_isspace(name
[i
]); i
--)
1253 name
[i
] = '\0'; /* Eliminate trailing spaces */
1255 DEBUG_printf(("2ppdOpen2: OpenUI of %s in group %s...", name
,
1256 group
? group
->text
: "(null)"));
1258 if (subgroup
!= NULL
)
1259 option
= ppd_get_option(subgroup
, name
);
1260 else if (group
== NULL
)
1262 if ((group
= ppd_get_group(ppd
, "General", _("General"), cg
,
1266 DEBUG_printf(("2ppdOpen2: Adding to group %s...", group
->text
));
1267 option
= ppd_get_option(group
, name
);
1271 option
= ppd_get_option(group
, name
);
1275 cg
->ppd_status
= PPD_ALLOC_ERROR
;
1281 * Now fill in the initial information for the option...
1284 if (string
&& !strcmp(string
, "PickMany"))
1285 option
->ui
= PPD_UI_PICKMANY
;
1286 else if (string
&& !strcmp(string
, "Boolean"))
1287 option
->ui
= PPD_UI_BOOLEAN
;
1288 else if (string
&& !strcmp(string
, "PickOne"))
1289 option
->ui
= PPD_UI_PICKONE
;
1290 else if (cg
->ppd_conform
== PPD_CONFORM_STRICT
)
1292 cg
->ppd_status
= PPD_BAD_OPEN_UI
;
1297 option
->ui
= PPD_UI_PICKONE
;
1299 for (j
= 0; j
< ppd
->num_attrs
; j
++)
1300 if (!strncmp(ppd
->attrs
[j
]->name
, "Default", 7) &&
1301 !strcmp(ppd
->attrs
[j
]->name
+ 7, name
) &&
1302 ppd
->attrs
[j
]->value
)
1304 DEBUG_printf(("2ppdOpen2: Setting Default%s to %s via attribute...",
1305 option
->keyword
, ppd
->attrs
[j
]->value
));
1306 strlcpy(option
->defchoice
, ppd
->attrs
[j
]->value
,
1307 sizeof(option
->defchoice
));
1312 cupsCharsetToUTF8((cups_utf8_t
*)option
->text
, text
,
1313 sizeof(option
->text
), encoding
);
1316 if (!strcmp(name
, "PageSize"))
1317 strlcpy(option
->text
, _("Media Size"), sizeof(option
->text
));
1318 else if (!strcmp(name
, "MediaType"))
1319 strlcpy(option
->text
, _("Media Type"), sizeof(option
->text
));
1320 else if (!strcmp(name
, "InputSlot"))
1321 strlcpy(option
->text
, _("Media Source"), sizeof(option
->text
));
1322 else if (!strcmp(name
, "ColorModel"))
1323 strlcpy(option
->text
, _("Output Mode"), sizeof(option
->text
));
1324 else if (!strcmp(name
, "Resolution"))
1325 strlcpy(option
->text
, _("Resolution"), sizeof(option
->text
));
1327 strlcpy(option
->text
, name
, sizeof(option
->text
));
1330 option
->section
= PPD_ORDER_ANY
;
1332 _cupsStrFree(string
);
1336 * Add a custom option choice if we have already seen a CustomFoo
1340 if (!_cups_strcasecmp(name
, "PageRegion"))
1341 strcpy(custom_name
, "CustomPageSize");
1343 snprintf(custom_name
, sizeof(custom_name
), "Custom%s", name
);
1345 if ((custom_attr
= ppdFindAttr(ppd
, custom_name
, "True")) != NULL
)
1347 if ((choice
= ppdFindChoice(option
, "Custom")) == NULL
)
1348 if ((choice
= ppd_add_choice(option
, "Custom")) == NULL
)
1350 DEBUG_puts("1ppdOpen2: Unable to add Custom choice!");
1352 cg
->ppd_status
= PPD_ALLOC_ERROR
;
1357 strlcpy(choice
->text
,
1358 custom_attr
->text
[0] ? custom_attr
->text
: _("Custom"),
1359 sizeof(choice
->text
));
1360 choice
->code
= _cupsStrRetain(custom_attr
->value
);
1363 else if (!strcmp(keyword
, "JCLOpenUI"))
1366 * Don't allow nesting of options...
1369 if (option
&& cg
->ppd_conform
== PPD_CONFORM_STRICT
)
1371 cg
->ppd_status
= PPD_NESTED_OPEN_UI
;
1377 * Find the JCL group, and add if needed...
1380 group
= ppd_get_group(ppd
, "JCL", _("JCL"), cg
, encoding
);
1386 * Add an option record to the current JCLs...
1390 _cups_strcpy(name
, name
+ 1);
1392 option
= ppd_get_option(group
, name
);
1396 cg
->ppd_status
= PPD_ALLOC_ERROR
;
1402 * Now fill in the initial information for the option...
1405 if (string
&& !strcmp(string
, "PickMany"))
1406 option
->ui
= PPD_UI_PICKMANY
;
1407 else if (string
&& !strcmp(string
, "Boolean"))
1408 option
->ui
= PPD_UI_BOOLEAN
;
1409 else if (string
&& !strcmp(string
, "PickOne"))
1410 option
->ui
= PPD_UI_PICKONE
;
1413 cg
->ppd_status
= PPD_BAD_OPEN_UI
;
1418 for (j
= 0; j
< ppd
->num_attrs
; j
++)
1419 if (!strncmp(ppd
->attrs
[j
]->name
, "Default", 7) &&
1420 !strcmp(ppd
->attrs
[j
]->name
+ 7, name
) &&
1421 ppd
->attrs
[j
]->value
)
1423 DEBUG_printf(("2ppdOpen2: Setting Default%s to %s via attribute...",
1424 option
->keyword
, ppd
->attrs
[j
]->value
));
1425 strlcpy(option
->defchoice
, ppd
->attrs
[j
]->value
,
1426 sizeof(option
->defchoice
));
1431 cupsCharsetToUTF8((cups_utf8_t
*)option
->text
, text
,
1432 sizeof(option
->text
), encoding
);
1434 strlcpy(option
->text
, name
, sizeof(option
->text
));
1436 option
->section
= PPD_ORDER_JCL
;
1439 _cupsStrFree(string
);
1443 * Add a custom option choice if we have already seen a CustomFoo
1447 snprintf(custom_name
, sizeof(custom_name
), "Custom%s", name
);
1449 if ((custom_attr
= ppdFindAttr(ppd
, custom_name
, "True")) != NULL
)
1451 if ((choice
= ppd_add_choice(option
, "Custom")) == NULL
)
1453 DEBUG_puts("1ppdOpen2: Unable to add Custom choice!");
1455 cg
->ppd_status
= PPD_ALLOC_ERROR
;
1460 strlcpy(choice
->text
,
1461 custom_attr
->text
[0] ? custom_attr
->text
: _("Custom"),
1462 sizeof(choice
->text
));
1463 choice
->code
= _cupsStrRetain(custom_attr
->value
);
1466 else if (!strcmp(keyword
, "CloseUI") || !strcmp(keyword
, "JCLCloseUI"))
1470 _cupsStrFree(string
);
1473 else if (!strcmp(keyword
, "OpenGroup"))
1476 * Open a new group...
1481 cg
->ppd_status
= PPD_NESTED_OPEN_GROUP
;
1488 cg
->ppd_status
= PPD_BAD_OPEN_GROUP
;
1494 * Separate the group name from the text (name/text)...
1497 if ((sptr
= strchr(string
, '/')) != NULL
)
1503 * Fix up the text...
1509 * Find/add the group...
1512 group
= ppd_get_group(ppd
, string
, sptr
, cg
, encoding
);
1517 _cupsStrFree(string
);
1520 else if (!strcmp(keyword
, "CloseGroup"))
1524 _cupsStrFree(string
);
1527 else if (!strcmp(keyword
, "OrderDependency"))
1529 order
= (float)_cupsStrScand(string
, &sptr
, loc
);
1531 if (!sptr
|| sscanf(sptr
, "%40s%40s", name
, keyword
) != 2)
1533 cg
->ppd_status
= PPD_BAD_ORDER_DEPENDENCY
;
1538 if (keyword
[0] == '*')
1539 _cups_strcpy(keyword
, keyword
+ 1);
1541 if (!strcmp(name
, "ExitServer"))
1542 section
= PPD_ORDER_EXIT
;
1543 else if (!strcmp(name
, "Prolog"))
1544 section
= PPD_ORDER_PROLOG
;
1545 else if (!strcmp(name
, "DocumentSetup"))
1546 section
= PPD_ORDER_DOCUMENT
;
1547 else if (!strcmp(name
, "PageSetup"))
1548 section
= PPD_ORDER_PAGE
;
1549 else if (!strcmp(name
, "JCLSetup"))
1550 section
= PPD_ORDER_JCL
;
1552 section
= PPD_ORDER_ANY
;
1560 * Only valid for Non-UI options...
1563 for (i
= ppd
->num_groups
, gtemp
= ppd
->groups
; i
> 0; i
--, gtemp
++)
1564 if (gtemp
->text
[0] == '\0')
1568 for (i
= 0; i
< gtemp
->num_options
; i
++)
1569 if (!strcmp(keyword
, gtemp
->options
[i
].keyword
))
1571 gtemp
->options
[i
].section
= section
;
1572 gtemp
->options
[i
].order
= order
;
1578 option
->section
= section
;
1579 option
->order
= order
;
1582 _cupsStrFree(string
);
1585 else if (!strncmp(keyword
, "Default", 7))
1591 * Drop UI text, if any, from value...
1594 if (strchr(string
, '/') != NULL
)
1595 *strchr(string
, '/') = '\0';
1598 * Assign the default value as appropriate...
1601 if (!strcmp(keyword
, "DefaultColorSpace"))
1604 * Set default colorspace...
1607 if (!strcmp(string
, "CMY"))
1608 ppd
->colorspace
= PPD_CS_CMY
;
1609 else if (!strcmp(string
, "CMYK"))
1610 ppd
->colorspace
= PPD_CS_CMYK
;
1611 else if (!strcmp(string
, "RGB"))
1612 ppd
->colorspace
= PPD_CS_RGB
;
1613 else if (!strcmp(string
, "RGBK"))
1614 ppd
->colorspace
= PPD_CS_RGBK
;
1615 else if (!strcmp(string
, "N"))
1616 ppd
->colorspace
= PPD_CS_N
;
1618 ppd
->colorspace
= PPD_CS_GRAY
;
1620 else if (option
&& !strcmp(keyword
+ 7, option
->keyword
))
1623 * Set the default as part of the current option...
1626 DEBUG_printf(("2ppdOpen2: Setting %s to %s...", keyword
, string
));
1628 strlcpy(option
->defchoice
, string
, sizeof(option
->defchoice
));
1630 DEBUG_printf(("2ppdOpen2: %s is now %s...", keyword
, option
->defchoice
));
1635 * Lookup option and set if it has been defined...
1638 ppd_option_t
*toption
; /* Temporary option */
1641 if ((toption
= ppdFindOption(ppd
, keyword
+ 7)) != NULL
)
1643 DEBUG_printf(("2ppdOpen2: Setting %s to %s...", keyword
, string
));
1644 strlcpy(toption
->defchoice
, string
, sizeof(toption
->defchoice
));
1648 else if (!strcmp(keyword
, "UIConstraints") ||
1649 !strcmp(keyword
, "NonUIConstraints"))
1653 cg
->ppd_status
= PPD_BAD_UI_CONSTRAINTS
;
1657 if (ppd
->num_consts
== 0)
1658 constraint
= calloc(2, sizeof(ppd_const_t
));
1660 constraint
= realloc(ppd
->consts
,
1661 (ppd
->num_consts
+ 2) * sizeof(ppd_const_t
));
1663 if (constraint
== NULL
)
1665 cg
->ppd_status
= PPD_ALLOC_ERROR
;
1670 ppd
->consts
= constraint
;
1671 constraint
+= ppd
->num_consts
;
1674 switch (sscanf(string
, "%40s%40s%40s%40s", constraint
->option1
,
1675 constraint
->choice1
, constraint
->option2
,
1676 constraint
->choice2
))
1678 case 0 : /* Error */
1679 case 1 : /* Error */
1680 cg
->ppd_status
= PPD_BAD_UI_CONSTRAINTS
;
1683 case 2 : /* Two options... */
1685 * Check for broken constraints like "* Option"...
1688 if (cg
->ppd_conform
== PPD_CONFORM_STRICT
&&
1689 (!strcmp(constraint
->option1
, "*") ||
1690 !strcmp(constraint
->choice1
, "*")))
1692 cg
->ppd_status
= PPD_BAD_UI_CONSTRAINTS
;
1697 * The following strcpy's are safe, as optionN and
1698 * choiceN are all the same size (size defined by PPD spec...)
1701 if (constraint
->option1
[0] == '*')
1702 _cups_strcpy(constraint
->option1
, constraint
->option1
+ 1);
1703 else if (cg
->ppd_conform
== PPD_CONFORM_STRICT
)
1705 cg
->ppd_status
= PPD_BAD_UI_CONSTRAINTS
;
1709 if (constraint
->choice1
[0] == '*')
1710 _cups_strcpy(constraint
->option2
, constraint
->choice1
+ 1);
1711 else if (cg
->ppd_conform
== PPD_CONFORM_STRICT
)
1713 cg
->ppd_status
= PPD_BAD_UI_CONSTRAINTS
;
1717 constraint
->choice1
[0] = '\0';
1718 constraint
->choice2
[0] = '\0';
1721 case 3 : /* Two options, one choice... */
1723 * Check for broken constraints like "* Option"...
1726 if (cg
->ppd_conform
== PPD_CONFORM_STRICT
&&
1727 (!strcmp(constraint
->option1
, "*") ||
1728 !strcmp(constraint
->choice1
, "*") ||
1729 !strcmp(constraint
->option2
, "*")))
1731 cg
->ppd_status
= PPD_BAD_UI_CONSTRAINTS
;
1736 * The following _cups_strcpy's are safe, as optionN and
1737 * choiceN are all the same size (size defined by PPD spec...)
1740 if (constraint
->option1
[0] == '*')
1741 _cups_strcpy(constraint
->option1
, constraint
->option1
+ 1);
1742 else if (cg
->ppd_conform
== PPD_CONFORM_STRICT
)
1744 cg
->ppd_status
= PPD_BAD_UI_CONSTRAINTS
;
1748 if (constraint
->choice1
[0] == '*')
1750 if (cg
->ppd_conform
== PPD_CONFORM_STRICT
&&
1751 constraint
->option2
[0] == '*')
1753 cg
->ppd_status
= PPD_BAD_UI_CONSTRAINTS
;
1757 _cups_strcpy(constraint
->choice2
, constraint
->option2
);
1758 _cups_strcpy(constraint
->option2
, constraint
->choice1
+ 1);
1759 constraint
->choice1
[0] = '\0';
1763 if (constraint
->option2
[0] == '*')
1764 _cups_strcpy(constraint
->option2
, constraint
->option2
+ 1);
1765 else if (cg
->ppd_conform
== PPD_CONFORM_STRICT
)
1767 cg
->ppd_status
= PPD_BAD_UI_CONSTRAINTS
;
1771 constraint
->choice2
[0] = '\0';
1775 case 4 : /* Two options, two choices... */
1777 * Check for broken constraints like "* Option"...
1780 if (cg
->ppd_conform
== PPD_CONFORM_STRICT
&&
1781 (!strcmp(constraint
->option1
, "*") ||
1782 !strcmp(constraint
->choice1
, "*") ||
1783 !strcmp(constraint
->option2
, "*") ||
1784 !strcmp(constraint
->choice2
, "*")))
1786 cg
->ppd_status
= PPD_BAD_UI_CONSTRAINTS
;
1790 if (constraint
->option1
[0] == '*')
1791 _cups_strcpy(constraint
->option1
, constraint
->option1
+ 1);
1792 else if (cg
->ppd_conform
== PPD_CONFORM_STRICT
)
1794 cg
->ppd_status
= PPD_BAD_UI_CONSTRAINTS
;
1798 if (cg
->ppd_conform
== PPD_CONFORM_STRICT
&&
1799 constraint
->choice1
[0] == '*')
1801 cg
->ppd_status
= PPD_BAD_UI_CONSTRAINTS
;
1805 if (constraint
->option2
[0] == '*')
1806 _cups_strcpy(constraint
->option2
, constraint
->option2
+ 1);
1807 else if (cg
->ppd_conform
== PPD_CONFORM_STRICT
)
1809 cg
->ppd_status
= PPD_BAD_UI_CONSTRAINTS
;
1813 if (cg
->ppd_conform
== PPD_CONFORM_STRICT
&&
1814 constraint
->choice2
[0] == '*')
1816 cg
->ppd_status
= PPD_BAD_UI_CONSTRAINTS
;
1823 * Don't add this one as an attribute...
1826 _cupsStrFree(string
);
1829 else if (!strcmp(keyword
, "PaperDimension"))
1831 if ((size
= ppdPageSize(ppd
, name
)) == NULL
)
1832 size
= ppd_add_size(ppd
, name
);
1837 * Unable to add or find size!
1840 cg
->ppd_status
= PPD_ALLOC_ERROR
;
1845 size
->width
= (float)_cupsStrScand(string
, &sptr
, loc
);
1846 size
->length
= (float)_cupsStrScand(sptr
, NULL
, loc
);
1848 _cupsStrFree(string
);
1851 else if (!strcmp(keyword
, "ImageableArea"))
1853 if ((size
= ppdPageSize(ppd
, name
)) == NULL
)
1854 size
= ppd_add_size(ppd
, name
);
1859 * Unable to add or find size!
1862 cg
->ppd_status
= PPD_ALLOC_ERROR
;
1867 size
->left
= (float)_cupsStrScand(string
, &sptr
, loc
);
1868 size
->bottom
= (float)_cupsStrScand(sptr
, &sptr
, loc
);
1869 size
->right
= (float)_cupsStrScand(sptr
, &sptr
, loc
);
1870 size
->top
= (float)_cupsStrScand(sptr
, NULL
, loc
);
1872 _cupsStrFree(string
);
1875 else if (option
!= NULL
&&
1876 (mask
& (PPD_KEYWORD
| PPD_OPTION
| PPD_STRING
)) ==
1877 (PPD_KEYWORD
| PPD_OPTION
| PPD_STRING
) &&
1878 !strcmp(keyword
, option
->keyword
))
1880 DEBUG_printf(("2ppdOpen2: group=%p, subgroup=%p", group
, subgroup
));
1882 if (!strcmp(keyword
, "PageSize"))
1885 * Add a page size...
1888 if (ppdPageSize(ppd
, name
) == NULL
)
1889 ppd_add_size(ppd
, name
);
1893 * Add the option choice...
1896 if ((choice
= ppd_add_choice(option
, name
)) == NULL
)
1898 cg
->ppd_status
= PPD_ALLOC_ERROR
;
1904 cupsCharsetToUTF8((cups_utf8_t
*)choice
->text
, text
,
1905 sizeof(choice
->text
), encoding
);
1906 else if (!strcmp(name
, "True"))
1907 strcpy(choice
->text
, _("Yes"));
1908 else if (!strcmp(name
, "False"))
1909 strcpy(choice
->text
, _("No"));
1911 strlcpy(choice
->text
, name
, sizeof(choice
->text
));
1913 if (option
->section
== PPD_ORDER_JCL
)
1914 ppd_decode(string
); /* Decode quoted string */
1916 choice
->code
= string
;
1917 string
= NULL
; /* Don't add as an attribute below */
1921 * Add remaining lines with keywords and string values as attributes...
1925 (mask
& (PPD_KEYWORD
| PPD_STRING
)) == (PPD_KEYWORD
| PPD_STRING
))
1926 ppd_add_attr(ppd
, keyword
, name
, text
, string
);
1928 _cupsStrFree(string
);
1932 * Check for a missing CloseGroup...
1935 if (group
&& cg
->ppd_conform
== PPD_CONFORM_STRICT
)
1937 cg
->ppd_status
= PPD_MISSING_CLOSE_GROUP
;
1941 ppd_free(line
.buffer
);
1944 * Reset language preferences...
1948 if (!cupsFileEOF(fp
))
1949 DEBUG_printf(("1ppdOpen2: Premature EOF at %lu...\n",
1950 (unsigned long)cupsFileTell(fp
)));
1953 if (cg
->ppd_status
!= PPD_OK
)
1956 * Had an error reading the PPD file, cannot continue!
1965 * Create the sorted options array and set the option back-pointer for
1966 * each choice and custom option...
1969 ppd
->options
= cupsArrayNew2((cups_array_func_t
)ppd_compare_options
, NULL
,
1970 (cups_ahash_func_t
)ppd_hash_option
,
1973 for (i
= ppd
->num_groups
, group
= ppd
->groups
;
1977 for (j
= group
->num_options
, option
= group
->options
;
1981 ppd_coption_t
*coption
; /* Custom option */
1984 cupsArrayAdd(ppd
->options
, option
);
1986 for (k
= 0; k
< option
->num_choices
; k
++)
1987 option
->choices
[k
].option
= option
;
1989 if ((coption
= ppdFindCustomOption(ppd
, option
->keyword
)) != NULL
)
1990 coption
->option
= option
;
1995 * Create an array to track the marked choices...
1998 ppd
->marked
= cupsArrayNew((cups_array_func_t
)ppd_compare_choices
, NULL
);
2001 * Return the PPD file structure...
2007 * Common exit point for errors to save code size...
2012 _cupsStrFree(string
);
2013 ppd_free(line
.buffer
);
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 (_cups_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 (_cups_strcasecmp(a
->keyword
, b
->keyword
));
2311 * 'ppd_compare_options()' - Compare two options.
2314 static int /* O - Result of comparison */
2315 ppd_compare_options(ppd_option_t
*a
, /* I - First option */
2316 ppd_option_t
*b
) /* I - Second option */
2318 return (_cups_strcasecmp(a
->keyword
, b
->keyword
));
2323 * 'ppd_decode()' - Decode a string value...
2326 static int /* O - Length of decoded string */
2327 ppd_decode(char *string
) /* I - String to decode */
2329 char *inptr
, /* Input pointer */
2330 *outptr
; /* Output pointer */
2336 while (*inptr
!= '\0')
2337 if (*inptr
== '<' && isxdigit(inptr
[1] & 255))
2340 * Convert hex to 8-bit values...
2344 while (isxdigit(*inptr
& 255))
2346 if (_cups_isalpha(*inptr
))
2347 *outptr
= (tolower(*inptr
) - 'a' + 10) << 4;
2349 *outptr
= (*inptr
- '0') << 4;
2353 if (!isxdigit(*inptr
& 255))
2356 if (_cups_isalpha(*inptr
))
2357 *outptr
|= tolower(*inptr
) - 'a' + 10;
2359 *outptr
|= *inptr
- '0';
2365 while (*inptr
!= '>' && *inptr
!= '\0')
2367 while (*inptr
== '>')
2371 *outptr
++ = *inptr
++;
2375 return ((int)(outptr
- string
));
2380 * 'ppd_free_group()' - Free a single UI group.
2384 ppd_free_group(ppd_group_t
*group
) /* I - Group to free */
2386 int i
; /* Looping var */
2387 ppd_option_t
*option
; /* Current option */
2388 ppd_group_t
*subgroup
; /* Current sub-group */
2391 if (group
->num_options
> 0)
2393 for (i
= group
->num_options
, option
= group
->options
;
2396 ppd_free_option(option
);
2398 ppd_free(group
->options
);
2401 if (group
->num_subgroups
> 0)
2403 for (i
= group
->num_subgroups
, subgroup
= group
->subgroups
;
2406 ppd_free_group(subgroup
);
2408 ppd_free(group
->subgroups
);
2414 * 'ppd_free_option()' - Free a single option.
2418 ppd_free_option(ppd_option_t
*option
) /* I - Option to free */
2420 int i
; /* Looping var */
2421 ppd_choice_t
*choice
; /* Current choice */
2424 if (option
->num_choices
> 0)
2426 for (i
= option
->num_choices
, choice
= option
->choices
;
2430 _cupsStrFree(choice
->code
);
2433 ppd_free(option
->choices
);
2439 * 'ppd_get_coption()' - Get a custom option record.
2442 static ppd_coption_t
* /* O - Custom option... */
2443 ppd_get_coption(ppd_file_t
*ppd
, /* I - PPD file */
2444 const char *name
) /* I - Name of option */
2446 ppd_coption_t
*copt
; /* New custom option */
2450 * See if the option already exists...
2453 if ((copt
= ppdFindCustomOption(ppd
, name
)) != NULL
)
2457 * Not found, so create the custom option record...
2460 if ((copt
= calloc(1, sizeof(ppd_coption_t
))) == NULL
)
2463 strlcpy(copt
->keyword
, name
, sizeof(copt
->keyword
));
2465 copt
->params
= cupsArrayNew((cups_array_func_t
)NULL
, NULL
);
2467 cupsArrayAdd(ppd
->coptions
, copt
);
2470 * Return the new record...
2478 * 'ppd_get_cparam()' - Get a custom parameter record.
2481 static ppd_cparam_t
* /* O - Extended option... */
2482 ppd_get_cparam(ppd_coption_t
*opt
, /* I - PPD file */
2483 const char *param
, /* I - Name of parameter */
2484 const char *text
) /* I - Human-readable text */
2486 ppd_cparam_t
*cparam
; /* New custom parameter */
2490 * See if the parameter already exists...
2493 if ((cparam
= ppdFindCustomParam(opt
, param
)) != NULL
)
2497 * Not found, so create the custom parameter record...
2500 if ((cparam
= calloc(1, sizeof(ppd_cparam_t
))) == NULL
)
2503 strlcpy(cparam
->name
, param
, sizeof(cparam
->name
));
2504 strlcpy(cparam
->text
, text
[0] ? text
: param
, sizeof(cparam
->text
));
2507 * Add this record to the array...
2510 cupsArrayAdd(opt
->params
, cparam
);
2513 * Return the new record...
2521 * 'ppd_get_group()' - Find or create the named group as needed.
2524 static ppd_group_t
* /* O - Named group */
2525 ppd_get_group(ppd_file_t
*ppd
, /* I - PPD file */
2526 const char *name
, /* I - Name of group */
2527 const char *text
, /* I - Text for group */
2528 _cups_globals_t
*cg
, /* I - Global data */
2529 cups_encoding_t encoding
) /* I - Encoding of text */
2531 int i
; /* Looping var */
2532 ppd_group_t
*group
; /* Group */
2535 DEBUG_printf(("7ppd_get_group(ppd=%p, name=\"%s\", text=\"%s\", cg=%p)",
2536 ppd
, name
, text
, cg
));
2538 for (i
= ppd
->num_groups
, group
= ppd
->groups
; i
> 0; i
--, group
++)
2539 if (!strcmp(group
->name
, name
))
2544 DEBUG_printf(("8ppd_get_group: Adding group %s...", name
));
2546 if (cg
->ppd_conform
== PPD_CONFORM_STRICT
&& strlen(text
) >= sizeof(group
->text
))
2548 cg
->ppd_status
= PPD_ILLEGAL_TRANSLATION
;
2553 if (ppd
->num_groups
== 0)
2554 group
= malloc(sizeof(ppd_group_t
));
2556 group
= realloc(ppd
->groups
,
2557 (ppd
->num_groups
+ 1) * sizeof(ppd_group_t
));
2561 cg
->ppd_status
= PPD_ALLOC_ERROR
;
2566 ppd
->groups
= group
;
2567 group
+= ppd
->num_groups
;
2570 memset(group
, 0, sizeof(ppd_group_t
));
2571 strlcpy(group
->name
, name
, sizeof(group
->name
));
2573 cupsCharsetToUTF8((cups_utf8_t
*)group
->text
, text
,
2574 sizeof(group
->text
), encoding
);
2582 * 'ppd_get_option()' - Find or create the named option as needed.
2585 static ppd_option_t
* /* O - Named option */
2586 ppd_get_option(ppd_group_t
*group
, /* I - Group */
2587 const char *name
) /* I - Name of option */
2589 int i
; /* Looping var */
2590 ppd_option_t
*option
; /* Option */
2593 DEBUG_printf(("7ppd_get_option(group=%p(\"%s\"), name=\"%s\")",
2594 group
, group
->name
, name
));
2596 for (i
= group
->num_options
, option
= group
->options
; i
> 0; i
--, option
++)
2597 if (!strcmp(option
->keyword
, name
))
2602 if (group
->num_options
== 0)
2603 option
= malloc(sizeof(ppd_option_t
));
2605 option
= realloc(group
->options
,
2606 (group
->num_options
+ 1) * sizeof(ppd_option_t
));
2611 group
->options
= option
;
2612 option
+= group
->num_options
;
2613 group
->num_options
++;
2615 memset(option
, 0, sizeof(ppd_option_t
));
2616 strlcpy(option
->keyword
, name
, sizeof(option
->keyword
));
2624 * 'ppd_hash_option()' - Generate a hash of the option name...
2627 static int /* O - Hash index */
2628 ppd_hash_option(ppd_option_t
*option
) /* I - Option */
2630 int hash
= 0; /* Hash index */
2631 const char *k
; /* Pointer into keyword */
2634 for (hash
= option
->keyword
[0], k
= option
->keyword
+ 1; *k
;)
2635 hash
= 33 * hash
+ *k
++;
2637 return (hash
& 511);
2642 * 'ppd_read()' - Read a line from a PPD file, skipping comment lines as
2646 static int /* O - Bitmask of fields read */
2647 ppd_read(cups_file_t
*fp
, /* I - File to read from */
2648 _ppd_line_t
*line
, /* I - Line buffer */
2649 char *keyword
, /* O - Keyword from line */
2650 char *option
, /* O - Option from line */
2651 char *text
, /* O - Human-readable text from line */
2652 char **string
, /* O - Code/string data */
2653 int ignoreblank
, /* I - Ignore blank lines? */
2654 _cups_globals_t
*cg
) /* I - Global data */
2656 int ch
, /* Character from file */
2657 col
, /* Column in line */
2658 colon
, /* Colon seen? */
2659 endquote
, /* Waiting for an end quote */
2660 mask
, /* Mask to be returned */
2661 startline
, /* Start line */
2662 textlen
; /* Length of text */
2663 char *keyptr
, /* Keyword pointer */
2664 *optptr
, /* Option pointer */
2665 *textptr
, /* Text pointer */
2666 *strptr
, /* Pointer into string */
2667 *lineptr
; /* Current position in line buffer */
2671 * Now loop until we have a valid line...
2676 startline
= cg
->ppd_line
+ 1;
2680 line
->bufsize
= 1024;
2681 line
->buffer
= malloc(1024);
2693 lineptr
= line
->buffer
;
2697 while ((ch
= cupsFileGetChar(fp
)) != EOF
)
2699 if (lineptr
>= (line
->buffer
+ line
->bufsize
- 1))
2702 * Expand the line buffer...
2705 char *temp
; /* Temporary line pointer */
2708 line
->bufsize
+= 1024;
2709 if (line
->bufsize
> 262144)
2712 * Don't allow lines longer than 256k!
2715 cg
->ppd_line
= startline
;
2716 cg
->ppd_status
= PPD_LINE_TOO_LONG
;
2721 temp
= realloc(line
->buffer
, line
->bufsize
);
2724 cg
->ppd_line
= startline
;
2725 cg
->ppd_status
= PPD_LINE_TOO_LONG
;
2730 lineptr
= temp
+ (lineptr
- line
->buffer
);
2731 line
->buffer
= temp
;
2734 if (ch
== '\r' || ch
== '\n')
2737 * Line feed or carriage return...
2746 * Check for a trailing line feed...
2749 if ((ch
= cupsFilePeekChar(fp
)) == EOF
)
2756 cupsFileGetChar(fp
);
2759 if (lineptr
== line
->buffer
&& ignoreblank
)
2760 continue; /* Skip blank lines */
2764 if (!endquote
) /* Continue for multi-line text */
2769 else if (ch
< ' ' && ch
!= '\t' && cg
->ppd_conform
== PPD_CONFORM_STRICT
)
2772 * Other control characters...
2775 cg
->ppd_line
= startline
;
2776 cg
->ppd_status
= PPD_ILLEGAL_CHARACTER
;
2780 else if (ch
!= 0x1a)
2783 * Any other character...
2789 if (col
> (PPD_MAX_LINE
- 1))
2792 * Line is too long...
2795 cg
->ppd_line
= startline
;
2796 cg
->ppd_status
= PPD_LINE_TOO_LONG
;
2801 if (ch
== ':' && strncmp(line
->buffer
, "*%", 2) != 0)
2804 if (ch
== '\"' && colon
)
2805 endquote
= !endquote
;
2812 * Didn't finish this quoted string...
2815 while ((ch
= cupsFileGetChar(fp
)) != EOF
)
2818 else if (ch
== '\r' || ch
== '\n')
2826 * Check for a trailing line feed...
2829 if ((ch
= cupsFilePeekChar(fp
)) == EOF
)
2832 cupsFileGetChar(fp
);
2835 else if (ch
< ' ' && ch
!= '\t' && cg
->ppd_conform
== PPD_CONFORM_STRICT
)
2838 * Other control characters...
2841 cg
->ppd_line
= startline
;
2842 cg
->ppd_status
= PPD_ILLEGAL_CHARACTER
;
2846 else if (ch
!= 0x1a)
2850 if (col
> (PPD_MAX_LINE
- 1))
2853 * Line is too long...
2856 cg
->ppd_line
= startline
;
2857 cg
->ppd_status
= PPD_LINE_TOO_LONG
;
2867 * Didn't finish this line...
2870 while ((ch
= cupsFileGetChar(fp
)) != EOF
)
2871 if (ch
== '\r' || ch
== '\n')
2874 * Line feed or carriage return...
2883 * Check for a trailing line feed...
2886 if ((ch
= cupsFilePeekChar(fp
)) == EOF
)
2889 cupsFileGetChar(fp
);
2894 else if (ch
< ' ' && ch
!= '\t' && cg
->ppd_conform
== PPD_CONFORM_STRICT
)
2897 * Other control characters...
2900 cg
->ppd_line
= startline
;
2901 cg
->ppd_status
= PPD_ILLEGAL_CHARACTER
;
2905 else if (ch
!= 0x1a)
2909 if (col
> (PPD_MAX_LINE
- 1))
2912 * Line is too long...
2915 cg
->ppd_line
= startline
;
2916 cg
->ppd_status
= PPD_LINE_TOO_LONG
;
2923 if (lineptr
> line
->buffer
&& lineptr
[-1] == '\n')
2928 DEBUG_printf(("9ppd_read: LINE=\"%s\"", line
->buffer
));
2931 * The dynamically created PPDs for older style Mac OS X
2932 * drivers include a large blob of data inserted as comments
2933 * at the end of the file. As an optimization we can stop
2934 * reading the PPD when we get to the start of this data.
2937 if (!strcmp(line
->buffer
, "*%APLWORKSET START"))
2940 if (ch
== EOF
&& lineptr
== line
->buffer
)
2948 lineptr
= line
->buffer
+ 1;
2955 if ((!line
->buffer
[0] || /* Blank line */
2956 !strncmp(line
->buffer
, "*%", 2) || /* Comment line */
2957 !strcmp(line
->buffer
, "*End")) && /* End of multi-line string */
2958 ignoreblank
) /* Ignore these? */
2960 startline
= cg
->ppd_line
+ 1;
2964 if (!strcmp(line
->buffer
, "*")) /* (Bad) comment line */
2966 if (cg
->ppd_conform
== PPD_CONFORM_RELAXED
)
2968 startline
= cg
->ppd_line
+ 1;
2973 cg
->ppd_line
= startline
;
2974 cg
->ppd_status
= PPD_ILLEGAL_MAIN_KEYWORD
;
2980 if (line
->buffer
[0] != '*') /* All lines start with an asterisk */
2983 * Allow lines consisting of just whitespace...
2986 for (lineptr
= line
->buffer
; *lineptr
; lineptr
++)
2987 if (*lineptr
&& !_cups_isspace(*lineptr
))
2992 cg
->ppd_status
= PPD_MISSING_ASTERISK
;
2995 else if (ignoreblank
)
3007 while (*lineptr
&& *lineptr
!= ':' && !_cups_isspace(*lineptr
))
3009 if (*lineptr
<= ' ' || *lineptr
> 126 || *lineptr
== '/' ||
3010 (keyptr
- keyword
) >= (PPD_MAX_NAME
- 1))
3012 cg
->ppd_status
= PPD_ILLEGAL_MAIN_KEYWORD
;
3016 *keyptr
++ = *lineptr
++;
3021 if (!strcmp(keyword
, "End"))
3024 mask
|= PPD_KEYWORD
;
3026 if (_cups_isspace(*lineptr
))
3029 * Get an option name...
3032 while (_cups_isspace(*lineptr
))
3037 while (*lineptr
&& !_cups_isspace(*lineptr
) && *lineptr
!= ':' &&
3040 if (*lineptr
<= ' ' || *lineptr
> 126 ||
3041 (optptr
- option
) >= (PPD_MAX_NAME
- 1))
3043 cg
->ppd_status
= PPD_ILLEGAL_OPTION_KEYWORD
;
3047 *optptr
++ = *lineptr
++;
3052 if (_cups_isspace(*lineptr
) && cg
->ppd_conform
== PPD_CONFORM_STRICT
)
3054 cg
->ppd_status
= PPD_ILLEGAL_WHITESPACE
;
3058 while (_cups_isspace(*lineptr
))
3063 if (*lineptr
== '/')
3066 * Get human-readable text...
3073 while (*lineptr
!= '\0' && *lineptr
!= '\n' && *lineptr
!= ':')
3075 if (((unsigned char)*lineptr
< ' ' && *lineptr
!= '\t') ||
3076 (textptr
- text
) >= (PPD_MAX_LINE
- 1))
3078 cg
->ppd_status
= PPD_ILLEGAL_TRANSLATION
;
3082 *textptr
++ = *lineptr
++;
3086 textlen
= ppd_decode(text
);
3088 if (textlen
> PPD_MAX_TEXT
&& cg
->ppd_conform
== PPD_CONFORM_STRICT
)
3090 cg
->ppd_status
= PPD_ILLEGAL_TRANSLATION
;
3098 if (_cups_isspace(*lineptr
) && cg
->ppd_conform
== PPD_CONFORM_STRICT
)
3100 cg
->ppd_status
= PPD_ILLEGAL_WHITESPACE
;
3104 while (_cups_isspace(*lineptr
))
3107 if (*lineptr
== ':')
3110 * Get string after triming leading and trailing whitespace...
3114 while (_cups_isspace(*lineptr
))
3117 strptr
= lineptr
+ strlen(lineptr
) - 1;
3118 while (strptr
>= lineptr
&& _cups_isspace(*strptr
))
3121 if (*strptr
== '\"')
3124 * Quoted string by itself, remove quotes...
3131 *string
= _cupsStrAlloc(lineptr
);
3143 * End of "$Id: ppd.c 7906 2008-09-03 20:19:43Z mike $".