4 * Option marking routines for CUPS.
6 * Copyright 2007-2011 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 "cups-private.h"
39 #include "ppd-private.h"
48 _PPD_NORMAL_CONSTRAINTS
,
49 _PPD_OPTION_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@.
82 * @since CUPS 1.4/Mac OS X 10.6@
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.
172 * @since CUPS 1.4/Mac OS X 10.6@
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 tries
, /* Number of tries */
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 firstpage
[255]; /* AP_FIRSTPAGE_Keyword string */
201 const char *value
; /* Selected option value */
202 int changed
; /* Did we change anything? */
203 ppd_choice_t
*marked
; /* Marked choice */
207 * Range check input...
210 if (!ppd
|| !num_options
|| !options
|| (option
== NULL
) != (choice
== NULL
))
214 * Build a shadow option array...
220 for (i
= 0; i
< *num_options
; i
++)
221 num_newopts
= cupsAddOption((*options
)[i
].name
, (*options
)[i
].value
,
222 num_newopts
, &newopts
);
223 if (option
&& strcasecmp(option
, "Collate"))
224 num_newopts
= cupsAddOption(option
, choice
, num_newopts
, &newopts
);
227 * Loop until we have no conflicts...
230 cupsArraySave(ppd
->sorted_attrs
);
233 pass
= cupsArrayNew((cups_array_func_t
)strcasecmp
, NULL
);
236 while (tries
< 100 &&
237 (active
= ppd_test_constraints(ppd
, NULL
, NULL
, num_newopts
, newopts
,
238 _PPD_ALL_CONSTRAINTS
)) != NULL
)
243 resolvers
= cupsArrayNew((cups_array_func_t
)strcasecmp
, NULL
);
245 for (consts
= (_ppd_cups_uiconsts_t
*)cupsArrayFirst(active
), changed
= 0;
247 consts
= (_ppd_cups_uiconsts_t
*)cupsArrayNext(active
))
249 if (consts
->resolver
[0])
252 * Look up the resolver...
255 if (cupsArrayFind(pass
, consts
->resolver
))
256 continue; /* Already applied this resolver... */
258 if (cupsArrayFind(resolvers
, consts
->resolver
))
264 DEBUG_printf(("1ppdResolveConflicts: Resolver loop with %s!",
269 if ((resolver
= ppdFindAttr(ppd
, "cupsUIResolver",
270 consts
->resolver
)) == NULL
)
272 DEBUG_printf(("1ppdResolveConflicts: Resolver %s not found!",
277 if (!resolver
->value
)
279 DEBUG_printf(("1ppdResolveConflicts: Resolver %s has no value!",
285 * Add the options from the resolver...
288 cupsArrayAdd(pass
, consts
->resolver
);
289 cupsArrayAdd(resolvers
, consts
->resolver
);
291 for (resval
= resolver
->value
; *resval
&& !changed
;)
293 while (_cups_isspace(*resval
))
299 for (resval
++, resptr
= resoption
;
300 *resval
&& !_cups_isspace(*resval
);
302 if (resptr
< (resoption
+ sizeof(resoption
) - 1))
307 while (_cups_isspace(*resval
))
310 for (resptr
= reschoice
;
311 *resval
&& !_cups_isspace(*resval
);
313 if (resptr
< (reschoice
+ sizeof(reschoice
) - 1))
318 if (!resoption
[0] || !reschoice
[0])
322 * Is this the option we are changing?
325 snprintf(firstpage
, sizeof(firstpage
), "AP_FIRSTPAGE_%s", resoption
);
328 (!strcasecmp(resoption
, option
) ||
329 !strcasecmp(firstpage
, option
) ||
330 (!strcasecmp(option
, "PageSize") &&
331 !strcasecmp(resoption
, "PageRegion")) ||
332 (!strcasecmp(option
, "AP_FIRSTPAGE_PageSize") &&
333 !strcasecmp(resoption
, "PageSize")) ||
334 (!strcasecmp(option
, "AP_FIRSTPAGE_PageSize") &&
335 !strcasecmp(resoption
, "PageRegion")) ||
336 (!strcasecmp(option
, "PageRegion") &&
337 !strcasecmp(resoption
, "PageSize")) ||
338 (!strcasecmp(option
, "AP_FIRSTPAGE_PageRegion") &&
339 !strcasecmp(resoption
, "PageSize")) ||
340 (!strcasecmp(option
, "AP_FIRSTPAGE_PageRegion") &&
341 !strcasecmp(resoption
, "PageRegion"))))
348 if ((test
= ppd_test_constraints(ppd
, resoption
, reschoice
,
349 num_newopts
, newopts
,
350 _PPD_ALL_CONSTRAINTS
)) == NULL
)
359 cupsArrayDelete(test
);
362 * Add the option/choice from the resolver regardless of whether it
363 * worked; this makes sure that we can cascade several changes to
364 * make things resolve...
367 num_newopts
= cupsAddOption(resoption
, reschoice
, num_newopts
,
374 * Try resolving by choosing the default values for non-installable
375 * options, then by iterating through the possible choices...
378 int j
; /* Looping var */
379 ppd_choice_t
*cptr
; /* Current choice */
380 ppd_size_t
*size
; /* Current page size */
383 for (i
= consts
->num_constraints
, constptr
= consts
->constraints
;
388 * Can't resolve by changing an installable option...
391 if (constptr
->installable
)
395 * Is this the option we are changing?
399 (!strcasecmp(constptr
->option
->keyword
, option
) ||
400 (!strcasecmp(option
, "PageSize") &&
401 !strcasecmp(constptr
->option
->keyword
, "PageRegion")) ||
402 (!strcasecmp(option
, "PageRegion") &&
403 !strcasecmp(constptr
->option
->keyword
, "PageSize"))))
407 * Get the current option choice...
410 if ((value
= cupsGetOption(constptr
->option
->keyword
, num_newopts
,
413 if (!strcasecmp(constptr
->option
->keyword
, "PageSize") ||
414 !strcasecmp(constptr
->option
->keyword
, "PageRegion"))
416 if ((value
= cupsGetOption("PageSize", num_newopts
,
418 value
= cupsGetOption("PageRegion", num_newopts
, newopts
);
422 if ((size
= ppdPageSize(ppd
, NULL
)) != NULL
)
430 marked
= ppdFindMarkedChoice(ppd
, constptr
->option
->keyword
);
431 value
= marked
? marked
->choice
: "";
435 if (!strncasecmp(value
, "Custom.", 7))
439 * Try the default choice...
444 if (strcasecmp(value
, constptr
->option
->defchoice
) &&
445 (test
= ppd_test_constraints(ppd
, constptr
->option
->keyword
,
446 constptr
->option
->defchoice
,
447 num_newopts
, newopts
,
448 _PPD_OPTION_CONSTRAINTS
)) == NULL
)
454 num_newopts
= cupsAddOption(constptr
->option
->keyword
,
455 constptr
->option
->defchoice
,
456 num_newopts
, &newopts
);
462 * Try each choice instead...
465 for (j
= constptr
->option
->num_choices
,
466 cptr
= constptr
->option
->choices
;
470 cupsArrayDelete(test
);
473 if (strcasecmp(value
, cptr
->choice
) &&
474 strcasecmp(constptr
->option
->defchoice
, cptr
->choice
) &&
475 strcasecmp("Custom", cptr
->choice
) &&
476 (test
= ppd_test_constraints(ppd
, constptr
->option
->keyword
,
477 cptr
->choice
, num_newopts
,
479 _PPD_OPTION_CONSTRAINTS
)) == NULL
)
482 * This choice works...
485 num_newopts
= cupsAddOption(constptr
->option
->keyword
,
486 cptr
->choice
, num_newopts
,
493 cupsArrayDelete(test
);
501 DEBUG_puts("1ppdResolveConflicts: Unable to automatically resolve "
506 cupsArrayClear(pass
);
507 cupsArrayDelete(active
);
515 * Free the caller's option array...
518 cupsFreeOptions(*num_options
, *options
);
521 * If Collate is the option we are testing, add it here. Otherwise, remove
522 * any Collate option from the resolve list since the filters automatically
523 * handle manual collation...
526 if (option
&& !strcasecmp(option
, "Collate"))
527 num_newopts
= cupsAddOption(option
, choice
, num_newopts
, &newopts
);
529 num_newopts
= cupsRemoveOption("Collate", num_newopts
, &newopts
);
532 * Return the new list of options to the caller...
535 *num_options
= num_newopts
;
538 cupsArrayDelete(pass
);
539 cupsArrayDelete(resolvers
);
541 cupsArrayRestore(ppd
->sorted_attrs
);
543 DEBUG_printf(("1cupsResolveConflicts: Returning %d options:", num_newopts
));
545 for (i
= 0; i
< num_newopts
; i
++)
546 DEBUG_printf(("1cupsResolveConflicts: options[%d]: %s=%s", i
,
547 newopts
[i
].name
, newopts
[i
].value
));
553 * If we get here, we failed to resolve...
558 cupsFreeOptions(num_newopts
, newopts
);
560 cupsArrayDelete(active
);
561 cupsArrayDelete(pass
);
562 cupsArrayDelete(resolvers
);
564 cupsArrayRestore(ppd
->sorted_attrs
);
566 DEBUG_puts("1cupsResolveConflicts: Unable to resolve conflicts!");
573 * 'ppdConflicts()' - Check to see if there are any conflicts among the
574 * marked option choices.
576 * The returned value is the same as returned by @link ppdMarkOption@.
579 int /* O - Number of conflicts found */
580 ppdConflicts(ppd_file_t
*ppd
) /* I - PPD to check */
582 int i
, /* Looping variable */
583 conflicts
; /* Number of conflicts */
584 cups_array_t
*active
; /* Active conflicts */
585 _ppd_cups_uiconsts_t
*c
; /* Current constraints */
586 _ppd_cups_uiconst_t
*cptr
; /* Current constraint */
587 ppd_option_t
*o
; /* Current option */
594 * Clear all conflicts...
597 cupsArraySave(ppd
->options
);
599 for (o
= ppdFirstOption(ppd
); o
; o
= ppdNextOption(ppd
))
602 cupsArrayRestore(ppd
->options
);
605 * Test for conflicts...
608 active
= ppd_test_constraints(ppd
, NULL
, NULL
, 0, NULL
,
609 _PPD_ALL_CONSTRAINTS
);
610 conflicts
= cupsArrayCount(active
);
613 * Loop through all of the UI constraints and flag any options
617 for (c
= (_ppd_cups_uiconsts_t
*)cupsArrayFirst(active
);
619 c
= (_ppd_cups_uiconsts_t
*)cupsArrayNext(active
))
621 for (i
= c
->num_constraints
, cptr
= c
->constraints
;
624 cptr
->option
->conflicted
= 1;
627 cupsArrayDelete(active
);
630 * Return the number of conflicts found...
638 * 'ppdInstallableConflict()' - Test whether an option choice conflicts with
639 * an installable option.
641 * This function tests whether a particular option choice is available based
642 * on constraints against options in the "InstallableOptions" group.
644 * @since CUPS 1.4/Mac OS X 10.6@
647 int /* O - 1 if conflicting, 0 if not conflicting */
648 ppdInstallableConflict(
649 ppd_file_t
*ppd
, /* I - PPD file */
650 const char *option
, /* I - Option */
651 const char *choice
) /* I - Choice */
653 cups_array_t
*active
; /* Active conflicts */
656 DEBUG_printf(("2ppdInstallableConflict(ppd=%p, option=\"%s\", choice=\"%s\")",
657 ppd
, option
, choice
));
660 * Range check input...
663 if (!ppd
|| !option
|| !choice
)
667 * Test constraints using the new option...
670 active
= ppd_test_constraints(ppd
, option
, choice
, 0, NULL
,
671 _PPD_INSTALLABLE_CONSTRAINTS
);
673 cupsArrayDelete(active
);
675 return (active
!= NULL
);
680 * 'ppd_is_installable()' - Determine whether an option is in the
681 * InstallableOptions group.
684 static int /* O - 1 if installable, 0 if normal */
686 ppd_group_t
*installable
, /* I - InstallableOptions group */
687 const char *name
) /* I - Option name */
691 int i
; /* Looping var */
692 ppd_option_t
*option
; /* Current option */
695 for (i
= installable
->num_options
, option
= installable
->options
;
698 if (!strcasecmp(option
->keyword
, name
))
707 * 'ppd_load_constraints()' - Load constraints from a PPD file.
711 ppd_load_constraints(ppd_file_t
*ppd
) /* I - PPD file */
713 int i
; /* Looping var */
714 ppd_const_t
*oldconst
; /* Current UIConstraints data */
715 ppd_attr_t
*constattr
; /* Current cupsUIConstraints attribute */
716 _ppd_cups_uiconsts_t
*consts
; /* Current cupsUIConstraints data */
717 _ppd_cups_uiconst_t
*constptr
; /* Current constraint */
718 ppd_group_t
*installable
; /* Installable options group */
719 const char *vptr
; /* Pointer into constraint value */
720 char option
[PPD_MAX_NAME
], /* Option name/MainKeyword */
721 choice
[PPD_MAX_NAME
], /* Choice/OptionKeyword */
722 *ptr
; /* Pointer into option or choice */
725 DEBUG_printf(("7ppd_load_constraints(ppd=%p)", ppd
));
728 * Create an array to hold the constraint data...
731 ppd
->cups_uiconstraints
= cupsArrayNew(NULL
, NULL
);
734 * Find the installable options group if it exists...
737 for (i
= ppd
->num_groups
, installable
= ppd
->groups
;
739 i
--, installable
++)
740 if (!strcasecmp(installable
->name
, "InstallableOptions"))
747 * Load old-style [Non]UIConstraints data...
750 for (i
= ppd
->num_consts
, oldconst
= ppd
->consts
; i
> 0; i
--, oldconst
++)
753 * Weed out nearby duplicates, since the PPD spec requires that you
754 * define both "*Foo foo *Bar bar" and "*Bar bar *Foo foo"...
758 !strcasecmp(oldconst
[0].option1
, oldconst
[1].option2
) &&
759 !strcasecmp(oldconst
[0].choice1
, oldconst
[1].choice2
) &&
760 !strcasecmp(oldconst
[0].option2
, oldconst
[1].option1
) &&
761 !strcasecmp(oldconst
[0].choice2
, oldconst
[1].choice1
))
768 if ((consts
= calloc(1, sizeof(_ppd_cups_uiconsts_t
))) == NULL
)
770 DEBUG_puts("8ppd_load_constraints: Unable to allocate memory for "
775 if ((constptr
= calloc(2, sizeof(_ppd_cups_uiconst_t
))) == NULL
)
778 DEBUG_puts("8ppd_load_constraints: Unable to allocate memory for "
784 * Fill in the information...
787 consts
->num_constraints
= 2;
788 consts
->constraints
= constptr
;
790 if (!strncasecmp(oldconst
->option1
, "Custom", 6) &&
791 !strcasecmp(oldconst
->choice1
, "True"))
793 constptr
[0].option
= ppdFindOption(ppd
, oldconst
->option1
+ 6);
794 constptr
[0].choice
= ppdFindChoice(constptr
[0].option
, "Custom");
795 constptr
[0].installable
= 0;
799 constptr
[0].option
= ppdFindOption(ppd
, oldconst
->option1
);
800 constptr
[0].choice
= ppdFindChoice(constptr
[0].option
,
802 constptr
[0].installable
= ppd_is_installable(installable
,
806 if (!constptr
[0].option
|| (!constptr
[0].choice
&& oldconst
->choice1
[0]))
808 DEBUG_printf(("8ppd_load_constraints: Unknown option *%s %s!",
809 oldconst
->option1
, oldconst
->choice1
));
810 free(consts
->constraints
);
815 if (!strncasecmp(oldconst
->option2
, "Custom", 6) &&
816 !strcasecmp(oldconst
->choice2
, "True"))
818 constptr
[1].option
= ppdFindOption(ppd
, oldconst
->option2
+ 6);
819 constptr
[1].choice
= ppdFindChoice(constptr
[1].option
, "Custom");
820 constptr
[1].installable
= 0;
824 constptr
[1].option
= ppdFindOption(ppd
, oldconst
->option2
);
825 constptr
[1].choice
= ppdFindChoice(constptr
[1].option
,
827 constptr
[1].installable
= ppd_is_installable(installable
,
831 if (!constptr
[1].option
|| (!constptr
[1].choice
&& oldconst
->choice2
[0]))
833 DEBUG_printf(("8ppd_load_constraints: Unknown option *%s %s!",
834 oldconst
->option2
, oldconst
->choice2
));
835 free(consts
->constraints
);
840 consts
->installable
= constptr
[0].installable
|| constptr
[1].installable
;
843 * Add it to the constraints array...
846 cupsArrayAdd(ppd
->cups_uiconstraints
, consts
);
850 * Then load new-style constraints...
853 for (constattr
= ppdFindAttr(ppd
, "cupsUIConstraints", NULL
);
855 constattr
= ppdFindNextAttr(ppd
, "cupsUIConstraints", NULL
))
857 if (!constattr
->value
)
859 DEBUG_puts("8ppd_load_constraints: Bad cupsUIConstraints value!");
863 for (i
= 0, vptr
= strchr(constattr
->value
, '*');
865 i
++, vptr
= strchr(vptr
+ 1, '*'));
869 DEBUG_puts("8ppd_load_constraints: Bad cupsUIConstraints value!");
873 if ((consts
= calloc(1, sizeof(_ppd_cups_uiconsts_t
))) == NULL
)
875 DEBUG_puts("8ppd_load_constraints: Unable to allocate memory for "
876 "cupsUIConstraints!");
880 if ((constptr
= calloc(i
, sizeof(_ppd_cups_uiconst_t
))) == NULL
)
883 DEBUG_puts("8ppd_load_constraints: Unable to allocate memory for "
884 "cupsUIConstraints!");
888 consts
->num_constraints
= i
;
889 consts
->constraints
= constptr
;
891 strlcpy(consts
->resolver
, constattr
->spec
, sizeof(consts
->resolver
));
893 for (i
= 0, vptr
= strchr(constattr
->value
, '*');
895 i
++, vptr
= strchr(vptr
, '*'), constptr
++)
898 * Extract "*Option Choice" or just "*Option"...
901 for (vptr
++, ptr
= option
; *vptr
&& !_cups_isspace(*vptr
); vptr
++)
902 if (ptr
< (option
+ sizeof(option
) - 1))
907 while (_cups_isspace(*vptr
))
914 for (ptr
= choice
; *vptr
&& !_cups_isspace(*vptr
); vptr
++)
915 if (ptr
< (choice
+ sizeof(choice
) - 1))
921 if (!strncasecmp(option
, "Custom", 6) && !strcasecmp(choice
, "True"))
923 _cups_strcpy(option
, option
+ 6);
924 strcpy(choice
, "Custom");
927 constptr
->option
= ppdFindOption(ppd
, option
);
928 constptr
->choice
= ppdFindChoice(constptr
->option
, choice
);
929 constptr
->installable
= ppd_is_installable(installable
, option
);
930 consts
->installable
|= constptr
->installable
;
932 if (!constptr
->option
|| (!constptr
->choice
&& choice
[0]))
934 DEBUG_printf(("8ppd_load_constraints: Unknown option *%s %s!",
941 cupsArrayAdd(ppd
->cups_uiconstraints
, consts
);
944 free(consts
->constraints
);
952 * 'ppd_test_constraints()' - See if any constraints are active.
955 static cups_array_t
* /* O - Array of active constraints */
956 ppd_test_constraints(
957 ppd_file_t
*ppd
, /* I - PPD file */
958 const char *option
, /* I - Current option */
959 const char *choice
, /* I - Current choice */
960 int num_options
, /* I - Number of additional options */
961 cups_option_t
*options
, /* I - Additional options */
962 int which
) /* I - Which constraints to test */
964 int i
; /* Looping var */
965 _ppd_cups_uiconsts_t
*consts
; /* Current constraints */
966 _ppd_cups_uiconst_t
*constptr
; /* Current constraint */
967 ppd_choice_t key
, /* Search key */
968 *marked
; /* Marked choice */
969 cups_array_t
*active
= NULL
; /* Active constraints */
970 const char *value
, /* Current value */
971 *firstvalue
; /* AP_FIRSTPAGE_Keyword value */
972 char firstpage
[255]; /* AP_FIRSTPAGE_Keyword string */
975 DEBUG_printf(("7ppd_test_constraints(ppd=%p, option=\"%s\", choice=\"%s\", "
976 "num_options=%d, options=%p, which=%d)", ppd
, option
, choice
,
977 num_options
, options
, which
));
979 if (!ppd
->cups_uiconstraints
)
980 ppd_load_constraints(ppd
);
982 DEBUG_printf(("9ppd_test_constraints: %d constraints!",
983 cupsArrayCount(ppd
->cups_uiconstraints
)));
985 cupsArraySave(ppd
->marked
);
987 for (consts
= (_ppd_cups_uiconsts_t
*)cupsArrayFirst(ppd
->cups_uiconstraints
);
989 consts
= (_ppd_cups_uiconsts_t
*)cupsArrayNext(ppd
->cups_uiconstraints
))
991 DEBUG_printf(("9ppd_test_constraints: installable=%d, resolver=\"%s\", "
992 "num_constraints=%d option1=\"%s\", choice1=\"%s\", "
993 "option2=\"%s\", choice2=\"%s\", ...",
994 consts
->installable
, consts
->resolver
, consts
->num_constraints
,
995 consts
->constraints
[0].option
->keyword
,
996 consts
->constraints
[0].choice
?
997 consts
->constraints
[0].choice
->choice
: "",
998 consts
->constraints
[1].option
->keyword
,
999 consts
->constraints
[1].choice
?
1000 consts
->constraints
[1].choice
->choice
: ""));
1002 if (consts
->installable
&& which
< _PPD_INSTALLABLE_CONSTRAINTS
)
1003 continue; /* Skip installable option constraint */
1005 if (!consts
->installable
&& which
== _PPD_INSTALLABLE_CONSTRAINTS
)
1006 continue; /* Skip non-installable option constraint */
1008 if (which
== _PPD_OPTION_CONSTRAINTS
&& option
)
1011 * Skip constraints that do not involve the current option...
1014 for (i
= consts
->num_constraints
, constptr
= consts
->constraints
;
1018 if (!strcasecmp(constptr
->option
->keyword
, option
))
1021 if (!strncasecmp(option
, "AP_FIRSTPAGE_", 13) &&
1022 !strcasecmp(constptr
->option
->keyword
, option
+ 13))
1030 DEBUG_puts("9ppd_test_constraints: Testing...");
1032 for (i
= consts
->num_constraints
, constptr
= consts
->constraints
;
1036 DEBUG_printf(("9ppd_test_constraints: %s=%s?", constptr
->option
->keyword
,
1037 constptr
->choice
? constptr
->choice
->choice
: ""));
1039 if (constptr
->choice
&&
1040 (!strcasecmp(constptr
->option
->keyword
, "PageSize") ||
1041 !strcasecmp(constptr
->option
->keyword
, "PageRegion")))
1044 * PageSize and PageRegion are used depending on the selected input slot
1045 * and manual feed mode. Validate against the selected page size instead
1046 * of an individual option...
1049 if (option
&& choice
&&
1050 (!strcasecmp(option
, "PageSize") ||
1051 !strcasecmp(option
, "PageRegion")))
1055 else if ((value
= cupsGetOption("PageSize", num_options
,
1057 if ((value
= cupsGetOption("PageRegion", num_options
,
1059 if ((value
= cupsGetOption("media", num_options
, options
)) == NULL
)
1061 ppd_size_t
*size
= ppdPageSize(ppd
, NULL
);
1067 if (value
&& !strncasecmp(value
, "Custom.", 7))
1070 if (option
&& choice
&&
1071 (!strcasecmp(option
, "AP_FIRSTPAGE_PageSize") ||
1072 !strcasecmp(option
, "AP_FIRSTPAGE_PageRegion")))
1074 firstvalue
= choice
;
1076 else if ((firstvalue
= cupsGetOption("AP_FIRSTPAGE_PageSize",
1077 num_options
, options
)) == NULL
)
1078 firstvalue
= cupsGetOption("AP_FIRSTPAGE_PageRegion", num_options
,
1081 if (firstvalue
&& !strncasecmp(firstvalue
, "Custom.", 7))
1082 firstvalue
= "Custom";
1084 if ((!value
|| strcasecmp(value
, constptr
->choice
->choice
)) &&
1085 (!firstvalue
|| strcasecmp(firstvalue
, constptr
->choice
->choice
)))
1087 DEBUG_puts("9ppd_test_constraints: NO");
1091 else if (constptr
->choice
)
1094 * Compare against the constrained choice...
1097 if (option
&& choice
&& !strcasecmp(option
, constptr
->option
->keyword
))
1099 if (!strncasecmp(choice
, "Custom.", 7))
1104 else if ((value
= cupsGetOption(constptr
->option
->keyword
, num_options
,
1107 if (!strncasecmp(value
, "Custom.", 7))
1110 else if (constptr
->choice
->marked
)
1111 value
= constptr
->choice
->choice
;
1116 * Now check AP_FIRSTPAGE_option...
1119 snprintf(firstpage
, sizeof(firstpage
), "AP_FIRSTPAGE_%s",
1120 constptr
->option
->keyword
);
1122 if (option
&& choice
&& !strcasecmp(option
, firstpage
))
1124 if (!strncasecmp(choice
, "Custom.", 7))
1125 firstvalue
= "Custom";
1127 firstvalue
= choice
;
1129 else if ((firstvalue
= cupsGetOption(firstpage
, num_options
,
1132 if (!strncasecmp(firstvalue
, "Custom.", 7))
1133 firstvalue
= "Custom";
1138 DEBUG_printf(("9ppd_test_constraints: value=%s, firstvalue=%s", value
,
1141 if ((!value
|| strcasecmp(value
, constptr
->choice
->choice
)) &&
1142 (!firstvalue
|| strcasecmp(firstvalue
, constptr
->choice
->choice
)))
1144 DEBUG_puts("9ppd_test_constraints: NO");
1148 else if (option
&& choice
&&
1149 !strcasecmp(option
, constptr
->option
->keyword
))
1151 if (!strcasecmp(choice
, "None") || !strcasecmp(choice
, "Off") ||
1152 !strcasecmp(choice
, "False"))
1154 DEBUG_puts("9ppd_test_constraints: NO");
1158 else if ((value
= cupsGetOption(constptr
->option
->keyword
, num_options
,
1161 if (!strcasecmp(value
, "None") || !strcasecmp(value
, "Off") ||
1162 !strcasecmp(value
, "False"))
1164 DEBUG_puts("9ppd_test_constraints: NO");
1170 key
.option
= constptr
->option
;
1172 if ((marked
= (ppd_choice_t
*)cupsArrayFind(ppd
->marked
, &key
))
1174 (!strcasecmp(marked
->choice
, "None") ||
1175 !strcasecmp(marked
->choice
, "Off") ||
1176 !strcasecmp(marked
->choice
, "False")))
1178 DEBUG_puts("9ppd_test_constraints: NO");
1187 active
= cupsArrayNew(NULL
, NULL
);
1189 cupsArrayAdd(active
, consts
);
1190 DEBUG_puts("9ppd_test_constraints: Added...");
1194 cupsArrayRestore(ppd
->marked
);
1196 DEBUG_printf(("8ppd_test_constraints: Found %d active constraints!",
1197 cupsArrayCount(active
)));