2 * "$Id: attr.c 9793 2011-05-20 03:49:49Z mike $"
4 * PPD model-specific attribute routines for CUPS.
6 * Copyright 2007-2011 by Apple Inc.
7 * Copyright 1997-2006 by Easy Software Products.
9 * These coded instructions, statements, and computer programs are the
10 * property of Apple Inc. and are protected by Federal copyright
11 * law. Distribution and use rights are outlined in the file "LICENSE.txt"
12 * which should have been included with this file. If this file is
13 * file is missing or damaged, see the license at "http://www.cups.org/".
17 * ppdFindAttr() - Find the first matching attribute.
18 * ppdFindNextAttr() - Find the next matching attribute.
19 * _ppdNormalizeMakeAndModel() - Normalize a product/make-and-model string.
23 * Include necessary headers...
26 #include "cups-private.h"
27 #include "ppd-private.h"
31 * 'ppdFindAttr()' - Find the first matching attribute.
33 * @since CUPS 1.1.19/Mac OS X 10.3@
36 ppd_attr_t * /* O - Attribute or @code NULL@ if not found */
37 ppdFindAttr(ppd_file_t *ppd, /* I - PPD file data */
38 const char *name, /* I - Attribute name */
39 const char *spec) /* I - Specifier string or @code NULL@ */
41 ppd_attr_t key, /* Search key */
42 *attr; /* Current attribute */
45 DEBUG_printf(("2ppdFindAttr(ppd=%p, name=\"%s\", spec=\"%s\")", ppd, name,
49 * Range check input...
52 if (!ppd || !name || ppd->num_attrs == 0)
56 * Search for a matching attribute...
59 memset(&key, 0, sizeof(key));
60 strlcpy(key.name, name, sizeof(key.name));
63 * Return the first matching attribute, if any...
66 if ((attr = (ppd_attr_t *)cupsArrayFind(ppd->sorted_attrs, &key)) != NULL)
71 * Loop until we find the first matching attribute for "spec"...
74 while (attr && _cups_strcasecmp(spec, attr->spec))
76 if ((attr = (ppd_attr_t *)cupsArrayNext(ppd->sorted_attrs)) != NULL &&
77 _cups_strcasecmp(attr->name, name))
88 * 'ppdFindNextAttr()' - Find the next matching attribute.
90 * @since CUPS 1.1.19/Mac OS X 10.3@
93 ppd_attr_t * /* O - Attribute or @code NULL@ if not found */
94 ppdFindNextAttr(ppd_file_t *ppd, /* I - PPD file data */
95 const char *name, /* I - Attribute name */
96 const char *spec) /* I - Specifier string or @code NULL@ */
98 ppd_attr_t *attr; /* Current attribute */
102 * Range check input...
105 if (!ppd || !name || ppd->num_attrs == 0)
109 * See if there are more attributes to return...
112 while ((attr = (ppd_attr_t *)cupsArrayNext(ppd->sorted_attrs)) != NULL)
115 * Check the next attribute to see if it is a match...
118 if (_cups_strcasecmp(attr->name, name))
121 * Nope, reset the current pointer to the end of the array...
124 cupsArrayIndex(ppd->sorted_attrs, cupsArrayCount(ppd->sorted_attrs));
129 if (!spec || !_cups_strcasecmp(attr->spec, spec))
134 * Return the next attribute's value...
142 * '_ppdNormalizeMakeAndModel()' - Normalize a product/make-and-model string.
144 * This function tries to undo the mistakes made by many printer manufacturers
145 * to produce a clean make-and-model string we can use.
148 char * /* O - Normalized make-and-model string or NULL on error */
149 _ppdNormalizeMakeAndModel(
150 const char *make_and_model, /* I - Original make-and-model string */
151 char *buffer, /* I - String buffer */
152 size_t bufsize) /* I - Size of string buffer */
154 char *bufptr; /* Pointer into buffer */
157 if (!make_and_model || !buffer || bufsize < 1)
166 * Skip leading whitespace...
169 while (_cups_isspace(*make_and_model))
173 * Remove parenthesis and add manufacturers as needed...
176 if (make_and_model[0] == '(')
178 strlcpy(buffer, make_and_model + 1, bufsize);
180 if ((bufptr = strrchr(buffer, ')')) != NULL)
183 else if (!_cups_strncasecmp(make_and_model, "XPrint", 6))
189 snprintf(buffer, bufsize, "Xerox %s", make_and_model);
191 else if (!_cups_strncasecmp(make_and_model, "Eastman", 7))
197 snprintf(buffer, bufsize, "Kodak %s", make_and_model + 7);
199 else if (!_cups_strncasecmp(make_and_model, "laserwriter", 11))
202 * Apple LaserWriter...
205 snprintf(buffer, bufsize, "Apple LaserWriter%s", make_and_model + 11);
207 else if (!_cups_strncasecmp(make_and_model, "colorpoint", 10))
213 snprintf(buffer, bufsize, "Seiko %s", make_and_model);
215 else if (!_cups_strncasecmp(make_and_model, "fiery", 5))
221 snprintf(buffer, bufsize, "EFI %s", make_and_model);
223 else if (!_cups_strncasecmp(make_and_model, "ps ", 3) ||
224 !_cups_strncasecmp(make_and_model, "colorpass", 9))
230 snprintf(buffer, bufsize, "Canon %s", make_and_model);
232 else if (!_cups_strncasecmp(make_and_model, "primera", 7))
238 snprintf(buffer, bufsize, "Fargo %s", make_and_model);
240 else if (!_cups_strncasecmp(make_and_model, "designjet", 9) ||
241 !_cups_strncasecmp(make_and_model, "deskjet", 7))
247 snprintf(buffer, bufsize, "HP %s", make_and_model);
250 strlcpy(buffer, make_and_model, bufsize);
253 * Clean up the make...
256 if (!_cups_strncasecmp(buffer, "agfa", 4))
259 * Replace with AGFA (all uppercase)...
267 else if (!_cups_strncasecmp(buffer, "Hewlett-Packard hp ", 19))
270 * Just put "HP" on the front...
275 _cups_strcpy(buffer + 2, buffer + 18);
277 else if (!_cups_strncasecmp(buffer, "Hewlett-Packard ", 16))
280 * Just put "HP" on the front...
285 _cups_strcpy(buffer + 2, buffer + 15);
287 else if (!_cups_strncasecmp(buffer, "Lexmark International", 21))
290 * Strip "International"...
293 _cups_strcpy(buffer + 8, buffer + 21);
295 else if (!_cups_strncasecmp(buffer, "herk", 4))
298 * Replace with LHAG...
306 else if (!_cups_strncasecmp(buffer, "linotype", 8))
309 * Replace with LHAG...
316 _cups_strcpy(buffer + 4, buffer + 8);
320 * Remove trailing whitespace and return...
323 for (bufptr = buffer + strlen(buffer) - 1;
324 bufptr >= buffer && _cups_isspace(*bufptr);
329 return (buffer[0] ? buffer : NULL);
334 * End of "$Id: attr.c 9793 2011-05-20 03:49:49Z mike $".