First import
[xorg_rtime.git] / xorg-server-1.4 / hw / xfree86 / parser / read.c
blob9f79696acc9ff3176bb83fd5bfa193cef4ad78ee
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 TopLevelTab[] =
70 {SECTION, "section"},
71 {-1, ""},
74 #define CLEANUP xf86freeConfig
76 /*
77 * This function resolves name references and reports errors if the named
78 * objects cannot be found.
80 static int
81 xf86validateConfig (XF86ConfigPtr p)
83 if (!xf86validateDevice (p))
84 return FALSE;
85 if (!xf86validateScreen (p))
86 return FALSE;
87 if (!xf86validateInput (p))
88 return FALSE;
89 if (!xf86validateLayout (p))
90 return FALSE;
92 return (TRUE);
95 XF86ConfigPtr
96 xf86readConfigFile (void)
98 int token;
99 XF86ConfigPtr ptr = NULL;
101 if ((ptr = xf86confcalloc (1, sizeof (XF86ConfigRec))) == NULL)
103 return NULL;
105 memset (ptr, 0, sizeof (XF86ConfigRec));
107 while ((token = xf86getToken (TopLevelTab)) != EOF_TOKEN)
109 switch (token)
111 case COMMENT:
112 ptr->conf_comment = xf86addComment(ptr->conf_comment, val.str);
113 break;
114 case SECTION:
115 if (xf86getSubToken (&(ptr->conf_comment)) != STRING)
117 xf86parseError (QUOTE_MSG, "Section");
118 CLEANUP (ptr);
119 return (NULL);
121 xf86setSection (val.str);
122 if (xf86nameCompare (val.str, "files") == 0)
124 xf86conffree(val.str);
125 val.str = NULL;
126 HANDLE_RETURN (conf_files, xf86parseFilesSection ());
128 else if (xf86nameCompare (val.str, "serverflags") == 0)
130 xf86conffree(val.str);
131 val.str = NULL;
132 HANDLE_RETURN (conf_flags, xf86parseFlagsSection ());
134 else if (xf86nameCompare (val.str, "pointer") == 0)
136 xf86conffree(val.str);
137 val.str = NULL;
138 HANDLE_LIST (conf_input_lst, xf86parsePointerSection,
139 XF86ConfInputPtr);
141 else if (xf86nameCompare (val.str, "videoadaptor") == 0)
143 xf86conffree(val.str);
144 val.str = NULL;
145 HANDLE_LIST (conf_videoadaptor_lst, xf86parseVideoAdaptorSection,
146 XF86ConfVideoAdaptorPtr);
148 else if (xf86nameCompare (val.str, "device") == 0)
150 xf86conffree(val.str);
151 val.str = NULL;
152 HANDLE_LIST (conf_device_lst, xf86parseDeviceSection,
153 XF86ConfDevicePtr);
155 else if (xf86nameCompare (val.str, "monitor") == 0)
157 xf86conffree(val.str);
158 val.str = NULL;
159 HANDLE_LIST (conf_monitor_lst, xf86parseMonitorSection,
160 XF86ConfMonitorPtr);
162 else if (xf86nameCompare (val.str, "modes") == 0)
164 xf86conffree(val.str);
165 val.str = NULL;
166 HANDLE_LIST (conf_modes_lst, xf86parseModesSection,
167 XF86ConfModesPtr);
169 else if (xf86nameCompare (val.str, "screen") == 0)
171 xf86conffree(val.str);
172 val.str = NULL;
173 HANDLE_LIST (conf_screen_lst, xf86parseScreenSection,
174 XF86ConfScreenPtr);
176 else if (xf86nameCompare(val.str, "inputdevice") == 0)
178 xf86conffree(val.str);
179 val.str = NULL;
180 HANDLE_LIST (conf_input_lst, xf86parseInputSection,
181 XF86ConfInputPtr);
183 else if (xf86nameCompare (val.str, "module") == 0)
185 xf86conffree(val.str);
186 val.str = NULL;
187 HANDLE_RETURN (conf_modules, xf86parseModuleSection ());
189 else if (xf86nameCompare (val.str, "serverlayout") == 0)
191 xf86conffree(val.str);
192 val.str = NULL;
193 HANDLE_LIST (conf_layout_lst, xf86parseLayoutSection,
194 XF86ConfLayoutPtr);
196 else if (xf86nameCompare (val.str, "vendor") == 0)
198 xf86conffree(val.str);
199 val.str = NULL;
200 HANDLE_LIST (conf_vendor_lst, xf86parseVendorSection,
201 XF86ConfVendorPtr);
203 else if (xf86nameCompare (val.str, "dri") == 0)
205 xf86conffree(val.str);
206 val.str = NULL;
207 HANDLE_RETURN (conf_dri, xf86parseDRISection ());
209 else if (xf86nameCompare (val.str, "extensions") == 0)
211 xf86conffree(val.str);
212 val.str = NULL;
213 HANDLE_RETURN (conf_extensions, xf86parseExtensionsSection ());
215 else
217 Error (INVALID_SECTION_MSG, xf86tokenString ());
218 xf86conffree(val.str);
219 val.str = NULL;
221 break;
222 default:
223 Error (INVALID_KEYWORD_MSG, xf86tokenString ());
224 xf86conffree(val.str);
225 val.str = NULL;
229 if (xf86validateConfig (ptr))
230 return (ptr);
231 else
233 CLEANUP (ptr);
234 return (NULL);
238 #undef CLEANUP
241 * adds an item to the end of the linked list. Any record whose first field
242 * is a GenericListRec can be cast to this type and used with this function.
243 * A pointer to the head of the list is returned to handle the addition of
244 * the first item.
246 GenericListPtr
247 xf86addListItem (GenericListPtr head, GenericListPtr new)
249 GenericListPtr p = head;
250 GenericListPtr last = NULL;
252 while (p)
254 last = p;
255 p = p->next;
258 if (last)
260 last->next = new;
261 return (head);
263 else
264 return (new);
268 * Test if one chained list contains the other.
269 * In this case both list have the same endpoint (provided they don't loop)
272 xf86itemNotSublist(GenericListPtr list_1, GenericListPtr list_2)
274 GenericListPtr p = list_1;
275 GenericListPtr last_1 = NULL, last_2 = NULL;
277 while (p) {
278 last_1 = p;
279 p = p->next;
282 p = list_2;
283 while (p) {
284 last_2 = p;
285 p = p->next;
288 return (!(last_1 == last_2));
291 void
292 xf86freeConfig (XF86ConfigPtr p)
294 if (p == NULL)
295 return;
297 xf86freeFiles (p->conf_files);
298 xf86freeModules (p->conf_modules);
299 xf86freeFlags (p->conf_flags);
300 xf86freeMonitorList (p->conf_monitor_lst);
301 xf86freeModesList (p->conf_modes_lst);
302 xf86freeVideoAdaptorList (p->conf_videoadaptor_lst);
303 xf86freeDeviceList (p->conf_device_lst);
304 xf86freeScreenList (p->conf_screen_lst);
305 xf86freeLayoutList (p->conf_layout_lst);
306 xf86freeInputList (p->conf_input_lst);
307 xf86freeVendorList (p->conf_vendor_lst);
308 xf86freeDRI (p->conf_dri);
309 xf86freeExtensions (p->conf_extensions);
310 TestFree(p->conf_comment);
312 xf86conffree (p);