]>
git.ipfire.org Git - thirdparty/cups.git/blob - cups/mark.c
2 * "$Id: mark.c 4980 2006-01-25 19:57:45Z 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 ppd_option_t key
; /* Option search key */
246 * Range check input...
256 strlcpy(key
.keyword
, option
, sizeof(key
.keyword
));
258 return ((ppd_option_t
*)cupsArrayFind(ppd
->options
, &key
));
263 * 'ppdIsMarked()' - Check to see if an option is marked...
266 int /* O - Non-zero if option is marked */
267 ppdIsMarked(ppd_file_t
*ppd
, /* I - PPD file data */
268 const char *option
, /* I - Option/Keyword name */
269 const char *choice
) /* I - Choice name */
271 ppd_option_t
*o
; /* Option pointer */
272 ppd_choice_t
*c
; /* Choice pointer */
278 if ((o
= ppdFindOption(ppd
, option
)) == NULL
)
281 if ((c
= ppdFindChoice(o
, choice
)) == NULL
)
289 * 'ppdMarkDefaults()' - Mark all default options in the PPD file.
293 ppdMarkDefaults(ppd_file_t
*ppd
)/* I - PPD file record */
295 int i
; /* Looping variables */
296 ppd_group_t
*g
; /* Current group */
302 for (i
= ppd
->num_groups
, g
= ppd
->groups
; i
> 0; i
--, g
++)
303 ppd_defaults(ppd
, g
);
308 * 'ppdMarkOption()' - Mark an option in a PPD file.
312 * -1 is returned if the given option would conflict with any currently
316 int /* O - Number of conflicts */
317 ppdMarkOption(ppd_file_t
*ppd
, /* I - PPD file record */
318 const char *option
, /* I - Keyword */
319 const char *choice
) /* I - Option name */
321 int i
, j
; /* Looping vars */
322 ppd_option_t
*o
; /* Option pointer */
323 ppd_choice_t
*c
; /* Choice pointer */
327 * Range check input...
330 if (!ppd
|| !option
|| !choice
)
334 * AP_D_InputSlot is the "default input slot" on MacOS X, and setting
335 * it clears the regular InputSlot choices...
338 if (!strcasecmp(option
, "AP_D_InputSlot"))
340 if ((o
= ppdFindOption(ppd
, "InputSlot")) != NULL
)
341 for (i
= 0; i
< o
->num_choices
; i
++)
342 o
->choices
[i
].marked
= 0;
346 * Check for custom options...
349 if ((o
= ppdFindOption(ppd
, option
)) == NULL
)
353 if (!strncasecmp(choice
, "Custom.", 7) /* TODO || strchr(choice, '=') */ )
356 * Handle a custom option...
359 if ((c
= ppdFindChoice(o
, "Custom")) == NULL
)
362 if (!strcasecmp(option
, "PageSize"))
365 * Handle custom page sizes...
368 ppdPageSize(ppd
, choice
);
373 * Handle other custom options...
376 ppd_coption_t
*coption
; /* Custom option */
377 ppd_cparam_t
*cparam
; /* Custom parameter */
378 char units
[33]; /* Custom points units */
382 * TODO: Detect and support custom option values using the
383 * collection format "{Name1=foo Name2=bar}". For now, just
384 * support Custom.value for single-valued custom options.
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
= atof(choice
+ 7);
400 case PPD_CUSTOM_POINTS
:
401 if (sscanf(choice
+ 7, "%f%s", &(cparam
->current
.custom_points
),
405 if (!strcasecmp(units
, "cm"))
406 cparam
->current
.custom_points
*= 72.0 / 2.54;
407 else if (!strcasecmp(units
, "mm"))
408 cparam
->current
.custom_points
*= 72.0 / 25.4;
409 else if (!strcasecmp(units
, "m"))
410 cparam
->current
.custom_points
*= 72.0 / 0.0254;
411 else if (!strcasecmp(units
, "in"))
412 cparam
->current
.custom_points
*= 72.0;
413 else if (!strcasecmp(units
, "ft"))
414 cparam
->current
.custom_points
*= 12 * 72.0;
417 case PPD_CUSTOM_INT
:
418 cparam
->current
.custom_int
= atoi(choice
+ 7);
421 case PPD_CUSTOM_PASSCODE
:
422 case PPD_CUSTOM_PASSWORD
:
423 case PPD_CUSTOM_STRING
:
424 if (cparam
->current
.custom_string
)
425 free(cparam
->current
.custom_string
);
427 cparam
->current
.custom_string
= strdup(choice
+ 7);
435 for (i
= o
->num_choices
, c
= o
->choices
; i
> 0; i
--, c
++)
436 if (!strcasecmp(c
->choice
, choice
))
444 * Option found; mark it and then handle unmarking any other options.
449 if (o
->ui
!= PPD_UI_PICKMANY
)
452 * Unmark all other choices...
455 for (i
= o
->num_choices
, c
= o
->choices
; i
> 0; i
--, c
++)
456 if (strcasecmp(c
->choice
, choice
))
460 if (!strcasecmp(option
, "PageSize") ||
461 !strcasecmp(option
, "PageRegion"))
464 * Mark current page size...
467 for (j
= 0; j
< ppd
->num_sizes
; j
++)
468 ppd
->sizes
[i
].marked
= !strcasecmp(ppd
->sizes
[i
].name
,
472 * Unmark the current PageSize or PageRegion setting, as
476 if (!strcasecmp(option
, "PageSize"))
478 if ((o
= ppdFindOption(ppd
, "PageRegion")) != NULL
)
479 for (j
= 0; j
< o
->num_choices
; j
++)
480 o
->choices
[i
].marked
= 0;
484 if ((o
= ppdFindOption(ppd
, "PageSize")) != NULL
)
485 for (j
= 0; j
< o
->num_choices
; j
++)
486 o
->choices
[j
].marked
= 0;
489 else if (!strcasecmp(option
, "InputSlot"))
492 * Unmark ManualFeed True and possibly mark ManualFeed False
496 if ((o
= ppdFindOption(ppd
, "ManualFeed")) != NULL
)
497 for (j
= 0; j
< o
->num_choices
; j
++)
498 o
->choices
[j
].marked
= !strcasecmp(o
->choices
[j
].choice
, "False");
500 else if (!strcasecmp(option
, "ManualFeed") &&
501 !strcasecmp(choice
, "True"))
504 * Unmark InputSlot option...
507 if ((o
= ppdFindOption(ppd
, "InputSlot")) != NULL
)
508 for (j
= 0; j
< o
->num_choices
; j
++)
509 o
->choices
[j
].marked
= 0;
515 * Return the number of conflicts...
518 return (ppdConflicts(ppd
));
523 * 'ppd_defaults()' - Set the defaults for this group and all sub-groups.
527 ppd_defaults(ppd_file_t
*ppd
, /* I - PPD file */
528 ppd_group_t
*g
) /* I - Group to default */
530 int i
; /* Looping var */
531 ppd_option_t
*o
; /* Current option */
532 ppd_group_t
*sg
; /* Current sub-group */
538 for (i
= g
->num_options
, o
= g
->options
; i
> 0; i
--, o
++)
539 if (strcasecmp(o
->keyword
, "PageRegion") != 0)
540 ppdMarkOption(ppd
, o
->keyword
, o
->defchoice
);
542 for (i
= g
->num_subgroups
, sg
= g
->subgroups
; i
> 0; i
--, sg
++)
543 ppd_defaults(ppd
, sg
);
548 * End of "$Id: mark.c 4980 2006-01-25 19:57:45Z mike $".