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 "ppd-private.h"
63 #include "pwg-private.h"
73 #if defined(WIN32) || defined(__EMX__)
74 # define READ_BINARY "rb" /* Open a binary file for reading */
75 # define WRITE_BINARY "wb" /* Open a binary file for writing */
77 # define READ_BINARY "r" /* Open a binary file for reading */
78 # define WRITE_BINARY "w" /* Open a binary file for writing */
79 #endif /* WIN32 || __EMX__ */
81 #define ppd_free(p) if (p) free(p) /* Safe free macro */
83 #define PPD_KEYWORD 1 /* Line contained a keyword */
84 #define PPD_OPTION 2 /* Line contained an option name */
85 #define PPD_TEXT 4 /* Line contained human-readable text */
86 #define PPD_STRING 8 /* Line contained a string or code */
88 #define PPD_HASHSIZE 512 /* Size of hash */
92 * Line buffer structure...
95 typedef struct _ppd_line_s
97 char *buffer
; /* Pointer to buffer */
98 size_t bufsize
; /* Size of the buffer */
106 static ppd_attr_t
*ppd_add_attr(ppd_file_t
*ppd
, const char *name
,
107 const char *spec
, const char *text
,
109 static ppd_choice_t
*ppd_add_choice(ppd_option_t
*option
, const char *name
);
110 static ppd_size_t
*ppd_add_size(ppd_file_t
*ppd
, const char *name
);
111 static int ppd_compare_attrs(ppd_attr_t
*a
, ppd_attr_t
*b
);
112 static int ppd_compare_choices(ppd_choice_t
*a
, ppd_choice_t
*b
);
113 static int ppd_compare_coptions(ppd_coption_t
*a
,
115 static int ppd_compare_cparams(ppd_cparam_t
*a
, ppd_cparam_t
*b
);
116 static int ppd_compare_options(ppd_option_t
*a
, ppd_option_t
*b
);
117 static int ppd_decode(char *string
);
118 static void ppd_free_group(ppd_group_t
*group
);
119 static void ppd_free_option(ppd_option_t
*option
);
120 static ppd_coption_t
*ppd_get_coption(ppd_file_t
*ppd
, const char *name
);
121 static ppd_cparam_t
*ppd_get_cparam(ppd_coption_t
*opt
,
124 static ppd_group_t
*ppd_get_group(ppd_file_t
*ppd
, const char *name
,
125 const char *text
, _cups_globals_t
*cg
,
126 cups_encoding_t encoding
);
127 static ppd_option_t
*ppd_get_option(ppd_group_t
*group
, const char *name
);
128 static int ppd_hash_option(ppd_option_t
*option
);
129 static int ppd_read(cups_file_t
*fp
, _ppd_line_t
*line
,
130 char *keyword
, char *option
, char *text
,
131 char **string
, int ignoreblank
,
132 _cups_globals_t
*cg
);
136 * 'ppdClose()' - Free all memory used by the PPD file.
140 ppdClose(ppd_file_t
*ppd
) /* I - PPD file record */
142 int i
; /* Looping var */
143 ppd_emul_t
*emul
; /* Current emulation */
144 ppd_group_t
*group
; /* Current group */
145 char **font
; /* Current font */
146 char **filter
; /* Current filter */
147 ppd_attr_t
**attr
; /* Current attribute */
148 ppd_coption_t
*coption
; /* Current custom option */
149 ppd_cparam_t
*cparam
; /* Current custom parameter */
153 * Range check arguments...
160 * Free all strings at the top level...
163 _cupsStrFree(ppd
->lang_encoding
);
164 _cupsStrFree(ppd
->nickname
);
167 _cupsStrFree(ppd
->jcl_begin
);
168 _cupsStrFree(ppd
->jcl_end
);
169 _cupsStrFree(ppd
->jcl_ps
);
172 * Free any emulations...
175 if (ppd
->num_emulations
> 0)
177 for (i
= ppd
->num_emulations
, emul
= ppd
->emulations
; i
> 0; i
--, emul
++)
179 _cupsStrFree(emul
->start
);
180 _cupsStrFree(emul
->stop
);
183 ppd_free(ppd
->emulations
);
187 * Free any UI groups, subgroups, and options...
190 if (ppd
->num_groups
> 0)
192 for (i
= ppd
->num_groups
, group
= ppd
->groups
; i
> 0; i
--, group
++)
193 ppd_free_group(group
);
195 ppd_free(ppd
->groups
);
198 cupsArrayDelete(ppd
->options
);
199 cupsArrayDelete(ppd
->marked
);
202 * Free any page sizes...
205 if (ppd
->num_sizes
> 0)
206 ppd_free(ppd
->sizes
);
209 * Free any constraints...
212 if (ppd
->num_consts
> 0)
213 ppd_free(ppd
->consts
);
216 * Free any filters...
219 if (ppd
->num_filters
> 0)
221 for (i
= ppd
->num_filters
, filter
= ppd
->filters
; i
> 0; i
--, filter
++)
222 _cupsStrFree(*filter
);
224 ppd_free(ppd
->filters
);
231 if (ppd
->num_fonts
> 0)
233 for (i
= ppd
->num_fonts
, font
= ppd
->fonts
; i
> 0; i
--, font
++)
236 ppd_free(ppd
->fonts
);
240 * Free any profiles...
243 if (ppd
->num_profiles
> 0)
244 ppd_free(ppd
->profiles
);
247 * Free any attributes...
250 if (ppd
->num_attrs
> 0)
252 for (i
= ppd
->num_attrs
, attr
= ppd
->attrs
; i
> 0; i
--, attr
++)
254 _cupsStrFree((*attr
)->value
);
258 ppd_free(ppd
->attrs
);
261 cupsArrayDelete(ppd
->sorted_attrs
);
264 * Free custom options...
267 for (coption
= (ppd_coption_t
*)cupsArrayFirst(ppd
->coptions
);
269 coption
= (ppd_coption_t
*)cupsArrayNext(ppd
->coptions
))
271 for (cparam
= (ppd_cparam_t
*)cupsArrayFirst(coption
->params
);
273 cparam
= (ppd_cparam_t
*)cupsArrayNext(coption
->params
))
275 switch (cparam
->type
)
277 case PPD_CUSTOM_PASSCODE
:
278 case PPD_CUSTOM_PASSWORD
:
279 case PPD_CUSTOM_STRING
:
280 _cupsStrFree(cparam
->current
.custom_string
);
290 cupsArrayDelete(coption
->params
);
295 cupsArrayDelete(ppd
->coptions
);
298 * Free constraints...
301 if (ppd
->cups_uiconstraints
)
303 _ppd_cups_uiconsts_t
*consts
; /* Current constraints */
306 for (consts
= (_ppd_cups_uiconsts_t
*)cupsArrayFirst(ppd
->cups_uiconstraints
);
308 consts
= (_ppd_cups_uiconsts_t
*)cupsArrayNext(ppd
->cups_uiconstraints
))
310 free(consts
->constraints
);
314 cupsArrayDelete(ppd
->cups_uiconstraints
);
318 * Free any PWG mapping data...
322 _pwgDestroy((_pwg_t
*)ppd
->pwg
);
325 * Free the whole record...
333 * 'ppdErrorString()' - Returns the text assocated with a status.
335 * @since CUPS 1.1.19/Mac OS X 10.3@
338 const char * /* O - Status string */
339 ppdErrorString(ppd_status_t status
) /* I - PPD status */
341 static const char * const messages
[] =/* Status messages */
344 _("Unable to open PPD file"),
345 _("NULL PPD file pointer"),
346 _("Memory allocation error"),
347 _("Missing PPD-Adobe-4.x header"),
348 _("Missing value string"),
351 _("OpenGroup without a CloseGroup first"),
352 _("Bad OpenUI/JCLOpenUI"),
353 _("OpenUI/JCLOpenUI without a CloseUI/JCLCloseUI first"),
354 _("Bad OrderDependency"),
355 _("Bad UIConstraints"),
356 _("Missing asterisk in column 1"),
357 _("Line longer than the maximum allowed (255 characters)"),
358 _("Illegal control character"),
359 _("Illegal main keyword string"),
360 _("Illegal option keyword string"),
361 _("Illegal translation string"),
362 _("Illegal whitespace character"),
363 _("Bad custom parameter"),
364 _("Missing option keyword"),
365 _("Bad value string")
369 if (status
< PPD_OK
|| status
>= PPD_MAX_STATUS
)
370 return (_cupsLangString(cupsLangDefault(), _("Unknown")));
372 return (_cupsLangString(cupsLangDefault(), messages
[status
]));
377 * '_ppdGetEncoding()' - Get the CUPS encoding value for the given
381 cups_encoding_t
/* O - CUPS encoding value */
382 _ppdGetEncoding(const char *name
) /* I - LanguageEncoding string */
384 if (!strcasecmp(name
, "ISOLatin1"))
385 return (CUPS_ISO8859_1
);
386 else if (!strcasecmp(name
, "ISOLatin2"))
387 return (CUPS_ISO8859_2
);
388 else if (!strcasecmp(name
, "ISOLatin5"))
389 return (CUPS_ISO8859_5
);
390 else if (!strcasecmp(name
, "JIS83-RKSJ"))
391 return (CUPS_JIS_X0213
);
392 else if (!strcasecmp(name
, "MacStandard"))
393 return (CUPS_MAC_ROMAN
);
394 else if (!strcasecmp(name
, "WindowsANSI"))
395 return (CUPS_WINDOWS_1252
);
402 * 'ppdLastError()' - Return the status from the last ppdOpen*().
404 * @since CUPS 1.1.19/Mac OS X 10.3@
407 ppd_status_t
/* O - Status code */
408 ppdLastError(int *line
) /* O - Line number */
410 _cups_globals_t
*cg
= _cupsGlobals();
415 *line
= cg
->ppd_line
;
417 return (cg
->ppd_status
);
422 * 'ppdOpen()' - Read a PPD file into memory.
425 ppd_file_t
* /* O - PPD file record */
426 ppdOpen(FILE *fp
) /* I - File to read from */
428 ppd_file_t
*ppd
; /* PPD file record */
429 cups_file_t
*cf
; /* CUPS file */
433 * Reopen the stdio file as a CUPS file...
436 if ((cf
= cupsFileOpenFd(fileno(fp
), "r")) == NULL
)
440 * Load the PPD file using the newer API...
446 * Close the CUPS file and return the PPD...
456 * 'ppdOpen2()' - Read a PPD file into memory.
458 * @since CUPS 1.2/Mac OS X 10.5@
461 ppd_file_t
* /* O - PPD file record or @code NULL@ if the PPD file could not be opened. */
462 ppdOpen2(cups_file_t
*fp
) /* I - File to read from */
464 int i
, j
, k
; /* Looping vars */
465 int count
; /* Temporary count */
466 _ppd_line_t line
; /* Line buffer */
467 ppd_file_t
*ppd
; /* PPD file record */
468 ppd_group_t
*group
, /* Current group */
469 *subgroup
; /* Current sub-group */
470 ppd_option_t
*option
; /* Current option */
471 ppd_choice_t
*choice
; /* Current choice */
472 ppd_const_t
*constraint
; /* Current constraint */
473 ppd_size_t
*size
; /* Current page size */
474 int mask
; /* Line data mask */
475 char keyword
[PPD_MAX_NAME
],
476 /* Keyword from file */
478 /* Option from file */
480 /* Human-readable text from file */
481 *string
, /* Code/text from file */
482 *sptr
, /* Pointer into string */
483 *nameptr
, /* Pointer into name */
484 *temp
, /* Temporary string pointer */
485 **tempfonts
; /* Temporary fonts pointer */
486 float order
; /* Order dependency number */
487 ppd_section_t section
; /* Order dependency section */
488 ppd_profile_t
*profile
; /* Pointer to color profile */
489 char **filter
; /* Pointer to filter */
490 cups_lang_t
*language
; /* Default language */
491 struct lconv
*loc
; /* Locale data */
492 int ui_keyword
; /* Is this line a UI keyword? */
493 cups_encoding_t encoding
; /* Encoding of PPD file */
494 _cups_globals_t
*cg
= _cupsGlobals();
496 char custom_name
[PPD_MAX_NAME
];
497 /* CustomFoo attribute name */
498 ppd_attr_t
*custom_attr
; /* CustomFoo attribute */
499 static const char * const ui_keywords
[] =
501 #ifdef CUPS_USE_FULL_UI_KEYWORDS_LIST
503 * Adobe defines some 41 keywords as "UI", meaning that they are
504 * user interface elements and that they should be treated as such
505 * even if the PPD creator doesn't use Open/CloseUI around them.
507 * Since this can cause previously invisible options to appear and
508 * confuse users, the default is to only treat the PageSize and
509 * PageRegion keywords this way.
511 /* Boolean keywords */
521 /* PickOne keywords */
534 "JCLFrameBufferSize",
555 #else /* !CUPS_USE_FULL_UI_KEYWORDS_LIST */
558 #endif /* CUPS_USE_FULL_UI_KEYWORDS_LIST */
562 DEBUG_printf(("ppdOpen2(fp=%p)", fp
));
565 * Default to "OK" status...
568 cg
->ppd_status
= PPD_OK
;
572 * Range check input...
577 cg
->ppd_status
= PPD_NULL_FILE
;
582 * Grab the first line and make sure it reads '*PPD-Adobe: "major.minor"'...
588 mask
= ppd_read(fp
, &line
, keyword
, name
, text
, &string
, 0, cg
);
590 DEBUG_printf(("2ppdOpen2: mask=%x, keyword=\"%s\"...", mask
, keyword
));
593 strcmp(keyword
, "PPD-Adobe") ||
594 string
== NULL
|| string
[0] != '4')
597 * Either this is not a PPD file, or it is not a 4.x PPD file.
600 if (cg
->ppd_status
== PPD_OK
)
601 cg
->ppd_status
= PPD_MISSING_PPDADOBE4
;
603 _cupsStrFree(string
);
604 ppd_free(line
.buffer
);
609 DEBUG_printf(("2ppdOpen2: keyword=%s, string=%p", keyword
, string
));
611 _cupsStrFree(string
);
614 * Allocate memory for the PPD file record...
617 if ((ppd
= calloc(1, sizeof(ppd_file_t
))) == NULL
)
619 cg
->ppd_status
= PPD_ALLOC_ERROR
;
621 _cupsStrFree(string
);
622 ppd_free(line
.buffer
);
627 ppd
->language_level
= 2;
628 ppd
->color_device
= 0;
629 ppd
->colorspace
= PPD_CS_N
;
630 ppd
->landscape
= -90;
631 ppd
->coptions
= cupsArrayNew((cups_array_func_t
)ppd_compare_coptions
,
635 * Get the default language for the user...
638 language
= cupsLangDefault();
642 * Read lines from the PPD file and add them to the file record...
650 encoding
= CUPS_ISO8859_1
;
652 while ((mask
= ppd_read(fp
, &line
, keyword
, name
, text
, &string
, 1, cg
)) != 0)
654 DEBUG_printf(("2ppdOpen2: mask=%x, keyword=\"%s\", name=\"%s\", "
655 "text=\"%s\", string=%d chars...", mask
, keyword
, name
, text
,
656 string
? (int)strlen(string
) : 0));
658 if (strncmp(keyword
, "Default", 7) && !string
&&
659 cg
->ppd_conform
!= PPD_CONFORM_RELAXED
)
662 * Need a string value!
665 cg
->ppd_status
= PPD_MISSING_VALUE
;
671 * Certain main keywords (as defined by the PPD spec) may be used
672 * without the usual OpenUI/CloseUI stuff. Presumably this is just
673 * so that Adobe wouldn't completely break compatibility with PPD
674 * files prior to v4.0 of the spec, but it is hopelessly
675 * inconsistent... Catch these main keywords and automatically
676 * create the corresponding option, as needed...
682 * Previous line was a UI keyword...
689 if (option
== NULL
&&
690 (mask
& (PPD_KEYWORD
| PPD_OPTION
| PPD_STRING
)) ==
691 (PPD_KEYWORD
| PPD_OPTION
| PPD_STRING
))
693 for (i
= 0; i
< (int)(sizeof(ui_keywords
) / sizeof(ui_keywords
[0])); i
++)
694 if (!strcmp(keyword
, ui_keywords
[i
]))
697 if (i
< (int)(sizeof(ui_keywords
) / sizeof(ui_keywords
[0])))
700 * Create the option in the appropriate group...
705 DEBUG_printf(("2ppdOpen2: FOUND ADOBE UI KEYWORD %s WITHOUT OPENUI!",
710 if ((group
= ppd_get_group(ppd
, "General", _("General"), cg
,
714 DEBUG_printf(("2ppdOpen2: Adding to group %s...", group
->text
));
715 option
= ppd_get_option(group
, keyword
);
719 option
= ppd_get_option(group
, keyword
);
723 cg
->ppd_status
= PPD_ALLOC_ERROR
;
729 * Now fill in the initial information for the option...
732 if (!strncmp(keyword
, "JCL", 3))
733 option
->section
= PPD_ORDER_JCL
;
735 option
->section
= PPD_ORDER_ANY
;
737 option
->order
= 10.0f
;
740 option
->ui
= PPD_UI_BOOLEAN
;
742 option
->ui
= PPD_UI_PICKONE
;
744 for (j
= 0; j
< ppd
->num_attrs
; j
++)
745 if (!strncmp(ppd
->attrs
[j
]->name
, "Default", 7) &&
746 !strcmp(ppd
->attrs
[j
]->name
+ 7, keyword
) &&
747 ppd
->attrs
[j
]->value
)
749 DEBUG_printf(("2ppdOpen2: Setting Default%s to %s via attribute...",
750 option
->keyword
, ppd
->attrs
[j
]->value
));
751 strlcpy(option
->defchoice
, ppd
->attrs
[j
]->value
,
752 sizeof(option
->defchoice
));
756 if (!strcmp(keyword
, "PageSize"))
757 strlcpy(option
->text
, _("Media Size"), sizeof(option
->text
));
758 else if (!strcmp(keyword
, "MediaType"))
759 strlcpy(option
->text
, _("Media Type"), sizeof(option
->text
));
760 else if (!strcmp(keyword
, "InputSlot"))
761 strlcpy(option
->text
, _("Media Source"), sizeof(option
->text
));
762 else if (!strcmp(keyword
, "ColorModel"))
763 strlcpy(option
->text
, _("Output Mode"), sizeof(option
->text
));
764 else if (!strcmp(keyword
, "Resolution"))
765 strlcpy(option
->text
, _("Resolution"), sizeof(option
->text
));
767 strlcpy(option
->text
, keyword
, sizeof(option
->text
));
771 if (!strcmp(keyword
, "LanguageLevel"))
772 ppd
->language_level
= atoi(string
);
773 else if (!strcmp(keyword
, "LanguageEncoding"))
776 * Say all PPD files are UTF-8, since we convert to UTF-8...
779 ppd
->lang_encoding
= _cupsStrAlloc("UTF-8");
780 encoding
= _ppdGetEncoding(string
);
782 else if (!strcmp(keyword
, "LanguageVersion"))
783 ppd
->lang_version
= string
;
784 else if (!strcmp(keyword
, "Manufacturer"))
785 ppd
->manufacturer
= string
;
786 else if (!strcmp(keyword
, "ModelName"))
787 ppd
->modelname
= string
;
788 else if (!strcmp(keyword
, "Protocols"))
789 ppd
->protocols
= string
;
790 else if (!strcmp(keyword
, "PCFileName"))
791 ppd
->pcfilename
= string
;
792 else if (!strcmp(keyword
, "NickName"))
794 if (encoding
!= CUPS_UTF8
)
796 cups_utf8_t utf8
[256]; /* UTF-8 version of NickName */
799 cupsCharsetToUTF8(utf8
, string
, sizeof(utf8
), encoding
);
800 ppd
->nickname
= _cupsStrAlloc((char *)utf8
);
803 ppd
->nickname
= _cupsStrAlloc(string
);
805 else if (!strcmp(keyword
, "Product"))
806 ppd
->product
= string
;
807 else if (!strcmp(keyword
, "ShortNickName"))
808 ppd
->shortnickname
= string
;
809 else if (!strcmp(keyword
, "TTRasterizer"))
810 ppd
->ttrasterizer
= string
;
811 else if (!strcmp(keyword
, "JCLBegin"))
813 ppd
->jcl_begin
= _cupsStrAlloc(string
);
814 ppd_decode(ppd
->jcl_begin
); /* Decode quoted string */
816 else if (!strcmp(keyword
, "JCLEnd"))
818 ppd
->jcl_end
= _cupsStrAlloc(string
);
819 ppd_decode(ppd
->jcl_end
); /* Decode quoted string */
821 else if (!strcmp(keyword
, "JCLToPSInterpreter"))
823 ppd
->jcl_ps
= _cupsStrAlloc(string
);
824 ppd_decode(ppd
->jcl_ps
); /* Decode quoted string */
826 else if (!strcmp(keyword
, "AccurateScreensSupport"))
827 ppd
->accurate_screens
= !strcmp(string
, "True");
828 else if (!strcmp(keyword
, "ColorDevice"))
829 ppd
->color_device
= !strcmp(string
, "True");
830 else if (!strcmp(keyword
, "ContoneOnly"))
831 ppd
->contone_only
= !strcmp(string
, "True");
832 else if (!strcmp(keyword
, "cupsFlipDuplex"))
833 ppd
->flip_duplex
= !strcmp(string
, "True");
834 else if (!strcmp(keyword
, "cupsManualCopies"))
835 ppd
->manual_copies
= !strcmp(string
, "True");
836 else if (!strcmp(keyword
, "cupsModelNumber"))
837 ppd
->model_number
= atoi(string
);
838 else if (!strcmp(keyword
, "cupsColorProfile"))
840 if (ppd
->num_profiles
== 0)
841 profile
= malloc(sizeof(ppd_profile_t
));
843 profile
= realloc(ppd
->profiles
, sizeof(ppd_profile_t
) *
844 (ppd
->num_profiles
+ 1));
848 cg
->ppd_status
= PPD_ALLOC_ERROR
;
853 ppd
->profiles
= profile
;
854 profile
+= ppd
->num_profiles
;
855 ppd
->num_profiles
++;
857 memset(profile
, 0, sizeof(ppd_profile_t
));
858 strlcpy(profile
->resolution
, name
, sizeof(profile
->resolution
));
859 strlcpy(profile
->media_type
, text
, sizeof(profile
->media_type
));
861 profile
->density
= (float)_cupsStrScand(string
, &sptr
, loc
);
862 profile
->gamma
= (float)_cupsStrScand(sptr
, &sptr
, loc
);
863 profile
->matrix
[0][0] = (float)_cupsStrScand(sptr
, &sptr
, loc
);
864 profile
->matrix
[0][1] = (float)_cupsStrScand(sptr
, &sptr
, loc
);
865 profile
->matrix
[0][2] = (float)_cupsStrScand(sptr
, &sptr
, loc
);
866 profile
->matrix
[1][0] = (float)_cupsStrScand(sptr
, &sptr
, loc
);
867 profile
->matrix
[1][1] = (float)_cupsStrScand(sptr
, &sptr
, loc
);
868 profile
->matrix
[1][2] = (float)_cupsStrScand(sptr
, &sptr
, loc
);
869 profile
->matrix
[2][0] = (float)_cupsStrScand(sptr
, &sptr
, loc
);
870 profile
->matrix
[2][1] = (float)_cupsStrScand(sptr
, &sptr
, loc
);
871 profile
->matrix
[2][2] = (float)_cupsStrScand(sptr
, &sptr
, loc
);
873 else if (!strcmp(keyword
, "cupsFilter"))
875 if (ppd
->num_filters
== 0)
876 filter
= malloc(sizeof(char *));
878 filter
= realloc(ppd
->filters
, sizeof(char *) * (ppd
->num_filters
+ 1));
882 cg
->ppd_status
= PPD_ALLOC_ERROR
;
887 ppd
->filters
= filter
;
888 filter
+= ppd
->num_filters
;
892 * Copy filter string and prevent it from being freed below...
898 else if (!strcmp(keyword
, "Throughput"))
899 ppd
->throughput
= atoi(string
);
900 else if (!strcmp(keyword
, "Font"))
903 * Add this font to the list of available fonts...
906 if (ppd
->num_fonts
== 0)
907 tempfonts
= (char **)malloc(sizeof(char *));
909 tempfonts
= (char **)realloc(ppd
->fonts
,
910 sizeof(char *) * (ppd
->num_fonts
+ 1));
912 if (tempfonts
== NULL
)
914 cg
->ppd_status
= PPD_ALLOC_ERROR
;
919 ppd
->fonts
= tempfonts
;
920 ppd
->fonts
[ppd
->num_fonts
] = _cupsStrAlloc(name
);
923 else if (!strncmp(keyword
, "ParamCustom", 11))
925 ppd_coption_t
*coption
; /* Custom option */
926 ppd_cparam_t
*cparam
; /* Custom parameter */
927 int corder
; /* Order number */
928 char ctype
[33], /* Data type */
929 cminimum
[65], /* Minimum value */
930 cmaximum
[65]; /* Maximum value */
934 * Get the custom option and parameter...
937 if ((coption
= ppd_get_coption(ppd
, keyword
+ 11)) == NULL
)
939 cg
->ppd_status
= PPD_ALLOC_ERROR
;
944 if ((cparam
= ppd_get_cparam(coption
, name
, text
)) == NULL
)
946 cg
->ppd_status
= PPD_ALLOC_ERROR
;
952 * Get the parameter data...
956 sscanf(string
, "%d%32s%64s%64s", &corder
, ctype
, cminimum
,
959 cg
->ppd_status
= PPD_BAD_CUSTOM_PARAM
;
964 cparam
->order
= corder
;
966 if (!strcmp(ctype
, "curve"))
968 cparam
->type
= PPD_CUSTOM_CURVE
;
969 cparam
->minimum
.custom_curve
= (float)_cupsStrScand(cminimum
, NULL
, loc
);
970 cparam
->maximum
.custom_curve
= (float)_cupsStrScand(cmaximum
, NULL
, loc
);
972 else if (!strcmp(ctype
, "int"))
974 cparam
->type
= PPD_CUSTOM_INT
;
975 cparam
->minimum
.custom_int
= atoi(cminimum
);
976 cparam
->maximum
.custom_int
= atoi(cmaximum
);
978 else if (!strcmp(ctype
, "invcurve"))
980 cparam
->type
= PPD_CUSTOM_INVCURVE
;
981 cparam
->minimum
.custom_invcurve
= (float)_cupsStrScand(cminimum
, NULL
, loc
);
982 cparam
->maximum
.custom_invcurve
= (float)_cupsStrScand(cmaximum
, NULL
, loc
);
984 else if (!strcmp(ctype
, "passcode"))
986 cparam
->type
= PPD_CUSTOM_PASSCODE
;
987 cparam
->minimum
.custom_passcode
= atoi(cminimum
);
988 cparam
->maximum
.custom_passcode
= atoi(cmaximum
);
990 else if (!strcmp(ctype
, "password"))
992 cparam
->type
= PPD_CUSTOM_PASSWORD
;
993 cparam
->minimum
.custom_password
= atoi(cminimum
);
994 cparam
->maximum
.custom_password
= atoi(cmaximum
);
996 else if (!strcmp(ctype
, "points"))
998 cparam
->type
= PPD_CUSTOM_POINTS
;
999 cparam
->minimum
.custom_points
= (float)_cupsStrScand(cminimum
, NULL
, loc
);
1000 cparam
->maximum
.custom_points
= (float)_cupsStrScand(cmaximum
, NULL
, loc
);
1002 else if (!strcmp(ctype
, "real"))
1004 cparam
->type
= PPD_CUSTOM_REAL
;
1005 cparam
->minimum
.custom_real
= (float)_cupsStrScand(cminimum
, NULL
, loc
);
1006 cparam
->maximum
.custom_real
= (float)_cupsStrScand(cmaximum
, NULL
, loc
);
1008 else if (!strcmp(ctype
, "string"))
1010 cparam
->type
= PPD_CUSTOM_STRING
;
1011 cparam
->minimum
.custom_string
= atoi(cminimum
);
1012 cparam
->maximum
.custom_string
= atoi(cmaximum
);
1016 cg
->ppd_status
= PPD_BAD_CUSTOM_PARAM
;
1022 * Now special-case for CustomPageSize...
1025 if (!strcmp(coption
->keyword
, "PageSize"))
1027 if (!strcmp(name
, "Width"))
1029 ppd
->custom_min
[0] = cparam
->minimum
.custom_points
;
1030 ppd
->custom_max
[0] = cparam
->maximum
.custom_points
;
1032 else if (!strcmp(name
, "Height"))
1034 ppd
->custom_min
[1] = cparam
->minimum
.custom_points
;
1035 ppd
->custom_max
[1] = cparam
->maximum
.custom_points
;
1039 else if (!strcmp(keyword
, "HWMargins"))
1041 for (i
= 0, sptr
= string
; i
< 4; i
++)
1042 ppd
->custom_margins
[i
] = (float)_cupsStrScand(sptr
, &sptr
, loc
);
1044 else if (!strncmp(keyword
, "Custom", 6) && !strcmp(name
, "True") && !option
)
1046 ppd_option_t
*custom_option
; /* Custom option */
1048 DEBUG_puts("2ppdOpen2: Processing Custom option...");
1051 * Get the option and custom option...
1054 if (!ppd_get_coption(ppd
, keyword
+ 6))
1056 cg
->ppd_status
= PPD_ALLOC_ERROR
;
1061 if (option
&& !strcasecmp(option
->keyword
, keyword
+ 6))
1062 custom_option
= option
;
1064 custom_option
= ppdFindOption(ppd
, keyword
+ 6);
1069 * Add the "custom" option...
1072 if ((choice
= ppdFindChoice(custom_option
, "Custom")) == NULL
)
1073 if ((choice
= ppd_add_choice(custom_option
, "Custom")) == NULL
)
1075 DEBUG_puts("1ppdOpen2: Unable to add Custom choice!");
1077 cg
->ppd_status
= PPD_ALLOC_ERROR
;
1082 strlcpy(choice
->text
, text
[0] ? text
: _("Custom"),
1083 sizeof(choice
->text
));
1085 choice
->code
= _cupsStrAlloc(string
);
1087 if (custom_option
->section
== PPD_ORDER_JCL
)
1088 ppd_decode(choice
->code
);
1092 * Now process custom page sizes specially...
1095 if (!strcmp(keyword
, "CustomPageSize"))
1098 * Add a "Custom" page size entry...
1101 ppd
->variable_sizes
= 1;
1103 ppd_add_size(ppd
, "Custom");
1105 if (option
&& !strcasecmp(option
->keyword
, "PageRegion"))
1106 custom_option
= option
;
1108 custom_option
= ppdFindOption(ppd
, "PageRegion");
1112 if ((choice
= ppdFindChoice(custom_option
, "Custom")) == NULL
)
1113 if ((choice
= ppd_add_choice(custom_option
, "Custom")) == NULL
)
1115 DEBUG_puts("1ppdOpen2: Unable to add Custom choice!");
1117 cg
->ppd_status
= PPD_ALLOC_ERROR
;
1122 strlcpy(choice
->text
, text
[0] ? text
: _("Custom"),
1123 sizeof(choice
->text
));
1127 else if (!strcmp(keyword
, "LandscapeOrientation"))
1129 if (!strcmp(string
, "Minus90"))
1130 ppd
->landscape
= -90;
1131 else if (!strcmp(string
, "Plus90"))
1132 ppd
->landscape
= 90;
1134 else if (!strcmp(keyword
, "Emulators") && string
)
1136 for (count
= 1, sptr
= string
; sptr
!= NULL
;)
1137 if ((sptr
= strchr(sptr
, ' ')) != NULL
)
1140 while (*sptr
== ' ')
1144 ppd
->num_emulations
= count
;
1145 if ((ppd
->emulations
= calloc(count
, sizeof(ppd_emul_t
))) == NULL
)
1147 cg
->ppd_status
= PPD_ALLOC_ERROR
;
1152 for (i
= 0, sptr
= string
; i
< count
; i
++)
1154 for (nameptr
= ppd
->emulations
[i
].name
;
1155 *sptr
!= '\0' && *sptr
!= ' ';
1157 if (nameptr
< (ppd
->emulations
[i
].name
+ sizeof(ppd
->emulations
[i
].name
) - 1))
1162 while (*sptr
== ' ')
1166 else if (!strncmp(keyword
, "StartEmulator_", 14))
1170 for (i
= 0; i
< ppd
->num_emulations
; i
++)
1171 if (!strcmp(keyword
+ 14, ppd
->emulations
[i
].name
))
1173 ppd
->emulations
[i
].start
= string
;
1177 else if (!strncmp(keyword
, "StopEmulator_", 13))
1181 for (i
= 0; i
< ppd
->num_emulations
; i
++)
1182 if (!strcmp(keyword
+ 13, ppd
->emulations
[i
].name
))
1184 ppd
->emulations
[i
].stop
= string
;
1188 else if (!strcmp(keyword
, "JobPatchFile"))
1191 * CUPS STR #3421: Check for "*JobPatchFile: int: string"
1194 if (isdigit(*string
& 255))
1196 for (sptr
= string
+ 1; isdigit(*sptr
& 255); sptr
++);
1201 * Found "*JobPatchFile: int: string"...
1204 cg
->ppd_status
= PPD_BAD_VALUE
;
1213 * Found "*JobPatchFile: string"...
1216 cg
->ppd_status
= PPD_MISSING_OPTION_KEYWORD
;
1221 if (ppd
->patches
== NULL
)
1222 ppd
->patches
= strdup(string
);
1225 temp
= realloc(ppd
->patches
, strlen(ppd
->patches
) +
1226 strlen(string
) + 1);
1229 cg
->ppd_status
= PPD_ALLOC_ERROR
;
1234 ppd
->patches
= temp
;
1236 strcpy(ppd
->patches
+ strlen(ppd
->patches
), string
);
1239 else if (!strcmp(keyword
, "OpenUI"))
1242 * Don't allow nesting of options...
1245 if (option
&& cg
->ppd_conform
== PPD_CONFORM_STRICT
)
1247 cg
->ppd_status
= PPD_NESTED_OPEN_UI
;
1253 * Add an option record to the current sub-group, group, or file...
1256 DEBUG_printf(("2ppdOpen2: name=\"%s\" (%d)", name
, (int)strlen(name
)));
1259 _cups_strcpy(name
, name
+ 1); /* Eliminate leading asterisk */
1261 for (i
= (int)strlen(name
) - 1; i
> 0 && isspace(name
[i
] & 255); i
--)
1262 name
[i
] = '\0'; /* Eliminate trailing spaces */
1264 DEBUG_printf(("2ppdOpen2: OpenUI of %s in group %s...", name
,
1265 group
? group
->text
: "(null)"));
1267 if (subgroup
!= NULL
)
1268 option
= ppd_get_option(subgroup
, name
);
1269 else if (group
== NULL
)
1271 if ((group
= ppd_get_group(ppd
, "General", _("General"), cg
,
1275 DEBUG_printf(("2ppdOpen2: Adding to group %s...", group
->text
));
1276 option
= ppd_get_option(group
, name
);
1280 option
= ppd_get_option(group
, name
);
1284 cg
->ppd_status
= PPD_ALLOC_ERROR
;
1290 * Now fill in the initial information for the option...
1293 if (string
&& !strcmp(string
, "PickMany"))
1294 option
->ui
= PPD_UI_PICKMANY
;
1295 else if (string
&& !strcmp(string
, "Boolean"))
1296 option
->ui
= PPD_UI_BOOLEAN
;
1297 else if (string
&& !strcmp(string
, "PickOne"))
1298 option
->ui
= PPD_UI_PICKONE
;
1299 else if (cg
->ppd_conform
== PPD_CONFORM_STRICT
)
1301 cg
->ppd_status
= PPD_BAD_OPEN_UI
;
1306 option
->ui
= PPD_UI_PICKONE
;
1308 for (j
= 0; j
< ppd
->num_attrs
; j
++)
1309 if (!strncmp(ppd
->attrs
[j
]->name
, "Default", 7) &&
1310 !strcmp(ppd
->attrs
[j
]->name
+ 7, name
) &&
1311 ppd
->attrs
[j
]->value
)
1313 DEBUG_printf(("2ppdOpen2: Setting Default%s to %s via attribute...",
1314 option
->keyword
, ppd
->attrs
[j
]->value
));
1315 strlcpy(option
->defchoice
, ppd
->attrs
[j
]->value
,
1316 sizeof(option
->defchoice
));
1321 cupsCharsetToUTF8((cups_utf8_t
*)option
->text
, text
,
1322 sizeof(option
->text
), encoding
);
1325 if (!strcmp(name
, "PageSize"))
1326 strlcpy(option
->text
, _("Media Size"), sizeof(option
->text
));
1327 else if (!strcmp(name
, "MediaType"))
1328 strlcpy(option
->text
, _("Media Type"), sizeof(option
->text
));
1329 else if (!strcmp(name
, "InputSlot"))
1330 strlcpy(option
->text
, _("Media Source"), sizeof(option
->text
));
1331 else if (!strcmp(name
, "ColorModel"))
1332 strlcpy(option
->text
, _("Output Mode"), sizeof(option
->text
));
1333 else if (!strcmp(name
, "Resolution"))
1334 strlcpy(option
->text
, _("Resolution"), sizeof(option
->text
));
1336 strlcpy(option
->text
, name
, sizeof(option
->text
));
1339 option
->section
= PPD_ORDER_ANY
;
1341 _cupsStrFree(string
);
1345 * Add a custom option choice if we have already seen a CustomFoo
1349 if (!strcasecmp(name
, "PageRegion"))
1350 strcpy(custom_name
, "CustomPageSize");
1352 snprintf(custom_name
, sizeof(custom_name
), "Custom%s", name
);
1354 if ((custom_attr
= ppdFindAttr(ppd
, custom_name
, "True")) != NULL
)
1356 if ((choice
= ppdFindChoice(option
, "Custom")) == NULL
)
1357 if ((choice
= ppd_add_choice(option
, "Custom")) == NULL
)
1359 DEBUG_puts("1ppdOpen2: Unable to add Custom choice!");
1361 cg
->ppd_status
= PPD_ALLOC_ERROR
;
1366 strlcpy(choice
->text
,
1367 custom_attr
->text
[0] ? custom_attr
->text
: _("Custom"),
1368 sizeof(choice
->text
));
1369 choice
->code
= _cupsStrRetain(custom_attr
->value
);
1372 else if (!strcmp(keyword
, "JCLOpenUI"))
1375 * Don't allow nesting of options...
1378 if (option
&& cg
->ppd_conform
== PPD_CONFORM_STRICT
)
1380 cg
->ppd_status
= PPD_NESTED_OPEN_UI
;
1386 * Find the JCL group, and add if needed...
1389 group
= ppd_get_group(ppd
, "JCL", _("JCL"), cg
, encoding
);
1395 * Add an option record to the current JCLs...
1399 _cups_strcpy(name
, name
+ 1);
1401 option
= ppd_get_option(group
, name
);
1405 cg
->ppd_status
= PPD_ALLOC_ERROR
;
1411 * Now fill in the initial information for the option...
1414 if (string
&& !strcmp(string
, "PickMany"))
1415 option
->ui
= PPD_UI_PICKMANY
;
1416 else if (string
&& !strcmp(string
, "Boolean"))
1417 option
->ui
= PPD_UI_BOOLEAN
;
1418 else if (string
&& !strcmp(string
, "PickOne"))
1419 option
->ui
= PPD_UI_PICKONE
;
1422 cg
->ppd_status
= PPD_BAD_OPEN_UI
;
1427 for (j
= 0; j
< ppd
->num_attrs
; j
++)
1428 if (!strncmp(ppd
->attrs
[j
]->name
, "Default", 7) &&
1429 !strcmp(ppd
->attrs
[j
]->name
+ 7, name
) &&
1430 ppd
->attrs
[j
]->value
)
1432 DEBUG_printf(("2ppdOpen2: Setting Default%s to %s via attribute...",
1433 option
->keyword
, ppd
->attrs
[j
]->value
));
1434 strlcpy(option
->defchoice
, ppd
->attrs
[j
]->value
,
1435 sizeof(option
->defchoice
));
1440 cupsCharsetToUTF8((cups_utf8_t
*)option
->text
, text
,
1441 sizeof(option
->text
), encoding
);
1443 strlcpy(option
->text
, name
, sizeof(option
->text
));
1445 option
->section
= PPD_ORDER_JCL
;
1448 _cupsStrFree(string
);
1452 * Add a custom option choice if we have already seen a CustomFoo
1456 snprintf(custom_name
, sizeof(custom_name
), "Custom%s", name
);
1458 if ((custom_attr
= ppdFindAttr(ppd
, custom_name
, "True")) != NULL
)
1460 if ((choice
= ppd_add_choice(option
, "Custom")) == NULL
)
1462 DEBUG_puts("1ppdOpen2: Unable to add Custom choice!");
1464 cg
->ppd_status
= PPD_ALLOC_ERROR
;
1469 strlcpy(choice
->text
,
1470 custom_attr
->text
[0] ? custom_attr
->text
: _("Custom"),
1471 sizeof(choice
->text
));
1472 choice
->code
= _cupsStrRetain(custom_attr
->value
);
1475 else if (!strcmp(keyword
, "CloseUI") || !strcmp(keyword
, "JCLCloseUI"))
1479 _cupsStrFree(string
);
1482 else if (!strcmp(keyword
, "OpenGroup"))
1485 * Open a new group...
1490 cg
->ppd_status
= PPD_NESTED_OPEN_GROUP
;
1497 cg
->ppd_status
= PPD_BAD_OPEN_GROUP
;
1503 * Separate the group name from the text (name/text)...
1506 if ((sptr
= strchr(string
, '/')) != NULL
)
1512 * Fix up the text...
1518 * Find/add the group...
1521 group
= ppd_get_group(ppd
, string
, sptr
, cg
, encoding
);
1526 _cupsStrFree(string
);
1529 else if (!strcmp(keyword
, "CloseGroup"))
1533 _cupsStrFree(string
);
1536 else if (!strcmp(keyword
, "OrderDependency"))
1538 order
= (float)_cupsStrScand(string
, &sptr
, loc
);
1540 if (!sptr
|| sscanf(sptr
, "%40s%40s", name
, keyword
) != 2)
1542 cg
->ppd_status
= PPD_BAD_ORDER_DEPENDENCY
;
1547 if (keyword
[0] == '*')
1548 _cups_strcpy(keyword
, keyword
+ 1);
1550 if (!strcmp(name
, "ExitServer"))
1551 section
= PPD_ORDER_EXIT
;
1552 else if (!strcmp(name
, "Prolog"))
1553 section
= PPD_ORDER_PROLOG
;
1554 else if (!strcmp(name
, "DocumentSetup"))
1555 section
= PPD_ORDER_DOCUMENT
;
1556 else if (!strcmp(name
, "PageSetup"))
1557 section
= PPD_ORDER_PAGE
;
1558 else if (!strcmp(name
, "JCLSetup"))
1559 section
= PPD_ORDER_JCL
;
1561 section
= PPD_ORDER_ANY
;
1569 * Only valid for Non-UI options...
1572 for (i
= ppd
->num_groups
, gtemp
= ppd
->groups
; i
> 0; i
--, gtemp
++)
1573 if (gtemp
->text
[0] == '\0')
1577 for (i
= 0; i
< gtemp
->num_options
; i
++)
1578 if (!strcmp(keyword
, gtemp
->options
[i
].keyword
))
1580 gtemp
->options
[i
].section
= section
;
1581 gtemp
->options
[i
].order
= order
;
1587 option
->section
= section
;
1588 option
->order
= order
;
1591 _cupsStrFree(string
);
1594 else if (!strncmp(keyword
, "Default", 7))
1600 * Drop UI text, if any, from value...
1603 if (strchr(string
, '/') != NULL
)
1604 *strchr(string
, '/') = '\0';
1607 * Assign the default value as appropriate...
1610 if (!strcmp(keyword
, "DefaultColorSpace"))
1613 * Set default colorspace...
1616 if (!strcmp(string
, "CMY"))
1617 ppd
->colorspace
= PPD_CS_CMY
;
1618 else if (!strcmp(string
, "CMYK"))
1619 ppd
->colorspace
= PPD_CS_CMYK
;
1620 else if (!strcmp(string
, "RGB"))
1621 ppd
->colorspace
= PPD_CS_RGB
;
1622 else if (!strcmp(string
, "RGBK"))
1623 ppd
->colorspace
= PPD_CS_RGBK
;
1624 else if (!strcmp(string
, "N"))
1625 ppd
->colorspace
= PPD_CS_N
;
1627 ppd
->colorspace
= PPD_CS_GRAY
;
1629 else if (option
&& !strcmp(keyword
+ 7, option
->keyword
))
1632 * Set the default as part of the current option...
1635 DEBUG_printf(("2ppdOpen2: Setting %s to %s...", keyword
, string
));
1637 strlcpy(option
->defchoice
, string
, sizeof(option
->defchoice
));
1639 DEBUG_printf(("2ppdOpen2: %s is now %s...", keyword
, option
->defchoice
));
1644 * Lookup option and set if it has been defined...
1647 ppd_option_t
*toption
; /* Temporary option */
1650 if ((toption
= ppdFindOption(ppd
, keyword
+ 7)) != NULL
)
1652 DEBUG_printf(("2ppdOpen2: Setting %s to %s...", keyword
, string
));
1653 strlcpy(toption
->defchoice
, string
, sizeof(toption
->defchoice
));
1657 else if (!strcmp(keyword
, "UIConstraints") ||
1658 !strcmp(keyword
, "NonUIConstraints"))
1662 cg
->ppd_status
= PPD_BAD_UI_CONSTRAINTS
;
1666 if (ppd
->num_consts
== 0)
1667 constraint
= calloc(2, sizeof(ppd_const_t
));
1669 constraint
= realloc(ppd
->consts
,
1670 (ppd
->num_consts
+ 2) * sizeof(ppd_const_t
));
1672 if (constraint
== NULL
)
1674 cg
->ppd_status
= PPD_ALLOC_ERROR
;
1679 ppd
->consts
= constraint
;
1680 constraint
+= ppd
->num_consts
;
1683 switch (sscanf(string
, "%40s%40s%40s%40s", constraint
->option1
,
1684 constraint
->choice1
, constraint
->option2
,
1685 constraint
->choice2
))
1687 case 0 : /* Error */
1688 case 1 : /* Error */
1689 cg
->ppd_status
= PPD_BAD_UI_CONSTRAINTS
;
1692 case 2 : /* Two options... */
1694 * Check for broken constraints like "* Option"...
1697 if (cg
->ppd_conform
== PPD_CONFORM_STRICT
&&
1698 (!strcmp(constraint
->option1
, "*") ||
1699 !strcmp(constraint
->choice1
, "*")))
1701 cg
->ppd_status
= PPD_BAD_UI_CONSTRAINTS
;
1706 * The following strcpy's are safe, as optionN and
1707 * choiceN are all the same size (size defined by PPD spec...)
1710 if (constraint
->option1
[0] == '*')
1711 _cups_strcpy(constraint
->option1
, constraint
->option1
+ 1);
1712 else if (cg
->ppd_conform
== PPD_CONFORM_STRICT
)
1714 cg
->ppd_status
= PPD_BAD_UI_CONSTRAINTS
;
1718 if (constraint
->choice1
[0] == '*')
1719 _cups_strcpy(constraint
->option2
, constraint
->choice1
+ 1);
1720 else if (cg
->ppd_conform
== PPD_CONFORM_STRICT
)
1722 cg
->ppd_status
= PPD_BAD_UI_CONSTRAINTS
;
1726 constraint
->choice1
[0] = '\0';
1727 constraint
->choice2
[0] = '\0';
1730 case 3 : /* Two options, one choice... */
1732 * Check for broken constraints like "* Option"...
1735 if (cg
->ppd_conform
== PPD_CONFORM_STRICT
&&
1736 (!strcmp(constraint
->option1
, "*") ||
1737 !strcmp(constraint
->choice1
, "*") ||
1738 !strcmp(constraint
->option2
, "*")))
1740 cg
->ppd_status
= PPD_BAD_UI_CONSTRAINTS
;
1745 * The following _cups_strcpy's are safe, as optionN and
1746 * choiceN are all the same size (size defined by PPD spec...)
1749 if (constraint
->option1
[0] == '*')
1750 _cups_strcpy(constraint
->option1
, constraint
->option1
+ 1);
1751 else if (cg
->ppd_conform
== PPD_CONFORM_STRICT
)
1753 cg
->ppd_status
= PPD_BAD_UI_CONSTRAINTS
;
1757 if (constraint
->choice1
[0] == '*')
1759 if (cg
->ppd_conform
== PPD_CONFORM_STRICT
&&
1760 constraint
->option2
[0] == '*')
1762 cg
->ppd_status
= PPD_BAD_UI_CONSTRAINTS
;
1766 _cups_strcpy(constraint
->choice2
, constraint
->option2
);
1767 _cups_strcpy(constraint
->option2
, constraint
->choice1
+ 1);
1768 constraint
->choice1
[0] = '\0';
1772 if (constraint
->option2
[0] == '*')
1773 _cups_strcpy(constraint
->option2
, constraint
->option2
+ 1);
1774 else if (cg
->ppd_conform
== PPD_CONFORM_STRICT
)
1776 cg
->ppd_status
= PPD_BAD_UI_CONSTRAINTS
;
1780 constraint
->choice2
[0] = '\0';
1784 case 4 : /* Two options, two choices... */
1786 * Check for broken constraints like "* Option"...
1789 if (cg
->ppd_conform
== PPD_CONFORM_STRICT
&&
1790 (!strcmp(constraint
->option1
, "*") ||
1791 !strcmp(constraint
->choice1
, "*") ||
1792 !strcmp(constraint
->option2
, "*") ||
1793 !strcmp(constraint
->choice2
, "*")))
1795 cg
->ppd_status
= PPD_BAD_UI_CONSTRAINTS
;
1799 if (constraint
->option1
[0] == '*')
1800 _cups_strcpy(constraint
->option1
, constraint
->option1
+ 1);
1801 else if (cg
->ppd_conform
== PPD_CONFORM_STRICT
)
1803 cg
->ppd_status
= PPD_BAD_UI_CONSTRAINTS
;
1807 if (cg
->ppd_conform
== PPD_CONFORM_STRICT
&&
1808 constraint
->choice1
[0] == '*')
1810 cg
->ppd_status
= PPD_BAD_UI_CONSTRAINTS
;
1814 if (constraint
->option2
[0] == '*')
1815 _cups_strcpy(constraint
->option2
, constraint
->option2
+ 1);
1816 else if (cg
->ppd_conform
== PPD_CONFORM_STRICT
)
1818 cg
->ppd_status
= PPD_BAD_UI_CONSTRAINTS
;
1822 if (cg
->ppd_conform
== PPD_CONFORM_STRICT
&&
1823 constraint
->choice2
[0] == '*')
1825 cg
->ppd_status
= PPD_BAD_UI_CONSTRAINTS
;
1832 * Don't add this one as an attribute...
1835 _cupsStrFree(string
);
1838 else if (!strcmp(keyword
, "PaperDimension"))
1840 if ((size
= ppdPageSize(ppd
, name
)) == NULL
)
1841 size
= ppd_add_size(ppd
, name
);
1846 * Unable to add or find size!
1849 cg
->ppd_status
= PPD_ALLOC_ERROR
;
1854 size
->width
= (float)_cupsStrScand(string
, &sptr
, loc
);
1855 size
->length
= (float)_cupsStrScand(sptr
, NULL
, loc
);
1857 _cupsStrFree(string
);
1860 else if (!strcmp(keyword
, "ImageableArea"))
1862 if ((size
= ppdPageSize(ppd
, name
)) == NULL
)
1863 size
= ppd_add_size(ppd
, name
);
1868 * Unable to add or find size!
1871 cg
->ppd_status
= PPD_ALLOC_ERROR
;
1876 size
->left
= (float)_cupsStrScand(string
, &sptr
, loc
);
1877 size
->bottom
= (float)_cupsStrScand(sptr
, &sptr
, loc
);
1878 size
->right
= (float)_cupsStrScand(sptr
, &sptr
, loc
);
1879 size
->top
= (float)_cupsStrScand(sptr
, NULL
, loc
);
1881 _cupsStrFree(string
);
1884 else if (option
!= NULL
&&
1885 (mask
& (PPD_KEYWORD
| PPD_OPTION
| PPD_STRING
)) ==
1886 (PPD_KEYWORD
| PPD_OPTION
| PPD_STRING
) &&
1887 !strcmp(keyword
, option
->keyword
))
1889 DEBUG_printf(("2ppdOpen2: group=%p, subgroup=%p", group
, subgroup
));
1891 if (!strcmp(keyword
, "PageSize"))
1894 * Add a page size...
1897 if (ppdPageSize(ppd
, name
) == NULL
)
1898 ppd_add_size(ppd
, name
);
1902 * Add the option choice...
1905 if ((choice
= ppd_add_choice(option
, name
)) == NULL
)
1907 cg
->ppd_status
= PPD_ALLOC_ERROR
;
1913 cupsCharsetToUTF8((cups_utf8_t
*)choice
->text
, text
,
1914 sizeof(choice
->text
), encoding
);
1915 else if (!strcmp(name
, "True"))
1916 strcpy(choice
->text
, _("Yes"));
1917 else if (!strcmp(name
, "False"))
1918 strcpy(choice
->text
, _("No"));
1920 strlcpy(choice
->text
, name
, sizeof(choice
->text
));
1922 if (option
->section
== PPD_ORDER_JCL
)
1923 ppd_decode(string
); /* Decode quoted string */
1925 choice
->code
= string
;
1926 string
= NULL
; /* Don't add as an attribute below */
1930 * Add remaining lines with keywords and string values as attributes...
1934 (mask
& (PPD_KEYWORD
| PPD_STRING
)) == (PPD_KEYWORD
| PPD_STRING
))
1935 ppd_add_attr(ppd
, keyword
, name
, text
, string
);
1937 _cupsStrFree(string
);
1940 ppd_free(line
.buffer
);
1943 * Reset language preferences...
1946 cupsLangFree(language
);
1949 if (!cupsFileEOF(fp
))
1950 DEBUG_printf(("1ppdOpen2: Premature EOF at %lu...\n",
1951 (unsigned long)cupsFileTell(fp
)));
1954 if (cg
->ppd_status
!= PPD_OK
)
1957 * Had an error reading the PPD file, cannot continue!
1966 * Create the sorted options array and set the option back-pointer for
1967 * each choice and custom option...
1970 ppd
->options
= cupsArrayNew2((cups_array_func_t
)ppd_compare_options
, NULL
,
1971 (cups_ahash_func_t
)ppd_hash_option
,
1974 for (i
= ppd
->num_groups
, group
= ppd
->groups
;
1978 for (j
= group
->num_options
, option
= group
->options
;
1982 ppd_coption_t
*coption
; /* Custom option */
1985 cupsArrayAdd(ppd
->options
, option
);
1987 for (k
= 0; k
< option
->num_choices
; k
++)
1988 option
->choices
[k
].option
= option
;
1990 if ((coption
= ppdFindCustomOption(ppd
, option
->keyword
)) != NULL
)
1991 coption
->option
= option
;
1996 * Create an array to track the marked choices...
1999 ppd
->marked
= cupsArrayNew((cups_array_func_t
)ppd_compare_choices
, NULL
);
2002 * Return the PPD file structure...
2008 * Common exit point for errors to save code size...
2013 _cupsStrFree(string
);
2014 ppd_free(line
.buffer
);
2018 cupsLangFree(language
);
2025 * 'ppdOpenFd()' - Read a PPD file into memory.
2028 ppd_file_t
* /* O - PPD file record or @code NULL@ if the PPD file could not be opened. */
2029 ppdOpenFd(int fd
) /* I - File to read from */
2031 cups_file_t
*fp
; /* CUPS file pointer */
2032 ppd_file_t
*ppd
; /* PPD file record */
2033 _cups_globals_t
*cg
= _cupsGlobals();
2038 * Set the line number to 0...
2044 * Range check input...
2049 cg
->ppd_status
= PPD_NULL_FILE
;
2055 * Try to open the file and parse it...
2058 if ((fp
= cupsFileOpenFd(fd
, "r")) != NULL
)
2066 cg
->ppd_status
= PPD_FILE_OPEN_ERROR
;
2075 * 'ppdOpenFile()' - Read a PPD file into memory.
2078 ppd_file_t
* /* O - PPD file record or @code NULL@ if the PPD file could not be opened. */
2079 ppdOpenFile(const char *filename
) /* I - File to read from */
2081 cups_file_t
*fp
; /* File pointer */
2082 ppd_file_t
*ppd
; /* PPD file record */
2083 _cups_globals_t
*cg
= _cupsGlobals();
2088 * Set the line number to 0...
2094 * Range check input...
2097 if (filename
== NULL
)
2099 cg
->ppd_status
= PPD_NULL_FILE
;
2105 * Try to open the file and parse it...
2108 if ((fp
= cupsFileOpen(filename
, "r")) != NULL
)
2116 cg
->ppd_status
= PPD_FILE_OPEN_ERROR
;
2125 * 'ppdSetConformance()' - Set the conformance level for PPD files.
2127 * @since CUPS 1.1.20/Mac OS X 10.4@
2131 ppdSetConformance(ppd_conform_t c
) /* I - Conformance level */
2133 _cups_globals_t
*cg
= _cupsGlobals();
2137 cg
->ppd_conform
= c
;
2142 * 'ppd_add_attr()' - Add an attribute to the PPD data.
2145 static ppd_attr_t
* /* O - New attribute */
2146 ppd_add_attr(ppd_file_t
*ppd
, /* I - PPD file data */
2147 const char *name
, /* I - Attribute name */
2148 const char *spec
, /* I - Specifier string, if any */
2149 const char *text
, /* I - Text string, if any */
2150 const char *value
) /* I - Value of attribute */
2152 ppd_attr_t
**ptr
, /* New array */
2153 *temp
; /* New attribute */
2157 * Range check input...
2160 if (ppd
== NULL
|| name
== NULL
|| spec
== NULL
)
2164 * Create the array as needed...
2167 if (!ppd
->sorted_attrs
)
2168 ppd
->sorted_attrs
= cupsArrayNew((cups_array_func_t
)ppd_compare_attrs
,
2172 * Allocate memory for the new attribute...
2175 if (ppd
->num_attrs
== 0)
2176 ptr
= malloc(sizeof(ppd_attr_t
*));
2178 ptr
= realloc(ppd
->attrs
, (ppd
->num_attrs
+ 1) * sizeof(ppd_attr_t
*));
2184 ptr
+= ppd
->num_attrs
;
2186 if ((temp
= calloc(1, sizeof(ppd_attr_t
))) == NULL
)
2197 strlcpy(temp
->name
, name
, sizeof(temp
->name
));
2198 strlcpy(temp
->spec
, spec
, sizeof(temp
->spec
));
2199 strlcpy(temp
->text
, text
, sizeof(temp
->text
));
2200 temp
->value
= (char *)value
;
2203 * Add the attribute to the sorted array...
2206 cupsArrayAdd(ppd
->sorted_attrs
, temp
);
2209 * Return the attribute...
2217 * 'ppd_add_choice()' - Add a choice to an option.
2220 static ppd_choice_t
* /* O - Named choice */
2221 ppd_add_choice(ppd_option_t
*option
, /* I - Option */
2222 const char *name
) /* I - Name of choice */
2224 ppd_choice_t
*choice
; /* Choice */
2227 if (option
->num_choices
== 0)
2228 choice
= malloc(sizeof(ppd_choice_t
));
2230 choice
= realloc(option
->choices
,
2231 sizeof(ppd_choice_t
) * (option
->num_choices
+ 1));
2236 option
->choices
= choice
;
2237 choice
+= option
->num_choices
;
2238 option
->num_choices
++;
2240 memset(choice
, 0, sizeof(ppd_choice_t
));
2241 strlcpy(choice
->choice
, name
, sizeof(choice
->choice
));
2248 * 'ppd_add_size()' - Add a page size.
2251 static ppd_size_t
* /* O - Named size */
2252 ppd_add_size(ppd_file_t
*ppd
, /* I - PPD file */
2253 const char *name
) /* I - Name of size */
2255 ppd_size_t
*size
; /* Size */
2258 if (ppd
->num_sizes
== 0)
2259 size
= malloc(sizeof(ppd_size_t
));
2261 size
= realloc(ppd
->sizes
, sizeof(ppd_size_t
) * (ppd
->num_sizes
+ 1));
2267 size
+= ppd
->num_sizes
;
2270 memset(size
, 0, sizeof(ppd_size_t
));
2271 strlcpy(size
->name
, name
, sizeof(size
->name
));
2278 * 'ppd_compare_attrs()' - Compare two attributes.
2281 static int /* O - Result of comparison */
2282 ppd_compare_attrs(ppd_attr_t
*a
, /* I - First attribute */
2283 ppd_attr_t
*b
) /* I - Second attribute */
2285 return (strcasecmp(a
->name
, b
->name
));
2290 * 'ppd_compare_choices()' - Compare two choices...
2293 static int /* O - Result of comparison */
2294 ppd_compare_choices(ppd_choice_t
*a
, /* I - First choice */
2295 ppd_choice_t
*b
) /* I - Second choice */
2297 return (strcmp(a
->option
->keyword
, b
->option
->keyword
));
2302 * 'ppd_compare_coptions()' - Compare two custom options.
2305 static int /* O - Result of comparison */
2306 ppd_compare_coptions(ppd_coption_t
*a
, /* I - First option */
2307 ppd_coption_t
*b
) /* I - Second option */
2309 return (strcasecmp(a
->keyword
, b
->keyword
));
2314 * 'ppd_compare_cparams()' - Compare two custom parameters.
2317 static int /* O - Result of comparison */
2318 ppd_compare_cparams(ppd_cparam_t
*a
, /* I - First parameter */
2319 ppd_cparam_t
*b
) /* I - Second parameter */
2321 return (strcasecmp(a
->name
, b
->name
));
2326 * 'ppd_compare_options()' - Compare two options.
2329 static int /* O - Result of comparison */
2330 ppd_compare_options(ppd_option_t
*a
, /* I - First option */
2331 ppd_option_t
*b
) /* I - Second option */
2333 return (strcasecmp(a
->keyword
, b
->keyword
));
2338 * 'ppd_decode()' - Decode a string value...
2341 static int /* O - Length of decoded string */
2342 ppd_decode(char *string
) /* I - String to decode */
2344 char *inptr
, /* Input pointer */
2345 *outptr
; /* Output pointer */
2351 while (*inptr
!= '\0')
2352 if (*inptr
== '<' && isxdigit(inptr
[1] & 255))
2355 * Convert hex to 8-bit values...
2359 while (isxdigit(*inptr
& 255))
2361 if (isalpha(*inptr
))
2362 *outptr
= (tolower(*inptr
) - 'a' + 10) << 4;
2364 *outptr
= (*inptr
- '0') << 4;
2368 if (!isxdigit(*inptr
& 255))
2371 if (isalpha(*inptr
))
2372 *outptr
|= tolower(*inptr
) - 'a' + 10;
2374 *outptr
|= *inptr
- '0';
2380 while (*inptr
!= '>' && *inptr
!= '\0')
2382 while (*inptr
== '>')
2386 *outptr
++ = *inptr
++;
2390 return ((int)(outptr
- string
));
2395 * 'ppd_free_group()' - Free a single UI group.
2399 ppd_free_group(ppd_group_t
*group
) /* I - Group to free */
2401 int i
; /* Looping var */
2402 ppd_option_t
*option
; /* Current option */
2403 ppd_group_t
*subgroup
; /* Current sub-group */
2406 if (group
->num_options
> 0)
2408 for (i
= group
->num_options
, option
= group
->options
;
2411 ppd_free_option(option
);
2413 ppd_free(group
->options
);
2416 if (group
->num_subgroups
> 0)
2418 for (i
= group
->num_subgroups
, subgroup
= group
->subgroups
;
2421 ppd_free_group(subgroup
);
2423 ppd_free(group
->subgroups
);
2429 * 'ppd_free_option()' - Free a single option.
2433 ppd_free_option(ppd_option_t
*option
) /* I - Option to free */
2435 int i
; /* Looping var */
2436 ppd_choice_t
*choice
; /* Current choice */
2439 if (option
->num_choices
> 0)
2441 for (i
= option
->num_choices
, choice
= option
->choices
;
2445 _cupsStrFree(choice
->code
);
2448 ppd_free(option
->choices
);
2454 * 'ppd_get_coption()' - Get a custom option record.
2457 static ppd_coption_t
* /* O - Custom option... */
2458 ppd_get_coption(ppd_file_t
*ppd
, /* I - PPD file */
2459 const char *name
) /* I - Name of option */
2461 ppd_coption_t
*copt
; /* New custom option */
2465 * See if the option already exists...
2468 if ((copt
= ppdFindCustomOption(ppd
, name
)) != NULL
)
2472 * Not found, so create the custom option record...
2475 if ((copt
= calloc(1, sizeof(ppd_coption_t
))) == NULL
)
2478 strlcpy(copt
->keyword
, name
, sizeof(copt
->keyword
));
2480 copt
->params
= cupsArrayNew((cups_array_func_t
)ppd_compare_cparams
, NULL
);
2482 cupsArrayAdd(ppd
->coptions
, copt
);
2485 * Return the new record...
2493 * 'ppd_get_cparam()' - Get a custom parameter record.
2496 static ppd_cparam_t
* /* O - Extended option... */
2497 ppd_get_cparam(ppd_coption_t
*opt
, /* I - PPD file */
2498 const char *param
, /* I - Name of parameter */
2499 const char *text
) /* I - Human-readable text */
2501 ppd_cparam_t
*cparam
; /* New custom parameter */
2505 * See if the parameter already exists...
2508 if ((cparam
= ppdFindCustomParam(opt
, param
)) != NULL
)
2512 * Not found, so create the custom parameter record...
2515 if ((cparam
= calloc(1, sizeof(ppd_cparam_t
))) == NULL
)
2518 strlcpy(cparam
->name
, param
, sizeof(cparam
->name
));
2519 strlcpy(cparam
->text
, text
[0] ? text
: param
, sizeof(cparam
->text
));
2522 * Add this record to the array...
2525 cupsArrayAdd(opt
->params
, cparam
);
2528 * Return the new record...
2536 * 'ppd_get_group()' - Find or create the named group as needed.
2539 static ppd_group_t
* /* O - Named group */
2540 ppd_get_group(ppd_file_t
*ppd
, /* I - PPD file */
2541 const char *name
, /* I - Name of group */
2542 const char *text
, /* I - Text for group */
2543 _cups_globals_t
*cg
, /* I - Global data */
2544 cups_encoding_t encoding
) /* I - Encoding of text */
2546 int i
; /* Looping var */
2547 ppd_group_t
*group
; /* Group */
2550 DEBUG_printf(("7ppd_get_group(ppd=%p, name=\"%s\", text=\"%s\", cg=%p)",
2551 ppd
, name
, text
, cg
));
2553 for (i
= ppd
->num_groups
, group
= ppd
->groups
; i
> 0; i
--, group
++)
2554 if (!strcmp(group
->name
, name
))
2559 DEBUG_printf(("8ppd_get_group: Adding group %s...", name
));
2561 if (cg
->ppd_conform
== PPD_CONFORM_STRICT
&& strlen(text
) >= sizeof(group
->text
))
2563 cg
->ppd_status
= PPD_ILLEGAL_TRANSLATION
;
2568 if (ppd
->num_groups
== 0)
2569 group
= malloc(sizeof(ppd_group_t
));
2571 group
= realloc(ppd
->groups
,
2572 (ppd
->num_groups
+ 1) * sizeof(ppd_group_t
));
2576 cg
->ppd_status
= PPD_ALLOC_ERROR
;
2581 ppd
->groups
= group
;
2582 group
+= ppd
->num_groups
;
2585 memset(group
, 0, sizeof(ppd_group_t
));
2586 strlcpy(group
->name
, name
, sizeof(group
->name
));
2588 cupsCharsetToUTF8((cups_utf8_t
*)group
->text
, text
,
2589 sizeof(group
->text
), encoding
);
2597 * 'ppd_get_option()' - Find or create the named option as needed.
2600 static ppd_option_t
* /* O - Named option */
2601 ppd_get_option(ppd_group_t
*group
, /* I - Group */
2602 const char *name
) /* I - Name of option */
2604 int i
; /* Looping var */
2605 ppd_option_t
*option
; /* Option */
2608 DEBUG_printf(("7ppd_get_option(group=%p(\"%s\"), name=\"%s\")",
2609 group
, group
->name
, name
));
2611 for (i
= group
->num_options
, option
= group
->options
; i
> 0; i
--, option
++)
2612 if (!strcmp(option
->keyword
, name
))
2617 if (group
->num_options
== 0)
2618 option
= malloc(sizeof(ppd_option_t
));
2620 option
= realloc(group
->options
,
2621 (group
->num_options
+ 1) * sizeof(ppd_option_t
));
2626 group
->options
= option
;
2627 option
+= group
->num_options
;
2628 group
->num_options
++;
2630 memset(option
, 0, sizeof(ppd_option_t
));
2631 strlcpy(option
->keyword
, name
, sizeof(option
->keyword
));
2639 * 'ppd_hash_option()' - Generate a hash of the option name...
2642 static int /* O - Hash index */
2643 ppd_hash_option(ppd_option_t
*option
) /* I - Option */
2645 int hash
= 0; /* Hash index */
2646 const char *k
; /* Pointer into keyword */
2649 for (hash
= option
->keyword
[0], k
= option
->keyword
+ 1; *k
;)
2650 hash
= 33 * hash
+ *k
++;
2652 return (hash
& 511);
2657 * 'ppd_read()' - Read a line from a PPD file, skipping comment lines as
2661 static int /* O - Bitmask of fields read */
2662 ppd_read(cups_file_t
*fp
, /* I - File to read from */
2663 _ppd_line_t
*line
, /* I - Line buffer */
2664 char *keyword
, /* O - Keyword from line */
2665 char *option
, /* O - Option from line */
2666 char *text
, /* O - Human-readable text from line */
2667 char **string
, /* O - Code/string data */
2668 int ignoreblank
, /* I - Ignore blank lines? */
2669 _cups_globals_t
*cg
) /* I - Global data */
2671 int ch
, /* Character from file */
2672 col
, /* Column in line */
2673 colon
, /* Colon seen? */
2674 endquote
, /* Waiting for an end quote */
2675 mask
, /* Mask to be returned */
2676 startline
, /* Start line */
2677 textlen
; /* Length of text */
2678 char *keyptr
, /* Keyword pointer */
2679 *optptr
, /* Option pointer */
2680 *textptr
, /* Text pointer */
2681 *strptr
, /* Pointer into string */
2682 *lineptr
; /* Current position in line buffer */
2686 * Now loop until we have a valid line...
2691 startline
= cg
->ppd_line
+ 1;
2695 line
->bufsize
= 1024;
2696 line
->buffer
= malloc(1024);
2708 lineptr
= line
->buffer
;
2712 while ((ch
= cupsFileGetChar(fp
)) != EOF
)
2714 if (lineptr
>= (line
->buffer
+ line
->bufsize
- 1))
2717 * Expand the line buffer...
2720 char *temp
; /* Temporary line pointer */
2723 line
->bufsize
+= 1024;
2724 if (line
->bufsize
> 262144)
2727 * Don't allow lines longer than 256k!
2730 cg
->ppd_line
= startline
;
2731 cg
->ppd_status
= PPD_LINE_TOO_LONG
;
2736 temp
= realloc(line
->buffer
, line
->bufsize
);
2739 cg
->ppd_line
= startline
;
2740 cg
->ppd_status
= PPD_LINE_TOO_LONG
;
2745 lineptr
= temp
+ (lineptr
- line
->buffer
);
2746 line
->buffer
= temp
;
2749 if (ch
== '\r' || ch
== '\n')
2752 * Line feed or carriage return...
2761 * Check for a trailing line feed...
2764 if ((ch
= cupsFilePeekChar(fp
)) == EOF
)
2771 cupsFileGetChar(fp
);
2774 if (lineptr
== line
->buffer
&& ignoreblank
)
2775 continue; /* Skip blank lines */
2779 if (!endquote
) /* Continue for multi-line text */
2784 else if (ch
< ' ' && ch
!= '\t' && cg
->ppd_conform
== PPD_CONFORM_STRICT
)
2787 * Other control characters...
2790 cg
->ppd_line
= startline
;
2791 cg
->ppd_status
= PPD_ILLEGAL_CHARACTER
;
2795 else if (ch
!= 0x1a)
2798 * Any other character...
2804 if (col
> (PPD_MAX_LINE
- 1))
2807 * Line is too long...
2810 cg
->ppd_line
= startline
;
2811 cg
->ppd_status
= PPD_LINE_TOO_LONG
;
2816 if (ch
== ':' && strncmp(line
->buffer
, "*%", 2) != 0)
2819 if (ch
== '\"' && colon
)
2820 endquote
= !endquote
;
2827 * Didn't finish this quoted string...
2830 while ((ch
= cupsFileGetChar(fp
)) != EOF
)
2833 else if (ch
== '\r' || ch
== '\n')
2841 * Check for a trailing line feed...
2844 if ((ch
= cupsFilePeekChar(fp
)) == EOF
)
2847 cupsFileGetChar(fp
);
2850 else if (ch
< ' ' && ch
!= '\t' && cg
->ppd_conform
== PPD_CONFORM_STRICT
)
2853 * Other control characters...
2856 cg
->ppd_line
= startline
;
2857 cg
->ppd_status
= PPD_ILLEGAL_CHARACTER
;
2861 else if (ch
!= 0x1a)
2865 if (col
> (PPD_MAX_LINE
- 1))
2868 * Line is too long...
2871 cg
->ppd_line
= startline
;
2872 cg
->ppd_status
= PPD_LINE_TOO_LONG
;
2882 * Didn't finish this line...
2885 while ((ch
= cupsFileGetChar(fp
)) != EOF
)
2886 if (ch
== '\r' || ch
== '\n')
2889 * Line feed or carriage return...
2898 * Check for a trailing line feed...
2901 if ((ch
= cupsFilePeekChar(fp
)) == EOF
)
2904 cupsFileGetChar(fp
);
2909 else if (ch
< ' ' && ch
!= '\t' && cg
->ppd_conform
== PPD_CONFORM_STRICT
)
2912 * Other control characters...
2915 cg
->ppd_line
= startline
;
2916 cg
->ppd_status
= PPD_ILLEGAL_CHARACTER
;
2920 else if (ch
!= 0x1a)
2924 if (col
> (PPD_MAX_LINE
- 1))
2927 * Line is too long...
2930 cg
->ppd_line
= startline
;
2931 cg
->ppd_status
= PPD_LINE_TOO_LONG
;
2938 if (lineptr
> line
->buffer
&& lineptr
[-1] == '\n')
2943 DEBUG_printf(("9ppd_read: LINE=\"%s\"", line
->buffer
));
2946 * The dynamically created PPDs for older style Mac OS X
2947 * drivers include a large blob of data inserted as comments
2948 * at the end of the file. As an optimization we can stop
2949 * reading the PPD when we get to the start of this data.
2952 if (!strcmp(line
->buffer
, "*%APLWORKSET START"))
2955 if (ch
== EOF
&& lineptr
== line
->buffer
)
2963 lineptr
= line
->buffer
+ 1;
2970 if ((!line
->buffer
[0] || /* Blank line */
2971 !strncmp(line
->buffer
, "*%", 2) || /* Comment line */
2972 !strcmp(line
->buffer
, "*End")) && /* End of multi-line string */
2973 ignoreblank
) /* Ignore these? */
2975 startline
= cg
->ppd_line
+ 1;
2979 if (!strcmp(line
->buffer
, "*")) /* (Bad) comment line */
2981 if (cg
->ppd_conform
== PPD_CONFORM_RELAXED
)
2983 startline
= cg
->ppd_line
+ 1;
2988 cg
->ppd_line
= startline
;
2989 cg
->ppd_status
= PPD_ILLEGAL_MAIN_KEYWORD
;
2995 if (line
->buffer
[0] != '*') /* All lines start with an asterisk */
2998 * Allow lines consisting of just whitespace...
3001 for (lineptr
= line
->buffer
; *lineptr
; lineptr
++)
3002 if (!isspace(*lineptr
& 255))
3007 cg
->ppd_status
= PPD_MISSING_ASTERISK
;
3010 else if (ignoreblank
)
3022 while (*lineptr
!= '\0' && *lineptr
!= ':' && !isspace(*lineptr
& 255))
3024 if (*lineptr
<= ' ' || *lineptr
> 126 || *lineptr
== '/' ||
3025 (keyptr
- keyword
) >= (PPD_MAX_NAME
- 1))
3027 cg
->ppd_status
= PPD_ILLEGAL_MAIN_KEYWORD
;
3031 *keyptr
++ = *lineptr
++;
3036 if (!strcmp(keyword
, "End"))
3039 mask
|= PPD_KEYWORD
;
3041 if (isspace(*lineptr
& 255))
3044 * Get an option name...
3047 while (isspace(*lineptr
& 255))
3052 while (*lineptr
!= '\0' && !isspace(*lineptr
& 255) && *lineptr
!= ':' &&
3055 if (*lineptr
<= ' ' || *lineptr
> 126 ||
3056 (optptr
- option
) >= (PPD_MAX_NAME
- 1))
3058 cg
->ppd_status
= PPD_ILLEGAL_OPTION_KEYWORD
;
3062 *optptr
++ = *lineptr
++;
3067 if (isspace(*lineptr
& 255) && cg
->ppd_conform
== PPD_CONFORM_STRICT
)
3069 cg
->ppd_status
= PPD_ILLEGAL_WHITESPACE
;
3073 while (isspace(*lineptr
& 255))
3078 if (*lineptr
== '/')
3081 * Get human-readable text...
3088 while (*lineptr
!= '\0' && *lineptr
!= '\n' && *lineptr
!= ':')
3090 if (((unsigned char)*lineptr
< ' ' && *lineptr
!= '\t') ||
3091 (textptr
- text
) >= (PPD_MAX_LINE
- 1))
3093 cg
->ppd_status
= PPD_ILLEGAL_TRANSLATION
;
3097 *textptr
++ = *lineptr
++;
3101 textlen
= ppd_decode(text
);
3103 if (textlen
> PPD_MAX_TEXT
&& cg
->ppd_conform
== PPD_CONFORM_STRICT
)
3105 cg
->ppd_status
= PPD_ILLEGAL_TRANSLATION
;
3113 if (isspace(*lineptr
& 255) && cg
->ppd_conform
== PPD_CONFORM_STRICT
)
3115 cg
->ppd_status
= PPD_ILLEGAL_WHITESPACE
;
3119 while (isspace(*lineptr
& 255))
3122 if (*lineptr
== ':')
3125 * Get string after triming leading and trailing whitespace...
3129 while (isspace(*lineptr
& 255))
3132 strptr
= lineptr
+ strlen(lineptr
) - 1;
3133 while (strptr
>= lineptr
&& isspace(*strptr
& 255))
3136 if (*strptr
== '\"')
3139 * Quoted string by itself, remove quotes...
3146 *string
= _cupsStrAlloc(lineptr
);
3158 * End of "$Id: ppd.c 7906 2008-09-03 20:19:43Z mike $".