]>
git.ipfire.org Git - thirdparty/cups.git/blob - cups/attr.c
2 * "$Id: attr.c,v 1.1.2.2 2003/01/07 18:26:23 mike Exp $"
4 * PPD model-specific attribute routines for the Common UNIX Printing System
7 * Copyright 1997-2003 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-3111 USA
21 * Voice: (301) 373-9600
22 * EMail: cups-info@cups.org
23 * WWW: http://www.cups.org
30 * Include necessary headers...
43 extern int _ppd_attr_compare(ppd_attr_t
**a
, ppd_attr_t
**b
);
47 * 'ppdFindAttr()' - Find the first matching attribute...
50 const char * /* O - Value or NULL if not found */
51 ppdFindAttr(ppd_file_t
*ppd
, /* I - PPD file data */
52 const char *name
, /* I - Attribute name */
53 const char *spec
) /* I - Specifier string or NULL */
55 ppd_attr_t key
, /* Search key */
56 *keyptr
, /* Pointer to key */
57 **match
; /* Matching attribute */
61 * Range check input...
64 if (ppd
== NULL
|| name
== NULL
|| ppd
->num_attrs
== 0)
68 * Do a binary search for a matching attribute...
71 memset(&key
, 0, sizeof(key
));
72 strncpy(key
.name
, name
, sizeof(key
.name
) - 1);
74 strncpy(key
.spec
, spec
, sizeof(key
.spec
) - 1);
78 match
= bsearch(&keyptr
, ppd
->attrs
, ppd
->num_attrs
, sizeof(ppd_attr_t
*),
79 (int (*)(const void *, const void *))_ppd_attr_compare
);
91 if (match
> ppd
->attrs
&& spec
== NULL
)
94 * Find the first attribute with the same name...
97 while (match
> ppd
->attrs
)
99 if (strcmp(match
[-1]->name
, name
) != 0)
107 * Save the current attribute and return its value...
110 ppd
->cur_attr
= match
- ppd
->attrs
;
113 return ((*match
)->value
);
120 * 'ppdFindNextAttr()' - Find the next matching attribute...
123 const char * /* O - Value or NULL if not found */
124 ppdFindNextAttr(ppd_file_t
*ppd
, /* I - PPD file data */
125 const char *name
, /* I - Attribute name */
126 const char *spec
) /* I - Specifier string or NULL */
128 ppd_attr_t
**match
; /* Matching attribute */
132 * Range check input...
135 if (ppd
== NULL
|| name
== NULL
|| ppd
->num_attrs
== 0 || ppd
->cur_attr
< 0)
139 * See if there are more attributes to return...
144 if (ppd
->cur_attr
>= ppd
->num_attrs
)
155 * Check the next attribute to see if it is a match...
158 match
= ppd
->attrs
+ ppd
->cur_attr
;
160 if (strcmp((*match
)->name
, name
) != 0 ||
161 (spec
!= NULL
&& strcmp((*match
)->spec
, spec
) != 0))
172 * Return the next attribute's value...
176 return ((*match
)->value
);
183 * End of "$Id: attr.c,v 1.1.2.2 2003/01/07 18:26:23 mike Exp $".