Commit | Line | Data |
---|---|---|
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 | ||
63 | extern LexRec val; | |
64 | ||
65 | static xf86ConfigSymTabRec SubModuleTab[] = { | |
66 | {ENDSUBSECTION, "endsubsection"}, | |
67 | {OPTION, "option"}, | |
68 | {-1, ""}, | |
69 | }; | |
70 | ||
71 | static xf86ConfigSymTabRec ModuleTab[] = { | |
72 | {ENDSECTION, "endsection"}, | |
73 | {LOAD, "load"}, | |
74 | {DISABLE, "disable"}, | |
75 | {LOAD_DRIVER, "loaddriver"}, | |
76 | {SUBSECTION, "subsection"}, | |
77 | {-1, ""}, | |
78 | }; | |
79 | ||
80 | #define CLEANUP xf86freeModules | |
81 | ||
82 | static XF86LoadPtr | |
83 | xf86parseModuleSubSection(XF86LoadPtr head, char *name) | |
84 | { | |
85 | int token; | |
86 | ||
87 | parsePrologue(XF86LoadPtr, XF86LoadRec) | |
88 | ||
89 | ptr->load_name = name; | |
90 | ptr->load_type = XF86_LOAD_MODULE; | |
91 | ptr->ignore = 0; | |
92 | ptr->load_opt = NULL; | |
93 | ptr->list.next = NULL; | |
94 | ||
95 | while ((token = xf86getToken(SubModuleTab)) != ENDSUBSECTION) { | |
96 | switch (token) { | |
97 | case COMMENT: | |
98 | ptr->load_comment = xf86addComment(ptr->load_comment, val.str); | |
99 | break; | |
100 | case OPTION: | |
101 | ptr->load_opt = xf86parseOption(ptr->load_opt); | |
102 | break; | |
103 | case EOF_TOKEN: | |
104 | xf86parseError(UNEXPECTED_EOF_MSG); | |
105 | free(ptr); | |
106 | return NULL; | |
107 | default: | |
108 | xf86parseError(INVALID_KEYWORD_MSG, xf86tokenString()); | |
109 | free(ptr); | |
110 | return NULL; | |
111 | break; | |
112 | } | |
113 | ||
114 | } | |
115 | ||
116 | return ((XF86LoadPtr) xf86addListItem((glp) head, (glp) ptr)); | |
117 | } | |
118 | ||
119 | XF86ConfModulePtr | |
120 | xf86parseModuleSection(void) | |
121 | { | |
122 | int token; | |
123 | ||
124 | parsePrologue(XF86ConfModulePtr, XF86ConfModuleRec) | |
125 | ||
126 | while ((token = xf86getToken(ModuleTab)) != ENDSECTION) { | |
127 | switch (token) { | |
128 | case COMMENT: | |
129 | ptr->mod_comment = xf86addComment(ptr->mod_comment, val.str); | |
130 | break; | |
131 | case LOAD: | |
132 | if (xf86getSubToken(&(ptr->mod_comment)) != STRING) | |
133 | Error(QUOTE_MSG, "Load"); | |
134 | ptr->mod_load_lst = | |
135 | xf86addNewLoadDirective(ptr->mod_load_lst, val.str, | |
136 | XF86_LOAD_MODULE, NULL); | |
137 | break; | |
138 | case DISABLE: | |
139 | if (xf86getSubToken(&(ptr->mod_comment)) != STRING) | |
140 | Error(QUOTE_MSG, "Disable"); | |
141 | ptr->mod_disable_lst = | |
142 | xf86addNewLoadDirective(ptr->mod_disable_lst, val.str, | |
143 | XF86_DISABLE_MODULE, NULL); | |
144 | break; | |
145 | case LOAD_DRIVER: | |
146 | if (xf86getSubToken(&(ptr->mod_comment)) != STRING) | |
147 | Error(QUOTE_MSG, "LoadDriver"); | |
148 | ptr->mod_load_lst = | |
149 | xf86addNewLoadDirective(ptr->mod_load_lst, val.str, | |
150 | XF86_LOAD_DRIVER, NULL); | |
151 | break; | |
152 | case SUBSECTION: | |
153 | if (xf86getSubToken(&(ptr->mod_comment)) != STRING) | |
154 | Error(QUOTE_MSG, "SubSection"); | |
155 | ptr->mod_load_lst = | |
156 | xf86parseModuleSubSection(ptr->mod_load_lst, val.str); | |
157 | break; | |
158 | case EOF_TOKEN: | |
159 | Error(UNEXPECTED_EOF_MSG); | |
160 | break; | |
161 | default: | |
162 | Error(INVALID_KEYWORD_MSG, xf86tokenString()); | |
163 | break; | |
164 | } | |
165 | } | |
166 | ||
167 | #ifdef DEBUG | |
168 | printf("Module section parsed\n"); | |
169 | #endif | |
170 | ||
171 | return ptr; | |
172 | } | |
173 | ||
174 | #undef CLEANUP | |
175 | ||
176 | void | |
177 | xf86printModuleSection(FILE * cf, XF86ConfModulePtr ptr) | |
178 | { | |
179 | XF86LoadPtr lptr; | |
180 | ||
181 | if (ptr == NULL) | |
182 | return; | |
183 | ||
184 | if (ptr->mod_comment) | |
185 | fprintf(cf, "%s", ptr->mod_comment); | |
186 | for (lptr = ptr->mod_load_lst; lptr; lptr = lptr->list.next) { | |
187 | switch (lptr->load_type) { | |
188 | case XF86_LOAD_MODULE: | |
189 | if (lptr->load_opt == NULL) { | |
190 | fprintf(cf, "\tLoad \"%s\"", lptr->load_name); | |
191 | if (lptr->load_comment) | |
192 | fprintf(cf, "%s", lptr->load_comment); | |
193 | else | |
194 | fputc('\n', cf); | |
195 | } | |
196 | else { | |
197 | fprintf(cf, "\tSubSection \"%s\"\n", lptr->load_name); | |
198 | if (lptr->load_comment) | |
199 | fprintf(cf, "%s", lptr->load_comment); | |
200 | xf86printOptionList(cf, lptr->load_opt, 2); | |
201 | fprintf(cf, "\tEndSubSection\n"); | |
202 | } | |
203 | break; | |
204 | case XF86_LOAD_DRIVER: | |
205 | fprintf(cf, "\tLoadDriver \"%s\"", lptr->load_name); | |
206 | if (lptr->load_comment) | |
207 | fprintf(cf, "%s", lptr->load_comment); | |
208 | else | |
209 | fputc('\n', cf); | |
210 | break; | |
211 | #if 0 | |
212 | default: | |
213 | fprintf(cf, "#\tUnknown type \"%s\"\n", lptr->load_name); | |
214 | break; | |
215 | #endif | |
216 | } | |
217 | } | |
218 | } | |
219 | ||
220 | XF86LoadPtr | |
221 | xf86addNewLoadDirective(XF86LoadPtr head, char *name, int type, | |
222 | XF86OptionPtr opts) | |
223 | { | |
224 | XF86LoadPtr new; | |
225 | int token; | |
226 | ||
227 | new = calloc(1, sizeof(XF86LoadRec)); | |
228 | new->load_name = name; | |
229 | new->load_type = type; | |
230 | new->load_opt = opts; | |
231 | new->ignore = 0; | |
232 | new->list.next = NULL; | |
233 | ||
234 | if ((token = xf86getToken(NULL)) == COMMENT) | |
235 | new->load_comment = xf86addComment(new->load_comment, val.str); | |
236 | else | |
237 | xf86unGetToken(token); | |
238 | ||
239 | return ((XF86LoadPtr) xf86addListItem((glp) head, (glp) new)); | |
240 | } | |
241 | ||
242 | void | |
243 | xf86freeModules(XF86ConfModulePtr ptr) | |
244 | { | |
245 | XF86LoadPtr lptr; | |
246 | XF86LoadPtr prev; | |
247 | ||
248 | if (ptr == NULL) | |
249 | return; | |
250 | lptr = ptr->mod_load_lst; | |
251 | while (lptr) { | |
252 | TestFree(lptr->load_name); | |
253 | TestFree(lptr->load_comment); | |
254 | prev = lptr; | |
255 | lptr = lptr->list.next; | |
256 | free(prev); | |
257 | } | |
258 | lptr = ptr->mod_disable_lst; | |
259 | while (lptr) { | |
260 | TestFree(lptr->load_name); | |
261 | TestFree(lptr->load_comment); | |
262 | prev = lptr; | |
263 | lptr = lptr->list.next; | |
264 | free(prev); | |
265 | } | |
266 | TestFree(ptr->mod_comment); | |
267 | free(ptr); | |
268 | } |