2 * "$Id: mark.c 11558 2014-02-06 18:33:34Z msweet $"
4 * Option marking routines for CUPS.
6 * Copyright 2007-2014 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"
32 static void ppd_debug_marked(ppd_file_t
*ppd
, const char *title
);
34 # define ppd_debug_marked(ppd,title)
36 static void ppd_defaults(ppd_file_t
*ppd
, ppd_group_t
*g
);
37 static void ppd_mark_choices(ppd_file_t
*ppd
, const char *s
);
38 static void ppd_mark_option(ppd_file_t
*ppd
, const char *option
,
43 * 'cupsMarkOptions()' - Mark command-line options in a PPD file.
45 * This function maps the IPP "finishings", "media", "mirror",
46 * "multiple-document-handling", "output-bin", "print-color-mode",
47 * "print-quality", "printer-resolution", and "sides" attributes to their
48 * corresponding PPD options and choices.
51 int /* O - 1 if conflicts exist, 0 otherwise */
53 ppd_file_t
*ppd
, /* I - PPD file */
54 int num_options
, /* I - Number of options */
55 cups_option_t
*options
) /* I - Options */
57 int i
, j
; /* Looping vars */
58 char *ptr
, /* Pointer into string */
59 s
[255]; /* Temporary string */
60 const char *val
, /* Pointer into value */
61 *media
, /* media option */
62 *output_bin
, /* output-bin option */
63 *page_size
, /* PageSize option */
64 *ppd_keyword
, /* PPD keyword */
65 *print_color_mode
, /* print-color-mode option */
66 *print_quality
, /* print-quality option */
67 *sides
; /* sides option */
68 cups_option_t
*optptr
; /* Current option */
69 ppd_attr_t
*attr
; /* PPD attribute */
70 _ppd_cache_t
*cache
; /* PPD cache and mapping data */
77 if (!ppd
|| num_options
<= 0 || !options
)
80 ppd_debug_marked(ppd
, "Before...");
83 * Do special handling for finishings, media, output-bin, output-mode,
84 * print-color-mode, print-quality, and PageSize...
87 media
= cupsGetOption("media", num_options
, options
);
88 output_bin
= cupsGetOption("output-bin", num_options
, options
);
89 page_size
= cupsGetOption("PageSize", num_options
, options
);
90 print_quality
= cupsGetOption("print-quality", num_options
, options
);
91 sides
= cupsGetOption("sides", num_options
, options
);
93 if ((print_color_mode
= cupsGetOption("print-color-mode", num_options
,
95 print_color_mode
= cupsGetOption("output-mode", num_options
, options
);
97 if ((media
|| output_bin
|| print_color_mode
|| print_quality
|| sides
) &&
101 * Load PPD cache and mapping data as needed...
104 ppd
->cache
= _ppdCacheCreateWithPPD(ppd
);
112 * Loop through the option string, separating it at commas and marking each
113 * individual option as long as the corresponding PPD option (PageSize,
114 * InputSlot, etc.) is not also set.
116 * For PageSize, we also check for an empty option value since some versions
117 * of MacOS X use it to specify auto-selection of the media based solely on
121 for (val
= media
; *val
;)
124 * Extract the sub-option from the string...
127 for (ptr
= s
; *val
&& *val
!= ',' && (size_t)(ptr
- s
) < (sizeof(s
) - 1);)
138 if (!page_size
|| !page_size
[0])
140 if (!_cups_strncasecmp(s
, "Custom.", 7) || ppdPageSize(ppd
, s
))
141 ppd_mark_option(ppd
, "PageSize", s
);
142 else if ((ppd_keyword
= _ppdCacheGetPageSize(cache
, NULL
, s
, NULL
)) != NULL
)
143 ppd_mark_option(ppd
, "PageSize", ppd_keyword
);
146 if (cache
&& cache
->source_option
&&
147 !cupsGetOption(cache
->source_option
, num_options
, options
) &&
148 (ppd_keyword
= _ppdCacheGetInputSlot(cache
, NULL
, s
)) != NULL
)
149 ppd_mark_option(ppd
, cache
->source_option
, ppd_keyword
);
151 if (!cupsGetOption("MediaType", num_options
, options
) &&
152 (ppd_keyword
= _ppdCacheGetMediaType(cache
, NULL
, s
)) != NULL
)
153 ppd_mark_option(ppd
, "MediaType", ppd_keyword
);
159 if (!cupsGetOption("com.apple.print.DocumentTicket.PMSpoolFormat",
160 num_options
, options
) &&
161 !cupsGetOption("APPrinterPreset", num_options
, options
) &&
162 (print_color_mode
|| print_quality
))
165 * Map output-mode and print-quality to a preset...
168 _pwg_print_color_mode_t pwg_pcm
;/* print-color-mode index */
169 _pwg_print_quality_t pwg_pq
; /* print-quality index */
170 cups_option_t
*preset
;/* Current preset option */
172 if (print_color_mode
&& !strcmp(print_color_mode
, "monochrome"))
173 pwg_pcm
= _PWG_PRINT_COLOR_MODE_MONOCHROME
;
175 pwg_pcm
= _PWG_PRINT_COLOR_MODE_COLOR
;
179 pwg_pq
= (_pwg_print_quality_t
)(atoi(print_quality
) - IPP_QUALITY_DRAFT
);
180 if (pwg_pq
< _PWG_PRINT_QUALITY_DRAFT
)
181 pwg_pq
= _PWG_PRINT_QUALITY_DRAFT
;
182 else if (pwg_pq
> _PWG_PRINT_QUALITY_HIGH
)
183 pwg_pq
= _PWG_PRINT_QUALITY_HIGH
;
186 pwg_pq
= _PWG_PRINT_QUALITY_NORMAL
;
188 if (cache
->num_presets
[pwg_pcm
][pwg_pq
] == 0)
191 * Try to find a preset that works so that we maximize the chances of us
192 * getting a good print using IPP attributes.
195 if (cache
->num_presets
[pwg_pcm
][_PWG_PRINT_QUALITY_NORMAL
] > 0)
196 pwg_pq
= _PWG_PRINT_QUALITY_NORMAL
;
197 else if (cache
->num_presets
[_PWG_PRINT_COLOR_MODE_COLOR
][pwg_pq
] > 0)
198 pwg_pcm
= _PWG_PRINT_COLOR_MODE_COLOR
;
201 pwg_pq
= _PWG_PRINT_QUALITY_NORMAL
;
202 pwg_pcm
= _PWG_PRINT_COLOR_MODE_COLOR
;
206 if (cache
->num_presets
[pwg_pcm
][pwg_pq
] > 0)
209 * Copy the preset options as long as the corresponding names are not
210 * already defined in the IPP request...
213 for (i
= cache
->num_presets
[pwg_pcm
][pwg_pq
],
214 preset
= cache
->presets
[pwg_pcm
][pwg_pq
];
218 if (!cupsGetOption(preset
->name
, num_options
, options
))
219 ppd_mark_option(ppd
, preset
->name
, preset
->value
);
224 if (output_bin
&& !cupsGetOption("OutputBin", num_options
, options
) &&
225 (ppd_keyword
= _ppdCacheGetOutputBin(cache
, output_bin
)) != NULL
)
228 * Map output-bin to OutputBin...
231 ppd_mark_option(ppd
, "OutputBin", ppd_keyword
);
234 if (sides
&& cache
->sides_option
&&
235 !cupsGetOption(cache
->sides_option
, num_options
, options
))
238 * Map sides to duplex option...
241 if (!strcmp(sides
, "one-sided") && cache
->sides_1sided
)
242 ppd_mark_option(ppd
, cache
->sides_option
, cache
->sides_1sided
);
243 else if (!strcmp(sides
, "two-sided-long-edge") &&
244 cache
->sides_2sided_long
)
245 ppd_mark_option(ppd
, cache
->sides_option
, cache
->sides_2sided_long
);
246 else if (!strcmp(sides
, "two-sided-short-edge") &&
247 cache
->sides_2sided_short
)
248 ppd_mark_option(ppd
, cache
->sides_option
, cache
->sides_2sided_short
);
253 * Mark other options...
256 for (i
= num_options
, optptr
= options
; i
> 0; i
--, optptr
++)
257 if (!_cups_strcasecmp(optptr
->name
, "media") ||
258 !_cups_strcasecmp(optptr
->name
, "output-bin") ||
259 !_cups_strcasecmp(optptr
->name
, "output-mode") ||
260 !_cups_strcasecmp(optptr
->name
, "print-quality") ||
261 !_cups_strcasecmp(optptr
->name
, "sides"))
263 else if (!_cups_strcasecmp(optptr
->name
, "resolution") ||
264 !_cups_strcasecmp(optptr
->name
, "printer-resolution"))
266 ppd_mark_option(ppd
, "Resolution", optptr
->value
);
267 ppd_mark_option(ppd
, "SetResolution", optptr
->value
);
268 /* Calcomp, Linotype, QMS, Summagraphics, Tektronix, Varityper */
269 ppd_mark_option(ppd
, "JCLResolution", optptr
->value
);
271 ppd_mark_option(ppd
, "CNRes_PGP", optptr
->value
);
274 else if (!_cups_strcasecmp(optptr
->name
, "multiple-document-handling"))
276 if (!cupsGetOption("Collate", num_options
, options
) &&
277 ppdFindOption(ppd
, "Collate"))
279 if (_cups_strcasecmp(optptr
->value
, "separate-documents-uncollated-copies"))
280 ppd_mark_option(ppd
, "Collate", "True");
282 ppd_mark_option(ppd
, "Collate", "False");
285 else if (!_cups_strcasecmp(optptr
->name
, "finishings"))
288 * Lookup cupsIPPFinishings attributes for each value...
291 for (ptr
= optptr
->value
; *ptr
;)
294 * Get the next finishings number...
297 if (!isdigit(*ptr
& 255))
300 if ((j
= (int)strtol(ptr
, &ptr
, 10)) < 3)
304 * Skip separator as needed...
311 * Look it up in the PPD file...
316 if ((attr
= ppdFindAttr(ppd
, "cupsIPPFinishings", s
)) == NULL
)
320 * Apply "*Option Choice" settings from the attribute value...
323 ppd_mark_choices(ppd
, attr
->value
);
326 else if (!_cups_strcasecmp(optptr
->name
, "APPrinterPreset"))
329 * Lookup APPrinterPreset value...
332 if ((attr
= ppdFindAttr(ppd
, "APPrinterPreset", optptr
->value
)) != NULL
)
335 * Apply "*Option Choice" settings from the attribute value...
338 ppd_mark_choices(ppd
, attr
->value
);
341 else if (!_cups_strcasecmp(optptr
->name
, "mirror"))
342 ppd_mark_option(ppd
, "MirrorPrint", optptr
->value
);
344 ppd_mark_option(ppd
, optptr
->name
, optptr
->value
);
346 ppd_debug_marked(ppd
, "After...");
348 return (ppdConflicts(ppd
) > 0);
353 * 'ppdFindChoice()' - Return a pointer to an option choice.
356 ppd_choice_t
* /* O - Choice pointer or @code NULL@ */
357 ppdFindChoice(ppd_option_t
*o
, /* I - Pointer to option */
358 const char *choice
) /* I - Name of choice */
360 int i
; /* Looping var */
361 ppd_choice_t
*c
; /* Current choice */
367 if (choice
[0] == '{' || !_cups_strncasecmp(choice
, "Custom.", 7))
370 for (i
= o
->num_choices
, c
= o
->choices
; i
> 0; i
--, c
++)
371 if (!_cups_strcasecmp(c
->choice
, choice
))
379 * 'ppdFindMarkedChoice()' - Return the marked choice for the specified option.
382 ppd_choice_t
* /* O - Pointer to choice or @code NULL@ */
383 ppdFindMarkedChoice(ppd_file_t
*ppd
, /* I - PPD file */
384 const char *option
) /* I - Keyword/option name */
386 ppd_choice_t key
, /* Search key for choice */
387 *marked
; /* Marked choice */
390 DEBUG_printf(("2ppdFindMarkedChoice(ppd=%p, option=\"%s\")", ppd
, option
));
392 if ((key
.option
= ppdFindOption(ppd
, option
)) == NULL
)
394 DEBUG_puts("3ppdFindMarkedChoice: Option not found, returning NULL");
398 marked
= (ppd_choice_t
*)cupsArrayFind(ppd
->marked
, &key
);
400 DEBUG_printf(("3ppdFindMarkedChoice: Returning %p(%s)...", marked
,
401 marked
? marked
->choice
: "NULL"));
408 * 'ppdFindOption()' - Return a pointer to the specified option.
411 ppd_option_t
* /* O - Pointer to option or @code NULL@ */
412 ppdFindOption(ppd_file_t
*ppd
, /* I - PPD file data */
413 const char *option
) /* I - Option/Keyword name */
416 * Range check input...
425 * Search in the array...
428 ppd_option_t key
; /* Option search key */
431 strlcpy(key
.keyword
, option
, sizeof(key
.keyword
));
433 return ((ppd_option_t
*)cupsArrayFind(ppd
->options
, &key
));
438 * Search in each group...
441 int i
, j
; /* Looping vars */
442 ppd_group_t
*group
; /* Current group */
443 ppd_option_t
*optptr
; /* Current option */
446 for (i
= ppd
->num_groups
, group
= ppd
->groups
; i
> 0; i
--, group
++)
447 for (j
= group
->num_options
, optptr
= group
->options
;
450 if (!_cups_strcasecmp(optptr
->keyword
, option
))
459 * 'ppdIsMarked()' - Check to see if an option is marked.
462 int /* O - Non-zero if option is marked */
463 ppdIsMarked(ppd_file_t
*ppd
, /* I - PPD file data */
464 const char *option
, /* I - Option/Keyword name */
465 const char *choice
) /* I - Choice name */
467 ppd_choice_t key
, /* Search key */
468 *c
; /* Choice pointer */
474 if ((key
.option
= ppdFindOption(ppd
, option
)) == NULL
)
477 if ((c
= (ppd_choice_t
*)cupsArrayFind(ppd
->marked
, &key
)) == NULL
)
480 return (!strcmp(c
->choice
, choice
));
485 * 'ppdMarkDefaults()' - Mark all default options in the PPD file.
489 ppdMarkDefaults(ppd_file_t
*ppd
) /* I - PPD file record */
491 int i
; /* Looping variables */
492 ppd_group_t
*g
; /* Current group */
493 ppd_choice_t
*c
; /* Current choice */
500 * Clean out the marked array...
503 for (c
= (ppd_choice_t
*)cupsArrayFirst(ppd
->marked
);
505 c
= (ppd_choice_t
*)cupsArrayNext(ppd
->marked
))
507 cupsArrayRemove(ppd
->marked
, c
);
512 * Then repopulate it with the defaults...
515 for (i
= ppd
->num_groups
, g
= ppd
->groups
; i
> 0; i
--, g
++)
516 ppd_defaults(ppd
, g
);
521 * 'ppdMarkOption()' - Mark an option in a PPD file and return the number of
525 int /* O - Number of conflicts */
526 ppdMarkOption(ppd_file_t
*ppd
, /* I - PPD file record */
527 const char *option
, /* I - Keyword */
528 const char *choice
) /* I - Option name */
530 DEBUG_printf(("ppdMarkOption(ppd=%p, option=\"%s\", choice=\"%s\")",
531 ppd
, option
, choice
));
534 * Range check input...
537 if (!ppd
|| !option
|| !choice
)
544 ppd_mark_option(ppd
, option
, choice
);
547 * Return the number of conflicts...
550 return (ppdConflicts(ppd
));
555 * 'ppdFirstOption()' - Return the first option in the PPD file.
557 * Options are returned from all groups in ascending alphanumeric order.
559 * @since CUPS 1.2/OS X 10.5@
562 ppd_option_t
* /* O - First option or @code NULL@ */
563 ppdFirstOption(ppd_file_t
*ppd
) /* I - PPD file */
568 return ((ppd_option_t
*)cupsArrayFirst(ppd
->options
));
573 * 'ppdNextOption()' - Return the next option in the PPD file.
575 * Options are returned from all groups in ascending alphanumeric order.
577 * @since CUPS 1.2/OS X 10.5@
580 ppd_option_t
* /* O - Next option or @code NULL@ */
581 ppdNextOption(ppd_file_t
*ppd
) /* I - PPD file */
586 return ((ppd_option_t
*)cupsArrayNext(ppd
->options
));
591 * '_ppdParseOptions()' - Parse options from a PPD file.
593 * This function looks for strings of the form:
595 * *option choice ... *optionN choiceN
596 * property value ... propertyN valueN
598 * It stops when it finds a string that doesn't match this format.
601 int /* O - Number of options */
603 const char *s
, /* I - String to parse */
604 int num_options
, /* I - Number of options */
605 cups_option_t
**options
, /* IO - Options */
606 _ppd_parse_t which
) /* I - What to parse */
608 char option
[PPD_MAX_NAME
* 2 + 1], /* Current option/property */
609 choice
[PPD_MAX_NAME
], /* Current choice/value */
610 *ptr
; /* Pointer into option or choice */
614 return (num_options
);
617 * Read all of the "*Option Choice" and "property value" pairs from the
618 * string, add them to an options array as we go...
624 * Skip leading whitespace...
627 while (_cups_isspace(*s
))
631 * Get the option/property name...
635 while (*s
&& !_cups_isspace(*s
) && ptr
< (option
+ sizeof(option
) - 1))
638 if (ptr
== s
|| !_cups_isspace(*s
))
647 while (_cups_isspace(*s
))
654 while (*s
&& !_cups_isspace(*s
) && ptr
< (choice
+ sizeof(choice
) - 1))
657 if (*s
&& !_cups_isspace(*s
))
663 * Add it to the options array...
666 if (option
[0] == '*' && which
!= _PPD_PARSE_PROPERTIES
)
667 num_options
= cupsAddOption(option
+ 1, choice
, num_options
, options
);
668 else if (option
[0] != '*' && which
!= _PPD_PARSE_OPTIONS
)
669 num_options
= cupsAddOption(option
, choice
, num_options
, options
);
672 return (num_options
);
678 * 'ppd_debug_marked()' - Output the marked array to stdout...
682 ppd_debug_marked(ppd_file_t
*ppd
, /* I - PPD file data */
683 const char *title
) /* I - Title for list */
685 ppd_choice_t
*c
; /* Current choice */
688 DEBUG_printf(("2cupsMarkOptions: %s", title
));
690 for (c
= (ppd_choice_t
*)cupsArrayFirst(ppd
->marked
);
692 c
= (ppd_choice_t
*)cupsArrayNext(ppd
->marked
))
693 DEBUG_printf(("2cupsMarkOptions: %s=%s", c
->option
->keyword
, c
->choice
));
699 * 'ppd_defaults()' - Set the defaults for this group and all sub-groups.
703 ppd_defaults(ppd_file_t
*ppd
, /* I - PPD file */
704 ppd_group_t
*g
) /* I - Group to default */
706 int i
; /* Looping var */
707 ppd_option_t
*o
; /* Current option */
708 ppd_group_t
*sg
; /* Current sub-group */
711 for (i
= g
->num_options
, o
= g
->options
; i
> 0; i
--, o
++)
712 if (_cups_strcasecmp(o
->keyword
, "PageRegion") != 0)
713 ppdMarkOption(ppd
, o
->keyword
, o
->defchoice
);
715 for (i
= g
->num_subgroups
, sg
= g
->subgroups
; i
> 0; i
--, sg
++)
716 ppd_defaults(ppd
, sg
);
721 * 'ppd_mark_choices()' - Mark one or more option choices from a string.
725 ppd_mark_choices(ppd_file_t
*ppd
, /* I - PPD file */
726 const char *s
) /* I - "*Option Choice ..." string */
728 int i
, /* Looping var */
729 num_options
; /* Number of options */
730 cups_option_t
*options
, /* Options */
731 *option
; /* Current option */
738 num_options
= _ppdParseOptions(s
, 0, &options
, 0);
740 for (i
= num_options
, option
= options
; i
> 0; i
--, option
++)
741 ppd_mark_option(ppd
, option
->name
, option
->value
);
743 cupsFreeOptions(num_options
, options
);
748 * 'ppd_mark_option()' - Quick mark an option without checking for conflicts.
752 ppd_mark_option(ppd_file_t
*ppd
, /* I - PPD file */
753 const char *option
, /* I - Option name */
754 const char *choice
) /* I - Choice name */
756 int i
, j
; /* Looping vars */
757 ppd_option_t
*o
; /* Option pointer */
758 ppd_choice_t
*c
, /* Choice pointer */
759 *oldc
, /* Old choice pointer */
760 key
; /* Search key for choice */
761 struct lconv
*loc
; /* Locale data */
764 DEBUG_printf(("7ppd_mark_option(ppd=%p, option=\"%s\", choice=\"%s\")",
765 ppd
, option
, choice
));
768 * AP_D_InputSlot is the "default input slot" on MacOS X, and setting
769 * it clears the regular InputSlot choices...
772 if (!_cups_strcasecmp(option
, "AP_D_InputSlot"))
774 cupsArraySave(ppd
->options
);
776 if ((o
= ppdFindOption(ppd
, "InputSlot")) != NULL
)
779 if ((oldc
= (ppd_choice_t
*)cupsArrayFind(ppd
->marked
, &key
)) != NULL
)
782 cupsArrayRemove(ppd
->marked
, oldc
);
786 cupsArrayRestore(ppd
->options
);
790 * Check for custom options...
793 cupsArraySave(ppd
->options
);
795 o
= ppdFindOption(ppd
, option
);
797 cupsArrayRestore(ppd
->options
);
804 if (!_cups_strncasecmp(choice
, "Custom.", 7))
807 * Handle a custom option...
810 if ((c
= ppdFindChoice(o
, "Custom")) == NULL
)
813 if (!_cups_strcasecmp(option
, "PageSize"))
816 * Handle custom page sizes...
819 ppdPageSize(ppd
, choice
);
824 * Handle other custom options...
827 ppd_coption_t
*coption
; /* Custom option */
828 ppd_cparam_t
*cparam
; /* Custom parameter */
829 char *units
; /* Custom points units */
832 if ((coption
= ppdFindCustomOption(ppd
, option
)) != NULL
)
834 if ((cparam
= (ppd_cparam_t
*)cupsArrayFirst(coption
->params
)) == NULL
)
837 switch (cparam
->type
)
839 case PPD_CUSTOM_CURVE
:
840 case PPD_CUSTOM_INVCURVE
:
841 case PPD_CUSTOM_REAL
:
842 cparam
->current
.custom_real
= (float)_cupsStrScand(choice
+ 7,
846 case PPD_CUSTOM_POINTS
:
847 cparam
->current
.custom_points
= (float)_cupsStrScand(choice
+ 7,
853 if (!_cups_strcasecmp(units
, "cm"))
854 cparam
->current
.custom_points
*= 72.0f
/ 2.54f
;
855 else if (!_cups_strcasecmp(units
, "mm"))
856 cparam
->current
.custom_points
*= 72.0f
/ 25.4f
;
857 else if (!_cups_strcasecmp(units
, "m"))
858 cparam
->current
.custom_points
*= 72.0f
/ 0.0254f
;
859 else if (!_cups_strcasecmp(units
, "in"))
860 cparam
->current
.custom_points
*= 72.0f
;
861 else if (!_cups_strcasecmp(units
, "ft"))
862 cparam
->current
.custom_points
*= 12.0f
* 72.0f
;
866 case PPD_CUSTOM_INT
:
867 cparam
->current
.custom_int
= atoi(choice
+ 7);
870 case PPD_CUSTOM_PASSCODE
:
871 case PPD_CUSTOM_PASSWORD
:
872 case PPD_CUSTOM_STRING
:
873 if (cparam
->current
.custom_string
)
874 _cupsStrFree(cparam
->current
.custom_string
);
876 cparam
->current
.custom_string
= _cupsStrAlloc(choice
+ 7);
883 * Make sure that we keep the option marked below...
888 else if (choice
[0] == '{')
891 * Handle multi-value custom options...
894 ppd_coption_t
*coption
; /* Custom option */
895 ppd_cparam_t
*cparam
; /* Custom parameter */
896 char *units
; /* Custom points units */
897 int num_vals
; /* Number of values */
898 cups_option_t
*vals
, /* Values */
902 if ((c
= ppdFindChoice(o
, "Custom")) == NULL
)
905 if ((coption
= ppdFindCustomOption(ppd
, option
)) != NULL
)
907 num_vals
= cupsParseOptions(choice
, 0, &vals
);
909 for (i
= 0, val
= vals
; i
< num_vals
; i
++, val
++)
911 if ((cparam
= ppdFindCustomParam(coption
, val
->name
)) == NULL
)
914 switch (cparam
->type
)
916 case PPD_CUSTOM_CURVE
:
917 case PPD_CUSTOM_INVCURVE
:
918 case PPD_CUSTOM_REAL
:
919 cparam
->current
.custom_real
= (float)_cupsStrScand(val
->value
,
923 case PPD_CUSTOM_POINTS
:
924 cparam
->current
.custom_points
= (float)_cupsStrScand(val
->value
,
930 if (!_cups_strcasecmp(units
, "cm"))
931 cparam
->current
.custom_points
*= 72.0f
/ 2.54f
;
932 else if (!_cups_strcasecmp(units
, "mm"))
933 cparam
->current
.custom_points
*= 72.0f
/ 25.4f
;
934 else if (!_cups_strcasecmp(units
, "m"))
935 cparam
->current
.custom_points
*= 72.0f
/ 0.0254f
;
936 else if (!_cups_strcasecmp(units
, "in"))
937 cparam
->current
.custom_points
*= 72.0f
;
938 else if (!_cups_strcasecmp(units
, "ft"))
939 cparam
->current
.custom_points
*= 12.0f
* 72.0f
;
943 case PPD_CUSTOM_INT
:
944 cparam
->current
.custom_int
= atoi(val
->value
);
947 case PPD_CUSTOM_PASSCODE
:
948 case PPD_CUSTOM_PASSWORD
:
949 case PPD_CUSTOM_STRING
:
950 if (cparam
->current
.custom_string
)
951 _cupsStrFree(cparam
->current
.custom_string
);
953 cparam
->current
.custom_string
= _cupsStrRetain(val
->value
);
958 cupsFreeOptions(num_vals
, vals
);
963 for (i
= o
->num_choices
, c
= o
->choices
; i
> 0; i
--, c
++)
964 if (!_cups_strcasecmp(c
->choice
, choice
))
972 * Option found; mark it and then handle unmarking any other options.
975 if (o
->ui
!= PPD_UI_PICKMANY
)
978 * Unmark all other choices...
981 if ((oldc
= (ppd_choice_t
*)cupsArrayFind(ppd
->marked
, c
)) != NULL
)
984 cupsArrayRemove(ppd
->marked
, oldc
);
987 if (!_cups_strcasecmp(option
, "PageSize") || !_cups_strcasecmp(option
, "PageRegion"))
990 * Mark current page size...
993 for (j
= 0; j
< ppd
->num_sizes
; j
++)
994 ppd
->sizes
[j
].marked
= !_cups_strcasecmp(ppd
->sizes
[j
].name
,
998 * Unmark the current PageSize or PageRegion setting, as
1002 cupsArraySave(ppd
->options
);
1004 if (!_cups_strcasecmp(option
, "PageSize"))
1006 if ((o
= ppdFindOption(ppd
, "PageRegion")) != NULL
)
1009 if ((oldc
= (ppd_choice_t
*)cupsArrayFind(ppd
->marked
, &key
)) != NULL
)
1012 cupsArrayRemove(ppd
->marked
, oldc
);
1018 if ((o
= ppdFindOption(ppd
, "PageSize")) != NULL
)
1021 if ((oldc
= (ppd_choice_t
*)cupsArrayFind(ppd
->marked
, &key
)) != NULL
)
1024 cupsArrayRemove(ppd
->marked
, oldc
);
1029 cupsArrayRestore(ppd
->options
);
1031 else if (!_cups_strcasecmp(option
, "InputSlot"))
1034 * Unmark ManualFeed option...
1037 cupsArraySave(ppd
->options
);
1039 if ((o
= ppdFindOption(ppd
, "ManualFeed")) != NULL
)
1042 if ((oldc
= (ppd_choice_t
*)cupsArrayFind(ppd
->marked
, &key
)) != NULL
)
1045 cupsArrayRemove(ppd
->marked
, oldc
);
1049 cupsArrayRestore(ppd
->options
);
1051 else if (!_cups_strcasecmp(option
, "ManualFeed") &&
1052 !_cups_strcasecmp(choice
, "True"))
1055 * Unmark InputSlot option...
1058 cupsArraySave(ppd
->options
);
1060 if ((o
= ppdFindOption(ppd
, "InputSlot")) != NULL
)
1063 if ((oldc
= (ppd_choice_t
*)cupsArrayFind(ppd
->marked
, &key
)) != NULL
)
1066 cupsArrayRemove(ppd
->marked
, oldc
);
1070 cupsArrayRestore(ppd
->options
);
1076 cupsArrayAdd(ppd
->marked
, c
);
1081 * End of "$Id: mark.c 11558 2014-02-06 18:33:34Z msweet $".