xf86config.c

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

C
2,368
字号
      else if (c == '\"')	{	  i = -1;	  do {	    configRBuf[++i] = (c = configBuf[configPos++]);#ifndef __EMX__	  } while ((c != '\"') && (c != '\n') && (c != '\0'));#else	  } while ((c != '\"') && (c != '\n') && (c != '\r') && (c != '\0'));#endif	  configRBuf[i] = '\0';	  val.str = (char *)xalloc(strlen(configRBuf) + 1);	  strcpy(val.str, configRBuf);      /* private copy ! */	  return(STRING);	}            /*       * ... and now we MUST have a valid token.  The search is       * handled later along with the pushed tokens.       */      else	{          configRBuf[0] = c;          i = 0;	  do {	    configRBuf[++i] = (c = configBuf[configPos++]);;#ifndef __EMX__	  } while ((c != ' ') && (c != '\t') && (c != '\n') && (c != '\0'));#else	  } while ((c != ' ') && (c != '\t') && (c != '\n') && (c != '\r') && (c != '\0') );#endif	  configRBuf[i] = '\0'; i=0;	}          }  else    {          /*       * Here we deal with pushed tokens. Reinitialize pushToken again. If       * the pushed token was NUMBER || STRING return them again ...       */      int temp = pushToken;      pushToken = LOCK_TOKEN;          if (temp == COMMA || temp == DASH) return(temp);      if (temp == NUMBER || temp == STRING) return(temp);    }    /*   * Joop, at last we have to lookup the token ...   */  if (tab)    {      i = 0;      while (tab[i].token != -1)	if (StrCaseCmp(configRBuf,tab[i].name) == 0)	  return(tab[i].token);	else	  i++;    }    return(ERROR_TOKEN);       /* Error catcher */}/* * xf86GetToken -- *	Lookup a string if it is actually a token in disguise. */static intgetStringToken(tab)     SymTabRec tab[];{  int i;  for ( i = 0 ; tab[i].token != -1 ; i++ ) {    if ( ! StrCaseCmp(tab[i].name,val.str) ) return tab[i].token;  }  return(ERROR_TOKEN);}/* * getScreenIndex -- *	Given the screen token, returns the index in xf86Screens, or -1 if *	the screen type is not applicable to this server. */static intgetScreenIndex(token)     int token;{  int i;  for (i = 0; xf86ScreenNames[i] >= 0 && xf86ScreenNames[i] != token; i++)    ;  if (xf86ScreenNames[i] < 0)    return(-1);  else    return(i);}/* * validateGraphicsToken -- *	If token is a graphics token, check it is in the list of validTokens * XXXX This needs modifying to work as it did with the old format */static BoolvalidateGraphicsToken(validTokens, token)     int *validTokens;     int token;{  int i;  for (i = 0; ScreenTab[i].token >= 0 && ScreenTab[i].token != token; i++)    ;  if (ScreenTab[i].token < 0)    return(FALSE);        /* Not a graphics token */  for (i = 0; validTokens[i] >= 0 && validTokens[i] != token; i++)    ;  return(validTokens[i] >= 0);}/* * xf86TokenToString -- *	returns the string corresponding to token */char *xf86TokenToString(table, token)     SymTabPtr table;     int token;{  int i;  for (i = 0; table[i].token >= 0 && table[i].token != token; i++)    ;  if (table[i].token < 0)    return("unknown");  else    return(table[i].name);} /* * xf86StringToToken -- *	returns the string corresponding to token */intxf86StringToToken(table, string)     SymTabPtr table;     char *string;{  int i;  for (i = 0; table[i].token >= 0 && StrCaseCmp(string, table[i].name); i++)    ;  return(table[i].token);} /* * xf86ConfigError -- *      Print a READABLE ErrorMessage!!!  All information that is  *      interesting is printed.  Even a pointer to the erroneous place is *      printed.  Maybe our e-mail will be less :-) */#ifdef XF86SETUPintXF86SetupXF86ConfigError(msg)#elsevoidxf86ConfigError(msg)#endif     char *msg;{  int i,j;  ErrorF( "\nConfig Error: %s:%d\n\n%s", configPath, configLineNo, configBuf);  for (i = 1, j = 1; i < configStart; i++, j++)     if (configBuf[i-1] != '\t')      ErrorF(" ");    else      do	ErrorF(" ");      while (((j++)%8) != 0);  for (i = configStart; i <= configPos; i++) ErrorF("^");  ErrorF("\n%s\n", msg);#ifdef NEED_RETURN_VALUE  return RET_ERROR;#else  exit(-1);                 /* simple exit ... */#endif}#ifndef XF86SETUPvoidxf86DeleteMode(infoptr, dispmp)ScrnInfoPtr	infoptr;DisplayModePtr	dispmp;{	if(infoptr->modes == dispmp)		infoptr->modes = dispmp->next;	if(dispmp->next == dispmp)		FatalError("No valid modes found.\n");	ErrorF("%s %s: Removing mode \"%s\" from list of valid modes.\n",	       XCONFIG_PROBED, infoptr->name, dispmp->name);	dispmp->prev->next = dispmp->next;	dispmp->next->prev = dispmp->prev;	xfree(dispmp->name);	xfree(dispmp);}#endif/* * findConfigFile -- * 	Locate the XF86Config file.  Abort if not found. */#ifndef XF86SETUPstatic#endifCONFIG_RETURN_TYPEfindConfigFile(filename, fp)      char *filename;      FILE **fp;{#define configFile (*fp)#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.   */  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] = (char *)xalloc(PATH_MAX);#if !defined(__EMX__) && !defined(OSKIT)    if (getuid() == 0 && xf86ConfigFile[0])#else    if (xf86ConfigFile[0])#endif    {      strcpy(configPaths[pcount], xf86ConfigFile);      if ((configFile = fopen(configPaths[pcount], "r")) != 0)        break;      else        FatalError(             "Cannot read file \"%s\" specified by the -xf86config flag\n",             configPaths[pcount]);    }    /*     * Check if XF86CONFIG is set.     */#if !defined(__EMX__) && !defined(OSKIT)    if (getuid() == 0     && (xconfig = getenv("XF86CONFIG")) != 0     && index(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          FatalError(               "Cannot read file \"%s\" specified by XF86CONFIG variable\n",               configPaths[pcount]);    }     #ifndef __EMX__#ifndef OSKIT    /*     * ~/XF86Config ...     */    if (getuid() == 0 && (home = getenv("HOME"))) {      configPaths[++pcount] = (char *)xalloc(PATH_MAX);      strcpy(configPaths[pcount],home);      strcat(configPaths[pcount],"/XF86Config");      if (xconfig) strcat(configPaths[pcount],xconfig);      if ((configFile = fopen( configPaths[pcount], "r" )) != 0) break;    }#endif /* !OSKIT */        /*     * /etc/XF86Config     */    configPaths[++pcount] = (char *)xalloc(PATH_MAX);    strcpy(configPaths[pcount], "/etc/XF86Config");    if (xconfig) strcat(configPaths[pcount],xconfig);    if ((configFile = fopen( configPaths[pcount], "r" )) != 0) break;#ifndef OSKIT        /*     * $(LIBDIR)/XF86Config.<hostname>     */    configPaths[++pcount] = (char *)xalloc(PATH_MAX);    if (getuid() == 0 && (xwinhome = getenv("XWINHOME")) != NULL)	sprintf(configPaths[pcount], "%s/lib/X11/XF86Config", xwinhome);    else	strcpy(configPaths[pcount], SERVER_CONFIG_FILE);    if (getuid() == 0 && xconfig) strcat(configPaths[pcount],xconfig);    strcat(configPaths[pcount], ".");#ifdef AMOEBA    {      extern char *XServerHostName;      strcat(configPaths[pcount], XServerHostName);    }#else    gethostname(configPaths[pcount]+strlen(configPaths[pcount]),                MAXHOSTNAMELEN);#endif    if ((configFile = fopen( configPaths[pcount], "r" )) != 0) break;#endif /* !OSKIT */#endif /* !__EMX__  */    #ifndef OSKIT    /*     * $(LIBDIR)/XF86Config     */    configPaths[++pcount] = (char *)xalloc(PATH_MAX);#ifndef __EMX__    if (getuid() == 0 && xwinhome)	sprintf(configPaths[pcount], "%s/lib/X11/XF86Config", xwinhome);    else	strcpy(configPaths[pcount], SERVER_CONFIG_FILE);    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) FatalError("X11ROOT environment variable not set\n");    strcpy(configPaths[pcount], __XOS2RedirRoot("/XFree86/lib/X11/XConfig"));#endif    if ((configFile = fopen( configPaths[pcount], "r" )) != 0) break;#endif /* !OSKIT */        ErrorF("\nCould not find config file!\n");    ErrorF("- Tried:\n");    for (idx = 1; idx <= pcount; idx++)        if (configPaths[idx] != NULL)            ErrorF("      %s\n", configPaths[idx]);#ifndef OSKIT    FatalError("No config file found!\n%s", getuid() == 0 ? "" :               "Note, the X server no longer looks for XF86Config in $HOME");#else    FatalError("No config file found!\n%s",                "Note, the X server no longer looks for XF86Config in $HOME");#endif  }  strcpy(filename, configPaths[pcount]);  if (xf86Verbose) {    ErrorF("XF86Config: %s\n", filename);    ErrorF("%s stands for supplied, %s stands for probed/default values\n",       XCONFIG_GIVEN, XCONFIG_PROBED);  }  for (idx = 0; idx <= pcount; idx++)      if (configPaths[idx] != NULL)          xfree(configPaths[idx]);#undef configFile#undef MAXPTRIES#ifdef NEED_RETURN_VALUE  return RET_OKAY;#endif}static DisplayModePtr pNew, pLast;static Bool graphFound = FALSE;/* * xf86GetNearestClock -- *	Find closest clock to given frequency (in kHz).  This assumes the *	number of clocks is greater than zero. */intxf86GetNearestClock(Screen, Frequency)	ScrnInfoPtr Screen;	int Frequency;{  int NearestClock = 0;  int MinimumGap = abs(Frequency - Screen->clock[0]);  int i;  for (i = 1;  i < Screen->clocks;  i++)  {    int Gap = abs(Frequency - Screen->clock[i]);    if (Gap < MinimumGap)    {      MinimumGap = Gap;      NearestClock = i;    }  }  return NearestClock;}/* * xf86Config -- *	Fill some internal structure with userdefined setups. Many internal *      Structs are initialized.  The drivers are selected and initialized. *	if (! vtopen), XF86Config is read, but devices are not probed. *	if (vtopen), devices are probed (and modes resolved). *	The vtopen argument was added so that XF86Config information could be *	made available before the VT is opened. */CONFIG_RETURN_TYPExf86Config (vtopen)     int vtopen;{  int            token;  int            i, j;#if defined(SYSV) || defined(linux)  int            xcpipe[2];#endif#ifdef XINPUT  LocalDevicePtr	local;#endif   if (!vtopen) {  OFLG_ZERO(&GenericXF86ConfigFlag);  configBuf  = (char*)xalloc(CONFIG_BUF_LEN);  configRBuf = (char*)xalloc(CONFIG_BUF_LEN);  configPath = (char*)xalloc(PATH_MAX);    configBuf[0] = '\0';                    /* sanity ... */  /*   * Read the XF86Config file with the real uid to avoid security problems   *   * For SYSV we fork, and send the data back to the parent through a pipe   */#if defined(SYSV) || defined(linux)  if (getuid() != 0) {    if (pipe(xcpipe))      FatalError("Pipe failed (%s)\n", strerror(errno));    switch (fork()) {      case -1:        FatalError("Fork failed (%s)\n", strerror(errno));        break;      case 0:   /* child */        close(xcpipe[0]);        setuid(getuid());          HANDLE_RETURN(findConfigFile(configPath, &configFile));        {          unsigned char pbuf[CONFIG_BUF_LEN];

⌨️ 快捷键说明

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