]>
git.ipfire.org Git - thirdparty/cups.git/blob - cups/mark.c
2 * "$Id: mark.c,v 1.20 2000/01/04 13:45:35 mike Exp $"
4 * Option marking routines for the Common UNIX Printing System (CUPS).
6 * Copyright 1997-2000 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-3111 USA
20 * Voice: (301) 373-9603
21 * EMail: cups-info@cups.org
22 * WWW: http://www.cups.org
24 * PostScript is a trademark of Adobe Systems, Inc.
28 * ppdConflicts() - Check to see if there are any conflicts.
29 * ppdFindChoice() - Return a pointer to an option choice.
30 * ppdFindMarkedChoice() - Return the marked choice for the specified option.
31 * ppdFindOption() - Return a pointer to the specified option.
32 * ppdIsMarked() - Check to see if an option is marked...
33 * ppdMarkDefaults() - Mark all default options in the PPD file.
34 * ppdMarkOption() - Mark an option in a PPD file.
35 * ppd_defaults() - Set the defaults for this group and all sub-groups.
39 * Include necessary headers...
50 static void ppd_defaults(ppd_file_t
*ppd
, ppd_group_t
*g
);
54 * 'ppdConflicts()' - Check to see if there are any conflicts.
57 int /* O - Number of conflicts found */
58 ppdConflicts(ppd_file_t
*ppd
) /* I - PPD to check */
60 int i
, j
, k
, /* Looping variables */
61 conflicts
; /* Number of conflicts */
62 ppd_const_t
*c
; /* Current constraint */
63 ppd_group_t
*g
, *sg
; /* Groups */
64 ppd_option_t
*o1
, *o2
; /* Options */
65 ppd_choice_t
*c1
, *c2
; /* Choices */
72 * Clear all conflicts...
77 for (i
= ppd
->num_groups
, g
= ppd
->groups
; i
> 0; i
--, g
++)
79 for (j
= g
->num_options
, o1
= g
->options
; j
> 0; j
--, o1
++)
82 for (j
= g
->num_subgroups
, sg
= g
->subgroups
; j
> 0; j
--, sg
++)
83 for (k
= sg
->num_options
, o1
= sg
->options
; k
> 0; k
--, o1
++)
88 * Loop through all of the UI constraints and flag any options
92 for (i
= ppd
->num_consts
, c
= ppd
->consts
; i
> 0; i
--, c
++)
95 * Grab pointers to the first option...
98 o1
= ppdFindOption(ppd
, c
->option1
);
102 else if (c
->choice1
[0] != '\0')
105 * This constraint maps to a specific choice.
108 c1
= ppdFindChoice(o1
, c
->choice1
);
113 * This constraint applies to any choice for this option.
116 for (j
= o1
->num_choices
, c1
= o1
->choices
; j
> 0; j
--, c1
++)
120 if (j
== 0 || strcasecmp(c1
->choice
, "None") == 0)
125 * Grab pointers to the second option...
128 o2
= ppdFindOption(ppd
, c
->option2
);
132 else if (c
->choice2
[0] != '\0')
135 * This constraint maps to a specific choice.
138 c2
= ppdFindChoice(o2
, c
->choice2
);
143 * This constraint applies to any choice for this option.
146 for (j
= o2
->num_choices
, c2
= o2
->choices
; j
> 0; j
--, c2
++)
150 if (j
== 0 || strcasecmp(c2
->choice
, "None") == 0)
155 * If both options are marked then there is a conflict...
158 if (c1
!= NULL
&& c1
->marked
&&
159 c2
!= NULL
&& c2
->marked
)
168 * Return the number of conflicts found...
176 * 'ppdFindChoice()' - Return a pointer to an option choice.
179 ppd_choice_t
* /* O - Choice pointer or NULL */
180 ppdFindChoice(ppd_option_t
*o
, /* I - Pointer to option */
181 const char *choice
) /* I - Name of choice */
183 int i
; /* Looping var */
184 ppd_choice_t
*c
; /* Current choice */
187 if (o
== NULL
|| choice
== NULL
)
190 for (i
= o
->num_choices
, c
= o
->choices
; i
> 0; i
--, c
++)
191 if (strcasecmp(c
->choice
, choice
) == 0)
199 * 'ppdFindMarkedChoice()' - Return the marked choice for the specified option.
202 ppd_choice_t
* /* O - Pointer to choice or NULL */
203 ppdFindMarkedChoice(ppd_file_t
*ppd
, /* I - PPD file */
204 const char *option
) /* I - Keyword/option name */
206 int i
; /* Looping var */
207 ppd_option_t
*o
; /* Pointer to option */
208 ppd_choice_t
*c
; /* Pointer to choice */
211 if ((o
= ppdFindOption(ppd
, option
)) == NULL
)
214 for (i
= o
->num_choices
, c
= o
->choices
; i
> 0; i
--, c
++)
223 * 'ppdFindOption()' - Return a pointer to the specified option.
226 ppd_option_t
* /* O - Pointer to option or NULL */
227 ppdFindOption(ppd_file_t
*ppd
, /* I - PPD file data */
228 const char *option
) /* I - Option/Keyword name */
230 int i
, j
, k
; /* Looping vars */
231 ppd_option_t
*o
; /* Pointer to option */
232 ppd_group_t
*g
, /* Pointer to group */
233 *sg
; /* Pointer to subgroup */
236 if (ppd
== NULL
|| option
== NULL
)
239 for (i
= ppd
->num_groups
, g
= ppd
->groups
; i
> 0; i
--, g
++)
241 for (j
= g
->num_options
, o
= g
->options
; j
> 0; j
--, o
++)
242 if (strcasecmp(o
->keyword
, option
) == 0)
245 for (j
= g
->num_subgroups
, sg
= g
->subgroups
; j
> 0; j
--, sg
++)
246 for (k
= sg
->num_options
, o
= sg
->options
; k
> 0; k
--, o
++)
247 if (strcasecmp(o
->keyword
, option
) == 0)
256 * 'ppdIsMarked()' - Check to see if an option is marked...
259 int /* O - Non-zero if option is marked */
260 ppdIsMarked(ppd_file_t
*ppd
, /* I - PPD file data */
261 const char *option
, /* I - Option/Keyword name */
262 const char *choice
) /* I - Choice name */
264 ppd_option_t
*o
; /* Option pointer */
265 ppd_choice_t
*c
; /* Choice pointer */
271 if ((o
= ppdFindOption(ppd
, option
)) == NULL
)
274 if ((c
= ppdFindChoice(o
, choice
)) == NULL
)
282 * 'ppdMarkDefaults()' - Mark all default options in the PPD file.
286 ppdMarkDefaults(ppd_file_t
*ppd
)/* I - PPD file record */
288 int i
; /* Looping variables */
289 ppd_group_t
*g
; /* Current group */
295 for (i
= ppd
->num_groups
, g
= ppd
->groups
; i
> 0; i
--, g
++)
296 ppd_defaults(ppd
, g
);
301 * 'ppdMarkOption()' - Mark an option in a PPD file.
305 * -1 is returned if the given option would conflict with any currently
309 int /* O - Number of conflicts */
310 ppdMarkOption(ppd_file_t
*ppd
, /* I - PPD file record */
311 const char *option
, /* I - Keyword */
312 const char *choice
) /* I - Option name */
314 int i
; /* Looping var */
315 ppd_option_t
*o
; /* Option pointer */
316 ppd_choice_t
*c
; /* Choice pointer */
322 if (strcasecmp(option
, "PageSize") == 0 && strncasecmp(choice
, "Custom.", 7) == 0)
325 * Handle variable page sizes...
328 ppdPageSize(ppd
, choice
);
332 if ((o
= ppdFindOption(ppd
, option
)) == NULL
)
335 for (i
= o
->num_choices
, c
= o
->choices
; i
> 0; i
--, c
++)
336 if (strcasecmp(c
->choice
, choice
) == 0)
342 * Option found; mark it and then handle unmarking any other options.
347 if (o
->ui
!= PPD_UI_PICKMANY
)
348 for (i
= o
->num_choices
, c
= o
->choices
; i
> 0; i
--, c
++)
349 if (strcasecmp(c
->choice
, choice
) != 0)
352 if (strcasecmp(option
, "PageSize") == 0 || strcasecmp(option
, "PageRegion") == 0)
355 * Mark current page size...
358 for (i
= 0; i
< ppd
->num_sizes
; i
++)
359 ppd
->sizes
[i
].marked
= strcasecmp(ppd
->sizes
[i
].name
, choice
) == 0;
362 * Unmark the current PageSize or PageRegion setting, as appropriate...
365 if (strcasecmp(option
, "PageSize") == 0)
367 if ((o
= ppdFindOption(ppd
, "PageRegion")) != NULL
)
368 for (i
= 0; i
< o
->num_choices
; i
++)
369 o
->choices
[i
].marked
= 0;
373 if ((o
= ppdFindOption(ppd
, "PageSize")) != NULL
)
374 for (i
= 0; i
< o
->num_choices
; i
++)
375 o
->choices
[i
].marked
= 0;
380 return (ppdConflicts(ppd
));
385 * 'ppd_defaults()' - Set the defaults for this group and all sub-groups.
389 ppd_defaults(ppd_file_t
*ppd
, /* I - PPD file */
390 ppd_group_t
*g
) /* I - Group to default */
392 int i
; /* Looping var */
393 ppd_option_t
*o
; /* Current option */
394 ppd_group_t
*sg
; /* Current sub-group */
400 for (i
= g
->num_options
, o
= g
->options
; i
> 0; i
--, o
++)
401 if (strcasecmp(o
->keyword
, "PageRegion") != 0)
402 ppdMarkOption(ppd
, o
->keyword
, o
->defchoice
);
404 for (i
= g
->num_subgroups
, sg
= g
->subgroups
; i
> 0; i
--, sg
++)
405 ppd_defaults(ppd
, sg
);
410 * End of "$Id: mark.c,v 1.20 2000/01/04 13:45:35 mike Exp $".