Imported Upstream version 1.15.1
[deb_xorg-server.git] / hw / xfree86 / parser / Files.c
CommitLineData
a09e091a
JB
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:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
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.
21 *
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.
25 *
26 */
27/*
28 * Copyright (c) 1997-2003 by The XFree86 Project, Inc.
29 *
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:
36 *
37 * The above copyright notice and this permission notice shall be included in
38 * all copies or substantial portions of the Software.
39 *
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.
47 *
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).
52 */
53
54#ifdef HAVE_XORG_CONFIG_H
55#include <xorg-config.h>
56#endif
57
58#include <X11/Xos.h>
59#include "xf86Parser.h"
60#include "xf86tokens.h"
61#include "Configint.h"
62
63extern LexRec val;
64
65static xf86ConfigSymTabRec FilesTab[] = {
66 {ENDSECTION, "endsection"},
67 {FONTPATH, "fontpath"},
68 {MODULEPATH, "modulepath"},
69 {LOGFILEPATH, "logfile"},
70 {XKBDIR, "xkbdir"},
71 /* Obsolete keywords that aren't used but shouldn't cause errors: */
72 {OBSOLETE_TOKEN, "rgbpath"},
73 {OBSOLETE_TOKEN, "inputdevices"},
74 {-1, ""},
75};
76
77#define CLEANUP xf86freeFiles
78
79XF86ConfFilesPtr
80xf86parseFilesSection(void)
81{
82 int i, j;
83 int k, l;
84 char *str;
85 int token;
86
87 parsePrologue(XF86ConfFilesPtr, XF86ConfFilesRec)
88
89 while ((token = xf86getToken(FilesTab)) != ENDSECTION) {
90 switch (token) {
91 case COMMENT:
92 ptr->file_comment = xf86addComment(ptr->file_comment, val.str);
93 break;
94 case FONTPATH:
95 if (xf86getSubToken(&(ptr->file_comment)) != STRING)
96 Error(QUOTE_MSG, "FontPath");
97 j = FALSE;
98 str = val.str;
99 if (ptr->file_fontpath == NULL) {
100 ptr->file_fontpath = malloc(1);
101 ptr->file_fontpath[0] = '\0';
102 i = strlen(str) + 1;
103 }
104 else {
105 i = strlen(ptr->file_fontpath) + strlen(str) + 1;
106 if (ptr->file_fontpath[strlen(ptr->file_fontpath) - 1] != ',') {
107 i++;
108 j = TRUE;
109 }
110 }
111 ptr->file_fontpath = realloc(ptr->file_fontpath, i);
112 if (j)
113 strcat(ptr->file_fontpath, ",");
114
115 strcat(ptr->file_fontpath, str);
116 free(val.str);
117 break;
118 case MODULEPATH:
119 if (xf86getSubToken(&(ptr->file_comment)) != STRING)
120 Error(QUOTE_MSG, "ModulePath");
121 l = FALSE;
122 str = val.str;
123 if (ptr->file_modulepath == NULL) {
124 ptr->file_modulepath = malloc(1);
125 ptr->file_modulepath[0] = '\0';
126 k = strlen(str) + 1;
127 }
128 else {
129 k = strlen(ptr->file_modulepath) + strlen(str) + 1;
130 if (ptr->file_modulepath[strlen(ptr->file_modulepath) - 1] !=
131 ',') {
132 k++;
133 l = TRUE;
134 }
135 }
136 ptr->file_modulepath = realloc(ptr->file_modulepath, k);
137 if (l)
138 strcat(ptr->file_modulepath, ",");
139
140 strcat(ptr->file_modulepath, str);
141 free(val.str);
142 break;
143 case LOGFILEPATH:
144 if (xf86getSubToken(&(ptr->file_comment)) != STRING)
145 Error(QUOTE_MSG, "LogFile");
146 ptr->file_logfile = val.str;
147 break;
148 case XKBDIR:
149 if (xf86getSubToken(&(ptr->file_xkbdir)) != STRING)
150 Error(QUOTE_MSG, "XkbDir");
151 ptr->file_xkbdir = val.str;
152 break;
153 case EOF_TOKEN:
154 Error(UNEXPECTED_EOF_MSG);
155 break;
156 case OBSOLETE_TOKEN:
157 xf86parseError(OBSOLETE_MSG, xf86tokenString());
158 xf86getSubToken(&(ptr->file_comment));
159 break;
160 default:
161 Error(INVALID_KEYWORD_MSG, xf86tokenString());
162 break;
163 }
164 }
165
166#ifdef DEBUG
167 printf("File section parsed\n");
168#endif
169
170 return ptr;
171}
172
173#undef CLEANUP
174
175void
176xf86printFileSection(FILE * cf, XF86ConfFilesPtr ptr)
177{
178 char *p, *s;
179
180 if (ptr == NULL)
181 return;
182
183 if (ptr->file_comment)
184 fprintf(cf, "%s", ptr->file_comment);
185 if (ptr->file_logfile)
186 fprintf(cf, "\tLogFile \"%s\"\n", ptr->file_logfile);
187 if (ptr->file_modulepath) {
188 s = ptr->file_modulepath;
189 p = index(s, ',');
190 while (p) {
191 *p = '\000';
192 fprintf(cf, "\tModulePath \"%s\"\n", s);
193 *p = ',';
194 s = p;
195 s++;
196 p = index(s, ',');
197 }
198 fprintf(cf, "\tModulePath \"%s\"\n", s);
199 }
200 if (ptr->file_fontpath) {
201 s = ptr->file_fontpath;
202 p = index(s, ',');
203 while (p) {
204 *p = '\000';
205 fprintf(cf, "\tFontPath \"%s\"\n", s);
206 *p = ',';
207 s = p;
208 s++;
209 p = index(s, ',');
210 }
211 fprintf(cf, "\tFontPath \"%s\"\n", s);
212 }
213 if (ptr->file_xkbdir)
214 fprintf(cf, "\tXkbDir \"%s\"\n", ptr->file_xkbdir);
215}
216
217void
218xf86freeFiles(XF86ConfFilesPtr p)
219{
220 if (p == NULL)
221 return;
222
223 TestFree(p->file_logfile);
224 TestFree(p->file_modulepath);
225 TestFree(p->file_fontpath);
226 TestFree(p->file_comment);
227 TestFree(p->file_xkbdir);
228
229 free(p);
230}