]>
git.ipfire.org Git - thirdparty/cups.git/blob - cups/ppd-attr.c
6324e6e15b98781fdc7cf0c3b78b123cc8994364
2 * PPD model-specific attribute routines for CUPS.
4 * Copyright 2007-2015 by Apple Inc.
5 * Copyright 1997-2006 by Easy Software Products.
7 * These coded instructions, statements, and computer programs are the
8 * property of Apple Inc. and are protected by Federal copyright
9 * law. Distribution and use rights are outlined in the file "LICENSE.txt"
10 * which should have been included with this file. If this file is
11 * file is missing or damaged, see the license at "http://www.cups.org/".
15 * Include necessary headers...
18 #include "cups-private.h"
19 #include "ppd-private.h"
23 * 'ppdFindAttr()' - Find the first matching attribute.
25 * @since CUPS 1.1.19/macOS 10.3@
28 ppd_attr_t
* /* O - Attribute or @code NULL@ if not found */
29 ppdFindAttr(ppd_file_t
*ppd
, /* I - PPD file data */
30 const char *name
, /* I - Attribute name */
31 const char *spec
) /* I - Specifier string or @code NULL@ */
33 ppd_attr_t key
, /* Search key */
34 *attr
; /* Current attribute */
37 DEBUG_printf(("2ppdFindAttr(ppd=%p, name=\"%s\", spec=\"%s\")", ppd
, name
,
41 * Range check input...
44 if (!ppd
|| !name
|| ppd
->num_attrs
== 0)
48 * Search for a matching attribute...
51 memset(&key
, 0, sizeof(key
));
52 strlcpy(key
.name
, name
, sizeof(key
.name
));
55 * Return the first matching attribute, if any...
58 if ((attr
= (ppd_attr_t
*)cupsArrayFind(ppd
->sorted_attrs
, &key
)) != NULL
)
63 * Loop until we find the first matching attribute for "spec"...
66 while (attr
&& _cups_strcasecmp(spec
, attr
->spec
))
68 if ((attr
= (ppd_attr_t
*)cupsArrayNext(ppd
->sorted_attrs
)) != NULL
&&
69 _cups_strcasecmp(attr
->name
, name
))
80 * 'ppdFindNextAttr()' - Find the next matching attribute.
82 * @since CUPS 1.1.19/macOS 10.3@
85 ppd_attr_t
* /* O - Attribute or @code NULL@ if not found */
86 ppdFindNextAttr(ppd_file_t
*ppd
, /* I - PPD file data */
87 const char *name
, /* I - Attribute name */
88 const char *spec
) /* I - Specifier string or @code NULL@ */
90 ppd_attr_t
*attr
; /* Current attribute */
94 * Range check input...
97 if (!ppd
|| !name
|| ppd
->num_attrs
== 0)
101 * See if there are more attributes to return...
104 while ((attr
= (ppd_attr_t
*)cupsArrayNext(ppd
->sorted_attrs
)) != NULL
)
107 * Check the next attribute to see if it is a match...
110 if (_cups_strcasecmp(attr
->name
, name
))
113 * Nope, reset the current pointer to the end of the array...
116 cupsArrayIndex(ppd
->sorted_attrs
, cupsArrayCount(ppd
->sorted_attrs
));
121 if (!spec
|| !_cups_strcasecmp(attr
->spec
, spec
))
126 * Return the next attribute's value...
134 * '_ppdNormalizeMakeAndModel()' - Normalize a product/make-and-model string.
136 * This function tries to undo the mistakes made by many printer manufacturers
137 * to produce a clean make-and-model string we can use.
140 char * /* O - Normalized make-and-model string or NULL on error */
141 _ppdNormalizeMakeAndModel(
142 const char *make_and_model
, /* I - Original make-and-model string */
143 char *buffer
, /* I - String buffer */
144 size_t bufsize
) /* I - Size of string buffer */
146 char *bufptr
; /* Pointer into buffer */
149 if (!make_and_model
|| !buffer
|| bufsize
< 1)
158 * Skip leading whitespace...
161 while (_cups_isspace(*make_and_model
))
165 * Remove parenthesis and add manufacturers as needed...
168 if (make_and_model
[0] == '(')
170 strlcpy(buffer
, make_and_model
+ 1, bufsize
);
172 if ((bufptr
= strrchr(buffer
, ')')) != NULL
)
175 else if (!_cups_strncasecmp(make_and_model
, "XPrint", 6))
181 snprintf(buffer
, bufsize
, "Xerox %s", make_and_model
);
183 else if (!_cups_strncasecmp(make_and_model
, "Eastman", 7))
189 snprintf(buffer
, bufsize
, "Kodak %s", make_and_model
+ 7);
191 else if (!_cups_strncasecmp(make_and_model
, "laserwriter", 11))
194 * Apple LaserWriter...
197 snprintf(buffer
, bufsize
, "Apple LaserWriter%s", make_and_model
+ 11);
199 else if (!_cups_strncasecmp(make_and_model
, "colorpoint", 10))
205 snprintf(buffer
, bufsize
, "Seiko %s", make_and_model
);
207 else if (!_cups_strncasecmp(make_and_model
, "fiery", 5))
213 snprintf(buffer
, bufsize
, "EFI %s", make_and_model
);
215 else if (!_cups_strncasecmp(make_and_model
, "ps ", 3) ||
216 !_cups_strncasecmp(make_and_model
, "colorpass", 9))
222 snprintf(buffer
, bufsize
, "Canon %s", make_and_model
);
224 else if (!_cups_strncasecmp(make_and_model
, "designjet", 9) ||
225 !_cups_strncasecmp(make_and_model
, "deskjet", 7))
231 snprintf(buffer
, bufsize
, "HP %s", make_and_model
);
234 strlcpy(buffer
, make_and_model
, bufsize
);
237 * Clean up the make...
240 if (!_cups_strncasecmp(buffer
, "agfa", 4))
243 * Replace with AGFA (all uppercase)...
251 else if (!_cups_strncasecmp(buffer
, "Hewlett-Packard hp ", 19))
254 * Just put "HP" on the front...
259 _cups_strcpy(buffer
+ 2, buffer
+ 18);
261 else if (!_cups_strncasecmp(buffer
, "Hewlett-Packard ", 16))
264 * Just put "HP" on the front...
269 _cups_strcpy(buffer
+ 2, buffer
+ 15);
271 else if (!_cups_strncasecmp(buffer
, "Lexmark International", 21))
274 * Strip "International"...
277 _cups_strcpy(buffer
+ 8, buffer
+ 21);
279 else if (!_cups_strncasecmp(buffer
, "herk", 4))
282 * Replace with LHAG...
290 else if (!_cups_strncasecmp(buffer
, "linotype", 8))
293 * Replace with LHAG...
300 _cups_strcpy(buffer
+ 4, buffer
+ 8);
304 * Remove trailing whitespace and return...
307 for (bufptr
= buffer
+ strlen(buffer
) - 1;
308 bufptr
>= buffer
&& _cups_isspace(*bufptr
);
313 return (buffer
[0] ? buffer
: NULL
);