]>
git.ipfire.org Git - thirdparty/cups.git/blob - cups/attr.c
36f911d0b03ff8ca56dccac7c4c4ae0bb9a49a3e
2 * "$Id: attr.c 4785 2005-10-13 19:39:05Z mike $"
4 * PPD model-specific attribute routines for the Common UNIX Printing System
7 * Copyright 1997-2005 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...
45 extern int _ppd_attr_compare(ppd_attr_t
**a
, ppd_attr_t
**b
);
49 * 'ppdFindAttr()' - Find the first matching attribute...
54 ppd_attr_t
* /* O - Attribute or NULL if not found */
55 ppdFindAttr(ppd_file_t
*ppd
, /* I - PPD file data */
56 const char *name
, /* I - Attribute name */
57 const char *spec
) /* I - Specifier string or NULL */
59 ppd_attr_t key
, /* Search key */
60 *keyptr
, /* Pointer to key */
61 **match
; /* Matching attribute */
65 * Range check input...
68 if (ppd
== NULL
|| name
== NULL
|| ppd
->num_attrs
== 0)
72 * Do a binary search for a matching attribute...
75 memset(&key
, 0, sizeof(key
));
76 strncpy(key
.name
, name
, sizeof(key
.name
) - 1);
78 strncpy(key
.spec
, spec
, sizeof(key
.spec
) - 1);
82 match
= bsearch(&keyptr
, ppd
->attrs
, ppd
->num_attrs
, sizeof(ppd_attr_t
*),
83 (int (*)(const void *, const void *))_ppd_attr_compare
);
95 if (match
> ppd
->attrs
&& spec
== NULL
)
98 * Find the first attribute with the same name...
101 while (match
> ppd
->attrs
)
103 if (strcmp(match
[-1]->name
, name
) != 0)
111 * Save the current attribute and return its value...
114 ppd
->cur_attr
= match
- ppd
->attrs
;
121 * 'ppdFindNextAttr()' - Find the next matching attribute...
123 * @since CUPS 1.1.19@
126 ppd_attr_t
* /* O - Attribute or NULL if not found */
127 ppdFindNextAttr(ppd_file_t
*ppd
, /* I - PPD file data */
128 const char *name
, /* I - Attribute name */
129 const char *spec
) /* I - Specifier string or NULL */
131 ppd_attr_t
**match
; /* Matching attribute */
135 * Range check input...
138 if (ppd
== NULL
|| name
== NULL
|| ppd
->num_attrs
== 0 || ppd
->cur_attr
< 0)
142 * See if there are more attributes to return...
147 if (ppd
->cur_attr
>= ppd
->num_attrs
)
158 * Check the next attribute to see if it is a match...
161 match
= ppd
->attrs
+ ppd
->cur_attr
;
163 if (strcmp((*match
)->name
, name
) != 0 ||
164 (spec
!= NULL
&& strcmp((*match
)->spec
, spec
) != 0))
175 * Return the next attribute's value...
183 * End of "$Id: attr.c 4785 2005-10-13 19:39:05Z mike $".