Imported Upstream version 1.15.1
[deb_xorg-server.git] / hw / xfree86 / parser / Vendor.c
CommitLineData
a09e091a
JB
1/*
2 *
3 * Copyright (c) 1997 Metro Link Incorporated
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
19 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
20 * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 * SOFTWARE.
22 *
23 * Except as contained in this notice, the name of the Metro Link shall not be
24 * used in advertising or otherwise to promote the sale, use or other dealings
25 * in this Software without prior written authorization from Metro Link.
26 *
27 */
28/*
29 * Copyright (c) 1997-2003 by The XFree86 Project, Inc.
30 *
31 * Permission is hereby granted, free of charge, to any person obtaining a
32 * copy of this software and associated documentation files (the "Software"),
33 * to deal in the Software without restriction, including without limitation
34 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
35 * and/or sell copies of the Software, and to permit persons to whom the
36 * Software is furnished to do so, subject to the following conditions:
37 *
38 * The above copyright notice and this permission notice shall be included in
39 * all copies or substantial portions of the Software.
40 *
41 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
42 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
43 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
44 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
45 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
46 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
47 * OTHER DEALINGS IN THE SOFTWARE.
48 *
49 * Except as contained in this notice, the name of the copyright holder(s)
50 * and author(s) shall not be used in advertising or otherwise to promote
51 * the sale, use or other dealings in this Software without prior written
52 * authorization from the copyright holder(s) and author(s).
53 */
54
55#ifdef HAVE_XORG_CONFIG_H
56#include <xorg-config.h>
57#endif
58
59#include "xf86Parser.h"
60#include "xf86tokens.h"
61#include "Configint.h"
62
63extern LexRec val;
64
65static xf86ConfigSymTabRec VendorSubTab[] = {
66 {ENDSUBSECTION, "endsubsection"},
67 {IDENTIFIER, "identifier"},
68 {OPTION, "option"},
69 {-1, ""},
70};
71
72#define CLEANUP xf86freeVendorSubList
73
74static XF86ConfVendSubPtr
75xf86parseVendorSubSection(void)
76{
77 int has_ident = FALSE;
78 int token;
79
80 parsePrologue(XF86ConfVendSubPtr, XF86ConfVendSubRec)
81
82 while ((token = xf86getToken(VendorSubTab)) != ENDSUBSECTION) {
83 switch (token) {
84 case COMMENT:
85 ptr->vs_comment = xf86addComment(ptr->vs_comment, val.str);
86 break;
87 case IDENTIFIER:
88 if (xf86getSubToken(&(ptr->vs_comment)))
89 Error(QUOTE_MSG, "Identifier");
90 if (has_ident == TRUE)
91 Error(MULTIPLE_MSG, "Identifier");
92 ptr->vs_identifier = val.str;
93 has_ident = TRUE;
94 break;
95 case OPTION:
96 ptr->vs_option_lst = xf86parseOption(ptr->vs_option_lst);
97 break;
98
99 case EOF_TOKEN:
100 Error(UNEXPECTED_EOF_MSG);
101 break;
102 default:
103 Error(INVALID_KEYWORD_MSG, xf86tokenString());
104 break;
105 }
106 }
107
108#ifdef DEBUG
109 printf("Vendor subsection parsed\n");
110#endif
111
112 return ptr;
113}
114
115#undef CLEANUP
116
117static xf86ConfigSymTabRec VendorTab[] = {
118 {ENDSECTION, "endsection"},
119 {IDENTIFIER, "identifier"},
120 {OPTION, "option"},
121 {SUBSECTION, "subsection"},
122 {-1, ""},
123};
124
125#define CLEANUP xf86freeVendorList
126
127XF86ConfVendorPtr
128xf86parseVendorSection(void)
129{
130 int has_ident = FALSE;
131 int token;
132
133 parsePrologue(XF86ConfVendorPtr, XF86ConfVendorRec)
134
135 while ((token = xf86getToken(VendorTab)) != ENDSECTION) {
136 switch (token) {
137 case COMMENT:
138 ptr->vnd_comment = xf86addComment(ptr->vnd_comment, val.str);
139 break;
140 case IDENTIFIER:
141 if (xf86getSubToken(&(ptr->vnd_comment)) != STRING)
142 Error(QUOTE_MSG, "Identifier");
143 if (has_ident == TRUE)
144 Error(MULTIPLE_MSG, "Identifier");
145 ptr->vnd_identifier = val.str;
146 has_ident = TRUE;
147 break;
148 case OPTION:
149 ptr->vnd_option_lst = xf86parseOption(ptr->vnd_option_lst);
150 break;
151 case SUBSECTION:
152 if (xf86getSubToken(&(ptr->vnd_comment)) != STRING)
153 Error(QUOTE_MSG, "SubSection");
154 {
155 HANDLE_LIST(vnd_sub_lst, xf86parseVendorSubSection,
156 XF86ConfVendSubPtr);
157 }
158 break;
159 case EOF_TOKEN:
160 Error(UNEXPECTED_EOF_MSG);
161 break;
162 default:
163 Error(INVALID_KEYWORD_MSG, xf86tokenString());
164 break;
165 }
166
167 }
168
169 if (!has_ident)
170 Error(NO_IDENT_MSG);
171
172#ifdef DEBUG
173 printf("Vendor section parsed\n");
174#endif
175
176 return ptr;
177}
178
179#undef CLEANUP
180
181void
182xf86printVendorSection(FILE * cf, XF86ConfVendorPtr ptr)
183{
184 XF86ConfVendSubPtr pptr;
185
186 while (ptr) {
187 fprintf(cf, "Section \"Vendor\"\n");
188 if (ptr->vnd_comment)
189 fprintf(cf, "%s", ptr->vnd_comment);
190 if (ptr->vnd_identifier)
191 fprintf(cf, "\tIdentifier \"%s\"\n", ptr->vnd_identifier);
192
193 xf86printOptionList(cf, ptr->vnd_option_lst, 1);
194 for (pptr = ptr->vnd_sub_lst; pptr; pptr = pptr->list.next) {
195 fprintf(cf, "\tSubSection \"Vendor\"\n");
196 if (pptr->vs_comment)
197 fprintf(cf, "%s", pptr->vs_comment);
198 if (pptr->vs_identifier)
199 fprintf(cf, "\t\tIdentifier \"%s\"\n", pptr->vs_identifier);
200 xf86printOptionList(cf, pptr->vs_option_lst, 2);
201 fprintf(cf, "\tEndSubSection\n");
202 }
203 fprintf(cf, "EndSection\n\n");
204 ptr = ptr->list.next;
205 }
206}
207
208void
209xf86freeVendorList(XF86ConfVendorPtr p)
210{
211 if (p == NULL)
212 return;
213 xf86freeVendorSubList(p->vnd_sub_lst);
214 TestFree(p->vnd_identifier);
215 TestFree(p->vnd_comment);
216 xf86optionListFree(p->vnd_option_lst);
217 free(p);
218}
219
220void
221xf86freeVendorSubList(XF86ConfVendSubPtr ptr)
222{
223 XF86ConfVendSubPtr prev;
224
225 while (ptr) {
226 TestFree(ptr->vs_identifier);
227 TestFree(ptr->vs_name);
228 TestFree(ptr->vs_comment);
229 xf86optionListFree(ptr->vs_option_lst);
230 prev = ptr;
231 ptr = ptr->list.next;
232 free(prev);
233 }
234}