1
/* $XFree86: xc/programs/Xserver/hw/xfree86/parser/Module.c,v 1.11 2003/01/04 20:20:23 paulo Exp $ */
4
* Copyright (c) 1997 Metro Link Incorporated
6
* Permission is hereby granted, free of charge, to any person obtaining a
7
* copy of this software and associated documentation files (the "Software"),
8
* to deal in the Software without restriction, including without limitation
9
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
10
* and/or sell copies of the Software, and to permit persons to whom the
11
* Software is furnished to do so, subject to the following conditions:
13
* The above copyright notice and this permission notice shall be included in
14
* all copies or substantial portions of the Software.
16
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19
* THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
20
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
21
* OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24
* Except as contained in this notice, the name of the Metro Link shall not be
25
* used in advertising or otherwise to promote the sale, use or other dealings
26
* in this Software without prior written authorization from Metro Link.
30
/* View/edit this file with tab stops set to 4 */
32
#include "xf86Parser.h"
33
#include "xf86tokens.h"
34
#include "Configint.h"
38
static xf86ConfigSymTabRec SubModuleTab[] =
40
{ENDSUBSECTION, "endsubsection"},
45
static xf86ConfigSymTabRec ModuleTab[] =
47
{ENDSECTION, "endsection"},
49
{LOAD_DRIVER, "loaddriver"},
50
{SUBSECTION, "subsection"},
54
#define CLEANUP xf86freeModules
57
xf86parseModuleSubSection (XF86LoadPtr head, char *name)
60
parsePrologue (XF86LoadPtr, XF86LoadRec)
62
ptr->load_name = name;
63
ptr->load_type = XF86_LOAD_MODULE;
65
ptr->list.next = NULL;
67
while ((token = xf86getToken (SubModuleTab)) != ENDSUBSECTION)
72
ptr->load_comment = xf86addComment(ptr->load_comment, val.str);
75
ptr->load_opt = xf86parseOption(ptr->load_opt);
78
xf86parseError (UNEXPECTED_EOF_MSG, NULL);
82
xf86parseError (INVALID_KEYWORD_MSG, xf86tokenString ());
90
return ((XF86LoadPtr) xf86addListItem ((glp) head, (glp) ptr));
94
xf86parseModuleSection (void)
97
parsePrologue (XF86ConfModulePtr, XF86ConfModuleRec)
99
while ((token = xf86getToken (ModuleTab)) != ENDSECTION)
104
ptr->mod_comment = xf86addComment(ptr->mod_comment, val.str);
107
if (xf86getSubToken (&(ptr->mod_comment)) != STRING)
108
Error (QUOTE_MSG, "Load");
110
xf86addNewLoadDirective (ptr->mod_load_lst, val.str,
111
XF86_LOAD_MODULE, NULL);
114
if (xf86getSubToken (&(ptr->mod_comment)) != STRING)
115
Error (QUOTE_MSG, "LoadDriver");
117
xf86addNewLoadDirective (ptr->mod_load_lst, val.str,
118
XF86_LOAD_DRIVER, NULL);
121
if (xf86getSubToken (&(ptr->mod_comment)) != STRING)
122
Error (QUOTE_MSG, "SubSection");
124
xf86parseModuleSubSection (ptr->mod_load_lst, val.str);
127
Error (UNEXPECTED_EOF_MSG, NULL);
130
Error (INVALID_KEYWORD_MSG, xf86tokenString ());
136
printf ("Module section parsed\n");
145
xf86printModuleSection (FILE * cf, XF86ConfModulePtr ptr)
152
if (ptr->mod_comment)
153
fprintf(cf, "%s", ptr->mod_comment);
154
for (lptr = ptr->mod_load_lst; lptr; lptr = lptr->list.next)
156
switch (lptr->load_type)
158
case XF86_LOAD_MODULE:
159
if( lptr->load_opt == NULL ) {
160
fprintf (cf, "\tLoad \"%s\"", lptr->load_name);
161
if (lptr->load_comment)
162
fprintf(cf, "%s", lptr->load_comment);
168
fprintf (cf, "\tSubSection \"%s\"\n", lptr->load_name);
169
if (lptr->load_comment)
170
fprintf(cf, "%s", lptr->load_comment);
171
xf86printOptionList(cf, lptr->load_opt, 2);
172
fprintf (cf, "\tEndSubSection\n");
175
case XF86_LOAD_DRIVER:
176
fprintf (cf, "\tLoadDriver \"%s\"", lptr->load_name);
177
if (lptr->load_comment)
178
fprintf(cf, "%s", lptr->load_comment);
184
fprintf (cf, "#\tUnknown type \"%s\"\n", lptr->load_name);
192
xf86addNewLoadDirective (XF86LoadPtr head, char *name, int type, XF86OptionPtr opts)
197
new = xf86confcalloc (1, sizeof (XF86LoadRec));
198
new->load_name = name;
199
new->load_type = type;
200
new->load_opt = opts;
201
new->list.next = NULL;
203
if ((token = xf86getToken(NULL)) == COMMENT)
204
new->load_comment = xf86addComment(new->load_comment, val.str);
206
xf86unGetToken(token);
208
return ((XF86LoadPtr) xf86addListItem ((glp) head, (glp) new));
212
xf86freeModules (XF86ConfModulePtr ptr)
219
lptr = ptr->mod_load_lst;
222
TestFree (lptr->load_name);
223
TestFree (lptr->load_comment);
225
lptr = lptr->list.next;
228
TestFree (ptr->mod_comment);