4 * Option marking routines for the Common UNIX Printing System (CUPS).
6 * Copyright 2007-2009 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 * cupsGetConflicts() - Get a list of conflicting options in a marked
23 * cupsResolveConflicts() - Resolve conflicts in a marked PPD.
24 * ppdConflicts() - Check to see if there are any conflicts among
25 * the marked option choices.
26 * ppdInstallableConflict() - Test whether an option choice conflicts with an
28 * ppd_is_installable() - Determine whether an option is in the
29 * InstallableOptions group.
30 * ppd_load_constraints() - Load constraints from a PPD file.
31 * ppd_test_constraints() - See if any constraints are active.
35 * Include necessary headers...
38 #include "ppd-private.h"
49 _PPD_NORMAL_CONSTRAINTS
,
50 _PPD_OPTION_CONSTRAINTS
,
51 _PPD_INSTALLABLE_CONSTRAINTS
,
60 static int ppd_is_installable(ppd_group_t
*installable
,
62 static void ppd_load_constraints(ppd_file_t
*ppd
);
63 static cups_array_t
*ppd_test_constraints(ppd_file_t
*ppd
,
67 cups_option_t
*options
,
72 * 'cupsGetConflicts()' - Get a list of conflicting options in a marked PPD.
74 * This function gets a list of options that would conflict if "option" and
75 * "choice" were marked in the PPD. You would typically call this function
76 * after marking the currently selected options in the PPD in order to
77 * determine whether a new option selection would cause a conflict.
79 * The number of conflicting options are returned with "options" pointing to
80 * the conflicting options. The returned option array must be freed using
81 * @link cupsFreeOptions@.
83 * @since CUPS 1.4/Mac OS X 10.6@
86 int /* O - Number of conflicting options */
88 ppd_file_t
*ppd
, /* I - PPD file */
89 const char *option
, /* I - Option to test */
90 const char *choice
, /* I - Choice to test */
91 cups_option_t
**options
) /* O - Conflicting options */
93 int i
, /* Looping var */
94 num_options
; /* Number of conflicting options */
95 cups_array_t
*active
; /* Active conflicts */
96 _ppd_cups_uiconsts_t
*c
; /* Current constraints */
97 _ppd_cups_uiconst_t
*cptr
; /* Current constraint */
101 * Range check input...
107 if (!ppd
|| !option
|| !choice
|| !options
)
111 * Test for conflicts...
114 active
= ppd_test_constraints(ppd
, option
, choice
, 0, NULL
,
115 _PPD_ALL_CONSTRAINTS
);
118 * Loop through all of the UI constraints and add any options that conflict...
121 for (num_options
= 0, c
= (_ppd_cups_uiconsts_t
*)cupsArrayFirst(active
);
123 c
= (_ppd_cups_uiconsts_t
*)cupsArrayNext(active
))
125 for (i
= c
->num_constraints
, cptr
= c
->constraints
;
128 if (strcasecmp(cptr
->option
->keyword
, option
))
129 num_options
= cupsAddOption(cptr
->option
->keyword
, cptr
->choice
->choice
,
130 num_options
, options
);
133 cupsArrayDelete(active
);
135 return (num_options
);
140 * 'cupsResolveConflicts()' - Resolve conflicts in a marked PPD.
142 * This function attempts to resolve any conflicts in a marked PPD, returning
143 * a list of option changes that are required to resolve them. On input,
144 * "num_options" and "options" contain any pending option changes that have
145 * not yet been marked, while "option" and "choice" contain the most recent
146 * selection which may or may not be in "num_options" or "options".
148 * On successful return, "num_options" and "options" are updated to contain
149 * "option" and "choice" along with any changes required to resolve conflicts
150 * specified in the PPD file and 1 is returned.
152 * If option conflicts cannot be resolved, "num_options" and "options" are not
153 * changed and 0 is returned.
155 * When resolving conflicts, @code cupsResolveConflicts@ does not consider
156 * changes to the current page size (@code media@, @code PageSize@, and
157 * @code PageRegion@) or to the most recent option specified in "option".
158 * Thus, if the only way to resolve a conflict is to change the page size
159 * or the option the user most recently changed, @code cupsResolveConflicts@
160 * will return 0 to indicate it was unable to resolve the conflicts.
162 * The @code cupsResolveConflicts@ function uses one of two sources of option
163 * constraint information. The preferred constraint information is defined by
164 * @code cupsUIConstraints@ and @code cupsUIResolver@ attributes - in this
165 * case, the PPD file provides constraint resolution actions.
167 * The backup constraint information is defined by the
168 * @code UIConstraints@ and @code NonUIConstraints@ attributes. These
169 * constraints are resolved algorithmically by first selecting the default
170 * choice for the conflicting option, then iterating over all possible choices
171 * until a non-conflicting option choice is found.
173 * @since CUPS 1.4/Mac OS X 10.6@
176 int /* O - 1 on success, 0 on failure */
177 cupsResolveConflicts(
178 ppd_file_t
*ppd
, /* I - PPD file */
179 const char *option
, /* I - Newly selected option or @code NULL@ for none */
180 const char *choice
, /* I - Newly selected choice or @code NULL@ for none */
181 int *num_options
, /* IO - Number of additional selected options */
182 cups_option_t
**options
) /* IO - Additional selected options */
184 int i
, /* Looping var */
185 num_newopts
; /* Number of new options */
186 cups_option_t
*newopts
; /* New options */
187 cups_array_t
*active
, /* Active constraints */
188 *pass
, /* Resolvers for this pass */
189 *resolvers
, /* Resolvers we have used */
190 *test
; /* Test array for conflicts */
191 _ppd_cups_uiconsts_t
*consts
; /* Current constraints */
192 _ppd_cups_uiconst_t
*constptr
; /* Current constraint */
193 ppd_attr_t
*resolver
; /* Current resolver */
194 const char *resval
; /* Pointer into resolver value */
195 char resoption
[PPD_MAX_NAME
],
196 /* Current resolver option */
197 reschoice
[PPD_MAX_NAME
],
198 /* Current resolver choice */
199 *resptr
; /* Pointer into option/choice */
200 const char *value
; /* Selected option value */
201 int changed
; /* Did we change anything? */
202 ppd_choice_t
*marked
; /* Marked choice */
206 * Range check input...
209 if (!ppd
|| !num_options
|| !options
|| (option
== NULL
) != (choice
== NULL
))
213 * Build a shadow option array...
219 for (i
= 0; i
< *num_options
; i
++)
220 num_newopts
= cupsAddOption((*options
)[i
].name
, (*options
)[i
].value
,
221 num_newopts
, &newopts
);
222 if (option
&& strcasecmp(option
, "Collate"))
223 num_newopts
= cupsAddOption(option
, choice
, num_newopts
, &newopts
);
226 * Loop until we have no conflicts...
229 cupsArraySave(ppd
->sorted_attrs
);
232 pass
= cupsArrayNew((cups_array_func_t
)strcasecmp
, NULL
);
234 while ((active
= ppd_test_constraints(ppd
, NULL
, NULL
, num_newopts
, newopts
,
235 _PPD_ALL_CONSTRAINTS
)) != NULL
)
238 resolvers
= cupsArrayNew((cups_array_func_t
)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(("1ppdResolveConflicts: Resolver loop with %s!",
264 if ((resolver
= ppdFindAttr(ppd
, "cupsUIResolver",
265 consts
->resolver
)) == NULL
)
267 DEBUG_printf(("1ppdResolveConflicts: Resolver %s not found!",
272 if (!resolver
->value
)
274 DEBUG_printf(("1ppdResolveConflicts: 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 (isspace(*resval
& 255))
294 for (resval
++, resptr
= resoption
;
295 *resval
&& !isspace(*resval
& 255);
297 if (resptr
< (resoption
+ sizeof(resoption
) - 1))
302 while (isspace(*resval
& 255))
305 for (resptr
= reschoice
;
306 *resval
&& !isspace(*resval
& 255);
308 if (resptr
< (reschoice
+ sizeof(reschoice
) - 1))
313 if (!resoption
[0] || !reschoice
[0])
317 * Is this the option we are changing?
321 (!strcasecmp(resoption
, option
) ||
322 (!strcasecmp(option
, "PageSize") &&
323 !strcasecmp(resoption
, "PageRegion")) ||
324 (!strcasecmp(option
, "PageRegion") &&
325 !strcasecmp(resoption
, "PageSize"))))
332 if ((test
= ppd_test_constraints(ppd
, resoption
, reschoice
,
333 num_newopts
, newopts
,
334 _PPD_ALL_CONSTRAINTS
)) == NULL
)
343 cupsArrayDelete(test
);
346 * Add the option/choice from the resolver regardless of whether it
347 * worked; this makes sure that we can cascade several changes to
348 * make things resolve...
351 num_newopts
= cupsAddOption(resoption
, reschoice
, num_newopts
,
358 * Try resolving by choosing the default values for non-installable
359 * options, then by iterating through the possible choices...
362 int j
; /* Looping var */
363 ppd_choice_t
*cptr
; /* Current choice */
364 ppd_size_t
*size
; /* Current page size */
367 for (i
= consts
->num_constraints
, constptr
= consts
->constraints
;
372 * Can't resolve by changing an installable option...
375 if (constptr
->installable
)
379 * Is this the option we are changing?
383 (!strcasecmp(constptr
->option
->keyword
, option
) ||
384 (!strcasecmp(option
, "PageSize") &&
385 !strcasecmp(constptr
->option
->keyword
, "PageRegion")) ||
386 (!strcasecmp(option
, "PageRegion") &&
387 !strcasecmp(constptr
->option
->keyword
, "PageSize"))))
391 * Get the current option choice...
394 if ((value
= cupsGetOption(constptr
->option
->keyword
, num_newopts
,
397 if (!strcasecmp(constptr
->option
->keyword
, "PageSize") ||
398 !strcasecmp(constptr
->option
->keyword
, "PageRegion"))
400 if ((value
= cupsGetOption("PageSize", num_newopts
,
402 value
= cupsGetOption("PageRegion", num_newopts
, newopts
);
406 if ((size
= ppdPageSize(ppd
, NULL
)) != NULL
)
414 marked
= ppdFindMarkedChoice(ppd
, constptr
->option
->keyword
);
415 value
= marked
? marked
->choice
: "";
419 if (!strncasecmp(value
, "Custom.", 7))
423 * Try the default choice...
428 if (strcasecmp(value
, constptr
->option
->defchoice
) &&
429 (test
= ppd_test_constraints(ppd
, constptr
->option
->keyword
,
430 constptr
->option
->defchoice
,
431 num_newopts
, newopts
,
432 _PPD_OPTION_CONSTRAINTS
)) == NULL
)
438 num_newopts
= cupsAddOption(constptr
->option
->keyword
,
439 constptr
->option
->defchoice
,
440 num_newopts
, &newopts
);
446 * Try each choice instead...
449 for (j
= constptr
->option
->num_choices
,
450 cptr
= constptr
->option
->choices
;
454 cupsArrayDelete(test
);
457 if (strcasecmp(value
, cptr
->choice
) &&
458 strcasecmp(constptr
->option
->defchoice
, cptr
->choice
) &&
459 strcasecmp("Custom", cptr
->choice
) &&
460 (test
= ppd_test_constraints(ppd
, constptr
->option
->keyword
,
461 cptr
->choice
, num_newopts
,
463 _PPD_OPTION_CONSTRAINTS
)) == NULL
)
466 * This choice works...
469 num_newopts
= cupsAddOption(constptr
->option
->keyword
,
470 cptr
->choice
, num_newopts
,
477 cupsArrayDelete(test
);
484 DEBUG_puts("1ppdResolveConflicts: Unable to automatically resolve "
490 cupsArrayClear(pass
);
491 cupsArrayDelete(active
);
495 * Free the caller's option array...
498 cupsFreeOptions(*num_options
, *options
);
501 * If Collate is the option we are testing, add it here. Otherwise, remove
502 * any Collate option from the resolve list since the filters automatically
503 * handle manual collation...
506 if (option
&& !strcasecmp(option
, "Collate"))
507 num_newopts
= cupsAddOption(option
, choice
, num_newopts
, &newopts
);
509 num_newopts
= cupsRemoveOption("Collate", num_newopts
, &newopts
);
512 * Return the new list of options to the caller...
515 *num_options
= num_newopts
;
518 cupsArrayDelete(pass
);
519 cupsArrayDelete(resolvers
);
521 cupsArrayRestore(ppd
->sorted_attrs
);
523 DEBUG_printf(("1cupsResolveConflicts: Returning %d options:", num_newopts
));
525 for (i
= 0; i
< num_newopts
; i
++)
526 DEBUG_printf(("1cupsResolveConflicts: options[%d]: %s=%s", i
,
527 newopts
[i
].name
, newopts
[i
].value
));
533 * If we get here, we failed to resolve...
538 cupsFreeOptions(num_newopts
, newopts
);
540 cupsArrayDelete(active
);
541 cupsArrayDelete(pass
);
542 cupsArrayDelete(resolvers
);
544 cupsArrayRestore(ppd
->sorted_attrs
);
546 DEBUG_puts("1cupsResolveConflicts: Unable to resolve conflicts!");
553 * 'ppdConflicts()' - Check to see if there are any conflicts among the
554 * marked option choices.
556 * The returned value is the same as returned by @link ppdMarkOption@.
559 int /* O - Number of conflicts found */
560 ppdConflicts(ppd_file_t
*ppd
) /* I - PPD to check */
562 int i
, /* Looping variable */
563 conflicts
; /* Number of conflicts */
564 cups_array_t
*active
; /* Active conflicts */
565 _ppd_cups_uiconsts_t
*c
; /* Current constraints */
566 _ppd_cups_uiconst_t
*cptr
; /* Current constraint */
567 ppd_option_t
*o
; /* Current option */
574 * Clear all conflicts...
577 for (o
= ppdFirstOption(ppd
); o
; o
= ppdNextOption(ppd
))
581 * Test for conflicts...
584 active
= ppd_test_constraints(ppd
, NULL
, NULL
, 0, NULL
,
585 _PPD_ALL_CONSTRAINTS
);
586 conflicts
= cupsArrayCount(active
);
589 * Loop through all of the UI constraints and flag any options
593 for (c
= (_ppd_cups_uiconsts_t
*)cupsArrayFirst(active
);
595 c
= (_ppd_cups_uiconsts_t
*)cupsArrayNext(active
))
597 for (i
= c
->num_constraints
, cptr
= c
->constraints
;
600 cptr
->option
->conflicted
= 1;
603 cupsArrayDelete(active
);
606 * Return the number of conflicts found...
614 * 'ppdInstallableConflict()' - Test whether an option choice conflicts with
615 * an installable option.
617 * This function tests whether a particular option choice is available based
618 * on constraints against options in the "InstallableOptions" group.
620 * @since CUPS 1.4/Mac OS X 10.6@
623 int /* O - 1 if conflicting, 0 if not conflicting */
624 ppdInstallableConflict(
625 ppd_file_t
*ppd
, /* I - PPD file */
626 const char *option
, /* I - Option */
627 const char *choice
) /* I - Choice */
629 cups_array_t
*active
; /* Active conflicts */
632 DEBUG_printf(("2ppdInstallableConflict(ppd=%p, option=\"%s\", choice=\"%s\")",
633 ppd
, option
, choice
));
636 * Range check input...
639 if (!ppd
|| !option
|| !choice
)
643 * Test constraints using the new option...
646 active
= ppd_test_constraints(ppd
, option
, choice
, 0, NULL
,
647 _PPD_INSTALLABLE_CONSTRAINTS
);
649 cupsArrayDelete(active
);
651 return (active
!= NULL
);
656 * 'ppd_is_installable()' - Determine whether an option is in the
657 * InstallableOptions group.
660 static int /* O - 1 if installable, 0 if normal */
662 ppd_group_t
*installable
, /* I - InstallableOptions group */
663 const char *name
) /* I - Option name */
667 int i
; /* Looping var */
668 ppd_option_t
*option
; /* Current option */
671 for (i
= installable
->num_options
, option
= installable
->options
;
674 if (!strcasecmp(option
->keyword
, name
))
683 * 'ppd_load_constraints()' - Load constraints from a PPD file.
687 ppd_load_constraints(ppd_file_t
*ppd
) /* I - PPD file */
689 int i
; /* Looping var */
690 ppd_const_t
*oldconst
; /* Current UIConstraints data */
691 ppd_attr_t
*constattr
; /* Current cupsUIConstraints attribute */
692 _ppd_cups_uiconsts_t
*consts
; /* Current cupsUIConstraints data */
693 _ppd_cups_uiconst_t
*constptr
; /* Current constraint */
694 ppd_group_t
*installable
; /* Installable options group */
695 const char *vptr
; /* Pointer into constraint value */
696 char option
[PPD_MAX_NAME
], /* Option name/MainKeyword */
697 choice
[PPD_MAX_NAME
], /* Choice/OptionKeyword */
698 *ptr
; /* Pointer into option or choice */
701 DEBUG_printf(("7ppd_load_constraints(ppd=%p)", ppd
));
704 * Create an array to hold the constraint data...
707 ppd
->cups_uiconstraints
= cupsArrayNew(NULL
, NULL
);
710 * Find the installable options group if it exists...
713 for (i
= ppd
->num_groups
, installable
= ppd
->groups
;
715 i
--, installable
++)
716 if (!strcasecmp(installable
->name
, "InstallableOptions"))
723 * Load old-style [Non]UIConstraints data...
726 for (i
= ppd
->num_consts
, oldconst
= ppd
->consts
; i
> 0; i
--, oldconst
++)
729 * Weed out nearby duplicates, since the PPD spec requires that you
730 * define both "*Foo foo *Bar bar" and "*Bar bar *Foo foo"...
734 !strcasecmp(oldconst
[0].option1
, oldconst
[1].option2
) &&
735 !strcasecmp(oldconst
[0].choice1
, oldconst
[1].choice2
) &&
736 !strcasecmp(oldconst
[0].option2
, oldconst
[1].option1
) &&
737 !strcasecmp(oldconst
[0].choice2
, oldconst
[1].choice1
))
744 if ((consts
= calloc(1, sizeof(_ppd_cups_uiconsts_t
))) == NULL
)
746 DEBUG_puts("8ppd_load_constraints: Unable to allocate memory for "
751 if ((constptr
= calloc(2, sizeof(_ppd_cups_uiconst_t
))) == NULL
)
754 DEBUG_puts("8ppd_load_constraints: Unable to allocate memory for "
760 * Fill in the information...
763 consts
->num_constraints
= 2;
764 consts
->constraints
= constptr
;
766 if (!strncasecmp(oldconst
->option1
, "Custom", 6) &&
767 !strcasecmp(oldconst
->choice1
, "True"))
769 constptr
[0].option
= ppdFindOption(ppd
, oldconst
->option1
+ 6);
770 constptr
[0].choice
= ppdFindChoice(constptr
[0].option
, "Custom");
771 constptr
[0].installable
= 0;
775 constptr
[0].option
= ppdFindOption(ppd
, oldconst
->option1
);
776 constptr
[0].choice
= ppdFindChoice(constptr
[0].option
,
778 constptr
[0].installable
= ppd_is_installable(installable
,
782 if (!constptr
[0].option
|| (!constptr
[0].choice
&& oldconst
->choice1
[0]))
784 DEBUG_printf(("8ppd_load_constraints: Unknown option *%s %s!",
785 oldconst
->option1
, oldconst
->choice1
));
786 free(consts
->constraints
);
791 if (!strncasecmp(oldconst
->option2
, "Custom", 6) &&
792 !strcasecmp(oldconst
->choice2
, "True"))
794 constptr
[1].option
= ppdFindOption(ppd
, oldconst
->option2
+ 6);
795 constptr
[1].choice
= ppdFindChoice(constptr
[1].option
, "Custom");
796 constptr
[1].installable
= 0;
800 constptr
[1].option
= ppdFindOption(ppd
, oldconst
->option2
);
801 constptr
[1].choice
= ppdFindChoice(constptr
[1].option
,
803 constptr
[1].installable
= ppd_is_installable(installable
,
807 if (!constptr
[1].option
|| (!constptr
[1].choice
&& oldconst
->choice2
[0]))
809 DEBUG_printf(("8ppd_load_constraints: Unknown option *%s %s!",
810 oldconst
->option2
, oldconst
->choice2
));
811 free(consts
->constraints
);
816 consts
->installable
= constptr
[0].installable
|| constptr
[1].installable
;
819 * Add it to the constraints array...
822 cupsArrayAdd(ppd
->cups_uiconstraints
, consts
);
826 * Then load new-style constraints...
829 for (constattr
= ppdFindAttr(ppd
, "cupsUIConstraints", NULL
);
831 constattr
= ppdFindNextAttr(ppd
, "cupsUIConstraints", NULL
))
833 if (!constattr
->value
)
835 DEBUG_puts("8ppd_load_constraints: Bad cupsUIConstraints value!");
839 for (i
= 0, vptr
= strchr(constattr
->value
, '*');
841 i
++, vptr
= strchr(vptr
+ 1, '*'));
845 DEBUG_puts("8ppd_load_constraints: Bad cupsUIConstraints value!");
849 if ((consts
= calloc(1, sizeof(_ppd_cups_uiconsts_t
))) == NULL
)
851 DEBUG_puts("8ppd_load_constraints: Unable to allocate memory for "
852 "cupsUIConstraints!");
856 if ((constptr
= calloc(i
, sizeof(_ppd_cups_uiconst_t
))) == NULL
)
859 DEBUG_puts("8ppd_load_constraints: Unable to allocate memory for "
860 "cupsUIConstraints!");
864 consts
->num_constraints
= i
;
865 consts
->constraints
= constptr
;
867 strlcpy(consts
->resolver
, constattr
->spec
, sizeof(consts
->resolver
));
869 for (i
= 0, vptr
= strchr(constattr
->value
, '*');
871 i
++, vptr
= strchr(vptr
, '*'), constptr
++)
874 * Extract "*Option Choice" or just "*Option"...
877 for (vptr
++, ptr
= option
; *vptr
&& !isspace(*vptr
& 255); vptr
++)
878 if (ptr
< (option
+ sizeof(option
) - 1))
883 while (isspace(*vptr
& 255))
890 for (ptr
= choice
; *vptr
&& !isspace(*vptr
& 255); vptr
++)
891 if (ptr
< (choice
+ sizeof(choice
) - 1))
897 if (!strncasecmp(option
, "Custom", 6) && !strcasecmp(choice
, "True"))
899 _cups_strcpy(option
, option
+ 6);
900 strcpy(choice
, "Custom");
903 constptr
->option
= ppdFindOption(ppd
, option
);
904 constptr
->choice
= ppdFindChoice(constptr
->option
, choice
);
905 constptr
->installable
= ppd_is_installable(installable
, option
);
906 consts
->installable
|= constptr
->installable
;
908 if (!constptr
->option
|| (!constptr
->choice
&& choice
[0]))
910 DEBUG_printf(("8ppd_load_constraints: Unknown option *%s %s!",
917 cupsArrayAdd(ppd
->cups_uiconstraints
, consts
);
920 free(consts
->constraints
);
928 * 'ppd_test_constraints()' - See if any constraints are active.
931 static cups_array_t
* /* O - Array of active constraints */
932 ppd_test_constraints(
933 ppd_file_t
*ppd
, /* I - PPD file */
934 const char *option
, /* I - Current option */
935 const char *choice
, /* I - Current choice */
936 int num_options
, /* I - Number of additional options */
937 cups_option_t
*options
, /* I - Additional options */
938 int which
) /* I - Which constraints to test */
940 int i
; /* Looping var */
941 _ppd_cups_uiconsts_t
*consts
; /* Current constraints */
942 _ppd_cups_uiconst_t
*constptr
; /* Current constraint */
943 ppd_choice_t key
, /* Search key */
944 *marked
; /* Marked choice */
945 cups_array_t
*active
= NULL
; /* Active constraints */
946 const char *value
; /* Current value */
949 DEBUG_printf(("7ppd_test_constraints(ppd=%p, option=\"%s\", choice=\"%s\", "
950 "num_options=%d, options=%p, which=%d)", ppd
, option
, choice
,
951 num_options
, options
, which
));
953 if (!ppd
->cups_uiconstraints
)
954 ppd_load_constraints(ppd
);
956 DEBUG_printf(("9ppd_test_constraints: %d constraints!",
957 cupsArrayCount(ppd
->cups_uiconstraints
)));
959 cupsArraySave(ppd
->marked
);
961 for (consts
= (_ppd_cups_uiconsts_t
*)cupsArrayFirst(ppd
->cups_uiconstraints
);
963 consts
= (_ppd_cups_uiconsts_t
*)cupsArrayNext(ppd
->cups_uiconstraints
))
965 DEBUG_printf(("9ppd_test_constraints: installable=%d, resolver=\"%s\", "
966 "num_constraints=%d option1=\"%s\", choice1=\"%s\", "
967 "option2=\"%s\", choice2=\"%s\", ...",
968 consts
->installable
, consts
->resolver
, consts
->num_constraints
,
969 consts
->constraints
[0].option
->keyword
,
970 consts
->constraints
[0].choice
?
971 consts
->constraints
[0].choice
->choice
: "",
972 consts
->constraints
[1].option
->keyword
,
973 consts
->constraints
[1].choice
?
974 consts
->constraints
[1].choice
->choice
: ""));
976 if (consts
->installable
&& which
< _PPD_INSTALLABLE_CONSTRAINTS
)
977 continue; /* Skip installable option constraint */
979 if (!consts
->installable
&& which
== _PPD_INSTALLABLE_CONSTRAINTS
)
980 continue; /* Skip non-installable option constraint */
982 if (which
== _PPD_OPTION_CONSTRAINTS
&& option
)
985 * Skip constraints that do not involve the current option...
988 for (i
= consts
->num_constraints
, constptr
= consts
->constraints
;
991 if (!strcasecmp(constptr
->option
->keyword
, option
))
998 DEBUG_puts("9ppd_test_constraints: Testing...");
1000 for (i
= consts
->num_constraints
, constptr
= consts
->constraints
;
1004 DEBUG_printf(("9ppd_test_constraints: %s=%s?", constptr
->option
->keyword
,
1005 constptr
->choice
? constptr
->choice
->choice
: ""));
1007 if (constptr
->choice
&&
1008 (!strcasecmp(constptr
->option
->keyword
, "PageSize") ||
1009 !strcasecmp(constptr
->option
->keyword
, "PageRegion")))
1012 * PageSize and PageRegion are used depending on the selected input slot
1013 * and manual feed mode. Validate against the selected page size instead
1014 * of an individual option...
1017 if (option
&& choice
&&
1018 (!strcasecmp(option
, "PageSize") ||
1019 !strcasecmp(option
, "PageRegion")))
1023 else if ((value
= cupsGetOption("PageSize", num_options
,
1025 if ((value
= cupsGetOption("PageRegion", num_options
,
1027 if ((value
= cupsGetOption("media", num_options
, options
)) == NULL
)
1029 ppd_size_t
*size
= ppdPageSize(ppd
, NULL
);
1035 if (value
&& !strncasecmp(value
, "Custom.", 7))
1038 if (!value
|| strcasecmp(value
, constptr
->choice
->choice
))
1040 DEBUG_puts("9ppd_test_constraints: NO");
1044 else if (constptr
->choice
)
1046 if (option
&& choice
&& !strcasecmp(option
, constptr
->option
->keyword
))
1048 if (!strncasecmp(choice
, "Custom.", 7))
1053 if (strcasecmp(value
, constptr
->choice
->choice
))
1055 DEBUG_puts("9ppd_test_constraints: NO");
1059 else if ((value
= cupsGetOption(constptr
->option
->keyword
, num_options
,
1062 if (!strncasecmp(value
, "Custom.", 7))
1065 if (strcasecmp(value
, constptr
->choice
->choice
))
1067 DEBUG_puts("9ppd_test_constraints: NO");
1071 else if (!constptr
->choice
->marked
)
1073 DEBUG_puts("9ppd_test_constraints: NO");
1077 else if (option
&& choice
&&
1078 !strcasecmp(option
, constptr
->option
->keyword
))
1080 if (!strcasecmp(choice
, "None") || !strcasecmp(choice
, "Off") ||
1081 !strcasecmp(choice
, "False"))
1083 DEBUG_puts("9ppd_test_constraints: NO");
1087 else if ((value
= cupsGetOption(constptr
->option
->keyword
, num_options
,
1090 if (!strcasecmp(value
, "None") || !strcasecmp(value
, "Off") ||
1091 !strcasecmp(value
, "False"))
1093 DEBUG_puts("9ppd_test_constraints: NO");
1099 key
.option
= constptr
->option
;
1101 if ((marked
= (ppd_choice_t
*)cupsArrayFind(ppd
->marked
, &key
))
1103 (!strcasecmp(marked
->choice
, "None") ||
1104 !strcasecmp(marked
->choice
, "Off") ||
1105 !strcasecmp(marked
->choice
, "False")))
1107 DEBUG_puts("9ppd_test_constraints: NO");
1116 active
= cupsArrayNew(NULL
, NULL
);
1118 cupsArrayAdd(active
, consts
);
1119 DEBUG_puts("9ppd_test_constraints: Added...");
1123 cupsArrayRestore(ppd
->marked
);
1125 DEBUG_printf(("8ppd_test_constraints: Found %d active constraints!",
1126 cupsArrayCount(active
)));