summaryrefslogtreecommitdiff
path: root/hw/xfree86/parser/scan.c
diff options
context:
space:
mode:
Diffstat (limited to 'hw/xfree86/parser/scan.c')
-rw-r--r--hw/xfree86/parser/scan.c281
1 files changed, 63 insertions, 218 deletions
diff --git a/hw/xfree86/parser/scan.c b/hw/xfree86/parser/scan.c
index 4d8167622..4dc2e0dd1 100644
--- a/hw/xfree86/parser/scan.c
+++ b/hw/xfree86/parser/scan.c
@@ -1,4 +1,4 @@
-/* $XFree86: xc/programs/Xserver/hw/xfree86/parser/scan.c,v 1.24 2003/01/04 20:20:23 paulo Exp $ */
+/* $XFree86: xc/programs/Xserver/hw/xfree86/parser/scan.c,v 1.30 2003/11/03 05:11:52 tsi Exp $ */
/*
*
* Copyright (c) 1997 Metro Link Incorporated
@@ -26,6 +26,33 @@
* in this Software without prior written authorization from Metro Link.
*
*/
+/*
+ * Copyright (c) 1997-2003 by The XFree86 Project, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ *
+ * Except as contained in this notice, the name of the copyright holder(s)
+ * and author(s) shall not be used in advertising or otherwise to promote
+ * the sale, use or other dealings in this Software without prior written
+ * authorization from the copyright holder(s) and author(s).
+ */
+
/* View/edit this file with tab stops set to 4 */
@@ -65,7 +92,8 @@
static int StringToToken (char *, xf86ConfigSymTabRec *);
static FILE *configFile = NULL;
-static int configStart = 0; /* start of the current token */
+static const char **builtinConfig = NULL;
+static int builtinIndex = 0;
static int configPos = 0; /* current readers position */
static int configLineNo = 0; /* linenumber */
static char *configBuf, *configRBuf; /* buffer for lines */
@@ -160,12 +188,24 @@ xf86getToken (xf86ConfigSymTabRec * tab)
again:
if (!c)
{
- if (fgets (configBuf, CONFIG_BUF_LEN - 1, configFile) == NULL)
+ char *ret;
+ if (configFile)
+ ret = fgets (configBuf, CONFIG_BUF_LEN - 1, configFile);
+ else {
+ if (builtinConfig[builtinIndex] == NULL)
+ ret = NULL;
+ else {
+ ret = strncpy(configBuf, builtinConfig[builtinIndex],
+ CONFIG_BUF_LEN);
+ builtinIndex++;
+ }
+ }
+ if (ret == NULL)
{
return (pushToken = EOF_TOKEN);
}
configLineNo++;
- configStart = configPos = 0;
+ configPos = 0;
eol_seen = 1;
}
@@ -205,16 +245,13 @@ again:
/* GJA -- handle '-' and ',' * Be careful: "-hsync" is a keyword. */
else if ((c == ',') && !isalpha (configBuf[configPos]))
{
- configStart = configPos;
return COMMA;
}
else if ((c == '-') && !isalpha (configBuf[configPos]))
{
- configStart = configPos;
return DASH;
}
- configStart = configPos;
/*
* Numbers are returned immediately ...
*/
@@ -359,7 +396,6 @@ xf86tokenString (void)
return configRBuf;
}
-#if 1
int
xf86pathIsAbsolute(const char *path)
{
@@ -367,7 +403,7 @@ xf86pathIsAbsolute(const char *path)
return 1;
#ifdef __UNIXOS2__
if (path && (path[0] == '\\' || (path[1] == ':')))
- return 0;
+ return 1;
#endif
return 0;
}
@@ -649,7 +685,6 @@ xf86openConfigFile(const char *path, const char *cmdline, const char *projroot)
int cmdlineUsed = 0;
configFile = NULL;
- configStart = 0; /* start of the current token */
configPos = 0; /* current readers position */
configLineNo = 0; /* linenumber */
pushToken = LOCK_TOKEN;
@@ -692,178 +727,6 @@ xf86openConfigFile(const char *path, const char *cmdline, const char *projroot)
return configPath;
}
-#else
-/*
- * xf86openConfigFile --
- *
- * Formerly findConfigFile(). This function take a pointer to a location
- * in which to place the actual name of the file that was opened.
- * This function uses the global character array xf86ConfigFile
- * This function returns the following results.
- *
- * 0 unable to open the config file
- * 1 file opened and ready to read
- *
- */
-
-int
-xf86openConfigFile (char *filename)
-{
-#define MAXPTRIES 6
- char *home = NULL;
- char *xconfig = NULL;
- char *xwinhome = NULL;
- char *configPaths[MAXPTRIES];
- int pcount = 0, idx;
-
-/*
- * First open if necessary the config file.
- * If the -xf86config flag was used, use the name supplied there (root only).
- * If $XF86CONFIG is a pathname, use it as the name of the config file (root)
- * If $XF86CONFIG is set but doesn't contain a '/', append it to 'XF86Config'
- * and search the standard places (root only).
- * If $XF86CONFIG is not set, just search the standard places.
- */
- configFile = NULL;
- configStart = 0; /* start of the current token */
- configPos = 0; /* current readers position */
- configLineNo = 0; /* linenumber */
- pushToken = LOCK_TOKEN;
- while (!configFile)
- {
-
- /*
- * configPaths[0] is used as a buffer for -xf86config
- * and $XF86CONFIG if it contains a path
- * configPaths[1...MAXPTRIES-1] is used to store the paths of each of
- * the other attempts
- */
- for (pcount = idx = 0; idx < MAXPTRIES; idx++)
- configPaths[idx] = NULL;
-
- /*
- * First check if the -xf86config option was used.
- */
- configPaths[pcount] = xf86confmalloc (PATH_MAX);
- if (xf86ConfigFile[0])
- {
- strcpy (configPaths[pcount], xf86ConfigFile);
- if ((configFile = fopen (configPaths[pcount], "r")) != 0)
- break;
- else
- return 0;
- }
- /*
- * Check if XF86CONFIG is set.
- */
-#ifndef __UNIXOS2__
- if (getuid () == 0
- && (xconfig = getenv ("XF86CONFIG")) != 0
- && strchr (xconfig, '/'))
-#else
- /* no root available, and filenames start with drive letter */
- if ((xconfig = getenv ("XF86CONFIG")) != 0
- && isalpha (xconfig[0])
- && xconfig[1] == ':')
-#endif
- {
- strcpy (configPaths[pcount], xconfig);
- if ((configFile = fopen (configPaths[pcount], "r")) != 0)
- break;
- else
- return 0;
- }
-
-#ifndef __UNIXOS2__
- /*
- * ~/XF86Config ...
- */
- if (getuid () == 0 && (home = getenv ("HOME")) != NULL)
- {
- configPaths[++pcount] = xf86confmalloc (PATH_MAX);
- strcpy (configPaths[pcount], home);
- strcat (configPaths[pcount], "/" XCONFIGFILE);
- if (xconfig)
- strcat (configPaths[pcount], xconfig);
- if ((configFile = fopen (configPaths[pcount], "r")) != 0)
- break;
- }
-
- /*
- * /etc/XF86Config
- */
- configPaths[++pcount] = xf86confmalloc (PATH_MAX);
- strcpy (configPaths[pcount], "/etc/" XCONFIGFILE);
- if (xconfig)
- strcat (configPaths[pcount], xconfig);
- if ((configFile = fopen (configPaths[pcount], "r")) != 0)
- break;
-
- /*
- * $(XCONFIGDIR)/XF86Config.<hostname>
- */
-
- configPaths[++pcount] = xf86confmalloc (PATH_MAX);
- if (getuid () == 0 && (xwinhome = getenv ("XWINHOME")) != NULL)
- sprintf (configPaths[pcount], "%s/lib/X11/" XCONFIGFILE, xwinhome);
- else
- strcpy (configPaths[pcount], XCONFIGDIR "/" XCONFIGFILE);
- if (getuid () == 0 && xconfig)
- strcat (configPaths[pcount], xconfig);
- strcat (configPaths[pcount], ".");
- gethostname (configPaths[pcount] + strlen (configPaths[pcount]),
- MAXHOSTNAMELEN);
- if ((configFile = fopen (configPaths[pcount], "r")) != 0)
- break;
-#endif /* !__UNIXOS2__ */
-
- /*
- * $(XCONFIGDIR)/XF86Config
- */
- configPaths[++pcount] = xf86confmalloc (PATH_MAX);
-#ifndef __UNIXOS2__
- if (getuid () == 0 && xwinhome)
- sprintf (configPaths[pcount], "%s/lib/X11/" XCONFIGFILE, xwinhome);
- else
- strcpy (configPaths[pcount], XCONFIGDIR "/" XCONFIGFILE);
- if (getuid () == 0 && xconfig)
- strcat (configPaths[pcount], xconfig);
-#else
- /*
- * we explicitly forbid numerous config files everywhere for OS/2;
- * users should consider them lucky to have one in a standard place
- * and another one with the -xf86config option
- */
- xwinhome = getenv ("X11ROOT"); /* get drive letter */
- if (!xwinhome) {
- fprintf (stderr,"X11ROOT environment variable not set\n");
- exit(2);
- }
- strcpy (configPaths[pcount], __XOS2RedirRoot ("/XFree86/lib/X11/XConfig"));
-#endif
-
- if ((configFile = fopen (configPaths[pcount], "r")) != 0)
- break;
-
- return 0;
- }
- configBuf = xf86confmalloc (CONFIG_BUF_LEN);
- configRBuf = xf86confmalloc (CONFIG_BUF_LEN);
- configPath = xf86confmalloc (PATH_MAX);
-
- strcpy (configPath, configPaths[pcount]);
-
- if (filename)
- strcpy (filename, configPaths[pcount]);
- for (idx = 0; idx <= pcount; idx++)
- if (configPaths[idx] != NULL)
- xf86conffree (configPaths[idx]);
-
- configBuf[0] = '\0'; /* sanity ... */
-
- return 1;
-}
-#endif
void
xf86closeConfigFile (void)
@@ -875,8 +738,24 @@ xf86closeConfigFile (void)
xf86conffree (configBuf);
configBuf = NULL;
- fclose (configFile);
- configFile = NULL;
+ if (configFile) {
+ fclose (configFile);
+ configFile = NULL;
+ } else {
+ builtinConfig = NULL;
+ builtinIndex = 0;
+ }
+}
+
+void
+xf86setBuiltinConfig(const char *config[])
+{
+ builtinConfig = config;
+ configPath = xf86configStrdup("<builtin configuration>");
+ configBuf = xf86confmalloc (CONFIG_BUF_LEN);
+ configRBuf = xf86confmalloc (CONFIG_BUF_LEN);
+ configBuf[0] = '\0'; /* sanity ... */
+
}
void
@@ -884,16 +763,6 @@ xf86parseError (char *format,...)
{
va_list ap;
-#if 0
- fprintf (stderr, "Parse error on line %d of section %s in file %s\n",
- configLineNo, configSection, configPath);
- fprintf (stderr, "\t");
- va_start (ap, format);
- vfprintf (stderr, format, ap);
- va_end (ap);
-
- fprintf (stderr, "\n");
-#else
ErrorF ("Parse error on line %d of section %s in file %s\n\t",
configLineNo, configSection, configPath);
va_start (ap, format);
@@ -901,8 +770,6 @@ xf86parseError (char *format,...)
va_end (ap);
ErrorF ("\n");
-#endif
-
}
void
@@ -910,16 +777,6 @@ xf86parseWarning (char *format,...)
{
va_list ap;
-#if 0
- fprintf (stderr, "Parse warning on line %d of section %s in file %s\n",
- configLineNo, configSection, configPath);
- fprintf (stderr, "\t");
- va_start (ap, format);
- vfprintf (stderr, format, ap);
- va_end (ap);
-
- fprintf (stderr, "\n");
-#else
ErrorF ("Parse warning on line %d of section %s in file %s\n\t",
configLineNo, configSection, configPath);
va_start (ap, format);
@@ -927,7 +784,6 @@ xf86parseWarning (char *format,...)
va_end (ap);
ErrorF ("\n");
-#endif
}
void
@@ -935,23 +791,12 @@ xf86validationError (char *format,...)
{
va_list ap;
-#if 0
- fprintf (stderr, "Data incomplete in file %s\n",
- configPath);
- fprintf (stderr, "\t");
- va_start (ap, format);
- vfprintf (stderr, format, ap);
- va_end (ap);
-
- fprintf (stderr, "\n");
-#else
ErrorF ("Data incomplete in file %s\n\t", configPath);
va_start (ap, format);
VErrorF (format, ap);
va_end (ap);
ErrorF ("\n");
-#endif
}
void