]> git.ipfire.org Git - thirdparty/cups.git/blame - cups/attr.c
Load cups into easysw/current.
[thirdparty/cups.git] / cups / attr.c
CommitLineData
ef416fc2 1/*
d09495fa 2 * "$Id: attr.c 5826 2006-08-15 19:04:11Z mike $"
ef416fc2 3 *
4 * PPD model-specific attribute routines for the Common UNIX Printing System
5 * (CUPS).
6 *
bd7854cb 7 * Copyright 1997-2006 by Easy Software Products.
ef416fc2 8 *
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
14 * at:
15 *
16 * Attn: CUPS Licensing Information
17 * Easy Software Products
18 * 44141 Airport View Drive, Suite 204
19 * Hollywood, Maryland 20636 USA
20 *
21 * Voice: (301) 373-9600
22 * EMail: cups-info@cups.org
23 * WWW: http://www.cups.org
24 *
25 * Contents:
26 *
27 * ppdFindAttr() - Find the first matching attribute...
28 * ppdFindNextAttr() - Find the next matching attribute...
29 */
30
31/*
32 * Include necessary headers...
33 */
34
35#include "ppd.h"
36#include "debug.h"
37#include "string.h"
38#include <stdlib.h>
39
40
ef416fc2 41/*
42 * 'ppdFindAttr()' - Find the first matching attribute...
43 *
44 * @since CUPS 1.1.19@
45 */
46
d09495fa 47ppd_attr_t * /* O - Attribute or NULL if not found */
48ppdFindAttr(ppd_file_t *ppd, /* I - PPD file data */
49 const char *name, /* I - Attribute name */
50 const char *spec) /* I - Specifier string or NULL */
ef416fc2 51{
d09495fa 52 ppd_attr_t key, /* Search key */
53 *attr; /* Current attribute */
54 int diff; /* Current difference */
55
ef416fc2 56
d09495fa 57 DEBUG_printf(("ppdFindAttr(ppd=%p, name=\"%s\", spec=\"%s\")\n", ppd,
58 name ? name : "(null)", spec ? spec : "(null)"));
ef416fc2 59
60 /*
61 * Range check input...
62 */
63
bd7854cb 64 if (!ppd || !name || ppd->num_attrs == 0)
ef416fc2 65 return (NULL);
66
67 /*
bd7854cb 68 * Search for a matching attribute...
ef416fc2 69 */
70
71 memset(&key, 0, sizeof(key));
bd7854cb 72 strlcpy(key.name, name, sizeof(key.name));
ef416fc2 73 if (spec)
bd7854cb 74 strlcpy(key.spec, spec, sizeof(key.spec));
ef416fc2 75
76 /*
bd7854cb 77 * Return the first matching attribute, if any...
ef416fc2 78 */
79
d09495fa 80 if ((attr = (ppd_attr_t *)cupsArrayFind(ppd->sorted_attrs, &key)) != NULL)
81 return (attr);
82 else if (spec)
83 return (NULL);
84
85 /*
86 * No match found, loop through the sorted attributes to see if we can
87 * find a "wildcard" match for the attribute...
88 */
89
90 for (attr = (ppd_attr_t *)cupsArrayFirst(ppd->sorted_attrs);
91 attr;
92 attr = (ppd_attr_t *)cupsArrayNext(ppd->sorted_attrs))
93 {
94 if ((diff = strcasecmp(attr->name, name)) == 0)
95 break;
96
97 if (diff > 0)
98 {
99 /*
100 * All remaining attributes are > than the one we are trying to find...
101 */
102
103 cupsArrayIndex(ppd->sorted_attrs, cupsArrayCount(ppd->sorted_attrs));
104
105 return (NULL);
106 }
107 }
108
109 return (attr);
ef416fc2 110}
111
112
113/*
114 * 'ppdFindNextAttr()' - Find the next matching attribute...
115 *
116 * @since CUPS 1.1.19@
117 */
118
119ppd_attr_t * /* O - Attribute or NULL if not found */
120ppdFindNextAttr(ppd_file_t *ppd, /* I - PPD file data */
121 const char *name, /* I - Attribute name */
122 const char *spec) /* I - Specifier string or NULL */
123{
bd7854cb 124 ppd_attr_t *attr; /* Current attribute */
ef416fc2 125
126
127 /*
128 * Range check input...
129 */
130
bd7854cb 131 if (!ppd || !name || ppd->num_attrs == 0 ||
132 !cupsArrayCurrent(ppd->sorted_attrs))
ef416fc2 133 return (NULL);
134
135 /*
136 * See if there are more attributes to return...
137 */
138
bd7854cb 139 if ((attr = (ppd_attr_t *)cupsArrayNext(ppd->sorted_attrs)) == NULL)
ef416fc2 140 return (NULL);
ef416fc2 141
142 /*
143 * Check the next attribute to see if it is a match...
144 */
145
bd7854cb 146 if (strcasecmp(attr->name, name) || (spec && strcasecmp(attr->spec, spec)))
ef416fc2 147 {
148 /*
bd7854cb 149 * Nope, reset the current pointer to the end of the array...
ef416fc2 150 */
151
bd7854cb 152 cupsArrayIndex(ppd->sorted_attrs, cupsArrayCount(ppd->sorted_attrs));
153
ef416fc2 154 return (NULL);
155 }
156
157 /*
158 * Return the next attribute's value...
159 */
160
bd7854cb 161 return (attr);
ef416fc2 162}
163
164
165/*
d09495fa 166 * End of "$Id: attr.c 5826 2006-08-15 19:04:11Z mike $".
ef416fc2 167 */