]>
git.ipfire.org Git - thirdparty/cups.git/blob - cups/attr.c
2 * "$Id: attr.c 5825 2006-08-15 19:03:49Z mike $"
4 * PPD model-specific attribute routines for the Common UNIX Printing System
7 * Copyright 1997-2006 by Easy Software Products.
9 * These coded instructions, statements, and computer programs are the
10 * property of Easy Software Products and are protected by Federal
11 * copyright law. Distribution and use rights are outlined in the file
12 * "LICENSE.txt" which should have been included with this file. If this
13 * file is missing or damaged please contact Easy Software Products
16 * Attn: CUPS Licensing Information
17 * Easy Software Products
18 * 44141 Airport View Drive, Suite 204
19 * Hollywood, Maryland 20636 USA
21 * Voice: (301) 373-9600
22 * EMail: cups-info@cups.org
23 * WWW: http://www.cups.org
27 * ppdFindAttr() - Find the first matching attribute...
28 * ppdFindNextAttr() - Find the next matching attribute...
32 * Include necessary headers...
42 * 'ppdFindAttr()' - Find the first matching attribute...
47 ppd_attr_t
* /* O - Attribute or NULL if not found */
48 ppdFindAttr(ppd_file_t
*ppd
, /* I - PPD file data */
49 const char *name
, /* I - Attribute name */
50 const char *spec
) /* I - Specifier string or NULL */
52 ppd_attr_t key
, /* Search key */
53 *attr
; /* Current attribute */
54 int diff
; /* Current difference */
57 DEBUG_printf(("ppdFindAttr(ppd=%p, name=\"%s\", spec=\"%s\")\n", ppd
,
58 name
? name
: "(null)", spec
? spec
: "(null)"));
61 * Range check input...
64 if (!ppd
|| !name
|| ppd
->num_attrs
== 0)
68 * Search for a matching attribute...
71 memset(&key
, 0, sizeof(key
));
72 strlcpy(key
.name
, name
, sizeof(key
.name
));
74 strlcpy(key
.spec
, spec
, sizeof(key
.spec
));
77 * Return the first matching attribute, if any...
80 if ((attr
= (ppd_attr_t
*)cupsArrayFind(ppd
->sorted_attrs
, &key
)) != NULL
)
86 * No match found, loop through the sorted attributes to see if we can
87 * find a "wildcard" match for the attribute...
90 for (attr
= (ppd_attr_t
*)cupsArrayFirst(ppd
->sorted_attrs
);
92 attr
= (ppd_attr_t
*)cupsArrayNext(ppd
->sorted_attrs
))
94 if ((diff
= strcasecmp(attr
->name
, name
)) == 0)
100 * All remaining attributes are > than the one we are trying to find...
103 cupsArrayIndex(ppd
->sorted_attrs
, cupsArrayCount(ppd
->sorted_attrs
));
114 * 'ppdFindNextAttr()' - Find the next matching attribute...
116 * @since CUPS 1.1.19@
119 ppd_attr_t
* /* O - Attribute or NULL if not found */
120 ppdFindNextAttr(ppd_file_t
*ppd
, /* I - PPD file data */
121 const char *name
, /* I - Attribute name */
122 const char *spec
) /* I - Specifier string or NULL */
124 ppd_attr_t
*attr
; /* Current attribute */
128 * Range check input...
131 if (!ppd
|| !name
|| ppd
->num_attrs
== 0 ||
132 !cupsArrayCurrent(ppd
->sorted_attrs
))
136 * See if there are more attributes to return...
139 if ((attr
= (ppd_attr_t
*)cupsArrayNext(ppd
->sorted_attrs
)) == NULL
)
143 * Check the next attribute to see if it is a match...
146 if (strcasecmp(attr
->name
, name
) || (spec
&& strcasecmp(attr
->spec
, spec
)))
149 * Nope, reset the current pointer to the end of the array...
152 cupsArrayIndex(ppd
->sorted_attrs
, cupsArrayCount(ppd
->sorted_attrs
));
158 * Return the next attribute's value...
166 * End of "$Id: attr.c 5825 2006-08-15 19:03:49Z mike $".