]> git.ipfire.org Git - thirdparty/cups.git/blob - cups/mark.c
Y2k copyright changes.
[thirdparty/cups.git] / cups / mark.c
1 /*
2 * "$Id: mark.c,v 1.20 2000/01/04 13:45:35 mike Exp $"
3 *
4 * Option marking routines for the Common UNIX Printing System (CUPS).
5 *
6 * Copyright 1997-2000 by Easy Software Products, all rights reserved.
7 *
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
13 * at:
14 *
15 * Attn: CUPS Licensing Information
16 * Easy Software Products
17 * 44141 Airport View Drive, Suite 204
18 * Hollywood, Maryland 20636-3111 USA
19 *
20 * Voice: (301) 373-9603
21 * EMail: cups-info@cups.org
22 * WWW: http://www.cups.org
23 *
24 * PostScript is a trademark of Adobe Systems, Inc.
25 *
26 * Contents:
27 *
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.
36 */
37
38 /*
39 * Include necessary headers...
40 */
41
42 #include "ppd.h"
43 #include "string.h"
44
45
46 /*
47 * Local functions...
48 */
49
50 static void ppd_defaults(ppd_file_t *ppd, ppd_group_t *g);
51
52
53 /*
54 * 'ppdConflicts()' - Check to see if there are any conflicts.
55 */
56
57 int /* O - Number of conflicts found */
58 ppdConflicts(ppd_file_t *ppd) /* I - PPD to check */
59 {
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 */
66
67
68 if (ppd == NULL)
69 return (0);
70
71 /*
72 * Clear all conflicts...
73 */
74
75 conflicts = 0;
76
77 for (i = ppd->num_groups, g = ppd->groups; i > 0; i --, g ++)
78 {
79 for (j = g->num_options, o1 = g->options; j > 0; j --, o1 ++)
80 o1->conflicted = 0;
81
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 ++)
84 o1->conflicted = 0;
85 }
86
87 /*
88 * Loop through all of the UI constraints and flag any options
89 * that conflict...
90 */
91
92 for (i = ppd->num_consts, c = ppd->consts; i > 0; i --, c ++)
93 {
94 /*
95 * Grab pointers to the first option...
96 */
97
98 o1 = ppdFindOption(ppd, c->option1);
99
100 if (o1 == NULL)
101 continue;
102 else if (c->choice1[0] != '\0')
103 {
104 /*
105 * This constraint maps to a specific choice.
106 */
107
108 c1 = ppdFindChoice(o1, c->choice1);
109 }
110 else
111 {
112 /*
113 * This constraint applies to any choice for this option.
114 */
115
116 for (j = o1->num_choices, c1 = o1->choices; j > 0; j --, c1 ++)
117 if (c1->marked)
118 break;
119
120 if (j == 0 || strcasecmp(c1->choice, "None") == 0)
121 c1 = NULL;
122 }
123
124 /*
125 * Grab pointers to the second option...
126 */
127
128 o2 = ppdFindOption(ppd, c->option2);
129
130 if (o2 == NULL)
131 continue;
132 else if (c->choice2[0] != '\0')
133 {
134 /*
135 * This constraint maps to a specific choice.
136 */
137
138 c2 = ppdFindChoice(o2, c->choice2);
139 }
140 else
141 {
142 /*
143 * This constraint applies to any choice for this option.
144 */
145
146 for (j = o2->num_choices, c2 = o2->choices; j > 0; j --, c2 ++)
147 if (c2->marked)
148 break;
149
150 if (j == 0 || strcasecmp(c2->choice, "None") == 0)
151 c2 = NULL;
152 }
153
154 /*
155 * If both options are marked then there is a conflict...
156 */
157
158 if (c1 != NULL && c1->marked &&
159 c2 != NULL && c2->marked)
160 {
161 conflicts ++;
162 o1->conflicted = 1;
163 o2->conflicted = 1;
164 }
165 }
166
167 /*
168 * Return the number of conflicts found...
169 */
170
171 return (conflicts);
172 }
173
174
175 /*
176 * 'ppdFindChoice()' - Return a pointer to an option choice.
177 */
178
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 */
182 {
183 int i; /* Looping var */
184 ppd_choice_t *c; /* Current choice */
185
186
187 if (o == NULL || choice == NULL)
188 return (NULL);
189
190 for (i = o->num_choices, c = o->choices; i > 0; i --, c ++)
191 if (strcasecmp(c->choice, choice) == 0)
192 return (c);
193
194 return (NULL);
195 }
196
197
198 /*
199 * 'ppdFindMarkedChoice()' - Return the marked choice for the specified option.
200 */
201
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 */
205 {
206 int i; /* Looping var */
207 ppd_option_t *o; /* Pointer to option */
208 ppd_choice_t *c; /* Pointer to choice */
209
210
211 if ((o = ppdFindOption(ppd, option)) == NULL)
212 return (NULL);
213
214 for (i = o->num_choices, c = o->choices; i > 0; i --, c ++)
215 if (c->marked)
216 return (c);
217
218 return (NULL);
219 }
220
221
222 /*
223 * 'ppdFindOption()' - Return a pointer to the specified option.
224 */
225
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 */
229 {
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 */
234
235
236 if (ppd == NULL || option == NULL)
237 return (NULL);
238
239 for (i = ppd->num_groups, g = ppd->groups; i > 0; i --, g ++)
240 {
241 for (j = g->num_options, o = g->options; j > 0; j --, o ++)
242 if (strcasecmp(o->keyword, option) == 0)
243 return (o);
244
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)
248 return (o);
249 }
250
251 return (NULL);
252 }
253
254
255 /*
256 * 'ppdIsMarked()' - Check to see if an option is marked...
257 */
258
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 */
263 {
264 ppd_option_t *o; /* Option pointer */
265 ppd_choice_t *c; /* Choice pointer */
266
267
268 if (ppd == NULL)
269 return (0);
270
271 if ((o = ppdFindOption(ppd, option)) == NULL)
272 return (0);
273
274 if ((c = ppdFindChoice(o, choice)) == NULL)
275 return (0);
276
277 return (c->marked);
278 }
279
280
281 /*
282 * 'ppdMarkDefaults()' - Mark all default options in the PPD file.
283 */
284
285 void
286 ppdMarkDefaults(ppd_file_t *ppd)/* I - PPD file record */
287 {
288 int i; /* Looping variables */
289 ppd_group_t *g; /* Current group */
290
291
292 if (ppd == NULL)
293 return;
294
295 for (i = ppd->num_groups, g = ppd->groups; i > 0; i --, g ++)
296 ppd_defaults(ppd, g);
297 }
298
299
300 /*
301 * 'ppdMarkOption()' - Mark an option in a PPD file.
302 *
303 * Notes:
304 *
305 * -1 is returned if the given option would conflict with any currently
306 * selected option.
307 */
308
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 */
313 {
314 int i; /* Looping var */
315 ppd_option_t *o; /* Option pointer */
316 ppd_choice_t *c; /* Choice pointer */
317
318
319 if (ppd == NULL)
320 return (0);
321
322 if (strcasecmp(option, "PageSize") == 0 && strncasecmp(choice, "Custom.", 7) == 0)
323 {
324 /*
325 * Handle variable page sizes...
326 */
327
328 ppdPageSize(ppd, choice);
329 choice = "Custom";
330 }
331
332 if ((o = ppdFindOption(ppd, option)) == NULL)
333 return (0);
334
335 for (i = o->num_choices, c = o->choices; i > 0; i --, c ++)
336 if (strcasecmp(c->choice, choice) == 0)
337 break;
338
339 if (i)
340 {
341 /*
342 * Option found; mark it and then handle unmarking any other options.
343 */
344
345 c->marked = 1;
346
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)
350 c->marked = 0;
351
352 if (strcasecmp(option, "PageSize") == 0 || strcasecmp(option, "PageRegion") == 0)
353 {
354 /*
355 * Mark current page size...
356 */
357
358 for (i = 0; i < ppd->num_sizes; i ++)
359 ppd->sizes[i].marked = strcasecmp(ppd->sizes[i].name, choice) == 0;
360
361 /*
362 * Unmark the current PageSize or PageRegion setting, as appropriate...
363 */
364
365 if (strcasecmp(option, "PageSize") == 0)
366 {
367 if ((o = ppdFindOption(ppd, "PageRegion")) != NULL)
368 for (i = 0; i < o->num_choices; i ++)
369 o->choices[i].marked = 0;
370 }
371 else
372 {
373 if ((o = ppdFindOption(ppd, "PageSize")) != NULL)
374 for (i = 0; i < o->num_choices; i ++)
375 o->choices[i].marked = 0;
376 }
377 }
378 }
379
380 return (ppdConflicts(ppd));
381 }
382
383
384 /*
385 * 'ppd_defaults()' - Set the defaults for this group and all sub-groups.
386 */
387
388 static void
389 ppd_defaults(ppd_file_t *ppd, /* I - PPD file */
390 ppd_group_t *g) /* I - Group to default */
391 {
392 int i; /* Looping var */
393 ppd_option_t *o; /* Current option */
394 ppd_group_t *sg; /* Current sub-group */
395
396
397 if (g == NULL)
398 return;
399
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);
403
404 for (i = g->num_subgroups, sg = g->subgroups; i > 0; i --, sg ++)
405 ppd_defaults(ppd, sg);
406 }
407
408
409 /*
410 * End of "$Id: mark.c,v 1.20 2000/01/04 13:45:35 mike Exp $".
411 */