4 * Option marking routines for CUPS.
6 * Copyright 2007-2015 by Apple Inc.
7 * Copyright 1997-2007 by Easy Software Products, all rights reserved.
9 * These coded instructions, statements, and computer programs are the
10 * property of Apple Inc. and are protected by Federal copyright
11 * law. Distribution and use rights are outlined in the file "LICENSE.txt"
12 * which should have been included with this file. If this file is
13 * file is missing or damaged, see the license at "http://www.cups.org/".
15 * PostScript is a trademark of Adobe Systems, Inc.
17 * This file is subject to the Apple OS-Developed Software exception.
21 * Include necessary headers...
24 #include "cups-private.h"
25 #include "ppd-private.h"
33 static void ppd_debug_marked(ppd_file_t
*ppd
, const char *title
);
35 # define ppd_debug_marked(ppd,title)
37 static void ppd_defaults(ppd_file_t
*ppd
, ppd_group_t
*g
);
38 static void ppd_mark_choices(ppd_file_t
*ppd
, const char *s
);
39 static void ppd_mark_option(ppd_file_t
*ppd
, const char *option
,
44 * 'cupsMarkOptions()' - Mark command-line options in a PPD file.
46 * This function maps the IPP "finishings", "media", "mirror",
47 * "multiple-document-handling", "output-bin", "print-color-mode",
48 * "print-quality", "printer-resolution", and "sides" attributes to their
49 * corresponding PPD options and choices.
52 int /* O - 1 if conflicts exist, 0 otherwise */
54 ppd_file_t
*ppd
, /* I - PPD file */
55 int num_options
, /* I - Number of options */
56 cups_option_t
*options
) /* I - Options */
58 int i
, j
; /* Looping vars */
59 char *ptr
, /* Pointer into string */
60 s
[255]; /* Temporary string */
61 const char *val
, /* Pointer into value */
62 *media
, /* media option */
63 *output_bin
, /* output-bin option */
64 *page_size
, /* PageSize option */
65 *ppd_keyword
, /* PPD keyword */
66 *print_color_mode
, /* print-color-mode option */
67 *print_quality
, /* print-quality option */
68 *sides
; /* sides option */
69 cups_option_t
*optptr
; /* Current option */
70 ppd_attr_t
*attr
; /* PPD attribute */
71 _ppd_cache_t
*cache
; /* PPD cache and mapping data */
78 if (!ppd
|| num_options
<= 0 || !options
)
81 ppd_debug_marked(ppd
, "Before...");
84 * Do special handling for finishings, media, output-bin, output-mode,
85 * print-color-mode, print-quality, and PageSize...
88 media
= cupsGetOption("media", num_options
, options
);
89 output_bin
= cupsGetOption("output-bin", num_options
, options
);
90 page_size
= cupsGetOption("PageSize", num_options
, options
);
91 print_quality
= cupsGetOption("print-quality", num_options
, options
);
92 sides
= cupsGetOption("sides", num_options
, options
);
94 if ((print_color_mode
= cupsGetOption("print-color-mode", num_options
,
96 print_color_mode
= cupsGetOption("output-mode", num_options
, options
);
98 if ((media
|| output_bin
|| print_color_mode
|| print_quality
|| sides
) &&
102 * Load PPD cache and mapping data as needed...
105 ppd
->cache
= _ppdCacheCreateWithPPD(ppd
);
113 * Loop through the option string, separating it at commas and marking each
114 * individual option as long as the corresponding PPD option (PageSize,
115 * InputSlot, etc.) is not also set.
117 * For PageSize, we also check for an empty option value since some versions
118 * of MacOS X use it to specify auto-selection of the media based solely on
122 for (val
= media
; *val
;)
125 * Extract the sub-option from the string...
128 for (ptr
= s
; *val
&& *val
!= ',' && (size_t)(ptr
- s
) < (sizeof(s
) - 1);)
139 if (!page_size
|| !page_size
[0])
141 if (!_cups_strncasecmp(s
, "Custom.", 7) || ppdPageSize(ppd
, s
))
142 ppd_mark_option(ppd
, "PageSize", s
);
143 else if ((ppd_keyword
= _ppdCacheGetPageSize(cache
, NULL
, s
, NULL
)) != NULL
)
144 ppd_mark_option(ppd
, "PageSize", ppd_keyword
);
147 if (cache
&& cache
->source_option
&&
148 !cupsGetOption(cache
->source_option
, num_options
, options
) &&
149 (ppd_keyword
= _ppdCacheGetInputSlot(cache
, NULL
, s
)) != NULL
)
150 ppd_mark_option(ppd
, cache
->source_option
, ppd_keyword
);
152 if (!cupsGetOption("MediaType", num_options
, options
) &&
153 (ppd_keyword
= _ppdCacheGetMediaType(cache
, NULL
, s
)) != NULL
)
154 ppd_mark_option(ppd
, "MediaType", ppd_keyword
);
160 if (!cupsGetOption("com.apple.print.DocumentTicket.PMSpoolFormat",
161 num_options
, options
) &&
162 !cupsGetOption("APPrinterPreset", num_options
, options
) &&
163 (print_color_mode
|| print_quality
))
166 * Map output-mode and print-quality to a preset...
169 _pwg_print_color_mode_t pwg_pcm
;/* print-color-mode index */
170 _pwg_print_quality_t pwg_pq
; /* print-quality index */
171 cups_option_t
*preset
;/* Current preset option */
173 if (print_color_mode
&& !strcmp(print_color_mode
, "monochrome"))
174 pwg_pcm
= _PWG_PRINT_COLOR_MODE_MONOCHROME
;
176 pwg_pcm
= _PWG_PRINT_COLOR_MODE_COLOR
;
180 pwg_pq
= (_pwg_print_quality_t
)(atoi(print_quality
) - IPP_QUALITY_DRAFT
);
181 if (pwg_pq
< _PWG_PRINT_QUALITY_DRAFT
)
182 pwg_pq
= _PWG_PRINT_QUALITY_DRAFT
;
183 else if (pwg_pq
> _PWG_PRINT_QUALITY_HIGH
)
184 pwg_pq
= _PWG_PRINT_QUALITY_HIGH
;
187 pwg_pq
= _PWG_PRINT_QUALITY_NORMAL
;
189 if (cache
->num_presets
[pwg_pcm
][pwg_pq
] == 0)
192 * Try to find a preset that works so that we maximize the chances of us
193 * getting a good print using IPP attributes.
196 if (cache
->num_presets
[pwg_pcm
][_PWG_PRINT_QUALITY_NORMAL
] > 0)
197 pwg_pq
= _PWG_PRINT_QUALITY_NORMAL
;
198 else if (cache
->num_presets
[_PWG_PRINT_COLOR_MODE_COLOR
][pwg_pq
] > 0)
199 pwg_pcm
= _PWG_PRINT_COLOR_MODE_COLOR
;
202 pwg_pq
= _PWG_PRINT_QUALITY_NORMAL
;
203 pwg_pcm
= _PWG_PRINT_COLOR_MODE_COLOR
;
207 if (cache
->num_presets
[pwg_pcm
][pwg_pq
] > 0)
210 * Copy the preset options as long as the corresponding names are not
211 * already defined in the IPP request...
214 for (i
= cache
->num_presets
[pwg_pcm
][pwg_pq
],
215 preset
= cache
->presets
[pwg_pcm
][pwg_pq
];
219 if (!cupsGetOption(preset
->name
, num_options
, options
))
220 ppd_mark_option(ppd
, preset
->name
, preset
->value
);
225 if (output_bin
&& !cupsGetOption("OutputBin", num_options
, options
) &&
226 (ppd_keyword
= _ppdCacheGetOutputBin(cache
, output_bin
)) != NULL
)
229 * Map output-bin to OutputBin...
232 ppd_mark_option(ppd
, "OutputBin", ppd_keyword
);
235 if (sides
&& cache
->sides_option
&&
236 !cupsGetOption(cache
->sides_option
, num_options
, options
))
239 * Map sides to duplex option...
242 if (!strcmp(sides
, "one-sided") && cache
->sides_1sided
)
243 ppd_mark_option(ppd
, cache
->sides_option
, cache
->sides_1sided
);
244 else if (!strcmp(sides
, "two-sided-long-edge") &&
245 cache
->sides_2sided_long
)
246 ppd_mark_option(ppd
, cache
->sides_option
, cache
->sides_2sided_long
);
247 else if (!strcmp(sides
, "two-sided-short-edge") &&
248 cache
->sides_2sided_short
)
249 ppd_mark_option(ppd
, cache
->sides_option
, cache
->sides_2sided_short
);
254 * Mark other options...
257 for (i
= num_options
, optptr
= options
; i
> 0; i
--, optptr
++)
258 if (!_cups_strcasecmp(optptr
->name
, "media") ||
259 !_cups_strcasecmp(optptr
->name
, "output-bin") ||
260 !_cups_strcasecmp(optptr
->name
, "output-mode") ||
261 !_cups_strcasecmp(optptr
->name
, "print-quality") ||
262 !_cups_strcasecmp(optptr
->name
, "sides"))
264 else if (!_cups_strcasecmp(optptr
->name
, "resolution") ||
265 !_cups_strcasecmp(optptr
->name
, "printer-resolution"))
267 ppd_mark_option(ppd
, "Resolution", optptr
->value
);
268 ppd_mark_option(ppd
, "SetResolution", optptr
->value
);
269 /* Calcomp, Linotype, QMS, Summagraphics, Tektronix, Varityper */
270 ppd_mark_option(ppd
, "JCLResolution", optptr
->value
);
272 ppd_mark_option(ppd
, "CNRes_PGP", optptr
->value
);
275 else if (!_cups_strcasecmp(optptr
->name
, "multiple-document-handling"))
277 if (!cupsGetOption("Collate", num_options
, options
) &&
278 ppdFindOption(ppd
, "Collate"))
280 if (_cups_strcasecmp(optptr
->value
, "separate-documents-uncollated-copies"))
281 ppd_mark_option(ppd
, "Collate", "True");
283 ppd_mark_option(ppd
, "Collate", "False");
286 else if (!_cups_strcasecmp(optptr
->name
, "finishings"))
289 * Lookup cupsIPPFinishings attributes for each value...
292 for (ptr
= optptr
->value
; *ptr
;)
295 * Get the next finishings number...
298 if (!isdigit(*ptr
& 255))
301 if ((j
= (int)strtol(ptr
, &ptr
, 10)) < 3)
305 * Skip separator as needed...
312 * Look it up in the PPD file...
317 if ((attr
= ppdFindAttr(ppd
, "cupsIPPFinishings", s
)) == NULL
)
321 * Apply "*Option Choice" settings from the attribute value...
324 ppd_mark_choices(ppd
, attr
->value
);
327 else if (!_cups_strcasecmp(optptr
->name
, "APPrinterPreset"))
330 * Lookup APPrinterPreset value...
333 if ((attr
= ppdFindAttr(ppd
, "APPrinterPreset", optptr
->value
)) != NULL
)
336 * Apply "*Option Choice" settings from the attribute value...
339 ppd_mark_choices(ppd
, attr
->value
);
342 else if (!_cups_strcasecmp(optptr
->name
, "mirror"))
343 ppd_mark_option(ppd
, "MirrorPrint", optptr
->value
);
345 ppd_mark_option(ppd
, optptr
->name
, optptr
->value
);
347 ppd_debug_marked(ppd
, "After...");
349 return (ppdConflicts(ppd
) > 0);
354 * 'ppdFindChoice()' - Return a pointer to an option choice.
357 ppd_choice_t
* /* O - Choice pointer or @code NULL@ */
358 ppdFindChoice(ppd_option_t
*o
, /* I - Pointer to option */
359 const char *choice
) /* I - Name of choice */
361 int i
; /* Looping var */
362 ppd_choice_t
*c
; /* Current choice */
368 if (choice
[0] == '{' || !_cups_strncasecmp(choice
, "Custom.", 7))
371 for (i
= o
->num_choices
, c
= o
->choices
; i
> 0; i
--, c
++)
372 if (!_cups_strcasecmp(c
->choice
, choice
))
380 * 'ppdFindMarkedChoice()' - Return the marked choice for the specified option.
383 ppd_choice_t
* /* O - Pointer to choice or @code NULL@ */
384 ppdFindMarkedChoice(ppd_file_t
*ppd
, /* I - PPD file */
385 const char *option
) /* I - Keyword/option name */
387 ppd_choice_t key
, /* Search key for choice */
388 *marked
; /* Marked choice */
391 DEBUG_printf(("2ppdFindMarkedChoice(ppd=%p, option=\"%s\")", ppd
, option
));
393 if ((key
.option
= ppdFindOption(ppd
, option
)) == NULL
)
395 DEBUG_puts("3ppdFindMarkedChoice: Option not found, returning NULL");
399 marked
= (ppd_choice_t
*)cupsArrayFind(ppd
->marked
, &key
);
401 DEBUG_printf(("3ppdFindMarkedChoice: Returning %p(%s)...", marked
,
402 marked
? marked
->choice
: "NULL"));
409 * 'ppdFindOption()' - Return a pointer to the specified option.
412 ppd_option_t
* /* O - Pointer to option or @code NULL@ */
413 ppdFindOption(ppd_file_t
*ppd
, /* I - PPD file data */
414 const char *option
) /* I - Option/Keyword name */
417 * Range check input...
426 * Search in the array...
429 ppd_option_t key
; /* Option search key */
432 strlcpy(key
.keyword
, option
, sizeof(key
.keyword
));
434 return ((ppd_option_t
*)cupsArrayFind(ppd
->options
, &key
));
439 * Search in each group...
442 int i
, j
; /* Looping vars */
443 ppd_group_t
*group
; /* Current group */
444 ppd_option_t
*optptr
; /* Current option */
447 for (i
= ppd
->num_groups
, group
= ppd
->groups
; i
> 0; i
--, group
++)
448 for (j
= group
->num_options
, optptr
= group
->options
;
451 if (!_cups_strcasecmp(optptr
->keyword
, option
))
460 * 'ppdIsMarked()' - Check to see if an option is marked.
463 int /* O - Non-zero if option is marked */
464 ppdIsMarked(ppd_file_t
*ppd
, /* I - PPD file data */
465 const char *option
, /* I - Option/Keyword name */
466 const char *choice
) /* I - Choice name */
468 ppd_choice_t key
, /* Search key */
469 *c
; /* Choice pointer */
475 if ((key
.option
= ppdFindOption(ppd
, option
)) == NULL
)
478 if ((c
= (ppd_choice_t
*)cupsArrayFind(ppd
->marked
, &key
)) == NULL
)
481 return (!strcmp(c
->choice
, choice
));
486 * 'ppdMarkDefaults()' - Mark all default options in the PPD file.
490 ppdMarkDefaults(ppd_file_t
*ppd
) /* I - PPD file record */
492 int i
; /* Looping variables */
493 ppd_group_t
*g
; /* Current group */
494 ppd_choice_t
*c
; /* Current choice */
501 * Clean out the marked array...
504 for (c
= (ppd_choice_t
*)cupsArrayFirst(ppd
->marked
);
506 c
= (ppd_choice_t
*)cupsArrayNext(ppd
->marked
))
508 cupsArrayRemove(ppd
->marked
, c
);
513 * Then repopulate it with the defaults...
516 for (i
= ppd
->num_groups
, g
= ppd
->groups
; i
> 0; i
--, g
++)
517 ppd_defaults(ppd
, g
);
520 * Finally, tag any conflicts (API compatibility) once at the end.
528 * 'ppdMarkOption()' - Mark an option in a PPD file and return the number of
532 int /* O - Number of conflicts */
533 ppdMarkOption(ppd_file_t
*ppd
, /* I - PPD file record */
534 const char *option
, /* I - Keyword */
535 const char *choice
) /* I - Option name */
537 DEBUG_printf(("ppdMarkOption(ppd=%p, option=\"%s\", choice=\"%s\")",
538 ppd
, option
, choice
));
541 * Range check input...
544 if (!ppd
|| !option
|| !choice
)
551 ppd_mark_option(ppd
, option
, choice
);
554 * Return the number of conflicts...
557 return (ppdConflicts(ppd
));
562 * 'ppdFirstOption()' - Return the first option in the PPD file.
564 * Options are returned from all groups in ascending alphanumeric order.
566 * @since CUPS 1.2/OS X 10.5@
569 ppd_option_t
* /* O - First option or @code NULL@ */
570 ppdFirstOption(ppd_file_t
*ppd
) /* I - PPD file */
575 return ((ppd_option_t
*)cupsArrayFirst(ppd
->options
));
580 * 'ppdNextOption()' - Return the next option in the PPD file.
582 * Options are returned from all groups in ascending alphanumeric order.
584 * @since CUPS 1.2/OS X 10.5@
587 ppd_option_t
* /* O - Next option or @code NULL@ */
588 ppdNextOption(ppd_file_t
*ppd
) /* I - PPD file */
593 return ((ppd_option_t
*)cupsArrayNext(ppd
->options
));
598 * '_ppdParseOptions()' - Parse options from a PPD file.
600 * This function looks for strings of the form:
602 * *option choice ... *optionN choiceN
603 * property value ... propertyN valueN
605 * It stops when it finds a string that doesn't match this format.
608 int /* O - Number of options */
610 const char *s
, /* I - String to parse */
611 int num_options
, /* I - Number of options */
612 cups_option_t
**options
, /* IO - Options */
613 _ppd_parse_t which
) /* I - What to parse */
615 char option
[PPD_MAX_NAME
* 2 + 1], /* Current option/property */
616 choice
[PPD_MAX_NAME
], /* Current choice/value */
617 *ptr
; /* Pointer into option or choice */
621 return (num_options
);
624 * Read all of the "*Option Choice" and "property value" pairs from the
625 * string, add them to an options array as we go...
631 * Skip leading whitespace...
634 while (_cups_isspace(*s
))
638 * Get the option/property name...
642 while (*s
&& !_cups_isspace(*s
) && ptr
< (option
+ sizeof(option
) - 1))
645 if (ptr
== s
|| !_cups_isspace(*s
))
654 while (_cups_isspace(*s
))
661 while (*s
&& !_cups_isspace(*s
) && ptr
< (choice
+ sizeof(choice
) - 1))
664 if (*s
&& !_cups_isspace(*s
))
670 * Add it to the options array...
673 if (option
[0] == '*' && which
!= _PPD_PARSE_PROPERTIES
)
674 num_options
= cupsAddOption(option
+ 1, choice
, num_options
, options
);
675 else if (option
[0] != '*' && which
!= _PPD_PARSE_OPTIONS
)
676 num_options
= cupsAddOption(option
, choice
, num_options
, options
);
679 return (num_options
);
685 * 'ppd_debug_marked()' - Output the marked array to stdout...
689 ppd_debug_marked(ppd_file_t
*ppd
, /* I - PPD file data */
690 const char *title
) /* I - Title for list */
692 ppd_choice_t
*c
; /* Current choice */
695 DEBUG_printf(("2cupsMarkOptions: %s", title
));
697 for (c
= (ppd_choice_t
*)cupsArrayFirst(ppd
->marked
);
699 c
= (ppd_choice_t
*)cupsArrayNext(ppd
->marked
))
700 DEBUG_printf(("2cupsMarkOptions: %s=%s", c
->option
->keyword
, c
->choice
));
706 * 'ppd_defaults()' - Set the defaults for this group and all sub-groups.
710 ppd_defaults(ppd_file_t
*ppd
, /* I - PPD file */
711 ppd_group_t
*g
) /* I - Group to default */
713 int i
; /* Looping var */
714 ppd_option_t
*o
; /* Current option */
715 ppd_group_t
*sg
; /* Current sub-group */
718 for (i
= g
->num_options
, o
= g
->options
; i
> 0; i
--, o
++)
719 if (_cups_strcasecmp(o
->keyword
, "PageRegion") != 0)
720 ppd_mark_option(ppd
, o
->keyword
, o
->defchoice
);
722 for (i
= g
->num_subgroups
, sg
= g
->subgroups
; i
> 0; i
--, sg
++)
723 ppd_defaults(ppd
, sg
);
728 * 'ppd_mark_choices()' - Mark one or more option choices from a string.
732 ppd_mark_choices(ppd_file_t
*ppd
, /* I - PPD file */
733 const char *s
) /* I - "*Option Choice ..." string */
735 int i
, /* Looping var */
736 num_options
; /* Number of options */
737 cups_option_t
*options
, /* Options */
738 *option
; /* Current option */
745 num_options
= _ppdParseOptions(s
, 0, &options
, 0);
747 for (i
= num_options
, option
= options
; i
> 0; i
--, option
++)
748 ppd_mark_option(ppd
, option
->name
, option
->value
);
750 cupsFreeOptions(num_options
, options
);
755 * 'ppd_mark_option()' - Quick mark an option without checking for conflicts.
759 ppd_mark_option(ppd_file_t
*ppd
, /* I - PPD file */
760 const char *option
, /* I - Option name */
761 const char *choice
) /* I - Choice name */
763 int i
, j
; /* Looping vars */
764 ppd_option_t
*o
; /* Option pointer */
765 ppd_choice_t
*c
, /* Choice pointer */
766 *oldc
, /* Old choice pointer */
767 key
; /* Search key for choice */
768 struct lconv
*loc
; /* Locale data */
771 DEBUG_printf(("7ppd_mark_option(ppd=%p, option=\"%s\", choice=\"%s\")",
772 ppd
, option
, choice
));
775 * AP_D_InputSlot is the "default input slot" on MacOS X, and setting
776 * it clears the regular InputSlot choices...
779 if (!_cups_strcasecmp(option
, "AP_D_InputSlot"))
781 cupsArraySave(ppd
->options
);
783 if ((o
= ppdFindOption(ppd
, "InputSlot")) != NULL
)
786 if ((oldc
= (ppd_choice_t
*)cupsArrayFind(ppd
->marked
, &key
)) != NULL
)
789 cupsArrayRemove(ppd
->marked
, oldc
);
793 cupsArrayRestore(ppd
->options
);
797 * Check for custom options...
800 cupsArraySave(ppd
->options
);
802 o
= ppdFindOption(ppd
, option
);
804 cupsArrayRestore(ppd
->options
);
811 if (!_cups_strncasecmp(choice
, "Custom.", 7))
814 * Handle a custom option...
817 if ((c
= ppdFindChoice(o
, "Custom")) == NULL
)
820 if (!_cups_strcasecmp(option
, "PageSize"))
823 * Handle custom page sizes...
826 ppdPageSize(ppd
, choice
);
831 * Handle other custom options...
834 ppd_coption_t
*coption
; /* Custom option */
835 ppd_cparam_t
*cparam
; /* Custom parameter */
836 char *units
; /* Custom points units */
839 if ((coption
= ppdFindCustomOption(ppd
, option
)) != NULL
)
841 if ((cparam
= (ppd_cparam_t
*)cupsArrayFirst(coption
->params
)) == NULL
)
844 switch (cparam
->type
)
846 case PPD_CUSTOM_CURVE
:
847 case PPD_CUSTOM_INVCURVE
:
848 case PPD_CUSTOM_REAL
:
849 cparam
->current
.custom_real
= (float)_cupsStrScand(choice
+ 7,
853 case PPD_CUSTOM_POINTS
:
854 cparam
->current
.custom_points
= (float)_cupsStrScand(choice
+ 7,
860 if (!_cups_strcasecmp(units
, "cm"))
861 cparam
->current
.custom_points
*= 72.0f
/ 2.54f
;
862 else if (!_cups_strcasecmp(units
, "mm"))
863 cparam
->current
.custom_points
*= 72.0f
/ 25.4f
;
864 else if (!_cups_strcasecmp(units
, "m"))
865 cparam
->current
.custom_points
*= 72.0f
/ 0.0254f
;
866 else if (!_cups_strcasecmp(units
, "in"))
867 cparam
->current
.custom_points
*= 72.0f
;
868 else if (!_cups_strcasecmp(units
, "ft"))
869 cparam
->current
.custom_points
*= 12.0f
* 72.0f
;
873 case PPD_CUSTOM_INT
:
874 cparam
->current
.custom_int
= atoi(choice
+ 7);
877 case PPD_CUSTOM_PASSCODE
:
878 case PPD_CUSTOM_PASSWORD
:
879 case PPD_CUSTOM_STRING
:
880 if (cparam
->current
.custom_string
)
881 _cupsStrFree(cparam
->current
.custom_string
);
883 cparam
->current
.custom_string
= _cupsStrAlloc(choice
+ 7);
890 * Make sure that we keep the option marked below...
895 else if (choice
[0] == '{')
898 * Handle multi-value custom options...
901 ppd_coption_t
*coption
; /* Custom option */
902 ppd_cparam_t
*cparam
; /* Custom parameter */
903 char *units
; /* Custom points units */
904 int num_vals
; /* Number of values */
905 cups_option_t
*vals
, /* Values */
909 if ((c
= ppdFindChoice(o
, "Custom")) == NULL
)
912 if ((coption
= ppdFindCustomOption(ppd
, option
)) != NULL
)
914 num_vals
= cupsParseOptions(choice
, 0, &vals
);
916 for (i
= 0, val
= vals
; i
< num_vals
; i
++, val
++)
918 if ((cparam
= ppdFindCustomParam(coption
, val
->name
)) == NULL
)
921 switch (cparam
->type
)
923 case PPD_CUSTOM_CURVE
:
924 case PPD_CUSTOM_INVCURVE
:
925 case PPD_CUSTOM_REAL
:
926 cparam
->current
.custom_real
= (float)_cupsStrScand(val
->value
,
930 case PPD_CUSTOM_POINTS
:
931 cparam
->current
.custom_points
= (float)_cupsStrScand(val
->value
,
937 if (!_cups_strcasecmp(units
, "cm"))
938 cparam
->current
.custom_points
*= 72.0f
/ 2.54f
;
939 else if (!_cups_strcasecmp(units
, "mm"))
940 cparam
->current
.custom_points
*= 72.0f
/ 25.4f
;
941 else if (!_cups_strcasecmp(units
, "m"))
942 cparam
->current
.custom_points
*= 72.0f
/ 0.0254f
;
943 else if (!_cups_strcasecmp(units
, "in"))
944 cparam
->current
.custom_points
*= 72.0f
;
945 else if (!_cups_strcasecmp(units
, "ft"))
946 cparam
->current
.custom_points
*= 12.0f
* 72.0f
;
950 case PPD_CUSTOM_INT
:
951 cparam
->current
.custom_int
= atoi(val
->value
);
954 case PPD_CUSTOM_PASSCODE
:
955 case PPD_CUSTOM_PASSWORD
:
956 case PPD_CUSTOM_STRING
:
957 if (cparam
->current
.custom_string
)
958 _cupsStrFree(cparam
->current
.custom_string
);
960 cparam
->current
.custom_string
= _cupsStrRetain(val
->value
);
965 cupsFreeOptions(num_vals
, vals
);
970 for (i
= o
->num_choices
, c
= o
->choices
; i
> 0; i
--, c
++)
971 if (!_cups_strcasecmp(c
->choice
, choice
))
979 * Option found; mark it and then handle unmarking any other options.
982 if (o
->ui
!= PPD_UI_PICKMANY
)
985 * Unmark all other choices...
988 if ((oldc
= (ppd_choice_t
*)cupsArrayFind(ppd
->marked
, c
)) != NULL
)
991 cupsArrayRemove(ppd
->marked
, oldc
);
994 if (!_cups_strcasecmp(option
, "PageSize") || !_cups_strcasecmp(option
, "PageRegion"))
997 * Mark current page size...
1000 for (j
= 0; j
< ppd
->num_sizes
; j
++)
1001 ppd
->sizes
[j
].marked
= !_cups_strcasecmp(ppd
->sizes
[j
].name
,
1005 * Unmark the current PageSize or PageRegion setting, as
1009 cupsArraySave(ppd
->options
);
1011 if (!_cups_strcasecmp(option
, "PageSize"))
1013 if ((o
= ppdFindOption(ppd
, "PageRegion")) != NULL
)
1016 if ((oldc
= (ppd_choice_t
*)cupsArrayFind(ppd
->marked
, &key
)) != NULL
)
1019 cupsArrayRemove(ppd
->marked
, oldc
);
1025 if ((o
= ppdFindOption(ppd
, "PageSize")) != NULL
)
1028 if ((oldc
= (ppd_choice_t
*)cupsArrayFind(ppd
->marked
, &key
)) != NULL
)
1031 cupsArrayRemove(ppd
->marked
, oldc
);
1036 cupsArrayRestore(ppd
->options
);
1038 else if (!_cups_strcasecmp(option
, "InputSlot"))
1041 * Unmark ManualFeed option...
1044 cupsArraySave(ppd
->options
);
1046 if ((o
= ppdFindOption(ppd
, "ManualFeed")) != NULL
)
1049 if ((oldc
= (ppd_choice_t
*)cupsArrayFind(ppd
->marked
, &key
)) != NULL
)
1052 cupsArrayRemove(ppd
->marked
, oldc
);
1056 cupsArrayRestore(ppd
->options
);
1058 else if (!_cups_strcasecmp(option
, "ManualFeed") &&
1059 !_cups_strcasecmp(choice
, "True"))
1062 * Unmark InputSlot option...
1065 cupsArraySave(ppd
->options
);
1067 if ((o
= ppdFindOption(ppd
, "InputSlot")) != NULL
)
1070 if ((oldc
= (ppd_choice_t
*)cupsArrayFind(ppd
->marked
, &key
)) != NULL
)
1073 cupsArrayRemove(ppd
->marked
, oldc
);
1077 cupsArrayRestore(ppd
->options
);
1083 cupsArrayAdd(ppd
->marked
, c
);