4917N/A * Copyright (c) 1997 Metro Link Incorporated 4917N/A * Permission is hereby granted, free of charge, to any person obtaining a 4917N/A * copy of this software and associated documentation files (the "Software"), 4917N/A * to deal in the Software without restriction, including without limitation 4917N/A * the rights to use, copy, modify, merge, publish, distribute, sublicense, 4917N/A * and/or sell copies of the Software, and to permit persons to whom the 4917N/A * Software is furnished to do so, subject to the following conditions: 4917N/A * The above copyright notice and this permission notice shall be included in 4917N/A * all copies or substantial portions of the Software. 4917N/A * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 4917N/A * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 4917N/A * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 4917N/A * THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 4917N/A * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF 4917N/A * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 5341N/A * Except as contained in this notice, the name of the Metro Link shall not be 4917N/A * used in advertising or otherwise to promote the sale, use or other dealings 5680N/A * in this Software without prior written authorization from Metro Link. 4917N/A * Copyright (c) 1997-2003 by The XFree86 Project, Inc. 4917N/A * Permission is hereby granted, free of charge, to any person obtaining a 4917N/A * copy of this software and associated documentation files (the "Software"), 4917N/A * to deal in the Software without restriction, including without limitation 4917N/A * the rights to use, copy, modify, merge, publish, distribute, sublicense, 4917N/A * and/or sell copies of the Software, and to permit persons to whom the 4917N/A * Software is furnished to do so, subject to the following conditions: 4917N/A * The above copyright notice and this permission notice shall be included in 4917N/A * all copies or substantial portions of the Software. 4917N/A * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 4917N/A * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 4917N/A * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 4917N/A * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR 4917N/A * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 5680N/A * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 5680N/A * OTHER DEALINGS IN THE SOFTWARE. 5680N/A * Except as contained in this notice, the name of the copyright holder(s) 5680N/A * and author(s) shall not be used in advertising or otherwise to promote 4917N/A * the sale, use or other dealings in this Software without prior written 4917N/A * authorization from the copyright holder(s) and author(s). #
endif /* !MAXHOSTNAMELEN */#
include "xf86Parser.h" /* Public function, etc. declarations */#
include "configProcs.h" /* Private function, etc. declarations */#
include "fbc_line_er.h" /* External Representation of config lines */#
if !
defined(
xf86printErrorF)
/* Could write prog name & variable fmt msg */static int configPos = 0;
/* current readers position */ static char *
configPath;
/* path to config file */ static int eol_seen = 0;
/* private state to handle comments */ * A portable, but restricted, version of strtoul(). It only understands * hex, octal, and decimal. But it's good enough for our needs. if ((*p ==
'x') || (*p ==
'X'))
if ((*p >=
'0') && (*p <= ((
base ==
8) ?
'7' :
'9')))
else if ((
base ==
16) && (*p >=
'a') && (*p <=
'f'))
else if ((
base ==
16) && (*p >=
'A') && (*p <=
'F'))
* Read from the configFile FILE stream until we encounter a newline; * this is a wrapper for fgets(3) that can handle arbitrarily long * Callers, such as xf86getToken(), assume that we will read up to the * next newline; we need to grow configBuf as necessary to support that. * Reallocate the buffer if it was grown last time (i.e., is no * longer CONFIG_BUF_LEN); we malloc the new buffer first, so * that if the malloc() fails, we can fall back to use the * [Might want to wait and shrink the buffer after reading the line.] * The malloc() succeeded; free the old buffer and use /* read in another block of chars */ /* search for EOL in the new block of chars */ if ((c ==
'\n') || (c ==
'\r')) {
* if we didn't find EOL, then grow the buffer and * The reallocation failed; we have to fall * back to the previous configBufLen size and * use the string we have, even though we don't /* reallocation succeeded */ * Read next Token from the config file. Handle the global variable * pushToken. If a pointer to a symbol table has been provided * (tab != NULL), the table may be searched for a match with the * token. If all attempts to recognize the token fail, an * ERROR_TOKEN code is returned. * First check whether pushToken has a different value than LOCK_TOKEN. * Otherwise the next token must be read from the input. * eol_seen is only set for the first token after a newline. * Get start of next Token. EOF is handled, * whitespaces are skipped. * Make the token buffer the same size as the input line * buffer. We malloc() the new token buffer first, so * that if the malloc() fails, we can fall back to use the * The malloc() succeeded; free the old buffer * and use the new buffer. * Start scanning the new token, which may include whitespace goto again;
/* [Should be a do-while loop] */ while ((c !=
'\n') && (c !=
'\r') && (c !=
'\0'));
* Use xf86addComment when setting a comment. /* GJA -- handle '-' and ',' * Be careful: "-hsync" is a keyword. */ * Numbers are returned immediately ... (c ==
'.') || (c ==
'x') || (c ==
'X') ||
((
base ==
16) && (((c >=
'a') && (c <=
'f')) ||
((c >=
'A') && (c <=
'F')))))
* All Strings START with a \" ... while ((c !=
'\"') && (c !=
'\n') && (c !=
'\r') && (c !=
'\0'));
* ... and now we MUST have a valid token. The search is * handled later along with the pushed tokens. while ((c !=
' ') && (c !=
'\t') && (c !=
'\n') && (c !=
'\r') && (c !=
'\0') && (c !=
'#'));
* Here we deal with pushed tokens. Reinitialize pushToken again. If * the pushed token was NUMBER || STRING return them again ... * Joop, at last we have to lookup the token ... * Read tokens from the configuration file until a non-COMMENT * token is encountered. No symbol table is provided for token * lookup. Unless no comment pointer is provided by the caller, * append any COMMENT text to the dynamically grown string of * comments. Return the code for the non-COMMENT token. * xf86getSubTokenWithTab() * Read tokens from the configuration file until a non-COMMENT * token is encountered. A symbol table is provided for token * lookup. Unless no comment pointer is provided by the caller, * append any COMMENT text to the dynamically grown string of * comments. Return the code for the non-COMMENT token. /* A path is "safe" if it is relative and if it contains no ".." elements. */ /* Look for leading "../" */ /* Look for trailing "/.." */ * This function substitutes the following escape sequences: * %A cmdline argument as an absolute path (must be absolute to match) * %R cmdline argument as a relative path * %S cmdline argument as a "safe" path (relative, and no ".." elements) * %E config file environment ($XORGCONFIG) as an absolute path * %F config file environment ($XORGCONFIG) as a relative path * %G config file environment ($XORGCONFIG) as a safe path * %M major version number * %& UNIXOS2 only: prepend X11ROOT env var * This function takes 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. This * function will fail if a command-line file name is specified and there * is no %A, %R, or %S escape sequence in the effective search path. * 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. The * default search path is defined below. const char *
path,
/* Search path, else NULL */ const char *
cmdline,
/* File path (%A,%R,%S), else NULL */ const char *
projroot)
/* Project root path (%P), else NULL */ const char *
const Xfile[] = {
};
/* Substitutions for %X */ const char *
const *
XConfigFile;
/* Ptr to current %X filename */ /* Initialize global variables for the scanner */ configPos = 0;
/* Index of current char in line buf */ configBuf[0] =
'\0';
/* Start with an empty line buffer */ /* Be sure there's a non-empty search path and a scratch buffer */ /* Be sure there's a non-empty project root to substitute for %P */ /* Repeat for each config filename that can be substituted for %X */ /* Repeat for each comma-separated pathname template */ /* Construct a config pathname from the template */ continue;
/* No memory */ /* Open the path unless a provided name wasn't used */ /* Discard the failed config pathname */ * This function takes 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. This * function will fail if a command-line file name is specified and there * is no %A, %R, or %S escape sequence in the effective search path. * 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. const char *
configPath;
/* Config file pathname, else NULL */ configBuf[0] =
'\0';
/* Start with an empty line buffer */ * Release all dynamically allocated memory used to scan the * Release all dynamically allocated memory used to scan the * configuration file. Close the input configuration file, else * discard the in-memory configuration text. * Lookup a string if it is actually a token in disguise. * xf86nameCompareResumable() * Compare two name-like strings pointed to by s1 and s2. Ignore * alphabetic case and the characters, '_', ' ', and '\t'. If s2 * matches the initial characters of s1 then return a pointer to the * next character of s1 via s1resume (where further comparison could * be resumed). Otherwise return NULL via s1resume. Return the * conventional negative, zero, or positive value to indicate the * result of the basic comparison. int c1;
/* Normalized character from s1 */ int c2;
/* Normalized character from s2 */ *
s1resume =
NULL;
/* Comparison has no resumption point yet */ return (-
1);
/* Behave as if NULL < non-NULL */ return (
1);
/* Behave as if non-NULL > NULL */ while ((*
s1 ==
'_') || (*
s1 ==
' ') || (*
s1 ==
'\t')) {
while ((*
s2 ==
'_') || (*
s2 ==
' ') || (*
s2 ==
'\t')) {
/* s1 matches s2 or contains s2 as a prefix */ * The strings don't match * Compare two name-like strings pointed to by s1 and s2. Ignore * alphabetic case and the characters, '_', ' ', and '\t'. Return * the conventional negative, zero, or positive value to indicate the * result of the comparison. int result;
/* Name comparison result */ const char *
s1resume;
/* Comparison resumption point */ * Compare the name strings, s1 and s2 * Determine whether s2 matches all of or just part of s1 * Note that s1resume will not be NULL if result is * Return the final result of the comparison * Look up an option name in an array of known Boolean option names. * Note that a Boolean option name can have a "No" prefix. If found, * return the array subscript of the Boolean option name. Otherwise int i;
/* Index into option name array */ const char *
s1resume;
/* Comparison resumption point */ * Look up the option name, which can be negated using a "No" prefix * See whether this is a plain instance of the option name return (i);
/* Have a match */ * See whether this is a negated instance of the option name return (i);
/* Have a match */ * Not the name of a known Boolean option * xf86optionNameCompare() * Compare two option names pointed to by s1 and s2. Ignore * alphabetic case and the characters, '_', ' ', and '\t'. For names * of known Boolean options (provided via bool_option_names[]), any * "No" prefix is ignored. Return the usual negative, zero, or * positive values to indicate the results of the comparison. * To see why we want a list of known Boolean option names, consider * * Can we tell from this hypothetical example whether "Tables" * is the name of a Boolean option, which could be negated? * * Can we tell whether "Notables" is the opposite of "Tables"? * * Is the opposite of the documented Boolean option, * "NoTrapSignals", intended to be "NoNoTrapSignals" or * "TrapSignals"? Ditto for "NoPM" and "NoInt10". int i;
/* Index of option name, else -1 */ return (0);
/* Known Boolean option names match */ if (*
str !=
' ' && *
str !=
'\t')