Initial commit
[xorg_rtime.git] / xorg-server-1.4 / hw / xfree86 / parser / Files.c
blob8cec2a91acb583047286848eeb22d66c02e92123
1 /*
2 * Copyright (c) 1997 Metro Link Incorporated
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
18 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
19 * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 * SOFTWARE.
22 * Except as contained in this notice, the name of the Metro Link shall not be
23 * used in advertising or otherwise to promote the sale, use or other dealings
24 * in this Software without prior written authorization from Metro Link.
28 * Copyright (c) 1997-2003 by The XFree86 Project, Inc.
30 * Permission is hereby granted, free of charge, to any person obtaining a
31 * copy of this software and associated documentation files (the "Software"),
32 * to deal in the Software without restriction, including without limitation
33 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
34 * and/or sell copies of the Software, and to permit persons to whom the
35 * Software is furnished to do so, subject to the following conditions:
37 * The above copyright notice and this permission notice shall be included in
38 * all copies or substantial portions of the Software.
40 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
41 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
42 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
43 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
44 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
45 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
46 * OTHER DEALINGS IN THE SOFTWARE.
48 * Except as contained in this notice, the name of the copyright holder(s)
49 * and author(s) shall not be used in advertising or otherwise to promote
50 * the sale, use or other dealings in this Software without prior written
51 * 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 <X11/Xos.h>
62 #include "xf86Parser.h"
63 #include "xf86tokens.h"
64 #include "Configint.h"
66 extern LexRec val;
68 static xf86ConfigSymTabRec FilesTab[] =
70 {ENDSECTION, "endsection"},
71 {FONTPATH, "fontpath"},
72 {RGBPATH, "rgbpath"},
73 {MODULEPATH, "modulepath"},
74 {INPUTDEVICES, "inputdevices"},
75 {LOGFILEPATH, "logfile"},
76 {-1, ""},
79 #define CLEANUP xf86freeFiles
81 XF86ConfFilesPtr
82 xf86parseFilesSection (void)
84 int i, j;
85 int k, l;
86 char *str;
87 int token;
88 parsePrologue (XF86ConfFilesPtr, XF86ConfFilesRec)
90 while ((token = xf86getToken (FilesTab)) != ENDSECTION)
92 switch (token)
94 case COMMENT:
95 ptr->file_comment = xf86addComment(ptr->file_comment, val.str);
96 break;
97 case FONTPATH:
98 if (xf86getSubToken (&(ptr->file_comment)) != STRING)
99 Error (QUOTE_MSG, "FontPath");
100 j = FALSE;
101 str = val.str;
102 if (ptr->file_fontpath == NULL)
104 ptr->file_fontpath = xf86confmalloc (1);
105 ptr->file_fontpath[0] = '\0';
106 i = strlen (str) + 1;
108 else
110 i = strlen (ptr->file_fontpath) + strlen (str) + 1;
111 if (ptr->file_fontpath[strlen (ptr->file_fontpath) - 1] != ',')
113 i++;
114 j = TRUE;
117 ptr->file_fontpath =
118 xf86confrealloc (ptr->file_fontpath, i);
119 if (j)
120 strcat (ptr->file_fontpath, ",");
122 strcat (ptr->file_fontpath, str);
123 xf86conffree (val.str);
124 break;
125 case RGBPATH:
126 if (xf86getSubToken (&(ptr->file_comment)) != STRING)
127 Error (QUOTE_MSG, "RGBPath");
128 ptr->file_rgbpath = val.str;
129 break;
130 case MODULEPATH:
131 if (xf86getSubToken (&(ptr->file_comment)) != STRING)
132 Error (QUOTE_MSG, "ModulePath");
133 l = FALSE;
134 str = val.str;
135 if (ptr->file_modulepath == NULL)
137 ptr->file_modulepath = xf86confmalloc (1);
138 ptr->file_modulepath[0] = '\0';
139 k = strlen (str) + 1;
141 else
143 k = strlen (ptr->file_modulepath) + strlen (str) + 1;
144 if (ptr->file_modulepath[strlen (ptr->file_modulepath) - 1] != ',')
146 k++;
147 l = TRUE;
150 ptr->file_modulepath = xf86confrealloc (ptr->file_modulepath, k);
151 if (l)
152 strcat (ptr->file_modulepath, ",");
154 strcat (ptr->file_modulepath, str);
155 xf86conffree (val.str);
156 break;
157 case INPUTDEVICES:
158 if (xf86getSubToken (&(ptr->file_comment)) != STRING)
159 Error (QUOTE_MSG, "InputDevices");
160 l = FALSE;
161 str = val.str;
162 if (ptr->file_inputdevs == NULL)
164 ptr->file_inputdevs = xf86confmalloc (1);
165 ptr->file_inputdevs[0] = '\0';
166 k = strlen (str) + 1;
168 else
170 k = strlen (ptr->file_inputdevs) + strlen (str) + 1;
171 if (ptr->file_inputdevs[strlen (ptr->file_inputdevs) - 1] != ',')
173 k++;
174 l = TRUE;
177 ptr->file_inputdevs = xf86confrealloc (ptr->file_inputdevs, k);
178 if (l)
179 strcat (ptr->file_inputdevs, ",");
181 strcat (ptr->file_inputdevs, str);
182 xf86conffree (val.str);
183 break;
184 case LOGFILEPATH:
185 if (xf86getSubToken (&(ptr->file_comment)) != STRING)
186 Error (QUOTE_MSG, "LogFile");
187 ptr->file_logfile = val.str;
188 break;
189 case EOF_TOKEN:
190 Error (UNEXPECTED_EOF_MSG, NULL);
191 break;
192 default:
193 Error (INVALID_KEYWORD_MSG, xf86tokenString ());
194 break;
198 #ifdef DEBUG
199 printf ("File section parsed\n");
200 #endif
202 return ptr;
205 #undef CLEANUP
207 void
208 xf86printFileSection (FILE * cf, XF86ConfFilesPtr ptr)
210 char *p, *s;
212 if (ptr == NULL)
213 return;
215 if (ptr->file_comment)
216 fprintf (cf, "%s", ptr->file_comment);
217 if (ptr->file_logfile)
218 fprintf (cf, "\tLogFile \"%s\"\n", ptr->file_logfile);
219 if (ptr->file_rgbpath)
220 fprintf (cf, "\tRgbPath \"%s\"\n", ptr->file_rgbpath);
221 if (ptr->file_modulepath)
223 s = ptr->file_modulepath;
224 p = index (s, ',');
225 while (p)
227 *p = '\000';
228 fprintf (cf, "\tModulePath \"%s\"\n", s);
229 *p = ',';
230 s = p;
231 s++;
232 p = index (s, ',');
234 fprintf (cf, "\tModulePath \"%s\"\n", s);
236 if (ptr->file_inputdevs)
238 s = ptr->file_inputdevs;
239 p = index (s, ',');
240 while (p)
242 *p = '\000';
243 fprintf (cf, "\tInputDevices \"%s\"\n", s);
244 *p = ',';
245 s = p;
246 s++;
247 p = index (s, ',');
249 fprintf (cf, "\tInputDevices \"%s\"\n", s);
251 if (ptr->file_fontpath)
253 s = ptr->file_fontpath;
254 p = index (s, ',');
255 while (p)
257 *p = '\000';
258 fprintf (cf, "\tFontPath \"%s\"\n", s);
259 *p = ',';
260 s = p;
261 s++;
262 p = index (s, ',');
264 fprintf (cf, "\tFontPath \"%s\"\n", s);
268 void
269 xf86freeFiles (XF86ConfFilesPtr p)
271 if (p == NULL)
272 return;
274 TestFree (p->file_logfile);
275 TestFree (p->file_rgbpath);
276 TestFree (p->file_modulepath);
277 TestFree (p->file_inputdevs);
278 TestFree (p->file_fontpath);
279 TestFree (p->file_comment);
281 xf86conffree (p);