xref: /OK3568_Linux_fs/external/xserver/hw/xfree86/parser/Files.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /*
2*4882a593Smuzhiyun  * Copyright (c) 1997  Metro Link Incorporated
3*4882a593Smuzhiyun  *
4*4882a593Smuzhiyun  * Permission is hereby granted, free of charge, to any person obtaining a
5*4882a593Smuzhiyun  * copy of this software and associated documentation files (the "Software"),
6*4882a593Smuzhiyun  * to deal in the Software without restriction, including without limitation
7*4882a593Smuzhiyun  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8*4882a593Smuzhiyun  * and/or sell copies of the Software, and to permit persons to whom the
9*4882a593Smuzhiyun  * Software is furnished to do so, subject to the following conditions:
10*4882a593Smuzhiyun  *
11*4882a593Smuzhiyun  * The above copyright notice and this permission notice shall be included in
12*4882a593Smuzhiyun  * all copies or substantial portions of the Software.
13*4882a593Smuzhiyun  *
14*4882a593Smuzhiyun  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15*4882a593Smuzhiyun  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16*4882a593Smuzhiyun  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
17*4882a593Smuzhiyun  * THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
18*4882a593Smuzhiyun  * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
19*4882a593Smuzhiyun  * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20*4882a593Smuzhiyun  * SOFTWARE.
21*4882a593Smuzhiyun  *
22*4882a593Smuzhiyun  * Except as contained in this notice, the name of the Metro Link shall not be
23*4882a593Smuzhiyun  * used in advertising or otherwise to promote the sale, use or other dealings
24*4882a593Smuzhiyun  * in this Software without prior written authorization from Metro Link.
25*4882a593Smuzhiyun  *
26*4882a593Smuzhiyun  */
27*4882a593Smuzhiyun /*
28*4882a593Smuzhiyun  * Copyright (c) 1997-2003 by The XFree86 Project, Inc.
29*4882a593Smuzhiyun  *
30*4882a593Smuzhiyun  * Permission is hereby granted, free of charge, to any person obtaining a
31*4882a593Smuzhiyun  * copy of this software and associated documentation files (the "Software"),
32*4882a593Smuzhiyun  * to deal in the Software without restriction, including without limitation
33*4882a593Smuzhiyun  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
34*4882a593Smuzhiyun  * and/or sell copies of the Software, and to permit persons to whom the
35*4882a593Smuzhiyun  * Software is furnished to do so, subject to the following conditions:
36*4882a593Smuzhiyun  *
37*4882a593Smuzhiyun  * The above copyright notice and this permission notice shall be included in
38*4882a593Smuzhiyun  * all copies or substantial portions of the Software.
39*4882a593Smuzhiyun  *
40*4882a593Smuzhiyun  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
41*4882a593Smuzhiyun  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
42*4882a593Smuzhiyun  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
43*4882a593Smuzhiyun  * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
44*4882a593Smuzhiyun  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
45*4882a593Smuzhiyun  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
46*4882a593Smuzhiyun  * OTHER DEALINGS IN THE SOFTWARE.
47*4882a593Smuzhiyun  *
48*4882a593Smuzhiyun  * Except as contained in this notice, the name of the copyright holder(s)
49*4882a593Smuzhiyun  * and author(s) shall not be used in advertising or otherwise to promote
50*4882a593Smuzhiyun  * the sale, use or other dealings in this Software without prior written
51*4882a593Smuzhiyun  * authorization from the copyright holder(s) and author(s).
52*4882a593Smuzhiyun  */
53*4882a593Smuzhiyun 
54*4882a593Smuzhiyun #ifdef HAVE_XORG_CONFIG_H
55*4882a593Smuzhiyun #include <xorg-config.h>
56*4882a593Smuzhiyun #endif
57*4882a593Smuzhiyun 
58*4882a593Smuzhiyun #include <X11/Xos.h>
59*4882a593Smuzhiyun #include "xf86Parser.h"
60*4882a593Smuzhiyun #include "xf86tokens.h"
61*4882a593Smuzhiyun #include "Configint.h"
62*4882a593Smuzhiyun 
63*4882a593Smuzhiyun 
64*4882a593Smuzhiyun static const xf86ConfigSymTabRec FilesTab[] = {
65*4882a593Smuzhiyun     {ENDSECTION, "endsection"},
66*4882a593Smuzhiyun     {FONTPATH, "fontpath"},
67*4882a593Smuzhiyun     {MODULEPATH, "modulepath"},
68*4882a593Smuzhiyun     {LOGFILEPATH, "logfile"},
69*4882a593Smuzhiyun     {XKBDIR, "xkbdir"},
70*4882a593Smuzhiyun     /* Obsolete keywords that aren't used but shouldn't cause errors: */
71*4882a593Smuzhiyun     {OBSOLETE_TOKEN, "rgbpath"},
72*4882a593Smuzhiyun     {OBSOLETE_TOKEN, "inputdevices"},
73*4882a593Smuzhiyun     {-1, ""},
74*4882a593Smuzhiyun };
75*4882a593Smuzhiyun 
76*4882a593Smuzhiyun #define CLEANUP xf86freeFiles
77*4882a593Smuzhiyun 
78*4882a593Smuzhiyun XF86ConfFilesPtr
xf86parseFilesSection(void)79*4882a593Smuzhiyun xf86parseFilesSection(void)
80*4882a593Smuzhiyun {
81*4882a593Smuzhiyun     int i, j;
82*4882a593Smuzhiyun     int k, l;
83*4882a593Smuzhiyun     char *str;
84*4882a593Smuzhiyun     int token;
85*4882a593Smuzhiyun 
86*4882a593Smuzhiyun     parsePrologue(XF86ConfFilesPtr, XF86ConfFilesRec)
87*4882a593Smuzhiyun 
88*4882a593Smuzhiyun         while ((token = xf86getToken(FilesTab)) != ENDSECTION) {
89*4882a593Smuzhiyun         switch (token) {
90*4882a593Smuzhiyun         case COMMENT:
91*4882a593Smuzhiyun             ptr->file_comment = xf86addComment(ptr->file_comment, xf86_lex_val.str);
92*4882a593Smuzhiyun             break;
93*4882a593Smuzhiyun         case FONTPATH:
94*4882a593Smuzhiyun             if (xf86getSubToken(&(ptr->file_comment)) != STRING)
95*4882a593Smuzhiyun                 Error(QUOTE_MSG, "FontPath");
96*4882a593Smuzhiyun             j = FALSE;
97*4882a593Smuzhiyun             str = xf86_lex_val.str;
98*4882a593Smuzhiyun             if (ptr->file_fontpath == NULL) {
99*4882a593Smuzhiyun                 ptr->file_fontpath = calloc(1, 1);
100*4882a593Smuzhiyun                 i = strlen(str) + 1;
101*4882a593Smuzhiyun             }
102*4882a593Smuzhiyun             else {
103*4882a593Smuzhiyun                 i = strlen(ptr->file_fontpath) + strlen(str) + 1;
104*4882a593Smuzhiyun                 if (ptr->file_fontpath[strlen(ptr->file_fontpath) - 1] != ',') {
105*4882a593Smuzhiyun                     i++;
106*4882a593Smuzhiyun                     j = TRUE;
107*4882a593Smuzhiyun                 }
108*4882a593Smuzhiyun             }
109*4882a593Smuzhiyun             ptr->file_fontpath = realloc(ptr->file_fontpath, i);
110*4882a593Smuzhiyun             if (j)
111*4882a593Smuzhiyun                 strcat(ptr->file_fontpath, ",");
112*4882a593Smuzhiyun 
113*4882a593Smuzhiyun             strcat(ptr->file_fontpath, str);
114*4882a593Smuzhiyun             free(xf86_lex_val.str);
115*4882a593Smuzhiyun             break;
116*4882a593Smuzhiyun         case MODULEPATH:
117*4882a593Smuzhiyun             if (xf86getSubToken(&(ptr->file_comment)) != STRING)
118*4882a593Smuzhiyun                 Error(QUOTE_MSG, "ModulePath");
119*4882a593Smuzhiyun             l = FALSE;
120*4882a593Smuzhiyun             str = xf86_lex_val.str;
121*4882a593Smuzhiyun             if (ptr->file_modulepath == NULL) {
122*4882a593Smuzhiyun                 ptr->file_modulepath = malloc(1);
123*4882a593Smuzhiyun                 ptr->file_modulepath[0] = '\0';
124*4882a593Smuzhiyun                 k = strlen(str) + 1;
125*4882a593Smuzhiyun             }
126*4882a593Smuzhiyun             else {
127*4882a593Smuzhiyun                 k = strlen(ptr->file_modulepath) + strlen(str) + 1;
128*4882a593Smuzhiyun                 if (ptr->file_modulepath[strlen(ptr->file_modulepath) - 1] !=
129*4882a593Smuzhiyun                     ',') {
130*4882a593Smuzhiyun                     k++;
131*4882a593Smuzhiyun                     l = TRUE;
132*4882a593Smuzhiyun                 }
133*4882a593Smuzhiyun             }
134*4882a593Smuzhiyun             ptr->file_modulepath = realloc(ptr->file_modulepath, k);
135*4882a593Smuzhiyun             if (l)
136*4882a593Smuzhiyun                 strcat(ptr->file_modulepath, ",");
137*4882a593Smuzhiyun 
138*4882a593Smuzhiyun             strcat(ptr->file_modulepath, str);
139*4882a593Smuzhiyun             free(xf86_lex_val.str);
140*4882a593Smuzhiyun             break;
141*4882a593Smuzhiyun         case LOGFILEPATH:
142*4882a593Smuzhiyun             if (xf86getSubToken(&(ptr->file_comment)) != STRING)
143*4882a593Smuzhiyun                 Error(QUOTE_MSG, "LogFile");
144*4882a593Smuzhiyun             ptr->file_logfile = xf86_lex_val.str;
145*4882a593Smuzhiyun             break;
146*4882a593Smuzhiyun         case XKBDIR:
147*4882a593Smuzhiyun             if (xf86getSubToken(&(ptr->file_xkbdir)) != STRING)
148*4882a593Smuzhiyun                 Error(QUOTE_MSG, "XkbDir");
149*4882a593Smuzhiyun             ptr->file_xkbdir = xf86_lex_val.str;
150*4882a593Smuzhiyun             break;
151*4882a593Smuzhiyun         case EOF_TOKEN:
152*4882a593Smuzhiyun             Error(UNEXPECTED_EOF_MSG);
153*4882a593Smuzhiyun             break;
154*4882a593Smuzhiyun         case OBSOLETE_TOKEN:
155*4882a593Smuzhiyun             xf86parseError(OBSOLETE_MSG, xf86tokenString());
156*4882a593Smuzhiyun             xf86getSubToken(&(ptr->file_comment));
157*4882a593Smuzhiyun             break;
158*4882a593Smuzhiyun         default:
159*4882a593Smuzhiyun             Error(INVALID_KEYWORD_MSG, xf86tokenString());
160*4882a593Smuzhiyun             break;
161*4882a593Smuzhiyun         }
162*4882a593Smuzhiyun     }
163*4882a593Smuzhiyun 
164*4882a593Smuzhiyun #ifdef DEBUG
165*4882a593Smuzhiyun     printf("File section parsed\n");
166*4882a593Smuzhiyun #endif
167*4882a593Smuzhiyun 
168*4882a593Smuzhiyun     return ptr;
169*4882a593Smuzhiyun }
170*4882a593Smuzhiyun 
171*4882a593Smuzhiyun #undef CLEANUP
172*4882a593Smuzhiyun 
173*4882a593Smuzhiyun void
xf86printFileSection(FILE * cf,XF86ConfFilesPtr ptr)174*4882a593Smuzhiyun xf86printFileSection(FILE * cf, XF86ConfFilesPtr ptr)
175*4882a593Smuzhiyun {
176*4882a593Smuzhiyun     char *p, *s;
177*4882a593Smuzhiyun 
178*4882a593Smuzhiyun     if (ptr == NULL)
179*4882a593Smuzhiyun         return;
180*4882a593Smuzhiyun 
181*4882a593Smuzhiyun     if (ptr->file_comment)
182*4882a593Smuzhiyun         fprintf(cf, "%s", ptr->file_comment);
183*4882a593Smuzhiyun     if (ptr->file_logfile)
184*4882a593Smuzhiyun         fprintf(cf, "\tLogFile      \"%s\"\n", ptr->file_logfile);
185*4882a593Smuzhiyun     if (ptr->file_modulepath) {
186*4882a593Smuzhiyun         s = ptr->file_modulepath;
187*4882a593Smuzhiyun         p = index(s, ',');
188*4882a593Smuzhiyun         while (p) {
189*4882a593Smuzhiyun             *p = '\000';
190*4882a593Smuzhiyun             fprintf(cf, "\tModulePath   \"%s\"\n", s);
191*4882a593Smuzhiyun             *p = ',';
192*4882a593Smuzhiyun             s = p;
193*4882a593Smuzhiyun             s++;
194*4882a593Smuzhiyun             p = index(s, ',');
195*4882a593Smuzhiyun         }
196*4882a593Smuzhiyun         fprintf(cf, "\tModulePath   \"%s\"\n", s);
197*4882a593Smuzhiyun     }
198*4882a593Smuzhiyun     if (ptr->file_fontpath) {
199*4882a593Smuzhiyun         s = ptr->file_fontpath;
200*4882a593Smuzhiyun         p = index(s, ',');
201*4882a593Smuzhiyun         while (p) {
202*4882a593Smuzhiyun             *p = '\000';
203*4882a593Smuzhiyun             fprintf(cf, "\tFontPath     \"%s\"\n", s);
204*4882a593Smuzhiyun             *p = ',';
205*4882a593Smuzhiyun             s = p;
206*4882a593Smuzhiyun             s++;
207*4882a593Smuzhiyun             p = index(s, ',');
208*4882a593Smuzhiyun         }
209*4882a593Smuzhiyun         fprintf(cf, "\tFontPath     \"%s\"\n", s);
210*4882a593Smuzhiyun     }
211*4882a593Smuzhiyun     if (ptr->file_xkbdir)
212*4882a593Smuzhiyun         fprintf(cf, "\tXkbDir		\"%s\"\n", ptr->file_xkbdir);
213*4882a593Smuzhiyun }
214*4882a593Smuzhiyun 
215*4882a593Smuzhiyun void
xf86freeFiles(XF86ConfFilesPtr p)216*4882a593Smuzhiyun xf86freeFiles(XF86ConfFilesPtr p)
217*4882a593Smuzhiyun {
218*4882a593Smuzhiyun     if (p == NULL)
219*4882a593Smuzhiyun         return;
220*4882a593Smuzhiyun 
221*4882a593Smuzhiyun     TestFree(p->file_logfile);
222*4882a593Smuzhiyun     TestFree(p->file_modulepath);
223*4882a593Smuzhiyun     TestFree(p->file_fontpath);
224*4882a593Smuzhiyun     TestFree(p->file_comment);
225*4882a593Smuzhiyun     TestFree(p->file_xkbdir);
226*4882a593Smuzhiyun 
227*4882a593Smuzhiyun     free(p);
228*4882a593Smuzhiyun }
229