]>
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-2009 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.
35 * @since CUPS 1.1.19/Mac OS X 10.3@
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 */
47 DEBUG_printf(("2ppdFindAttr(ppd=%p, name=\"%s\", spec=\"%s\")", ppd
, name
,
51 * Range check input...
54 if (!ppd
|| !name
|| ppd
->num_attrs
== 0)
58 * Search for a matching attribute...
61 memset(&key
, 0, sizeof(key
));
62 strlcpy(key
.name
, name
, sizeof(key
.name
));
65 * Return the first matching attribute, if any...
68 if ((attr
= (ppd_attr_t
*)cupsArrayFind(ppd
->sorted_attrs
, &key
)) != NULL
)
73 * Loop until we find the first matching attribute for "spec"...
76 while (attr
&& strcasecmp(spec
, attr
->spec
))
78 if ((attr
= (ppd_attr_t
*)cupsArrayNext(ppd
->sorted_attrs
)) != NULL
&&
79 strcasecmp(attr
->name
, name
))
90 * 'ppdFindNextAttr()' - Find the next matching attribute.
92 * @since CUPS 1.1.19/Mac OS X 10.3@
95 ppd_attr_t
* /* O - Attribute or @code NULL@ if not found */
96 ppdFindNextAttr(ppd_file_t
*ppd
, /* I - PPD file data */
97 const char *name
, /* I - Attribute name */
98 const char *spec
) /* I - Specifier string or @code NULL@ */
100 ppd_attr_t
*attr
; /* Current attribute */
104 * Range check input...
107 if (!ppd
|| !name
|| ppd
->num_attrs
== 0)
111 * See if there are more attributes to return...
114 while ((attr
= (ppd_attr_t
*)cupsArrayNext(ppd
->sorted_attrs
)) != NULL
)
117 * Check the next attribute to see if it is a match...
120 if (strcasecmp(attr
->name
, name
))
123 * Nope, reset the current pointer to the end of the array...
126 cupsArrayIndex(ppd
->sorted_attrs
, cupsArrayCount(ppd
->sorted_attrs
));
131 if (!spec
|| !strcasecmp(attr
->spec
, spec
))
136 * Return the next attribute's value...
144 * '_ppdGet1284Values()' - Get 1284 device ID keys and values.
146 * The returned dictionary is a CUPS option array that can be queried with
147 * cupsGetOption and freed with cupsFreeOptions.
150 int /* O - Number of key/value pairs */
152 const char *device_id
, /* I - IEEE-1284 device ID string */
153 cups_option_t
**values
) /* O - Array of key/value pairs */
155 int num_values
; /* Number of values */
156 char key
[256], /* Key string */
157 value
[256], /* Value string */
158 *ptr
; /* Pointer into key/value */
162 * Range check input...
168 if (!device_id
|| !values
)
172 * Parse the 1284 device ID value into keys and values. The format is
173 * repeating sequences of:
175 * [whitespace]key:value[whitespace];
181 while (isspace(*device_id
& 255))
187 for (ptr
= key
; *device_id
&& *device_id
!= ':'; device_id
++)
188 if (ptr
< (key
+ sizeof(key
) - 1))
194 while (ptr
> key
&& isspace(ptr
[-1] & 255))
200 while (isspace(*device_id
& 255))
206 for (ptr
= value
; *device_id
&& *device_id
!= ';'; device_id
++)
207 if (ptr
< (value
+ sizeof(value
) - 1))
213 while (ptr
> value
&& isspace(ptr
[-1] & 255))
219 num_values
= cupsAddOption(key
, value
, num_values
, values
);
227 * '_ppdNormalizeMakeAndModel()' - Normalize a product/make-and-model string.
229 * This function tries to undo the mistakes made by many printer manufacturers
230 * to produce a clean make-and-model string we can use.
233 char * /* O - Normalized make-and-model string or NULL on error */
234 _ppdNormalizeMakeAndModel(
235 const char *make_and_model
, /* I - Original make-and-model string */
236 char *buffer
, /* I - String buffer */
237 size_t bufsize
) /* I - Size of string buffer */
239 char *bufptr
; /* Pointer into buffer */
242 if (!make_and_model
|| !buffer
|| bufsize
< 1)
251 * Skip leading whitespace...
254 while (isspace(*make_and_model
& 255))
258 * Remove parenthesis and add manufacturers as needed...
261 if (make_and_model
[0] == '(')
263 strlcpy(buffer
, make_and_model
+ 1, bufsize
);
265 if ((bufptr
= strrchr(buffer
, ')')) != NULL
)
268 else if (!strncasecmp(make_and_model
, "XPrint", 6))
274 snprintf(buffer
, bufsize
, "Xerox %s", make_and_model
);
276 else if (!strncasecmp(make_and_model
, "Eastman", 7))
282 snprintf(buffer
, bufsize
, "Kodak %s", make_and_model
+ 7);
284 else if (!strncasecmp(make_and_model
, "laserwriter", 11))
287 * Apple LaserWriter...
290 snprintf(buffer
, bufsize
, "Apple LaserWriter%s", make_and_model
+ 11);
292 else if (!strncasecmp(make_and_model
, "colorpoint", 10))
298 snprintf(buffer
, bufsize
, "Seiko %s", make_and_model
);
300 else if (!strncasecmp(make_and_model
, "fiery", 5))
306 snprintf(buffer
, bufsize
, "EFI %s", make_and_model
);
308 else if (!strncasecmp(make_and_model
, "ps ", 3) ||
309 !strncasecmp(make_and_model
, "colorpass", 9))
315 snprintf(buffer
, bufsize
, "Canon %s", make_and_model
);
317 else if (!strncasecmp(make_and_model
, "primera", 7))
323 snprintf(buffer
, bufsize
, "Fargo %s", make_and_model
);
325 else if (!strncasecmp(make_and_model
, "designjet", 9) ||
326 !strncasecmp(make_and_model
, "deskjet", 7))
332 snprintf(buffer
, bufsize
, "HP %s", make_and_model
);
335 strlcpy(buffer
, make_and_model
, bufsize
);
338 * Clean up the make...
341 if (!strncasecmp(buffer
, "agfa", 4))
344 * Replace with AGFA (all uppercase)...
352 else if (!strncasecmp(buffer
, "Hewlett-Packard hp ", 19))
355 * Just put "HP" on the front...
360 _cups_strcpy(buffer
+ 2, buffer
+ 18);
362 else if (!strncasecmp(buffer
, "Hewlett-Packard ", 16))
365 * Just put "HP" on the front...
370 _cups_strcpy(buffer
+ 2, buffer
+ 15);
372 else if (!strncasecmp(buffer
, "Lexmark International", 21))
375 * Strip "International"...
378 _cups_strcpy(buffer
+ 8, buffer
+ 21);
380 else if (!strncasecmp(buffer
, "herk", 4))
383 * Replace with LHAG...
391 else if (!strncasecmp(buffer
, "linotype", 8))
394 * Replace with LHAG...
401 _cups_strcpy(buffer
+ 4, buffer
+ 8);
405 * Remove trailing whitespace and return...
408 for (bufptr
= buffer
+ strlen(buffer
) - 1;
409 bufptr
>= buffer
&& isspace(*bufptr
& 255);
414 return (buffer
[0] ? buffer
: NULL
);
419 * End of "$Id: attr.c 7584 2008-05-16 22:55:53Z mike $".