xf86config.c

来自「基于组件方式开发操作系统的OSKIT源代码」· C语言 代码 · 共 2,368 行 · 第 1/5 页

C
2,368
字号
/* * $XFree86: xc/programs/Xserver/hw/xfree86/common/xf86Config.c,v 3.113.2.13 1997/08/04 02:10:39 dawes Exp $ * * Copyright 1990,91 by Thomas Roell, Dinkelscherben, Germany. * * Permission to use, copy, modify, distribute, and sell this software and its * documentation for any purpose is hereby granted without fee, provided that * the above copyright notice appear in all copies and that both that * copyright notice and this permission notice appear in supporting * documentation, and that the name of Thomas Roell not be used in * advertising or publicity pertaining to distribution of the software without * specific, written prior permission.  Thomas Roell makes no representations * about the suitability of this software for any purpose.  It is provided * "as is" without express or implied warranty. * * THOMAS ROELL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO * EVENT SHALL THOMAS ROELL BE LIABLE FOR ANY SPECIAL, INDIRECT OR * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR * PERFORMANCE OF THIS SOFTWARE. *//* $XConsortium: xf86Config.c /main/58 1996/12/28 14:46:17 kaleb $ */#ifndef X_NOT_STDC_ENV#include <stdlib.h>#elseextern double atof();extern char *getenv();#endif#define NEED_EVENTS 1#include "X.h"#include "Xproto.h"#include "Xmd.h"#ifndef OSKIT#include "input.h"#include "servermd.h"#endif#include "scrnintstr.h"#ifdef DPMSExtension#include "opaque.h"#endif#define NO_COMPILER_H_EXTRAS#include "xf86Procs.h"#include "xf86_OSlib.h"#define INIT_CONFIG#include "xf86_Config.h"#ifdef XKB#include "inputstr.h"#include "XKBsrv.h"#endif#ifdef XF86SETUP#include "xfsconf.h"#endif#ifdef XINPUT#include "xf86Xinput.h"#ifndef XF86SETUPextern DeviceAssocRec	mouse_assoc;#endif#endif#ifdef NEED_RETURN_VALUE#define HANDLE_RETURN(xx)	if (xx == RET_ERROR) return RET_ERROR#else#define HANDLE_RETURN(xx)	xx#endif#define CONFIG_BUF_LEN     1024static FILE * configFile   = NULL;static int    configStart  = 0;           /* start of the current token */static int    configPos    = 0;           /* current readers position */static int    configLineNo = 0;           /* linenumber */static char   *configBuf,*configRBuf;     /* buffer for lines */static char   *configPath;                /* path to config file */static char   *fontPath = NULL;           /* font path */static char   *modulePath = NULL;	  /* module path */static int    pushToken = LOCK_TOKEN;static LexRec val;                        /* global return value */static char   DCerr;  static int scr_index = 0;#ifdef XF86SETUP#define STATIC_OR_NOT#else#define STATIC_OR_NOT static#endifSTATIC_OR_NOT int n_monitors = 0;STATIC_OR_NOT MonPtr monitor_list = NULL;STATIC_OR_NOT int n_devices = 0;STATIC_OR_NOT GDevPtr device_list = NULL;static int screenno = -100;      /* some little number ... */extern char *defaultFontPath;extern char *rgbPath;extern Bool xf86fpFlag, xf86coFlag, xf86sFlag;extern Bool xf86ScreensOpen;extern int defaultColorVisualClass;extern CARD32 defaultScreenSaverTime, ScreenSaverTime;char *xf86VisualNames[] = {    "StaticGray",    "GrayScale",    "StaticColor",    "PseudoColor",    "TrueColor",    "DirectColor"};static CONFIG_RETURN_TYPE configFilesSection(#if NeedFunctionPrototypes    void#endif);static CONFIG_RETURN_TYPE configServerFlagsSection(#if NeedFunctionPrototypes    void#endif);static CONFIG_RETURN_TYPE configKeyboardSection(#if NeedFunctionPrototypes    void#endif);static CONFIG_RETURN_TYPE configDeviceSection(#if NeedFunctionPrototypes    void#endif);static CONFIG_RETURN_TYPE configScreenSection(#if NeedFunctionPrototypes    void#endif);static CONFIG_RETURN_TYPE configDisplaySubsection(#if NeedFunctionPrototypes    DispPtr disp#endif);static CONFIG_RETURN_TYPE configMonitorSection(#if NeedFunctionPrototypes    void#endif);static CONFIG_RETURN_TYPE configDynamicModuleSection(#if NeedFunctionPrototypes    void#endif);static char *xf86DCSaveLine(#if NeedFunctionPrototypeschar *,int#endif);static char *xf86DCOption(#if NeedFunctionPrototypeschar *,LexRec#endif);static char * xf86DCConcatOption(#if NeedFunctionPrototypeschar *,char *#endif);#ifndef XF86SETUPstatic#endifCONFIG_RETURN_TYPE findConfigFile(#if NeedFunctionPrototypes      char *filename,      FILE **fp#endif);static int getScreenIndex(#if NeedFunctionPrototypes     int token#endif);static int getStringToken(#if NeedFunctionPrototypes     SymTabRec tab[]#endif);static CONFIG_RETURN_TYPE readVerboseMode(#if NeedFunctionPrototypes    MonPtr monp#endif);static Bool validateGraphicsToken(#if NeedFunctionPrototypes     int *validTokens,     int token#endif);extern char * xf86GetPathElem(#if NeedFunctionPrototypes     char **pnt#endif);static DisplayModePtr xf86PruneModes(#if NeedFunctionPrototypes    MonPtr monp,    DisplayModePtr allmodes,    ScrnInfoPtr scrp,    Bool card#endif);static char * xf86ValidateFontPath(#if NeedFunctionPrototypes     char * /* path */#endif);#ifdef XINPUTextern CONFIG_RETURN_TYPE xf86ConfigExtendedInputSection(#if NeedFunctionPrototypes    LexPtr      pval#endif);#endif#ifdef XKBextern char *XkbInitialMap;#endif#define DIR_FILE	"/fonts.dir"/* * xf86GetPathElem -- *	Extract a single element from the font path string starting at *	pnt.  The font path element will be returned, and pnt will be *	updated to point to the start of the next element, or set to *	NULL if there are no more. */char *xf86GetPathElem(pnt)     char **pnt;{  char *p1;  p1 = *pnt;  *pnt = index(*pnt, ',');  if (*pnt != NULL) {    **pnt = '\0';    *pnt += 1;  }  return(p1);}/* * StrToUL -- * *	A portable, but restricted, version of strtoul().  It only understands *	hex, octal, and decimal.  But it's good enough for our needs. */unsigned int StrToUL(str)char *str;{  int base = 10;  char *p = str;  unsigned int tot = 0;  if (*p == '0') {    p++;    if (*p == 'x') {      p++;      base = 16;    }    else      base = 8;  }  while (*p) {    if ((*p >= '0') && (*p <= ((base == 8)?'7':'9'))) {      tot = tot * base + (*p - '0');    }    else if ((base == 16) && (*p >= 'a') && (*p <= 'f')) {      tot = tot * base + 10 + (*p - 'a');    }    else if ((base == 16) && (*p >= 'A') && (*p <= 'F')) {      tot = tot * base + 10 + (*p - 'A');    }    else {      return(tot);    }    p++;  }  return(tot);}#ifndef OSKIT/* * xf86ValidateFontPath -- *	Validates the user-specified font path.  Each element that *	begins with a '/' is checked to make sure the directory exists. *	If the directory exists, the existence of a file named 'fonts.dir' *	is checked.  If either check fails, an error is printed and the *	element is removed from the font path. */#define CHECK_TYPE(mode, type) ((S_IFMT & (mode)) == (type))static char *xf86ValidateFontPath(path)     char *path;{  char *tmp_path, *out_pnt, *path_elem, *next, *p1, *dir_elem;  struct stat stat_buf;  int flag;  int dirlen;  tmp_path = (char *)xcalloc(1,strlen(path)+1);  out_pnt = tmp_path;  path_elem = NULL;  next = path;  while (next != NULL) {    path_elem = xf86GetPathElem(&next);#ifndef __EMX__    if (*path_elem == '/') {      dir_elem = (char *)xcalloc(1, strlen(path_elem) + 1);      if ((p1 = strchr(path_elem, ':')) != 0)#else    /* OS/2 must prepend X11ROOT */    if (*path_elem == '/') {      path_elem = (char*)__XOS2RedirRoot(path_elem);      dir_elem = (char*)xcalloc(1, strlen(path_elem) + 1);      if (p1 = strchr(path_elem+2, ':'))#endif	dirlen = p1 - path_elem;      else	dirlen = strlen(path_elem);      strncpy(dir_elem, path_elem, dirlen);      dir_elem[dirlen] = '\0';      flag = stat(dir_elem, &stat_buf);      if (flag == 0)	if (!CHECK_TYPE(stat_buf.st_mode, S_IFDIR))	  flag = -1;      if (flag != 0) {        ErrorF("Warning: The directory \"%s\" does not exist.\n", dir_elem);	ErrorF("         Entry deleted from font path.\n");	continue;      }      else {	p1 = (char *)xalloc(strlen(dir_elem)+strlen(DIR_FILE)+1);	strcpy(p1, dir_elem);	strcat(p1, DIR_FILE);	flag = stat(p1, &stat_buf);	if (flag == 0)	  if (!CHECK_TYPE(stat_buf.st_mode, S_IFREG))	    flag = -1;#ifndef __EMX__	xfree(p1);#endif	if (flag != 0) {	  ErrorF("Warning: 'fonts.dir' not found (or not valid) in \"%s\".\n", 		 dir_elem);	  ErrorF("          Entry deleted from font path.\n");	  ErrorF("          (Run 'mkfontdir' on \"%s\").\n", dir_elem);	  continue;	}      }      xfree(dir_elem);    }    /*     * Either an OK directory, or a font server name.  So add it to     * the path.     */    if (out_pnt != tmp_path)      *out_pnt++ = ',';    strcat(out_pnt, path_elem);    out_pnt += strlen(path_elem);  }  return(tmp_path);}#endif /* !OSKIT *//* * xf86GetToken -- *      Read next Token form the config file. Handle the global variable *      pushToken. */intxf86GetToken(tab)     SymTabRec tab[];{  int          c, i;  /*   * First check whether pushToken has a different value than LOCK_TOKEN.   * In this case rBuf[] contains a valid STRING/TOKEN/NUMBER. But in the other   * case the next token must be read from the input.   */  if (pushToken == EOF) return(EOF);  else if (pushToken == LOCK_TOKEN)    {            c = configBuf[configPos];            /*       * Get start of next Token. EOF is handled, whitespaces & comments are       * skipped.        */      do {	if (!c)  {	  if (fgets(configBuf,CONFIG_BUF_LEN-1,configFile) == NULL)	    {	      return( pushToken = EOF );	    }	  configLineNo++;	  configStart = configPos = 0;	}#ifndef __EMX__	while (((c=configBuf[configPos++])==' ') || ( c=='\t') || ( c=='\n'));#else	while (((c=configBuf[configPos++])==' ') || ( c=='\t') || ( c=='\n') 		|| (c=='\r'));#endif	if (c == '#') c = '\0';       } while (!c);            /* GJA -- handle '-' and ','        * Be careful: "-hsync" is a keyword.       */      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 ...       */      if (isdigit(c))	{	  int base;	  if (c == '0')	    if ((configBuf[configPos] == 'x') || 		(configBuf[configPos] == 'X'))	      base = 16;	    else	      base = 8;	  else	    base = 10;	  configRBuf[0] = c; i = 1;	  while (isdigit(c = configBuf[configPos++]) || 		 (c == '.') || (c == 'x') || 		 ((base == 16) && (((c >= 'a') && (c <= 'f')) ||				   ((c >= 'A') && (c <= 'F')))))            configRBuf[i++] = c;          configPos--; /* GJA -- one too far */	  configRBuf[i] = '\0';	  val.num = StrToUL(configRBuf);          val.realnum = atof(configRBuf);	  return(NUMBER);	}            /*       * All Strings START with a \" ...       */

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?