1706f2543Smrg/*
2706f2543Smrg * Copyright (c) 1997  Metro Link Incorporated
3706f2543Smrg *
4706f2543Smrg * Permission is hereby granted, free of charge, to any person obtaining a
5706f2543Smrg * copy of this software and associated documentation files (the "Software"),
6706f2543Smrg * to deal in the Software without restriction, including without limitation
7706f2543Smrg * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8706f2543Smrg * and/or sell copies of the Software, and to permit persons to whom the
9706f2543Smrg * Software is furnished to do so, subject to the following conditions:
10706f2543Smrg *
11706f2543Smrg * The above copyright notice and this permission notice shall be included in
12706f2543Smrg * all copies or substantial portions of the Software.
13706f2543Smrg *
14706f2543Smrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15706f2543Smrg * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16706f2543Smrg * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
17706f2543Smrg * THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
18706f2543Smrg * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
19706f2543Smrg * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20706f2543Smrg * SOFTWARE.
21706f2543Smrg *
22706f2543Smrg * Except as contained in this notice, the name of the Metro Link shall not be
23706f2543Smrg * used in advertising or otherwise to promote the sale, use or other dealings
24706f2543Smrg * in this Software without prior written authorization from Metro Link.
25706f2543Smrg *
26706f2543Smrg */
27706f2543Smrg/*
28706f2543Smrg * Copyright (c) 1997-2003 by The XFree86 Project, Inc.
29706f2543Smrg *
30706f2543Smrg * Permission is hereby granted, free of charge, to any person obtaining a
31706f2543Smrg * copy of this software and associated documentation files (the "Software"),
32706f2543Smrg * to deal in the Software without restriction, including without limitation
33706f2543Smrg * the rights to use, copy, modify, merge, publish, distribute, sublicense,
34706f2543Smrg * and/or sell copies of the Software, and to permit persons to whom the
35706f2543Smrg * Software is furnished to do so, subject to the following conditions:
36706f2543Smrg *
37706f2543Smrg * The above copyright notice and this permission notice shall be included in
38706f2543Smrg * all copies or substantial portions of the Software.
39706f2543Smrg *
40706f2543Smrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
41706f2543Smrg * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
42706f2543Smrg * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
43706f2543Smrg * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
44706f2543Smrg * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
45706f2543Smrg * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
46706f2543Smrg * OTHER DEALINGS IN THE SOFTWARE.
47706f2543Smrg *
48706f2543Smrg * Except as contained in this notice, the name of the copyright holder(s)
49706f2543Smrg * and author(s) shall not be used in advertising or otherwise to promote
50706f2543Smrg * the sale, use or other dealings in this Software without prior written
51706f2543Smrg * authorization from the copyright holder(s) and author(s).
52706f2543Smrg */
53706f2543Smrg
54706f2543Smrg
55706f2543Smrg/* View/edit this file with tab stops set to 4 */
56706f2543Smrg
57706f2543Smrg#ifdef HAVE_XORG_CONFIG_H
58706f2543Smrg#include <xorg-config.h>
59706f2543Smrg#endif
60706f2543Smrg
61706f2543Smrg#include <X11/Xos.h>
62706f2543Smrg#include "xf86Parser.h"
63706f2543Smrg#include "xf86tokens.h"
64706f2543Smrg#include "Configint.h"
65706f2543Smrg
66706f2543Smrgextern LexRec val;
67706f2543Smrg
68706f2543Smrgstatic xf86ConfigSymTabRec FilesTab[] =
69706f2543Smrg{
70706f2543Smrg	{ENDSECTION, "endsection"},
71706f2543Smrg	{FONTPATH, "fontpath"},
72706f2543Smrg	{MODULEPATH, "modulepath"},
73706f2543Smrg	{LOGFILEPATH, "logfile"},
74706f2543Smrg	{XKBDIR, "xkbdir"},
75706f2543Smrg	/* Obsolete keywords that aren't used but shouldn't cause errors: */
76706f2543Smrg	{OBSOLETE_TOKEN, "rgbpath"},
77706f2543Smrg	{OBSOLETE_TOKEN, "inputdevices"},
78706f2543Smrg	{-1, ""},
79706f2543Smrg};
80706f2543Smrg
81706f2543Smrg#define CLEANUP xf86freeFiles
82706f2543Smrg
83706f2543SmrgXF86ConfFilesPtr
84706f2543Smrgxf86parseFilesSection (void)
85706f2543Smrg{
86706f2543Smrg	int i, j;
87706f2543Smrg	int k, l;
88706f2543Smrg	char *str;
89706f2543Smrg	int token;
90706f2543Smrg	parsePrologue (XF86ConfFilesPtr, XF86ConfFilesRec)
91706f2543Smrg
92706f2543Smrg	while ((token = xf86getToken (FilesTab)) != ENDSECTION)
93706f2543Smrg	{
94706f2543Smrg		switch (token)
95706f2543Smrg		{
96706f2543Smrg		case COMMENT:
97706f2543Smrg			ptr->file_comment = xf86addComment(ptr->file_comment, val.str);
98706f2543Smrg			break;
99706f2543Smrg		case FONTPATH:
100706f2543Smrg			if (xf86getSubToken (&(ptr->file_comment)) != STRING)
101706f2543Smrg				Error (QUOTE_MSG, "FontPath");
102706f2543Smrg			j = FALSE;
103706f2543Smrg			str = val.str;
104706f2543Smrg			if (ptr->file_fontpath == NULL)
105706f2543Smrg			{
106706f2543Smrg				ptr->file_fontpath = malloc (1);
107706f2543Smrg				ptr->file_fontpath[0] = '\0';
108706f2543Smrg				i = strlen (str) + 1;
109706f2543Smrg			}
110706f2543Smrg			else
111706f2543Smrg			{
112706f2543Smrg				i = strlen (ptr->file_fontpath) + strlen (str) + 1;
113706f2543Smrg				if (ptr->file_fontpath[strlen (ptr->file_fontpath) - 1] != ',')
114706f2543Smrg				{
115706f2543Smrg					i++;
116706f2543Smrg					j = TRUE;
117706f2543Smrg				}
118706f2543Smrg			}
119706f2543Smrg			ptr->file_fontpath =
120706f2543Smrg				realloc (ptr->file_fontpath, i);
121706f2543Smrg			if (j)
122706f2543Smrg				strcat (ptr->file_fontpath, ",");
123706f2543Smrg
124706f2543Smrg			strcat (ptr->file_fontpath, str);
125706f2543Smrg			free (val.str);
126706f2543Smrg			break;
127706f2543Smrg		case MODULEPATH:
128706f2543Smrg			if (xf86getSubToken (&(ptr->file_comment)) != STRING)
129706f2543Smrg				Error (QUOTE_MSG, "ModulePath");
130706f2543Smrg			l = FALSE;
131706f2543Smrg			str = val.str;
132706f2543Smrg			if (ptr->file_modulepath == NULL)
133706f2543Smrg			{
134706f2543Smrg				ptr->file_modulepath = malloc (1);
135706f2543Smrg				ptr->file_modulepath[0] = '\0';
136706f2543Smrg				k = strlen (str) + 1;
137706f2543Smrg			}
138706f2543Smrg			else
139706f2543Smrg			{
140706f2543Smrg				k = strlen (ptr->file_modulepath) + strlen (str) + 1;
141706f2543Smrg				if (ptr->file_modulepath[strlen (ptr->file_modulepath) - 1] != ',')
142706f2543Smrg				{
143706f2543Smrg					k++;
144706f2543Smrg					l = TRUE;
145706f2543Smrg				}
146706f2543Smrg			}
147706f2543Smrg			ptr->file_modulepath = realloc (ptr->file_modulepath, k);
148706f2543Smrg			if (l)
149706f2543Smrg				strcat (ptr->file_modulepath, ",");
150706f2543Smrg
151706f2543Smrg			strcat (ptr->file_modulepath, str);
152706f2543Smrg			free (val.str);
153706f2543Smrg			break;
154706f2543Smrg		case LOGFILEPATH:
155706f2543Smrg			if (xf86getSubToken (&(ptr->file_comment)) != STRING)
156706f2543Smrg				Error (QUOTE_MSG, "LogFile");
157706f2543Smrg			ptr->file_logfile = val.str;
158706f2543Smrg			break;
159706f2543Smrg		case XKBDIR:
160706f2543Smrg			if (xf86getSubToken (&(ptr->file_xkbdir)) != STRING)
161706f2543Smrg				Error (QUOTE_MSG, "XkbDir");
162706f2543Smrg			ptr->file_xkbdir = val.str;
163706f2543Smrg			break;
164706f2543Smrg		case EOF_TOKEN:
165706f2543Smrg			Error (UNEXPECTED_EOF_MSG, NULL);
166706f2543Smrg			break;
167706f2543Smrg		case OBSOLETE_TOKEN:
168706f2543Smrg			xf86parseError (OBSOLETE_MSG, xf86tokenString ());
169706f2543Smrg			xf86getSubToken (&(ptr->file_comment));
170706f2543Smrg			break;
171706f2543Smrg		default:
172706f2543Smrg			Error (INVALID_KEYWORD_MSG, xf86tokenString ());
173706f2543Smrg			break;
174706f2543Smrg		}
175706f2543Smrg	}
176706f2543Smrg
177706f2543Smrg#ifdef DEBUG
178706f2543Smrg	printf ("File section parsed\n");
179706f2543Smrg#endif
180706f2543Smrg
181706f2543Smrg	return ptr;
182706f2543Smrg}
183706f2543Smrg
184706f2543Smrg#undef CLEANUP
185706f2543Smrg
186706f2543Smrgvoid
187706f2543Smrgxf86printFileSection (FILE * cf, XF86ConfFilesPtr ptr)
188706f2543Smrg{
189706f2543Smrg	char *p, *s;
190706f2543Smrg
191706f2543Smrg	if (ptr == NULL)
192706f2543Smrg		return;
193706f2543Smrg
194706f2543Smrg	if (ptr->file_comment)
195706f2543Smrg		fprintf (cf, "%s", ptr->file_comment);
196706f2543Smrg	if (ptr->file_logfile)
197706f2543Smrg		fprintf (cf, "\tLogFile      \"%s\"\n", ptr->file_logfile);
198706f2543Smrg	if (ptr->file_modulepath)
199706f2543Smrg	{
200706f2543Smrg		s = ptr->file_modulepath;
201706f2543Smrg		p = index (s, ',');
202706f2543Smrg		while (p)
203706f2543Smrg		{
204706f2543Smrg			*p = '\000';
205706f2543Smrg			fprintf (cf, "\tModulePath   \"%s\"\n", s);
206706f2543Smrg			*p = ',';
207706f2543Smrg			s = p;
208706f2543Smrg			s++;
209706f2543Smrg			p = index (s, ',');
210706f2543Smrg		}
211706f2543Smrg		fprintf (cf, "\tModulePath   \"%s\"\n", s);
212706f2543Smrg	}
213706f2543Smrg	if (ptr->file_fontpath)
214706f2543Smrg	{
215706f2543Smrg		s = ptr->file_fontpath;
216706f2543Smrg		p = index (s, ',');
217706f2543Smrg		while (p)
218706f2543Smrg		{
219706f2543Smrg			*p = '\000';
220706f2543Smrg			fprintf (cf, "\tFontPath     \"%s\"\n", s);
221706f2543Smrg			*p = ',';
222706f2543Smrg			s = p;
223706f2543Smrg			s++;
224706f2543Smrg			p = index (s, ',');
225706f2543Smrg		}
226706f2543Smrg		fprintf (cf, "\tFontPath     \"%s\"\n", s);
227706f2543Smrg	}
228706f2543Smrg	if (ptr->file_xkbdir)
229706f2543Smrg		fprintf (cf, "\tXkbDir		\"%s\"\n", ptr->file_xkbdir);
230706f2543Smrg}
231706f2543Smrg
232706f2543Smrgvoid
233706f2543Smrgxf86freeFiles (XF86ConfFilesPtr p)
234706f2543Smrg{
235706f2543Smrg	if (p == NULL)
236706f2543Smrg		return;
237706f2543Smrg
238706f2543Smrg	TestFree (p->file_logfile);
239706f2543Smrg	TestFree (p->file_modulepath);
240706f2543Smrg	TestFree (p->file_fontpath);
241706f2543Smrg	TestFree (p->file_comment);
242706f2543Smrg	TestFree (p->file_xkbdir);
243706f2543Smrg
244706f2543Smrg	free (p);
245706f2543Smrg}
246