]>
git.ipfire.org Git - thirdparty/cups.git/blob - cups/attr.c
2 * "$Id: attr.c 7584 2008-05-16 22:55:53Z mike $"
4 * PPD model-specific attribute routines for the Common UNIX Printing System
7 * Copyright 2007-2008 by Apple Inc.
8 * Copyright 1997-2006 by Easy Software Products.
10 * These coded instructions, statements, and computer programs are the
11 * property of Apple Inc. and are protected by Federal copyright
12 * law. Distribution and use rights are outlined in the file "LICENSE.txt"
13 * which should have been included with this file. If this file is
14 * file is missing or damaged, see the license at "http://www.cups.org/".
18 * ppdFindAttr() - Find the first matching attribute.
19 * ppdFindNextAttr() - Find the next matching attribute.
23 * Include necessary headers...
26 #include "ppd-private.h"
33 * 'ppdFindAttr()' - Find the first matching attribute.
38 ppd_attr_t
* /* O - Attribute or @code NULL@ if not found */
39 ppdFindAttr(ppd_file_t
*ppd
, /* I - PPD file data */
40 const char *name
, /* I - Attribute name */
41 const char *spec
) /* I - Specifier string or @code NULL@ */
43 ppd_attr_t key
, /* Search key */
44 *attr
; /* Current attribute */
45 int diff
; /* Current difference */
48 DEBUG_printf(("ppdFindAttr(ppd=%p, name=\"%s\", spec=\"%s\")\n", ppd
,
49 name
? name
: "(null)", spec
? spec
: "(null)"));
52 * Range check input...
55 if (!ppd
|| !name
|| ppd
->num_attrs
== 0)
59 * Search for a matching attribute...
62 memset(&key
, 0, sizeof(key
));
63 strlcpy(key
.name
, name
, sizeof(key
.name
));
65 strlcpy(key
.spec
, spec
, sizeof(key
.spec
));
68 * Return the first matching attribute, if any...
71 if ((attr
= (ppd_attr_t
*)cupsArrayFind(ppd
->sorted_attrs
, &key
)) != NULL
)
77 * No match found, loop through the sorted attributes to see if we can
78 * find a "wildcard" match for the attribute...
81 for (attr
= (ppd_attr_t
*)cupsArrayFirst(ppd
->sorted_attrs
);
83 attr
= (ppd_attr_t
*)cupsArrayNext(ppd
->sorted_attrs
))
85 if ((diff
= strcasecmp(attr
->name
, name
)) == 0)
91 * All remaining attributes are > than the one we are trying to find...
94 cupsArrayIndex(ppd
->sorted_attrs
, cupsArrayCount(ppd
->sorted_attrs
));
105 * 'ppdFindNextAttr()' - Find the next matching attribute.
107 * @since CUPS 1.1.19@
110 ppd_attr_t
* /* O - Attribute or @code NULL@ if not found */
111 ppdFindNextAttr(ppd_file_t
*ppd
, /* I - PPD file data */
112 const char *name
, /* I - Attribute name */
113 const char *spec
) /* I - Specifier string or @code NULL@ */
115 ppd_attr_t
*attr
; /* Current attribute */
119 * Range check input...
122 if (!ppd
|| !name
|| ppd
->num_attrs
== 0 ||
123 !cupsArrayCurrent(ppd
->sorted_attrs
))
127 * See if there are more attributes to return...
130 if ((attr
= (ppd_attr_t
*)cupsArrayNext(ppd
->sorted_attrs
)) == NULL
)
134 * Check the next attribute to see if it is a match...
137 if (strcasecmp(attr
->name
, name
) || (spec
&& strcasecmp(attr
->spec
, spec
)))
140 * Nope, reset the current pointer to the end of the array...
143 cupsArrayIndex(ppd
->sorted_attrs
, cupsArrayCount(ppd
->sorted_attrs
));
149 * Return the next attribute's value...
157 * '_ppdGet1284Values()' - Get 1284 device ID keys and values.
159 * The returned dictionary is a CUPS option array that can be queried with
160 * cupsGetOption and freed with cupsFreeOptions.
163 int /* O - Number of key/value pairs */
165 const char *device_id
, /* I - IEEE-1284 device ID string */
166 cups_option_t
**values
) /* O - Array of key/value pairs */
168 int num_values
; /* Number of values */
169 char key
[256], /* Key string */
170 value
[256], /* Value string */
171 *ptr
; /* Pointer into key/value */
175 * Range check input...
181 if (!device_id
|| !values
)
185 * Parse the 1284 device ID value into keys and values. The format is
186 * repeating sequences of:
188 * [whitespace]key:value[whitespace];
194 while (isspace(*device_id
& 255))
200 for (ptr
= key
; *device_id
&& *device_id
!= ':'; device_id
++)
201 if (ptr
< (key
+ sizeof(key
) - 1))
207 while (ptr
> key
&& isspace(ptr
[-1] & 255))
213 while (isspace(*device_id
& 255))
219 for (ptr
= value
; *device_id
&& *device_id
!= ';'; device_id
++)
220 if (ptr
< (value
+ sizeof(value
) - 1))
226 while (ptr
> value
&& isspace(ptr
[-1] & 255))
232 num_values
= cupsAddOption(key
, value
, num_values
, values
);
240 * '_ppdNormalizeMakeAndModel()' - Normalize a product/make-and-model string.
242 * This function tries to undo the mistakes made by many printer manufacturers
243 * to produce a clean make-and-model string we can use.
246 char * /* O - Normalized make-and-model string or NULL on error */
247 _ppdNormalizeMakeAndModel(
248 const char *make_and_model
, /* I - Original make-and-model string */
249 char *buffer
, /* I - String buffer */
250 size_t bufsize
) /* I - Size of string buffer */
252 char *bufptr
; /* Pointer into buffer */
255 if (!make_and_model
|| !buffer
|| bufsize
< 1)
264 * Skip leading whitespace...
267 while (isspace(*make_and_model
& 255))
271 * Remove parenthesis and add manufacturers as needed...
274 if (make_and_model
[0] == '(')
276 strlcpy(buffer
, make_and_model
+ 1, bufsize
);
278 if ((bufptr
= strrchr(buffer
, ')')) != NULL
)
281 else if (!strncasecmp(make_and_model
, "XPrint", 6))
287 snprintf(buffer
, bufsize
, "Xerox %s", make_and_model
);
289 else if (!strncasecmp(make_and_model
, "Eastman", 7))
295 snprintf(buffer
, bufsize
, "Kodak %s", make_and_model
+ 7);
297 else if (!strncasecmp(make_and_model
, "laserwriter", 11))
300 * Apple LaserWriter...
303 snprintf(buffer
, bufsize
, "Apple LaserWriter%s", make_and_model
+ 11);
305 else if (!strncasecmp(make_and_model
, "colorpoint", 10))
311 snprintf(buffer
, bufsize
, "Seiko %s", make_and_model
);
313 else if (!strncasecmp(make_and_model
, "fiery", 5))
319 snprintf(buffer
, bufsize
, "EFI %s", make_and_model
);
321 else if (!strncasecmp(make_and_model
, "ps ", 3) ||
322 !strncasecmp(make_and_model
, "colorpass", 9))
328 snprintf(buffer
, bufsize
, "Canon %s", make_and_model
);
330 else if (!strncasecmp(make_and_model
, "primera", 7))
336 snprintf(buffer
, bufsize
, "Fargo %s", make_and_model
);
338 else if (!strncasecmp(make_and_model
, "designjet", 9) ||
339 !strncasecmp(make_and_model
, "deskjet", 7))
345 snprintf(buffer
, bufsize
, "HP %s", make_and_model
);
348 strlcpy(buffer
, make_and_model
, bufsize
);
351 * Clean up the make...
354 if (!strncasecmp(buffer
, "agfa", 4))
357 * Replace with AGFA (all uppercase)...
365 else if (!strncasecmp(buffer
, "Hewlett-Packard hp ", 19))
368 * Just put "HP" on the front...
373 _cups_strcpy(buffer
+ 2, buffer
+ 18);
375 else if (!strncasecmp(buffer
, "Hewlett-Packard ", 16))
378 * Just put "HP" on the front...
383 _cups_strcpy(buffer
+ 2, buffer
+ 15);
385 else if (!strncasecmp(buffer
, "Lexmark International", 21))
388 * Strip "International"...
391 _cups_strcpy(buffer
+ 8, buffer
+ 21);
393 else if (!strncasecmp(buffer
, "herk", 4))
396 * Replace with LHAG...
404 else if (!strncasecmp(buffer
, "linotype", 8))
407 * Replace with LHAG...
414 _cups_strcpy(buffer
+ 4, buffer
+ 8);
418 * Remove trailing whitespace and return...
421 for (bufptr
= buffer
+ strlen(buffer
) - 1;
422 bufptr
>= buffer
&& isspace(*bufptr
& 255);
427 return (buffer
[0] ? buffer
: NULL
);
432 * End of "$Id: attr.c 7584 2008-05-16 22:55:53Z mike $".