]>
Commit | Line | Data |
---|---|---|
ef416fc2 | 1 | /* |
bc44d920 | 2 | * "$Id: attr.c 6649 2007-07-11 21:46:42Z mike $" |
ef416fc2 | 3 | * |
4 | * PPD model-specific attribute routines for the Common UNIX Printing System | |
5 | * (CUPS). | |
6 | * | |
bc44d920 | 7 | * Copyright 2007 by Apple Inc. |
bd7854cb | 8 | * Copyright 1997-2006 by Easy Software Products. |
ef416fc2 | 9 | * |
10 | * These coded instructions, statements, and computer programs are the | |
bc44d920 | 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/". | |
ef416fc2 | 15 | * |
16 | * Contents: | |
17 | * | |
18 | * ppdFindAttr() - Find the first matching attribute... | |
19 | * ppdFindNextAttr() - Find the next matching attribute... | |
20 | */ | |
21 | ||
22 | /* | |
23 | * Include necessary headers... | |
24 | */ | |
25 | ||
26 | #include "ppd.h" | |
27 | #include "debug.h" | |
28 | #include "string.h" | |
29 | #include <stdlib.h> | |
30 | ||
31 | ||
ef416fc2 | 32 | /* |
33 | * 'ppdFindAttr()' - Find the first matching attribute... | |
34 | * | |
35 | * @since CUPS 1.1.19@ | |
36 | */ | |
37 | ||
d09495fa | 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 */ | |
ef416fc2 | 42 | { |
d09495fa | 43 | ppd_attr_t key, /* Search key */ |
44 | *attr; /* Current attribute */ | |
45 | int diff; /* Current difference */ | |
46 | ||
ef416fc2 | 47 | |
d09495fa | 48 | DEBUG_printf(("ppdFindAttr(ppd=%p, name=\"%s\", spec=\"%s\")\n", ppd, |
49 | name ? name : "(null)", spec ? spec : "(null)")); | |
ef416fc2 | 50 | |
51 | /* | |
52 | * Range check input... | |
53 | */ | |
54 | ||
bd7854cb | 55 | if (!ppd || !name || ppd->num_attrs == 0) |
ef416fc2 | 56 | return (NULL); |
57 | ||
58 | /* | |
bd7854cb | 59 | * Search for a matching attribute... |
ef416fc2 | 60 | */ |
61 | ||
62 | memset(&key, 0, sizeof(key)); | |
bd7854cb | 63 | strlcpy(key.name, name, sizeof(key.name)); |
ef416fc2 | 64 | if (spec) |
bd7854cb | 65 | strlcpy(key.spec, spec, sizeof(key.spec)); |
ef416fc2 | 66 | |
67 | /* | |
bd7854cb | 68 | * Return the first matching attribute, if any... |
ef416fc2 | 69 | */ |
70 | ||
d09495fa | 71 | if ((attr = (ppd_attr_t *)cupsArrayFind(ppd->sorted_attrs, &key)) != NULL) |
72 | return (attr); | |
73 | else if (spec) | |
74 | return (NULL); | |
75 | ||
76 | /* | |
77 | * No match found, loop through the sorted attributes to see if we can | |
78 | * find a "wildcard" match for the attribute... | |
79 | */ | |
80 | ||
81 | for (attr = (ppd_attr_t *)cupsArrayFirst(ppd->sorted_attrs); | |
82 | attr; | |
83 | attr = (ppd_attr_t *)cupsArrayNext(ppd->sorted_attrs)) | |
84 | { | |
85 | if ((diff = strcasecmp(attr->name, name)) == 0) | |
86 | break; | |
87 | ||
88 | if (diff > 0) | |
89 | { | |
90 | /* | |
91 | * All remaining attributes are > than the one we are trying to find... | |
92 | */ | |
93 | ||
94 | cupsArrayIndex(ppd->sorted_attrs, cupsArrayCount(ppd->sorted_attrs)); | |
95 | ||
96 | return (NULL); | |
97 | } | |
98 | } | |
99 | ||
100 | return (attr); | |
ef416fc2 | 101 | } |
102 | ||
103 | ||
104 | /* | |
105 | * 'ppdFindNextAttr()' - Find the next matching attribute... | |
106 | * | |
107 | * @since CUPS 1.1.19@ | |
108 | */ | |
109 | ||
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 */ | |
114 | { | |
bd7854cb | 115 | ppd_attr_t *attr; /* Current attribute */ |
ef416fc2 | 116 | |
117 | ||
118 | /* | |
119 | * Range check input... | |
120 | */ | |
121 | ||
bd7854cb | 122 | if (!ppd || !name || ppd->num_attrs == 0 || |
123 | !cupsArrayCurrent(ppd->sorted_attrs)) | |
ef416fc2 | 124 | return (NULL); |
125 | ||
126 | /* | |
127 | * See if there are more attributes to return... | |
128 | */ | |
129 | ||
bd7854cb | 130 | if ((attr = (ppd_attr_t *)cupsArrayNext(ppd->sorted_attrs)) == NULL) |
ef416fc2 | 131 | return (NULL); |
ef416fc2 | 132 | |
133 | /* | |
134 | * Check the next attribute to see if it is a match... | |
135 | */ | |
136 | ||
bd7854cb | 137 | if (strcasecmp(attr->name, name) || (spec && strcasecmp(attr->spec, spec))) |
ef416fc2 | 138 | { |
139 | /* | |
bd7854cb | 140 | * Nope, reset the current pointer to the end of the array... |
ef416fc2 | 141 | */ |
142 | ||
bd7854cb | 143 | cupsArrayIndex(ppd->sorted_attrs, cupsArrayCount(ppd->sorted_attrs)); |
144 | ||
ef416fc2 | 145 | return (NULL); |
146 | } | |
147 | ||
148 | /* | |
149 | * Return the next attribute's value... | |
150 | */ | |
151 | ||
bd7854cb | 152 | return (attr); |
ef416fc2 | 153 | } |
154 | ||
155 | ||
156 | /* | |
bc44d920 | 157 | * End of "$Id: attr.c 6649 2007-07-11 21:46:42Z mike $". |
ef416fc2 | 158 | */ |