Lines Matching +full:- +full:- +full:option

2  * Option conflict management routines for CUPS.
4 * Copyright 2007-2015 by Apple Inc.
5 * Copyright 1997-2007 by Easy Software Products, all rights reserved.
15 * This file is subject to the Apple OS-Developed Software exception.
22 #include "cups-private.h"
23 #include "ppd-private.h"
44 const char *option);
47 const char *option,
55 * 'cupsGetConflicts()' - Get a list of conflicting options in a marked PPD.
57 * This function gets a list of options that would conflict if "option" and
60 * determine whether a new option selection would cause a conflict.
63 * the conflicting options. The returned option array must be freed using
69 int /* O - Number of conflicting options */
71 ppd_file_t *ppd, /* I - PPD file */ in cupsGetConflicts()
72 const char *option, /* I - Option to test */ in cupsGetConflicts() argument
73 const char *choice, /* I - Choice to test */ in cupsGetConflicts()
74 cups_option_t **options) /* O - Conflicting options */ in cupsGetConflicts()
91 if (!ppd || !option || !choice || !options) in cupsGetConflicts()
98 active = ppd_test_constraints(ppd, option, choice, 0, NULL, in cupsGetConflicts()
109 for (i = c->num_constraints, cptr = c->constraints; in cupsGetConflicts()
111 i --, cptr ++) in cupsGetConflicts()
112 if (_cups_strcasecmp(cptr->option->keyword, option)) in cupsGetConflicts()
114 if (cptr->choice) in cupsGetConflicts()
115 num_options = cupsAddOption(cptr->option->keyword, in cupsGetConflicts()
116 cptr->choice->choice, num_options, in cupsGetConflicts()
119 cptr->option->keyword)) != NULL) in cupsGetConflicts()
120 num_options = cupsAddOption(cptr->option->keyword, marked->choice, in cupsGetConflicts()
132 * 'cupsResolveConflicts()' - Resolve conflicts in a marked PPD.
135 * a list of option changes that are required to resolve them. On input,
136 * "num_options" and "options" contain any pending option changes that have
137 * not yet been marked, while "option" and "choice" contain the most recent
141 * "option" and "choice" along with any changes required to resolve conflicts
144 * If option conflicts cannot be resolved, "num_options" and "options" are not
149 * @code PageRegion@) or to the most recent option specified in "option".
151 * or the option the user most recently changed, @code cupsResolveConflicts@
154 * The @code cupsResolveConflicts@ function uses one of two sources of option
156 * @code cupsUIConstraints@ and @code cupsUIResolver@ attributes - in this
162 * choice for the conflicting option, then iterating over all possible choices
163 * until a non-conflicting option choice is found.
168 int /* O - 1 on success, 0 on failure */
170 ppd_file_t *ppd, /* I - PPD file */ in cupsResolveConflicts()
171 const char *option, /* I - Newly selected option or @code NULL@ for none */ in cupsResolveConflicts() argument
172 const char *choice, /* I - Newly selected choice or @code NULL@ for none */ in cupsResolveConflicts()
173 int *num_options, /* IO - Number of additional selected options */ in cupsResolveConflicts()
174 cups_option_t **options) /* IO - Additional selected options */ in cupsResolveConflicts()
189 /* Current resolver option */ in cupsResolveConflicts()
192 *resptr, /* Pointer into option/choice */ in cupsResolveConflicts()
194 const char *value; /* Selected option value */ in cupsResolveConflicts()
203 if (!ppd || !num_options || !options || (option == NULL) != (choice == NULL)) in cupsResolveConflicts()
207 * Build a shadow option array... in cupsResolveConflicts()
216 if (option && _cups_strcasecmp(option, "Collate")) in cupsResolveConflicts()
217 num_newopts = cupsAddOption(option, choice, num_newopts, &newopts); in cupsResolveConflicts()
223 cupsArraySave(ppd->sorted_attrs); in cupsResolveConflicts()
242 if (consts->resolver[0]) in cupsResolveConflicts()
248 if (cupsArrayFind(pass, consts->resolver)) in cupsResolveConflicts()
251 if (cupsArrayFind(resolvers, consts->resolver)) in cupsResolveConflicts()
258 consts->resolver)); in cupsResolveConflicts()
263 consts->resolver)) == NULL) in cupsResolveConflicts()
266 consts->resolver)); in cupsResolveConflicts()
270 if (!resolver->value) in cupsResolveConflicts()
273 consts->resolver)); in cupsResolveConflicts()
281 cupsArrayAdd(pass, consts->resolver); in cupsResolveConflicts()
282 cupsArrayAdd(resolvers, consts->resolver); in cupsResolveConflicts()
284 for (resval = resolver->value; *resval && !changed;) in cupsResolveConflicts()
295 if (resptr < (resoption + sizeof(resoption) - 1)) in cupsResolveConflicts()
306 if (resptr < (reschoice + sizeof(reschoice) - 1)) in cupsResolveConflicts()
315 * Is this the option we are changing? in cupsResolveConflicts()
320 if (option && in cupsResolveConflicts()
321 (!_cups_strcasecmp(resoption, option) || in cupsResolveConflicts()
322 !_cups_strcasecmp(firstpage, option) || in cupsResolveConflicts()
323 (!_cups_strcasecmp(option, "PageSize") && in cupsResolveConflicts()
325 (!_cups_strcasecmp(option, "AP_FIRSTPAGE_PageSize") && in cupsResolveConflicts()
327 (!_cups_strcasecmp(option, "AP_FIRSTPAGE_PageSize") && in cupsResolveConflicts()
329 (!_cups_strcasecmp(option, "PageRegion") && in cupsResolveConflicts()
331 (!_cups_strcasecmp(option, "AP_FIRSTPAGE_PageRegion") && in cupsResolveConflicts()
333 (!_cups_strcasecmp(option, "AP_FIRSTPAGE_PageRegion") && in cupsResolveConflicts()
355 * Add the option/choice from the resolver regardless of whether it in cupsResolveConflicts()
367 * Try resolving by choosing the default values for non-installable in cupsResolveConflicts()
376 for (i = consts->num_constraints, constptr = consts->constraints; in cupsResolveConflicts()
378 i --, constptr ++) in cupsResolveConflicts()
381 * Can't resolve by changing an installable option... in cupsResolveConflicts()
384 if (constptr->installable) in cupsResolveConflicts()
388 * Is this the option we are changing? in cupsResolveConflicts()
391 if (option && in cupsResolveConflicts()
392 (!_cups_strcasecmp(constptr->option->keyword, option) || in cupsResolveConflicts()
393 (!_cups_strcasecmp(option, "PageSize") && in cupsResolveConflicts()
394 !_cups_strcasecmp(constptr->option->keyword, "PageRegion")) || in cupsResolveConflicts()
395 (!_cups_strcasecmp(option, "PageRegion") && in cupsResolveConflicts()
396 !_cups_strcasecmp(constptr->option->keyword, "PageSize")))) in cupsResolveConflicts()
400 * Get the current option choice... in cupsResolveConflicts()
403 if ((value = cupsGetOption(constptr->option->keyword, num_newopts, in cupsResolveConflicts()
406 if (!_cups_strcasecmp(constptr->option->keyword, "PageSize") || in cupsResolveConflicts()
407 !_cups_strcasecmp(constptr->option->keyword, "PageRegion")) in cupsResolveConflicts()
416 value = size->name; in cupsResolveConflicts()
423 marked = ppdFindMarkedChoice(ppd, constptr->option->keyword); in cupsResolveConflicts()
424 value = marked ? marked->choice : ""; in cupsResolveConflicts()
437 if (_cups_strcasecmp(value, constptr->option->defchoice) && in cupsResolveConflicts()
438 (test = ppd_test_constraints(ppd, constptr->option->keyword, in cupsResolveConflicts()
439 constptr->option->defchoice, in cupsResolveConflicts()
447 num_newopts = cupsAddOption(constptr->option->keyword, in cupsResolveConflicts()
448 constptr->option->defchoice, in cupsResolveConflicts()
458 for (j = constptr->option->num_choices, in cupsResolveConflicts()
459 cptr = constptr->option->choices; in cupsResolveConflicts()
461 j --, cptr ++) in cupsResolveConflicts()
466 if (_cups_strcasecmp(value, cptr->choice) && in cupsResolveConflicts()
467 _cups_strcasecmp(constptr->option->defchoice, cptr->choice) && in cupsResolveConflicts()
468 _cups_strcasecmp("Custom", cptr->choice) && in cupsResolveConflicts()
469 (test = ppd_test_constraints(ppd, constptr->option->keyword, in cupsResolveConflicts()
470 cptr->choice, num_newopts, in cupsResolveConflicts()
478 num_newopts = cupsAddOption(constptr->option->keyword, in cupsResolveConflicts()
479 cptr->choice, num_newopts, in cupsResolveConflicts()
508 * Free the caller's option array... in cupsResolveConflicts()
514 * If Collate is the option we are testing, add it here. Otherwise, remove in cupsResolveConflicts()
515 * any Collate option from the resolve list since the filters automatically in cupsResolveConflicts()
519 if (option && !_cups_strcasecmp(option, "Collate")) in cupsResolveConflicts()
520 num_newopts = cupsAddOption(option, choice, num_newopts, &newopts); in cupsResolveConflicts()
534 cupsArrayRestore(ppd->sorted_attrs); in cupsResolveConflicts()
557 cupsArrayRestore(ppd->sorted_attrs); in cupsResolveConflicts()
566 * 'ppdConflicts()' - Check to see if there are any conflicts among the
567 * marked option choices.
572 int /* O - Number of conflicts found */
573 ppdConflicts(ppd_file_t *ppd) /* I - PPD to check */ in ppdConflicts()
580 ppd_option_t *o; /* Current option */ in ppdConflicts()
590 cupsArraySave(ppd->options); in ppdConflicts()
593 o->conflicted = 0; in ppdConflicts()
595 cupsArrayRestore(ppd->options); in ppdConflicts()
614 for (i = c->num_constraints, cptr = c->constraints; in ppdConflicts()
616 i --, cptr ++) in ppdConflicts()
617 cptr->option->conflicted = 1; in ppdConflicts()
631 * 'ppdInstallableConflict()' - Test whether an option choice conflicts with
632 * an installable option.
634 * This function tests whether a particular option choice is available based
640 int /* O - 1 if conflicting, 0 if not conflicting */
642 ppd_file_t *ppd, /* I - PPD file */ in ppdInstallableConflict()
643 const char *option, /* I - Option */ in ppdInstallableConflict() argument
644 const char *choice) /* I - Choice */ in ppdInstallableConflict()
649 DEBUG_printf(("2ppdInstallableConflict(ppd=%p, option=\"%s\", choice=\"%s\")", in ppdInstallableConflict()
650 ppd, option, choice)); in ppdInstallableConflict()
656 if (!ppd || !option || !choice) in ppdInstallableConflict()
660 * Test constraints using the new option... in ppdInstallableConflict()
663 active = ppd_test_constraints(ppd, option, choice, 0, NULL, in ppdInstallableConflict()
673 * 'ppd_is_installable()' - Determine whether an option is in the
677 static int /* O - 1 if installable, 0 if normal */
679 ppd_group_t *installable, /* I - InstallableOptions group */ in ppd_is_installable()
680 const char *name) /* I - Option name */ in ppd_is_installable()
685 ppd_option_t *option; /* Current option */ in ppd_is_installable() local
688 for (i = installable->num_options, option = installable->options; in ppd_is_installable()
690 i --, option ++) in ppd_is_installable()
691 if (!_cups_strcasecmp(option->keyword, name)) in ppd_is_installable()
700 * 'ppd_load_constraints()' - Load constraints from a PPD file.
704 ppd_load_constraints(ppd_file_t *ppd) /* I - PPD file */ in ppd_load_constraints()
713 char option[PPD_MAX_NAME], /* Option name/MainKeyword */ in ppd_load_constraints() local
715 *ptr; /* Pointer into option or choice */ in ppd_load_constraints()
724 ppd->cups_uiconstraints = cupsArrayNew(NULL, NULL); in ppd_load_constraints()
730 for (i = ppd->num_groups, installable = ppd->groups; in ppd_load_constraints()
732 i --, installable ++) in ppd_load_constraints()
733 if (!_cups_strcasecmp(installable->name, "InstallableOptions")) in ppd_load_constraints()
740 * Load old-style [Non]UIConstraints data... in ppd_load_constraints()
743 for (i = ppd->num_consts, oldconst = ppd->consts; i > 0; i --, oldconst ++) in ppd_load_constraints()
780 consts->num_constraints = 2; in ppd_load_constraints()
781 consts->constraints = constptr; in ppd_load_constraints()
783 if (!_cups_strncasecmp(oldconst->option1, "Custom", 6) && in ppd_load_constraints()
784 !_cups_strcasecmp(oldconst->choice1, "True")) in ppd_load_constraints()
786 constptr[0].option = ppdFindOption(ppd, oldconst->option1 + 6); in ppd_load_constraints()
787 constptr[0].choice = ppdFindChoice(constptr[0].option, "Custom"); in ppd_load_constraints()
792 constptr[0].option = ppdFindOption(ppd, oldconst->option1); in ppd_load_constraints()
793 constptr[0].choice = ppdFindChoice(constptr[0].option, in ppd_load_constraints()
794 oldconst->choice1); in ppd_load_constraints()
796 oldconst->option1); in ppd_load_constraints()
799 if (!constptr[0].option || (!constptr[0].choice && oldconst->choice1[0])) in ppd_load_constraints()
801 DEBUG_printf(("8ppd_load_constraints: Unknown option *%s %s!", in ppd_load_constraints()
802 oldconst->option1, oldconst->choice1)); in ppd_load_constraints()
803 free(consts->constraints); in ppd_load_constraints()
808 if (!_cups_strncasecmp(oldconst->option2, "Custom", 6) && in ppd_load_constraints()
809 !_cups_strcasecmp(oldconst->choice2, "True")) in ppd_load_constraints()
811 constptr[1].option = ppdFindOption(ppd, oldconst->option2 + 6); in ppd_load_constraints()
812 constptr[1].choice = ppdFindChoice(constptr[1].option, "Custom"); in ppd_load_constraints()
817 constptr[1].option = ppdFindOption(ppd, oldconst->option2); in ppd_load_constraints()
818 constptr[1].choice = ppdFindChoice(constptr[1].option, in ppd_load_constraints()
819 oldconst->choice2); in ppd_load_constraints()
821 oldconst->option2); in ppd_load_constraints()
824 if (!constptr[1].option || (!constptr[1].choice && oldconst->choice2[0])) in ppd_load_constraints()
826 DEBUG_printf(("8ppd_load_constraints: Unknown option *%s %s!", in ppd_load_constraints()
827 oldconst->option2, oldconst->choice2)); in ppd_load_constraints()
828 free(consts->constraints); in ppd_load_constraints()
833 consts->installable = constptr[0].installable || constptr[1].installable; in ppd_load_constraints()
839 cupsArrayAdd(ppd->cups_uiconstraints, consts); in ppd_load_constraints()
843 * Then load new-style constraints... in ppd_load_constraints()
850 if (!constattr->value) in ppd_load_constraints()
856 for (i = 0, vptr = strchr(constattr->value, '*'); in ppd_load_constraints()
881 consts->num_constraints = i; in ppd_load_constraints()
882 consts->constraints = constptr; in ppd_load_constraints()
884 strlcpy(consts->resolver, constattr->spec, sizeof(consts->resolver)); in ppd_load_constraints()
886 for (i = 0, vptr = strchr(constattr->value, '*'); in ppd_load_constraints()
891 * Extract "*Option Choice" or just "*Option"... in ppd_load_constraints()
894 for (vptr ++, ptr = option; *vptr && !_cups_isspace(*vptr); vptr ++) in ppd_load_constraints()
895 if (ptr < (option + sizeof(option) - 1)) in ppd_load_constraints()
908 if (ptr < (choice + sizeof(choice) - 1)) in ppd_load_constraints()
914 if (!_cups_strncasecmp(option, "Custom", 6) && !_cups_strcasecmp(choice, "True")) in ppd_load_constraints()
916 _cups_strcpy(option, option + 6); in ppd_load_constraints()
920 constptr->option = ppdFindOption(ppd, option); in ppd_load_constraints()
921 constptr->choice = ppdFindChoice(constptr->option, choice); in ppd_load_constraints()
922 constptr->installable = ppd_is_installable(installable, option); in ppd_load_constraints()
923 consts->installable |= constptr->installable; in ppd_load_constraints()
925 if (!constptr->option || (!constptr->choice && choice[0])) in ppd_load_constraints()
927 DEBUG_printf(("8ppd_load_constraints: Unknown option *%s %s!", in ppd_load_constraints()
928 option, choice)); in ppd_load_constraints()
934 cupsArrayAdd(ppd->cups_uiconstraints, consts); in ppd_load_constraints()
937 free(consts->constraints); in ppd_load_constraints()
945 * 'ppd_test_constraints()' - See if any constraints are active.
948 static cups_array_t * /* O - Array of active constraints */
950 ppd_file_t *ppd, /* I - PPD file */ in ppd_test_constraints()
951 const char *option, /* I - Current option */ in ppd_test_constraints() argument
952 const char *choice, /* I - Current choice */ in ppd_test_constraints()
953 int num_options, /* I - Number of additional options */ in ppd_test_constraints()
954 cups_option_t *options, /* I - Additional options */ in ppd_test_constraints()
955 int which) /* I - Which constraints to test */ in ppd_test_constraints()
968 DEBUG_printf(("7ppd_test_constraints(ppd=%p, option=\"%s\", choice=\"%s\", " in ppd_test_constraints()
969 "num_options=%d, options=%p, which=%d)", ppd, option, choice, in ppd_test_constraints()
972 if (!ppd->cups_uiconstraints) in ppd_test_constraints()
976 cupsArrayCount(ppd->cups_uiconstraints))); in ppd_test_constraints()
978 cupsArraySave(ppd->marked); in ppd_test_constraints()
980 for (consts = (_ppd_cups_uiconsts_t *)cupsArrayFirst(ppd->cups_uiconstraints); in ppd_test_constraints()
982 consts = (_ppd_cups_uiconsts_t *)cupsArrayNext(ppd->cups_uiconstraints)) in ppd_test_constraints()
987 consts->installable, consts->resolver, consts->num_constraints, in ppd_test_constraints()
988 consts->constraints[0].option->keyword, in ppd_test_constraints()
989 consts->constraints[0].choice ? in ppd_test_constraints()
990 consts->constraints[0].choice->choice : "", in ppd_test_constraints()
991 consts->constraints[1].option->keyword, in ppd_test_constraints()
992 consts->constraints[1].choice ? in ppd_test_constraints()
993 consts->constraints[1].choice->choice : "")); in ppd_test_constraints()
995 if (consts->installable && which < _PPD_INSTALLABLE_CONSTRAINTS) in ppd_test_constraints()
996 continue; /* Skip installable option constraint */ in ppd_test_constraints()
998 if (!consts->installable && which == _PPD_INSTALLABLE_CONSTRAINTS) in ppd_test_constraints()
999 continue; /* Skip non-installable option constraint */ in ppd_test_constraints()
1001 if (which == _PPD_OPTION_CONSTRAINTS && option) in ppd_test_constraints()
1004 * Skip constraints that do not involve the current option... in ppd_test_constraints()
1007 for (i = consts->num_constraints, constptr = consts->constraints; in ppd_test_constraints()
1009 i --, constptr ++) in ppd_test_constraints()
1011 if (!_cups_strcasecmp(constptr->option->keyword, option)) in ppd_test_constraints()
1014 if (!_cups_strncasecmp(option, "AP_FIRSTPAGE_", 13) && in ppd_test_constraints()
1015 !_cups_strcasecmp(constptr->option->keyword, option + 13)) in ppd_test_constraints()
1025 for (i = consts->num_constraints, constptr = consts->constraints; in ppd_test_constraints()
1027 i --, constptr ++) in ppd_test_constraints()
1029 DEBUG_printf(("9ppd_test_constraints: %s=%s?", constptr->option->keyword, in ppd_test_constraints()
1030 constptr->choice ? constptr->choice->choice : "")); in ppd_test_constraints()
1032 if (constptr->choice && in ppd_test_constraints()
1033 (!_cups_strcasecmp(constptr->option->keyword, "PageSize") || in ppd_test_constraints()
1034 !_cups_strcasecmp(constptr->option->keyword, "PageRegion"))) in ppd_test_constraints()
1039 * of an individual option... in ppd_test_constraints()
1042 if (option && choice && in ppd_test_constraints()
1043 (!_cups_strcasecmp(option, "PageSize") || in ppd_test_constraints()
1044 !_cups_strcasecmp(option, "PageRegion"))) in ppd_test_constraints()
1057 value = size->name; in ppd_test_constraints()
1063 if (option && choice && in ppd_test_constraints()
1064 (!_cups_strcasecmp(option, "AP_FIRSTPAGE_PageSize") || in ppd_test_constraints()
1065 !_cups_strcasecmp(option, "AP_FIRSTPAGE_PageRegion"))) in ppd_test_constraints()
1077 if ((!value || _cups_strcasecmp(value, constptr->choice->choice)) && in ppd_test_constraints()
1078 (!firstvalue || _cups_strcasecmp(firstvalue, constptr->choice->choice))) in ppd_test_constraints()
1084 else if (constptr->choice) in ppd_test_constraints()
1090 if (option && choice && !_cups_strcasecmp(option, constptr->option->keyword)) in ppd_test_constraints()
1097 else if ((value = cupsGetOption(constptr->option->keyword, num_options, in ppd_test_constraints()
1103 else if (constptr->choice->marked) in ppd_test_constraints()
1104 value = constptr->choice->choice; in ppd_test_constraints()
1113 constptr->option->keyword); in ppd_test_constraints()
1115 if (option && choice && !_cups_strcasecmp(option, firstpage)) in ppd_test_constraints()
1134 if ((!value || _cups_strcasecmp(value, constptr->choice->choice)) && in ppd_test_constraints()
1135 (!firstvalue || _cups_strcasecmp(firstvalue, constptr->choice->choice))) in ppd_test_constraints()
1141 else if (option && choice && in ppd_test_constraints()
1142 !_cups_strcasecmp(option, constptr->option->keyword)) in ppd_test_constraints()
1151 else if ((value = cupsGetOption(constptr->option->keyword, num_options, in ppd_test_constraints()
1163 key.option = constptr->option; in ppd_test_constraints()
1165 if ((marked = (ppd_choice_t *)cupsArrayFind(ppd->marked, &key)) in ppd_test_constraints()
1167 (!_cups_strcasecmp(marked->choice, "None") || in ppd_test_constraints()
1168 !_cups_strcasecmp(marked->choice, "Off") || in ppd_test_constraints()
1169 !_cups_strcasecmp(marked->choice, "False"))) in ppd_test_constraints()
1187 cupsArrayRestore(ppd->marked); in ppd_test_constraints()