]>
git.ipfire.org Git - thirdparty/cups.git/blob - cups/mark.c
2 * "$Id: mark.c 4494 2005-02-18 02:18:11Z mike $"
4 * Option marking routines for the Common UNIX Printing System (CUPS).
6 * Copyright 1997-2005 by Easy Software Products, all rights reserved.
8 * These coded instructions, statements, and computer programs are the
9 * property of Easy Software Products and are protected by Federal
10 * copyright law. Distribution and use rights are outlined in the file
11 * "LICENSE.txt" which should have been included with this file. If this
12 * file is missing or damaged please contact Easy Software Products
15 * Attn: CUPS Licensing Information
16 * Easy Software Products
17 * 44141 Airport View Drive, Suite 204
18 * Hollywood, Maryland 20636 USA
20 * Voice: (301) 373-9600
21 * EMail: cups-info@cups.org
22 * WWW: http://www.cups.org
24 * PostScript is a trademark of Adobe Systems, Inc.
26 * This file is subject to the Apple OS-Developed Software exception.
30 * ppdConflicts() - Check to see if there are any conflicts.
31 * ppdFindChoice() - Return a pointer to an option choice.
32 * ppdFindMarkedChoice() - Return the marked choice for the specified option.
33 * ppdFindOption() - Return a pointer to the specified option.
34 * ppdIsMarked() - Check to see if an option is marked...
35 * ppdMarkDefaults() - Mark all default options in the PPD file.
36 * ppdMarkOption() - Mark an option in a PPD file.
37 * ppd_defaults() - Set the defaults for this group and all sub-groups.
41 * Include necessary headers...
53 static void ppd_defaults(ppd_file_t
*ppd
, ppd_group_t
*g
);
57 * 'ppdConflicts()' - Check to see if there are any conflicts.
60 int /* O - Number of conflicts found */
61 ppdConflicts(ppd_file_t
*ppd
) /* I - PPD to check */
63 int i
, j
, k
, /* Looping variables */
64 conflicts
; /* Number of conflicts */
65 ppd_const_t
*c
; /* Current constraint */
66 ppd_group_t
*g
, *sg
; /* Groups */
67 ppd_option_t
*o1
, *o2
; /* Options */
68 ppd_choice_t
*c1
, *c2
; /* Choices */
75 * Clear all conflicts...
80 for (i
= ppd
->num_groups
, g
= ppd
->groups
; i
> 0; i
--, g
++)
82 for (j
= g
->num_options
, o1
= g
->options
; j
> 0; j
--, o1
++)
85 for (j
= g
->num_subgroups
, sg
= g
->subgroups
; j
> 0; j
--, sg
++)
86 for (k
= sg
->num_options
, o1
= sg
->options
; k
> 0; k
--, o1
++)
91 * Loop through all of the UI constraints and flag any options
95 for (i
= ppd
->num_consts
, c
= ppd
->consts
; i
> 0; i
--, c
++)
98 * Grab pointers to the first option...
101 o1
= ppdFindOption(ppd
, c
->option1
);
105 else if (c
->choice1
[0] != '\0')
108 * This constraint maps to a specific choice.
111 c1
= ppdFindChoice(o1
, c
->choice1
);
116 * This constraint applies to any choice for this option.
119 for (j
= o1
->num_choices
, c1
= o1
->choices
; j
> 0; j
--, c1
++)
124 strcasecmp(c1
->choice
, "None") == 0 ||
125 strcasecmp(c1
->choice
, "Off") == 0 ||
126 strcasecmp(c1
->choice
, "False") == 0)
131 * Grab pointers to the second option...
134 o2
= ppdFindOption(ppd
, c
->option2
);
138 else if (c
->choice2
[0] != '\0')
141 * This constraint maps to a specific choice.
144 c2
= ppdFindChoice(o2
, c
->choice2
);
149 * This constraint applies to any choice for this option.
152 for (j
= o2
->num_choices
, c2
= o2
->choices
; j
> 0; j
--, c2
++)
157 strcasecmp(c2
->choice
, "None") == 0 ||
158 strcasecmp(c2
->choice
, "Off") == 0 ||
159 strcasecmp(c2
->choice
, "False") == 0)
164 * If both options are marked then there is a conflict...
167 if (c1
!= NULL
&& c1
->marked
&&
168 c2
!= NULL
&& c2
->marked
)
170 DEBUG_printf(("%s->%s conflicts with %s->%s (%s %s %s %s)\n",
171 o1
->keyword
, c1
->choice
, o2
->keyword
, c2
->choice
,
172 c
->option1
, c
->choice1
, c
->option2
, c
->choice2
));
180 * Return the number of conflicts found...
188 * 'ppdFindChoice()' - Return a pointer to an option choice.
191 ppd_choice_t
* /* O - Choice pointer or NULL */
192 ppdFindChoice(ppd_option_t
*o
, /* I - Pointer to option */
193 const char *choice
) /* I - Name of choice */
195 int i
; /* Looping var */
196 ppd_choice_t
*c
; /* Current choice */
199 if (o
== NULL
|| choice
== NULL
)
202 for (i
= o
->num_choices
, c
= o
->choices
; i
> 0; i
--, c
++)
203 if (strcasecmp(c
->choice
, choice
) == 0)
211 * 'ppdFindMarkedChoice()' - Return the marked choice for the specified option.
214 ppd_choice_t
* /* O - Pointer to choice or NULL */
215 ppdFindMarkedChoice(ppd_file_t
*ppd
, /* I - PPD file */
216 const char *option
) /* I - Keyword/option name */
218 int i
; /* Looping var */
219 ppd_option_t
*o
; /* Pointer to option */
220 ppd_choice_t
*c
; /* Pointer to choice */
223 if ((o
= ppdFindOption(ppd
, option
)) == NULL
)
226 for (i
= o
->num_choices
, c
= o
->choices
; i
> 0; i
--, c
++)
235 * 'ppdFindOption()' - Return a pointer to the specified option.
238 ppd_option_t
* /* O - Pointer to option or NULL */
239 ppdFindOption(ppd_file_t
*ppd
, /* I - PPD file data */
240 const char *option
) /* I - Option/Keyword name */
242 int i
, j
, k
; /* Looping vars */
243 ppd_option_t
*o
; /* Pointer to option */
244 ppd_group_t
*g
, /* Pointer to group */
245 *sg
; /* Pointer to subgroup */
248 if (ppd
== NULL
|| option
== NULL
)
251 for (i
= ppd
->num_groups
, g
= ppd
->groups
; i
> 0; i
--, g
++)
253 for (j
= g
->num_options
, o
= g
->options
; j
> 0; j
--, o
++)
254 if (strcasecmp(o
->keyword
, option
) == 0)
257 for (j
= g
->num_subgroups
, sg
= g
->subgroups
; j
> 0; j
--, sg
++)
258 for (k
= sg
->num_options
, o
= sg
->options
; k
> 0; k
--, o
++)
259 if (strcasecmp(o
->keyword
, option
) == 0)
268 * 'ppdIsMarked()' - Check to see if an option is marked...
271 int /* O - Non-zero if option is marked */
272 ppdIsMarked(ppd_file_t
*ppd
, /* I - PPD file data */
273 const char *option
, /* I - Option/Keyword name */
274 const char *choice
) /* I - Choice name */
276 ppd_option_t
*o
; /* Option pointer */
277 ppd_choice_t
*c
; /* Choice pointer */
283 if ((o
= ppdFindOption(ppd
, option
)) == NULL
)
286 if ((c
= ppdFindChoice(o
, choice
)) == NULL
)
294 * 'ppdMarkDefaults()' - Mark all default options in the PPD file.
298 ppdMarkDefaults(ppd_file_t
*ppd
)/* I - PPD file record */
300 int i
; /* Looping variables */
301 ppd_group_t
*g
; /* Current group */
307 for (i
= ppd
->num_groups
, g
= ppd
->groups
; i
> 0; i
--, g
++)
308 ppd_defaults(ppd
, g
);
313 * 'ppdMarkOption()' - Mark an option in a PPD file.
317 * -1 is returned if the given option would conflict with any currently
321 int /* O - Number of conflicts */
322 ppdMarkOption(ppd_file_t
*ppd
, /* I - PPD file record */
323 const char *option
, /* I - Keyword */
324 const char *choice
) /* I - Option name */
326 int i
; /* Looping var */
327 ppd_option_t
*o
; /* Option pointer */
328 ppd_choice_t
*c
; /* Choice pointer */
334 if (strcasecmp(option
, "PageSize") == 0 && strncasecmp(choice
, "Custom.", 7) == 0)
337 * Handle variable page sizes...
340 ppdPageSize(ppd
, choice
);
344 if ((o
= ppdFindOption(ppd
, option
)) == NULL
)
347 for (i
= o
->num_choices
, c
= o
->choices
; i
> 0; i
--, c
++)
348 if (strcasecmp(c
->choice
, choice
) == 0)
354 * Option found; mark it and then handle unmarking any other options.
359 if (o
->ui
!= PPD_UI_PICKMANY
)
360 for (i
= o
->num_choices
, c
= o
->choices
; i
> 0; i
--, c
++)
361 if (strcasecmp(c
->choice
, choice
) != 0)
364 if (strcasecmp(option
, "PageSize") == 0 || strcasecmp(option
, "PageRegion") == 0)
367 * Mark current page size...
370 for (i
= 0; i
< ppd
->num_sizes
; i
++)
371 ppd
->sizes
[i
].marked
= strcasecmp(ppd
->sizes
[i
].name
, choice
) == 0;
374 * Unmark the current PageSize or PageRegion setting, as appropriate...
377 if (strcasecmp(option
, "PageSize") == 0)
379 if ((o
= ppdFindOption(ppd
, "PageRegion")) != NULL
)
380 for (i
= 0; i
< o
->num_choices
; i
++)
381 o
->choices
[i
].marked
= 0;
385 if ((o
= ppdFindOption(ppd
, "PageSize")) != NULL
)
386 for (i
= 0; i
< o
->num_choices
; i
++)
387 o
->choices
[i
].marked
= 0;
390 else if (strcasecmp(option
, "InputSlot") == 0)
393 * Unmark ManualFeed option...
396 if ((o
= ppdFindOption(ppd
, "ManualFeed")) != NULL
)
397 for (i
= 0; i
< o
->num_choices
; i
++)
398 o
->choices
[i
].marked
= 0;
400 else if (strcasecmp(option
, "ManualFeed") == 0)
403 * Unmark InputSlot option...
406 if ((o
= ppdFindOption(ppd
, "InputSlot")) != NULL
)
407 for (i
= 0; i
< o
->num_choices
; i
++)
408 o
->choices
[i
].marked
= 0;
412 return (ppdConflicts(ppd
));
417 * 'ppd_defaults()' - Set the defaults for this group and all sub-groups.
421 ppd_defaults(ppd_file_t
*ppd
, /* I - PPD file */
422 ppd_group_t
*g
) /* I - Group to default */
424 int i
; /* Looping var */
425 ppd_option_t
*o
; /* Current option */
426 ppd_group_t
*sg
; /* Current sub-group */
432 for (i
= g
->num_options
, o
= g
->options
; i
> 0; i
--, o
++)
433 if (strcasecmp(o
->keyword
, "PageRegion") != 0)
434 ppdMarkOption(ppd
, o
->keyword
, o
->defchoice
);
436 for (i
= g
->num_subgroups
, sg
= g
->subgroups
; i
> 0; i
--, sg
++)
437 ppd_defaults(ppd
, sg
);
442 * End of "$Id: mark.c 4494 2005-02-18 02:18:11Z mike $".