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_INSTALLABLE_CONSTRAINTS
,
59 static int ppd_is_installable(ppd_group_t
*installable
,
61 static void ppd_load_constraints(ppd_file_t
*ppd
);
62 static cups_array_t
*ppd_test_constraints(ppd_file_t
*ppd
,
66 cups_option_t
*options
,
71 * 'cupsGetConflicts()' - Get a list of conflicting options in a marked PPD.
73 * This function gets a list of options that would conflict if "option" and
74 * "choice" were marked in the PPD. You would typically call this function
75 * after marking the currently selected options in the PPD in order to
76 * determine whether a new option selection would cause a conflict.
78 * The number of conflicting options are returned with "options" pointing to
79 * the conflicting options. The returned option array must be freed using
80 * @link cupsFreeOptions@.
85 int /* O - Number of conflicting options */
87 ppd_file_t
*ppd
, /* I - PPD file */
88 const char *option
, /* I - Option to test */
89 const char *choice
, /* I - Choice to test */
90 cups_option_t
**options
) /* O - Conflicting options */
92 int i
, /* Looping var */
93 num_options
; /* Number of conflicting options */
94 cups_array_t
*active
; /* Active conflicts */
95 _ppd_cups_uiconsts_t
*c
; /* Current constraints */
96 _ppd_cups_uiconst_t
*cptr
; /* Current constraint */
100 * Range check input...
106 if (!ppd
|| !option
|| !choice
|| !options
)
110 * Test for conflicts...
113 active
= ppd_test_constraints(ppd
, option
, choice
, 0, NULL
,
114 _PPD_ALL_CONSTRAINTS
);
117 * Loop through all of the UI constraints and add any options that conflict...
120 for (num_options
= 0, c
= (_ppd_cups_uiconsts_t
*)cupsArrayFirst(active
);
122 c
= (_ppd_cups_uiconsts_t
*)cupsArrayNext(active
))
124 for (i
= c
->num_constraints
, cptr
= c
->constraints
;
127 if (strcasecmp(cptr
->option
->keyword
, option
))
128 num_options
= cupsAddOption(cptr
->option
->keyword
, cptr
->choice
->choice
,
129 num_options
, options
);
132 cupsArrayDelete(active
);
134 return (num_options
);
139 * 'cupsResolveConflicts()' - Resolve conflicts in a marked PPD.
141 * This function attempts to resolve any conflicts in a marked PPD, returning
142 * a list of option changes that are required to resolve them. On input,
143 * "num_options" and "options" contain any pending option changes that have
144 * not yet been marked, while "option" and "choice" contain the most recent
145 * selection which may or may not be in "num_options" or "options".
147 * On successful return, "num_options" and "options" are updated to contain
148 * "option" and "choice" along with any changes required to resolve conflicts
149 * specified in the PPD file and 1 is returned.
151 * If option conflicts cannot be resolved, "num_options" and "options" are not
152 * changed and 0 is returned.
154 * When resolving conflicts, @code cupsResolveConflicts@ does not consider
155 * changes to the current page size (@code media@, @code PageSize@, and
156 * @code PageRegion@) or to the most recent option specified in "option".
157 * Thus, if the only way to resolve a conflict is to change the page size
158 * or the option the user most recently changed, @code cupsResolveConflicts@
159 * will return 0 to indicate it was unable to resolve the conflicts.
161 * The @code cupsResolveConflicts@ function uses one of two sources of option
162 * constraint information. The preferred constraint information is defined by
163 * @code cupsUIConstraints@ and @code cupsUIResolver@ attributes - in this
164 * case, the PPD file provides constraint resolution actions.
166 * The backup constraint information is defined by the
167 * @code UIConstraints@ and @code NonUIConstraints@ attributes. These
168 * constraints are resolved algorithmically by first selecting the default
169 * choice for the conflicting option, then iterating over all possible choices
170 * until a non-conflicting option choice is found.
175 int /* O - 1 on success, 0 on failure */
176 cupsResolveConflicts(
177 ppd_file_t
*ppd
, /* I - PPD file */
178 const char *option
, /* I - Newly selected option or @code NULL@ for none */
179 const char *choice
, /* I - Newly selected choice or @code NULL@ for none */
180 int *num_options
, /* IO - Number of additional selected options */
181 cups_option_t
**options
) /* IO - Additional selected options */
183 int i
, /* Looping var */
184 num_newopts
; /* Number of new options */
185 cups_option_t
*newopts
; /* New options */
186 cups_array_t
*active
, /* Active constraints */
187 *pass
, /* Resolvers for this pass */
188 *resolvers
, /* Resolvers we have used */
189 *test
; /* Test array for conflicts */
190 _ppd_cups_uiconsts_t
*consts
; /* Current constraints */
191 _ppd_cups_uiconst_t
*constptr
; /* Current constraint */
192 ppd_attr_t
*resolver
; /* Current resolver */
193 const char *resval
; /* Pointer into resolver value */
194 char resoption
[PPD_MAX_NAME
],
195 /* Current resolver option */
196 reschoice
[PPD_MAX_NAME
],
197 /* Current resolver choice */
198 *resptr
; /* Pointer into option/choice */
199 const char *value
; /* Selected option value */
200 int changed
; /* Did we change anything? */
201 ppd_choice_t
*marked
; /* Marked choice */
205 * Range check input...
208 if (!ppd
|| !num_options
|| !options
|| (option
== NULL
) != (choice
== NULL
))
212 * Build a shadow option array...
218 for (i
= 0; i
< *num_options
; i
++)
219 num_newopts
= cupsAddOption((*options
)[i
].name
, (*options
)[i
].value
,
220 num_newopts
, &newopts
);
221 if (option
&& strcasecmp(option
, "Collate"))
222 num_newopts
= cupsAddOption(option
, choice
, num_newopts
, &newopts
);
225 * Loop until we have no conflicts...
228 cupsArraySave(ppd
->sorted_attrs
);
231 pass
= cupsArrayNew((cups_array_func_t
)strcasecmp
, NULL
);
233 while ((active
= ppd_test_constraints(ppd
, NULL
, NULL
, num_newopts
, newopts
,
234 _PPD_ALL_CONSTRAINTS
)) != NULL
)
237 resolvers
= cupsArrayNew((cups_array_func_t
)strcasecmp
, NULL
);
239 for (consts
= (_ppd_cups_uiconsts_t
*)cupsArrayFirst(active
), changed
= 0;
241 consts
= (_ppd_cups_uiconsts_t
*)cupsArrayNext(active
))
243 if (consts
->resolver
[0])
246 * Look up the resolver...
249 if (cupsArrayFind(pass
, consts
->resolver
))
250 continue; /* Already applied this resolver... */
252 if (cupsArrayFind(resolvers
, consts
->resolver
))
258 DEBUG_printf(("ppdResolveConflicts: Resolver loop with %s!\n",
263 if ((resolver
= ppdFindAttr(ppd
, "cupsUIResolver",
264 consts
->resolver
)) == NULL
)
266 DEBUG_printf(("ppdResolveConflicts: Resolver %s not found!\n",
271 if (!resolver
->value
)
273 DEBUG_printf(("ppdResolveConflicts: Resolver %s has no value!\n",
279 * Add the options from the resolver...
282 cupsArrayAdd(pass
, consts
->resolver
);
283 cupsArrayAdd(resolvers
, consts
->resolver
);
285 for (resval
= resolver
->value
; *resval
&& !changed
;)
287 while (isspace(*resval
& 255))
293 for (resval
++, resptr
= resoption
;
294 *resval
&& !isspace(*resval
& 255);
296 if (resptr
< (resoption
+ sizeof(resoption
) - 1))
301 while (isspace(*resval
& 255))
304 for (resptr
= reschoice
;
305 *resval
&& !isspace(*resval
& 255);
307 if (resptr
< (reschoice
+ sizeof(reschoice
) - 1))
312 if (!resoption
[0] || !reschoice
[0])
316 * Is this the option we are changing?
320 (!strcasecmp(resoption
, option
) ||
321 (!strcasecmp(option
, "PageSize") &&
322 !strcasecmp(resoption
, "PageRegion")) ||
323 (!strcasecmp(option
, "PageRegion") &&
324 !strcasecmp(resoption
, "PageSize"))))
331 if ((test
= ppd_test_constraints(ppd
, resoption
, reschoice
,
332 num_newopts
, newopts
,
333 _PPD_ALL_CONSTRAINTS
)) == NULL
)
342 cupsArrayDelete(test
);
345 * Add the option/choice from the resolver regardless of whether it
346 * worked; this makes sure that we can cascade several changes to
347 * make things resolve...
350 num_newopts
= cupsAddOption(resoption
, reschoice
, num_newopts
,
357 * Try resolving by choosing the default values for non-installable
358 * options, then by iterating through the possible choices...
361 int j
; /* Looping var */
362 ppd_choice_t
*cptr
; /* Current choice */
363 ppd_size_t
*size
; /* Current page size */
366 for (i
= consts
->num_constraints
, constptr
= consts
->constraints
;
371 * Can't resolve by changing an installable option...
374 if (constptr
->installable
)
378 * Is this the option we are changing?
382 (!strcasecmp(constptr
->option
->keyword
, option
) ||
383 (!strcasecmp(option
, "PageSize") &&
384 !strcasecmp(constptr
->option
->keyword
, "PageRegion")) ||
385 (!strcasecmp(option
, "PageRegion") &&
386 !strcasecmp(constptr
->option
->keyword
, "PageSize"))))
390 * Get the current option choice...
393 if ((value
= cupsGetOption(constptr
->option
->keyword
, num_newopts
,
396 if (!strcasecmp(constptr
->option
->keyword
, "PageSize") ||
397 !strcasecmp(constptr
->option
->keyword
, "PageRegion"))
399 if ((value
= cupsGetOption("PageSize", num_newopts
,
401 value
= cupsGetOption("PageRegion", num_newopts
, newopts
);
405 if ((size
= ppdPageSize(ppd
, NULL
)) != NULL
)
413 marked
= ppdFindMarkedChoice(ppd
, constptr
->option
->keyword
);
414 value
= marked
? marked
->choice
: "";
418 if (!strncasecmp(value
, "Custom.", 7))
422 * Try the default choice...
427 if (strcasecmp(value
, constptr
->option
->defchoice
) &&
428 (test
= ppd_test_constraints(ppd
, constptr
->option
->keyword
,
429 constptr
->option
->defchoice
,
430 num_newopts
, newopts
,
431 _PPD_ALL_CONSTRAINTS
)) == NULL
)
437 num_newopts
= cupsAddOption(constptr
->option
->keyword
,
438 constptr
->option
->defchoice
,
439 num_newopts
, &newopts
);
445 * Try each choice instead...
448 for (j
= constptr
->option
->num_choices
,
449 cptr
= constptr
->option
->choices
;
453 cupsArrayDelete(test
);
456 if (strcasecmp(value
, cptr
->choice
) &&
457 strcasecmp(constptr
->option
->defchoice
, cptr
->choice
) &&
458 strcasecmp("Custom", cptr
->choice
) &&
459 (test
= ppd_test_constraints(ppd
, constptr
->option
->keyword
,
460 cptr
->choice
, num_newopts
,
462 _PPD_ALL_CONSTRAINTS
)) == NULL
)
465 * This choice works...
468 num_newopts
= cupsAddOption(constptr
->option
->keyword
,
469 cptr
->choice
, num_newopts
,
476 cupsArrayDelete(test
);
483 DEBUG_puts("ppdResolveConflicts: Unable to automatically resolve "
489 cupsArrayClear(pass
);
490 cupsArrayDelete(active
);
494 * Free the caller's option array...
497 cupsFreeOptions(*num_options
, *options
);
500 * If Collate is the option we are testing, add it here. Otherwise, remove
501 * any Collate option from the resolve list since the filters automatically
502 * handle manual collation...
505 if (option
&& !strcasecmp(option
, "Collate"))
506 num_newopts
= cupsAddOption(option
, choice
, num_newopts
, &newopts
);
508 num_newopts
= cupsRemoveOption("Collate", num_newopts
, &newopts
);
511 * Return the new list of options to the caller...
514 *num_options
= num_newopts
;
517 cupsArrayDelete(pass
);
518 cupsArrayDelete(resolvers
);
520 cupsArrayRestore(ppd
->sorted_attrs
);
522 DEBUG_printf(("cupsResolveConflicts: Returning %d options:", num_newopts
));
524 for (i
= 0; i
< num_newopts
; i
++)
525 DEBUG_printf(("cupsResolveConflicts: options[%d]: %s=%s", i
,
526 newopts
[i
].name
, newopts
[i
].value
));
532 * If we get here, we failed to resolve...
537 cupsFreeOptions(num_newopts
, newopts
);
539 cupsArrayDelete(active
);
540 cupsArrayDelete(pass
);
541 cupsArrayDelete(resolvers
);
543 cupsArrayRestore(ppd
->sorted_attrs
);
545 DEBUG_puts("cupsResolveConflicts: Unable to resolve conflicts!");
552 * 'ppdConflicts()' - Check to see if there are any conflicts among the
553 * marked option choices.
555 * The returned value is the same as returned by @link ppdMarkOption@.
558 int /* O - Number of conflicts found */
559 ppdConflicts(ppd_file_t
*ppd
) /* I - PPD to check */
561 int i
, /* Looping variable */
562 conflicts
; /* Number of conflicts */
563 cups_array_t
*active
; /* Active conflicts */
564 _ppd_cups_uiconsts_t
*c
; /* Current constraints */
565 _ppd_cups_uiconst_t
*cptr
; /* Current constraint */
566 ppd_option_t
*o
; /* Current option */
573 * Clear all conflicts...
576 for (o
= ppdFirstOption(ppd
); o
; o
= ppdNextOption(ppd
))
580 * Test for conflicts...
583 active
= ppd_test_constraints(ppd
, NULL
, NULL
, 0, NULL
,
584 _PPD_ALL_CONSTRAINTS
);
585 conflicts
= cupsArrayCount(active
);
588 * Loop through all of the UI constraints and flag any options
592 for (c
= (_ppd_cups_uiconsts_t
*)cupsArrayFirst(active
);
594 c
= (_ppd_cups_uiconsts_t
*)cupsArrayNext(active
))
596 for (i
= c
->num_constraints
, cptr
= c
->constraints
;
599 cptr
->option
->conflicted
= 1;
602 cupsArrayDelete(active
);
605 * Return the number of conflicts found...
613 * 'ppdInstallableConflict()' - Test whether an option choice conflicts with
614 * an installable option.
616 * This function tests whether a particular option choice is available based
617 * on constraints against options in the "InstallableOptions" group.
622 int /* O - 1 if conflicting, 0 if not conflicting */
623 ppdInstallableConflict(
624 ppd_file_t
*ppd
, /* I - PPD file */
625 const char *option
, /* I - Option */
626 const char *choice
) /* I - Choice */
628 cups_array_t
*active
; /* Active conflicts */
632 * Range check input...
635 if (!ppd
|| !option
|| !choice
)
639 * Test constraints using the new option...
642 active
= ppd_test_constraints(ppd
, option
, choice
, 0, NULL
,
643 _PPD_INSTALLABLE_CONSTRAINTS
);
645 cupsArrayDelete(active
);
647 return (active
!= NULL
);
652 * 'ppd_is_installable()' - Determine whether an option is in the
653 * InstallableOptions group.
656 static int /* O - 1 if installable, 0 if normal */
658 ppd_group_t
*installable
, /* I - InstallableOptions group */
659 const char *name
) /* I - Option name */
663 int i
; /* Looping var */
664 ppd_option_t
*option
; /* Current option */
667 for (i
= installable
->num_options
, option
= installable
->options
;
670 if (!strcasecmp(option
->keyword
, name
))
679 * 'ppd_load_constraints()' - Load constraints from a PPD file.
683 ppd_load_constraints(ppd_file_t
*ppd
) /* I - PPD file */
685 int i
; /* Looping var */
686 ppd_const_t
*oldconst
; /* Current UIConstraints data */
687 ppd_attr_t
*constattr
; /* Current cupsUIConstraints attribute */
688 _ppd_cups_uiconsts_t
*consts
; /* Current cupsUIConstraints data */
689 _ppd_cups_uiconst_t
*constptr
; /* Current constraint */
690 ppd_group_t
*installable
; /* Installable options group */
691 const char *vptr
; /* Pointer into constraint value */
692 char option
[PPD_MAX_NAME
], /* Option name/MainKeyword */
693 choice
[PPD_MAX_NAME
], /* Choice/OptionKeyword */
694 *ptr
; /* Pointer into option or choice */
698 * Create an array to hold the constraint data...
701 ppd
->cups_uiconstraints
= cupsArrayNew(NULL
, NULL
);
704 * Find the installable options group if it exists...
707 for (i
= ppd
->num_groups
, installable
= ppd
->groups
;
709 i
--, installable
++)
710 if (!strcasecmp(installable
->name
, "InstallableOptions"))
717 * Load old-style [Non]UIConstraints data...
720 for (i
= ppd
->num_consts
, oldconst
= ppd
->consts
; i
> 0; i
--, oldconst
++)
723 * Weed out nearby duplicates, since the PPD spec requires that you
724 * define both "*Foo foo *Bar bar" and "*Bar bar *Foo foo"...
728 !strcasecmp(oldconst
[0].option1
, oldconst
[1].option2
) &&
729 !strcasecmp(oldconst
[0].choice1
, oldconst
[1].choice2
) &&
730 !strcasecmp(oldconst
[0].option2
, oldconst
[1].option1
) &&
731 !strcasecmp(oldconst
[0].choice2
, oldconst
[1].choice1
))
738 if ((consts
= calloc(1, sizeof(_ppd_cups_uiconsts_t
))) == NULL
)
740 DEBUG_puts("ppd_load_constraints: Unable to allocate memory for "
745 if ((constptr
= calloc(2, sizeof(_ppd_cups_uiconst_t
))) == NULL
)
748 DEBUG_puts("ppd_load_constraints: Unable to allocate memory for "
754 * Fill in the information...
757 consts
->num_constraints
= 2;
758 consts
->constraints
= constptr
;
760 if (!strncasecmp(oldconst
->option1
, "Custom", 6) &&
761 !strcasecmp(oldconst
->choice1
, "True"))
763 constptr
[0].option
= ppdFindOption(ppd
, oldconst
->option1
+ 6);
764 constptr
[0].choice
= ppdFindChoice(constptr
[0].option
, "Custom");
765 constptr
[0].installable
= 0;
769 constptr
[0].option
= ppdFindOption(ppd
, oldconst
->option1
);
770 constptr
[0].choice
= ppdFindChoice(constptr
[0].option
,
772 constptr
[0].installable
= ppd_is_installable(installable
,
776 if (!constptr
[0].option
|| (!constptr
[0].choice
&& oldconst
->choice1
[0]))
778 DEBUG_printf(("ppd_load_constraints: Unknown option *%s %s!\n",
779 oldconst
->option1
, oldconst
->choice1
));
780 free(consts
->constraints
);
785 if (!strncasecmp(oldconst
->option2
, "Custom", 6) &&
786 !strcasecmp(oldconst
->choice2
, "True"))
788 constptr
[1].option
= ppdFindOption(ppd
, oldconst
->option2
+ 6);
789 constptr
[1].choice
= ppdFindChoice(constptr
[1].option
, "Custom");
790 constptr
[1].installable
= 0;
794 constptr
[1].option
= ppdFindOption(ppd
, oldconst
->option2
);
795 constptr
[1].choice
= ppdFindChoice(constptr
[1].option
,
797 constptr
[1].installable
= ppd_is_installable(installable
,
801 if (!constptr
[1].option
|| (!constptr
[1].choice
&& oldconst
->choice2
[0]))
803 DEBUG_printf(("ppd_load_constraints: Unknown option *%s %s!\n",
804 oldconst
->option2
, oldconst
->choice2
));
805 free(consts
->constraints
);
810 consts
->installable
= constptr
[0].installable
|| constptr
[1].installable
;
813 * Add it to the constraints array...
816 cupsArrayAdd(ppd
->cups_uiconstraints
, consts
);
820 * Then load new-style constraints...
823 for (constattr
= ppdFindAttr(ppd
, "cupsUIConstraints", NULL
);
825 constattr
= ppdFindNextAttr(ppd
, "cupsUIConstraints", NULL
))
827 if (!constattr
->value
)
829 DEBUG_puts("ppd_load_constraints: Bad cupsUIConstraints value!");
833 for (i
= 0, vptr
= strchr(constattr
->value
, '*');
835 i
++, vptr
= strchr(vptr
+ 1, '*'));
839 DEBUG_puts("ppd_load_constraints: Bad cupsUIConstraints value!");
843 if ((consts
= calloc(1, sizeof(_ppd_cups_uiconsts_t
))) == NULL
)
845 DEBUG_puts("ppd_load_constraints: Unable to allocate memory for "
846 "cupsUIConstraints!");
850 if ((constptr
= calloc(i
, sizeof(_ppd_cups_uiconst_t
))) == NULL
)
853 DEBUG_puts("ppd_load_constraints: Unable to allocate memory for "
854 "cupsUIConstraints!");
858 consts
->num_constraints
= i
;
859 consts
->constraints
= constptr
;
861 strlcpy(consts
->resolver
, constattr
->spec
, sizeof(consts
->resolver
));
863 for (i
= 0, vptr
= strchr(constattr
->value
, '*');
865 i
++, vptr
= strchr(vptr
, '*'), constptr
++)
868 * Extract "*Option Choice" or just "*Option"...
871 for (vptr
++, ptr
= option
; *vptr
&& !isspace(*vptr
& 255); vptr
++)
872 if (ptr
< (option
+ sizeof(option
) - 1))
877 while (isspace(*vptr
& 255))
884 for (ptr
= choice
; *vptr
&& !isspace(*vptr
& 255); vptr
++)
885 if (ptr
< (choice
+ sizeof(choice
) - 1))
891 if (!strncasecmp(option
, "Custom", 6) && !strcasecmp(choice
, "True"))
893 _cups_strcpy(option
, option
+ 6);
894 strcpy(choice
, "Custom");
897 constptr
->option
= ppdFindOption(ppd
, option
);
898 constptr
->choice
= ppdFindChoice(constptr
->option
, choice
);
899 constptr
->installable
= ppd_is_installable(installable
, option
);
900 consts
->installable
|= constptr
->installable
;
902 if (!constptr
->option
|| (!constptr
->choice
&& choice
[0]))
904 DEBUG_printf(("ppd_load_constraints: Unknown option *%s %s!\n",
911 cupsArrayAdd(ppd
->cups_uiconstraints
, consts
);
914 free(consts
->constraints
);
922 * 'ppd_test_constraints()' - See if any constraints are active.
925 static cups_array_t
* /* O - Array of active constraints */
926 ppd_test_constraints(
927 ppd_file_t
*ppd
, /* I - PPD file */
928 const char *option
, /* I - Current option */
929 const char *choice
, /* I - Current choice */
930 int num_options
, /* I - Number of additional options */
931 cups_option_t
*options
, /* I - Additional options */
932 int which
) /* I - Which constraints to test */
934 int i
; /* Looping var */
935 _ppd_cups_uiconsts_t
*consts
; /* Current constraints */
936 _ppd_cups_uiconst_t
*constptr
; /* Current constraint */
937 ppd_choice_t key
, /* Search key */
938 *marked
; /* Marked choice */
939 cups_array_t
*active
= NULL
; /* Active constraints */
940 const char *value
; /* Current value */
943 DEBUG_printf(("ppd_test_constraints(ppd=%p, num_options=%d, options=%p, "
944 "which=%d)\n", ppd
, num_options
, options
, which
));
946 if (!ppd
->cups_uiconstraints
)
947 ppd_load_constraints(ppd
);
949 DEBUG_printf(("ppd_test_constraints: %d constraints!\n",
950 cupsArrayCount(ppd
->cups_uiconstraints
)));
952 cupsArraySave(ppd
->marked
);
954 for (consts
= (_ppd_cups_uiconsts_t
*)cupsArrayFirst(ppd
->cups_uiconstraints
);
956 consts
= (_ppd_cups_uiconsts_t
*)cupsArrayNext(ppd
->cups_uiconstraints
))
958 DEBUG_printf(("ppd_test_constraints: installable=%d, resolver=\"%s\", "
959 "num_constraints=%d option1=\"%s\", choice1=\"%s\", "
960 "option2=\"%s\", choice2=\"%s\", ...\n",
961 consts
->installable
, consts
->resolver
, consts
->num_constraints
,
962 consts
->constraints
[0].option
->keyword
,
963 consts
->constraints
[0].choice
?
964 consts
->constraints
[0].choice
->choice
: "",
965 consts
->constraints
[1].option
->keyword
,
966 consts
->constraints
[1].choice
?
967 consts
->constraints
[1].choice
->choice
: ""));
969 if (which
!= _PPD_ALL_CONSTRAINTS
&& which
!= consts
->installable
)
972 DEBUG_puts("ppd_test_constraints: Testing...");
974 for (i
= consts
->num_constraints
, constptr
= consts
->constraints
;
978 DEBUG_printf(("ppd_test_constraints: %s=%s?\n", constptr
->option
->keyword
,
979 constptr
->choice
? constptr
->choice
->choice
: ""));
981 if (constptr
->choice
&&
982 (!strcasecmp(constptr
->option
->keyword
, "PageSize") ||
983 !strcasecmp(constptr
->option
->keyword
, "PageRegion")))
986 * PageSize and PageRegion are used depending on the selected input slot
987 * and manual feed mode. Validate against the selected page size instead
988 * of an individual option...
991 if (option
&& choice
&&
992 (!strcasecmp(option
, "PageSize") ||
993 !strcasecmp(option
, "PageRegion")))
997 else if ((value
= cupsGetOption("PageSize", num_options
,
999 if ((value
= cupsGetOption("PageRegion", num_options
,
1001 if ((value
= cupsGetOption("media", num_options
, options
)) == NULL
)
1003 ppd_size_t
*size
= ppdPageSize(ppd
, NULL
);
1009 if (value
&& !strncasecmp(value
, "Custom.", 7))
1012 if (!value
|| strcasecmp(value
, constptr
->choice
->choice
))
1014 DEBUG_puts("ppd_test_constraints: NO");
1018 else if (constptr
->choice
)
1020 if (option
&& choice
&& !strcasecmp(option
, constptr
->option
->keyword
))
1022 if (!strncasecmp(choice
, "Custom.", 7))
1027 if (strcasecmp(value
, constptr
->choice
->choice
))
1029 DEBUG_puts("ppd_test_constraints: NO");
1033 else if ((value
= cupsGetOption(constptr
->option
->keyword
, num_options
,
1036 if (!strncasecmp(value
, "Custom.", 7))
1039 if (strcasecmp(value
, constptr
->choice
->choice
))
1041 DEBUG_puts("ppd_test_constraints: NO");
1045 else if (!constptr
->choice
->marked
)
1047 DEBUG_puts("ppd_test_constraints: NO");
1051 else if (option
&& choice
&&
1052 !strcasecmp(option
, constptr
->option
->keyword
))
1054 if (!strcasecmp(choice
, "None") || !strcasecmp(choice
, "Off") ||
1055 !strcasecmp(choice
, "False"))
1057 DEBUG_puts("ppd_test_constraints: NO");
1061 else if ((value
= cupsGetOption(constptr
->option
->keyword
, num_options
,
1064 if (!strcasecmp(value
, "None") || !strcasecmp(value
, "Off") ||
1065 !strcasecmp(value
, "False"))
1067 DEBUG_puts("ppd_test_constraints: NO");
1073 key
.option
= constptr
->option
;
1075 if ((marked
= (ppd_choice_t
*)cupsArrayFind(ppd
->marked
, &key
))
1077 (!strcasecmp(marked
->choice
, "None") ||
1078 !strcasecmp(marked
->choice
, "Off") ||
1079 !strcasecmp(marked
->choice
, "False")))
1081 DEBUG_puts("ppd_test_constraints: NO");
1090 active
= cupsArrayNew(NULL
, NULL
);
1092 cupsArrayAdd(active
, consts
);
1093 DEBUG_puts("ppd_test_constraints: Added...");
1097 cupsArrayRestore(ppd
->marked
);
1099 DEBUG_printf(("ppd_test_constraints: Found %d active constraints!\n",
1100 cupsArrayCount(active
)));