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 information.
9 * PostScript is a trademark of Adobe Systems, Inc.
13 * Include necessary headers...
16 #include "cups-private.h"
17 #include "ppd-private.h"
25 static void ppd_debug_marked(ppd_file_t
*ppd
, const char *title
);
27 # define ppd_debug_marked(ppd,title)
29 static void ppd_defaults(ppd_file_t
*ppd
, ppd_group_t
*g
);
30 static void ppd_mark_choices(ppd_file_t
*ppd
, const char *s
);
31 static void ppd_mark_option(ppd_file_t
*ppd
, const char *option
,
36 * 'cupsMarkOptions()' - Mark command-line options in a PPD file.
38 * This function maps the IPP "finishings", "media", "mirror",
39 * "multiple-document-handling", "output-bin", "print-color-mode",
40 * "print-quality", "printer-resolution", and "sides" attributes to their
41 * corresponding PPD options and choices.
44 int /* O - 1 if conflicts exist, 0 otherwise */
46 ppd_file_t
*ppd
, /* I - PPD file */
47 int num_options
, /* I - Number of options */
48 cups_option_t
*options
) /* I - Options */
50 int i
, j
; /* Looping vars */
51 char *ptr
, /* Pointer into string */
52 s
[255]; /* Temporary string */
53 const char *val
, /* Pointer into value */
54 *media
, /* media option */
55 *output_bin
, /* output-bin option */
56 *page_size
, /* PageSize option */
57 *ppd_keyword
, /* PPD keyword */
58 *print_color_mode
, /* print-color-mode option */
59 *print_quality
, /* print-quality option */
60 *sides
; /* sides option */
61 cups_option_t
*optptr
; /* Current option */
62 ppd_attr_t
*attr
; /* PPD attribute */
63 _ppd_cache_t
*cache
; /* PPD cache and mapping data */
70 if (!ppd
|| num_options
<= 0 || !options
)
73 ppd_debug_marked(ppd
, "Before...");
76 * Do special handling for finishings, media, output-bin, output-mode,
77 * print-color-mode, print-quality, and PageSize...
80 media
= cupsGetOption("media", num_options
, options
);
81 output_bin
= cupsGetOption("output-bin", num_options
, options
);
82 page_size
= cupsGetOption("PageSize", num_options
, options
);
83 print_quality
= cupsGetOption("print-quality", num_options
, options
);
84 sides
= cupsGetOption("sides", num_options
, options
);
86 if ((print_color_mode
= cupsGetOption("print-color-mode", num_options
,
88 print_color_mode
= cupsGetOption("output-mode", num_options
, options
);
90 if ((media
|| output_bin
|| print_color_mode
|| print_quality
|| sides
) &&
94 * Load PPD cache and mapping data as needed...
97 ppd
->cache
= _ppdCacheCreateWithPPD(ppd
);
105 * Loop through the option string, separating it at commas and marking each
106 * individual option as long as the corresponding PPD option (PageSize,
107 * InputSlot, etc.) is not also set.
109 * For PageSize, we also check for an empty option value since some versions
110 * of macOS use it to specify auto-selection of the media based solely on
114 for (val
= media
; *val
;)
117 * Extract the sub-option from the string...
120 for (ptr
= s
; *val
&& *val
!= ',' && (size_t)(ptr
- s
) < (sizeof(s
) - 1);)
131 if (!page_size
|| !page_size
[0])
133 if (!_cups_strncasecmp(s
, "Custom.", 7) || ppdPageSize(ppd
, s
))
134 ppd_mark_option(ppd
, "PageSize", s
);
135 else if ((ppd_keyword
= _ppdCacheGetPageSize(cache
, NULL
, s
, NULL
)) != NULL
)
136 ppd_mark_option(ppd
, "PageSize", ppd_keyword
);
139 if (cache
&& cache
->source_option
&&
140 !cupsGetOption(cache
->source_option
, num_options
, options
) &&
141 (ppd_keyword
= _ppdCacheGetInputSlot(cache
, NULL
, s
)) != NULL
)
142 ppd_mark_option(ppd
, cache
->source_option
, ppd_keyword
);
144 if (!cupsGetOption("MediaType", num_options
, options
) &&
145 (ppd_keyword
= _ppdCacheGetMediaType(cache
, NULL
, s
)) != NULL
)
146 ppd_mark_option(ppd
, "MediaType", ppd_keyword
);
152 if (!cupsGetOption("com.apple.print.DocumentTicket.PMSpoolFormat",
153 num_options
, options
) &&
154 !cupsGetOption("APPrinterPreset", num_options
, options
) &&
155 (print_color_mode
|| print_quality
))
158 * Map output-mode and print-quality to a preset...
161 _pwg_print_color_mode_t pwg_pcm
;/* print-color-mode index */
162 _pwg_print_quality_t pwg_pq
; /* print-quality index */
163 cups_option_t
*preset
;/* Current preset option */
165 if (print_color_mode
&& !strcmp(print_color_mode
, "monochrome"))
166 pwg_pcm
= _PWG_PRINT_COLOR_MODE_MONOCHROME
;
168 pwg_pcm
= _PWG_PRINT_COLOR_MODE_COLOR
;
172 pwg_pq
= (_pwg_print_quality_t
)(atoi(print_quality
) - IPP_QUALITY_DRAFT
);
173 if (pwg_pq
< _PWG_PRINT_QUALITY_DRAFT
)
174 pwg_pq
= _PWG_PRINT_QUALITY_DRAFT
;
175 else if (pwg_pq
> _PWG_PRINT_QUALITY_HIGH
)
176 pwg_pq
= _PWG_PRINT_QUALITY_HIGH
;
179 pwg_pq
= _PWG_PRINT_QUALITY_NORMAL
;
181 if (cache
->num_presets
[pwg_pcm
][pwg_pq
] == 0)
184 * Try to find a preset that works so that we maximize the chances of us
185 * getting a good print using IPP attributes.
188 if (cache
->num_presets
[pwg_pcm
][_PWG_PRINT_QUALITY_NORMAL
] > 0)
189 pwg_pq
= _PWG_PRINT_QUALITY_NORMAL
;
190 else if (cache
->num_presets
[_PWG_PRINT_COLOR_MODE_COLOR
][pwg_pq
] > 0)
191 pwg_pcm
= _PWG_PRINT_COLOR_MODE_COLOR
;
194 pwg_pq
= _PWG_PRINT_QUALITY_NORMAL
;
195 pwg_pcm
= _PWG_PRINT_COLOR_MODE_COLOR
;
199 if (cache
->num_presets
[pwg_pcm
][pwg_pq
] > 0)
202 * Copy the preset options as long as the corresponding names are not
203 * already defined in the IPP request...
206 for (i
= cache
->num_presets
[pwg_pcm
][pwg_pq
],
207 preset
= cache
->presets
[pwg_pcm
][pwg_pq
];
211 if (!cupsGetOption(preset
->name
, num_options
, options
))
212 ppd_mark_option(ppd
, preset
->name
, preset
->value
);
217 if (output_bin
&& !cupsGetOption("OutputBin", num_options
, options
) &&
218 (ppd_keyword
= _ppdCacheGetOutputBin(cache
, output_bin
)) != NULL
)
221 * Map output-bin to OutputBin...
224 ppd_mark_option(ppd
, "OutputBin", ppd_keyword
);
227 if (sides
&& cache
->sides_option
&&
228 !cupsGetOption(cache
->sides_option
, num_options
, options
))
231 * Map sides to duplex option...
234 if (!strcmp(sides
, "one-sided") && cache
->sides_1sided
)
235 ppd_mark_option(ppd
, cache
->sides_option
, cache
->sides_1sided
);
236 else if (!strcmp(sides
, "two-sided-long-edge") &&
237 cache
->sides_2sided_long
)
238 ppd_mark_option(ppd
, cache
->sides_option
, cache
->sides_2sided_long
);
239 else if (!strcmp(sides
, "two-sided-short-edge") &&
240 cache
->sides_2sided_short
)
241 ppd_mark_option(ppd
, cache
->sides_option
, cache
->sides_2sided_short
);
246 * Mark other options...
249 for (i
= num_options
, optptr
= options
; i
> 0; i
--, optptr
++)
251 if (!_cups_strcasecmp(optptr
->name
, "media") ||
252 !_cups_strcasecmp(optptr
->name
, "output-bin") ||
253 !_cups_strcasecmp(optptr
->name
, "output-mode") ||
254 !_cups_strcasecmp(optptr
->name
, "print-quality") ||
255 !_cups_strcasecmp(optptr
->name
, "sides"))
257 else if (!_cups_strcasecmp(optptr
->name
, "resolution") ||
258 !_cups_strcasecmp(optptr
->name
, "printer-resolution"))
260 ppd_mark_option(ppd
, "Resolution", optptr
->value
);
261 ppd_mark_option(ppd
, "SetResolution", optptr
->value
);
262 /* Calcomp, Linotype, QMS, Summagraphics, Tektronix, Varityper */
263 ppd_mark_option(ppd
, "JCLResolution", optptr
->value
);
265 ppd_mark_option(ppd
, "CNRes_PGP", optptr
->value
);
268 else if (!_cups_strcasecmp(optptr
->name
, "multiple-document-handling"))
270 if (!cupsGetOption("Collate", num_options
, options
) &&
271 ppdFindOption(ppd
, "Collate"))
273 if (_cups_strcasecmp(optptr
->value
, "separate-documents-uncollated-copies"))
274 ppd_mark_option(ppd
, "Collate", "True");
276 ppd_mark_option(ppd
, "Collate", "False");
279 else if (!_cups_strcasecmp(optptr
->name
, "finishings"))
282 * Lookup cupsIPPFinishings attributes for each value...
285 for (ptr
= optptr
->value
; *ptr
;)
288 * Get the next finishings number...
291 if (!isdigit(*ptr
& 255))
294 if ((j
= (int)strtol(ptr
, &ptr
, 10)) < 3)
298 * Skip separator as needed...
305 * Look it up in the PPD file...
310 if ((attr
= ppdFindAttr(ppd
, "cupsIPPFinishings", s
)) == NULL
)
314 * Apply "*Option Choice" settings from the attribute value...
317 ppd_mark_choices(ppd
, attr
->value
);
320 else if (!_cups_strcasecmp(optptr
->name
, "APPrinterPreset"))
323 * Lookup APPrinterPreset value...
326 if ((attr
= ppdFindAttr(ppd
, "APPrinterPreset", optptr
->value
)) != NULL
)
329 * Apply "*Option Choice" settings from the attribute value...
332 ppd_mark_choices(ppd
, attr
->value
);
335 else if (!_cups_strcasecmp(optptr
->name
, "mirror"))
336 ppd_mark_option(ppd
, "MirrorPrint", optptr
->value
);
338 ppd_mark_option(ppd
, optptr
->name
, optptr
->value
);
343 int pq
= atoi(print_quality
); /* print-quaity value */
345 if (pq
== IPP_QUALITY_DRAFT
)
346 ppd_mark_option(ppd
, "cupsPrintQuality", "Draft");
347 else if (pq
== IPP_QUALITY_HIGH
)
348 ppd_mark_option(ppd
, "cupsPrintQuality", "High");
350 ppd_mark_option(ppd
, "cupsPrintQuality", "Normal");
353 ppd_debug_marked(ppd
, "After...");
355 return (ppdConflicts(ppd
) > 0);
360 * 'ppdFindChoice()' - Return a pointer to an option choice.
363 ppd_choice_t
* /* O - Choice pointer or @code NULL@ */
364 ppdFindChoice(ppd_option_t
*o
, /* I - Pointer to option */
365 const char *choice
) /* I - Name of choice */
367 int i
; /* Looping var */
368 ppd_choice_t
*c
; /* Current choice */
374 if (choice
[0] == '{' || !_cups_strncasecmp(choice
, "Custom.", 7))
377 for (i
= o
->num_choices
, c
= o
->choices
; i
> 0; i
--, c
++)
378 if (!_cups_strcasecmp(c
->choice
, choice
))
386 * 'ppdFindMarkedChoice()' - Return the marked choice for the specified option.
389 ppd_choice_t
* /* O - Pointer to choice or @code NULL@ */
390 ppdFindMarkedChoice(ppd_file_t
*ppd
, /* I - PPD file */
391 const char *option
) /* I - Keyword/option name */
393 ppd_choice_t key
, /* Search key for choice */
394 *marked
; /* Marked choice */
397 DEBUG_printf(("2ppdFindMarkedChoice(ppd=%p, option=\"%s\")", ppd
, option
));
399 if ((key
.option
= ppdFindOption(ppd
, option
)) == NULL
)
401 DEBUG_puts("3ppdFindMarkedChoice: Option not found, returning NULL");
405 marked
= (ppd_choice_t
*)cupsArrayFind(ppd
->marked
, &key
);
407 DEBUG_printf(("3ppdFindMarkedChoice: Returning %p(%s)...", marked
,
408 marked
? marked
->choice
: "NULL"));
415 * 'ppdFindOption()' - Return a pointer to the specified option.
418 ppd_option_t
* /* O - Pointer to option or @code NULL@ */
419 ppdFindOption(ppd_file_t
*ppd
, /* I - PPD file data */
420 const char *option
) /* I - Option/Keyword name */
423 * Range check input...
432 * Search in the array...
435 ppd_option_t key
; /* Option search key */
438 strlcpy(key
.keyword
, option
, sizeof(key
.keyword
));
440 return ((ppd_option_t
*)cupsArrayFind(ppd
->options
, &key
));
445 * Search in each group...
448 int i
, j
; /* Looping vars */
449 ppd_group_t
*group
; /* Current group */
450 ppd_option_t
*optptr
; /* Current option */
453 for (i
= ppd
->num_groups
, group
= ppd
->groups
; i
> 0; i
--, group
++)
454 for (j
= group
->num_options
, optptr
= group
->options
;
457 if (!_cups_strcasecmp(optptr
->keyword
, option
))
466 * 'ppdIsMarked()' - Check to see if an option is marked.
469 int /* O - Non-zero if option is marked */
470 ppdIsMarked(ppd_file_t
*ppd
, /* I - PPD file data */
471 const char *option
, /* I - Option/Keyword name */
472 const char *choice
) /* I - Choice name */
474 ppd_choice_t key
, /* Search key */
475 *c
; /* Choice pointer */
481 if ((key
.option
= ppdFindOption(ppd
, option
)) == NULL
)
484 if ((c
= (ppd_choice_t
*)cupsArrayFind(ppd
->marked
, &key
)) == NULL
)
487 return (!strcmp(c
->choice
, choice
));
492 * 'ppdMarkDefaults()' - Mark all default options in the PPD file.
496 ppdMarkDefaults(ppd_file_t
*ppd
) /* I - PPD file record */
498 int i
; /* Looping variables */
499 ppd_group_t
*g
; /* Current group */
500 ppd_choice_t
*c
; /* Current choice */
507 * Clean out the marked array...
510 for (c
= (ppd_choice_t
*)cupsArrayFirst(ppd
->marked
);
512 c
= (ppd_choice_t
*)cupsArrayNext(ppd
->marked
))
514 cupsArrayRemove(ppd
->marked
, c
);
519 * Then repopulate it with the defaults...
522 for (i
= ppd
->num_groups
, g
= ppd
->groups
; i
> 0; i
--, g
++)
523 ppd_defaults(ppd
, g
);
526 * Finally, tag any conflicts (API compatibility) once at the end.
534 * 'ppdMarkOption()' - Mark an option in a PPD file and return the number of
538 int /* O - Number of conflicts */
539 ppdMarkOption(ppd_file_t
*ppd
, /* I - PPD file record */
540 const char *option
, /* I - Keyword */
541 const char *choice
) /* I - Option name */
543 DEBUG_printf(("ppdMarkOption(ppd=%p, option=\"%s\", choice=\"%s\")",
544 ppd
, option
, choice
));
547 * Range check input...
550 if (!ppd
|| !option
|| !choice
)
557 ppd_mark_option(ppd
, option
, choice
);
560 * Return the number of conflicts...
563 return (ppdConflicts(ppd
));
568 * 'ppdFirstOption()' - Return the first option in the PPD file.
570 * Options are returned from all groups in ascending alphanumeric order.
572 * @since CUPS 1.2/macOS 10.5@
575 ppd_option_t
* /* O - First option or @code NULL@ */
576 ppdFirstOption(ppd_file_t
*ppd
) /* I - PPD file */
581 return ((ppd_option_t
*)cupsArrayFirst(ppd
->options
));
586 * 'ppdNextOption()' - Return the next option in the PPD file.
588 * Options are returned from all groups in ascending alphanumeric order.
590 * @since CUPS 1.2/macOS 10.5@
593 ppd_option_t
* /* O - Next option or @code NULL@ */
594 ppdNextOption(ppd_file_t
*ppd
) /* I - PPD file */
599 return ((ppd_option_t
*)cupsArrayNext(ppd
->options
));
604 * '_ppdParseOptions()' - Parse options from a PPD file.
606 * This function looks for strings of the form:
608 * *option choice ... *optionN choiceN
609 * property value ... propertyN valueN
611 * It stops when it finds a string that doesn't match this format.
614 int /* O - Number of options */
616 const char *s
, /* I - String to parse */
617 int num_options
, /* I - Number of options */
618 cups_option_t
**options
, /* IO - Options */
619 _ppd_parse_t which
) /* I - What to parse */
621 char option
[PPD_MAX_NAME
* 2 + 1], /* Current option/property */
622 choice
[PPD_MAX_NAME
], /* Current choice/value */
623 *ptr
; /* Pointer into option or choice */
627 return (num_options
);
630 * Read all of the "*Option Choice" and "property value" pairs from the
631 * string, add them to an options array as we go...
637 * Skip leading whitespace...
640 while (_cups_isspace(*s
))
644 * Get the option/property name...
648 while (*s
&& !_cups_isspace(*s
) && ptr
< (option
+ sizeof(option
) - 1))
651 if (ptr
== s
|| !_cups_isspace(*s
))
660 while (_cups_isspace(*s
))
667 while (*s
&& !_cups_isspace(*s
) && ptr
< (choice
+ sizeof(choice
) - 1))
670 if (*s
&& !_cups_isspace(*s
))
676 * Add it to the options array...
679 if (option
[0] == '*' && which
!= _PPD_PARSE_PROPERTIES
)
680 num_options
= cupsAddOption(option
+ 1, choice
, num_options
, options
);
681 else if (option
[0] != '*' && which
!= _PPD_PARSE_OPTIONS
)
682 num_options
= cupsAddOption(option
, choice
, num_options
, options
);
685 return (num_options
);
691 * 'ppd_debug_marked()' - Output the marked array to stdout...
695 ppd_debug_marked(ppd_file_t
*ppd
, /* I - PPD file data */
696 const char *title
) /* I - Title for list */
698 ppd_choice_t
*c
; /* Current choice */
701 DEBUG_printf(("2cupsMarkOptions: %s", title
));
703 for (c
= (ppd_choice_t
*)cupsArrayFirst(ppd
->marked
);
705 c
= (ppd_choice_t
*)cupsArrayNext(ppd
->marked
))
706 DEBUG_printf(("2cupsMarkOptions: %s=%s", c
->option
->keyword
, c
->choice
));
712 * 'ppd_defaults()' - Set the defaults for this group and all sub-groups.
716 ppd_defaults(ppd_file_t
*ppd
, /* I - PPD file */
717 ppd_group_t
*g
) /* I - Group to default */
719 int i
; /* Looping var */
720 ppd_option_t
*o
; /* Current option */
721 ppd_group_t
*sg
; /* Current sub-group */
724 for (i
= g
->num_options
, o
= g
->options
; i
> 0; i
--, o
++)
725 if (_cups_strcasecmp(o
->keyword
, "PageRegion") != 0)
726 ppd_mark_option(ppd
, o
->keyword
, o
->defchoice
);
728 for (i
= g
->num_subgroups
, sg
= g
->subgroups
; i
> 0; i
--, sg
++)
729 ppd_defaults(ppd
, sg
);
734 * 'ppd_mark_choices()' - Mark one or more option choices from a string.
738 ppd_mark_choices(ppd_file_t
*ppd
, /* I - PPD file */
739 const char *s
) /* I - "*Option Choice ..." string */
741 int i
, /* Looping var */
742 num_options
; /* Number of options */
743 cups_option_t
*options
, /* Options */
744 *option
; /* Current option */
751 num_options
= _ppdParseOptions(s
, 0, &options
, 0);
753 for (i
= num_options
, option
= options
; i
> 0; i
--, option
++)
754 ppd_mark_option(ppd
, option
->name
, option
->value
);
756 cupsFreeOptions(num_options
, options
);
761 * 'ppd_mark_option()' - Quick mark an option without checking for conflicts.
765 ppd_mark_option(ppd_file_t
*ppd
, /* I - PPD file */
766 const char *option
, /* I - Option name */
767 const char *choice
) /* I - Choice name */
769 int i
, j
; /* Looping vars */
770 ppd_option_t
*o
; /* Option pointer */
771 ppd_choice_t
*c
, /* Choice pointer */
772 *oldc
, /* Old choice pointer */
773 key
; /* Search key for choice */
774 struct lconv
*loc
; /* Locale data */
777 DEBUG_printf(("7ppd_mark_option(ppd=%p, option=\"%s\", choice=\"%s\")",
778 ppd
, option
, choice
));
781 * AP_D_InputSlot is the "default input slot" on macOS, and setting
782 * it clears the regular InputSlot choices...
785 if (!_cups_strcasecmp(option
, "AP_D_InputSlot"))
787 cupsArraySave(ppd
->options
);
789 if ((o
= ppdFindOption(ppd
, "InputSlot")) != NULL
)
792 if ((oldc
= (ppd_choice_t
*)cupsArrayFind(ppd
->marked
, &key
)) != NULL
)
795 cupsArrayRemove(ppd
->marked
, oldc
);
799 cupsArrayRestore(ppd
->options
);
803 * Check for custom options...
806 cupsArraySave(ppd
->options
);
808 o
= ppdFindOption(ppd
, option
);
810 cupsArrayRestore(ppd
->options
);
817 if (!_cups_strncasecmp(choice
, "Custom.", 7))
820 * Handle a custom option...
823 if ((c
= ppdFindChoice(o
, "Custom")) == NULL
)
826 if (!_cups_strcasecmp(option
, "PageSize"))
829 * Handle custom page sizes...
832 ppdPageSize(ppd
, choice
);
837 * Handle other custom options...
840 ppd_coption_t
*coption
; /* Custom option */
841 ppd_cparam_t
*cparam
; /* Custom parameter */
842 char *units
; /* Custom points units */
845 if ((coption
= ppdFindCustomOption(ppd
, option
)) != NULL
)
847 if ((cparam
= (ppd_cparam_t
*)cupsArrayFirst(coption
->params
)) == NULL
)
850 switch (cparam
->type
)
852 case PPD_CUSTOM_CURVE
:
853 case PPD_CUSTOM_INVCURVE
:
854 case PPD_CUSTOM_REAL
:
855 cparam
->current
.custom_real
= (float)_cupsStrScand(choice
+ 7,
859 case PPD_CUSTOM_POINTS
:
860 cparam
->current
.custom_points
= (float)_cupsStrScand(choice
+ 7,
866 if (!_cups_strcasecmp(units
, "cm"))
867 cparam
->current
.custom_points
*= 72.0f
/ 2.54f
;
868 else if (!_cups_strcasecmp(units
, "mm"))
869 cparam
->current
.custom_points
*= 72.0f
/ 25.4f
;
870 else if (!_cups_strcasecmp(units
, "m"))
871 cparam
->current
.custom_points
*= 72.0f
/ 0.0254f
;
872 else if (!_cups_strcasecmp(units
, "in"))
873 cparam
->current
.custom_points
*= 72.0f
;
874 else if (!_cups_strcasecmp(units
, "ft"))
875 cparam
->current
.custom_points
*= 12.0f
* 72.0f
;
879 case PPD_CUSTOM_INT
:
880 cparam
->current
.custom_int
= atoi(choice
+ 7);
883 case PPD_CUSTOM_PASSCODE
:
884 case PPD_CUSTOM_PASSWORD
:
885 case PPD_CUSTOM_STRING
:
886 if (cparam
->current
.custom_string
)
887 _cupsStrFree(cparam
->current
.custom_string
);
889 cparam
->current
.custom_string
= _cupsStrAlloc(choice
+ 7);
896 * Make sure that we keep the option marked below...
901 else if (choice
[0] == '{')
904 * Handle multi-value custom options...
907 ppd_coption_t
*coption
; /* Custom option */
908 ppd_cparam_t
*cparam
; /* Custom parameter */
909 char *units
; /* Custom points units */
910 int num_vals
; /* Number of values */
911 cups_option_t
*vals
, /* Values */
915 if ((c
= ppdFindChoice(o
, "Custom")) == NULL
)
918 if ((coption
= ppdFindCustomOption(ppd
, option
)) != NULL
)
920 num_vals
= cupsParseOptions(choice
, 0, &vals
);
922 for (i
= 0, val
= vals
; i
< num_vals
; i
++, val
++)
924 if ((cparam
= ppdFindCustomParam(coption
, val
->name
)) == NULL
)
927 switch (cparam
->type
)
929 case PPD_CUSTOM_CURVE
:
930 case PPD_CUSTOM_INVCURVE
:
931 case PPD_CUSTOM_REAL
:
932 cparam
->current
.custom_real
= (float)_cupsStrScand(val
->value
,
936 case PPD_CUSTOM_POINTS
:
937 cparam
->current
.custom_points
= (float)_cupsStrScand(val
->value
,
943 if (!_cups_strcasecmp(units
, "cm"))
944 cparam
->current
.custom_points
*= 72.0f
/ 2.54f
;
945 else if (!_cups_strcasecmp(units
, "mm"))
946 cparam
->current
.custom_points
*= 72.0f
/ 25.4f
;
947 else if (!_cups_strcasecmp(units
, "m"))
948 cparam
->current
.custom_points
*= 72.0f
/ 0.0254f
;
949 else if (!_cups_strcasecmp(units
, "in"))
950 cparam
->current
.custom_points
*= 72.0f
;
951 else if (!_cups_strcasecmp(units
, "ft"))
952 cparam
->current
.custom_points
*= 12.0f
* 72.0f
;
956 case PPD_CUSTOM_INT
:
957 cparam
->current
.custom_int
= atoi(val
->value
);
960 case PPD_CUSTOM_PASSCODE
:
961 case PPD_CUSTOM_PASSWORD
:
962 case PPD_CUSTOM_STRING
:
963 if (cparam
->current
.custom_string
)
964 _cupsStrFree(cparam
->current
.custom_string
);
966 cparam
->current
.custom_string
= _cupsStrRetain(val
->value
);
971 cupsFreeOptions(num_vals
, vals
);
976 for (i
= o
->num_choices
, c
= o
->choices
; i
> 0; i
--, c
++)
977 if (!_cups_strcasecmp(c
->choice
, choice
))
985 * Option found; mark it and then handle unmarking any other options.
988 if (o
->ui
!= PPD_UI_PICKMANY
)
991 * Unmark all other choices...
994 if ((oldc
= (ppd_choice_t
*)cupsArrayFind(ppd
->marked
, c
)) != NULL
)
997 cupsArrayRemove(ppd
->marked
, oldc
);
1000 if (!_cups_strcasecmp(option
, "PageSize") || !_cups_strcasecmp(option
, "PageRegion"))
1003 * Mark current page size...
1006 for (j
= 0; j
< ppd
->num_sizes
; j
++)
1007 ppd
->sizes
[j
].marked
= !_cups_strcasecmp(ppd
->sizes
[j
].name
,
1011 * Unmark the current PageSize or PageRegion setting, as
1015 cupsArraySave(ppd
->options
);
1017 if (!_cups_strcasecmp(option
, "PageSize"))
1019 if ((o
= ppdFindOption(ppd
, "PageRegion")) != NULL
)
1022 if ((oldc
= (ppd_choice_t
*)cupsArrayFind(ppd
->marked
, &key
)) != NULL
)
1025 cupsArrayRemove(ppd
->marked
, oldc
);
1031 if ((o
= ppdFindOption(ppd
, "PageSize")) != NULL
)
1034 if ((oldc
= (ppd_choice_t
*)cupsArrayFind(ppd
->marked
, &key
)) != NULL
)
1037 cupsArrayRemove(ppd
->marked
, oldc
);
1042 cupsArrayRestore(ppd
->options
);
1044 else if (!_cups_strcasecmp(option
, "InputSlot"))
1047 * Unmark ManualFeed option...
1050 cupsArraySave(ppd
->options
);
1052 if ((o
= ppdFindOption(ppd
, "ManualFeed")) != NULL
)
1055 if ((oldc
= (ppd_choice_t
*)cupsArrayFind(ppd
->marked
, &key
)) != NULL
)
1058 cupsArrayRemove(ppd
->marked
, oldc
);
1062 cupsArrayRestore(ppd
->options
);
1064 else if (!_cups_strcasecmp(option
, "ManualFeed") &&
1065 !_cups_strcasecmp(choice
, "True"))
1068 * Unmark InputSlot option...
1071 cupsArraySave(ppd
->options
);
1073 if ((o
= ppdFindOption(ppd
, "InputSlot")) != NULL
)
1076 if ((oldc
= (ppd_choice_t
*)cupsArrayFind(ppd
->marked
, &key
)) != NULL
)
1079 cupsArrayRemove(ppd
->marked
, oldc
);
1083 cupsArrayRestore(ppd
->options
);
1089 cupsArrayAdd(ppd
->marked
, c
);