]>
Commit | Line | Data |
---|---|---|
ef416fc2 | 1 | /* |
bd7854cb | 2 | * "$Id: attr.c 5119 2006-02-16 15:52:06Z 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 | ||
47 | ppd_attr_t * /* O - Attribute or NULL if not found */ | |
48 | ppdFindAttr(ppd_file_t *ppd, /* I - PPD file data */ | |
49 | const char *name, /* I - Attribute name */ | |
50 | const char *spec) /* I - Specifier string or NULL */ | |
51 | { | |
bd7854cb | 52 | ppd_attr_t key; /* Search key */ |
ef416fc2 | 53 | |
54 | ||
55 | /* | |
56 | * Range check input... | |
57 | */ | |
58 | ||
bd7854cb | 59 | if (!ppd || !name || ppd->num_attrs == 0) |
ef416fc2 | 60 | return (NULL); |
61 | ||
62 | /* | |
bd7854cb | 63 | * Search for a matching attribute... |
ef416fc2 | 64 | */ |
65 | ||
66 | memset(&key, 0, sizeof(key)); | |
bd7854cb | 67 | strlcpy(key.name, name, sizeof(key.name)); |
ef416fc2 | 68 | if (spec) |
bd7854cb | 69 | strlcpy(key.spec, spec, sizeof(key.spec)); |
ef416fc2 | 70 | |
71 | /* | |
bd7854cb | 72 | * Return the first matching attribute, if any... |
ef416fc2 | 73 | */ |
74 | ||
bd7854cb | 75 | return ((ppd_attr_t *)cupsArrayFind(ppd->sorted_attrs, &key)); |
ef416fc2 | 76 | } |
77 | ||
78 | ||
79 | /* | |
80 | * 'ppdFindNextAttr()' - Find the next matching attribute... | |
81 | * | |
82 | * @since CUPS 1.1.19@ | |
83 | */ | |
84 | ||
85 | ppd_attr_t * /* O - Attribute or NULL if not found */ | |
86 | ppdFindNextAttr(ppd_file_t *ppd, /* I - PPD file data */ | |
87 | const char *name, /* I - Attribute name */ | |
88 | const char *spec) /* I - Specifier string or NULL */ | |
89 | { | |
bd7854cb | 90 | ppd_attr_t *attr; /* Current attribute */ |
ef416fc2 | 91 | |
92 | ||
93 | /* | |
94 | * Range check input... | |
95 | */ | |
96 | ||
bd7854cb | 97 | if (!ppd || !name || ppd->num_attrs == 0 || |
98 | !cupsArrayCurrent(ppd->sorted_attrs)) | |
ef416fc2 | 99 | return (NULL); |
100 | ||
101 | /* | |
102 | * See if there are more attributes to return... | |
103 | */ | |
104 | ||
bd7854cb | 105 | if ((attr = (ppd_attr_t *)cupsArrayNext(ppd->sorted_attrs)) == NULL) |
ef416fc2 | 106 | return (NULL); |
ef416fc2 | 107 | |
108 | /* | |
109 | * Check the next attribute to see if it is a match... | |
110 | */ | |
111 | ||
bd7854cb | 112 | if (strcasecmp(attr->name, name) || (spec && strcasecmp(attr->spec, spec))) |
ef416fc2 | 113 | { |
114 | /* | |
bd7854cb | 115 | * Nope, reset the current pointer to the end of the array... |
ef416fc2 | 116 | */ |
117 | ||
bd7854cb | 118 | cupsArrayIndex(ppd->sorted_attrs, cupsArrayCount(ppd->sorted_attrs)); |
119 | ||
ef416fc2 | 120 | return (NULL); |
121 | } | |
122 | ||
123 | /* | |
124 | * Return the next attribute's value... | |
125 | */ | |
126 | ||
bd7854cb | 127 | return (attr); |
ef416fc2 | 128 | } |
129 | ||
130 | ||
131 | /* | |
bd7854cb | 132 | * End of "$Id: attr.c 5119 2006-02-16 15:52:06Z mike $". |
ef416fc2 | 133 | */ |