]>
git.ipfire.org Git - thirdparty/cups.git/blob - cups/ppd-attr.c
2 * PPD model-specific attribute routines for CUPS.
4 * Copyright 2007-2015 by Apple Inc.
5 * Copyright 1997-2006 by Easy Software Products.
7 * Licensed under Apache License v2.0. See the file "LICENSE" for more
12 * Include necessary headers...
15 #include "cups-private.h"
16 #include "ppd-private.h"
20 * 'ppdFindAttr()' - Find the first matching attribute.
22 * @since CUPS 1.1.19/macOS 10.3@
25 ppd_attr_t
* /* O - Attribute or @code NULL@ if not found */
26 ppdFindAttr(ppd_file_t
*ppd
, /* I - PPD file data */
27 const char *name
, /* I - Attribute name */
28 const char *spec
) /* I - Specifier string or @code NULL@ */
30 ppd_attr_t key
, /* Search key */
31 *attr
; /* Current attribute */
34 DEBUG_printf(("2ppdFindAttr(ppd=%p, name=\"%s\", spec=\"%s\")", ppd
, name
,
38 * Range check input...
41 if (!ppd
|| !name
|| ppd
->num_attrs
== 0)
45 * Search for a matching attribute...
48 memset(&key
, 0, sizeof(key
));
49 strlcpy(key
.name
, name
, sizeof(key
.name
));
52 * Return the first matching attribute, if any...
55 if ((attr
= (ppd_attr_t
*)cupsArrayFind(ppd
->sorted_attrs
, &key
)) != NULL
)
60 * Loop until we find the first matching attribute for "spec"...
63 while (attr
&& _cups_strcasecmp(spec
, attr
->spec
))
65 if ((attr
= (ppd_attr_t
*)cupsArrayNext(ppd
->sorted_attrs
)) != NULL
&&
66 _cups_strcasecmp(attr
->name
, name
))
77 * 'ppdFindNextAttr()' - Find the next matching attribute.
79 * @since CUPS 1.1.19/macOS 10.3@
82 ppd_attr_t
* /* O - Attribute or @code NULL@ if not found */
83 ppdFindNextAttr(ppd_file_t
*ppd
, /* I - PPD file data */
84 const char *name
, /* I - Attribute name */
85 const char *spec
) /* I - Specifier string or @code NULL@ */
87 ppd_attr_t
*attr
; /* Current attribute */
91 * Range check input...
94 if (!ppd
|| !name
|| ppd
->num_attrs
== 0)
98 * See if there are more attributes to return...
101 while ((attr
= (ppd_attr_t
*)cupsArrayNext(ppd
->sorted_attrs
)) != NULL
)
104 * Check the next attribute to see if it is a match...
107 if (_cups_strcasecmp(attr
->name
, name
))
110 * Nope, reset the current pointer to the end of the array...
113 cupsArrayIndex(ppd
->sorted_attrs
, cupsArrayCount(ppd
->sorted_attrs
));
118 if (!spec
|| !_cups_strcasecmp(attr
->spec
, spec
))
123 * Return the next attribute's value...
131 * '_ppdNormalizeMakeAndModel()' - Normalize a product/make-and-model string.
133 * This function tries to undo the mistakes made by many printer manufacturers
134 * to produce a clean make-and-model string we can use.
137 char * /* O - Normalized make-and-model string or NULL on error */
138 _ppdNormalizeMakeAndModel(
139 const char *make_and_model
, /* I - Original make-and-model string */
140 char *buffer
, /* I - String buffer */
141 size_t bufsize
) /* I - Size of string buffer */
143 char *bufptr
; /* Pointer into buffer */
146 if (!make_and_model
|| !buffer
|| bufsize
< 1)
155 * Skip leading whitespace...
158 while (_cups_isspace(*make_and_model
))
162 * Remove parenthesis and add manufacturers as needed...
165 if (make_and_model
[0] == '(')
167 strlcpy(buffer
, make_and_model
+ 1, bufsize
);
169 if ((bufptr
= strrchr(buffer
, ')')) != NULL
)
172 else if (!_cups_strncasecmp(make_and_model
, "XPrint", 6))
178 snprintf(buffer
, bufsize
, "Xerox %s", make_and_model
);
180 else if (!_cups_strncasecmp(make_and_model
, "Eastman", 7))
186 snprintf(buffer
, bufsize
, "Kodak %s", make_and_model
+ 7);
188 else if (!_cups_strncasecmp(make_and_model
, "laserwriter", 11))
191 * Apple LaserWriter...
194 snprintf(buffer
, bufsize
, "Apple LaserWriter%s", make_and_model
+ 11);
196 else if (!_cups_strncasecmp(make_and_model
, "colorpoint", 10))
202 snprintf(buffer
, bufsize
, "Seiko %s", make_and_model
);
204 else if (!_cups_strncasecmp(make_and_model
, "fiery", 5))
210 snprintf(buffer
, bufsize
, "EFI %s", make_and_model
);
212 else if (!_cups_strncasecmp(make_and_model
, "ps ", 3) ||
213 !_cups_strncasecmp(make_and_model
, "colorpass", 9))
219 snprintf(buffer
, bufsize
, "Canon %s", make_and_model
);
221 else if (!_cups_strncasecmp(make_and_model
, "designjet", 9) ||
222 !_cups_strncasecmp(make_and_model
, "deskjet", 7))
228 snprintf(buffer
, bufsize
, "HP %s", make_and_model
);
231 strlcpy(buffer
, make_and_model
, bufsize
);
234 * Clean up the make...
237 if (!_cups_strncasecmp(buffer
, "agfa", 4))
240 * Replace with AGFA (all uppercase)...
248 else if (!_cups_strncasecmp(buffer
, "Hewlett-Packard hp ", 19))
251 * Just put "HP" on the front...
256 _cups_strcpy(buffer
+ 2, buffer
+ 18);
258 else if (!_cups_strncasecmp(buffer
, "Hewlett-Packard ", 16))
261 * Just put "HP" on the front...
266 _cups_strcpy(buffer
+ 2, buffer
+ 15);
268 else if (!_cups_strncasecmp(buffer
, "Lexmark International", 21))
271 * Strip "International"...
274 _cups_strcpy(buffer
+ 8, buffer
+ 21);
276 else if (!_cups_strncasecmp(buffer
, "herk", 4))
279 * Replace with LHAG...
287 else if (!_cups_strncasecmp(buffer
, "linotype", 8))
290 * Replace with LHAG...
297 _cups_strcpy(buffer
+ 4, buffer
+ 8);
301 * Remove trailing whitespace and return...
304 for (bufptr
= buffer
+ strlen(buffer
) - 1;
305 bufptr
>= buffer
&& _cups_isspace(*bufptr
);
310 return (buffer
[0] ? buffer
: NULL
);