]> git.ipfire.org Git - thirdparty/cups.git/blame - cups/attr.c
Update svn:keyword properties.
[thirdparty/cups.git] / cups / attr.c
CommitLineData
ef416fc2 1/*
f2d18633 2 * "$Id$"
ef416fc2 3 *
f8b3a85b 4 * PPD model-specific attribute routines for CUPS.
ef416fc2 5 *
f3c17241 6 * Copyright 2007-2012 by Apple Inc.
bd7854cb 7 * Copyright 1997-2006 by Easy Software Products.
ef416fc2 8 *
9 * These coded instructions, statements, and computer programs are the
bc44d920 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/".
ef416fc2 14 *
15 * Contents:
16 *
f8b3a85b
MS
17 * ppdFindAttr() - Find the first matching attribute.
18 * ppdFindNextAttr() - Find the next matching attribute.
19 * _ppdNormalizeMakeAndModel() - Normalize a product/make-and-model string.
ef416fc2 20 */
21
22/*
23 * Include necessary headers...
24 */
25
71e16022 26#include "cups-private.h"
5eb9da71 27#include "ppd-private.h"
ef416fc2 28
29
ef416fc2 30/*
5a738aea 31 * 'ppdFindAttr()' - Find the first matching attribute.
ef416fc2 32 *
f3c17241 33 * @since CUPS 1.1.19/OS X 10.3@
ef416fc2 34 */
35
5a738aea 36ppd_attr_t * /* O - Attribute or @code NULL@ if not found */
d09495fa 37ppdFindAttr(ppd_file_t *ppd, /* I - PPD file data */
38 const char *name, /* I - Attribute name */
5a738aea 39 const char *spec) /* I - Specifier string or @code NULL@ */
ef416fc2 40{
d09495fa 41 ppd_attr_t key, /* Search key */
42 *attr; /* Current attribute */
d09495fa 43
ef416fc2 44
e07d4801
MS
45 DEBUG_printf(("2ppdFindAttr(ppd=%p, name=\"%s\", spec=\"%s\")", ppd, name,
46 spec));
ef416fc2 47
48 /*
49 * Range check input...
50 */
51
bd7854cb 52 if (!ppd || !name || ppd->num_attrs == 0)
ef416fc2 53 return (NULL);
54
55 /*
bd7854cb 56 * Search for a matching attribute...
ef416fc2 57 */
58
59 memset(&key, 0, sizeof(key));
bd7854cb 60 strlcpy(key.name, name, sizeof(key.name));
ef416fc2 61
62 /*
bd7854cb 63 * Return the first matching attribute, if any...
ef416fc2 64 */
65
d09495fa 66 if ((attr = (ppd_attr_t *)cupsArrayFind(ppd->sorted_attrs, &key)) != NULL)
d09495fa 67 {
6e8b116d 68 if (spec)
d09495fa 69 {
70 /*
6e8b116d 71 * Loop until we find the first matching attribute for "spec"...
d09495fa 72 */
73
88f9aafc 74 while (attr && _cups_strcasecmp(spec, attr->spec))
6e8b116d
MS
75 {
76 if ((attr = (ppd_attr_t *)cupsArrayNext(ppd->sorted_attrs)) != NULL &&
88f9aafc 77 _cups_strcasecmp(attr->name, name))
6e8b116d
MS
78 attr = NULL;
79 }
d09495fa 80 }
81 }
82
83 return (attr);
ef416fc2 84}
85
86
87/*
5a738aea 88 * 'ppdFindNextAttr()' - Find the next matching attribute.
ef416fc2 89 *
f3c17241 90 * @since CUPS 1.1.19/OS X 10.3@
ef416fc2 91 */
92
5a738aea 93ppd_attr_t * /* O - Attribute or @code NULL@ if not found */
ef416fc2 94ppdFindNextAttr(ppd_file_t *ppd, /* I - PPD file data */
95 const char *name, /* I - Attribute name */
5a738aea 96 const char *spec) /* I - Specifier string or @code NULL@ */
ef416fc2 97{
bd7854cb 98 ppd_attr_t *attr; /* Current attribute */
ef416fc2 99
100
101 /*
102 * Range check input...
103 */
104
6e8b116d 105 if (!ppd || !name || ppd->num_attrs == 0)
ef416fc2 106 return (NULL);
107
108 /*
109 * See if there are more attributes to return...
110 */
111
6e8b116d 112 while ((attr = (ppd_attr_t *)cupsArrayNext(ppd->sorted_attrs)) != NULL)
ef416fc2 113 {
114 /*
6e8b116d 115 * Check the next attribute to see if it is a match...
ef416fc2 116 */
117
88f9aafc 118 if (_cups_strcasecmp(attr->name, name))
6e8b116d
MS
119 {
120 /*
121 * Nope, reset the current pointer to the end of the array...
122 */
bd7854cb 123
6e8b116d
MS
124 cupsArrayIndex(ppd->sorted_attrs, cupsArrayCount(ppd->sorted_attrs));
125
126 return (NULL);
127 }
128
88f9aafc 129 if (!spec || !_cups_strcasecmp(attr->spec, spec))
6e8b116d 130 break;
ef416fc2 131 }
6e8b116d 132
ef416fc2 133 /*
134 * Return the next attribute's value...
135 */
136
bd7854cb 137 return (attr);
ef416fc2 138}
139
140
5eb9da71
MS
141/*
142 * '_ppdNormalizeMakeAndModel()' - Normalize a product/make-and-model string.
143 *
144 * This function tries to undo the mistakes made by many printer manufacturers
145 * to produce a clean make-and-model string we can use.
146 */
147
148char * /* O - Normalized make-and-model string or NULL on error */
149_ppdNormalizeMakeAndModel(
150 const char *make_and_model, /* I - Original make-and-model string */
151 char *buffer, /* I - String buffer */
152 size_t bufsize) /* I - Size of string buffer */
153{
154 char *bufptr; /* Pointer into buffer */
155
156
157 if (!make_and_model || !buffer || bufsize < 1)
158 {
159 if (buffer)
160 *buffer = '\0';
161
162 return (NULL);
163 }
164
165 /*
166 * Skip leading whitespace...
167 */
168
7cf5915e 169 while (_cups_isspace(*make_and_model))
5eb9da71
MS
170 make_and_model ++;
171
172 /*
173 * Remove parenthesis and add manufacturers as needed...
174 */
175
176 if (make_and_model[0] == '(')
177 {
178 strlcpy(buffer, make_and_model + 1, bufsize);
179
180 if ((bufptr = strrchr(buffer, ')')) != NULL)
181 *bufptr = '\0';
182 }
88f9aafc 183 else if (!_cups_strncasecmp(make_and_model, "XPrint", 6))
5eb9da71
MS
184 {
185 /*
186 * Xerox XPrint...
187 */
188
189 snprintf(buffer, bufsize, "Xerox %s", make_and_model);
190 }
88f9aafc 191 else if (!_cups_strncasecmp(make_and_model, "Eastman", 7))
5eb9da71
MS
192 {
193 /*
194 * Kodak...
195 */
196
197 snprintf(buffer, bufsize, "Kodak %s", make_and_model + 7);
198 }
88f9aafc 199 else if (!_cups_strncasecmp(make_and_model, "laserwriter", 11))
5eb9da71
MS
200 {
201 /*
202 * Apple LaserWriter...
203 */
204
205 snprintf(buffer, bufsize, "Apple LaserWriter%s", make_and_model + 11);
206 }
88f9aafc 207 else if (!_cups_strncasecmp(make_and_model, "colorpoint", 10))
5eb9da71
MS
208 {
209 /*
210 * Seiko...
211 */
212
213 snprintf(buffer, bufsize, "Seiko %s", make_and_model);
214 }
88f9aafc 215 else if (!_cups_strncasecmp(make_and_model, "fiery", 5))
5eb9da71
MS
216 {
217 /*
218 * EFI...
219 */
220
221 snprintf(buffer, bufsize, "EFI %s", make_and_model);
222 }
88f9aafc
MS
223 else if (!_cups_strncasecmp(make_and_model, "ps ", 3) ||
224 !_cups_strncasecmp(make_and_model, "colorpass", 9))
5eb9da71
MS
225 {
226 /*
227 * Canon...
228 */
229
230 snprintf(buffer, bufsize, "Canon %s", make_and_model);
231 }
88f9aafc 232 else if (!_cups_strncasecmp(make_and_model, "primera", 7))
5eb9da71
MS
233 {
234 /*
235 * Fargo...
236 */
237
238 snprintf(buffer, bufsize, "Fargo %s", make_and_model);
239 }
88f9aafc
MS
240 else if (!_cups_strncasecmp(make_and_model, "designjet", 9) ||
241 !_cups_strncasecmp(make_and_model, "deskjet", 7))
5eb9da71
MS
242 {
243 /*
244 * HP...
245 */
246
247 snprintf(buffer, bufsize, "HP %s", make_and_model);
248 }
249 else
250 strlcpy(buffer, make_and_model, bufsize);
251
252 /*
253 * Clean up the make...
254 */
255
88f9aafc 256 if (!_cups_strncasecmp(buffer, "agfa", 4))
5eb9da71
MS
257 {
258 /*
259 * Replace with AGFA (all uppercase)...
260 */
261
262 buffer[0] = 'A';
263 buffer[1] = 'G';
264 buffer[2] = 'F';
265 buffer[3] = 'A';
266 }
88f9aafc 267 else if (!_cups_strncasecmp(buffer, "Hewlett-Packard hp ", 19))
5eb9da71
MS
268 {
269 /*
270 * Just put "HP" on the front...
271 */
272
273 buffer[0] = 'H';
274 buffer[1] = 'P';
275 _cups_strcpy(buffer + 2, buffer + 18);
276 }
88f9aafc 277 else if (!_cups_strncasecmp(buffer, "Hewlett-Packard ", 16))
5eb9da71
MS
278 {
279 /*
280 * Just put "HP" on the front...
281 */
282
283 buffer[0] = 'H';
284 buffer[1] = 'P';
285 _cups_strcpy(buffer + 2, buffer + 15);
286 }
88f9aafc 287 else if (!_cups_strncasecmp(buffer, "Lexmark International", 21))
5eb9da71
MS
288 {
289 /*
290 * Strip "International"...
291 */
292
293 _cups_strcpy(buffer + 8, buffer + 21);
294 }
88f9aafc 295 else if (!_cups_strncasecmp(buffer, "herk", 4))
5eb9da71
MS
296 {
297 /*
298 * Replace with LHAG...
299 */
300
301 buffer[0] = 'L';
302 buffer[1] = 'H';
303 buffer[2] = 'A';
304 buffer[3] = 'G';
305 }
88f9aafc 306 else if (!_cups_strncasecmp(buffer, "linotype", 8))
5eb9da71
MS
307 {
308 /*
309 * Replace with LHAG...
310 */
311
312 buffer[0] = 'L';
313 buffer[1] = 'H';
314 buffer[2] = 'A';
315 buffer[3] = 'G';
316 _cups_strcpy(buffer + 4, buffer + 8);
317 }
318
319 /*
320 * Remove trailing whitespace and return...
321 */
322
323 for (bufptr = buffer + strlen(buffer) - 1;
7cf5915e 324 bufptr >= buffer && _cups_isspace(*bufptr);
5eb9da71
MS
325 bufptr --);
326
327 bufptr[1] = '\0';
328
329 return (buffer[0] ? buffer : NULL);
330}
331
332
333/*
f2d18633 334 * End of "$Id$".
ef416fc2 335 */