--- xf86Parser.h.old 2005-09-30 16:06:18.000000000 -0400 +++ xf86Parser.h 2005-09-30 21:18:57.000000000 -0400 @@ -454,8 +454,8 @@ xf86ConfigSymTabRec, *xf86ConfigSymTabPt /* * prototypes for public functions */ -extern const char *xf86openConfigFile (const char *, const char *, - const char *); +extern FILE *configFile; +extern void xf86openConfigFile(const char *); extern void xf86setBuiltinConfig(const char *config[]); extern XF86ConfigPtr xf86readConfigFile (void); extern void xf86closeConfigFile (void); --- scan.c.old 2005-09-30 18:16:13.000000000 -0400 +++ scan.c 2005-09-30 22:41:33.000000000 -0400 @@ -95,7 +95,7 @@ static int StringToToken (char *, xf86ConfigSymTabRec *); -static FILE *configFile = NULL; +FILE *configFile = NULL; static const char **builtinConfig = NULL; static int builtinIndex = 0; static int configPos = 0; /* current readers position */ @@ -181,9 +181,15 @@ xf86getToken (xf86ConfigSymTabRec * tab) * eol_seen is only set for the first token after a newline. */ eol_seen = 0; + + if (!configBuf) { + configBuf = xf86confmalloc (CONFIG_BUF_LEN); + configBuf[0] = '\0'; /* sanity ... */ + } + if (!configRBuf) + configRBuf = xf86confmalloc (CONFIG_BUF_LEN); c = configBuf[configPos]; - /* * Get start of next Token. EOF is handled, * whitespaces are skipped. @@ -193,7 +199,7 @@ again: if (!c) { char *ret; - if (configFile) + if (configFile) ret = fgets (configBuf, CONFIG_BUF_LEN - 1, configFile); else { if (builtinConfig[builtinIndex] == NULL) @@ -498,265 +504,18 @@ xf86pathIsSafe(const char *path) } \ } while (0) -static char * -DoSubstitution(const char *template, const char *cmdline, const char *projroot, - int *cmdlineUsed, int *envUsed, char *XConfigFile) -{ - char *result; - int i, l; - static const char *env = NULL, *home = NULL; - static char *hostname = NULL; - static char majorvers[3] = ""; -#ifdef __UNIXOS2__ - static char *x11root = NULL; -#endif - - if (!template) - return NULL; - - if (cmdlineUsed) - *cmdlineUsed = 0; - if (envUsed) - *envUsed = 0; - - result = xf86confmalloc(PATH_MAX + 1); - l = 0; - for (i = 0; template[i]; i++) { - if (template[i] != '%') { - result[l++] = template[i]; - CHECK_LENGTH; - } else { - switch (template[++i]) { - case 'A': - if (cmdline && xf86pathIsAbsolute(cmdline)) { - APPEND_STR(cmdline); - if (cmdlineUsed) - *cmdlineUsed = 1; - } else - BAIL_OUT; - break; - case 'R': - if (cmdline && !xf86pathIsAbsolute(cmdline)) { - APPEND_STR(cmdline); - if (cmdlineUsed) - *cmdlineUsed = 1; - } else - BAIL_OUT; - break; - case 'S': - if (cmdline && xf86pathIsSafe(cmdline)) { - APPEND_STR(cmdline); - if (cmdlineUsed) - *cmdlineUsed = 1; - } else - BAIL_OUT; - break; - case 'X': - APPEND_STR(XConfigFile); - break; - case 'H': - if (!hostname) { - if ((hostname = xf86confmalloc(MAXHOSTNAMELEN + 1))) { - if (gethostname(hostname, MAXHOSTNAMELEN) == 0) { - hostname[MAXHOSTNAMELEN] = '\0'; - } else { - xf86conffree(hostname); - hostname = NULL; - } - } - } - if (hostname) - APPEND_STR(hostname); - break; - case 'E': - if (!env) - env = getenv(XCONFENV); - if (env && xf86pathIsAbsolute(env)) { - APPEND_STR(env); - if (envUsed) - *envUsed = 1; - } else - BAIL_OUT; - break; - case 'F': - if (!env) - env = getenv(XCONFENV); - if (env && !xf86pathIsAbsolute(env)) { - APPEND_STR(env); - if (envUsed) - *envUsed = 1; - } else - BAIL_OUT; - break; - case 'G': - if (!env) - env = getenv(XCONFENV); - if (env && xf86pathIsSafe(env)) { - APPEND_STR(env); - if (envUsed) - *envUsed = 1; - } else - BAIL_OUT; - break; - case 'D': - if (!home) - home = getenv("HOME"); - if (home && xf86pathIsAbsolute(home)) - APPEND_STR(home); - else - BAIL_OUT; - break; - case 'P': - if (projroot && xf86pathIsAbsolute(projroot)) - APPEND_STR(projroot); - else - BAIL_OUT; - break; - case 'M': - if (!majorvers[0]) { - if (XF86_VERSION_MAJOR < 0 || XF86_VERSION_MAJOR > 99) { - fprintf(stderr, "XF86_VERSION_MAJOR is out of range\n"); - BAIL_OUT; - } else - sprintf(majorvers, "%d", XF86_VERSION_MAJOR); - } - APPEND_STR(majorvers); - break; - case '%': - result[l++] = '%'; - CHECK_LENGTH; - break; -#ifdef __UNIXOS2__ - case '&': - if (!x11root) - x11root = getenv("X11ROOT"); - if (x11root) - APPEND_STR(x11root); - else - BAIL_OUT; - break; -#endif - default: - fprintf(stderr, "invalid escape %%%c found in path template\n", - template[i]); - BAIL_OUT; - break; - } - } - } -#ifdef DEBUG - fprintf(stderr, "Converted `%s' to `%s'\n", template, result); -#endif - return result; -} - /* * xf86openConfigFile -- - * - * This function take a config file search path (optional), a command-line - * specified file name (optional) and the ProjectRoot path (optional) and - * locates and opens a config file based on that information. If a - * command-line file name is specified, then this function fails if none - * of the located files. - * - * The return value is a pointer to the actual name of the file that was - * opened. When no file is found, the return value is NULL. - * - * The escape sequences allowed in the search path are defined above. - * */ -#ifndef DEFAULT_CONF_PATH -#define DEFAULT_CONF_PATH "/etc/X11/%S," \ - "%P/etc/X11/%S," \ - "/etc/X11/%G," \ - "%P/etc/X11/%G," \ - "/etc/X11/%X-%M," \ - "/etc/X11/%X," \ - "/etc/%X," \ - "%P/etc/X11/%X.%H," \ - "%P/etc/X11/%X-%M," \ - "%P/etc/X11/%X," \ - "%P/lib/X11/%X.%H," \ - "%P/lib/X11/%X-%M," \ - "%P/lib/X11/%X" -#endif - -const char * -xf86openConfigFile(const char *path, const char *cmdline, const char *projroot) -{ - char *pathcopy; - const char *template; - int cmdlineUsed = 0; - - configFile = NULL; - configPos = 0; /* current readers position */ - configLineNo = 0; /* linenumber */ - pushToken = LOCK_TOKEN; - - if (!path || !path[0]) - path = DEFAULT_CONF_PATH; - pathcopy = xf86confmalloc(strlen(path) + 1); - strcpy(pathcopy, path); - if (!projroot || !projroot[0]) - projroot = PROJECTROOT; - - template = strtok(pathcopy, ","); - - /* First, search for a config file. */ - while (template && !configFile) { - if ((configPath = DoSubstitution(template, cmdline, projroot, - &cmdlineUsed, NULL, - XCONFIGFILE))) { - if ((configFile = fopen(configPath, "r")) != 0) { - if (cmdline && !cmdlineUsed) { - fclose(configFile); - configFile = NULL; - } - } - } - if (configPath && !configFile) { - xf86conffree(configPath); - configPath = NULL; - } - template = strtok(NULL, ","); - } - - /* Then search for fallback */ - if (!configFile) { - strcpy(pathcopy, path); - template = strtok(pathcopy, ","); - - while (template && !configFile) { - if ((configPath = DoSubstitution(template, cmdline, projroot, - &cmdlineUsed, NULL, - XFREE86CFGFILE))) { - if ((configFile = fopen(configPath, "r")) != 0) { - if (cmdline && !cmdlineUsed) { - fclose(configFile); - configFile = NULL; - } - } - } - if (configPath && !configFile) { - xf86conffree(configPath); - configPath = NULL; - } - template = strtok(NULL, ","); - } - } - - xf86conffree(pathcopy); - if (!configFile) { - - return NULL; - } +void +xf86openConfigFile(const char *conf) { + if (!configFile) + configFile = fopen(conf, "r"); configBuf = xf86confmalloc (CONFIG_BUF_LEN); configRBuf = xf86confmalloc (CONFIG_BUF_LEN); configBuf[0] = '\0'; /* sanity ... */ - - return configPath; } void