]>
git.ipfire.org Git - thirdparty/cups.git/blob - cups/attr.c
4 * PPD model-specific attribute routines for CUPS.
6 * Copyright 2007-2015 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 * Include necessary headers...
20 #include "cups-private.h"
21 #include "ppd-private.h"
25 * 'ppdFindAttr()' - Find the first matching attribute.
27 * @since CUPS 1.1.19/OS X 10.3@
30 ppd_attr_t
* /* O - Attribute or @code NULL@ if not found */
31 ppdFindAttr(ppd_file_t
*ppd
, /* I - PPD file data */
32 const char *name
, /* I - Attribute name */
33 const char *spec
) /* I - Specifier string or @code NULL@ */
35 ppd_attr_t key
, /* Search key */
36 *attr
; /* Current attribute */
39 DEBUG_printf(("2ppdFindAttr(ppd=%p, name=\"%s\", spec=\"%s\")", ppd
, name
,
43 * Range check input...
46 if (!ppd
|| !name
|| ppd
->num_attrs
== 0)
50 * Search for a matching attribute...
53 memset(&key
, 0, sizeof(key
));
54 strlcpy(key
.name
, name
, sizeof(key
.name
));
57 * Return the first matching attribute, if any...
60 if ((attr
= (ppd_attr_t
*)cupsArrayFind(ppd
->sorted_attrs
, &key
)) != NULL
)
65 * Loop until we find the first matching attribute for "spec"...
68 while (attr
&& _cups_strcasecmp(spec
, attr
->spec
))
70 if ((attr
= (ppd_attr_t
*)cupsArrayNext(ppd
->sorted_attrs
)) != NULL
&&
71 _cups_strcasecmp(attr
->name
, name
))
82 * 'ppdFindNextAttr()' - Find the next matching attribute.
84 * @since CUPS 1.1.19/OS X 10.3@
87 ppd_attr_t
* /* O - Attribute or @code NULL@ if not found */
88 ppdFindNextAttr(ppd_file_t
*ppd
, /* I - PPD file data */
89 const char *name
, /* I - Attribute name */
90 const char *spec
) /* I - Specifier string or @code NULL@ */
92 ppd_attr_t
*attr
; /* Current attribute */
96 * Range check input...
99 if (!ppd
|| !name
|| ppd
->num_attrs
== 0)
103 * See if there are more attributes to return...
106 while ((attr
= (ppd_attr_t
*)cupsArrayNext(ppd
->sorted_attrs
)) != NULL
)
109 * Check the next attribute to see if it is a match...
112 if (_cups_strcasecmp(attr
->name
, name
))
115 * Nope, reset the current pointer to the end of the array...
118 cupsArrayIndex(ppd
->sorted_attrs
, cupsArrayCount(ppd
->sorted_attrs
));
123 if (!spec
|| !_cups_strcasecmp(attr
->spec
, spec
))
128 * Return the next attribute's value...
136 * '_ppdNormalizeMakeAndModel()' - Normalize a product/make-and-model string.
138 * This function tries to undo the mistakes made by many printer manufacturers
139 * to produce a clean make-and-model string we can use.
142 char * /* O - Normalized make-and-model string or NULL on error */
143 _ppdNormalizeMakeAndModel(
144 const char *make_and_model
, /* I - Original make-and-model string */
145 char *buffer
, /* I - String buffer */
146 size_t bufsize
) /* I - Size of string buffer */
148 char *bufptr
; /* Pointer into buffer */
151 if (!make_and_model
|| !buffer
|| bufsize
< 1)
160 * Skip leading whitespace...
163 while (_cups_isspace(*make_and_model
))
167 * Remove parenthesis and add manufacturers as needed...
170 if (make_and_model
[0] == '(')
172 strlcpy(buffer
, make_and_model
+ 1, bufsize
);
174 if ((bufptr
= strrchr(buffer
, ')')) != NULL
)
177 else if (!_cups_strncasecmp(make_and_model
, "XPrint", 6))
183 snprintf(buffer
, bufsize
, "Xerox %s", make_and_model
);
185 else if (!_cups_strncasecmp(make_and_model
, "Eastman", 7))
191 snprintf(buffer
, bufsize
, "Kodak %s", make_and_model
+ 7);
193 else if (!_cups_strncasecmp(make_and_model
, "laserwriter", 11))
196 * Apple LaserWriter...
199 snprintf(buffer
, bufsize
, "Apple LaserWriter%s", make_and_model
+ 11);
201 else if (!_cups_strncasecmp(make_and_model
, "colorpoint", 10))
207 snprintf(buffer
, bufsize
, "Seiko %s", make_and_model
);
209 else if (!_cups_strncasecmp(make_and_model
, "fiery", 5))
215 snprintf(buffer
, bufsize
, "EFI %s", make_and_model
);
217 else if (!_cups_strncasecmp(make_and_model
, "ps ", 3) ||
218 !_cups_strncasecmp(make_and_model
, "colorpass", 9))
224 snprintf(buffer
, bufsize
, "Canon %s", make_and_model
);
226 else if (!_cups_strncasecmp(make_and_model
, "designjet", 9) ||
227 !_cups_strncasecmp(make_and_model
, "deskjet", 7))
233 snprintf(buffer
, bufsize
, "HP %s", make_and_model
);
236 strlcpy(buffer
, make_and_model
, bufsize
);
239 * Clean up the make...
242 if (!_cups_strncasecmp(buffer
, "agfa", 4))
245 * Replace with AGFA (all uppercase)...
253 else if (!_cups_strncasecmp(buffer
, "Hewlett-Packard hp ", 19))
256 * Just put "HP" on the front...
261 _cups_strcpy(buffer
+ 2, buffer
+ 18);
263 else if (!_cups_strncasecmp(buffer
, "Hewlett-Packard ", 16))
266 * Just put "HP" on the front...
271 _cups_strcpy(buffer
+ 2, buffer
+ 15);
273 else if (!_cups_strncasecmp(buffer
, "Lexmark International", 21))
276 * Strip "International"...
279 _cups_strcpy(buffer
+ 8, buffer
+ 21);
281 else if (!_cups_strncasecmp(buffer
, "herk", 4))
284 * Replace with LHAG...
292 else if (!_cups_strncasecmp(buffer
, "linotype", 8))
295 * Replace with LHAG...
302 _cups_strcpy(buffer
+ 4, buffer
+ 8);
306 * Remove trailing whitespace and return...
309 for (bufptr
= buffer
+ strlen(buffer
) - 1;
310 bufptr
>= buffer
&& _cups_isspace(*bufptr
);
315 return (buffer
[0] ? buffer
: NULL
);