]>
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 information.
11 * Include necessary headers...
14 #include "cups-private.h"
15 #include "ppd-private.h"
19 * 'ppdFindAttr()' - Find the first matching attribute.
21 * @since CUPS 1.1.19/macOS 10.3@
24 ppd_attr_t
* /* O - Attribute or @code NULL@ if not found */
25 ppdFindAttr(ppd_file_t
*ppd
, /* I - PPD file data */
26 const char *name
, /* I - Attribute name */
27 const char *spec
) /* I - Specifier string or @code NULL@ */
29 ppd_attr_t key
, /* Search key */
30 *attr
; /* Current attribute */
33 DEBUG_printf(("2ppdFindAttr(ppd=%p, name=\"%s\", spec=\"%s\")", ppd
, name
,
37 * Range check input...
40 if (!ppd
|| !name
|| ppd
->num_attrs
== 0)
44 * Search for a matching attribute...
47 memset(&key
, 0, sizeof(key
));
48 strlcpy(key
.name
, name
, sizeof(key
.name
));
51 * Return the first matching attribute, if any...
54 if ((attr
= (ppd_attr_t
*)cupsArrayFind(ppd
->sorted_attrs
, &key
)) != NULL
)
59 * Loop until we find the first matching attribute for "spec"...
62 while (attr
&& _cups_strcasecmp(spec
, attr
->spec
))
64 if ((attr
= (ppd_attr_t
*)cupsArrayNext(ppd
->sorted_attrs
)) != NULL
&&
65 _cups_strcasecmp(attr
->name
, name
))
76 * 'ppdFindNextAttr()' - Find the next matching attribute.
78 * @since CUPS 1.1.19/macOS 10.3@
81 ppd_attr_t
* /* O - Attribute or @code NULL@ if not found */
82 ppdFindNextAttr(ppd_file_t
*ppd
, /* I - PPD file data */
83 const char *name
, /* I - Attribute name */
84 const char *spec
) /* I - Specifier string or @code NULL@ */
86 ppd_attr_t
*attr
; /* Current attribute */
90 * Range check input...
93 if (!ppd
|| !name
|| ppd
->num_attrs
== 0)
97 * See if there are more attributes to return...
100 while ((attr
= (ppd_attr_t
*)cupsArrayNext(ppd
->sorted_attrs
)) != NULL
)
103 * Check the next attribute to see if it is a match...
106 if (_cups_strcasecmp(attr
->name
, name
))
109 * Nope, reset the current pointer to the end of the array...
112 cupsArrayIndex(ppd
->sorted_attrs
, cupsArrayCount(ppd
->sorted_attrs
));
117 if (!spec
|| !_cups_strcasecmp(attr
->spec
, spec
))
122 * Return the next attribute's value...
130 * '_ppdNormalizeMakeAndModel()' - Normalize a product/make-and-model string.
132 * This function tries to undo the mistakes made by many printer manufacturers
133 * to produce a clean make-and-model string we can use.
136 char * /* O - Normalized make-and-model string or NULL on error */
137 _ppdNormalizeMakeAndModel(
138 const char *make_and_model
, /* I - Original make-and-model string */
139 char *buffer
, /* I - String buffer */
140 size_t bufsize
) /* I - Size of string buffer */
142 char *bufptr
; /* Pointer into buffer */
145 if (!make_and_model
|| !buffer
|| bufsize
< 1)
154 * Skip leading whitespace...
157 while (_cups_isspace(*make_and_model
))
161 * Remove parenthesis and add manufacturers as needed...
164 if (make_and_model
[0] == '(')
166 strlcpy(buffer
, make_and_model
+ 1, bufsize
);
168 if ((bufptr
= strrchr(buffer
, ')')) != NULL
)
171 else if (!_cups_strncasecmp(make_and_model
, "XPrint", 6))
177 snprintf(buffer
, bufsize
, "Xerox %s", make_and_model
);
179 else if (!_cups_strncasecmp(make_and_model
, "Eastman", 7))
185 snprintf(buffer
, bufsize
, "Kodak %s", make_and_model
+ 7);
187 else if (!_cups_strncasecmp(make_and_model
, "laserwriter", 11))
190 * Apple LaserWriter...
193 snprintf(buffer
, bufsize
, "Apple LaserWriter%s", make_and_model
+ 11);
195 else if (!_cups_strncasecmp(make_and_model
, "colorpoint", 10))
201 snprintf(buffer
, bufsize
, "Seiko %s", make_and_model
);
203 else if (!_cups_strncasecmp(make_and_model
, "fiery", 5))
209 snprintf(buffer
, bufsize
, "EFI %s", make_and_model
);
211 else if (!_cups_strncasecmp(make_and_model
, "ps ", 3) ||
212 !_cups_strncasecmp(make_and_model
, "colorpass", 9))
218 snprintf(buffer
, bufsize
, "Canon %s", make_and_model
);
220 else if (!_cups_strncasecmp(make_and_model
, "designjet", 9) ||
221 !_cups_strncasecmp(make_and_model
, "deskjet", 7))
227 snprintf(buffer
, bufsize
, "HP %s", make_and_model
);
230 strlcpy(buffer
, make_and_model
, bufsize
);
233 * Clean up the make...
236 if (!_cups_strncasecmp(buffer
, "agfa", 4))
239 * Replace with AGFA (all uppercase)...
247 else if (!_cups_strncasecmp(buffer
, "Hewlett-Packard hp ", 19))
250 * Just put "HP" on the front...
255 _cups_strcpy(buffer
+ 2, buffer
+ 18);
257 else if (!_cups_strncasecmp(buffer
, "Hewlett-Packard ", 16))
260 * Just put "HP" on the front...
265 _cups_strcpy(buffer
+ 2, buffer
+ 15);
267 else if (!_cups_strncasecmp(buffer
, "Lexmark International", 21))
270 * Strip "International"...
273 _cups_strcpy(buffer
+ 8, buffer
+ 21);
275 else if (!_cups_strncasecmp(buffer
, "herk", 4))
278 * Replace with LHAG...
286 else if (!_cups_strncasecmp(buffer
, "linotype", 8))
289 * Replace with LHAG...
296 _cups_strcpy(buffer
+ 4, buffer
+ 8);
300 * Remove trailing whitespace and return...
303 for (bufptr
= buffer
+ strlen(buffer
) - 1;
304 bufptr
>= buffer
&& _cups_isspace(*bufptr
);
309 return (buffer
[0] ? buffer
: NULL
);