]>
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"
17 #include "debug-internal.h"
21 * 'ppdFindAttr()' - Find the first matching attribute.
23 * @since CUPS 1.1.19/macOS 10.3@
26 ppd_attr_t
* /* O - Attribute or @code NULL@ if not found */
27 ppdFindAttr(ppd_file_t
*ppd
, /* I - PPD file data */
28 const char *name
, /* I - Attribute name */
29 const char *spec
) /* I - Specifier string or @code NULL@ */
31 ppd_attr_t key
, /* Search key */
32 *attr
; /* Current attribute */
35 DEBUG_printf(("2ppdFindAttr(ppd=%p, name=\"%s\", spec=\"%s\")", ppd
, name
,
39 * Range check input...
42 if (!ppd
|| !name
|| ppd
->num_attrs
== 0)
46 * Search for a matching attribute...
49 memset(&key
, 0, sizeof(key
));
50 strlcpy(key
.name
, name
, sizeof(key
.name
));
53 * Return the first matching attribute, if any...
56 if ((attr
= (ppd_attr_t
*)cupsArrayFind(ppd
->sorted_attrs
, &key
)) != NULL
)
61 * Loop until we find the first matching attribute for "spec"...
64 while (attr
&& _cups_strcasecmp(spec
, attr
->spec
))
66 if ((attr
= (ppd_attr_t
*)cupsArrayNext(ppd
->sorted_attrs
)) != NULL
&&
67 _cups_strcasecmp(attr
->name
, name
))
78 * 'ppdFindNextAttr()' - Find the next matching attribute.
80 * @since CUPS 1.1.19/macOS 10.3@
83 ppd_attr_t
* /* O - Attribute or @code NULL@ if not found */
84 ppdFindNextAttr(ppd_file_t
*ppd
, /* I - PPD file data */
85 const char *name
, /* I - Attribute name */
86 const char *spec
) /* I - Specifier string or @code NULL@ */
88 ppd_attr_t
*attr
; /* Current attribute */
92 * Range check input...
95 if (!ppd
|| !name
|| ppd
->num_attrs
== 0)
99 * See if there are more attributes to return...
102 while ((attr
= (ppd_attr_t
*)cupsArrayNext(ppd
->sorted_attrs
)) != NULL
)
105 * Check the next attribute to see if it is a match...
108 if (_cups_strcasecmp(attr
->name
, name
))
111 * Nope, reset the current pointer to the end of the array...
114 cupsArrayIndex(ppd
->sorted_attrs
, cupsArrayCount(ppd
->sorted_attrs
));
119 if (!spec
|| !_cups_strcasecmp(attr
->spec
, spec
))
124 * Return the next attribute's value...
132 * '_ppdNormalizeMakeAndModel()' - Normalize a product/make-and-model string.
134 * This function tries to undo the mistakes made by many printer manufacturers
135 * to produce a clean make-and-model string we can use.
138 char * /* O - Normalized make-and-model string or NULL on error */
139 _ppdNormalizeMakeAndModel(
140 const char *make_and_model
, /* I - Original make-and-model string */
141 char *buffer
, /* I - String buffer */
142 size_t bufsize
) /* I - Size of string buffer */
144 char *bufptr
; /* Pointer into buffer */
147 if (!make_and_model
|| !buffer
|| bufsize
< 1)
156 * Skip leading whitespace...
159 while (_cups_isspace(*make_and_model
))
163 * Remove parenthesis and add manufacturers as needed...
166 if (make_and_model
[0] == '(')
168 strlcpy(buffer
, make_and_model
+ 1, bufsize
);
170 if ((bufptr
= strrchr(buffer
, ')')) != NULL
)
173 else if (!_cups_strncasecmp(make_and_model
, "XPrint", 6))
179 snprintf(buffer
, bufsize
, "Xerox %s", make_and_model
);
181 else if (!_cups_strncasecmp(make_and_model
, "Eastman", 7))
187 snprintf(buffer
, bufsize
, "Kodak %s", make_and_model
+ 7);
189 else if (!_cups_strncasecmp(make_and_model
, "laserwriter", 11))
192 * Apple LaserWriter...
195 snprintf(buffer
, bufsize
, "Apple LaserWriter%s", make_and_model
+ 11);
197 else if (!_cups_strncasecmp(make_and_model
, "colorpoint", 10))
203 snprintf(buffer
, bufsize
, "Seiko %s", make_and_model
);
205 else if (!_cups_strncasecmp(make_and_model
, "fiery", 5))
211 snprintf(buffer
, bufsize
, "EFI %s", make_and_model
);
213 else if (!_cups_strncasecmp(make_and_model
, "ps ", 3) ||
214 !_cups_strncasecmp(make_and_model
, "colorpass", 9))
220 snprintf(buffer
, bufsize
, "Canon %s", make_and_model
);
222 else if (!_cups_strncasecmp(make_and_model
, "designjet", 9) ||
223 !_cups_strncasecmp(make_and_model
, "deskjet", 7))
229 snprintf(buffer
, bufsize
, "HP %s", make_and_model
);
232 strlcpy(buffer
, make_and_model
, bufsize
);
235 * Clean up the make...
238 if (!_cups_strncasecmp(buffer
, "agfa", 4))
241 * Replace with AGFA (all uppercase)...
249 else if (!_cups_strncasecmp(buffer
, "Hewlett-Packard hp ", 19))
252 * Just put "HP" on the front...
257 _cups_strcpy(buffer
+ 2, buffer
+ 18);
259 else if (!_cups_strncasecmp(buffer
, "Hewlett-Packard ", 16))
262 * Just put "HP" on the front...
267 _cups_strcpy(buffer
+ 2, buffer
+ 15);
269 else if (!_cups_strncasecmp(buffer
, "Lexmark International", 21))
272 * Strip "International"...
275 _cups_strcpy(buffer
+ 8, buffer
+ 21);
277 else if (!_cups_strncasecmp(buffer
, "herk", 4))
280 * Replace with LHAG...
288 else if (!_cups_strncasecmp(buffer
, "linotype", 8))
291 * Replace with LHAG...
298 _cups_strcpy(buffer
+ 4, buffer
+ 8);
302 * Remove trailing whitespace and return...
305 for (bufptr
= buffer
+ strlen(buffer
) - 1;
306 bufptr
>= buffer
&& _cups_isspace(*bufptr
);
311 return (buffer
[0] ? buffer
: NULL
);