2 * "$Id: ppd.c 6479 2007-04-27 11:44:10Z mike $"
4 * PPD file routines for the Common UNIX Printing System (CUPS).
6 * Copyright 1997-2007 by Easy Software Products, all rights reserved.
8 * These coded instructions, statements, and computer programs are the
9 * property of Easy Software Products and are protected by Federal
10 * copyright law. Distribution and use rights are outlined in the file
11 * "LICENSE.txt" which should have been included with this file. If this
12 * file is missing or damaged please contact Easy Software Products
15 * Attn: CUPS Licensing Information
16 * Easy Software Products
17 * 44141 Airport View Drive, Suite 204
18 * Hollywood, Maryland 20636 USA
20 * Voice: (301) 373-9600
21 * EMail: cups-info@cups.org
22 * WWW: http://www.cups.org
24 * PostScript is a trademark of Adobe Systems, Inc.
26 * This code and any derivative of it may be used and distributed
27 * freely under the terms of the GNU General Public License when
28 * used with GNU Ghostscript or its derivatives. Use of the code
29 * (or any derivative of it) with software other than GNU
30 * GhostScript (or its derivatives) is governed by the CUPS license
33 * This file is subject to the Apple OS-Developed Software exception.
37 * ppdClose() - Free all memory used by the PPD file.
38 * ppdErrorString() - Returns the text assocated with a status.
39 * _ppdGetEncoding() - Get the CUPS encoding value for the given
41 * ppdLastError() - Return the status from the last ppdOpen*().
42 * ppdOpen() - Read a PPD file into memory.
43 * ppdOpen2() - Read a PPD file into memory.
44 * ppdOpenFd() - Read a PPD file into memory.
45 * ppdOpenFile() - Read a PPD file into memory.
46 * ppdSetConformance() - Set the conformance level for PPD files.
47 * ppd_add_attr() - Add an attribute to the PPD data.
48 * ppd_add_choice() - Add a choice to an option.
49 * ppd_add_size() - Add a page size.
50 * ppd_compare_attrs() - Compare two attributes.
51 * ppd_compare_choices() - Compare two choices...
52 * ppd_compare_consts() - Compare two constraints.
53 * ppd_compare_coptions() - Compare two custom options.
54 * ppd_compare_cparams() - Compare two custom parameters.
55 * ppd_compare_options() - Compare two options.
56 * ppd_decode() - Decode a string value...
57 * ppd_free_group() - Free a single UI group.
58 * ppd_free_option() - Free a single option.
59 * ppd_get_coption() - Get a custom option record.
60 * ppd_get_cparam() - Get a custom parameter record.
61 * ppd_get_group() - Find or create the named group as needed.
62 * ppd_get_option() - Find or create the named option as needed.
63 * ppd_hash_option() - Generate a hash of the option name...
64 * ppd_read() - Read a line from a PPD file, skipping comment
69 * Include necessary headers.
81 #if defined(WIN32) || defined(__EMX__)
82 # define READ_BINARY "rb" /* Open a binary file for reading */
83 # define WRITE_BINARY "wb" /* Open a binary file for writing */
85 # define READ_BINARY "r" /* Open a binary file for reading */
86 # define WRITE_BINARY "w" /* Open a binary file for writing */
87 #endif /* WIN32 || __EMX__ */
89 #define ppd_free(p) if (p) free(p) /* Safe free macro */
91 #define PPD_KEYWORD 1 /* Line contained a keyword */
92 #define PPD_OPTION 2 /* Line contained an option name */
93 #define PPD_TEXT 4 /* Line contained human-readable text */
94 #define PPD_STRING 8 /* Line contained a string or code */
96 #define PPD_HASHSIZE 512 /* Size of hash */
103 static ppd_attr_t
*ppd_add_attr(ppd_file_t
*ppd
, const char *name
,
104 const char *spec
, const char *text
,
106 static ppd_choice_t
*ppd_add_choice(ppd_option_t
*option
, const char *name
);
107 static ppd_size_t
*ppd_add_size(ppd_file_t
*ppd
, const char *name
);
108 static int ppd_compare_attrs(ppd_attr_t
*a
, ppd_attr_t
*b
);
109 static int ppd_compare_choices(ppd_choice_t
*a
, ppd_choice_t
*b
);
110 static int ppd_compare_consts(ppd_const_t
*a
, ppd_const_t
*b
);
111 static int ppd_compare_coptions(ppd_coption_t
*a
,
113 static int ppd_compare_cparams(ppd_cparam_t
*a
, ppd_cparam_t
*b
);
114 static int ppd_compare_options(ppd_option_t
*a
, ppd_option_t
*b
);
115 static int ppd_decode(char *string
);
116 static void ppd_free_group(ppd_group_t
*group
);
117 static void ppd_free_option(ppd_option_t
*option
);
118 static ppd_coption_t
*ppd_get_coption(ppd_file_t
*ppd
, const char *name
);
119 static ppd_cparam_t
*ppd_get_cparam(ppd_coption_t
*opt
,
122 static ppd_group_t
*ppd_get_group(ppd_file_t
*ppd
, const char *name
,
123 const char *text
, _cups_globals_t
*cg
,
124 cups_encoding_t encoding
);
125 static ppd_option_t
*ppd_get_option(ppd_group_t
*group
, const char *name
);
126 static int ppd_hash_option(ppd_option_t
*option
);
127 static int ppd_read(cups_file_t
*fp
, char *keyword
, char *option
,
128 char *text
, char **string
, int ignoreblank
,
129 _cups_globals_t
*cg
);
133 * 'ppdClose()' - Free all memory used by the PPD file.
137 ppdClose(ppd_file_t
*ppd
) /* I - PPD file record */
139 int i
; /* Looping var */
140 ppd_emul_t
*emul
; /* Current emulation */
141 ppd_group_t
*group
; /* Current group */
142 char **font
; /* Current font */
143 char **filter
; /* Current filter */
144 ppd_attr_t
**attr
; /* Current attribute */
145 ppd_coption_t
*coption
; /* Current custom option */
146 ppd_cparam_t
*cparam
; /* Current custom parameter */
150 * Range check arguments...
157 * Free all strings at the top level...
160 ppd_free(ppd
->lang_encoding
);
161 ppd_free(ppd
->nickname
);
162 ppd_free(ppd
->patches
);
163 ppd_free(ppd
->jcl_begin
);
164 ppd_free(ppd
->jcl_end
);
165 ppd_free(ppd
->jcl_ps
);
168 * Free any emulations...
171 if (ppd
->num_emulations
> 0)
173 for (i
= ppd
->num_emulations
, emul
= ppd
->emulations
; i
> 0; i
--, emul
++)
175 ppd_free(emul
->start
);
176 ppd_free(emul
->stop
);
179 ppd_free(ppd
->emulations
);
183 * Free any UI groups, subgroups, and options...
186 if (ppd
->num_groups
> 0)
188 for (i
= ppd
->num_groups
, group
= ppd
->groups
; i
> 0; i
--, group
++)
189 ppd_free_group(group
);
191 ppd_free(ppd
->groups
);
194 cupsArrayDelete(ppd
->options
);
195 cupsArrayDelete(ppd
->marked
);
198 * Free any page sizes...
201 if (ppd
->num_sizes
> 0)
202 ppd_free(ppd
->sizes
);
205 * Free any constraints...
208 if (ppd
->num_consts
> 0)
209 ppd_free(ppd
->consts
);
212 * Free any filters...
215 if (ppd
->num_filters
> 0)
217 for (i
= ppd
->num_filters
, filter
= ppd
->filters
; i
> 0; i
--, filter
++)
222 ppd_free(ppd
->filters
);
229 if (ppd
->num_fonts
> 0)
231 for (i
= ppd
->num_fonts
, font
= ppd
->fonts
; i
> 0; i
--, font
++)
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 ppd_free((*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 ppd_free(cparam
->current
.custom_string
);
290 cupsArrayDelete(coption
->params
);
295 cupsArrayDelete(ppd
->coptions
);
298 * Free the whole record...
306 * 'ppdErrorString()' - Returns the text assocated with a status.
308 * @since CUPS 1.1.19@
311 const char * /* O - Status string */
312 ppdErrorString(ppd_status_t status
) /* I - PPD status */
314 static const char * const messages
[] =/* Status messages */
317 _("Unable to open PPD file"),
318 _("NULL PPD file pointer"),
319 _("Memory allocation error"),
320 _("Missing PPD-Adobe-4.x header"),
321 _("Missing value string"),
324 _("OpenGroup without a CloseGroup first"),
325 _("Bad OpenUI/JCLOpenUI"),
326 _("OpenUI/JCLOpenUI without a CloseUI/JCLCloseUI first"),
327 _("Bad OrderDependency"),
328 _("Bad UIConstraints"),
329 _("Missing asterisk in column 1"),
330 _("Line longer than the maximum allowed (255 characters)"),
331 _("Illegal control character"),
332 _("Illegal main keyword string"),
333 _("Illegal option keyword string"),
334 _("Illegal translation string"),
335 _("Illegal whitespace character"),
336 _("Bad custom parameter")
340 if (status
< PPD_OK
|| status
> PPD_ILLEGAL_WHITESPACE
)
341 return (_cupsLangString(cupsLangDefault(), _("Unknown")));
343 return (_cupsLangString(cupsLangDefault(), messages
[status
]));
348 * '_ppdGetEncoding()' - Get the CUPS encoding value for the given
352 cups_encoding_t
/* O - CUPS encoding value */
353 _ppdGetEncoding(const char *name
) /* I - LanguageEncoding string */
355 if (!strcasecmp(name
, "ISOLatin1"))
356 return (CUPS_ISO8859_1
);
357 else if (!strcasecmp(name
, "ISOLatin2"))
358 return (CUPS_ISO8859_2
);
359 else if (!strcasecmp(name
, "ISOLatin5"))
360 return (CUPS_ISO8859_5
);
361 else if (!strcasecmp(name
, "JIS83-RKSJ"))
362 return (CUPS_WINDOWS_932
);
363 else if (!strcasecmp(name
, "MacStandard"))
364 return (CUPS_MAC_ROMAN
);
365 else if (!strcasecmp(name
, "WindowsANSI"))
366 return (CUPS_WINDOWS_1252
);
373 * 'ppdLastError()' - Return the status from the last ppdOpen*().
375 * @since CUPS 1.1.19@
378 ppd_status_t
/* O - Status code */
379 ppdLastError(int *line
) /* O - Line number */
381 _cups_globals_t
*cg
= _cupsGlobals();
386 *line
= cg
->ppd_line
;
388 return (cg
->ppd_status
);
393 * 'ppdOpen()' - Read a PPD file into memory.
396 ppd_file_t
* /* O - PPD file record */
397 ppdOpen(FILE *fp
) /* I - File to read from */
399 ppd_file_t
*ppd
; /* PPD file record */
400 cups_file_t
*cf
; /* CUPS file */
404 * Reopen the stdio file as a CUPS file...
407 if ((cf
= cupsFileOpenFd(fileno(fp
), "r")) == NULL
)
411 * Load the PPD file using the newer API...
417 * Close the CUPS file and return the PPD...
427 * 'ppdOpen2()' - Read a PPD file into memory.
432 ppd_file_t
* /* O - PPD file record */
433 ppdOpen2(cups_file_t
*fp
) /* I - File to read from */
435 int i
, j
, k
; /* Looping vars */
436 int count
; /* Temporary count */
437 ppd_file_t
*ppd
; /* PPD file record */
438 ppd_group_t
*group
, /* Current group */
439 *subgroup
; /* Current sub-group */
440 ppd_option_t
*option
; /* Current option */
441 ppd_choice_t
*choice
; /* Current choice */
442 ppd_const_t
*constraint
; /* Current constraint */
443 ppd_size_t
*size
; /* Current page size */
444 int mask
; /* Line data mask */
445 char keyword
[PPD_MAX_NAME
],
446 /* Keyword from file */
448 /* Option from file */
450 /* Human-readable text from file */
451 *string
, /* Code/text from file */
452 *sptr
, /* Pointer into string */
453 *nameptr
, /* Pointer into name */
454 *temp
, /* Temporary string pointer */
455 **tempfonts
; /* Temporary fonts pointer */
456 float order
; /* Order dependency number */
457 ppd_section_t section
; /* Order dependency section */
458 ppd_profile_t
*profile
; /* Pointer to color profile */
459 char **filter
; /* Pointer to filter */
460 cups_lang_t
*language
; /* Default language */
461 struct lconv
*loc
; /* Locale data */
462 int ui_keyword
; /* Is this line a UI keyword? */
463 cups_encoding_t encoding
; /* Encoding of PPD file */
464 _cups_globals_t
*cg
= _cupsGlobals();
466 static const char * const ui_keywords
[] =
468 #ifdef CUPS_USE_FULL_UI_KEYWORDS_LIST
470 * Adobe defines some 41 keywords as "UI", meaning that they are
471 * user interface elements and that they should be treated as such
472 * even if the PPD creator doesn't use Open/CloseUI around them.
474 * Since this can cause previously invisible options to appear and
475 * confuse users, the default is to only treat the PageSize and
476 * PageRegion keywords this way.
478 /* Boolean keywords */
488 /* PickOne keywords */
501 "JCLFrameBufferSize",
522 #else /* !CUPS_USE_FULL_UI_KEYWORDS_LIST */
525 #endif /* CUPS_USE_FULL_UI_KEYWORDS_LIST */
530 * Default to "OK" status...
533 cg
->ppd_status
= PPD_OK
;
537 * Range check input...
542 cg
->ppd_status
= PPD_NULL_FILE
;
547 * Grab the first line and make sure it reads '*PPD-Adobe: "major.minor"'...
550 mask
= ppd_read(fp
, keyword
, name
, text
, &string
, 0, cg
);
552 DEBUG_printf(("mask=%x, keyword=\"%s\"...\n", mask
, keyword
));
555 strcmp(keyword
, "PPD-Adobe") ||
556 string
== NULL
|| string
[0] != '4')
559 * Either this is not a PPD file, or it is not a 4.x PPD file.
562 if (cg
->ppd_status
== PPD_OK
)
563 cg
->ppd_status
= PPD_MISSING_PPDADOBE4
;
570 DEBUG_printf(("ppdOpen: keyword = %s, string = %p\n", keyword
, string
));
575 * Allocate memory for the PPD file record...
578 if ((ppd
= calloc(1, sizeof(ppd_file_t
))) == NULL
)
580 cg
->ppd_status
= PPD_ALLOC_ERROR
;
585 ppd
->language_level
= 1;
586 ppd
->color_device
= 0;
587 ppd
->colorspace
= PPD_CS_GRAY
;
588 ppd
->landscape
= -90;
589 ppd
->coptions
= cupsArrayNew((cups_array_func_t
)ppd_compare_coptions
,
593 * Get the default language for the user...
596 language
= cupsLangDefault();
600 * Read lines from the PPD file and add them to the file record...
608 encoding
= CUPS_ISO8859_1
;
610 while ((mask
= ppd_read(fp
, keyword
, name
, text
, &string
, 1, cg
)) != 0)
613 printf("mask = %x, keyword = \"%s\"", mask
, keyword
);
616 printf(", name = \"%s\"", name
);
619 printf(", text = \"%s\"", text
);
623 if (strlen(string
) > 40)
624 printf(", string = %p", string
);
626 printf(", string = \"%s\"", string
);
632 if (strcmp(keyword
, "CloseUI") && strcmp(keyword
, "CloseGroup") &&
633 strcmp(keyword
, "CloseSubGroup") && strncmp(keyword
, "Default", 7) &&
634 strcmp(keyword
, "JCLCloseUI") && strcmp(keyword
, "JCLOpenUI") &&
635 strcmp(keyword
, "OpenUI") && strcmp(keyword
, "OpenGroup") &&
636 strcmp(keyword
, "OpenSubGroup") && string
== NULL
)
639 * Need a string value!
642 cg
->ppd_status
= PPD_MISSING_VALUE
;
648 * Certain main keywords (as defined by the PPD spec) may be used
649 * without the usual OpenUI/CloseUI stuff. Presumably this is just
650 * so that Adobe wouldn't completely break compatibility with PPD
651 * files prior to v4.0 of the spec, but it is hopelessly
652 * inconsistent... Catch these main keywords and automatically
653 * create the corresponding option, as needed...
659 * Previous line was a UI keyword...
666 if (option
== NULL
&&
667 (mask
& (PPD_KEYWORD
| PPD_OPTION
| PPD_STRING
)) ==
668 (PPD_KEYWORD
| PPD_OPTION
| PPD_STRING
))
670 for (i
= 0; i
< (int)(sizeof(ui_keywords
) / sizeof(ui_keywords
[0])); i
++)
671 if (!strcmp(keyword
, ui_keywords
[i
]))
674 if (i
< (int)(sizeof(ui_keywords
) / sizeof(ui_keywords
[0])))
677 * Create the option in the appropriate group...
682 DEBUG_printf(("**** FOUND ADOBE UI KEYWORD %s WITHOUT OPENUI!\n",
687 if ((group
= ppd_get_group(ppd
, "General", _("General"), cg
,
691 DEBUG_printf(("Adding to group %s...\n", group
->text
));
692 option
= ppd_get_option(group
, keyword
);
696 option
= ppd_get_option(group
, keyword
);
700 cg
->ppd_status
= PPD_ALLOC_ERROR
;
706 * Now fill in the initial information for the option...
709 if (!strncmp(keyword
, "JCL", 3))
710 option
->section
= PPD_ORDER_JCL
;
712 option
->section
= PPD_ORDER_ANY
;
714 option
->order
= 10.0f
;
717 option
->ui
= PPD_UI_BOOLEAN
;
719 option
->ui
= PPD_UI_PICKONE
;
721 for (j
= 0; j
< ppd
->num_attrs
; j
++)
722 if (!strncmp(ppd
->attrs
[j
]->name
, "Default", 7) &&
723 !strcmp(ppd
->attrs
[j
]->name
+ 7, keyword
) &&
724 ppd
->attrs
[j
]->value
)
726 DEBUG_printf(("Setting Default%s to %s via attribute...\n",
727 option
->keyword
, ppd
->attrs
[j
]->value
));
728 strlcpy(option
->defchoice
, ppd
->attrs
[j
]->value
,
729 sizeof(option
->defchoice
));
733 if (!strcmp(keyword
, "PageSize"))
734 strlcpy(option
->text
, _("Media Size"), sizeof(option
->text
));
735 else if (!strcmp(keyword
, "MediaType"))
736 strlcpy(option
->text
, _("Media Type"), sizeof(option
->text
));
737 else if (!strcmp(keyword
, "InputSlot"))
738 strlcpy(option
->text
, _("Media Source"), sizeof(option
->text
));
739 else if (!strcmp(keyword
, "ColorModel"))
740 strlcpy(option
->text
, _("Output Mode"), sizeof(option
->text
));
741 else if (!strcmp(keyword
, "Resolution"))
742 strlcpy(option
->text
, _("Resolution"), sizeof(option
->text
));
744 strlcpy(option
->text
, keyword
, sizeof(option
->text
));
748 if (!strcmp(keyword
, "LanguageLevel"))
749 ppd
->language_level
= atoi(string
);
750 else if (!strcmp(keyword
, "LanguageEncoding"))
753 * Say all PPD files are UTF-8, since we convert to UTF-8...
756 ppd
->lang_encoding
= strdup("UTF-8");
757 encoding
= _ppdGetEncoding(string
);
759 else if (!strcmp(keyword
, "LanguageVersion"))
760 ppd
->lang_version
= string
;
761 else if (!strcmp(keyword
, "Manufacturer"))
762 ppd
->manufacturer
= string
;
763 else if (!strcmp(keyword
, "ModelName"))
764 ppd
->modelname
= string
;
765 else if (!strcmp(keyword
, "Protocols"))
766 ppd
->protocols
= string
;
767 else if (!strcmp(keyword
, "PCFileName"))
768 ppd
->pcfilename
= string
;
769 else if (!strcmp(keyword
, "NickName"))
771 if (encoding
!= CUPS_UTF8
)
773 cups_utf8_t utf8
[256]; /* UTF-8 version of NickName */
776 cupsCharsetToUTF8(utf8
, string
, sizeof(utf8
), encoding
);
777 ppd
->nickname
= strdup((char *)utf8
);
780 ppd
->nickname
= strdup(string
);
782 else if (!strcmp(keyword
, "Product"))
783 ppd
->product
= string
;
784 else if (!strcmp(keyword
, "ShortNickName"))
785 ppd
->shortnickname
= string
;
786 else if (!strcmp(keyword
, "TTRasterizer"))
787 ppd
->ttrasterizer
= string
;
788 else if (!strcmp(keyword
, "JCLBegin"))
790 ppd
->jcl_begin
= strdup(string
);
791 ppd_decode(ppd
->jcl_begin
); /* Decode quoted string */
793 else if (!strcmp(keyword
, "JCLEnd"))
795 ppd
->jcl_end
= strdup(string
);
796 ppd_decode(ppd
->jcl_end
); /* Decode quoted string */
798 else if (!strcmp(keyword
, "JCLToPSInterpreter"))
800 ppd
->jcl_ps
= strdup(string
);
801 ppd_decode(ppd
->jcl_ps
); /* Decode quoted string */
803 else if (!strcmp(keyword
, "AccurateScreensSupport"))
804 ppd
->accurate_screens
= !strcmp(string
, "True");
805 else if (!strcmp(keyword
, "ColorDevice"))
806 ppd
->color_device
= !strcmp(string
, "True");
807 else if (!strcmp(keyword
, "ContoneOnly"))
808 ppd
->contone_only
= !strcmp(string
, "True");
809 else if (!strcmp(keyword
, "cupsFlipDuplex"))
810 ppd
->flip_duplex
= !strcmp(string
, "True");
811 else if (!strcmp(keyword
, "cupsManualCopies"))
812 ppd
->manual_copies
= !strcmp(string
, "True");
813 else if (!strcmp(keyword
, "cupsModelNumber"))
814 ppd
->model_number
= atoi(string
);
815 else if (!strcmp(keyword
, "cupsColorProfile"))
817 if (ppd
->num_profiles
== 0)
818 profile
= malloc(sizeof(ppd_profile_t
));
820 profile
= realloc(ppd
->profiles
, sizeof(ppd_profile_t
) *
821 (ppd
->num_profiles
+ 1));
823 ppd
->profiles
= profile
;
824 profile
+= ppd
->num_profiles
;
825 ppd
->num_profiles
++;
827 memset(profile
, 0, sizeof(ppd_profile_t
));
828 strlcpy(profile
->resolution
, name
, sizeof(profile
->resolution
));
829 strlcpy(profile
->media_type
, text
, sizeof(profile
->media_type
));
831 profile
->density
= (float)_cupsStrScand(string
, &sptr
, loc
);
832 profile
->gamma
= (float)_cupsStrScand(sptr
, &sptr
, loc
);
833 profile
->matrix
[0][0] = (float)_cupsStrScand(sptr
, &sptr
, loc
);
834 profile
->matrix
[0][1] = (float)_cupsStrScand(sptr
, &sptr
, loc
);
835 profile
->matrix
[0][2] = (float)_cupsStrScand(sptr
, &sptr
, loc
);
836 profile
->matrix
[1][0] = (float)_cupsStrScand(sptr
, &sptr
, loc
);
837 profile
->matrix
[1][1] = (float)_cupsStrScand(sptr
, &sptr
, loc
);
838 profile
->matrix
[1][2] = (float)_cupsStrScand(sptr
, &sptr
, loc
);
839 profile
->matrix
[2][0] = (float)_cupsStrScand(sptr
, &sptr
, loc
);
840 profile
->matrix
[2][1] = (float)_cupsStrScand(sptr
, &sptr
, loc
);
841 profile
->matrix
[2][2] = (float)_cupsStrScand(sptr
, &sptr
, loc
);
843 else if (!strcmp(keyword
, "cupsFilter"))
845 if (ppd
->num_filters
== 0)
846 filter
= malloc(sizeof(char *));
848 filter
= realloc(ppd
->filters
, sizeof(char *) * (ppd
->num_filters
+ 1));
854 cg
->ppd_status
= PPD_ALLOC_ERROR
;
859 ppd
->filters
= filter
;
860 filter
+= ppd
->num_filters
;
864 * Copy filter string and prevent it from being freed below...
870 else if (!strcmp(keyword
, "Throughput"))
871 ppd
->throughput
= atoi(string
);
872 else if (!strcmp(keyword
, "Font"))
875 * Add this font to the list of available fonts...
878 if (ppd
->num_fonts
== 0)
879 tempfonts
= (char **)malloc(sizeof(char *));
881 tempfonts
= (char **)realloc(ppd
->fonts
,
882 sizeof(char *) * (ppd
->num_fonts
+ 1));
884 if (tempfonts
== NULL
)
886 cg
->ppd_status
= PPD_ALLOC_ERROR
;
891 ppd
->fonts
= tempfonts
;
892 ppd
->fonts
[ppd
->num_fonts
] = strdup(name
);
895 else if (!strncmp(keyword
, "ParamCustom", 11))
897 ppd_coption_t
*coption
; /* Custom option */
898 ppd_cparam_t
*cparam
; /* Custom parameter */
899 int corder
; /* Order number */
900 char ctype
[33], /* Data type */
901 cminimum
[65], /* Minimum value */
902 cmaximum
[65]; /* Maximum value */
906 * Get the custom option and parameter...
909 if ((coption
= ppd_get_coption(ppd
, keyword
+ 11)) == NULL
)
911 cg
->ppd_status
= PPD_ALLOC_ERROR
;
916 if ((cparam
= ppd_get_cparam(coption
, name
, text
)) == NULL
)
918 cg
->ppd_status
= PPD_ALLOC_ERROR
;
924 * Get the parameter data...
927 if (sscanf(string
, "%d%32s%64s%64s", &corder
, ctype
, cminimum
,
930 cg
->ppd_status
= PPD_BAD_CUSTOM_PARAM
;
935 cparam
->order
= corder
;
937 if (!strcmp(ctype
, "curve"))
939 cparam
->type
= PPD_CUSTOM_CURVE
;
940 cparam
->minimum
.custom_curve
= (float)_cupsStrScand(cminimum
, NULL
, loc
);
941 cparam
->maximum
.custom_curve
= (float)_cupsStrScand(cmaximum
, NULL
, loc
);
943 else if (!strcmp(ctype
, "int"))
945 cparam
->type
= PPD_CUSTOM_INT
;
946 cparam
->minimum
.custom_int
= atoi(cminimum
);
947 cparam
->maximum
.custom_int
= atoi(cmaximum
);
949 else if (!strcmp(ctype
, "invcurve"))
951 cparam
->type
= PPD_CUSTOM_INVCURVE
;
952 cparam
->minimum
.custom_invcurve
= (float)_cupsStrScand(cminimum
, NULL
, loc
);
953 cparam
->maximum
.custom_invcurve
= (float)_cupsStrScand(cmaximum
, NULL
, loc
);
955 else if (!strcmp(ctype
, "passcode"))
957 cparam
->type
= PPD_CUSTOM_PASSCODE
;
958 cparam
->minimum
.custom_passcode
= atoi(cminimum
);
959 cparam
->maximum
.custom_passcode
= atoi(cmaximum
);
961 else if (!strcmp(ctype
, "password"))
963 cparam
->type
= PPD_CUSTOM_PASSWORD
;
964 cparam
->minimum
.custom_password
= atoi(cminimum
);
965 cparam
->maximum
.custom_password
= atoi(cmaximum
);
967 else if (!strcmp(ctype
, "points"))
969 cparam
->type
= PPD_CUSTOM_POINTS
;
970 cparam
->minimum
.custom_points
= (float)_cupsStrScand(cminimum
, NULL
, loc
);
971 cparam
->maximum
.custom_points
= (float)_cupsStrScand(cmaximum
, NULL
, loc
);
973 else if (!strcmp(ctype
, "real"))
975 cparam
->type
= PPD_CUSTOM_REAL
;
976 cparam
->minimum
.custom_real
= (float)_cupsStrScand(cminimum
, NULL
, loc
);
977 cparam
->maximum
.custom_real
= (float)_cupsStrScand(cmaximum
, NULL
, loc
);
979 else if (!strcmp(ctype
, "string"))
981 cparam
->type
= PPD_CUSTOM_STRING
;
982 cparam
->minimum
.custom_string
= atoi(cminimum
);
983 cparam
->maximum
.custom_string
= atoi(cmaximum
);
987 cg
->ppd_status
= PPD_BAD_CUSTOM_PARAM
;
993 * Now special-case for CustomPageSize...
996 if (!strcmp(coption
->keyword
, "PageSize"))
998 if (!strcmp(name
, "Width"))
1000 ppd
->custom_min
[0] = cparam
->minimum
.custom_points
;
1001 ppd
->custom_max
[0] = cparam
->maximum
.custom_points
;
1003 else if (!strcmp(name
, "Height"))
1005 ppd
->custom_min
[1] = cparam
->minimum
.custom_points
;
1006 ppd
->custom_max
[1] = cparam
->maximum
.custom_points
;
1010 else if (!strcmp(keyword
, "HWMargins"))
1012 for (i
= 0, sptr
= string
; i
< 4; i
++)
1013 ppd
->custom_margins
[i
] = (float)_cupsStrScand(sptr
, &sptr
, loc
);
1015 else if (!strncmp(keyword
, "Custom", 6) && !strcmp(name
, "True") && !option
)
1017 DEBUG_puts("Processing Custom option...");
1020 * Get the option and custom option...
1023 if ((option
= ppdFindOption(ppd
, keyword
+ 6)) == NULL
)
1025 ppd_group_t
*gtemp
; /* Temporary group */
1028 DEBUG_printf(("%s option not found for %s...\n", keyword
+ 6, keyword
));
1030 if ((gtemp
= ppd_get_group(ppd
, "General", _("General"), cg
,
1033 DEBUG_puts("Unable to get general group!");
1038 if ((option
= ppd_get_option(gtemp
, keyword
+ 6)) == NULL
)
1040 DEBUG_printf(("Unable to get %s option!\n", keyword
+ 6));
1042 cg
->ppd_status
= PPD_ALLOC_ERROR
;
1048 if (!ppd_get_coption(ppd
, keyword
+ 6))
1050 cg
->ppd_status
= PPD_ALLOC_ERROR
;
1056 * Add the "custom" option...
1059 if ((choice
= ppd_add_choice(option
, "Custom")) == NULL
)
1061 DEBUG_puts("Unable to add Custom choice!");
1063 cg
->ppd_status
= PPD_ALLOC_ERROR
;
1068 strlcpy(choice
->text
, text
[0] ? text
: _("Custom"),
1069 sizeof(choice
->text
));
1071 choice
->code
= string
;
1072 string
= NULL
; /* Don't add as an attribute below */
1076 * Now process custom page sizes specially...
1079 if (!strcmp(keyword
, "CustomPageSize"))
1081 ppd
->variable_sizes
= 1;
1084 * Add a "Custom" page size entry...
1087 ppd_add_size(ppd
, "Custom");
1089 if ((option
= ppdFindOption(ppd
, "PageRegion")) == NULL
)
1091 ppd_group_t
*gtemp
; /* Temporary group */
1093 if ((gtemp
= ppd_get_group(ppd
, "General", _("General"), cg
,
1096 DEBUG_puts("Unable to get general group!");
1101 option
= ppd_get_option(gtemp
, "PageRegion");
1104 if ((choice
= ppd_add_choice(option
, "Custom")) == NULL
)
1106 DEBUG_puts("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"))
1127 for (count
= 1, sptr
= string
; sptr
!= NULL
;)
1128 if ((sptr
= strchr(sptr
, ' ')) != NULL
)
1131 while (*sptr
== ' ')
1135 ppd
->num_emulations
= count
;
1136 ppd
->emulations
= calloc(count
, sizeof(ppd_emul_t
));
1138 for (i
= 0, sptr
= string
; i
< count
; i
++)
1140 for (nameptr
= ppd
->emulations
[i
].name
;
1141 *sptr
!= '\0' && *sptr
!= ' ';
1143 if (nameptr
< (ppd
->emulations
[i
].name
+ sizeof(ppd
->emulations
[i
].name
) - 1))
1148 while (*sptr
== ' ')
1152 else if (!strncmp(keyword
, "StartEmulator_", 14))
1156 for (i
= 0; i
< ppd
->num_emulations
; i
++)
1157 if (!strcmp(keyword
+ 14, ppd
->emulations
[i
].name
))
1159 ppd
->emulations
[i
].start
= string
;
1163 else if (!strncmp(keyword
, "StopEmulator_", 13))
1167 for (i
= 0; i
< ppd
->num_emulations
; i
++)
1168 if (!strcmp(keyword
+ 13, ppd
->emulations
[i
].name
))
1170 ppd
->emulations
[i
].stop
= string
;
1174 else if (!strcmp(keyword
, "JobPatchFile"))
1176 if (ppd
->patches
== NULL
)
1177 ppd
->patches
= strdup(string
);
1180 temp
= realloc(ppd
->patches
, strlen(ppd
->patches
) +
1181 strlen(string
) + 1);
1184 cg
->ppd_status
= PPD_ALLOC_ERROR
;
1189 ppd
->patches
= temp
;
1191 strcpy(ppd
->patches
+ strlen(ppd
->patches
), string
);
1194 else if (!strcmp(keyword
, "OpenUI"))
1197 * Don't allow nesting of options...
1200 if (option
&& cg
->ppd_conform
== PPD_CONFORM_STRICT
)
1202 cg
->ppd_status
= PPD_NESTED_OPEN_UI
;
1208 * Add an option record to the current sub-group, group, or file...
1212 _cups_strcpy(name
, name
+ 1); /* Eliminate leading asterisk */
1214 for (i
= (int)strlen(name
) - 1; i
> 0 && isspace(name
[i
] & 255); i
--)
1215 name
[i
] = '\0'; /* Eliminate trailing spaces */
1217 DEBUG_printf(("OpenUI of %s in group %s...\n", name
,
1218 group
? group
->text
: "(null)"));
1220 if (subgroup
!= NULL
)
1221 option
= ppd_get_option(subgroup
, name
);
1222 else if (group
== NULL
)
1224 if ((group
= ppd_get_group(ppd
, "General", _("General"), cg
,
1228 DEBUG_printf(("Adding to group %s...\n", group
->text
));
1229 option
= ppd_get_option(group
, name
);
1233 option
= ppd_get_option(group
, name
);
1237 cg
->ppd_status
= PPD_ALLOC_ERROR
;
1243 * Now fill in the initial information for the option...
1246 if (string
&& !strcmp(string
, "PickMany"))
1247 option
->ui
= PPD_UI_PICKMANY
;
1248 else if (string
&& !strcmp(string
, "Boolean"))
1249 option
->ui
= PPD_UI_BOOLEAN
;
1250 else if (string
&& !strcmp(string
, "PickOne"))
1251 option
->ui
= PPD_UI_PICKONE
;
1252 else if (cg
->ppd_conform
== PPD_CONFORM_STRICT
)
1254 cg
->ppd_status
= PPD_BAD_OPEN_UI
;
1259 option
->ui
= PPD_UI_PICKONE
;
1261 for (j
= 0; j
< ppd
->num_attrs
; j
++)
1262 if (!strncmp(ppd
->attrs
[j
]->name
, "Default", 7) &&
1263 !strcmp(ppd
->attrs
[j
]->name
+ 7, name
) &&
1264 ppd
->attrs
[j
]->value
)
1266 DEBUG_printf(("Setting Default%s to %s via attribute...\n",
1267 option
->keyword
, ppd
->attrs
[j
]->value
));
1268 strlcpy(option
->defchoice
, ppd
->attrs
[j
]->value
,
1269 sizeof(option
->defchoice
));
1274 cupsCharsetToUTF8((cups_utf8_t
*)option
->text
, text
,
1275 sizeof(option
->text
), encoding
);
1278 if (!strcmp(name
, "PageSize"))
1279 strlcpy(option
->text
, _("Media Size"), sizeof(option
->text
));
1280 else if (!strcmp(name
, "MediaType"))
1281 strlcpy(option
->text
, _("Media Type"), sizeof(option
->text
));
1282 else if (!strcmp(name
, "InputSlot"))
1283 strlcpy(option
->text
, _("Media Source"), sizeof(option
->text
));
1284 else if (!strcmp(name
, "ColorModel"))
1285 strlcpy(option
->text
, _("Output Mode"), sizeof(option
->text
));
1286 else if (!strcmp(name
, "Resolution"))
1287 strlcpy(option
->text
, _("Resolution"), sizeof(option
->text
));
1289 strlcpy(option
->text
, name
, sizeof(option
->text
));
1292 option
->section
= PPD_ORDER_ANY
;
1297 else if (!strcmp(keyword
, "JCLOpenUI"))
1300 * Don't allow nesting of options...
1303 if (option
&& cg
->ppd_conform
== PPD_CONFORM_STRICT
)
1305 cg
->ppd_status
= PPD_NESTED_OPEN_UI
;
1311 * Find the JCL group, and add if needed...
1314 group
= ppd_get_group(ppd
, "JCL", _("JCL"), cg
, encoding
);
1320 * Add an option record to the current JCLs...
1324 _cups_strcpy(name
, name
+ 1);
1326 option
= ppd_get_option(group
, name
);
1330 cg
->ppd_status
= PPD_ALLOC_ERROR
;
1336 * Now fill in the initial information for the option...
1339 if (string
&& !strcmp(string
, "PickMany"))
1340 option
->ui
= PPD_UI_PICKMANY
;
1341 else if (string
&& !strcmp(string
, "Boolean"))
1342 option
->ui
= PPD_UI_BOOLEAN
;
1343 else if (string
&& !strcmp(string
, "PickOne"))
1344 option
->ui
= PPD_UI_PICKONE
;
1347 cg
->ppd_status
= PPD_BAD_OPEN_UI
;
1352 for (j
= 0; j
< ppd
->num_attrs
; j
++)
1353 if (!strncmp(ppd
->attrs
[j
]->name
, "Default", 7) &&
1354 !strcmp(ppd
->attrs
[j
]->name
+ 7, name
) &&
1355 ppd
->attrs
[j
]->value
)
1357 DEBUG_printf(("Setting Default%s to %s via attribute...\n",
1358 option
->keyword
, ppd
->attrs
[j
]->value
));
1359 strlcpy(option
->defchoice
, ppd
->attrs
[j
]->value
,
1360 sizeof(option
->defchoice
));
1365 cupsCharsetToUTF8((cups_utf8_t
*)option
->text
, text
,
1366 sizeof(option
->text
), encoding
);
1368 strlcpy(option
->text
, name
, sizeof(option
->text
));
1370 option
->section
= PPD_ORDER_JCL
;
1376 else if (!strcmp(keyword
, "CloseUI") || !strcmp(keyword
, "JCLCloseUI"))
1383 else if (!strcmp(keyword
, "OpenGroup"))
1386 * Open a new group...
1391 cg
->ppd_status
= PPD_NESTED_OPEN_GROUP
;
1398 cg
->ppd_status
= PPD_BAD_OPEN_GROUP
;
1404 * Separate the group name from the text (name/text)...
1407 if ((sptr
= strchr(string
, '/')) != NULL
)
1413 * Fix up the text...
1419 * Find/add the group...
1422 group
= ppd_get_group(ppd
, string
, sptr
, cg
, encoding
);
1430 else if (!strcmp(keyword
, "CloseGroup"))
1437 else if (!strcmp(keyword
, "OrderDependency") ||
1438 !strcmp(keyword
, "NonUIOrderDependency"))
1440 order
= (float)_cupsStrScand(string
, &sptr
, loc
);
1442 if (!sptr
|| sscanf(sptr
, "%40s%40s", name
, keyword
) != 2)
1444 cg
->ppd_status
= PPD_BAD_ORDER_DEPENDENCY
;
1449 if (keyword
[0] == '*')
1450 _cups_strcpy(keyword
, keyword
+ 1);
1452 if (!strcmp(name
, "ExitServer"))
1453 section
= PPD_ORDER_EXIT
;
1454 else if (!strcmp(name
, "Prolog"))
1455 section
= PPD_ORDER_PROLOG
;
1456 else if (!strcmp(name
, "DocumentSetup"))
1457 section
= PPD_ORDER_DOCUMENT
;
1458 else if (!strcmp(name
, "PageSetup"))
1459 section
= PPD_ORDER_PAGE
;
1460 else if (!strcmp(name
, "JCLSetup"))
1461 section
= PPD_ORDER_JCL
;
1463 section
= PPD_ORDER_ANY
;
1471 * Only valid for Non-UI options...
1474 for (i
= ppd
->num_groups
, gtemp
= ppd
->groups
; i
> 0; i
--, gtemp
++)
1475 if (gtemp
->text
[0] == '\0')
1479 for (i
= 0; i
< gtemp
->num_options
; i
++)
1480 if (!strcmp(keyword
, gtemp
->options
[i
].keyword
))
1482 gtemp
->options
[i
].section
= section
;
1483 gtemp
->options
[i
].order
= order
;
1489 option
->section
= section
;
1490 option
->order
= order
;
1496 else if (!strncmp(keyword
, "Default", 7))
1502 * Drop UI text, if any, from value...
1505 if (strchr(string
, '/') != NULL
)
1506 *strchr(string
, '/') = '\0';
1509 * Assign the default value as appropriate...
1512 if (!strcmp(keyword
, "DefaultColorSpace"))
1515 * Set default colorspace...
1518 if (!strcmp(string
, "CMY"))
1519 ppd
->colorspace
= PPD_CS_CMY
;
1520 else if (!strcmp(string
, "CMYK"))
1521 ppd
->colorspace
= PPD_CS_CMYK
;
1522 else if (!strcmp(string
, "RGB"))
1523 ppd
->colorspace
= PPD_CS_RGB
;
1524 else if (!strcmp(string
, "RGBK"))
1525 ppd
->colorspace
= PPD_CS_RGBK
;
1526 else if (!strcmp(string
, "N"))
1527 ppd
->colorspace
= PPD_CS_N
;
1529 ppd
->colorspace
= PPD_CS_GRAY
;
1531 else if (option
&& !strcmp(keyword
+ 7, option
->keyword
))
1534 * Set the default as part of the current option...
1537 DEBUG_printf(("Setting %s to %s...\n", keyword
, string
));
1539 strlcpy(option
->defchoice
, string
, sizeof(option
->defchoice
));
1541 DEBUG_printf(("%s is now %s...\n", keyword
, option
->defchoice
));
1546 * Lookup option and set if it has been defined...
1549 ppd_option_t
*toption
; /* Temporary option */
1552 if ((toption
= ppdFindOption(ppd
, keyword
+ 7)) != NULL
)
1554 DEBUG_printf(("Setting %s to %s...\n", keyword
, string
));
1555 strlcpy(toption
->defchoice
, string
, sizeof(toption
->defchoice
));
1559 else if (!strcmp(keyword
, "UIConstraints") ||
1560 !strcmp(keyword
, "NonUIConstraints"))
1562 if (ppd
->num_consts
== 0)
1563 constraint
= calloc(2, sizeof(ppd_const_t
));
1565 constraint
= realloc(ppd
->consts
,
1566 (ppd
->num_consts
+ 2) * sizeof(ppd_const_t
));
1568 if (constraint
== NULL
)
1570 cg
->ppd_status
= PPD_ALLOC_ERROR
;
1575 ppd
->consts
= constraint
;
1576 constraint
+= ppd
->num_consts
;
1579 switch (sscanf(string
, "%40s%40s%40s%40s", constraint
->option1
,
1580 constraint
->choice1
, constraint
->option2
,
1581 constraint
->choice2
))
1583 case 0 : /* Error */
1584 case 1 : /* Error */
1585 cg
->ppd_status
= PPD_BAD_UI_CONSTRAINTS
;
1588 case 2 : /* Two options... */
1590 * Check for broken constraints like "* Option"...
1593 if (cg
->ppd_conform
== PPD_CONFORM_STRICT
&&
1594 (!strcmp(constraint
->option1
, "*") ||
1595 !strcmp(constraint
->choice1
, "*")))
1597 cg
->ppd_status
= PPD_BAD_UI_CONSTRAINTS
;
1602 * The following strcpy's are safe, as optionN and
1603 * choiceN are all the same size (size defined by PPD spec...)
1606 if (constraint
->option1
[0] == '*')
1607 _cups_strcpy(constraint
->option1
, constraint
->option1
+ 1);
1608 else if (cg
->ppd_conform
== PPD_CONFORM_STRICT
)
1610 cg
->ppd_status
= PPD_BAD_UI_CONSTRAINTS
;
1614 if (constraint
->choice1
[0] == '*')
1615 _cups_strcpy(constraint
->option2
, constraint
->choice1
+ 1);
1616 else if (cg
->ppd_conform
== PPD_CONFORM_STRICT
)
1618 cg
->ppd_status
= PPD_BAD_UI_CONSTRAINTS
;
1622 constraint
->choice1
[0] = '\0';
1623 constraint
->choice2
[0] = '\0';
1626 case 3 : /* Two options, one choice... */
1628 * Check for broken constraints like "* Option"...
1631 if (cg
->ppd_conform
== PPD_CONFORM_STRICT
&&
1632 (!strcmp(constraint
->option1
, "*") ||
1633 !strcmp(constraint
->choice1
, "*") ||
1634 !strcmp(constraint
->option2
, "*")))
1636 cg
->ppd_status
= PPD_BAD_UI_CONSTRAINTS
;
1641 * The following _cups_strcpy's are safe, as optionN and
1642 * choiceN are all the same size (size defined by PPD spec...)
1645 if (constraint
->option1
[0] == '*')
1646 _cups_strcpy(constraint
->option1
, constraint
->option1
+ 1);
1647 else if (cg
->ppd_conform
== PPD_CONFORM_STRICT
)
1649 cg
->ppd_status
= PPD_BAD_UI_CONSTRAINTS
;
1653 if (constraint
->choice1
[0] == '*')
1655 if (cg
->ppd_conform
== PPD_CONFORM_STRICT
&&
1656 constraint
->option2
[0] == '*')
1658 cg
->ppd_status
= PPD_BAD_UI_CONSTRAINTS
;
1662 _cups_strcpy(constraint
->choice2
, constraint
->option2
);
1663 _cups_strcpy(constraint
->option2
, constraint
->choice1
+ 1);
1664 constraint
->choice1
[0] = '\0';
1668 if (constraint
->option2
[0] == '*')
1669 _cups_strcpy(constraint
->option2
, constraint
->option2
+ 1);
1670 else if (cg
->ppd_conform
== PPD_CONFORM_STRICT
)
1672 cg
->ppd_status
= PPD_BAD_UI_CONSTRAINTS
;
1676 constraint
->choice2
[0] = '\0';
1680 case 4 : /* Two options, two choices... */
1682 * Check for broken constraints like "* Option"...
1685 if (cg
->ppd_conform
== PPD_CONFORM_STRICT
&&
1686 (!strcmp(constraint
->option1
, "*") ||
1687 !strcmp(constraint
->choice1
, "*") ||
1688 !strcmp(constraint
->option2
, "*") ||
1689 !strcmp(constraint
->choice2
, "*")))
1691 cg
->ppd_status
= PPD_BAD_UI_CONSTRAINTS
;
1695 if (constraint
->option1
[0] == '*')
1696 _cups_strcpy(constraint
->option1
, constraint
->option1
+ 1);
1697 else if (cg
->ppd_conform
== PPD_CONFORM_STRICT
)
1699 cg
->ppd_status
= PPD_BAD_UI_CONSTRAINTS
;
1703 if (cg
->ppd_conform
== PPD_CONFORM_STRICT
&&
1704 constraint
->choice1
[0] == '*')
1706 cg
->ppd_status
= PPD_BAD_UI_CONSTRAINTS
;
1710 if (constraint
->option2
[0] == '*')
1711 _cups_strcpy(constraint
->option2
, constraint
->option2
+ 1);
1712 else if (cg
->ppd_conform
== PPD_CONFORM_STRICT
)
1714 cg
->ppd_status
= PPD_BAD_UI_CONSTRAINTS
;
1718 if (cg
->ppd_conform
== PPD_CONFORM_STRICT
&&
1719 constraint
->choice2
[0] == '*')
1721 cg
->ppd_status
= PPD_BAD_UI_CONSTRAINTS
;
1728 * For CustomPageSize and InputSlot/ManualFeed, create a duplicate
1729 * constraint for PageRegion...
1732 if (!strcasecmp(constraint
->option1
, "CustomPageSize") &&
1733 (!strcasecmp(constraint
->option2
, "InputSlot") ||
1734 !strcasecmp(constraint
->option2
, "ManualFeed")))
1738 strcpy(constraint
[1].option1
, "PageRegion");
1739 strcpy(constraint
[1].choice1
, "Custom");
1740 strcpy(constraint
[1].option2
, constraint
->option2
);
1741 strcpy(constraint
[1].choice2
, constraint
->choice2
);
1743 else if (!strcasecmp(constraint
->option2
, "CustomPageSize") &&
1744 (!strcasecmp(constraint
->option1
, "InputSlot") ||
1745 !strcasecmp(constraint
->option1
, "ManualFeed")))
1749 strcpy(constraint
[1].option1
, constraint
->option1
);
1750 strcpy(constraint
[1].choice1
, constraint
->choice1
);
1751 strcpy(constraint
[1].option2
, "PageRegion");
1752 strcpy(constraint
[1].choice2
, "Custom");
1756 * Handle CustomFoo option constraints...
1759 if (!strncasecmp(constraint
->option1
, "Custom", 6) &&
1760 !strcasecmp(constraint
->choice1
, "True"))
1762 _cups_strcpy(constraint
->option1
, constraint
->option1
+ 6);
1763 strcpy(constraint
->choice1
, "Custom");
1766 if (!strncasecmp(constraint
->option2
, "Custom", 6) &&
1767 !strcasecmp(constraint
->choice2
, "True"))
1769 _cups_strcpy(constraint
->option2
, constraint
->option2
+ 6);
1770 strcpy(constraint
->choice2
, "Custom");
1774 * Don't add this one as an attribute...
1780 else if (!strcmp(keyword
, "PaperDimension"))
1782 if ((size
= ppdPageSize(ppd
, name
)) == NULL
)
1783 size
= ppd_add_size(ppd
, name
);
1788 * Unable to add or find size!
1791 cg
->ppd_status
= PPD_ALLOC_ERROR
;
1796 size
->width
= (float)_cupsStrScand(string
, &sptr
, loc
);
1797 size
->length
= (float)_cupsStrScand(sptr
, NULL
, loc
);
1802 else if (!strcmp(keyword
, "ImageableArea"))
1804 if ((size
= ppdPageSize(ppd
, name
)) == NULL
)
1805 size
= ppd_add_size(ppd
, name
);
1810 * Unable to add or find size!
1813 cg
->ppd_status
= PPD_ALLOC_ERROR
;
1818 size
->left
= (float)_cupsStrScand(string
, &sptr
, loc
);
1819 size
->bottom
= (float)_cupsStrScand(sptr
, &sptr
, loc
);
1820 size
->right
= (float)_cupsStrScand(sptr
, &sptr
, loc
);
1821 size
->top
= (float)_cupsStrScand(sptr
, NULL
, loc
);
1826 else if (option
!= NULL
&&
1827 (mask
& (PPD_KEYWORD
| PPD_OPTION
| PPD_STRING
)) ==
1828 (PPD_KEYWORD
| PPD_OPTION
| PPD_STRING
) &&
1829 !strcmp(keyword
, option
->keyword
))
1831 DEBUG_printf(("group = %p, subgroup = %p\n", group
, subgroup
));
1833 if (!strcmp(keyword
, "PageSize"))
1836 * Add a page size...
1839 if (ppdPageSize(ppd
, name
) == NULL
)
1840 ppd_add_size(ppd
, name
);
1844 * Add the option choice...
1847 choice
= ppd_add_choice(option
, name
);
1850 cupsCharsetToUTF8((cups_utf8_t
*)choice
->text
, text
,
1851 sizeof(choice
->text
), encoding
);
1852 else if (!strcmp(name
, "True"))
1853 strcpy(choice
->text
, _("Yes"));
1854 else if (!strcmp(name
, "False"))
1855 strcpy(choice
->text
, _("No"));
1857 strlcpy(choice
->text
, name
, sizeof(choice
->text
));
1859 if (option
->section
== PPD_ORDER_JCL
)
1860 ppd_decode(string
); /* Decode quoted string */
1862 choice
->code
= string
;
1863 string
= NULL
; /* Don't add as an attribute below */
1867 * Add remaining lines with keywords and string values as attributes...
1871 (mask
& (PPD_KEYWORD
| PPD_STRING
)) == (PPD_KEYWORD
| PPD_STRING
))
1872 ppd_add_attr(ppd
, keyword
, name
, text
, string
);
1878 * Reset language preferences...
1881 cupsLangFree(language
);
1885 printf("Premature EOF at %lu...\n", (unsigned long)ftell(fp
));
1888 if (cg
->ppd_status
!= PPD_OK
)
1891 * Had an error reading the PPD file, cannot continue!
1900 * Create the sorted options array and set the option back-pointer for
1901 * each choice and custom option...
1904 ppd
->options
= cupsArrayNew2((cups_array_func_t
)ppd_compare_options
, NULL
,
1905 (cups_ahash_func_t
)ppd_hash_option
,
1908 for (i
= ppd
->num_groups
, group
= ppd
->groups
;
1912 for (j
= group
->num_options
, option
= group
->options
;
1916 ppd_coption_t
*coption
; /* Custom option */
1919 cupsArrayAdd(ppd
->options
, option
);
1921 for (k
= 0; k
< option
->num_choices
; k
++)
1922 option
->choices
[k
].option
= option
;
1924 if ((coption
= ppdFindCustomOption(ppd
, option
->keyword
)) != NULL
)
1925 coption
->option
= option
;
1930 * Sort the constraints...
1933 if (ppd
->num_consts
> 1)
1934 qsort(ppd
->consts
, ppd
->num_consts
, sizeof(ppd_const_t
),
1935 (int (*)(const void *, const void *))ppd_compare_consts
);
1938 * Create an array to track the marked choices...
1941 ppd
->marked
= cupsArrayNew((cups_array_func_t
)ppd_compare_choices
, NULL
);
1944 * Return the PPD file structure...
1950 * Common exit point for errors to save code size...
1959 cupsLangFree(language
);
1966 * 'ppdOpenFd()' - Read a PPD file into memory.
1969 ppd_file_t
* /* O - PPD file record */
1970 ppdOpenFd(int fd
) /* I - File to read from */
1972 cups_file_t
*fp
; /* CUPS file pointer */
1973 ppd_file_t
*ppd
; /* PPD file record */
1974 _cups_globals_t
*cg
= _cupsGlobals();
1979 * Set the line number to 0...
1985 * Range check input...
1990 cg
->ppd_status
= PPD_NULL_FILE
;
1996 * Try to open the file and parse it...
1999 if ((fp
= cupsFileOpenFd(fd
, "r")) != NULL
)
2007 cg
->ppd_status
= PPD_FILE_OPEN_ERROR
;
2016 * 'ppdOpenFile()' - Read a PPD file into memory.
2019 ppd_file_t
* /* O - PPD file record */
2020 ppdOpenFile(const char *filename
) /* I - File to read from */
2022 cups_file_t
*fp
; /* File pointer */
2023 ppd_file_t
*ppd
; /* PPD file record */
2024 _cups_globals_t
*cg
= _cupsGlobals();
2029 * Set the line number to 0...
2035 * Range check input...
2038 if (filename
== NULL
)
2040 cg
->ppd_status
= PPD_NULL_FILE
;
2046 * Try to open the file and parse it...
2049 if ((fp
= cupsFileOpen(filename
, "r")) != NULL
)
2057 cg
->ppd_status
= PPD_FILE_OPEN_ERROR
;
2066 * 'ppdSetConformance()' - Set the conformance level for PPD files.
2068 * @since CUPS 1.1.20@
2072 ppdSetConformance(ppd_conform_t c
) /* I - Conformance level */
2074 _cups_globals_t
*cg
= _cupsGlobals();
2078 cg
->ppd_conform
= c
;
2083 * 'ppd_add_attr()' - Add an attribute to the PPD data.
2086 static ppd_attr_t
* /* O - New attribute */
2087 ppd_add_attr(ppd_file_t
*ppd
, /* I - PPD file data */
2088 const char *name
, /* I - Attribute name */
2089 const char *spec
, /* I - Specifier string, if any */
2090 const char *text
, /* I - Text string, if any */
2091 const char *value
) /* I - Value of attribute */
2093 ppd_attr_t
**ptr
, /* New array */
2094 *temp
; /* New attribute */
2098 * Range check input...
2101 if (ppd
== NULL
|| name
== NULL
|| spec
== NULL
)
2105 * Create the array as needed...
2108 if (!ppd
->sorted_attrs
)
2109 ppd
->sorted_attrs
= cupsArrayNew((cups_array_func_t
)ppd_compare_attrs
,
2113 * Allocate memory for the new attribute...
2116 if (ppd
->num_attrs
== 0)
2117 ptr
= malloc(sizeof(ppd_attr_t
*));
2119 ptr
= realloc(ppd
->attrs
, (ppd
->num_attrs
+ 1) * sizeof(ppd_attr_t
*));
2125 ptr
+= ppd
->num_attrs
;
2127 if ((temp
= calloc(1, sizeof(ppd_attr_t
))) == NULL
)
2138 strlcpy(temp
->name
, name
, sizeof(temp
->name
));
2139 strlcpy(temp
->spec
, spec
, sizeof(temp
->spec
));
2140 strlcpy(temp
->text
, text
, sizeof(temp
->text
));
2141 temp
->value
= (char *)value
;
2144 * Add the attribute to the sorted array...
2147 cupsArrayAdd(ppd
->sorted_attrs
, temp
);
2150 * Return the attribute...
2158 * 'ppd_add_choice()' - Add a choice to an option.
2161 static ppd_choice_t
* /* O - Named choice */
2162 ppd_add_choice(ppd_option_t
*option
, /* I - Option */
2163 const char *name
) /* I - Name of choice */
2165 ppd_choice_t
*choice
; /* Choice */
2168 if (option
->num_choices
== 0)
2169 choice
= malloc(sizeof(ppd_choice_t
));
2171 choice
= realloc(option
->choices
,
2172 sizeof(ppd_choice_t
) * (option
->num_choices
+ 1));
2177 option
->choices
= choice
;
2178 choice
+= option
->num_choices
;
2179 option
->num_choices
++;
2181 memset(choice
, 0, sizeof(ppd_choice_t
));
2182 strlcpy(choice
->choice
, name
, sizeof(choice
->choice
));
2189 * 'ppd_add_size()' - Add a page size.
2192 static ppd_size_t
* /* O - Named size */
2193 ppd_add_size(ppd_file_t
*ppd
, /* I - PPD file */
2194 const char *name
) /* I - Name of size */
2196 ppd_size_t
*size
; /* Size */
2199 if (ppd
->num_sizes
== 0)
2200 size
= malloc(sizeof(ppd_size_t
));
2202 size
= realloc(ppd
->sizes
, sizeof(ppd_size_t
) * (ppd
->num_sizes
+ 1));
2208 size
+= ppd
->num_sizes
;
2211 memset(size
, 0, sizeof(ppd_size_t
));
2212 strlcpy(size
->name
, name
, sizeof(size
->name
));
2219 * 'ppd_compare_attrs()' - Compare two attributes.
2222 static int /* O - Result of comparison */
2223 ppd_compare_attrs(ppd_attr_t
*a
, /* I - First attribute */
2224 ppd_attr_t
*b
) /* I - Second attribute */
2226 int ret
; /* Result of comparison */
2229 if ((ret
= strcasecmp(a
->name
, b
->name
)) != 0)
2232 return (strcasecmp(a
->spec
, b
->spec
));
2237 * 'ppd_compare_choices()' - Compare two choices...
2240 static int /* O - Result of comparison */
2241 ppd_compare_choices(ppd_choice_t
*a
, /* I - First choice */
2242 ppd_choice_t
*b
) /* I - Second choice */
2244 return (a
->option
- b
->option
);
2249 * 'ppd_compare_consts()' - Compare two constraints.
2252 static int /* O - Result of comparison */
2253 ppd_compare_consts(ppd_const_t
*a
, /* I - First constraint */
2254 ppd_const_t
*b
) /* I - Second constraint */
2256 int ret
; /* Result of comparison */
2259 if ((ret
= strcmp(a
->option1
, b
->option1
)) != 0)
2261 else if ((ret
= strcmp(a
->choice1
, b
->choice1
)) != 0)
2263 else if ((ret
= strcmp(a
->option2
, b
->option2
)) != 0)
2266 return (strcmp(a
->choice2
, b
->choice2
));
2271 * 'ppd_compare_coptions()' - Compare two custom options.
2274 static int /* O - Result of comparison */
2275 ppd_compare_coptions(ppd_coption_t
*a
, /* I - First option */
2276 ppd_coption_t
*b
) /* I - Second option */
2278 return (strcasecmp(a
->keyword
, b
->keyword
));
2283 * 'ppd_compare_cparams()' - Compare two custom parameters.
2286 static int /* O - Result of comparison */
2287 ppd_compare_cparams(ppd_cparam_t
*a
, /* I - First parameter */
2288 ppd_cparam_t
*b
) /* I - Second parameter */
2290 return (strcasecmp(a
->name
, b
->name
));
2295 * 'ppd_compare_options()' - Compare two options.
2298 static int /* O - Result of comparison */
2299 ppd_compare_options(ppd_option_t
*a
, /* I - First option */
2300 ppd_option_t
*b
) /* I - Second option */
2302 return (strcasecmp(a
->keyword
, b
->keyword
));
2307 * 'ppd_decode()' - Decode a string value...
2310 static int /* O - Length of decoded string */
2311 ppd_decode(char *string
) /* I - String to decode */
2313 char *inptr
, /* Input pointer */
2314 *outptr
; /* Output pointer */
2320 while (*inptr
!= '\0')
2321 if (*inptr
== '<' && isxdigit(inptr
[1] & 255))
2324 * Convert hex to 8-bit values...
2328 while (isxdigit(*inptr
& 255))
2330 if (isalpha(*inptr
))
2331 *outptr
= (tolower(*inptr
) - 'a' + 10) << 4;
2333 *outptr
= (*inptr
- '0') << 4;
2337 if (!isxdigit(*inptr
& 255))
2340 if (isalpha(*inptr
))
2341 *outptr
|= tolower(*inptr
) - 'a' + 10;
2343 *outptr
|= *inptr
- '0';
2349 while (*inptr
!= '>' && *inptr
!= '\0')
2351 while (*inptr
== '>')
2355 *outptr
++ = *inptr
++;
2359 return ((int)(outptr
- string
));
2364 * 'ppd_free_group()' - Free a single UI group.
2368 ppd_free_group(ppd_group_t
*group
) /* I - Group to free */
2370 int i
; /* Looping var */
2371 ppd_option_t
*option
; /* Current option */
2372 ppd_group_t
*subgroup
; /* Current sub-group */
2375 if (group
->num_options
> 0)
2377 for (i
= group
->num_options
, option
= group
->options
;
2380 ppd_free_option(option
);
2382 ppd_free(group
->options
);
2385 if (group
->num_subgroups
> 0)
2387 for (i
= group
->num_subgroups
, subgroup
= group
->subgroups
;
2390 ppd_free_group(subgroup
);
2392 ppd_free(group
->subgroups
);
2398 * 'ppd_free_option()' - Free a single option.
2402 ppd_free_option(ppd_option_t
*option
) /* I - Option to free */
2404 int i
; /* Looping var */
2405 ppd_choice_t
*choice
; /* Current choice */
2408 if (option
->num_choices
> 0)
2410 for (i
= option
->num_choices
, choice
= option
->choices
;
2414 ppd_free(choice
->code
);
2417 ppd_free(option
->choices
);
2423 * 'ppd_get_coption()' - Get a custom option record.
2426 static ppd_coption_t
* /* O - Custom option... */
2427 ppd_get_coption(ppd_file_t
*ppd
, /* I - PPD file */
2428 const char *name
) /* I - Name of option */
2430 ppd_coption_t
*copt
; /* New custom option */
2434 * See if the option already exists...
2437 if ((copt
= ppdFindCustomOption(ppd
, name
)) != NULL
)
2441 * Not found, so create the custom option record...
2444 if ((copt
= calloc(1, sizeof(ppd_coption_t
))) == NULL
)
2447 strlcpy(copt
->keyword
, name
, sizeof(copt
->keyword
));
2449 copt
->params
= cupsArrayNew((cups_array_func_t
)ppd_compare_cparams
, NULL
);
2451 cupsArrayAdd(ppd
->coptions
, copt
);
2454 * Return the new record...
2462 * 'ppd_get_cparam()' - Get a custom parameter record.
2465 static ppd_cparam_t
* /* O - Extended option... */
2466 ppd_get_cparam(ppd_coption_t
*opt
, /* I - PPD file */
2467 const char *param
, /* I - Name of parameter */
2468 const char *text
) /* I - Human-readable text */
2470 ppd_cparam_t
*cparam
; /* New custom parameter */
2474 * See if the parameter already exists...
2477 if ((cparam
= ppdFindCustomParam(opt
, param
)) != NULL
)
2481 * Not found, so create the custom parameter record...
2484 if ((cparam
= calloc(1, sizeof(ppd_cparam_t
))) == NULL
)
2487 strlcpy(cparam
->name
, param
, sizeof(cparam
->name
));
2488 strlcpy(cparam
->text
, text
[0] ? text
: param
, sizeof(cparam
->text
));
2491 * Add this record to the array...
2494 cupsArrayAdd(opt
->params
, cparam
);
2497 * Return the new record...
2505 * 'ppd_get_group()' - Find or create the named group as needed.
2508 static ppd_group_t
* /* O - Named group */
2509 ppd_get_group(ppd_file_t
*ppd
, /* I - PPD file */
2510 const char *name
, /* I - Name of group */
2511 const char *text
, /* I - Text for group */
2512 _cups_globals_t
*cg
, /* I - Global data */
2513 cups_encoding_t encoding
) /* I - Encoding of text */
2515 int i
; /* Looping var */
2516 ppd_group_t
*group
; /* Group */
2519 DEBUG_printf(("ppd_get_group(ppd=%p, name=\"%s\", text=\"%s\", cg=%p)\n",
2520 ppd
, name
, text
, cg
));
2522 for (i
= ppd
->num_groups
, group
= ppd
->groups
; i
> 0; i
--, group
++)
2523 if (!strcmp(group
->name
, name
))
2528 DEBUG_printf(("Adding group %s...\n", name
));
2530 if (cg
->ppd_conform
== PPD_CONFORM_STRICT
&& strlen(text
) >= sizeof(group
->text
))
2532 cg
->ppd_status
= PPD_ILLEGAL_TRANSLATION
;
2537 if (ppd
->num_groups
== 0)
2538 group
= malloc(sizeof(ppd_group_t
));
2540 group
= realloc(ppd
->groups
,
2541 (ppd
->num_groups
+ 1) * sizeof(ppd_group_t
));
2545 cg
->ppd_status
= PPD_ALLOC_ERROR
;
2550 ppd
->groups
= group
;
2551 group
+= ppd
->num_groups
;
2554 memset(group
, 0, sizeof(ppd_group_t
));
2555 strlcpy(group
->name
, name
, sizeof(group
->name
));
2557 cupsCharsetToUTF8((cups_utf8_t
*)group
->text
, text
,
2558 sizeof(group
->text
), encoding
);
2566 * 'ppd_get_option()' - Find or create the named option as needed.
2569 static ppd_option_t
* /* O - Named option */
2570 ppd_get_option(ppd_group_t
*group
, /* I - Group */
2571 const char *name
) /* I - Name of option */
2573 int i
; /* Looping var */
2574 ppd_option_t
*option
; /* Option */
2577 DEBUG_printf(("ppd_get_option(group=%p(\"%s\"), name=\"%s\")\n",
2578 group
, group
->name
, name
));
2580 for (i
= group
->num_options
, option
= group
->options
; i
> 0; i
--, option
++)
2581 if (!strcmp(option
->keyword
, name
))
2586 if (group
->num_options
== 0)
2587 option
= malloc(sizeof(ppd_option_t
));
2589 option
= realloc(group
->options
,
2590 (group
->num_options
+ 1) * sizeof(ppd_option_t
));
2595 group
->options
= option
;
2596 option
+= group
->num_options
;
2597 group
->num_options
++;
2599 memset(option
, 0, sizeof(ppd_option_t
));
2600 strlcpy(option
->keyword
, name
, sizeof(option
->keyword
));
2608 * 'ppd_hash_option()' - Generate a hash of the option name...
2611 static int /* O - Hash index */
2612 ppd_hash_option(ppd_option_t
*option
) /* I - Option */
2614 int hash
= 0; /* Hash index */
2615 const char *k
; /* Pointer into keyword */
2618 for (hash
= option
->keyword
[0], k
= option
->keyword
+ 1; *k
;)
2619 hash
= 33 * hash
+ *k
++;
2621 return (hash
& 511);
2626 * 'ppd_read()' - Read a line from a PPD file, skipping comment lines as
2630 static int /* O - Bitmask of fields read */
2631 ppd_read(cups_file_t
*fp
, /* I - File to read from */
2632 char *keyword
, /* O - Keyword from line */
2633 char *option
, /* O - Option from line */
2634 char *text
, /* O - Human-readable text from line */
2635 char **string
, /* O - Code/string data */
2636 int ignoreblank
, /* I - Ignore blank lines? */
2637 _cups_globals_t
*cg
) /* I - Global data */
2639 int ch
, /* Character from file */
2640 col
, /* Column in line */
2641 colon
, /* Colon seen? */
2642 endquote
, /* Waiting for an end quote */
2643 mask
, /* Mask to be returned */
2644 startline
, /* Start line */
2645 textlen
; /* Length of text */
2646 char *keyptr
, /* Keyword pointer */
2647 *optptr
, /* Option pointer */
2648 *textptr
, /* Text pointer */
2649 *strptr
, /* Pointer into string */
2650 *lineptr
, /* Current position in line buffer */
2651 *line
; /* Line buffer */
2652 int linesize
; /* Current size of line buffer */
2655 * Range check everything...
2658 if (!fp
|| !keyword
|| !option
|| !text
|| !string
)
2662 * Now loop until we have a valid line...
2667 startline
= cg
->ppd_line
+ 1;
2669 line
= malloc(linesize
);
2684 while ((ch
= cupsFileGetChar(fp
)) != EOF
)
2686 if (lineptr
>= (line
+ linesize
- 1))
2689 * Expand the line buffer...
2692 char *temp
; /* Temporary line pointer */
2696 if (linesize
> 262144)
2699 * Don't allow lines longer than 256k!
2702 cg
->ppd_line
= startline
;
2703 cg
->ppd_status
= PPD_LINE_TOO_LONG
;
2710 temp
= realloc(line
, linesize
);
2713 cg
->ppd_line
= startline
;
2714 cg
->ppd_status
= PPD_LINE_TOO_LONG
;
2721 lineptr
= temp
+ (lineptr
- line
);
2725 if (ch
== '\r' || ch
== '\n')
2728 * Line feed or carriage return...
2737 * Check for a trailing line feed...
2740 if ((ch
= cupsFilePeekChar(fp
)) == EOF
)
2747 cupsFileGetChar(fp
);
2750 if (lineptr
== line
&& ignoreblank
)
2751 continue; /* Skip blank lines */
2755 if (!endquote
) /* Continue for multi-line text */
2760 else if (ch
< ' ' && ch
!= '\t' && cg
->ppd_conform
== PPD_CONFORM_STRICT
)
2763 * Other control characters...
2766 cg
->ppd_line
= startline
;
2767 cg
->ppd_status
= PPD_ILLEGAL_CHARACTER
;
2773 else if (ch
!= 0x1a)
2776 * Any other character...
2782 if (col
> (PPD_MAX_LINE
- 1))
2785 * Line is too long...
2788 cg
->ppd_line
= startline
;
2789 cg
->ppd_status
= PPD_LINE_TOO_LONG
;
2796 if (ch
== ':' && strncmp(line
, "*%", 2) != 0)
2799 if (ch
== '\"' && colon
)
2800 endquote
= !endquote
;
2807 * Didn't finish this quoted string...
2810 while ((ch
= cupsFileGetChar(fp
)) != EOF
)
2813 else if (ch
== '\r' || ch
== '\n')
2821 * Check for a trailing line feed...
2824 if ((ch
= cupsFilePeekChar(fp
)) == EOF
)
2827 cupsFileGetChar(fp
);
2832 else if (ch
< ' ' && ch
!= '\t' && cg
->ppd_conform
== PPD_CONFORM_STRICT
)
2835 * Other control characters...
2838 cg
->ppd_line
= startline
;
2839 cg
->ppd_status
= PPD_ILLEGAL_CHARACTER
;
2845 else if (ch
!= 0x1a)
2849 if (col
> (PPD_MAX_LINE
- 1))
2852 * Line is too long...
2855 cg
->ppd_line
= startline
;
2856 cg
->ppd_status
= PPD_LINE_TOO_LONG
;
2868 * Didn't finish this line...
2871 while ((ch
= cupsFileGetChar(fp
)) != EOF
)
2872 if (ch
== '\r' || ch
== '\n')
2875 * Line feed or carriage return...
2884 * Check for a trailing line feed...
2887 if ((ch
= cupsFilePeekChar(fp
)) == EOF
)
2890 cupsFileGetChar(fp
);
2895 else if (ch
< ' ' && ch
!= '\t' && cg
->ppd_conform
== PPD_CONFORM_STRICT
)
2898 * Other control characters...
2901 cg
->ppd_line
= startline
;
2902 cg
->ppd_status
= PPD_ILLEGAL_CHARACTER
;
2908 else if (ch
!= 0x1a)
2912 if (col
> (PPD_MAX_LINE
- 1))
2915 * Line is too long...
2918 cg
->ppd_line
= startline
;
2919 cg
->ppd_status
= PPD_LINE_TOO_LONG
;
2928 if (lineptr
> line
&& lineptr
[-1] == '\n')
2933 DEBUG_printf(("LINE = \"%s\"\n", line
));
2936 * The dynamically created PPDs for older style Mac OS X
2937 * drivers include a large blob of data inserted as comments
2938 * at the end of the file. As an optimization we can stop
2939 * reading the PPD when we get to the start of this data.
2942 if (!strcmp(line
, "*%APLWORKSET START"))
2948 if (ch
== EOF
&& lineptr
== line
)
2966 if ((!line
[0] || /* Blank line */
2967 !strncmp(line
, "*%", 2) || /* Comment line */
2968 !strcmp(line
, "*End")) && /* End of multi-line string */
2969 ignoreblank
) /* Ignore these? */
2971 startline
= cg
->ppd_line
+ 1;
2975 if (!strcmp(line
, "*")) /* (Bad) comment line */
2977 if (cg
->ppd_conform
== PPD_CONFORM_RELAXED
)
2979 startline
= cg
->ppd_line
+ 1;
2984 cg
->ppd_line
= startline
;
2985 cg
->ppd_status
= PPD_ILLEGAL_MAIN_KEYWORD
;
2992 if (line
[0] != '*') /* All lines start with an asterisk */
2995 * Allow lines consisting of just whitespace...
2998 for (lineptr
= line
; *lineptr
; lineptr
++)
2999 if (!isspace(*lineptr
& 255))
3004 cg
->ppd_status
= PPD_MISSING_ASTERISK
;
3008 else if (ignoreblank
)
3023 while (*lineptr
!= '\0' && *lineptr
!= ':' && !isspace(*lineptr
& 255))
3025 if (*lineptr
<= ' ' || *lineptr
> 126 || *lineptr
== '/' ||
3026 (keyptr
- keyword
) >= (PPD_MAX_NAME
- 1))
3028 cg
->ppd_status
= PPD_ILLEGAL_MAIN_KEYWORD
;
3033 *keyptr
++ = *lineptr
++;
3038 if (!strcmp(keyword
, "End"))
3041 mask
|= PPD_KEYWORD
;
3043 /* DEBUG_printf(("keyword = \"%s\", lineptr = \"%s\"\n", keyword, lineptr));*/
3045 if (isspace(*lineptr
& 255))
3048 * Get an option name...
3051 while (isspace(*lineptr
& 255))
3056 while (*lineptr
!= '\0' && !isspace(*lineptr
& 255) && *lineptr
!= ':' &&
3059 if (*lineptr
<= ' ' || *lineptr
> 126 ||
3060 (optptr
- option
) >= (PPD_MAX_NAME
- 1))
3062 cg
->ppd_status
= PPD_ILLEGAL_OPTION_KEYWORD
;
3067 *optptr
++ = *lineptr
++;
3072 if (isspace(*lineptr
& 255) && cg
->ppd_conform
== PPD_CONFORM_STRICT
)
3074 cg
->ppd_status
= PPD_ILLEGAL_WHITESPACE
;
3079 while (isspace(*lineptr
& 255))
3084 /* DEBUG_printf(("option = \"%s\", lineptr = \"%s\"\n", option, lineptr));*/
3086 if (*lineptr
== '/')
3089 * Get human-readable text...
3096 while (*lineptr
!= '\0' && *lineptr
!= '\n' && *lineptr
!= ':')
3098 if (((unsigned char)*lineptr
< ' ' && *lineptr
!= '\t') ||
3099 (textptr
- text
) >= (PPD_MAX_LINE
- 1))
3101 cg
->ppd_status
= PPD_ILLEGAL_TRANSLATION
;
3106 *textptr
++ = *lineptr
++;
3110 textlen
= ppd_decode(text
);
3112 if (textlen
> PPD_MAX_TEXT
&& cg
->ppd_conform
== PPD_CONFORM_STRICT
)
3114 cg
->ppd_status
= PPD_ILLEGAL_TRANSLATION
;
3122 /* DEBUG_printf(("text = \"%s\", lineptr = \"%s\"\n", text, lineptr));*/
3125 if (isspace(*lineptr
& 255) && cg
->ppd_conform
== PPD_CONFORM_STRICT
)
3127 cg
->ppd_status
= PPD_ILLEGAL_WHITESPACE
;
3132 while (isspace(*lineptr
& 255))
3135 if (*lineptr
== ':')
3138 * Get string after triming leading and trailing whitespace...
3142 while (isspace(*lineptr
& 255))
3145 strptr
= lineptr
+ strlen(lineptr
) - 1;
3146 while (strptr
>= lineptr
&& isspace(*strptr
& 255))
3149 if (*strptr
== '\"')
3152 * Quoted string by itself...
3155 *string
= malloc(strlen(lineptr
) + 1);
3159 for (; *lineptr
!= '\0'; lineptr
++)
3160 if (*lineptr
!= '\"')
3161 *strptr
++ = *lineptr
;
3166 *string
= strdup(lineptr
);
3168 /* DEBUG_printf(("string = \"%s\", lineptr = \"%s\"\n", *string, lineptr));*/
3182 * End of "$Id: ppd.c 6479 2007-04-27 11:44:10Z mike $".