]>
git.ipfire.org Git - thirdparty/cups.git/blob - cups/mark.c
2 * "$Id: mark.c 6187 2007-01-10 16:20:42Z mike $"
4 * Option marking routines for the Common UNIX Printing System (CUPS).
6 * Copyright 1997-2007 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 * ppdFirstOption() - Return the first option in the PPD file.
35 * ppdNextOption() - Return the next option in the PPD file.
36 * ppdIsMarked() - Check to see if an option is marked...
37 * ppdMarkDefaults() - Mark all default options in the PPD file.
38 * ppdMarkOption() - Mark an option in a PPD file.
39 * ppd_defaults() - Set the defaults for this group and all sub-groups.
43 * Include necessary headers...
55 static void ppd_defaults(ppd_file_t
*ppd
, ppd_group_t
*g
);
59 * 'ppdConflicts()' - Check to see if there are any conflicts.
62 int /* O - Number of conflicts found */
63 ppdConflicts(ppd_file_t
*ppd
) /* I - PPD to check */
65 int i
, j
, /* Looping variables */
66 conflicts
; /* Number of conflicts */
67 ppd_const_t
*c
; /* Current constraint */
68 ppd_option_t
*o1
, *o2
; /* Options */
69 ppd_choice_t
*c1
, *c2
; /* Choices */
76 * Clear all conflicts...
81 for (o1
= ppdFirstOption(ppd
); o1
; o1
= ppdNextOption(ppd
))
85 * Loop through all of the UI constraints and flag any options
89 for (i
= ppd
->num_consts
, c
= ppd
->consts
; i
> 0; i
--, c
++)
92 * Grab pointers to the first option...
95 o1
= ppdFindOption(ppd
, c
->option1
);
99 else if (c
->choice1
[0])
102 * This constraint maps to a specific choice.
105 c1
= ppdFindChoice(o1
, c
->choice1
);
110 * This constraint applies to any choice for this option.
113 for (j
= o1
->num_choices
, c1
= o1
->choices
; j
> 0; j
--, c1
++)
118 !strcasecmp(c1
->choice
, "None") ||
119 !strcasecmp(c1
->choice
, "Off") ||
120 !strcasecmp(c1
->choice
, "False"))
125 * Grab pointers to the second option...
128 o2
= ppdFindOption(ppd
, c
->option2
);
132 else if (c
->choice2
[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
++)
151 !strcasecmp(c2
->choice
, "None") ||
152 !strcasecmp(c2
->choice
, "Off") ||
153 !strcasecmp(c2
->choice
, "False"))
158 * If both options are marked then there is a conflict...
161 if (c1
&& c1
->marked
&& c2
&& c2
->marked
)
163 DEBUG_printf(("%s->%s conflicts with %s->%s (%s %s %s %s)\n",
164 o1
->keyword
, c1
->choice
, o2
->keyword
, c2
->choice
,
165 c
->option1
, c
->choice1
, c
->option2
, c
->choice2
));
173 * Return the number of conflicts found...
181 * 'ppdFindChoice()' - Return a pointer to an option choice.
184 ppd_choice_t
* /* O - Choice pointer or NULL */
185 ppdFindChoice(ppd_option_t
*o
, /* I - Pointer to option */
186 const char *choice
) /* I - Name of choice */
188 int i
; /* Looping var */
189 ppd_choice_t
*c
; /* Current choice */
192 if (o
== NULL
|| choice
== NULL
)
195 for (i
= o
->num_choices
, c
= o
->choices
; i
> 0; i
--, c
++)
196 if (strcasecmp(c
->choice
, choice
) == 0)
204 * 'ppdFindMarkedChoice()' - Return the marked choice for the specified option.
207 ppd_choice_t
* /* O - Pointer to choice or NULL */
208 ppdFindMarkedChoice(ppd_file_t
*ppd
, /* I - PPD file */
209 const char *option
) /* I - Keyword/option name */
211 int i
; /* Looping var */
212 ppd_option_t
*o
; /* Pointer to option */
213 ppd_choice_t
*c
; /* Pointer to choice */
216 if ((o
= ppdFindOption(ppd
, option
)) == NULL
)
219 for (i
= o
->num_choices
, c
= o
->choices
; i
> 0; i
--, c
++)
228 * 'ppdFindOption()' - Return a pointer to the specified option.
231 ppd_option_t
* /* O - Pointer to option or NULL */
232 ppdFindOption(ppd_file_t
*ppd
, /* I - PPD file data */
233 const char *option
) /* I - Option/Keyword name */
236 * Range check input...
245 * Search in the array...
248 ppd_option_t key
; /* Option search key */
251 strlcpy(key
.keyword
, option
, sizeof(key
.keyword
));
253 return ((ppd_option_t
*)cupsArrayFind(ppd
->options
, &key
));
258 * Search in each group...
261 int i
, j
; /* Looping vars */
262 ppd_group_t
*group
; /* Current group */
263 ppd_option_t
*optptr
; /* Current option */
266 for (i
= ppd
->num_groups
, group
= ppd
->groups
; i
> 0; i
--, group
++)
267 for (j
= group
->num_options
, optptr
= group
->options
;
270 if (!strcasecmp(optptr
->keyword
, option
))
279 * 'ppdIsMarked()' - Check to see if an option is marked...
282 int /* O - Non-zero if option is marked */
283 ppdIsMarked(ppd_file_t
*ppd
, /* I - PPD file data */
284 const char *option
, /* I - Option/Keyword name */
285 const char *choice
) /* I - Choice name */
287 ppd_option_t
*o
; /* Option pointer */
288 ppd_choice_t
*c
; /* Choice pointer */
294 if ((o
= ppdFindOption(ppd
, option
)) == NULL
)
297 if ((c
= ppdFindChoice(o
, choice
)) == NULL
)
305 * 'ppdMarkDefaults()' - Mark all default options in the PPD file.
309 ppdMarkDefaults(ppd_file_t
*ppd
)/* I - PPD file record */
311 int i
; /* Looping variables */
312 ppd_group_t
*g
; /* Current group */
318 for (i
= ppd
->num_groups
, g
= ppd
->groups
; i
> 0; i
--, g
++)
319 ppd_defaults(ppd
, g
);
324 * 'ppdMarkOption()' - Mark an option in a PPD file.
328 * -1 is returned if the given option would conflict with any currently
332 int /* O - Number of conflicts */
333 ppdMarkOption(ppd_file_t
*ppd
, /* I - PPD file record */
334 const char *option
, /* I - Keyword */
335 const char *choice
) /* I - Option name */
337 int i
, j
; /* Looping vars */
338 ppd_option_t
*o
; /* Option pointer */
339 ppd_choice_t
*c
; /* Choice pointer */
340 struct lconv
*loc
; /* Locale data */
343 DEBUG_printf(("ppdMarkOption(ppd=%p, option=\"%s\", choice=\"%s\")\n",
344 ppd
, option
, choice
));
347 * Range check input...
350 if (!ppd
|| !option
|| !choice
)
354 * AP_D_InputSlot is the "default input slot" on MacOS X, and setting
355 * it clears the regular InputSlot choices...
358 if (!strcasecmp(option
, "AP_D_InputSlot"))
360 if ((o
= ppdFindOption(ppd
, "InputSlot")) != NULL
)
361 for (i
= 0; i
< o
->num_choices
; i
++)
362 o
->choices
[i
].marked
= 0;
366 * Check for custom options...
369 if ((o
= ppdFindOption(ppd
, option
)) == NULL
)
374 if (!strncasecmp(choice
, "Custom.", 7))
377 * Handle a custom option...
380 if ((c
= ppdFindChoice(o
, "Custom")) == NULL
)
383 if (!strcasecmp(option
, "PageSize"))
386 * Handle custom page sizes...
389 ppdPageSize(ppd
, choice
);
394 * Handle other custom options...
397 ppd_coption_t
*coption
; /* Custom option */
398 ppd_cparam_t
*cparam
; /* Custom parameter */
399 char *units
; /* Custom points units */
402 if ((coption
= ppdFindCustomOption(ppd
, option
)) != NULL
)
404 if ((cparam
= (ppd_cparam_t
*)cupsArrayFirst(coption
->params
)) == NULL
)
407 switch (cparam
->type
)
409 case PPD_CUSTOM_CURVE
:
410 case PPD_CUSTOM_INVCURVE
:
411 case PPD_CUSTOM_REAL
:
412 cparam
->current
.custom_real
= (float)_cupsStrScand(choice
+ 7,
416 case PPD_CUSTOM_POINTS
:
417 cparam
->current
.custom_points
= (float)_cupsStrScand(choice
+ 7,
423 if (!strcasecmp(units
, "cm"))
424 cparam
->current
.custom_points
*= 72.0f
/ 2.54f
;
425 else if (!strcasecmp(units
, "mm"))
426 cparam
->current
.custom_points
*= 72.0f
/ 25.4f
;
427 else if (!strcasecmp(units
, "m"))
428 cparam
->current
.custom_points
*= 72.0f
/ 0.0254f
;
429 else if (!strcasecmp(units
, "in"))
430 cparam
->current
.custom_points
*= 72.0f
;
431 else if (!strcasecmp(units
, "ft"))
432 cparam
->current
.custom_points
*= 12.0f
* 72.0f
;
436 case PPD_CUSTOM_INT
:
437 cparam
->current
.custom_int
= atoi(choice
+ 7);
440 case PPD_CUSTOM_PASSCODE
:
441 case PPD_CUSTOM_PASSWORD
:
442 case PPD_CUSTOM_STRING
:
443 if (cparam
->current
.custom_string
)
444 free(cparam
->current
.custom_string
);
446 cparam
->current
.custom_string
= strdup(choice
+ 7);
453 * Make sure that we keep the option marked below...
458 else if (choice
[0] == '{')
461 * Handle multi-value custom options...
464 ppd_coption_t
*coption
; /* Custom option */
465 ppd_cparam_t
*cparam
; /* Custom parameter */
466 char *units
; /* Custom points units */
467 int num_vals
; /* Number of values */
468 cups_option_t
*vals
, /* Values */
472 if ((c
= ppdFindChoice(o
, "Custom")) == NULL
)
475 if ((coption
= ppdFindCustomOption(ppd
, option
)) != NULL
)
477 num_vals
= cupsParseOptions(choice
+ 1, 0, &vals
);
479 for (i
= 0, val
= vals
; i
< num_vals
; i
++, val
++)
481 if ((cparam
= ppdFindCustomParam(coption
, val
->name
)) == NULL
)
484 switch (cparam
->type
)
486 case PPD_CUSTOM_CURVE
:
487 case PPD_CUSTOM_INVCURVE
:
488 case PPD_CUSTOM_REAL
:
489 cparam
->current
.custom_real
= (float)_cupsStrScand(val
->value
,
493 case PPD_CUSTOM_POINTS
:
494 cparam
->current
.custom_points
= (float)_cupsStrScand(val
->value
,
500 if (!strcasecmp(units
, "cm"))
501 cparam
->current
.custom_points
*= 72.0f
/ 2.54f
;
502 else if (!strcasecmp(units
, "mm"))
503 cparam
->current
.custom_points
*= 72.0f
/ 25.4f
;
504 else if (!strcasecmp(units
, "m"))
505 cparam
->current
.custom_points
*= 72.0f
/ 0.0254f
;
506 else if (!strcasecmp(units
, "in"))
507 cparam
->current
.custom_points
*= 72.0f
;
508 else if (!strcasecmp(units
, "ft"))
509 cparam
->current
.custom_points
*= 12.0f
* 72.0f
;
513 case PPD_CUSTOM_INT
:
514 cparam
->current
.custom_int
= atoi(val
->value
);
517 case PPD_CUSTOM_PASSCODE
:
518 case PPD_CUSTOM_PASSWORD
:
519 case PPD_CUSTOM_STRING
:
520 if (cparam
->current
.custom_string
)
521 free(cparam
->current
.custom_string
);
523 cparam
->current
.custom_string
= strdup(val
->value
);
528 cupsFreeOptions(num_vals
, vals
);
533 for (i
= o
->num_choices
, c
= o
->choices
; i
> 0; i
--, c
++)
534 if (!strcasecmp(c
->choice
, choice
))
542 * Option found; mark it and then handle unmarking any other options.
547 if (o
->ui
!= PPD_UI_PICKMANY
)
550 * Unmark all other choices...
553 for (i
= o
->num_choices
, c
= o
->choices
; i
> 0; i
--, c
++)
554 if (strcasecmp(c
->choice
, choice
))
558 if (!strcasecmp(option
, "PageSize") ||
559 !strcasecmp(option
, "PageRegion"))
562 * Mark current page size...
565 for (j
= 0; j
< ppd
->num_sizes
; j
++)
566 ppd
->sizes
[j
].marked
= !strcasecmp(ppd
->sizes
[j
].name
,
570 * Unmark the current PageSize or PageRegion setting, as
574 if (!strcasecmp(option
, "PageSize"))
576 if ((o
= ppdFindOption(ppd
, "PageRegion")) != NULL
)
577 for (j
= 0; j
< o
->num_choices
; j
++)
578 o
->choices
[j
].marked
= 0;
582 if ((o
= ppdFindOption(ppd
, "PageSize")) != NULL
)
583 for (j
= 0; j
< o
->num_choices
; j
++)
584 o
->choices
[j
].marked
= 0;
587 else if (!strcasecmp(option
, "InputSlot"))
590 * Unmark ManualFeed True and possibly mark ManualFeed False
594 if ((o
= ppdFindOption(ppd
, "ManualFeed")) != NULL
)
595 for (j
= 0; j
< o
->num_choices
; j
++)
596 o
->choices
[j
].marked
= !strcasecmp(o
->choices
[j
].choice
, "False");
598 else if (!strcasecmp(option
, "ManualFeed") &&
599 !strcasecmp(choice
, "True"))
602 * Unmark InputSlot option...
605 if ((o
= ppdFindOption(ppd
, "InputSlot")) != NULL
)
606 for (j
= 0; j
< o
->num_choices
; j
++)
607 o
->choices
[j
].marked
= 0;
613 * Return the number of conflicts...
616 return (ppdConflicts(ppd
));
621 * 'ppdFirstOption()' - Return the first option in the PPD file.
623 * Options are returned from all groups in sorted order.
628 ppd_option_t
* /* O - First option or NULL */
629 ppdFirstOption(ppd_file_t
*ppd
) /* I - PPD file */
634 return ((ppd_option_t
*)cupsArrayFirst(ppd
->options
));
639 * 'ppdNextOption()' - Return the next option in the PPD file.
641 * Options are returned from all groups in sorted order.
646 ppd_option_t
* /* O - Next option or NULL */
647 ppdNextOption(ppd_file_t
*ppd
) /* I - PPD file */
652 return ((ppd_option_t
*)cupsArrayNext(ppd
->options
));
657 * 'ppd_defaults()' - Set the defaults for this group and all sub-groups.
661 ppd_defaults(ppd_file_t
*ppd
, /* I - PPD file */
662 ppd_group_t
*g
) /* I - Group to default */
664 int i
; /* Looping var */
665 ppd_option_t
*o
; /* Current option */
666 ppd_group_t
*sg
; /* Current sub-group */
672 for (i
= g
->num_options
, o
= g
->options
; i
> 0; i
--, o
++)
673 if (strcasecmp(o
->keyword
, "PageRegion") != 0)
674 ppdMarkOption(ppd
, o
->keyword
, o
->defchoice
);
676 for (i
= g
->num_subgroups
, sg
= g
->subgroups
; i
> 0; i
--, sg
++)
677 ppd_defaults(ppd
, sg
);
682 * End of "$Id: mark.c 6187 2007-01-10 16:20:42Z mike $".