]>
git.ipfire.org Git - thirdparty/cups.git/blob - cups/mark.c
2 * "$Id: mark.c 5238 2006-03-07 04:41:42Z mike $"
4 * Option marking routines for the Common UNIX Printing System (CUPS).
6 * Copyright 1997-2006 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
, k
, /* Looping variables */
66 conflicts
; /* Number of conflicts */
67 ppd_const_t
*c
; /* Current constraint */
68 ppd_group_t
*g
, *sg
; /* Groups */
69 ppd_option_t
*o1
, *o2
; /* Options */
70 ppd_choice_t
*c1
, *c2
; /* Choices */
77 * Clear all conflicts...
82 for (i
= ppd
->num_groups
, g
= ppd
->groups
; i
> 0; i
--, g
++)
84 for (j
= g
->num_options
, o1
= g
->options
; j
> 0; j
--, o1
++)
87 for (j
= g
->num_subgroups
, sg
= g
->subgroups
; j
> 0; j
--, sg
++)
88 for (k
= sg
->num_options
, o1
= sg
->options
; k
> 0; k
--, o1
++)
93 * Loop through all of the UI constraints and flag any options
97 for (i
= ppd
->num_consts
, c
= ppd
->consts
; i
> 0; i
--, c
++)
100 * Grab pointers to the first option...
103 o1
= ppdFindOption(ppd
, c
->option1
);
107 else if (c
->choice1
[0] != '\0')
110 * This constraint maps to a specific choice.
113 c1
= ppdFindChoice(o1
, c
->choice1
);
118 * This constraint applies to any choice for this option.
121 for (j
= o1
->num_choices
, c1
= o1
->choices
; j
> 0; j
--, c1
++)
126 strcasecmp(c1
->choice
, "None") == 0 ||
127 strcasecmp(c1
->choice
, "Off") == 0 ||
128 strcasecmp(c1
->choice
, "False") == 0)
133 * Grab pointers to the second option...
136 o2
= ppdFindOption(ppd
, c
->option2
);
140 else if (c
->choice2
[0] != '\0')
143 * This constraint maps to a specific choice.
146 c2
= ppdFindChoice(o2
, c
->choice2
);
151 * This constraint applies to any choice for this option.
154 for (j
= o2
->num_choices
, c2
= o2
->choices
; j
> 0; j
--, c2
++)
159 strcasecmp(c2
->choice
, "None") == 0 ||
160 strcasecmp(c2
->choice
, "Off") == 0 ||
161 strcasecmp(c2
->choice
, "False") == 0)
166 * If both options are marked then there is a conflict...
169 if (c1
!= NULL
&& c1
->marked
&&
170 c2
!= NULL
&& c2
->marked
)
172 DEBUG_printf(("%s->%s conflicts with %s->%s (%s %s %s %s)\n",
173 o1
->keyword
, c1
->choice
, o2
->keyword
, c2
->choice
,
174 c
->option1
, c
->choice1
, c
->option2
, c
->choice2
));
182 * Return the number of conflicts found...
190 * 'ppdFindChoice()' - Return a pointer to an option choice.
193 ppd_choice_t
* /* O - Choice pointer or NULL */
194 ppdFindChoice(ppd_option_t
*o
, /* I - Pointer to option */
195 const char *choice
) /* I - Name of choice */
197 int i
; /* Looping var */
198 ppd_choice_t
*c
; /* Current choice */
201 if (o
== NULL
|| choice
== NULL
)
204 for (i
= o
->num_choices
, c
= o
->choices
; i
> 0; i
--, c
++)
205 if (strcasecmp(c
->choice
, choice
) == 0)
213 * 'ppdFindMarkedChoice()' - Return the marked choice for the specified option.
216 ppd_choice_t
* /* O - Pointer to choice or NULL */
217 ppdFindMarkedChoice(ppd_file_t
*ppd
, /* I - PPD file */
218 const char *option
) /* I - Keyword/option name */
220 int i
; /* Looping var */
221 ppd_option_t
*o
; /* Pointer to option */
222 ppd_choice_t
*c
; /* Pointer to choice */
225 if ((o
= ppdFindOption(ppd
, option
)) == NULL
)
228 for (i
= o
->num_choices
, c
= o
->choices
; i
> 0; i
--, c
++)
237 * 'ppdFindOption()' - Return a pointer to the specified option.
240 ppd_option_t
* /* O - Pointer to option or NULL */
241 ppdFindOption(ppd_file_t
*ppd
, /* I - PPD file data */
242 const char *option
) /* I - Option/Keyword name */
244 ppd_option_t key
; /* Option search key */
248 * Range check input...
258 strlcpy(key
.keyword
, option
, sizeof(key
.keyword
));
260 return ((ppd_option_t
*)cupsArrayFind(ppd
->options
, &key
));
265 * 'ppdIsMarked()' - Check to see if an option is marked...
268 int /* O - Non-zero if option is marked */
269 ppdIsMarked(ppd_file_t
*ppd
, /* I - PPD file data */
270 const char *option
, /* I - Option/Keyword name */
271 const char *choice
) /* I - Choice name */
273 ppd_option_t
*o
; /* Option pointer */
274 ppd_choice_t
*c
; /* Choice pointer */
280 if ((o
= ppdFindOption(ppd
, option
)) == NULL
)
283 if ((c
= ppdFindChoice(o
, choice
)) == NULL
)
291 * 'ppdMarkDefaults()' - Mark all default options in the PPD file.
295 ppdMarkDefaults(ppd_file_t
*ppd
)/* I - PPD file record */
297 int i
; /* Looping variables */
298 ppd_group_t
*g
; /* Current group */
304 for (i
= ppd
->num_groups
, g
= ppd
->groups
; i
> 0; i
--, g
++)
305 ppd_defaults(ppd
, g
);
310 * 'ppdMarkOption()' - Mark an option in a PPD file.
314 * -1 is returned if the given option would conflict with any currently
318 int /* O - Number of conflicts */
319 ppdMarkOption(ppd_file_t
*ppd
, /* I - PPD file record */
320 const char *option
, /* I - Keyword */
321 const char *choice
) /* I - Option name */
323 int i
, j
; /* Looping vars */
324 ppd_option_t
*o
; /* Option pointer */
325 ppd_choice_t
*c
; /* Choice pointer */
326 struct lconv
*loc
; /* Locale data */
329 DEBUG_printf(("ppdMarkOption(ppd=%p, option=\"%s\", choice=\"%s\")\n",
330 ppd
, option
, choice
));
333 * Range check input...
336 if (!ppd
|| !option
|| !choice
)
340 * AP_D_InputSlot is the "default input slot" on MacOS X, and setting
341 * it clears the regular InputSlot choices...
344 if (!strcasecmp(option
, "AP_D_InputSlot"))
346 if ((o
= ppdFindOption(ppd
, "InputSlot")) != NULL
)
347 for (i
= 0; i
< o
->num_choices
; i
++)
348 o
->choices
[i
].marked
= 0;
352 * Check for custom options...
355 if ((o
= ppdFindOption(ppd
, option
)) == NULL
)
360 if (!strncasecmp(choice
, "Custom.", 7))
363 * Handle a custom option...
366 if ((c
= ppdFindChoice(o
, "Custom")) == NULL
)
369 if (!strcasecmp(option
, "PageSize"))
372 * Handle custom page sizes...
375 ppdPageSize(ppd
, choice
);
380 * Handle other custom options...
383 ppd_coption_t
*coption
; /* Custom option */
384 ppd_cparam_t
*cparam
; /* Custom parameter */
385 char *units
; /* Custom points units */
387 if ((coption
= ppdFindCustomOption(ppd
, option
)) != NULL
)
389 if ((cparam
= (ppd_cparam_t
*)cupsArrayFirst(coption
->params
)) == NULL
)
392 switch (cparam
->type
)
394 case PPD_CUSTOM_CURVE
:
395 case PPD_CUSTOM_INVCURVE
:
396 case PPD_CUSTOM_REAL
:
397 cparam
->current
.custom_real
= _cupsStrScand(choice
+ 7, NULL
,
401 case PPD_CUSTOM_POINTS
:
402 cparam
->current
.custom_points
= _cupsStrScand(choice
+ 7,
407 if (!strcasecmp(units
, "cm"))
408 cparam
->current
.custom_points
*= 72.0 / 2.54;
409 else if (!strcasecmp(units
, "mm"))
410 cparam
->current
.custom_points
*= 72.0 / 25.4;
411 else if (!strcasecmp(units
, "m"))
412 cparam
->current
.custom_points
*= 72.0 / 0.0254;
413 else if (!strcasecmp(units
, "in"))
414 cparam
->current
.custom_points
*= 72.0;
415 else if (!strcasecmp(units
, "ft"))
416 cparam
->current
.custom_points
*= 12 * 72.0;
420 case PPD_CUSTOM_INT
:
421 cparam
->current
.custom_int
= atoi(choice
+ 7);
424 case PPD_CUSTOM_PASSCODE
:
425 case PPD_CUSTOM_PASSWORD
:
426 case PPD_CUSTOM_STRING
:
427 if (cparam
->current
.custom_string
)
428 free(cparam
->current
.custom_string
);
430 cparam
->current
.custom_string
= strdup(choice
+ 7);
436 else if (choice
[0] == '{')
439 * Handle multi-value custom options...
442 ppd_coption_t
*coption
; /* Custom option */
443 ppd_cparam_t
*cparam
; /* Custom parameter */
444 char *units
; /* Custom points units */
445 int num_vals
; /* Number of values */
446 cups_option_t
*vals
, /* Values */
450 if ((c
= ppdFindChoice(o
, "Custom")) == NULL
)
453 if ((coption
= ppdFindCustomOption(ppd
, option
)) != NULL
)
455 num_vals
= cupsParseOptions(choice
+ 1, 0, &vals
);
457 for (i
= 0, val
= vals
; i
< num_vals
; i
++, val
++)
459 if ((cparam
= ppdFindCustomParam(coption
, val
->name
)) == NULL
)
462 switch (cparam
->type
)
464 case PPD_CUSTOM_CURVE
:
465 case PPD_CUSTOM_INVCURVE
:
466 case PPD_CUSTOM_REAL
:
467 cparam
->current
.custom_real
= _cupsStrScand(val
->value
, NULL
,
471 case PPD_CUSTOM_POINTS
:
472 cparam
->current
.custom_points
= _cupsStrScand(val
->value
, &units
,
477 if (!strcasecmp(units
, "cm"))
478 cparam
->current
.custom_points
*= 72.0 / 2.54;
479 else if (!strcasecmp(units
, "mm"))
480 cparam
->current
.custom_points
*= 72.0 / 25.4;
481 else if (!strcasecmp(units
, "m"))
482 cparam
->current
.custom_points
*= 72.0 / 0.0254;
483 else if (!strcasecmp(units
, "in"))
484 cparam
->current
.custom_points
*= 72.0;
485 else if (!strcasecmp(units
, "ft"))
486 cparam
->current
.custom_points
*= 12 * 72.0;
490 case PPD_CUSTOM_INT
:
491 cparam
->current
.custom_int
= atoi(val
->value
);
494 case PPD_CUSTOM_PASSCODE
:
495 case PPD_CUSTOM_PASSWORD
:
496 case PPD_CUSTOM_STRING
:
497 if (cparam
->current
.custom_string
)
498 free(cparam
->current
.custom_string
);
500 cparam
->current
.custom_string
= strdup(val
->value
);
505 cupsFreeOptions(num_vals
, vals
);
510 for (i
= o
->num_choices
, c
= o
->choices
; i
> 0; i
--, c
++)
511 if (!strcasecmp(c
->choice
, choice
))
519 * Option found; mark it and then handle unmarking any other options.
524 if (o
->ui
!= PPD_UI_PICKMANY
)
527 * Unmark all other choices...
530 for (i
= o
->num_choices
, c
= o
->choices
; i
> 0; i
--, c
++)
531 if (strcasecmp(c
->choice
, choice
))
535 if (!strcasecmp(option
, "PageSize") ||
536 !strcasecmp(option
, "PageRegion"))
539 * Mark current page size...
542 for (j
= 0; j
< ppd
->num_sizes
; j
++)
543 ppd
->sizes
[j
].marked
= !strcasecmp(ppd
->sizes
[j
].name
,
547 * Unmark the current PageSize or PageRegion setting, as
551 if (!strcasecmp(option
, "PageSize"))
553 if ((o
= ppdFindOption(ppd
, "PageRegion")) != NULL
)
554 for (j
= 0; j
< o
->num_choices
; j
++)
555 o
->choices
[j
].marked
= 0;
559 if ((o
= ppdFindOption(ppd
, "PageSize")) != NULL
)
560 for (j
= 0; j
< o
->num_choices
; j
++)
561 o
->choices
[j
].marked
= 0;
564 else if (!strcasecmp(option
, "InputSlot"))
567 * Unmark ManualFeed True and possibly mark ManualFeed False
571 if ((o
= ppdFindOption(ppd
, "ManualFeed")) != NULL
)
572 for (j
= 0; j
< o
->num_choices
; j
++)
573 o
->choices
[j
].marked
= !strcasecmp(o
->choices
[j
].choice
, "False");
575 else if (!strcasecmp(option
, "ManualFeed") &&
576 !strcasecmp(choice
, "True"))
579 * Unmark InputSlot option...
582 if ((o
= ppdFindOption(ppd
, "InputSlot")) != NULL
)
583 for (j
= 0; j
< o
->num_choices
; j
++)
584 o
->choices
[j
].marked
= 0;
590 * Return the number of conflicts...
593 return (ppdConflicts(ppd
));
598 * 'ppdFirstOption()' - Return the first option in the PPD file.
600 * Options are returned from all groups in sorted order.
605 ppd_option_t
* /* O - First option or NULL */
606 ppdFirstOption(ppd_file_t
*ppd
) /* I - PPD file */
611 return ((ppd_option_t
*)cupsArrayFirst(ppd
->options
));
616 * 'ppdNextOption()' - Return the next option in the PPD file.
618 * Options are returned from all groups in sorted order.
623 ppd_option_t
* /* O - Next option or NULL */
624 ppdNextOption(ppd_file_t
*ppd
) /* I - PPD file */
629 return ((ppd_option_t
*)cupsArrayNext(ppd
->options
));
634 * 'ppd_defaults()' - Set the defaults for this group and all sub-groups.
638 ppd_defaults(ppd_file_t
*ppd
, /* I - PPD file */
639 ppd_group_t
*g
) /* I - Group to default */
641 int i
; /* Looping var */
642 ppd_option_t
*o
; /* Current option */
643 ppd_group_t
*sg
; /* Current sub-group */
649 for (i
= g
->num_options
, o
= g
->options
; i
> 0; i
--, o
++)
650 if (strcasecmp(o
->keyword
, "PageRegion") != 0)
651 ppdMarkOption(ppd
, o
->keyword
, o
->defchoice
);
653 for (i
= g
->num_subgroups
, sg
= g
->subgroups
; i
> 0; i
--, sg
++)
654 ppd_defaults(ppd
, sg
);
659 * End of "$Id: mark.c 5238 2006-03-07 04:41:42Z mike $".