config.c revision 76028eb6
1bbe1b32bSmrg/* 2bbe1b32bSmrgCopyright 1987, 1998 The Open Group 3bbe1b32bSmrg 4bbe1b32bSmrgPermission to use, copy, modify, distribute, and sell this software and its 5bbe1b32bSmrgdocumentation for any purpose is hereby granted without fee, provided that 6bbe1b32bSmrgthe above copyright notice appear in all copies and that both that 7bbe1b32bSmrgcopyright notice and this permission notice appear in supporting 8bbe1b32bSmrgdocumentation. 9bbe1b32bSmrg 10bbe1b32bSmrgThe above copyright notice and this permission notice shall be included in 11bbe1b32bSmrgall copies or substantial portions of the Software. 12bbe1b32bSmrg 13bbe1b32bSmrgTHE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14bbe1b32bSmrgIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15bbe1b32bSmrgFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16bbe1b32bSmrgOPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 17bbe1b32bSmrgAN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 18bbe1b32bSmrgCONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19bbe1b32bSmrg 20bbe1b32bSmrgExcept as contained in this notice, the name of The Open Group shall not be 21bbe1b32bSmrgused in advertising or otherwise to promote the sale, use or other dealings 22bbe1b32bSmrgin this Software without prior written authorization from The Open Group. 23bbe1b32bSmrg * Copyright 1990, 1991 Network Computing Devices; 24bbe1b32bSmrg * Portions Copyright 1987 by Digital Equipment Corporation 25bbe1b32bSmrg * 26bbe1b32bSmrg * Permission to use, copy, modify, distribute, and sell this software and its 27bbe1b32bSmrg * documentation for any purpose is hereby granted without fee, provided that 28bbe1b32bSmrg * the above copyright notice appear in all copies and that both that 29bbe1b32bSmrg * copyright notice and this permission notice appear in supporting 30bbe1b32bSmrg * documentation, and that the names of Network Computing Devices, 31bbe1b32bSmrg * or Digital not be used in advertising or 32bbe1b32bSmrg * publicity pertaining to distribution of the software without specific, 33bbe1b32bSmrg * written prior permission. Network Computing Devices, or Digital 34bbe1b32bSmrg * make no representations about the 35bbe1b32bSmrg * suitability of this software for any purpose. It is provided "as is" 36bbe1b32bSmrg * without express or implied warranty. 37bbe1b32bSmrg * 38bbe1b32bSmrg * NETWORK COMPUTING DEVICES, AND DIGITAL DISCLAIM ALL WARRANTIES WITH 39bbe1b32bSmrg * REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 40bbe1b32bSmrg * AND FITNESS, IN NO EVENT SHALL NETWORK COMPUTING DEVICES, OR DIGITAL BE 41bbe1b32bSmrg * LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 42bbe1b32bSmrg * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION 43bbe1b32bSmrg * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN 44bbe1b32bSmrg * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 45bbe1b32bSmrg * 46bbe1b32bSmrg */ 47bbe1b32bSmrg 4834f90d55Smrg#include "config.h" 49bbe1b32bSmrg 50bbe1b32bSmrg#include <stdio.h> 51bbe1b32bSmrg#include <stdlib.h> 52bbe1b32bSmrg#include <ctype.h> 53bbe1b32bSmrg#include <X11/Xtrans/Xtrans.h> 54bbe1b32bSmrg#include <X11/Xos.h> 55bbe1b32bSmrg#include "misc.h" 56bbe1b32bSmrg#include "configstr.h" 57bbe1b32bSmrg#include "osdep.h" 58bbe1b32bSmrg#include "globals.h" 59bbe1b32bSmrg#include "access.h" 60bbe1b32bSmrg#include "difsutils.h" 61bbe1b32bSmrg#include "difs.h" 6240c5823bSmrg#include <X11/fonts/libxfont2.h> 63bbe1b32bSmrg 64ce6676dbSmrg/* libXfont/src/bitmap/snfstr.h */ 65ce6676dbSmrgextern void SnfSetFormat(int bit, int byte, int glyph, int scan); 66ce6676dbSmrg 67bbe1b32bSmrgstatic const char * const default_config_files[] = { 68bbe1b32bSmrg#ifdef DEFAULT_CONFIG_FILE 69bbe1b32bSmrg DEFAULT_CONFIG_FILE, 70bbe1b32bSmrg#else 71bbe1b32bSmrg "/usr/lib/X11/fs/config", 72bbe1b32bSmrg#endif 73bbe1b32bSmrg NULL 74bbe1b32bSmrg}; 75bbe1b32bSmrg 76bbe1b32bSmrgstatic char *font_catalogue = NULL; 77bbe1b32bSmrg 78bbe1b32bSmrgstatic char *config_set_int(ConfigOptionPtr parm, char *val); 79bbe1b32bSmrgstatic char *config_set_bool(ConfigOptionPtr parm, char *val); 80bbe1b32bSmrgstatic char *config_set_catalogue(ConfigOptionPtr parm, char *val); 81bbe1b32bSmrgstatic char *config_set_glyph_caching_mode(ConfigOptionPtr parm, char *val); 82bbe1b32bSmrgstatic char *config_set_list(ConfigOptionPtr parm, char *val); 83bbe1b32bSmrgstatic char *config_set_file(ConfigOptionPtr parm, char *val); 84bbe1b32bSmrgstatic char *config_set_resolutions(ConfigOptionPtr parm, char *val); 85bbe1b32bSmrgstatic char *config_set_ignored_transports(ConfigOptionPtr parm, char *val); 86bbe1b32bSmrgstatic char *config_set_snf_format(ConfigOptionPtr parm, char *val); 87bbe1b32bSmrg 88bbe1b32bSmrg/* these need to be in lower case and alphabetical order so a 89bbe1b32bSmrg * binary search lookup can be used 90bbe1b32bSmrg */ 91bbe1b32bSmrgstatic ConfigOptionRec config_options[] = { 92bbe1b32bSmrg {"alternate-servers", config_set_list}, 93bbe1b32bSmrg {"catalogue", config_set_catalogue}, 94bbe1b32bSmrg {"client-limit", config_set_int}, 95bbe1b32bSmrg {"clone-self", config_set_bool}, 96bbe1b32bSmrg {"default-point-size", config_set_int}, 97bbe1b32bSmrg {"default-resolutions", config_set_resolutions}, 98bbe1b32bSmrg {"deferglyphs", config_set_glyph_caching_mode}, 99bbe1b32bSmrg {"error-file", config_set_file}, 100bbe1b32bSmrg {"no-listen", config_set_ignored_transports}, 101bbe1b32bSmrg {"port", config_set_int}, 102bbe1b32bSmrg {"server-number", config_set_int}, 103bbe1b32bSmrg {"snf-format", config_set_snf_format}, 104bbe1b32bSmrg {"trusted-clients", config_set_list}, 105bbe1b32bSmrg {"use-syslog", config_set_bool}, 106ce6676dbSmrg {NULL, NULL}, 107bbe1b32bSmrg}; 108bbe1b32bSmrg 10934f90d55Smrg/* max size in bytes of config file */ 11034f90d55Smrg#define CONFIG_MAX_FILESIZE 32767 11134f90d55Smrg 11234f90d55Smrg#define CONFIG_ERR_MEMORY \ 11334f90d55Smrg "CONFIG: insufficient memory to load configuration file \"%s\"\n" 11434f90d55Smrg#define CONFIG_ERR_OPEN "CONFIG: can't open configuration file \"%s\"\n" 11534f90d55Smrg#define CONFIG_ERR_READ "CONFIG: error reading configuration file \"%s\"\n" 11634f90d55Smrg#define CONFIG_ERR_VALUE "CONFIG: bad value \"%s\" for parameter \"%s\"\n" 11734f90d55Smrg#define CONFIG_ERR_UNKNOWN "CONFIG: unknown parameter \"%s\"\n" 11834f90d55Smrg#define CONFIG_ERR_NOEQUALS "CONFIG: missing '=' after parameter \"%s\"\n" 11934f90d55Smrg#define CONFIG_ERR_RANGE "CONFIG: value out of range for parameter \"%s\"\n" 12034f90d55Smrg#define CONFIG_ERR_SYNTAX "CONFIG: syntax error near parameter \"%s\"\n" 12134f90d55Smrg#define CONFIG_ERR_NOVALUE "CONFIG: missing value for parameter \"%s\"\n" 12234f90d55Smrg#define CONFIG_ERR_EXTRAVALUE "CONFIG: extra value for parameter \"%s\"\n" 123bbe1b32bSmrg 124bbe1b32bSmrg#define iseol(c) ((c) == '\n' || (c) == '\r' || (c) == '\f') 125bbe1b32bSmrg#define skip_whitespace(c) while(isspace(*(c)) || *(c) == ',') (c)++; 126bbe1b32bSmrg#define skip_val(c) while(!isspace(*(c)) && *(c) != ',' && *(c) != '\0')\ 127bbe1b32bSmrg (c) ++; 128bbe1b32bSmrg#define skip_list_val(c) while(!isspace(*(c)) && *(c) != '\0')\ 129bbe1b32bSmrg (c) ++; 130bbe1b32bSmrg#define blank_comment(c) while (!iseol(*(c)) && *(c) != '\0') \ 131bbe1b32bSmrg *(c)++= ' '; 132bbe1b32bSmrg 133bbe1b32bSmrgstatic char * 134bbe1b32bSmrgnext_assign(char *c) 135bbe1b32bSmrg{ 136bbe1b32bSmrg int nesting = 0; 137bbe1b32bSmrg 138bbe1b32bSmrg while (*c != '\0') { 139bbe1b32bSmrg if (*c == '(') 140bbe1b32bSmrg nesting++; 141bbe1b32bSmrg else if (*c == ')') 142bbe1b32bSmrg nesting--; 143bbe1b32bSmrg else if (*c == '=' && nesting == 0) 144bbe1b32bSmrg return c; 145bbe1b32bSmrg c++; 146bbe1b32bSmrg } 147bbe1b32bSmrg return (char *) 0; 148bbe1b32bSmrg} 149bbe1b32bSmrg 150bbe1b32bSmrgstatic void 151bbe1b32bSmrgstrip_comments(char *data) 152bbe1b32bSmrg{ 153bbe1b32bSmrg char *c; 154bbe1b32bSmrg 155bbe1b32bSmrg c = data; 156bbe1b32bSmrg while ((c = strchr(c, '#')) != NULL) { 157bbe1b32bSmrg if (c == data || *(c - 1) != '\\') { 158bbe1b32bSmrg blank_comment(c); 159bbe1b32bSmrg } else { 160bbe1b32bSmrg c++; 161bbe1b32bSmrg } 162bbe1b32bSmrg } 163bbe1b32bSmrg} 164bbe1b32bSmrg 165bbe1b32bSmrgstatic ConfigOptionPtr 166bbe1b32bSmrgmatch_param_name(char *name) 167bbe1b32bSmrg{ 168bbe1b32bSmrg int pos, 169bbe1b32bSmrg rc, 170bbe1b32bSmrg low, 171bbe1b32bSmrg high; 172bbe1b32bSmrg 173bbe1b32bSmrg low = 0; 174bbe1b32bSmrg high = sizeof(config_options) / sizeof(ConfigOptionRec) - 2; 175bbe1b32bSmrg pos = high >> 1; 176bbe1b32bSmrg 177bbe1b32bSmrg while (low <= high) { 178bbe1b32bSmrg rc = strcmp(name, config_options[pos].parm_name); 179bbe1b32bSmrg if (rc == 0) { 180bbe1b32bSmrg return &config_options[pos]; 181bbe1b32bSmrg } else if (rc < 0) { 182bbe1b32bSmrg high = pos - 1; 183bbe1b32bSmrg } else { 184bbe1b32bSmrg low = pos + 1; 185bbe1b32bSmrg } 186bbe1b32bSmrg pos = ((high + low) >> 1); 187bbe1b32bSmrg } 188ce6676dbSmrg return NULL; 189bbe1b32bSmrg} 190bbe1b32bSmrg 191bbe1b32bSmrgstatic int 192bbe1b32bSmrgparse_config(char *data) 193bbe1b32bSmrg{ 194bbe1b32bSmrg char *c, 195bbe1b32bSmrg *val = NULL, 196bbe1b32bSmrg *next_eq, 197bbe1b32bSmrg *consumed, 198bbe1b32bSmrg *p; 199bbe1b32bSmrg char param_name[64]; 200bbe1b32bSmrg Bool equals_missing; 201bbe1b32bSmrg ConfigOptionPtr param; 202bbe1b32bSmrg 203bbe1b32bSmrg c = data; 204bbe1b32bSmrg skip_whitespace(c); 205bbe1b32bSmrg 206bbe1b32bSmrg while (*c != '\0') { 207bbe1b32bSmrg equals_missing = FALSE; 208bbe1b32bSmrg 209bbe1b32bSmrg /* get parm name in lower case */ 210bbe1b32bSmrg p = c; 211bbe1b32bSmrg while (isalnum(*c) || *c == '-') { 212bbe1b32bSmrg if (isupper(*c)) 213bbe1b32bSmrg *c = tolower(*c); 214bbe1b32bSmrg c++; 215bbe1b32bSmrg } 21676028eb6Smrg memcpy(param_name, p, min(sizeof(param_name), (int) (c - p))); 217bbe1b32bSmrg param_name[(int) (c - p)] = '\0'; 218bbe1b32bSmrg 219bbe1b32bSmrg /* check for junk */ 220bbe1b32bSmrg if (!isspace(*c) && *c != '=') { 22134f90d55Smrg ErrorF(CONFIG_ERR_SYNTAX, param_name); 222bbe1b32bSmrg /* eat garbage */ 223bbe1b32bSmrg while (!isspace(*c) && *c != '=' && *c != '\0') 224bbe1b32bSmrg c++; 225bbe1b32bSmrg } 226bbe1b32bSmrg skip_whitespace(c); 227bbe1b32bSmrg if (*c != '=') { 22834f90d55Smrg ErrorF(CONFIG_ERR_NOEQUALS, param_name); 229bbe1b32bSmrg equals_missing = TRUE; 230bbe1b32bSmrg } else { 231bbe1b32bSmrg c++; 232bbe1b32bSmrg } 233bbe1b32bSmrg 234bbe1b32bSmrg skip_whitespace(c); 235bbe1b32bSmrg 236bbe1b32bSmrg /* find next assignment to guess where the value ends */ 237bbe1b32bSmrg if ((next_eq = next_assign(c)) != NULL) { 238bbe1b32bSmrg /* back up over whitespace */ 239bbe1b32bSmrg for (val = next_eq - 1; val >= c && 240bbe1b32bSmrg (isspace(*val) || *val == ','); 241bbe1b32bSmrg val--); 242bbe1b32bSmrg 243bbe1b32bSmrg /* back over parm name */ 244bbe1b32bSmrg for (; val >= c && (isalnum(*val) || *val == '-'); val--); 245bbe1b32bSmrg 246bbe1b32bSmrg if (val <= c) { 247bbe1b32bSmrg /* no value, ignore */ 24834f90d55Smrg ErrorF(CONFIG_ERR_NOVALUE, param_name); 249bbe1b32bSmrg continue; 250bbe1b32bSmrg } 251bbe1b32bSmrg *val = '\0'; 252bbe1b32bSmrg } else if (*c == '\0') { 253bbe1b32bSmrg /* no value, ignore */ 25434f90d55Smrg ErrorF(CONFIG_ERR_NOVALUE, param_name); 255bbe1b32bSmrg continue; 256bbe1b32bSmrg } 257bbe1b32bSmrg /* match parm name */ 258bbe1b32bSmrg if (equals_missing) { 259bbe1b32bSmrg equals_missing = FALSE; 260bbe1b32bSmrg } else if ((param = match_param_name(param_name)) == NULL) { 26134f90d55Smrg ErrorF(CONFIG_ERR_UNKNOWN, param_name); 262bbe1b32bSmrg } else { 263bbe1b32bSmrg consumed = (param->set_func) (param, c); 264bbe1b32bSmrg 265bbe1b32bSmrg skip_whitespace(consumed); 266bbe1b32bSmrg if (*consumed != '\0') { 26734f90d55Smrg ErrorF(CONFIG_ERR_EXTRAVALUE, 268bbe1b32bSmrg param_name); 269bbe1b32bSmrg } 270bbe1b32bSmrg } 271bbe1b32bSmrg 272bbe1b32bSmrg if (next_eq != NULL) 273bbe1b32bSmrg c = val + 1; 274bbe1b32bSmrg else /* last setting */ 275bbe1b32bSmrg break; 276bbe1b32bSmrg } 277bbe1b32bSmrg return FSSuccess; 278bbe1b32bSmrg} 279bbe1b32bSmrg 280bbe1b32bSmrg/* 281bbe1b32bSmrg * handles anything that should be set once the file is parsed 282bbe1b32bSmrg */ 283bbe1b32bSmrgvoid 284bbe1b32bSmrgSetConfigValues(void) 285bbe1b32bSmrg{ 286bbe1b32bSmrg int err, 287bbe1b32bSmrg num; 288bbe1b32bSmrg 289bbe1b32bSmrg if (font_catalogue == NULL) { 290bbe1b32bSmrg FatalError("font catalogue is missing/empty\n"); 291bbe1b32bSmrg } 292bbe1b32bSmrg 293bbe1b32bSmrg err = SetFontCatalogue(font_catalogue, &num); 294bbe1b32bSmrg if (err != FSSuccess) { 295bbe1b32bSmrg FatalError("element #%d (starting at 0) of font path is bad or has a bad font:\n\"%s\"\n", 296bbe1b32bSmrg num, font_catalogue); 297bbe1b32bSmrg } 298bbe1b32bSmrg InitErrors(); 299bbe1b32bSmrg fsfree((char *) font_catalogue); 300bbe1b32bSmrg font_catalogue = NULL; 301bbe1b32bSmrg} 302bbe1b32bSmrg 303bbe1b32bSmrg 304bbe1b32bSmrg/* If argument is NULL, uses first file found from default_config_files */ 305bbe1b32bSmrgint 306bbe1b32bSmrgReadConfigFile(const char *filename) 307bbe1b32bSmrg{ 308ce6676dbSmrg FILE *fp = NULL; 309bbe1b32bSmrg int ret; 310bbe1b32bSmrg int len; 311bbe1b32bSmrg int i; 312bbe1b32bSmrg char *data; 313bbe1b32bSmrg 314bbe1b32bSmrg data = (char *) fsalloc(CONFIG_MAX_FILESIZE); 315bbe1b32bSmrg if (!data) { 31634f90d55Smrg ErrorF(CONFIG_ERR_MEMORY, filename); 317bbe1b32bSmrg return FSBadAlloc; 318bbe1b32bSmrg } 319bbe1b32bSmrg if (filename != NULL) { 320bbe1b32bSmrg fp = fopen(filename, "r"); 321bbe1b32bSmrg if (fp == NULL) { 32234f90d55Smrg ErrorF(CONFIG_ERR_OPEN, filename); 323bbe1b32bSmrg } 324bbe1b32bSmrg } else { 325bbe1b32bSmrg for (i = 0; default_config_files[i] != NULL; i++) { 326bbe1b32bSmrg filename = default_config_files[i]; 327ce6676dbSmrg if ((fp = fopen(filename, "r")) != NULL) { 328ce6676dbSmrg if (configfilename == NULL) { 329ce6676dbSmrg configfilename = strdup(filename); /* save for clones */ 330ce6676dbSmrg } 331bbe1b32bSmrg break; 332ce6676dbSmrg } 333bbe1b32bSmrg } 334bbe1b32bSmrg if (fp == NULL) { 335bbe1b32bSmrg for (i = 0; default_config_files[i] != NULL; i++) { 33634f90d55Smrg ErrorF(CONFIG_ERR_OPEN, default_config_files[i]); 337bbe1b32bSmrg } 338bbe1b32bSmrg } 339bbe1b32bSmrg } 340bbe1b32bSmrg if (fp == NULL) { 341bbe1b32bSmrg fsfree(data); 342bbe1b32bSmrg return FSBadName; 343bbe1b32bSmrg } 344bbe1b32bSmrg ret = fread(data, sizeof(char), CONFIG_MAX_FILESIZE, fp); 345bbe1b32bSmrg if (ret <= 0) { 346bbe1b32bSmrg fsfree(data); 347bbe1b32bSmrg (void) fclose(fp); 34834f90d55Smrg ErrorF(CONFIG_ERR_READ, filename); 349bbe1b32bSmrg return FSBadName; 350bbe1b32bSmrg } 351bbe1b32bSmrg len = ftell(fp); 352bbe1b32bSmrg len = min(len, CONFIG_MAX_FILESIZE); 353bbe1b32bSmrg data[len] = '\0'; /* NULL terminate the data */ 354bbe1b32bSmrg 355bbe1b32bSmrg (void) fclose(fp); 356bbe1b32bSmrg 357bbe1b32bSmrg strip_comments(data); 358bbe1b32bSmrg ret = parse_config(data); 359bbe1b32bSmrg 360bbe1b32bSmrg fsfree(data); 361bbe1b32bSmrg 362bbe1b32bSmrg return ret; 363bbe1b32bSmrg} 364bbe1b32bSmrg 365bbe1b32bSmrgstruct nameVal { 36634f90d55Smrg const char *name; 367bbe1b32bSmrg int val; 368bbe1b32bSmrg}; 369bbe1b32bSmrg 370bbe1b32bSmrgstatic char * 371bbe1b32bSmrgconfig_parse_nameVal ( 37234f90d55Smrg ConfigOptionPtr parm, 373bbe1b32bSmrg char *c, 374bbe1b32bSmrg int *ret, 375bbe1b32bSmrg int *pval, 376bbe1b32bSmrg struct nameVal *name_val) 377bbe1b32bSmrg{ 378bbe1b32bSmrg char *start, 379bbe1b32bSmrg t; 380bbe1b32bSmrg int i, 381bbe1b32bSmrg len; 382bbe1b32bSmrg 383bbe1b32bSmrg start = c; 384bbe1b32bSmrg skip_val(c); 385bbe1b32bSmrg t = *c; 386bbe1b32bSmrg *c = '\0'; 387bbe1b32bSmrg len = c - start; 388bbe1b32bSmrg 389bbe1b32bSmrg for (i = 0; name_val[i].name; i++) { 390bbe1b32bSmrg if (!strncmpnocase(start, name_val[i].name, len)) { 391bbe1b32bSmrg *pval = name_val[i].val; 392bbe1b32bSmrg *ret = 0; 393bbe1b32bSmrg *c = t; 394bbe1b32bSmrg return c; 395bbe1b32bSmrg } 396bbe1b32bSmrg } 39734f90d55Smrg ErrorF(CONFIG_ERR_VALUE, start, parm->parm_name); 398bbe1b32bSmrg *c = t; 399bbe1b32bSmrg *ret = -1; 400bbe1b32bSmrg return c; 401bbe1b32bSmrg} 402bbe1b32bSmrg 403bbe1b32bSmrgstatic char * 404bbe1b32bSmrgconfig_parse_bool ( 40534f90d55Smrg ConfigOptionPtr parm, 406bbe1b32bSmrg char *c, 407bbe1b32bSmrg int *ret, 408bbe1b32bSmrg Bool *pval) 409bbe1b32bSmrg{ 410bbe1b32bSmrg static struct nameVal bool_val[] = { 411bbe1b32bSmrg { "yes", TRUE }, 412bbe1b32bSmrg { "on", TRUE }, 413bbe1b32bSmrg { "1", TRUE }, 414bbe1b32bSmrg { "true", TRUE }, 415bbe1b32bSmrg { "no", FALSE }, 416bbe1b32bSmrg { "off", FALSE }, 417bbe1b32bSmrg { "0", FALSE }, 418bbe1b32bSmrg { "false", FALSE }, 419bbe1b32bSmrg { (char *) 0, 0 }, 420bbe1b32bSmrg }; 42134f90d55Smrg return config_parse_nameVal (parm, c, ret, pval, bool_val); 422bbe1b32bSmrg} 423bbe1b32bSmrg 424bbe1b32bSmrgstatic char * 425bbe1b32bSmrgconfig_parse_int( 42634f90d55Smrg ConfigOptionPtr parm, 427bbe1b32bSmrg char *c, 428bbe1b32bSmrg int *ret, 429bbe1b32bSmrg int *pval) 430bbe1b32bSmrg{ 431bbe1b32bSmrg char *start, 432bbe1b32bSmrg t; 433bbe1b32bSmrg 434bbe1b32bSmrg start = c; 435bbe1b32bSmrg while (*c != '\0' && !isspace(*c) && *c != ',') { 436bbe1b32bSmrg if (!isdigit(*c)) { /* error */ 437bbe1b32bSmrg skip_val(c); 438bbe1b32bSmrg t = *c; 439bbe1b32bSmrg *c = '\0'; 44034f90d55Smrg ErrorF(CONFIG_ERR_VALUE, start, parm->parm_name); 441bbe1b32bSmrg *ret = -1; 442bbe1b32bSmrg *c = t; 443bbe1b32bSmrg return c; 444bbe1b32bSmrg } 445bbe1b32bSmrg c++; 446bbe1b32bSmrg } 447bbe1b32bSmrg t = *c; 448bbe1b32bSmrg *c = '\0'; 449bbe1b32bSmrg *ret = 0; 450bbe1b32bSmrg *pval = atoi(start); 451bbe1b32bSmrg *c = t; 452bbe1b32bSmrg return c; 453bbe1b32bSmrg} 454bbe1b32bSmrg 455bbe1b32bSmrg 456bbe1b32bSmrg/* config option sets */ 457bbe1b32bSmrg/* these have to know how to do the real work and tweak the proper things */ 458bbe1b32bSmrgstatic char * 459bbe1b32bSmrgconfig_set_int( 460bbe1b32bSmrg ConfigOptionPtr parm, 461bbe1b32bSmrg char *val) 462bbe1b32bSmrg{ 463bbe1b32bSmrg int ival, 464bbe1b32bSmrg ret; 465bbe1b32bSmrg 46634f90d55Smrg val = config_parse_int(parm, val, &ret, &ival); 467bbe1b32bSmrg if (ret == -1) 468bbe1b32bSmrg return val; 469bbe1b32bSmrg 470bbe1b32bSmrg /* now do individual attribute checks */ 471bbe1b32bSmrg if (!strcmp(parm->parm_name, "port") && !portFromCmdline) { 472bbe1b32bSmrg ListenPort = ival; 473bbe1b32bSmrg } else if (!strcmp(parm->parm_name, "client-limit")) { 474bbe1b32bSmrg AccessSetConnectionLimit(ival); 475bbe1b32bSmrg } else if (!strcmp(parm->parm_name, "default-point-size")) { 476bbe1b32bSmrg SetDefaultPointSize(ival); 477bbe1b32bSmrg } 478bbe1b32bSmrg return val; 479bbe1b32bSmrg} 480bbe1b32bSmrg 481bbe1b32bSmrgstatic char * 482bbe1b32bSmrgconfig_set_bool( 483bbe1b32bSmrg ConfigOptionPtr parm, 484bbe1b32bSmrg char *val) 485bbe1b32bSmrg{ 486bbe1b32bSmrg int 487bbe1b32bSmrg ret; 488bbe1b32bSmrg Bool bval; 489bbe1b32bSmrg 49034f90d55Smrg val = config_parse_bool(parm, val, &ret, &bval); 491bbe1b32bSmrg if (ret == -1) 492bbe1b32bSmrg return val; 493bbe1b32bSmrg 494bbe1b32bSmrg /* now do individual attribute checks */ 495bbe1b32bSmrg if (!strcmp(parm->parm_name, "use-syslog")) { 496bbe1b32bSmrg UseSyslog = bval; 497bbe1b32bSmrg } else if (!strcmp(parm->parm_name, "clone-self")) { 498bbe1b32bSmrg CloneSelf = bval; 499bbe1b32bSmrg } 500bbe1b32bSmrg return val; 501bbe1b32bSmrg} 502bbe1b32bSmrg 503bbe1b32bSmrgstatic char * 504bbe1b32bSmrgconfig_set_file( 505bbe1b32bSmrg ConfigOptionPtr parm, 506bbe1b32bSmrg char *val) 507bbe1b32bSmrg{ 508bbe1b32bSmrg char *start = val, 509bbe1b32bSmrg t; 510bbe1b32bSmrg 511bbe1b32bSmrg skip_val(val); 512bbe1b32bSmrg t = *val; 513bbe1b32bSmrg *val = '\0'; 514bbe1b32bSmrg if (!strcmp(parm->parm_name, "error-file")) { 515bbe1b32bSmrg memmove( ErrorFile, start, val - start + 1); 516bbe1b32bSmrg } 517bbe1b32bSmrg *val = t; 518bbe1b32bSmrg return val; 519bbe1b32bSmrg} 520bbe1b32bSmrg 521bbe1b32bSmrgstatic char * 522bbe1b32bSmrgconfig_set_catalogue( 523bbe1b32bSmrg ConfigOptionPtr parm, 524bbe1b32bSmrg char *val) 525bbe1b32bSmrg{ 526bbe1b32bSmrg char *b; 527bbe1b32bSmrg 528bbe1b32bSmrg if (!strcmp(parm->parm_name, "catalogue")) { 529bbe1b32bSmrg /* stash it for later */ 530bbe1b32bSmrg fsfree((char *) font_catalogue); /* dump any previous one */ 531bbe1b32bSmrg b = font_catalogue = (char *) fsalloc(strlen(val) + 1); 532bbe1b32bSmrg if (!font_catalogue) 53376028eb6Smrg FatalError("insufficient memory for font catalogue\n"); 534bbe1b32bSmrg while (*val) { /* remove all the gunk */ 535bbe1b32bSmrg if (!isspace(*val)) { 536bbe1b32bSmrg *b++ = *val; 537bbe1b32bSmrg } 538bbe1b32bSmrg val++; 539bbe1b32bSmrg } 540bbe1b32bSmrg *b = '\0'; 541bbe1b32bSmrg } 542bbe1b32bSmrg return val; 543bbe1b32bSmrg} 544bbe1b32bSmrg 545bbe1b32bSmrgstatic char * 546bbe1b32bSmrgconfig_set_list( 547bbe1b32bSmrg ConfigOptionPtr parm, 548bbe1b32bSmrg char *val) 549bbe1b32bSmrg{ 550bbe1b32bSmrg char *start = val, 551bbe1b32bSmrg t; 552bbe1b32bSmrg 553bbe1b32bSmrg skip_list_val(val); 554bbe1b32bSmrg t = *val; 555bbe1b32bSmrg *val = '\0'; 556bbe1b32bSmrg if (!strcmp(parm->parm_name, "alternate-servers")) { 557bbe1b32bSmrg SetAlternateServers(start); 558bbe1b32bSmrg } 559bbe1b32bSmrg *val = t; 560bbe1b32bSmrg return val; 561bbe1b32bSmrg} 562bbe1b32bSmrg 563bbe1b32bSmrgstatic char * 564bbe1b32bSmrgconfig_set_ignored_transports( 565bbe1b32bSmrg ConfigOptionPtr parm, 566bbe1b32bSmrg char *val) 567bbe1b32bSmrg{ 568bbe1b32bSmrg char *start = val, 569bbe1b32bSmrg t; 570bbe1b32bSmrg 571bbe1b32bSmrg skip_list_val(val); 572bbe1b32bSmrg t = *val; 573bbe1b32bSmrg *val = '\0'; 574bbe1b32bSmrg _FontTransNoListen(start); 575bbe1b32bSmrg *val = t; 576bbe1b32bSmrg return val; 577bbe1b32bSmrg} 578bbe1b32bSmrg 579bbe1b32bSmrgstatic char * 580bbe1b32bSmrgconfig_set_glyph_caching_mode( 581bbe1b32bSmrg ConfigOptionPtr parm, 582bbe1b32bSmrg char *val) 583bbe1b32bSmrg{ 584bbe1b32bSmrg char *start = val, 585bbe1b32bSmrg t; 586bbe1b32bSmrg 587bbe1b32bSmrg skip_list_val(val); 588bbe1b32bSmrg t = *val; 589bbe1b32bSmrg *val = '\0'; 590bbe1b32bSmrg if (!strcmp(parm->parm_name, "deferglyphs")) { 59140c5823bSmrg xfont2_parse_glyph_caching_mode(start); 592bbe1b32bSmrg } 593bbe1b32bSmrg *val = t; 594bbe1b32bSmrg return val; 595bbe1b32bSmrg} 596bbe1b32bSmrg 597bbe1b32bSmrgstatic char * 598bbe1b32bSmrgconfig_set_resolutions( 599bbe1b32bSmrg ConfigOptionPtr parm, 600bbe1b32bSmrg char *val) 601bbe1b32bSmrg{ 602bbe1b32bSmrg char *start = val, 603bbe1b32bSmrg t; 604bbe1b32bSmrg int err; 605bbe1b32bSmrg 606bbe1b32bSmrg skip_list_val(val); 607bbe1b32bSmrg t = *val; 608bbe1b32bSmrg *val = '\0'; 609bbe1b32bSmrg if (!strcmp(parm->parm_name, "default-resolutions")) { 610bbe1b32bSmrg err = SetDefaultResolutions(start); 611bbe1b32bSmrg if (err != FSSuccess) { 612bbe1b32bSmrg FatalError("bogus resolution list \"%s\"\n", start); 613bbe1b32bSmrg } 614bbe1b32bSmrg } 615bbe1b32bSmrg *val = t; 616bbe1b32bSmrg return val; 617bbe1b32bSmrg} 618bbe1b32bSmrg 619bbe1b32bSmrg 620bbe1b32bSmrgstatic char * 621bbe1b32bSmrgconfig_parse_endian( 62234f90d55Smrg ConfigOptionPtr parm, 623bbe1b32bSmrg char *c, 624bbe1b32bSmrg int *ret, 625bbe1b32bSmrg int *pval) 626bbe1b32bSmrg{ 627bbe1b32bSmrg static struct nameVal endian_val[] = { 628bbe1b32bSmrg { "lsb", LSBFirst }, 629bbe1b32bSmrg { "little", LSBFirst }, 630bbe1b32bSmrg { "lsbfirst", LSBFirst }, 631bbe1b32bSmrg { "msb", MSBFirst }, 632bbe1b32bSmrg { "big", MSBFirst }, 633bbe1b32bSmrg { "msbfirst", MSBFirst }, 634bbe1b32bSmrg { (char *) 0, 0 }, 635bbe1b32bSmrg }; 63634f90d55Smrg return config_parse_nameVal (parm, c, ret, pval, endian_val); 637bbe1b32bSmrg} 638bbe1b32bSmrg 639bbe1b32bSmrg/* ARGSUSED */ 640bbe1b32bSmrgstatic char * 641bbe1b32bSmrgconfig_set_snf_format ( 642bbe1b32bSmrg ConfigOptionPtr parm, 643bbe1b32bSmrg char *val) 644bbe1b32bSmrg{ 645bbe1b32bSmrg int bit, byte, glyph, scan; 646bbe1b32bSmrg int ret; 647bbe1b32bSmrg 64834f90d55Smrg val = config_parse_endian (parm, val, &ret, &bit); 649bbe1b32bSmrg if (ret == -1) 650bbe1b32bSmrg return val; 651bbe1b32bSmrg skip_whitespace (val); 65234f90d55Smrg val = config_parse_endian (parm, val, &ret, &byte); 653bbe1b32bSmrg if (ret == -1) 654bbe1b32bSmrg return val; 655bbe1b32bSmrg skip_whitespace (val); 65634f90d55Smrg val = config_parse_int (parm, val, &ret, &glyph); 657bbe1b32bSmrg if (ret == -1) 658bbe1b32bSmrg return val; 659bbe1b32bSmrg skip_whitespace (val); 66034f90d55Smrg val = config_parse_int (parm, val, &ret, &scan); 661bbe1b32bSmrg if (ret == -1) 662bbe1b32bSmrg return val; 6638f34cbf9Ssnj#ifdef XFONT_SNFFORMAT 664bbe1b32bSmrg SnfSetFormat (bit, byte, glyph, scan); 6658f34cbf9Ssnj#endif 666bbe1b32bSmrg return val; 667bbe1b32bSmrg} 668