2 * Option marking routines for CUPS.
4 * Copyright 2007-2017 by Apple Inc.
5 * Copyright 1997-2007 by Easy Software Products, all rights reserved.
7 * Licensed under Apache License v2.0. See the file "LICENSE" for more
10 * PostScript is a trademark of Adobe Systems, Inc.
14 * Include necessary headers...
17 #include "cups-private.h"
18 #include "ppd-private.h"
26 static void ppd_debug_marked(ppd_file_t
*ppd
, const char *title
);
28 # define ppd_debug_marked(ppd,title)
30 static void ppd_defaults(ppd_file_t
*ppd
, ppd_group_t
*g
);
31 static void ppd_mark_choices(ppd_file_t
*ppd
, const char *s
);
32 static void ppd_mark_option(ppd_file_t
*ppd
, const char *option
,
37 * 'cupsMarkOptions()' - Mark command-line options in a PPD file.
39 * This function maps the IPP "finishings", "media", "mirror",
40 * "multiple-document-handling", "output-bin", "print-color-mode",
41 * "print-quality", "printer-resolution", and "sides" attributes to their
42 * corresponding PPD options and choices.
45 int /* O - 1 if conflicts exist, 0 otherwise */
47 ppd_file_t
*ppd
, /* I - PPD file */
48 int num_options
, /* I - Number of options */
49 cups_option_t
*options
) /* I - Options */
51 int i
, j
; /* Looping vars */
52 char *ptr
, /* Pointer into string */
53 s
[255]; /* Temporary string */
54 const char *val
, /* Pointer into value */
55 *media
, /* media option */
56 *output_bin
, /* output-bin option */
57 *page_size
, /* PageSize option */
58 *ppd_keyword
, /* PPD keyword */
59 *print_color_mode
, /* print-color-mode option */
60 *print_quality
, /* print-quality option */
61 *sides
; /* sides option */
62 cups_option_t
*optptr
; /* Current option */
63 ppd_attr_t
*attr
; /* PPD attribute */
64 _ppd_cache_t
*cache
; /* PPD cache and mapping data */
71 if (!ppd
|| num_options
<= 0 || !options
)
74 ppd_debug_marked(ppd
, "Before...");
77 * Do special handling for finishings, media, output-bin, output-mode,
78 * print-color-mode, print-quality, and PageSize...
81 media
= cupsGetOption("media", num_options
, options
);
82 output_bin
= cupsGetOption("output-bin", num_options
, options
);
83 page_size
= cupsGetOption("PageSize", num_options
, options
);
84 print_quality
= cupsGetOption("print-quality", num_options
, options
);
85 sides
= cupsGetOption("sides", num_options
, options
);
87 if ((print_color_mode
= cupsGetOption("print-color-mode", num_options
,
89 print_color_mode
= cupsGetOption("output-mode", num_options
, options
);
91 if ((media
|| output_bin
|| print_color_mode
|| print_quality
|| sides
) &&
95 * Load PPD cache and mapping data as needed...
98 ppd
->cache
= _ppdCacheCreateWithPPD(ppd
);
106 * Loop through the option string, separating it at commas and marking each
107 * individual option as long as the corresponding PPD option (PageSize,
108 * InputSlot, etc.) is not also set.
110 * For PageSize, we also check for an empty option value since some versions
111 * of macOS use it to specify auto-selection of the media based solely on
115 for (val
= media
; *val
;)
118 * Extract the sub-option from the string...
121 for (ptr
= s
; *val
&& *val
!= ',' && (size_t)(ptr
- s
) < (sizeof(s
) - 1);)
132 if (!page_size
|| !page_size
[0])
134 if (!_cups_strncasecmp(s
, "Custom.", 7) || ppdPageSize(ppd
, s
))
135 ppd_mark_option(ppd
, "PageSize", s
);
136 else if ((ppd_keyword
= _ppdCacheGetPageSize(cache
, NULL
, s
, NULL
)) != NULL
)
137 ppd_mark_option(ppd
, "PageSize", ppd_keyword
);
140 if (cache
&& cache
->source_option
&&
141 !cupsGetOption(cache
->source_option
, num_options
, options
) &&
142 (ppd_keyword
= _ppdCacheGetInputSlot(cache
, NULL
, s
)) != NULL
)
143 ppd_mark_option(ppd
, cache
->source_option
, ppd_keyword
);
145 if (!cupsGetOption("MediaType", num_options
, options
) &&
146 (ppd_keyword
= _ppdCacheGetMediaType(cache
, NULL
, s
)) != NULL
)
147 ppd_mark_option(ppd
, "MediaType", ppd_keyword
);
153 if (!cupsGetOption("com.apple.print.DocumentTicket.PMSpoolFormat",
154 num_options
, options
) &&
155 !cupsGetOption("APPrinterPreset", num_options
, options
) &&
156 (print_color_mode
|| print_quality
))
159 * Map output-mode and print-quality to a preset...
162 _pwg_print_color_mode_t pwg_pcm
;/* print-color-mode index */
163 _pwg_print_quality_t pwg_pq
; /* print-quality index */
164 cups_option_t
*preset
;/* Current preset option */
166 if (print_color_mode
&& !strcmp(print_color_mode
, "monochrome"))
167 pwg_pcm
= _PWG_PRINT_COLOR_MODE_MONOCHROME
;
169 pwg_pcm
= _PWG_PRINT_COLOR_MODE_COLOR
;
173 pwg_pq
= (_pwg_print_quality_t
)(atoi(print_quality
) - IPP_QUALITY_DRAFT
);
174 if (pwg_pq
< _PWG_PRINT_QUALITY_DRAFT
)
175 pwg_pq
= _PWG_PRINT_QUALITY_DRAFT
;
176 else if (pwg_pq
> _PWG_PRINT_QUALITY_HIGH
)
177 pwg_pq
= _PWG_PRINT_QUALITY_HIGH
;
180 pwg_pq
= _PWG_PRINT_QUALITY_NORMAL
;
182 if (cache
->num_presets
[pwg_pcm
][pwg_pq
] == 0)
185 * Try to find a preset that works so that we maximize the chances of us
186 * getting a good print using IPP attributes.
189 if (cache
->num_presets
[pwg_pcm
][_PWG_PRINT_QUALITY_NORMAL
] > 0)
190 pwg_pq
= _PWG_PRINT_QUALITY_NORMAL
;
191 else if (cache
->num_presets
[_PWG_PRINT_COLOR_MODE_COLOR
][pwg_pq
] > 0)
192 pwg_pcm
= _PWG_PRINT_COLOR_MODE_COLOR
;
195 pwg_pq
= _PWG_PRINT_QUALITY_NORMAL
;
196 pwg_pcm
= _PWG_PRINT_COLOR_MODE_COLOR
;
200 if (cache
->num_presets
[pwg_pcm
][pwg_pq
] > 0)
203 * Copy the preset options as long as the corresponding names are not
204 * already defined in the IPP request...
207 for (i
= cache
->num_presets
[pwg_pcm
][pwg_pq
],
208 preset
= cache
->presets
[pwg_pcm
][pwg_pq
];
212 if (!cupsGetOption(preset
->name
, num_options
, options
))
213 ppd_mark_option(ppd
, preset
->name
, preset
->value
);
218 if (output_bin
&& !cupsGetOption("OutputBin", num_options
, options
) &&
219 (ppd_keyword
= _ppdCacheGetOutputBin(cache
, output_bin
)) != NULL
)
222 * Map output-bin to OutputBin...
225 ppd_mark_option(ppd
, "OutputBin", ppd_keyword
);
228 if (sides
&& cache
->sides_option
&&
229 !cupsGetOption(cache
->sides_option
, num_options
, options
))
232 * Map sides to duplex option...
235 if (!strcmp(sides
, "one-sided") && cache
->sides_1sided
)
236 ppd_mark_option(ppd
, cache
->sides_option
, cache
->sides_1sided
);
237 else if (!strcmp(sides
, "two-sided-long-edge") &&
238 cache
->sides_2sided_long
)
239 ppd_mark_option(ppd
, cache
->sides_option
, cache
->sides_2sided_long
);
240 else if (!strcmp(sides
, "two-sided-short-edge") &&
241 cache
->sides_2sided_short
)
242 ppd_mark_option(ppd
, cache
->sides_option
, cache
->sides_2sided_short
);
247 * Mark other options...
250 for (i
= num_options
, optptr
= options
; i
> 0; i
--, optptr
++)
252 if (!_cups_strcasecmp(optptr
->name
, "media") ||
253 !_cups_strcasecmp(optptr
->name
, "output-bin") ||
254 !_cups_strcasecmp(optptr
->name
, "output-mode") ||
255 !_cups_strcasecmp(optptr
->name
, "print-quality") ||
256 !_cups_strcasecmp(optptr
->name
, "sides"))
258 else if (!_cups_strcasecmp(optptr
->name
, "resolution") ||
259 !_cups_strcasecmp(optptr
->name
, "printer-resolution"))
261 ppd_mark_option(ppd
, "Resolution", optptr
->value
);
262 ppd_mark_option(ppd
, "SetResolution", optptr
->value
);
263 /* Calcomp, Linotype, QMS, Summagraphics, Tektronix, Varityper */
264 ppd_mark_option(ppd
, "JCLResolution", optptr
->value
);
266 ppd_mark_option(ppd
, "CNRes_PGP", optptr
->value
);
269 else if (!_cups_strcasecmp(optptr
->name
, "multiple-document-handling"))
271 if (!cupsGetOption("Collate", num_options
, options
) &&
272 ppdFindOption(ppd
, "Collate"))
274 if (_cups_strcasecmp(optptr
->value
, "separate-documents-uncollated-copies"))
275 ppd_mark_option(ppd
, "Collate", "True");
277 ppd_mark_option(ppd
, "Collate", "False");
280 else if (!_cups_strcasecmp(optptr
->name
, "finishings"))
283 * Lookup cupsIPPFinishings attributes for each value...
286 for (ptr
= optptr
->value
; *ptr
;)
289 * Get the next finishings number...
292 if (!isdigit(*ptr
& 255))
295 if ((j
= (int)strtol(ptr
, &ptr
, 10)) < 3)
299 * Skip separator as needed...
306 * Look it up in the PPD file...
311 if ((attr
= ppdFindAttr(ppd
, "cupsIPPFinishings", s
)) == NULL
)
315 * Apply "*Option Choice" settings from the attribute value...
318 ppd_mark_choices(ppd
, attr
->value
);
321 else if (!_cups_strcasecmp(optptr
->name
, "APPrinterPreset"))
324 * Lookup APPrinterPreset value...
327 if ((attr
= ppdFindAttr(ppd
, "APPrinterPreset", optptr
->value
)) != NULL
)
330 * Apply "*Option Choice" settings from the attribute value...
333 ppd_mark_choices(ppd
, attr
->value
);
336 else if (!_cups_strcasecmp(optptr
->name
, "mirror"))
337 ppd_mark_option(ppd
, "MirrorPrint", optptr
->value
);
339 ppd_mark_option(ppd
, optptr
->name
, optptr
->value
);
344 int pq
= atoi(print_quality
); /* print-quaity value */
346 if (pq
== IPP_QUALITY_DRAFT
)
347 ppd_mark_option(ppd
, "cupsPrintQuality", "Draft");
348 else if (pq
== IPP_QUALITY_HIGH
)
349 ppd_mark_option(ppd
, "cupsPrintQuality", "High");
351 ppd_mark_option(ppd
, "cupsPrintQuality", "Normal");
354 ppd_debug_marked(ppd
, "After...");
356 return (ppdConflicts(ppd
) > 0);
361 * 'ppdFindChoice()' - Return a pointer to an option choice.
364 ppd_choice_t
* /* O - Choice pointer or @code NULL@ */
365 ppdFindChoice(ppd_option_t
*o
, /* I - Pointer to option */
366 const char *choice
) /* I - Name of choice */
368 int i
; /* Looping var */
369 ppd_choice_t
*c
; /* Current choice */
375 if (choice
[0] == '{' || !_cups_strncasecmp(choice
, "Custom.", 7))
378 for (i
= o
->num_choices
, c
= o
->choices
; i
> 0; i
--, c
++)
379 if (!_cups_strcasecmp(c
->choice
, choice
))
387 * 'ppdFindMarkedChoice()' - Return the marked choice for the specified option.
390 ppd_choice_t
* /* O - Pointer to choice or @code NULL@ */
391 ppdFindMarkedChoice(ppd_file_t
*ppd
, /* I - PPD file */
392 const char *option
) /* I - Keyword/option name */
394 ppd_choice_t key
, /* Search key for choice */
395 *marked
; /* Marked choice */
398 DEBUG_printf(("2ppdFindMarkedChoice(ppd=%p, option=\"%s\")", ppd
, option
));
400 if ((key
.option
= ppdFindOption(ppd
, option
)) == NULL
)
402 DEBUG_puts("3ppdFindMarkedChoice: Option not found, returning NULL");
406 marked
= (ppd_choice_t
*)cupsArrayFind(ppd
->marked
, &key
);
408 DEBUG_printf(("3ppdFindMarkedChoice: Returning %p(%s)...", marked
,
409 marked
? marked
->choice
: "NULL"));
416 * 'ppdFindOption()' - Return a pointer to the specified option.
419 ppd_option_t
* /* O - Pointer to option or @code NULL@ */
420 ppdFindOption(ppd_file_t
*ppd
, /* I - PPD file data */
421 const char *option
) /* I - Option/Keyword name */
424 * Range check input...
433 * Search in the array...
436 ppd_option_t key
; /* Option search key */
439 strlcpy(key
.keyword
, option
, sizeof(key
.keyword
));
441 return ((ppd_option_t
*)cupsArrayFind(ppd
->options
, &key
));
446 * Search in each group...
449 int i
, j
; /* Looping vars */
450 ppd_group_t
*group
; /* Current group */
451 ppd_option_t
*optptr
; /* Current option */
454 for (i
= ppd
->num_groups
, group
= ppd
->groups
; i
> 0; i
--, group
++)
455 for (j
= group
->num_options
, optptr
= group
->options
;
458 if (!_cups_strcasecmp(optptr
->keyword
, option
))
467 * 'ppdIsMarked()' - Check to see if an option is marked.
470 int /* O - Non-zero if option is marked */
471 ppdIsMarked(ppd_file_t
*ppd
, /* I - PPD file data */
472 const char *option
, /* I - Option/Keyword name */
473 const char *choice
) /* I - Choice name */
475 ppd_choice_t key
, /* Search key */
476 *c
; /* Choice pointer */
482 if ((key
.option
= ppdFindOption(ppd
, option
)) == NULL
)
485 if ((c
= (ppd_choice_t
*)cupsArrayFind(ppd
->marked
, &key
)) == NULL
)
488 return (!strcmp(c
->choice
, choice
));
493 * 'ppdMarkDefaults()' - Mark all default options in the PPD file.
497 ppdMarkDefaults(ppd_file_t
*ppd
) /* I - PPD file record */
499 int i
; /* Looping variables */
500 ppd_group_t
*g
; /* Current group */
501 ppd_choice_t
*c
; /* Current choice */
508 * Clean out the marked array...
511 for (c
= (ppd_choice_t
*)cupsArrayFirst(ppd
->marked
);
513 c
= (ppd_choice_t
*)cupsArrayNext(ppd
->marked
))
515 cupsArrayRemove(ppd
->marked
, c
);
520 * Then repopulate it with the defaults...
523 for (i
= ppd
->num_groups
, g
= ppd
->groups
; i
> 0; i
--, g
++)
524 ppd_defaults(ppd
, g
);
527 * Finally, tag any conflicts (API compatibility) once at the end.
535 * 'ppdMarkOption()' - Mark an option in a PPD file and return the number of
539 int /* O - Number of conflicts */
540 ppdMarkOption(ppd_file_t
*ppd
, /* I - PPD file record */
541 const char *option
, /* I - Keyword */
542 const char *choice
) /* I - Option name */
544 DEBUG_printf(("ppdMarkOption(ppd=%p, option=\"%s\", choice=\"%s\")",
545 ppd
, option
, choice
));
548 * Range check input...
551 if (!ppd
|| !option
|| !choice
)
558 ppd_mark_option(ppd
, option
, choice
);
561 * Return the number of conflicts...
564 return (ppdConflicts(ppd
));
569 * 'ppdFirstOption()' - Return the first option in the PPD file.
571 * Options are returned from all groups in ascending alphanumeric order.
573 * @since CUPS 1.2/macOS 10.5@
576 ppd_option_t
* /* O - First option or @code NULL@ */
577 ppdFirstOption(ppd_file_t
*ppd
) /* I - PPD file */
582 return ((ppd_option_t
*)cupsArrayFirst(ppd
->options
));
587 * 'ppdNextOption()' - Return the next option in the PPD file.
589 * Options are returned from all groups in ascending alphanumeric order.
591 * @since CUPS 1.2/macOS 10.5@
594 ppd_option_t
* /* O - Next option or @code NULL@ */
595 ppdNextOption(ppd_file_t
*ppd
) /* I - PPD file */
600 return ((ppd_option_t
*)cupsArrayNext(ppd
->options
));
605 * '_ppdParseOptions()' - Parse options from a PPD file.
607 * This function looks for strings of the form:
609 * *option choice ... *optionN choiceN
610 * property value ... propertyN valueN
612 * It stops when it finds a string that doesn't match this format.
615 int /* O - Number of options */
617 const char *s
, /* I - String to parse */
618 int num_options
, /* I - Number of options */
619 cups_option_t
**options
, /* IO - Options */
620 _ppd_parse_t which
) /* I - What to parse */
622 char option
[PPD_MAX_NAME
* 2 + 1], /* Current option/property */
623 choice
[PPD_MAX_NAME
], /* Current choice/value */
624 *ptr
; /* Pointer into option or choice */
628 return (num_options
);
631 * Read all of the "*Option Choice" and "property value" pairs from the
632 * string, add them to an options array as we go...
638 * Skip leading whitespace...
641 while (_cups_isspace(*s
))
645 * Get the option/property name...
649 while (*s
&& !_cups_isspace(*s
) && ptr
< (option
+ sizeof(option
) - 1))
652 if (ptr
== s
|| !_cups_isspace(*s
))
661 while (_cups_isspace(*s
))
668 while (*s
&& !_cups_isspace(*s
) && ptr
< (choice
+ sizeof(choice
) - 1))
671 if (*s
&& !_cups_isspace(*s
))
677 * Add it to the options array...
680 if (option
[0] == '*' && which
!= _PPD_PARSE_PROPERTIES
)
681 num_options
= cupsAddOption(option
+ 1, choice
, num_options
, options
);
682 else if (option
[0] != '*' && which
!= _PPD_PARSE_OPTIONS
)
683 num_options
= cupsAddOption(option
, choice
, num_options
, options
);
686 return (num_options
);
692 * 'ppd_debug_marked()' - Output the marked array to stdout...
696 ppd_debug_marked(ppd_file_t
*ppd
, /* I - PPD file data */
697 const char *title
) /* I - Title for list */
699 ppd_choice_t
*c
; /* Current choice */
702 DEBUG_printf(("2cupsMarkOptions: %s", title
));
704 for (c
= (ppd_choice_t
*)cupsArrayFirst(ppd
->marked
);
706 c
= (ppd_choice_t
*)cupsArrayNext(ppd
->marked
))
707 DEBUG_printf(("2cupsMarkOptions: %s=%s", c
->option
->keyword
, c
->choice
));
713 * 'ppd_defaults()' - Set the defaults for this group and all sub-groups.
717 ppd_defaults(ppd_file_t
*ppd
, /* I - PPD file */
718 ppd_group_t
*g
) /* I - Group to default */
720 int i
; /* Looping var */
721 ppd_option_t
*o
; /* Current option */
722 ppd_group_t
*sg
; /* Current sub-group */
725 for (i
= g
->num_options
, o
= g
->options
; i
> 0; i
--, o
++)
726 if (_cups_strcasecmp(o
->keyword
, "PageRegion") != 0)
727 ppd_mark_option(ppd
, o
->keyword
, o
->defchoice
);
729 for (i
= g
->num_subgroups
, sg
= g
->subgroups
; i
> 0; i
--, sg
++)
730 ppd_defaults(ppd
, sg
);
735 * 'ppd_mark_choices()' - Mark one or more option choices from a string.
739 ppd_mark_choices(ppd_file_t
*ppd
, /* I - PPD file */
740 const char *s
) /* I - "*Option Choice ..." string */
742 int i
, /* Looping var */
743 num_options
; /* Number of options */
744 cups_option_t
*options
, /* Options */
745 *option
; /* Current option */
752 num_options
= _ppdParseOptions(s
, 0, &options
, 0);
754 for (i
= num_options
, option
= options
; i
> 0; i
--, option
++)
755 ppd_mark_option(ppd
, option
->name
, option
->value
);
757 cupsFreeOptions(num_options
, options
);
762 * 'ppd_mark_option()' - Quick mark an option without checking for conflicts.
766 ppd_mark_option(ppd_file_t
*ppd
, /* I - PPD file */
767 const char *option
, /* I - Option name */
768 const char *choice
) /* I - Choice name */
770 int i
, j
; /* Looping vars */
771 ppd_option_t
*o
; /* Option pointer */
772 ppd_choice_t
*c
, /* Choice pointer */
773 *oldc
, /* Old choice pointer */
774 key
; /* Search key for choice */
775 struct lconv
*loc
; /* Locale data */
778 DEBUG_printf(("7ppd_mark_option(ppd=%p, option=\"%s\", choice=\"%s\")",
779 ppd
, option
, choice
));
782 * AP_D_InputSlot is the "default input slot" on macOS, and setting
783 * it clears the regular InputSlot choices...
786 if (!_cups_strcasecmp(option
, "AP_D_InputSlot"))
788 cupsArraySave(ppd
->options
);
790 if ((o
= ppdFindOption(ppd
, "InputSlot")) != NULL
)
793 if ((oldc
= (ppd_choice_t
*)cupsArrayFind(ppd
->marked
, &key
)) != NULL
)
796 cupsArrayRemove(ppd
->marked
, oldc
);
800 cupsArrayRestore(ppd
->options
);
804 * Check for custom options...
807 cupsArraySave(ppd
->options
);
809 o
= ppdFindOption(ppd
, option
);
811 cupsArrayRestore(ppd
->options
);
818 if (!_cups_strncasecmp(choice
, "Custom.", 7))
821 * Handle a custom option...
824 if ((c
= ppdFindChoice(o
, "Custom")) == NULL
)
827 if (!_cups_strcasecmp(option
, "PageSize"))
830 * Handle custom page sizes...
833 ppdPageSize(ppd
, choice
);
838 * Handle other custom options...
841 ppd_coption_t
*coption
; /* Custom option */
842 ppd_cparam_t
*cparam
; /* Custom parameter */
843 char *units
; /* Custom points units */
846 if ((coption
= ppdFindCustomOption(ppd
, option
)) != NULL
)
848 if ((cparam
= (ppd_cparam_t
*)cupsArrayFirst(coption
->params
)) == NULL
)
851 switch (cparam
->type
)
853 case PPD_CUSTOM_CURVE
:
854 case PPD_CUSTOM_INVCURVE
:
855 case PPD_CUSTOM_REAL
:
856 cparam
->current
.custom_real
= (float)_cupsStrScand(choice
+ 7,
860 case PPD_CUSTOM_POINTS
:
861 cparam
->current
.custom_points
= (float)_cupsStrScand(choice
+ 7,
867 if (!_cups_strcasecmp(units
, "cm"))
868 cparam
->current
.custom_points
*= 72.0f
/ 2.54f
;
869 else if (!_cups_strcasecmp(units
, "mm"))
870 cparam
->current
.custom_points
*= 72.0f
/ 25.4f
;
871 else if (!_cups_strcasecmp(units
, "m"))
872 cparam
->current
.custom_points
*= 72.0f
/ 0.0254f
;
873 else if (!_cups_strcasecmp(units
, "in"))
874 cparam
->current
.custom_points
*= 72.0f
;
875 else if (!_cups_strcasecmp(units
, "ft"))
876 cparam
->current
.custom_points
*= 12.0f
* 72.0f
;
880 case PPD_CUSTOM_INT
:
881 cparam
->current
.custom_int
= atoi(choice
+ 7);
884 case PPD_CUSTOM_PASSCODE
:
885 case PPD_CUSTOM_PASSWORD
:
886 case PPD_CUSTOM_STRING
:
887 if (cparam
->current
.custom_string
)
888 _cupsStrFree(cparam
->current
.custom_string
);
890 cparam
->current
.custom_string
= _cupsStrAlloc(choice
+ 7);
897 * Make sure that we keep the option marked below...
902 else if (choice
[0] == '{')
905 * Handle multi-value custom options...
908 ppd_coption_t
*coption
; /* Custom option */
909 ppd_cparam_t
*cparam
; /* Custom parameter */
910 char *units
; /* Custom points units */
911 int num_vals
; /* Number of values */
912 cups_option_t
*vals
, /* Values */
916 if ((c
= ppdFindChoice(o
, "Custom")) == NULL
)
919 if ((coption
= ppdFindCustomOption(ppd
, option
)) != NULL
)
921 num_vals
= cupsParseOptions(choice
, 0, &vals
);
923 for (i
= 0, val
= vals
; i
< num_vals
; i
++, val
++)
925 if ((cparam
= ppdFindCustomParam(coption
, val
->name
)) == NULL
)
928 switch (cparam
->type
)
930 case PPD_CUSTOM_CURVE
:
931 case PPD_CUSTOM_INVCURVE
:
932 case PPD_CUSTOM_REAL
:
933 cparam
->current
.custom_real
= (float)_cupsStrScand(val
->value
,
937 case PPD_CUSTOM_POINTS
:
938 cparam
->current
.custom_points
= (float)_cupsStrScand(val
->value
,
944 if (!_cups_strcasecmp(units
, "cm"))
945 cparam
->current
.custom_points
*= 72.0f
/ 2.54f
;
946 else if (!_cups_strcasecmp(units
, "mm"))
947 cparam
->current
.custom_points
*= 72.0f
/ 25.4f
;
948 else if (!_cups_strcasecmp(units
, "m"))
949 cparam
->current
.custom_points
*= 72.0f
/ 0.0254f
;
950 else if (!_cups_strcasecmp(units
, "in"))
951 cparam
->current
.custom_points
*= 72.0f
;
952 else if (!_cups_strcasecmp(units
, "ft"))
953 cparam
->current
.custom_points
*= 12.0f
* 72.0f
;
957 case PPD_CUSTOM_INT
:
958 cparam
->current
.custom_int
= atoi(val
->value
);
961 case PPD_CUSTOM_PASSCODE
:
962 case PPD_CUSTOM_PASSWORD
:
963 case PPD_CUSTOM_STRING
:
964 if (cparam
->current
.custom_string
)
965 _cupsStrFree(cparam
->current
.custom_string
);
967 cparam
->current
.custom_string
= _cupsStrRetain(val
->value
);
972 cupsFreeOptions(num_vals
, vals
);
977 for (i
= o
->num_choices
, c
= o
->choices
; i
> 0; i
--, c
++)
978 if (!_cups_strcasecmp(c
->choice
, choice
))
986 * Option found; mark it and then handle unmarking any other options.
989 if (o
->ui
!= PPD_UI_PICKMANY
)
992 * Unmark all other choices...
995 if ((oldc
= (ppd_choice_t
*)cupsArrayFind(ppd
->marked
, c
)) != NULL
)
998 cupsArrayRemove(ppd
->marked
, oldc
);
1001 if (!_cups_strcasecmp(option
, "PageSize") || !_cups_strcasecmp(option
, "PageRegion"))
1004 * Mark current page size...
1007 for (j
= 0; j
< ppd
->num_sizes
; j
++)
1008 ppd
->sizes
[j
].marked
= !_cups_strcasecmp(ppd
->sizes
[j
].name
,
1012 * Unmark the current PageSize or PageRegion setting, as
1016 cupsArraySave(ppd
->options
);
1018 if (!_cups_strcasecmp(option
, "PageSize"))
1020 if ((o
= ppdFindOption(ppd
, "PageRegion")) != NULL
)
1023 if ((oldc
= (ppd_choice_t
*)cupsArrayFind(ppd
->marked
, &key
)) != NULL
)
1026 cupsArrayRemove(ppd
->marked
, oldc
);
1032 if ((o
= ppdFindOption(ppd
, "PageSize")) != NULL
)
1035 if ((oldc
= (ppd_choice_t
*)cupsArrayFind(ppd
->marked
, &key
)) != NULL
)
1038 cupsArrayRemove(ppd
->marked
, oldc
);
1043 cupsArrayRestore(ppd
->options
);
1045 else if (!_cups_strcasecmp(option
, "InputSlot"))
1048 * Unmark ManualFeed option...
1051 cupsArraySave(ppd
->options
);
1053 if ((o
= ppdFindOption(ppd
, "ManualFeed")) != NULL
)
1056 if ((oldc
= (ppd_choice_t
*)cupsArrayFind(ppd
->marked
, &key
)) != NULL
)
1059 cupsArrayRemove(ppd
->marked
, oldc
);
1063 cupsArrayRestore(ppd
->options
);
1065 else if (!_cups_strcasecmp(option
, "ManualFeed") &&
1066 !_cups_strcasecmp(choice
, "True"))
1069 * Unmark InputSlot option...
1072 cupsArraySave(ppd
->options
);
1074 if ((o
= ppdFindOption(ppd
, "InputSlot")) != NULL
)
1077 if ((oldc
= (ppd_choice_t
*)cupsArrayFind(ppd
->marked
, &key
)) != NULL
)
1080 cupsArrayRemove(ppd
->marked
, oldc
);
1084 cupsArrayRestore(ppd
->options
);
1090 cupsArrayAdd(ppd
->marked
, c
);