2 * Option marking routines for CUPS.
4 * Copyright 2007-2015 by Apple Inc.
5 * Copyright 1997-2007 by Easy Software Products, all rights reserved.
7 * These coded instructions, statements, and computer programs are the
8 * property of Apple Inc. and are protected by Federal copyright
9 * law. Distribution and use rights are outlined in the file "LICENSE.txt"
10 * which should have been included with this file. If this file is
11 * file is missing or damaged, see the license at "http://www.cups.org/".
13 * PostScript is a trademark of Adobe Systems, Inc.
15 * This file is subject to the Apple OS-Developed Software exception.
19 * Include necessary headers...
22 #include "cups-private.h"
23 #include "ppd-private.h"
31 static void ppd_debug_marked(ppd_file_t
*ppd
, const char *title
);
33 # define ppd_debug_marked(ppd,title)
35 static void ppd_defaults(ppd_file_t
*ppd
, ppd_group_t
*g
);
36 static void ppd_mark_choices(ppd_file_t
*ppd
, const char *s
);
37 static void ppd_mark_option(ppd_file_t
*ppd
, const char *option
,
42 * 'cupsMarkOptions()' - Mark command-line options in a PPD file.
44 * This function maps the IPP "finishings", "media", "mirror",
45 * "multiple-document-handling", "output-bin", "print-color-mode",
46 * "print-quality", "printer-resolution", and "sides" attributes to their
47 * corresponding PPD options and choices.
50 int /* O - 1 if conflicts exist, 0 otherwise */
52 ppd_file_t
*ppd
, /* I - PPD file */
53 int num_options
, /* I - Number of options */
54 cups_option_t
*options
) /* I - Options */
56 int i
, j
; /* Looping vars */
57 char *ptr
, /* Pointer into string */
58 s
[255]; /* Temporary string */
59 const char *val
, /* Pointer into value */
60 *media
, /* media option */
61 *output_bin
, /* output-bin option */
62 *page_size
, /* PageSize option */
63 *ppd_keyword
, /* PPD keyword */
64 *print_color_mode
, /* print-color-mode option */
65 *print_quality
, /* print-quality option */
66 *sides
; /* sides option */
67 cups_option_t
*optptr
; /* Current option */
68 ppd_attr_t
*attr
; /* PPD attribute */
69 _ppd_cache_t
*cache
; /* PPD cache and mapping data */
76 if (!ppd
|| num_options
<= 0 || !options
)
79 ppd_debug_marked(ppd
, "Before...");
82 * Do special handling for finishings, media, output-bin, output-mode,
83 * print-color-mode, print-quality, and PageSize...
86 media
= cupsGetOption("media", num_options
, options
);
87 output_bin
= cupsGetOption("output-bin", num_options
, options
);
88 page_size
= cupsGetOption("PageSize", num_options
, options
);
89 print_quality
= cupsGetOption("print-quality", num_options
, options
);
90 sides
= cupsGetOption("sides", num_options
, options
);
92 if ((print_color_mode
= cupsGetOption("print-color-mode", num_options
,
94 print_color_mode
= cupsGetOption("output-mode", num_options
, options
);
96 if ((media
|| output_bin
|| print_color_mode
|| print_quality
|| sides
) &&
100 * Load PPD cache and mapping data as needed...
103 ppd
->cache
= _ppdCacheCreateWithPPD(ppd
);
111 * Loop through the option string, separating it at commas and marking each
112 * individual option as long as the corresponding PPD option (PageSize,
113 * InputSlot, etc.) is not also set.
115 * For PageSize, we also check for an empty option value since some versions
116 * of MacmacOS use it to specify auto-selection of the media based solely on
120 for (val
= media
; *val
;)
123 * Extract the sub-option from the string...
126 for (ptr
= s
; *val
&& *val
!= ',' && (size_t)(ptr
- s
) < (sizeof(s
) - 1);)
137 if (!page_size
|| !page_size
[0])
139 if (!_cups_strncasecmp(s
, "Custom.", 7) || ppdPageSize(ppd
, s
))
140 ppd_mark_option(ppd
, "PageSize", s
);
141 else if ((ppd_keyword
= _ppdCacheGetPageSize(cache
, NULL
, s
, NULL
)) != NULL
)
142 ppd_mark_option(ppd
, "PageSize", ppd_keyword
);
145 if (cache
&& cache
->source_option
&&
146 !cupsGetOption(cache
->source_option
, num_options
, options
) &&
147 (ppd_keyword
= _ppdCacheGetInputSlot(cache
, NULL
, s
)) != NULL
)
148 ppd_mark_option(ppd
, cache
->source_option
, ppd_keyword
);
150 if (!cupsGetOption("MediaType", num_options
, options
) &&
151 (ppd_keyword
= _ppdCacheGetMediaType(cache
, NULL
, s
)) != NULL
)
152 ppd_mark_option(ppd
, "MediaType", ppd_keyword
);
158 if (!cupsGetOption("com.apple.print.DocumentTicket.PMSpoolFormat",
159 num_options
, options
) &&
160 !cupsGetOption("APPrinterPreset", num_options
, options
) &&
161 (print_color_mode
|| print_quality
))
164 * Map output-mode and print-quality to a preset...
167 _pwg_print_color_mode_t pwg_pcm
;/* print-color-mode index */
168 _pwg_print_quality_t pwg_pq
; /* print-quality index */
169 cups_option_t
*preset
;/* Current preset option */
171 if (print_color_mode
&& !strcmp(print_color_mode
, "monochrome"))
172 pwg_pcm
= _PWG_PRINT_COLOR_MODE_MONOCHROME
;
174 pwg_pcm
= _PWG_PRINT_COLOR_MODE_COLOR
;
178 pwg_pq
= (_pwg_print_quality_t
)(atoi(print_quality
) - IPP_QUALITY_DRAFT
);
179 if (pwg_pq
< _PWG_PRINT_QUALITY_DRAFT
)
180 pwg_pq
= _PWG_PRINT_QUALITY_DRAFT
;
181 else if (pwg_pq
> _PWG_PRINT_QUALITY_HIGH
)
182 pwg_pq
= _PWG_PRINT_QUALITY_HIGH
;
185 pwg_pq
= _PWG_PRINT_QUALITY_NORMAL
;
187 if (cache
->num_presets
[pwg_pcm
][pwg_pq
] == 0)
190 * Try to find a preset that works so that we maximize the chances of us
191 * getting a good print using IPP attributes.
194 if (cache
->num_presets
[pwg_pcm
][_PWG_PRINT_QUALITY_NORMAL
] > 0)
195 pwg_pq
= _PWG_PRINT_QUALITY_NORMAL
;
196 else if (cache
->num_presets
[_PWG_PRINT_COLOR_MODE_COLOR
][pwg_pq
] > 0)
197 pwg_pcm
= _PWG_PRINT_COLOR_MODE_COLOR
;
200 pwg_pq
= _PWG_PRINT_QUALITY_NORMAL
;
201 pwg_pcm
= _PWG_PRINT_COLOR_MODE_COLOR
;
205 if (cache
->num_presets
[pwg_pcm
][pwg_pq
] > 0)
208 * Copy the preset options as long as the corresponding names are not
209 * already defined in the IPP request...
212 for (i
= cache
->num_presets
[pwg_pcm
][pwg_pq
],
213 preset
= cache
->presets
[pwg_pcm
][pwg_pq
];
217 if (!cupsGetOption(preset
->name
, num_options
, options
))
218 ppd_mark_option(ppd
, preset
->name
, preset
->value
);
223 if (output_bin
&& !cupsGetOption("OutputBin", num_options
, options
) &&
224 (ppd_keyword
= _ppdCacheGetOutputBin(cache
, output_bin
)) != NULL
)
227 * Map output-bin to OutputBin...
230 ppd_mark_option(ppd
, "OutputBin", ppd_keyword
);
233 if (sides
&& cache
->sides_option
&&
234 !cupsGetOption(cache
->sides_option
, num_options
, options
))
237 * Map sides to duplex option...
240 if (!strcmp(sides
, "one-sided") && cache
->sides_1sided
)
241 ppd_mark_option(ppd
, cache
->sides_option
, cache
->sides_1sided
);
242 else if (!strcmp(sides
, "two-sided-long-edge") &&
243 cache
->sides_2sided_long
)
244 ppd_mark_option(ppd
, cache
->sides_option
, cache
->sides_2sided_long
);
245 else if (!strcmp(sides
, "two-sided-short-edge") &&
246 cache
->sides_2sided_short
)
247 ppd_mark_option(ppd
, cache
->sides_option
, cache
->sides_2sided_short
);
252 * Mark other options...
255 for (i
= num_options
, optptr
= options
; i
> 0; i
--, optptr
++)
256 if (!_cups_strcasecmp(optptr
->name
, "media") ||
257 !_cups_strcasecmp(optptr
->name
, "output-bin") ||
258 !_cups_strcasecmp(optptr
->name
, "output-mode") ||
259 !_cups_strcasecmp(optptr
->name
, "print-quality") ||
260 !_cups_strcasecmp(optptr
->name
, "sides"))
262 else if (!_cups_strcasecmp(optptr
->name
, "resolution") ||
263 !_cups_strcasecmp(optptr
->name
, "printer-resolution"))
265 ppd_mark_option(ppd
, "Resolution", optptr
->value
);
266 ppd_mark_option(ppd
, "SetResolution", optptr
->value
);
267 /* Calcomp, Linotype, QMS, Summagraphics, Tektronix, Varityper */
268 ppd_mark_option(ppd
, "JCLResolution", optptr
->value
);
270 ppd_mark_option(ppd
, "CNRes_PGP", optptr
->value
);
273 else if (!_cups_strcasecmp(optptr
->name
, "multiple-document-handling"))
275 if (!cupsGetOption("Collate", num_options
, options
) &&
276 ppdFindOption(ppd
, "Collate"))
278 if (_cups_strcasecmp(optptr
->value
, "separate-documents-uncollated-copies"))
279 ppd_mark_option(ppd
, "Collate", "True");
281 ppd_mark_option(ppd
, "Collate", "False");
284 else if (!_cups_strcasecmp(optptr
->name
, "finishings"))
287 * Lookup cupsIPPFinishings attributes for each value...
290 for (ptr
= optptr
->value
; *ptr
;)
293 * Get the next finishings number...
296 if (!isdigit(*ptr
& 255))
299 if ((j
= (int)strtol(ptr
, &ptr
, 10)) < 3)
303 * Skip separator as needed...
310 * Look it up in the PPD file...
315 if ((attr
= ppdFindAttr(ppd
, "cupsIPPFinishings", s
)) == NULL
)
319 * Apply "*Option Choice" settings from the attribute value...
322 ppd_mark_choices(ppd
, attr
->value
);
325 else if (!_cups_strcasecmp(optptr
->name
, "APPrinterPreset"))
328 * Lookup APPrinterPreset value...
331 if ((attr
= ppdFindAttr(ppd
, "APPrinterPreset", optptr
->value
)) != NULL
)
334 * Apply "*Option Choice" settings from the attribute value...
337 ppd_mark_choices(ppd
, attr
->value
);
340 else if (!_cups_strcasecmp(optptr
->name
, "mirror"))
341 ppd_mark_option(ppd
, "MirrorPrint", optptr
->value
);
343 ppd_mark_option(ppd
, optptr
->name
, optptr
->value
);
345 ppd_debug_marked(ppd
, "After...");
347 return (ppdConflicts(ppd
) > 0);
352 * 'ppdFindChoice()' - Return a pointer to an option choice.
355 ppd_choice_t
* /* O - Choice pointer or @code NULL@ */
356 ppdFindChoice(ppd_option_t
*o
, /* I - Pointer to option */
357 const char *choice
) /* I - Name of choice */
359 int i
; /* Looping var */
360 ppd_choice_t
*c
; /* Current choice */
366 if (choice
[0] == '{' || !_cups_strncasecmp(choice
, "Custom.", 7))
369 for (i
= o
->num_choices
, c
= o
->choices
; i
> 0; i
--, c
++)
370 if (!_cups_strcasecmp(c
->choice
, choice
))
378 * 'ppdFindMarkedChoice()' - Return the marked choice for the specified option.
381 ppd_choice_t
* /* O - Pointer to choice or @code NULL@ */
382 ppdFindMarkedChoice(ppd_file_t
*ppd
, /* I - PPD file */
383 const char *option
) /* I - Keyword/option name */
385 ppd_choice_t key
, /* Search key for choice */
386 *marked
; /* Marked choice */
389 DEBUG_printf(("2ppdFindMarkedChoice(ppd=%p, option=\"%s\")", ppd
, option
));
391 if ((key
.option
= ppdFindOption(ppd
, option
)) == NULL
)
393 DEBUG_puts("3ppdFindMarkedChoice: Option not found, returning NULL");
397 marked
= (ppd_choice_t
*)cupsArrayFind(ppd
->marked
, &key
);
399 DEBUG_printf(("3ppdFindMarkedChoice: Returning %p(%s)...", marked
,
400 marked
? marked
->choice
: "NULL"));
407 * 'ppdFindOption()' - Return a pointer to the specified option.
410 ppd_option_t
* /* O - Pointer to option or @code NULL@ */
411 ppdFindOption(ppd_file_t
*ppd
, /* I - PPD file data */
412 const char *option
) /* I - Option/Keyword name */
415 * Range check input...
424 * Search in the array...
427 ppd_option_t key
; /* Option search key */
430 strlcpy(key
.keyword
, option
, sizeof(key
.keyword
));
432 return ((ppd_option_t
*)cupsArrayFind(ppd
->options
, &key
));
437 * Search in each group...
440 int i
, j
; /* Looping vars */
441 ppd_group_t
*group
; /* Current group */
442 ppd_option_t
*optptr
; /* Current option */
445 for (i
= ppd
->num_groups
, group
= ppd
->groups
; i
> 0; i
--, group
++)
446 for (j
= group
->num_options
, optptr
= group
->options
;
449 if (!_cups_strcasecmp(optptr
->keyword
, option
))
458 * 'ppdIsMarked()' - Check to see if an option is marked.
461 int /* O - Non-zero if option is marked */
462 ppdIsMarked(ppd_file_t
*ppd
, /* I - PPD file data */
463 const char *option
, /* I - Option/Keyword name */
464 const char *choice
) /* I - Choice name */
466 ppd_choice_t key
, /* Search key */
467 *c
; /* Choice pointer */
473 if ((key
.option
= ppdFindOption(ppd
, option
)) == NULL
)
476 if ((c
= (ppd_choice_t
*)cupsArrayFind(ppd
->marked
, &key
)) == NULL
)
479 return (!strcmp(c
->choice
, choice
));
484 * 'ppdMarkDefaults()' - Mark all default options in the PPD file.
488 ppdMarkDefaults(ppd_file_t
*ppd
) /* I - PPD file record */
490 int i
; /* Looping variables */
491 ppd_group_t
*g
; /* Current group */
492 ppd_choice_t
*c
; /* Current choice */
499 * Clean out the marked array...
502 for (c
= (ppd_choice_t
*)cupsArrayFirst(ppd
->marked
);
504 c
= (ppd_choice_t
*)cupsArrayNext(ppd
->marked
))
506 cupsArrayRemove(ppd
->marked
, c
);
511 * Then repopulate it with the defaults...
514 for (i
= ppd
->num_groups
, g
= ppd
->groups
; i
> 0; i
--, g
++)
515 ppd_defaults(ppd
, g
);
518 * Finally, tag any conflicts (API compatibility) once at the end.
526 * 'ppdMarkOption()' - Mark an option in a PPD file and return the number of
530 int /* O - Number of conflicts */
531 ppdMarkOption(ppd_file_t
*ppd
, /* I - PPD file record */
532 const char *option
, /* I - Keyword */
533 const char *choice
) /* I - Option name */
535 DEBUG_printf(("ppdMarkOption(ppd=%p, option=\"%s\", choice=\"%s\")",
536 ppd
, option
, choice
));
539 * Range check input...
542 if (!ppd
|| !option
|| !choice
)
549 ppd_mark_option(ppd
, option
, choice
);
552 * Return the number of conflicts...
555 return (ppdConflicts(ppd
));
560 * 'ppdFirstOption()' - Return the first option in the PPD file.
562 * Options are returned from all groups in ascending alphanumeric order.
564 * @since CUPS 1.2/macOS 10.5@
567 ppd_option_t
* /* O - First option or @code NULL@ */
568 ppdFirstOption(ppd_file_t
*ppd
) /* I - PPD file */
573 return ((ppd_option_t
*)cupsArrayFirst(ppd
->options
));
578 * 'ppdNextOption()' - Return the next option in the PPD file.
580 * Options are returned from all groups in ascending alphanumeric order.
582 * @since CUPS 1.2/macOS 10.5@
585 ppd_option_t
* /* O - Next option or @code NULL@ */
586 ppdNextOption(ppd_file_t
*ppd
) /* I - PPD file */
591 return ((ppd_option_t
*)cupsArrayNext(ppd
->options
));
596 * '_ppdParseOptions()' - Parse options from a PPD file.
598 * This function looks for strings of the form:
600 * *option choice ... *optionN choiceN
601 * property value ... propertyN valueN
603 * It stops when it finds a string that doesn't match this format.
606 int /* O - Number of options */
608 const char *s
, /* I - String to parse */
609 int num_options
, /* I - Number of options */
610 cups_option_t
**options
, /* IO - Options */
611 _ppd_parse_t which
) /* I - What to parse */
613 char option
[PPD_MAX_NAME
* 2 + 1], /* Current option/property */
614 choice
[PPD_MAX_NAME
], /* Current choice/value */
615 *ptr
; /* Pointer into option or choice */
619 return (num_options
);
622 * Read all of the "*Option Choice" and "property value" pairs from the
623 * string, add them to an options array as we go...
629 * Skip leading whitespace...
632 while (_cups_isspace(*s
))
636 * Get the option/property name...
640 while (*s
&& !_cups_isspace(*s
) && ptr
< (option
+ sizeof(option
) - 1))
643 if (ptr
== s
|| !_cups_isspace(*s
))
652 while (_cups_isspace(*s
))
659 while (*s
&& !_cups_isspace(*s
) && ptr
< (choice
+ sizeof(choice
) - 1))
662 if (*s
&& !_cups_isspace(*s
))
668 * Add it to the options array...
671 if (option
[0] == '*' && which
!= _PPD_PARSE_PROPERTIES
)
672 num_options
= cupsAddOption(option
+ 1, choice
, num_options
, options
);
673 else if (option
[0] != '*' && which
!= _PPD_PARSE_OPTIONS
)
674 num_options
= cupsAddOption(option
, choice
, num_options
, options
);
677 return (num_options
);
683 * 'ppd_debug_marked()' - Output the marked array to stdout...
687 ppd_debug_marked(ppd_file_t
*ppd
, /* I - PPD file data */
688 const char *title
) /* I - Title for list */
690 ppd_choice_t
*c
; /* Current choice */
693 DEBUG_printf(("2cupsMarkOptions: %s", title
));
695 for (c
= (ppd_choice_t
*)cupsArrayFirst(ppd
->marked
);
697 c
= (ppd_choice_t
*)cupsArrayNext(ppd
->marked
))
698 DEBUG_printf(("2cupsMarkOptions: %s=%s", c
->option
->keyword
, c
->choice
));
704 * 'ppd_defaults()' - Set the defaults for this group and all sub-groups.
708 ppd_defaults(ppd_file_t
*ppd
, /* I - PPD file */
709 ppd_group_t
*g
) /* I - Group to default */
711 int i
; /* Looping var */
712 ppd_option_t
*o
; /* Current option */
713 ppd_group_t
*sg
; /* Current sub-group */
716 for (i
= g
->num_options
, o
= g
->options
; i
> 0; i
--, o
++)
717 if (_cups_strcasecmp(o
->keyword
, "PageRegion") != 0)
718 ppd_mark_option(ppd
, o
->keyword
, o
->defchoice
);
720 for (i
= g
->num_subgroups
, sg
= g
->subgroups
; i
> 0; i
--, sg
++)
721 ppd_defaults(ppd
, sg
);
726 * 'ppd_mark_choices()' - Mark one or more option choices from a string.
730 ppd_mark_choices(ppd_file_t
*ppd
, /* I - PPD file */
731 const char *s
) /* I - "*Option Choice ..." string */
733 int i
, /* Looping var */
734 num_options
; /* Number of options */
735 cups_option_t
*options
, /* Options */
736 *option
; /* Current option */
743 num_options
= _ppdParseOptions(s
, 0, &options
, 0);
745 for (i
= num_options
, option
= options
; i
> 0; i
--, option
++)
746 ppd_mark_option(ppd
, option
->name
, option
->value
);
748 cupsFreeOptions(num_options
, options
);
753 * 'ppd_mark_option()' - Quick mark an option without checking for conflicts.
757 ppd_mark_option(ppd_file_t
*ppd
, /* I - PPD file */
758 const char *option
, /* I - Option name */
759 const char *choice
) /* I - Choice name */
761 int i
, j
; /* Looping vars */
762 ppd_option_t
*o
; /* Option pointer */
763 ppd_choice_t
*c
, /* Choice pointer */
764 *oldc
, /* Old choice pointer */
765 key
; /* Search key for choice */
766 struct lconv
*loc
; /* Locale data */
769 DEBUG_printf(("7ppd_mark_option(ppd=%p, option=\"%s\", choice=\"%s\")",
770 ppd
, option
, choice
));
773 * AP_D_InputSlot is the "default input slot" on MacmacOS, and setting
774 * it clears the regular InputSlot choices...
777 if (!_cups_strcasecmp(option
, "AP_D_InputSlot"))
779 cupsArraySave(ppd
->options
);
781 if ((o
= ppdFindOption(ppd
, "InputSlot")) != NULL
)
784 if ((oldc
= (ppd_choice_t
*)cupsArrayFind(ppd
->marked
, &key
)) != NULL
)
787 cupsArrayRemove(ppd
->marked
, oldc
);
791 cupsArrayRestore(ppd
->options
);
795 * Check for custom options...
798 cupsArraySave(ppd
->options
);
800 o
= ppdFindOption(ppd
, option
);
802 cupsArrayRestore(ppd
->options
);
809 if (!_cups_strncasecmp(choice
, "Custom.", 7))
812 * Handle a custom option...
815 if ((c
= ppdFindChoice(o
, "Custom")) == NULL
)
818 if (!_cups_strcasecmp(option
, "PageSize"))
821 * Handle custom page sizes...
824 ppdPageSize(ppd
, choice
);
829 * Handle other custom options...
832 ppd_coption_t
*coption
; /* Custom option */
833 ppd_cparam_t
*cparam
; /* Custom parameter */
834 char *units
; /* Custom points units */
837 if ((coption
= ppdFindCustomOption(ppd
, option
)) != NULL
)
839 if ((cparam
= (ppd_cparam_t
*)cupsArrayFirst(coption
->params
)) == NULL
)
842 switch (cparam
->type
)
844 case PPD_CUSTOM_CURVE
:
845 case PPD_CUSTOM_INVCURVE
:
846 case PPD_CUSTOM_REAL
:
847 cparam
->current
.custom_real
= (float)_cupsStrScand(choice
+ 7,
851 case PPD_CUSTOM_POINTS
:
852 cparam
->current
.custom_points
= (float)_cupsStrScand(choice
+ 7,
858 if (!_cups_strcasecmp(units
, "cm"))
859 cparam
->current
.custom_points
*= 72.0f
/ 2.54f
;
860 else if (!_cups_strcasecmp(units
, "mm"))
861 cparam
->current
.custom_points
*= 72.0f
/ 25.4f
;
862 else if (!_cups_strcasecmp(units
, "m"))
863 cparam
->current
.custom_points
*= 72.0f
/ 0.0254f
;
864 else if (!_cups_strcasecmp(units
, "in"))
865 cparam
->current
.custom_points
*= 72.0f
;
866 else if (!_cups_strcasecmp(units
, "ft"))
867 cparam
->current
.custom_points
*= 12.0f
* 72.0f
;
871 case PPD_CUSTOM_INT
:
872 cparam
->current
.custom_int
= atoi(choice
+ 7);
875 case PPD_CUSTOM_PASSCODE
:
876 case PPD_CUSTOM_PASSWORD
:
877 case PPD_CUSTOM_STRING
:
878 if (cparam
->current
.custom_string
)
879 _cupsStrFree(cparam
->current
.custom_string
);
881 cparam
->current
.custom_string
= _cupsStrAlloc(choice
+ 7);
888 * Make sure that we keep the option marked below...
893 else if (choice
[0] == '{')
896 * Handle multi-value custom options...
899 ppd_coption_t
*coption
; /* Custom option */
900 ppd_cparam_t
*cparam
; /* Custom parameter */
901 char *units
; /* Custom points units */
902 int num_vals
; /* Number of values */
903 cups_option_t
*vals
, /* Values */
907 if ((c
= ppdFindChoice(o
, "Custom")) == NULL
)
910 if ((coption
= ppdFindCustomOption(ppd
, option
)) != NULL
)
912 num_vals
= cupsParseOptions(choice
, 0, &vals
);
914 for (i
= 0, val
= vals
; i
< num_vals
; i
++, val
++)
916 if ((cparam
= ppdFindCustomParam(coption
, val
->name
)) == NULL
)
919 switch (cparam
->type
)
921 case PPD_CUSTOM_CURVE
:
922 case PPD_CUSTOM_INVCURVE
:
923 case PPD_CUSTOM_REAL
:
924 cparam
->current
.custom_real
= (float)_cupsStrScand(val
->value
,
928 case PPD_CUSTOM_POINTS
:
929 cparam
->current
.custom_points
= (float)_cupsStrScand(val
->value
,
935 if (!_cups_strcasecmp(units
, "cm"))
936 cparam
->current
.custom_points
*= 72.0f
/ 2.54f
;
937 else if (!_cups_strcasecmp(units
, "mm"))
938 cparam
->current
.custom_points
*= 72.0f
/ 25.4f
;
939 else if (!_cups_strcasecmp(units
, "m"))
940 cparam
->current
.custom_points
*= 72.0f
/ 0.0254f
;
941 else if (!_cups_strcasecmp(units
, "in"))
942 cparam
->current
.custom_points
*= 72.0f
;
943 else if (!_cups_strcasecmp(units
, "ft"))
944 cparam
->current
.custom_points
*= 12.0f
* 72.0f
;
948 case PPD_CUSTOM_INT
:
949 cparam
->current
.custom_int
= atoi(val
->value
);
952 case PPD_CUSTOM_PASSCODE
:
953 case PPD_CUSTOM_PASSWORD
:
954 case PPD_CUSTOM_STRING
:
955 if (cparam
->current
.custom_string
)
956 _cupsStrFree(cparam
->current
.custom_string
);
958 cparam
->current
.custom_string
= _cupsStrRetain(val
->value
);
963 cupsFreeOptions(num_vals
, vals
);
968 for (i
= o
->num_choices
, c
= o
->choices
; i
> 0; i
--, c
++)
969 if (!_cups_strcasecmp(c
->choice
, choice
))
977 * Option found; mark it and then handle unmarking any other options.
980 if (o
->ui
!= PPD_UI_PICKMANY
)
983 * Unmark all other choices...
986 if ((oldc
= (ppd_choice_t
*)cupsArrayFind(ppd
->marked
, c
)) != NULL
)
989 cupsArrayRemove(ppd
->marked
, oldc
);
992 if (!_cups_strcasecmp(option
, "PageSize") || !_cups_strcasecmp(option
, "PageRegion"))
995 * Mark current page size...
998 for (j
= 0; j
< ppd
->num_sizes
; j
++)
999 ppd
->sizes
[j
].marked
= !_cups_strcasecmp(ppd
->sizes
[j
].name
,
1003 * Unmark the current PageSize or PageRegion setting, as
1007 cupsArraySave(ppd
->options
);
1009 if (!_cups_strcasecmp(option
, "PageSize"))
1011 if ((o
= ppdFindOption(ppd
, "PageRegion")) != NULL
)
1014 if ((oldc
= (ppd_choice_t
*)cupsArrayFind(ppd
->marked
, &key
)) != NULL
)
1017 cupsArrayRemove(ppd
->marked
, oldc
);
1023 if ((o
= ppdFindOption(ppd
, "PageSize")) != NULL
)
1026 if ((oldc
= (ppd_choice_t
*)cupsArrayFind(ppd
->marked
, &key
)) != NULL
)
1029 cupsArrayRemove(ppd
->marked
, oldc
);
1034 cupsArrayRestore(ppd
->options
);
1036 else if (!_cups_strcasecmp(option
, "InputSlot"))
1039 * Unmark ManualFeed option...
1042 cupsArraySave(ppd
->options
);
1044 if ((o
= ppdFindOption(ppd
, "ManualFeed")) != NULL
)
1047 if ((oldc
= (ppd_choice_t
*)cupsArrayFind(ppd
->marked
, &key
)) != NULL
)
1050 cupsArrayRemove(ppd
->marked
, oldc
);
1054 cupsArrayRestore(ppd
->options
);
1056 else if (!_cups_strcasecmp(option
, "ManualFeed") &&
1057 !_cups_strcasecmp(choice
, "True"))
1060 * Unmark InputSlot option...
1063 cupsArraySave(ppd
->options
);
1065 if ((o
= ppdFindOption(ppd
, "InputSlot")) != NULL
)
1068 if ((oldc
= (ppd_choice_t
*)cupsArrayFind(ppd
->marked
, &key
)) != NULL
)
1071 cupsArrayRemove(ppd
->marked
, oldc
);
1075 cupsArrayRestore(ppd
->options
);
1081 cupsArrayAdd(ppd
->marked
, c
);