]>
git.ipfire.org Git - thirdparty/cups.git/blob - cups/attr.c
2 * "$Id: attr.c 6649 2007-07-11 21:46:42Z mike $"
4 * PPD model-specific attribute routines for the Common UNIX Printing System
7 * Copyright 2007 by Apple Inc.
8 * Copyright 1997-2006 by Easy Software Products.
10 * These coded instructions, statements, and computer programs are the
11 * property of Apple Inc. and are protected by Federal copyright
12 * law. Distribution and use rights are outlined in the file "LICENSE.txt"
13 * which should have been included with this file. If this file is
14 * file is missing or damaged, see the license at "http://www.cups.org/".
18 * ppdFindAttr() - Find the first matching attribute...
19 * ppdFindNextAttr() - Find the next matching attribute...
23 * Include necessary headers...
33 * 'ppdFindAttr()' - Find the first matching attribute...
38 ppd_attr_t
* /* O - Attribute or NULL if not found */
39 ppdFindAttr(ppd_file_t
*ppd
, /* I - PPD file data */
40 const char *name
, /* I - Attribute name */
41 const char *spec
) /* I - Specifier string or NULL */
43 ppd_attr_t key
, /* Search key */
44 *attr
; /* Current attribute */
45 int diff
; /* Current difference */
48 DEBUG_printf(("ppdFindAttr(ppd=%p, name=\"%s\", spec=\"%s\")\n", ppd
,
49 name
? name
: "(null)", spec
? spec
: "(null)"));
52 * Range check input...
55 if (!ppd
|| !name
|| ppd
->num_attrs
== 0)
59 * Search for a matching attribute...
62 memset(&key
, 0, sizeof(key
));
63 strlcpy(key
.name
, name
, sizeof(key
.name
));
65 strlcpy(key
.spec
, spec
, sizeof(key
.spec
));
68 * Return the first matching attribute, if any...
71 if ((attr
= (ppd_attr_t
*)cupsArrayFind(ppd
->sorted_attrs
, &key
)) != NULL
)
77 * No match found, loop through the sorted attributes to see if we can
78 * find a "wildcard" match for the attribute...
81 for (attr
= (ppd_attr_t
*)cupsArrayFirst(ppd
->sorted_attrs
);
83 attr
= (ppd_attr_t
*)cupsArrayNext(ppd
->sorted_attrs
))
85 if ((diff
= strcasecmp(attr
->name
, name
)) == 0)
91 * All remaining attributes are > than the one we are trying to find...
94 cupsArrayIndex(ppd
->sorted_attrs
, cupsArrayCount(ppd
->sorted_attrs
));
105 * 'ppdFindNextAttr()' - Find the next matching attribute...
107 * @since CUPS 1.1.19@
110 ppd_attr_t
* /* O - Attribute or NULL if not found */
111 ppdFindNextAttr(ppd_file_t
*ppd
, /* I - PPD file data */
112 const char *name
, /* I - Attribute name */
113 const char *spec
) /* I - Specifier string or NULL */
115 ppd_attr_t
*attr
; /* Current attribute */
119 * Range check input...
122 if (!ppd
|| !name
|| ppd
->num_attrs
== 0 ||
123 !cupsArrayCurrent(ppd
->sorted_attrs
))
127 * See if there are more attributes to return...
130 if ((attr
= (ppd_attr_t
*)cupsArrayNext(ppd
->sorted_attrs
)) == NULL
)
134 * Check the next attribute to see if it is a match...
137 if (strcasecmp(attr
->name
, name
) || (spec
&& strcasecmp(attr
->spec
, spec
)))
140 * Nope, reset the current pointer to the end of the array...
143 cupsArrayIndex(ppd
->sorted_attrs
, cupsArrayCount(ppd
->sorted_attrs
));
149 * Return the next attribute's value...
157 * End of "$Id: attr.c 6649 2007-07-11 21:46:42Z mike $".