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"
25 #include "ppd-private.h"
34 _PPD_NORMAL_CONSTRAINTS
,
35 _PPD_OPTION_CONSTRAINTS
,
36 _PPD_INSTALLABLE_CONSTRAINTS
,
45 static int ppd_is_installable(ppd_group_t
*installable
,
47 static void ppd_load_constraints(ppd_file_t
*ppd
);
48 static cups_array_t
*ppd_test_constraints(ppd_file_t
*ppd
,
52 cups_option_t
*options
,
57 * 'cupsGetConflicts()' - Get a list of conflicting options in a marked PPD.
59 * This function gets a list of options that would conflict if "option" and
60 * "choice" were marked in the PPD. You would typically call this function
61 * after marking the currently selected options in the PPD in order to
62 * determine whether a new option selection would cause a conflict.
64 * The number of conflicting options are returned with "options" pointing to
65 * the conflicting options. The returned option array must be freed using
66 * @link cupsFreeOptions@.
68 * @since CUPS 1.4/OS X 10.6@
71 int /* O - Number of conflicting options */
73 ppd_file_t
*ppd
, /* I - PPD file */
74 const char *option
, /* I - Option to test */
75 const char *choice
, /* I - Choice to test */
76 cups_option_t
**options
) /* O - Conflicting options */
78 int i
, /* Looping var */
79 num_options
; /* Number of conflicting options */
80 cups_array_t
*active
; /* Active conflicts */
81 _ppd_cups_uiconsts_t
*c
; /* Current constraints */
82 _ppd_cups_uiconst_t
*cptr
; /* Current constraint */
83 ppd_choice_t
*marked
; /* Marked choice */
87 * Range check input...
93 if (!ppd
|| !option
|| !choice
|| !options
)
97 * Test for conflicts...
100 active
= ppd_test_constraints(ppd
, option
, choice
, 0, NULL
,
101 _PPD_ALL_CONSTRAINTS
);
104 * Loop through all of the UI constraints and add any options that conflict...
107 for (num_options
= 0, c
= (_ppd_cups_uiconsts_t
*)cupsArrayFirst(active
);
109 c
= (_ppd_cups_uiconsts_t
*)cupsArrayNext(active
))
111 for (i
= c
->num_constraints
, cptr
= c
->constraints
;
114 if (_cups_strcasecmp(cptr
->option
->keyword
, option
))
117 num_options
= cupsAddOption(cptr
->option
->keyword
,
118 cptr
->choice
->choice
, num_options
,
120 else if ((marked
= ppdFindMarkedChoice(ppd
,
121 cptr
->option
->keyword
)) != NULL
)
122 num_options
= cupsAddOption(cptr
->option
->keyword
, marked
->choice
,
123 num_options
, options
);
127 cupsArrayDelete(active
);
129 return (num_options
);
134 * 'cupsResolveConflicts()' - Resolve conflicts in a marked PPD.
136 * This function attempts to resolve any conflicts in a marked PPD, returning
137 * a list of option changes that are required to resolve them. On input,
138 * "num_options" and "options" contain any pending option changes that have
139 * not yet been marked, while "option" and "choice" contain the most recent
140 * selection which may or may not be in "num_options" or "options".
142 * On successful return, "num_options" and "options" are updated to contain
143 * "option" and "choice" along with any changes required to resolve conflicts
144 * specified in the PPD file and 1 is returned.
146 * If option conflicts cannot be resolved, "num_options" and "options" are not
147 * changed and 0 is returned.
149 * When resolving conflicts, @code cupsResolveConflicts@ does not consider
150 * changes to the current page size (@code media@, @code PageSize@, and
151 * @code PageRegion@) or to the most recent option specified in "option".
152 * Thus, if the only way to resolve a conflict is to change the page size
153 * or the option the user most recently changed, @code cupsResolveConflicts@
154 * will return 0 to indicate it was unable to resolve the conflicts.
156 * The @code cupsResolveConflicts@ function uses one of two sources of option
157 * constraint information. The preferred constraint information is defined by
158 * @code cupsUIConstraints@ and @code cupsUIResolver@ attributes - in this
159 * case, the PPD file provides constraint resolution actions.
161 * The backup constraint information is defined by the
162 * @code UIConstraints@ and @code NonUIConstraints@ attributes. These
163 * constraints are resolved algorithmically by first selecting the default
164 * choice for the conflicting option, then iterating over all possible choices
165 * until a non-conflicting option choice is found.
167 * @since CUPS 1.4/OS X 10.6@
170 int /* O - 1 on success, 0 on failure */
171 cupsResolveConflicts(
172 ppd_file_t
*ppd
, /* I - PPD file */
173 const char *option
, /* I - Newly selected option or @code NULL@ for none */
174 const char *choice
, /* I - Newly selected choice or @code NULL@ for none */
175 int *num_options
, /* IO - Number of additional selected options */
176 cups_option_t
**options
) /* IO - Additional selected options */
178 int i
, /* Looping var */
179 tries
, /* Number of tries */
180 num_newopts
; /* Number of new options */
181 cups_option_t
*newopts
; /* New options */
182 cups_array_t
*active
= NULL
, /* Active constraints */
183 *pass
, /* Resolvers for this pass */
184 *resolvers
, /* Resolvers we have used */
185 *test
; /* Test array for conflicts */
186 _ppd_cups_uiconsts_t
*consts
; /* Current constraints */
187 _ppd_cups_uiconst_t
*constptr
; /* Current constraint */
188 ppd_attr_t
*resolver
; /* Current resolver */
189 const char *resval
; /* Pointer into resolver value */
190 char resoption
[PPD_MAX_NAME
],
191 /* Current resolver option */
192 reschoice
[PPD_MAX_NAME
],
193 /* Current resolver choice */
194 *resptr
, /* Pointer into option/choice */
195 firstpage
[255]; /* AP_FIRSTPAGE_Keyword string */
196 const char *value
; /* Selected option value */
197 int changed
; /* Did we change anything? */
198 ppd_choice_t
*marked
; /* Marked choice */
202 * Range check input...
205 if (!ppd
|| !num_options
|| !options
|| (option
== NULL
) != (choice
== NULL
))
209 * Build a shadow option array...
215 for (i
= 0; i
< *num_options
; i
++)
216 num_newopts
= cupsAddOption((*options
)[i
].name
, (*options
)[i
].value
,
217 num_newopts
, &newopts
);
218 if (option
&& _cups_strcasecmp(option
, "Collate"))
219 num_newopts
= cupsAddOption(option
, choice
, num_newopts
, &newopts
);
222 * Loop until we have no conflicts...
225 cupsArraySave(ppd
->sorted_attrs
);
228 pass
= cupsArrayNew((cups_array_func_t
)_cups_strcasecmp
, NULL
);
231 while (tries
< 100 &&
232 (active
= ppd_test_constraints(ppd
, NULL
, NULL
, num_newopts
, newopts
,
233 _PPD_ALL_CONSTRAINTS
)) != NULL
)
238 resolvers
= cupsArrayNew((cups_array_func_t
)_cups_strcasecmp
, NULL
);
240 for (consts
= (_ppd_cups_uiconsts_t
*)cupsArrayFirst(active
), changed
= 0;
242 consts
= (_ppd_cups_uiconsts_t
*)cupsArrayNext(active
))
244 if (consts
->resolver
[0])
247 * Look up the resolver...
250 if (cupsArrayFind(pass
, consts
->resolver
))
251 continue; /* Already applied this resolver... */
253 if (cupsArrayFind(resolvers
, consts
->resolver
))
259 DEBUG_printf(("1cupsResolveConflicts: Resolver loop with %s!",
264 if ((resolver
= ppdFindAttr(ppd
, "cupsUIResolver",
265 consts
->resolver
)) == NULL
)
267 DEBUG_printf(("1cupsResolveConflicts: Resolver %s not found!",
272 if (!resolver
->value
)
274 DEBUG_printf(("1cupsResolveConflicts: Resolver %s has no value!",
280 * Add the options from the resolver...
283 cupsArrayAdd(pass
, consts
->resolver
);
284 cupsArrayAdd(resolvers
, consts
->resolver
);
286 for (resval
= resolver
->value
; *resval
&& !changed
;)
288 while (_cups_isspace(*resval
))
294 for (resval
++, resptr
= resoption
;
295 *resval
&& !_cups_isspace(*resval
);
297 if (resptr
< (resoption
+ sizeof(resoption
) - 1))
302 while (_cups_isspace(*resval
))
305 for (resptr
= reschoice
;
306 *resval
&& !_cups_isspace(*resval
);
308 if (resptr
< (reschoice
+ sizeof(reschoice
) - 1))
313 if (!resoption
[0] || !reschoice
[0])
317 * Is this the option we are changing?
320 snprintf(firstpage
, sizeof(firstpage
), "AP_FIRSTPAGE_%s", resoption
);
323 (!_cups_strcasecmp(resoption
, option
) ||
324 !_cups_strcasecmp(firstpage
, option
) ||
325 (!_cups_strcasecmp(option
, "PageSize") &&
326 !_cups_strcasecmp(resoption
, "PageRegion")) ||
327 (!_cups_strcasecmp(option
, "AP_FIRSTPAGE_PageSize") &&
328 !_cups_strcasecmp(resoption
, "PageSize")) ||
329 (!_cups_strcasecmp(option
, "AP_FIRSTPAGE_PageSize") &&
330 !_cups_strcasecmp(resoption
, "PageRegion")) ||
331 (!_cups_strcasecmp(option
, "PageRegion") &&
332 !_cups_strcasecmp(resoption
, "PageSize")) ||
333 (!_cups_strcasecmp(option
, "AP_FIRSTPAGE_PageRegion") &&
334 !_cups_strcasecmp(resoption
, "PageSize")) ||
335 (!_cups_strcasecmp(option
, "AP_FIRSTPAGE_PageRegion") &&
336 !_cups_strcasecmp(resoption
, "PageRegion"))))
343 if ((test
= ppd_test_constraints(ppd
, resoption
, reschoice
,
344 num_newopts
, newopts
,
345 _PPD_ALL_CONSTRAINTS
)) == NULL
)
354 cupsArrayDelete(test
);
357 * Add the option/choice from the resolver regardless of whether it
358 * worked; this makes sure that we can cascade several changes to
359 * make things resolve...
362 num_newopts
= cupsAddOption(resoption
, reschoice
, num_newopts
,
369 * Try resolving by choosing the default values for non-installable
370 * options, then by iterating through the possible choices...
373 int j
; /* Looping var */
374 ppd_choice_t
*cptr
; /* Current choice */
375 ppd_size_t
*size
; /* Current page size */
378 for (i
= consts
->num_constraints
, constptr
= consts
->constraints
;
383 * Can't resolve by changing an installable option...
386 if (constptr
->installable
)
390 * Is this the option we are changing?
394 (!_cups_strcasecmp(constptr
->option
->keyword
, option
) ||
395 (!_cups_strcasecmp(option
, "PageSize") &&
396 !_cups_strcasecmp(constptr
->option
->keyword
, "PageRegion")) ||
397 (!_cups_strcasecmp(option
, "PageRegion") &&
398 !_cups_strcasecmp(constptr
->option
->keyword
, "PageSize"))))
402 * Get the current option choice...
405 if ((value
= cupsGetOption(constptr
->option
->keyword
, num_newopts
,
408 if (!_cups_strcasecmp(constptr
->option
->keyword
, "PageSize") ||
409 !_cups_strcasecmp(constptr
->option
->keyword
, "PageRegion"))
411 if ((value
= cupsGetOption("PageSize", num_newopts
,
413 value
= cupsGetOption("PageRegion", num_newopts
, newopts
);
417 if ((size
= ppdPageSize(ppd
, NULL
)) != NULL
)
425 marked
= ppdFindMarkedChoice(ppd
, constptr
->option
->keyword
);
426 value
= marked
? marked
->choice
: "";
430 if (!_cups_strncasecmp(value
, "Custom.", 7))
434 * Try the default choice...
439 if (_cups_strcasecmp(value
, constptr
->option
->defchoice
) &&
440 (test
= ppd_test_constraints(ppd
, constptr
->option
->keyword
,
441 constptr
->option
->defchoice
,
442 num_newopts
, newopts
,
443 _PPD_OPTION_CONSTRAINTS
)) == NULL
)
449 num_newopts
= cupsAddOption(constptr
->option
->keyword
,
450 constptr
->option
->defchoice
,
451 num_newopts
, &newopts
);
457 * Try each choice instead...
460 for (j
= constptr
->option
->num_choices
,
461 cptr
= constptr
->option
->choices
;
465 cupsArrayDelete(test
);
468 if (_cups_strcasecmp(value
, cptr
->choice
) &&
469 _cups_strcasecmp(constptr
->option
->defchoice
, cptr
->choice
) &&
470 _cups_strcasecmp("Custom", cptr
->choice
) &&
471 (test
= ppd_test_constraints(ppd
, constptr
->option
->keyword
,
472 cptr
->choice
, num_newopts
,
474 _PPD_OPTION_CONSTRAINTS
)) == NULL
)
477 * This choice works...
480 num_newopts
= cupsAddOption(constptr
->option
->keyword
,
481 cptr
->choice
, num_newopts
,
488 cupsArrayDelete(test
);
496 DEBUG_puts("1cupsResolveConflicts: Unable to automatically resolve "
501 cupsArrayClear(pass
);
502 cupsArrayDelete(active
);
510 * Free the caller's option array...
513 cupsFreeOptions(*num_options
, *options
);
516 * If Collate is the option we are testing, add it here. Otherwise, remove
517 * any Collate option from the resolve list since the filters automatically
518 * handle manual collation...
521 if (option
&& !_cups_strcasecmp(option
, "Collate"))
522 num_newopts
= cupsAddOption(option
, choice
, num_newopts
, &newopts
);
524 num_newopts
= cupsRemoveOption("Collate", num_newopts
, &newopts
);
527 * Return the new list of options to the caller...
530 *num_options
= num_newopts
;
533 cupsArrayDelete(pass
);
534 cupsArrayDelete(resolvers
);
536 cupsArrayRestore(ppd
->sorted_attrs
);
538 DEBUG_printf(("1cupsResolveConflicts: Returning %d options:", num_newopts
));
540 for (i
= 0; i
< num_newopts
; i
++)
541 DEBUG_printf(("1cupsResolveConflicts: options[%d]: %s=%s", i
,
542 newopts
[i
].name
, newopts
[i
].value
));
548 * If we get here, we failed to resolve...
553 cupsFreeOptions(num_newopts
, newopts
);
555 cupsArrayDelete(active
);
556 cupsArrayDelete(pass
);
557 cupsArrayDelete(resolvers
);
559 cupsArrayRestore(ppd
->sorted_attrs
);
561 DEBUG_puts("1cupsResolveConflicts: Unable to resolve conflicts!");
568 * 'ppdConflicts()' - Check to see if there are any conflicts among the
569 * marked option choices.
571 * The returned value is the same as returned by @link ppdMarkOption@.
574 int /* O - Number of conflicts found */
575 ppdConflicts(ppd_file_t
*ppd
) /* I - PPD to check */
577 int i
, /* Looping variable */
578 conflicts
; /* Number of conflicts */
579 cups_array_t
*active
; /* Active conflicts */
580 _ppd_cups_uiconsts_t
*c
; /* Current constraints */
581 _ppd_cups_uiconst_t
*cptr
; /* Current constraint */
582 ppd_option_t
*o
; /* Current option */
589 * Clear all conflicts...
592 cupsArraySave(ppd
->options
);
594 for (o
= ppdFirstOption(ppd
); o
; o
= ppdNextOption(ppd
))
597 cupsArrayRestore(ppd
->options
);
600 * Test for conflicts...
603 active
= ppd_test_constraints(ppd
, NULL
, NULL
, 0, NULL
,
604 _PPD_ALL_CONSTRAINTS
);
605 conflicts
= cupsArrayCount(active
);
608 * Loop through all of the UI constraints and flag any options
612 for (c
= (_ppd_cups_uiconsts_t
*)cupsArrayFirst(active
);
614 c
= (_ppd_cups_uiconsts_t
*)cupsArrayNext(active
))
616 for (i
= c
->num_constraints
, cptr
= c
->constraints
;
619 cptr
->option
->conflicted
= 1;
622 cupsArrayDelete(active
);
625 * Return the number of conflicts found...
633 * 'ppdInstallableConflict()' - Test whether an option choice conflicts with
634 * an installable option.
636 * This function tests whether a particular option choice is available based
637 * on constraints against options in the "InstallableOptions" group.
639 * @since CUPS 1.4/OS X 10.6@
642 int /* O - 1 if conflicting, 0 if not conflicting */
643 ppdInstallableConflict(
644 ppd_file_t
*ppd
, /* I - PPD file */
645 const char *option
, /* I - Option */
646 const char *choice
) /* I - Choice */
648 cups_array_t
*active
; /* Active conflicts */
651 DEBUG_printf(("2ppdInstallableConflict(ppd=%p, option=\"%s\", choice=\"%s\")",
652 ppd
, option
, choice
));
655 * Range check input...
658 if (!ppd
|| !option
|| !choice
)
662 * Test constraints using the new option...
665 active
= ppd_test_constraints(ppd
, option
, choice
, 0, NULL
,
666 _PPD_INSTALLABLE_CONSTRAINTS
);
668 cupsArrayDelete(active
);
670 return (active
!= NULL
);
675 * 'ppd_is_installable()' - Determine whether an option is in the
676 * InstallableOptions group.
679 static int /* O - 1 if installable, 0 if normal */
681 ppd_group_t
*installable
, /* I - InstallableOptions group */
682 const char *name
) /* I - Option name */
686 int i
; /* Looping var */
687 ppd_option_t
*option
; /* Current option */
690 for (i
= installable
->num_options
, option
= installable
->options
;
693 if (!_cups_strcasecmp(option
->keyword
, name
))
702 * 'ppd_load_constraints()' - Load constraints from a PPD file.
706 ppd_load_constraints(ppd_file_t
*ppd
) /* I - PPD file */
708 int i
; /* Looping var */
709 ppd_const_t
*oldconst
; /* Current UIConstraints data */
710 ppd_attr_t
*constattr
; /* Current cupsUIConstraints attribute */
711 _ppd_cups_uiconsts_t
*consts
; /* Current cupsUIConstraints data */
712 _ppd_cups_uiconst_t
*constptr
; /* Current constraint */
713 ppd_group_t
*installable
; /* Installable options group */
714 const char *vptr
; /* Pointer into constraint value */
715 char option
[PPD_MAX_NAME
], /* Option name/MainKeyword */
716 choice
[PPD_MAX_NAME
], /* Choice/OptionKeyword */
717 *ptr
; /* Pointer into option or choice */
720 DEBUG_printf(("7ppd_load_constraints(ppd=%p)", ppd
));
723 * Create an array to hold the constraint data...
726 ppd
->cups_uiconstraints
= cupsArrayNew(NULL
, NULL
);
729 * Find the installable options group if it exists...
732 for (i
= ppd
->num_groups
, installable
= ppd
->groups
;
734 i
--, installable
++)
735 if (!_cups_strcasecmp(installable
->name
, "InstallableOptions"))
742 * Load old-style [Non]UIConstraints data...
745 for (i
= ppd
->num_consts
, oldconst
= ppd
->consts
; i
> 0; i
--, oldconst
++)
748 * Weed out nearby duplicates, since the PPD spec requires that you
749 * define both "*Foo foo *Bar bar" and "*Bar bar *Foo foo"...
753 !_cups_strcasecmp(oldconst
[0].option1
, oldconst
[1].option2
) &&
754 !_cups_strcasecmp(oldconst
[0].choice1
, oldconst
[1].choice2
) &&
755 !_cups_strcasecmp(oldconst
[0].option2
, oldconst
[1].option1
) &&
756 !_cups_strcasecmp(oldconst
[0].choice2
, oldconst
[1].choice1
))
763 if ((consts
= calloc(1, sizeof(_ppd_cups_uiconsts_t
))) == NULL
)
765 DEBUG_puts("8ppd_load_constraints: Unable to allocate memory for "
770 if ((constptr
= calloc(2, sizeof(_ppd_cups_uiconst_t
))) == NULL
)
773 DEBUG_puts("8ppd_load_constraints: Unable to allocate memory for "
779 * Fill in the information...
782 consts
->num_constraints
= 2;
783 consts
->constraints
= constptr
;
785 if (!_cups_strncasecmp(oldconst
->option1
, "Custom", 6) &&
786 !_cups_strcasecmp(oldconst
->choice1
, "True"))
788 constptr
[0].option
= ppdFindOption(ppd
, oldconst
->option1
+ 6);
789 constptr
[0].choice
= ppdFindChoice(constptr
[0].option
, "Custom");
790 constptr
[0].installable
= 0;
794 constptr
[0].option
= ppdFindOption(ppd
, oldconst
->option1
);
795 constptr
[0].choice
= ppdFindChoice(constptr
[0].option
,
797 constptr
[0].installable
= ppd_is_installable(installable
,
801 if (!constptr
[0].option
|| (!constptr
[0].choice
&& oldconst
->choice1
[0]))
803 DEBUG_printf(("8ppd_load_constraints: Unknown option *%s %s!",
804 oldconst
->option1
, oldconst
->choice1
));
805 free(consts
->constraints
);
810 if (!_cups_strncasecmp(oldconst
->option2
, "Custom", 6) &&
811 !_cups_strcasecmp(oldconst
->choice2
, "True"))
813 constptr
[1].option
= ppdFindOption(ppd
, oldconst
->option2
+ 6);
814 constptr
[1].choice
= ppdFindChoice(constptr
[1].option
, "Custom");
815 constptr
[1].installable
= 0;
819 constptr
[1].option
= ppdFindOption(ppd
, oldconst
->option2
);
820 constptr
[1].choice
= ppdFindChoice(constptr
[1].option
,
822 constptr
[1].installable
= ppd_is_installable(installable
,
826 if (!constptr
[1].option
|| (!constptr
[1].choice
&& oldconst
->choice2
[0]))
828 DEBUG_printf(("8ppd_load_constraints: Unknown option *%s %s!",
829 oldconst
->option2
, oldconst
->choice2
));
830 free(consts
->constraints
);
835 consts
->installable
= constptr
[0].installable
|| constptr
[1].installable
;
838 * Add it to the constraints array...
841 cupsArrayAdd(ppd
->cups_uiconstraints
, consts
);
845 * Then load new-style constraints...
848 for (constattr
= ppdFindAttr(ppd
, "cupsUIConstraints", NULL
);
850 constattr
= ppdFindNextAttr(ppd
, "cupsUIConstraints", NULL
))
852 if (!constattr
->value
)
854 DEBUG_puts("8ppd_load_constraints: Bad cupsUIConstraints value!");
858 for (i
= 0, vptr
= strchr(constattr
->value
, '*');
860 i
++, vptr
= strchr(vptr
+ 1, '*'));
864 DEBUG_puts("8ppd_load_constraints: Bad cupsUIConstraints value!");
868 if ((consts
= calloc(1, sizeof(_ppd_cups_uiconsts_t
))) == NULL
)
870 DEBUG_puts("8ppd_load_constraints: Unable to allocate memory for "
871 "cupsUIConstraints!");
875 if ((constptr
= calloc((size_t)i
, sizeof(_ppd_cups_uiconst_t
))) == NULL
)
878 DEBUG_puts("8ppd_load_constraints: Unable to allocate memory for "
879 "cupsUIConstraints!");
883 consts
->num_constraints
= i
;
884 consts
->constraints
= constptr
;
886 strlcpy(consts
->resolver
, constattr
->spec
, sizeof(consts
->resolver
));
888 for (i
= 0, vptr
= strchr(constattr
->value
, '*');
890 i
++, vptr
= strchr(vptr
, '*'), constptr
++)
893 * Extract "*Option Choice" or just "*Option"...
896 for (vptr
++, ptr
= option
; *vptr
&& !_cups_isspace(*vptr
); vptr
++)
897 if (ptr
< (option
+ sizeof(option
) - 1))
902 while (_cups_isspace(*vptr
))
909 for (ptr
= choice
; *vptr
&& !_cups_isspace(*vptr
); vptr
++)
910 if (ptr
< (choice
+ sizeof(choice
) - 1))
916 if (!_cups_strncasecmp(option
, "Custom", 6) && !_cups_strcasecmp(choice
, "True"))
918 _cups_strcpy(option
, option
+ 6);
919 strlcpy(choice
, "Custom", sizeof(choice
));
922 constptr
->option
= ppdFindOption(ppd
, option
);
923 constptr
->choice
= ppdFindChoice(constptr
->option
, choice
);
924 constptr
->installable
= ppd_is_installable(installable
, option
);
925 consts
->installable
|= constptr
->installable
;
927 if (!constptr
->option
|| (!constptr
->choice
&& choice
[0]))
929 DEBUG_printf(("8ppd_load_constraints: Unknown option *%s %s!",
936 cupsArrayAdd(ppd
->cups_uiconstraints
, consts
);
939 free(consts
->constraints
);
947 * 'ppd_test_constraints()' - See if any constraints are active.
950 static cups_array_t
* /* O - Array of active constraints */
951 ppd_test_constraints(
952 ppd_file_t
*ppd
, /* I - PPD file */
953 const char *option
, /* I - Current option */
954 const char *choice
, /* I - Current choice */
955 int num_options
, /* I - Number of additional options */
956 cups_option_t
*options
, /* I - Additional options */
957 int which
) /* I - Which constraints to test */
959 int i
; /* Looping var */
960 _ppd_cups_uiconsts_t
*consts
; /* Current constraints */
961 _ppd_cups_uiconst_t
*constptr
; /* Current constraint */
962 ppd_choice_t key
, /* Search key */
963 *marked
; /* Marked choice */
964 cups_array_t
*active
= NULL
; /* Active constraints */
965 const char *value
, /* Current value */
966 *firstvalue
; /* AP_FIRSTPAGE_Keyword value */
967 char firstpage
[255]; /* AP_FIRSTPAGE_Keyword string */
970 DEBUG_printf(("7ppd_test_constraints(ppd=%p, option=\"%s\", choice=\"%s\", "
971 "num_options=%d, options=%p, which=%d)", ppd
, option
, choice
,
972 num_options
, options
, which
));
974 if (!ppd
->cups_uiconstraints
)
975 ppd_load_constraints(ppd
);
977 DEBUG_printf(("9ppd_test_constraints: %d constraints!",
978 cupsArrayCount(ppd
->cups_uiconstraints
)));
980 cupsArraySave(ppd
->marked
);
982 for (consts
= (_ppd_cups_uiconsts_t
*)cupsArrayFirst(ppd
->cups_uiconstraints
);
984 consts
= (_ppd_cups_uiconsts_t
*)cupsArrayNext(ppd
->cups_uiconstraints
))
986 DEBUG_printf(("9ppd_test_constraints: installable=%d, resolver=\"%s\", "
987 "num_constraints=%d option1=\"%s\", choice1=\"%s\", "
988 "option2=\"%s\", choice2=\"%s\", ...",
989 consts
->installable
, consts
->resolver
, consts
->num_constraints
,
990 consts
->constraints
[0].option
->keyword
,
991 consts
->constraints
[0].choice
?
992 consts
->constraints
[0].choice
->choice
: "",
993 consts
->constraints
[1].option
->keyword
,
994 consts
->constraints
[1].choice
?
995 consts
->constraints
[1].choice
->choice
: ""));
997 if (consts
->installable
&& which
< _PPD_INSTALLABLE_CONSTRAINTS
)
998 continue; /* Skip installable option constraint */
1000 if (!consts
->installable
&& which
== _PPD_INSTALLABLE_CONSTRAINTS
)
1001 continue; /* Skip non-installable option constraint */
1003 if (which
== _PPD_OPTION_CONSTRAINTS
&& option
)
1006 * Skip constraints that do not involve the current option...
1009 for (i
= consts
->num_constraints
, constptr
= consts
->constraints
;
1013 if (!_cups_strcasecmp(constptr
->option
->keyword
, option
))
1016 if (!_cups_strncasecmp(option
, "AP_FIRSTPAGE_", 13) &&
1017 !_cups_strcasecmp(constptr
->option
->keyword
, option
+ 13))
1025 DEBUG_puts("9ppd_test_constraints: Testing...");
1027 for (i
= consts
->num_constraints
, constptr
= consts
->constraints
;
1031 DEBUG_printf(("9ppd_test_constraints: %s=%s?", constptr
->option
->keyword
,
1032 constptr
->choice
? constptr
->choice
->choice
: ""));
1034 if (constptr
->choice
&&
1035 (!_cups_strcasecmp(constptr
->option
->keyword
, "PageSize") ||
1036 !_cups_strcasecmp(constptr
->option
->keyword
, "PageRegion")))
1039 * PageSize and PageRegion are used depending on the selected input slot
1040 * and manual feed mode. Validate against the selected page size instead
1041 * of an individual option...
1044 if (option
&& choice
&&
1045 (!_cups_strcasecmp(option
, "PageSize") ||
1046 !_cups_strcasecmp(option
, "PageRegion")))
1050 else if ((value
= cupsGetOption("PageSize", num_options
,
1052 if ((value
= cupsGetOption("PageRegion", num_options
,
1054 if ((value
= cupsGetOption("media", num_options
, options
)) == NULL
)
1056 ppd_size_t
*size
= ppdPageSize(ppd
, NULL
);
1062 if (value
&& !_cups_strncasecmp(value
, "Custom.", 7))
1065 if (option
&& choice
&&
1066 (!_cups_strcasecmp(option
, "AP_FIRSTPAGE_PageSize") ||
1067 !_cups_strcasecmp(option
, "AP_FIRSTPAGE_PageRegion")))
1069 firstvalue
= choice
;
1071 else if ((firstvalue
= cupsGetOption("AP_FIRSTPAGE_PageSize",
1072 num_options
, options
)) == NULL
)
1073 firstvalue
= cupsGetOption("AP_FIRSTPAGE_PageRegion", num_options
,
1076 if (firstvalue
&& !_cups_strncasecmp(firstvalue
, "Custom.", 7))
1077 firstvalue
= "Custom";
1079 if ((!value
|| _cups_strcasecmp(value
, constptr
->choice
->choice
)) &&
1080 (!firstvalue
|| _cups_strcasecmp(firstvalue
, constptr
->choice
->choice
)))
1082 DEBUG_puts("9ppd_test_constraints: NO");
1086 else if (constptr
->choice
)
1089 * Compare against the constrained choice...
1092 if (option
&& choice
&& !_cups_strcasecmp(option
, constptr
->option
->keyword
))
1094 if (!_cups_strncasecmp(choice
, "Custom.", 7))
1099 else if ((value
= cupsGetOption(constptr
->option
->keyword
, num_options
,
1102 if (!_cups_strncasecmp(value
, "Custom.", 7))
1105 else if (constptr
->choice
->marked
)
1106 value
= constptr
->choice
->choice
;
1111 * Now check AP_FIRSTPAGE_option...
1114 snprintf(firstpage
, sizeof(firstpage
), "AP_FIRSTPAGE_%s",
1115 constptr
->option
->keyword
);
1117 if (option
&& choice
&& !_cups_strcasecmp(option
, firstpage
))
1119 if (!_cups_strncasecmp(choice
, "Custom.", 7))
1120 firstvalue
= "Custom";
1122 firstvalue
= choice
;
1124 else if ((firstvalue
= cupsGetOption(firstpage
, num_options
,
1127 if (!_cups_strncasecmp(firstvalue
, "Custom.", 7))
1128 firstvalue
= "Custom";
1133 DEBUG_printf(("9ppd_test_constraints: value=%s, firstvalue=%s", value
,
1136 if ((!value
|| _cups_strcasecmp(value
, constptr
->choice
->choice
)) &&
1137 (!firstvalue
|| _cups_strcasecmp(firstvalue
, constptr
->choice
->choice
)))
1139 DEBUG_puts("9ppd_test_constraints: NO");
1143 else if (option
&& choice
&&
1144 !_cups_strcasecmp(option
, constptr
->option
->keyword
))
1146 if (!_cups_strcasecmp(choice
, "None") || !_cups_strcasecmp(choice
, "Off") ||
1147 !_cups_strcasecmp(choice
, "False"))
1149 DEBUG_puts("9ppd_test_constraints: NO");
1153 else if ((value
= cupsGetOption(constptr
->option
->keyword
, num_options
,
1156 if (!_cups_strcasecmp(value
, "None") || !_cups_strcasecmp(value
, "Off") ||
1157 !_cups_strcasecmp(value
, "False"))
1159 DEBUG_puts("9ppd_test_constraints: NO");
1165 key
.option
= constptr
->option
;
1167 if ((marked
= (ppd_choice_t
*)cupsArrayFind(ppd
->marked
, &key
))
1169 (!_cups_strcasecmp(marked
->choice
, "None") ||
1170 !_cups_strcasecmp(marked
->choice
, "Off") ||
1171 !_cups_strcasecmp(marked
->choice
, "False")))
1173 DEBUG_puts("9ppd_test_constraints: NO");
1182 active
= cupsArrayNew(NULL
, NULL
);
1184 cupsArrayAdd(active
, consts
);
1185 DEBUG_puts("9ppd_test_constraints: Added...");
1189 cupsArrayRestore(ppd
->marked
);
1191 DEBUG_printf(("8ppd_test_constraints: Found %d active constraints!",
1192 cupsArrayCount(active
)));