First import
[xorg_rtime.git] / xorg-server-1.4 / hw / xfree86 / parser / Vendor.c
blobd1e608067ac8a9bdde596ef3b189b4de8fdaa94b
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:
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
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.
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.
29 * Copyright (c) 1997-2003 by The XFree86 Project, Inc.
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:
38 * The above copyright notice and this permission notice shall be included in
39 * all copies or substantial portions of the Software.
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.
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).
56 /* View/edit this file with tab stops set to 4 */
58 #ifdef HAVE_XORG_CONFIG_H
59 #include <xorg-config.h>
60 #endif
62 #include "xf86Parser.h"
63 #include "xf86tokens.h"
64 #include "Configint.h"
66 extern LexRec val;
68 static xf86ConfigSymTabRec VendorSubTab[] =
70 {ENDSUBSECTION, "endsubsection"},
71 {IDENTIFIER, "identifier"},
72 {OPTION, "option"},
73 {-1, ""},
76 #define CLEANUP xf86freeVendorSubList
78 static XF86ConfVendSubPtr
79 xf86parseVendorSubSection (void)
81 int has_ident = FALSE;
82 int token;
83 parsePrologue (XF86ConfVendSubPtr, XF86ConfVendSubRec)
85 while ((token = xf86getToken (VendorSubTab)) != ENDSUBSECTION)
87 switch (token)
89 case COMMENT:
90 ptr->vs_comment = xf86addComment(ptr->vs_comment, val.str);
91 break;
92 case IDENTIFIER:
93 if (xf86getSubToken (&(ptr->vs_comment)))
94 Error (QUOTE_MSG, "Identifier");
95 if (has_ident == TRUE)
96 Error (MULTIPLE_MSG, "Identifier");
97 ptr->vs_identifier = val.str;
98 has_ident = TRUE;
99 break;
100 case OPTION:
101 ptr->vs_option_lst = xf86parseOption(ptr->vs_option_lst);
102 break;
104 case EOF_TOKEN:
105 Error (UNEXPECTED_EOF_MSG, NULL);
106 break;
107 default:
108 Error (INVALID_KEYWORD_MSG, xf86tokenString ());
109 break;
113 #ifdef DEBUG
114 printf ("Vendor subsection parsed\n");
115 #endif
117 return ptr;
120 #undef CLEANUP
122 static xf86ConfigSymTabRec VendorTab[] =
124 {ENDSECTION, "endsection"},
125 {IDENTIFIER, "identifier"},
126 {OPTION, "option"},
127 {SUBSECTION, "subsection"},
128 {-1, ""},
131 #define CLEANUP xf86freeVendorList
133 XF86ConfVendorPtr
134 xf86parseVendorSection (void)
136 int has_ident = FALSE;
137 int token;
138 parsePrologue (XF86ConfVendorPtr, XF86ConfVendorRec)
140 while ((token = xf86getToken (VendorTab)) != ENDSECTION)
142 switch (token)
144 case COMMENT:
145 ptr->vnd_comment = xf86addComment(ptr->vnd_comment, val.str);
146 break;
147 case IDENTIFIER:
148 if (xf86getSubToken (&(ptr->vnd_comment)) != STRING)
149 Error (QUOTE_MSG, "Identifier");
150 if (has_ident == TRUE)
151 Error (MULTIPLE_MSG, "Identifier");
152 ptr->vnd_identifier = val.str;
153 has_ident = TRUE;
154 break;
155 case OPTION:
156 ptr->vnd_option_lst = xf86parseOption(ptr->vnd_option_lst);
157 break;
158 case SUBSECTION:
159 if (xf86getSubToken (&(ptr->vnd_comment)) != STRING)
160 Error (QUOTE_MSG, "SubSection");
162 HANDLE_LIST (vnd_sub_lst, xf86parseVendorSubSection,
163 XF86ConfVendSubPtr);
165 break;
166 case EOF_TOKEN:
167 Error (UNEXPECTED_EOF_MSG, NULL);
168 break;
169 default:
170 Error (INVALID_KEYWORD_MSG, xf86tokenString ());
171 break;
176 if (!has_ident)
177 Error (NO_IDENT_MSG, NULL);
179 #ifdef DEBUG
180 printf ("Vendor section parsed\n");
181 #endif
183 return ptr;
186 #undef CLEANUP
188 void
189 xf86printVendorSection (FILE * cf, XF86ConfVendorPtr ptr)
191 XF86ConfVendSubPtr pptr;
193 while (ptr)
195 fprintf (cf, "Section \"Vendor\"\n");
196 if (ptr->vnd_comment)
197 fprintf (cf, "%s", ptr->vnd_comment);
198 if (ptr->vnd_identifier)
199 fprintf (cf, "\tIdentifier \"%s\"\n", ptr->vnd_identifier);
201 xf86printOptionList(cf, ptr->vnd_option_lst, 1);
202 for (pptr = ptr->vnd_sub_lst; pptr; pptr = pptr->list.next)
204 fprintf (cf, "\tSubSection \"Vendor\"\n");
205 if (pptr->vs_comment)
206 fprintf (cf, "%s", pptr->vs_comment);
207 if (pptr->vs_identifier)
208 fprintf (cf, "\t\tIdentifier \"%s\"\n", pptr->vs_identifier);
209 xf86printOptionList(cf, pptr->vs_option_lst, 2);
210 fprintf (cf, "\tEndSubSection\n");
212 fprintf (cf, "EndSection\n\n");
213 ptr = ptr->list.next;
217 void
218 xf86freeVendorList (XF86ConfVendorPtr p)
220 if (p == NULL)
221 return;
222 xf86freeVendorSubList (p->vnd_sub_lst);
223 TestFree (p->vnd_identifier);
224 TestFree (p->vnd_comment);
225 xf86optionListFree (p->vnd_option_lst);
226 xf86conffree (p);
229 void
230 xf86freeVendorSubList (XF86ConfVendSubPtr ptr)
232 XF86ConfVendSubPtr prev;
234 while (ptr)
236 TestFree (ptr->vs_identifier);
237 TestFree (ptr->vs_name);
238 TestFree (ptr->vs_comment);
239 xf86optionListFree (ptr->vs_option_lst);
240 prev = ptr;
241 ptr = ptr->list.next;
242 xf86conffree (prev);