Initial commit
[xorg_rtime.git] / xorg-server-1.4 / hw / xfree86 / parser / Video.c
bloba8912cf4438f3fa96c504d5f52666c8be374b79f
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).
55 /* View/edit this file with tab stops set to 4 */
57 #ifdef HAVE_XORG_CONFIG_H
58 #include <xorg-config.h>
59 #endif
61 #include "xf86Parser.h"
62 #include "xf86tokens.h"
63 #include "Configint.h"
65 extern LexRec val;
67 static xf86ConfigSymTabRec VideoPortTab[] =
69 {ENDSUBSECTION, "endsubsection"},
70 {IDENTIFIER, "identifier"},
71 {OPTION, "option"},
72 {-1, ""},
75 #define CLEANUP xf86freeVideoPortList
77 static void
78 xf86freeVideoPortList (XF86ConfVideoPortPtr ptr)
80 XF86ConfVideoPortPtr prev;
82 while (ptr)
84 TestFree (ptr->vp_identifier);
85 TestFree (ptr->vp_comment);
86 xf86optionListFree (ptr->vp_option_lst);
87 prev = ptr;
88 ptr = ptr->list.next;
89 xf86conffree (prev);
93 static XF86ConfVideoPortPtr
94 xf86parseVideoPortSubSection (void)
96 int has_ident = FALSE;
97 int token;
98 parsePrologue (XF86ConfVideoPortPtr, XF86ConfVideoPortRec)
100 while ((token = xf86getToken (VideoPortTab)) != ENDSUBSECTION)
102 switch (token)
104 case COMMENT:
105 ptr->vp_comment = xf86addComment(ptr->vp_comment, val.str);
106 break;
107 case IDENTIFIER:
108 if (xf86getSubToken (&(ptr->vp_comment)) != STRING)
109 Error (QUOTE_MSG, "Identifier");
110 if (has_ident == TRUE)
111 Error (MULTIPLE_MSG, "Identifier");
112 ptr->vp_identifier = val.str;
113 has_ident = TRUE;
114 break;
115 case OPTION:
116 ptr->vp_option_lst = xf86parseOption(ptr->vp_option_lst);
117 break;
119 case EOF_TOKEN:
120 Error (UNEXPECTED_EOF_MSG, NULL);
121 break;
122 default:
123 Error (INVALID_KEYWORD_MSG, xf86tokenString ());
124 break;
128 #ifdef DEBUG
129 printf ("VideoPort subsection parsed\n");
130 #endif
132 return ptr;
135 #undef CLEANUP
137 static xf86ConfigSymTabRec VideoAdaptorTab[] =
139 {ENDSECTION, "endsection"},
140 {IDENTIFIER, "identifier"},
141 {VENDOR, "vendorname"},
142 {BOARD, "boardname"},
143 {BUSID, "busid"},
144 {DRIVER, "driver"},
145 {OPTION, "option"},
146 {SUBSECTION, "subsection"},
147 {-1, ""},
150 #define CLEANUP xf86freeVideoAdaptorList
152 XF86ConfVideoAdaptorPtr
153 xf86parseVideoAdaptorSection (void)
155 int has_ident = FALSE;
156 int token;
158 parsePrologue (XF86ConfVideoAdaptorPtr, XF86ConfVideoAdaptorRec)
160 while ((token = xf86getToken (VideoAdaptorTab)) != ENDSECTION)
162 switch (token)
164 case COMMENT:
165 ptr->va_comment = xf86addComment(ptr->va_comment, val.str);
166 break;
167 case IDENTIFIER:
168 if (xf86getSubToken (&(ptr->va_comment)) != STRING)
169 Error (QUOTE_MSG, "Identifier");
170 ptr->va_identifier = val.str;
171 if (has_ident == TRUE)
172 Error (MULTIPLE_MSG, "Identifier");
173 has_ident = TRUE;
174 break;
175 case VENDOR:
176 if (xf86getSubToken (&(ptr->va_comment)) != STRING)
177 Error (QUOTE_MSG, "Vendor");
178 ptr->va_vendor = val.str;
179 break;
180 case BOARD:
181 if (xf86getSubToken (&(ptr->va_comment)) != STRING)
182 Error (QUOTE_MSG, "Board");
183 ptr->va_board = val.str;
184 break;
185 case BUSID:
186 if (xf86getSubToken (&(ptr->va_comment)) != STRING)
187 Error (QUOTE_MSG, "BusID");
188 ptr->va_busid = val.str;
189 break;
190 case DRIVER:
191 if (xf86getSubToken (&(ptr->va_comment)) != STRING)
192 Error (QUOTE_MSG, "Driver");
193 ptr->va_driver = val.str;
194 break;
195 case OPTION:
196 ptr->va_option_lst = xf86parseOption(ptr->va_option_lst);
197 break;
198 case SUBSECTION:
199 if (xf86getSubToken (&(ptr->va_comment)) != STRING)
200 Error (QUOTE_MSG, "SubSection");
202 HANDLE_LIST (va_port_lst, xf86parseVideoPortSubSection,
203 XF86ConfVideoPortPtr);
205 break;
207 case EOF_TOKEN:
208 Error (UNEXPECTED_EOF_MSG, NULL);
209 break;
210 default:
211 Error (INVALID_KEYWORD_MSG, xf86tokenString ());
212 break;
216 if (!has_ident)
217 Error (NO_IDENT_MSG, NULL);
219 #ifdef DEBUG
220 printf ("VideoAdaptor section parsed\n");
221 #endif
223 return ptr;
226 void
227 xf86printVideoAdaptorSection (FILE * cf, XF86ConfVideoAdaptorPtr ptr)
229 XF86ConfVideoPortPtr pptr;
231 while (ptr)
233 fprintf (cf, "Section \"VideoAdaptor\"\n");
234 if (ptr->va_comment)
235 fprintf (cf, "%s", ptr->va_comment);
236 if (ptr->va_identifier)
237 fprintf (cf, "\tIdentifier \"%s\"\n", ptr->va_identifier);
238 if (ptr->va_vendor)
239 fprintf (cf, "\tVendorName \"%s\"\n", ptr->va_vendor);
240 if (ptr->va_board)
241 fprintf (cf, "\tBoardName \"%s\"\n", ptr->va_board);
242 if (ptr->va_busid)
243 fprintf (cf, "\tBusID \"%s\"\n", ptr->va_busid);
244 if (ptr->va_driver)
245 fprintf (cf, "\tDriver \"%s\"\n", ptr->va_driver);
246 xf86printOptionList(cf, ptr->va_option_lst, 1);
247 for (pptr = ptr->va_port_lst; pptr; pptr = pptr->list.next)
249 fprintf (cf, "\tSubSection \"VideoPort\"\n");
250 if (pptr->vp_comment)
251 fprintf (cf, "%s", pptr->vp_comment);
252 if (pptr->vp_identifier)
253 fprintf (cf, "\t\tIdentifier \"%s\"\n", pptr->vp_identifier);
254 xf86printOptionList(cf, pptr->vp_option_lst, 2);
255 fprintf (cf, "\tEndSubSection\n");
257 fprintf (cf, "EndSection\n\n");
258 ptr = ptr->list.next;
263 void
264 xf86freeVideoAdaptorList (XF86ConfVideoAdaptorPtr ptr)
266 XF86ConfVideoAdaptorPtr prev;
268 while (ptr)
270 TestFree (ptr->va_identifier);
271 TestFree (ptr->va_vendor);
272 TestFree (ptr->va_board);
273 TestFree (ptr->va_busid);
274 TestFree (ptr->va_driver);
275 TestFree (ptr->va_fwdref);
276 TestFree (ptr->va_comment);
277 xf86freeVideoPortList (ptr->va_port_lst);
278 xf86optionListFree (ptr->va_option_lst);
279 prev = ptr;
280 ptr = ptr->list.next;
281 xf86conffree (prev);
285 XF86ConfVideoAdaptorPtr
286 xf86findVideoAdaptor (const char *ident, XF86ConfVideoAdaptorPtr p)
288 while (p)
290 if (xf86nameCompare (ident, p->va_identifier) == 0)
291 return (p);
293 p = p->list.next;
295 return (NULL);