static XF86ConfScreenPtr configureScreenSection (int screennum) { int i; int depths[] = { 1, 4, 8, 15, 16, 24/*, 32*/ }; parsePrologue (XF86ConfScreenPtr, XF86ConfScreenRec) ptr->scrn_identifier = xf86confmalloc(18); sprintf(ptr->scrn_identifier, "Screen%d", screennum); ptr->scrn_monitor_str = xf86confmalloc(19); sprintf(ptr->scrn_monitor_str, "Monitor%d", screennum); ptr->scrn_device_str = xf86confmalloc(16); sprintf(ptr->scrn_device_str, "Card%d", screennum); for (i=0; i<sizeof(depths)/sizeof(depths[0]); i++) { XF86ConfDisplayPtr display; display = xf86confmalloc(sizeof(XF86ConfDisplayRec)); memset((XF86ConfDisplayPtr)display,0,sizeof(XF86ConfDisplayRec)); display->disp_depth = depths[i]; display->disp_black.red = display->disp_white.red = -1; display->disp_black.green = display->disp_white.green = -1; display->disp_black.blue = display->disp_white.blue = -1; ptr->scrn_display_lst = (XF86ConfDisplayPtr)xf86addListItem( (glp)ptr->scrn_display_lst, (glp)display); } return ptr; }
static XF86ConfLayoutPtr configureLayoutSection (void) { int scrnum = 0; parsePrologue (XF86ConfLayoutPtr, XF86ConfLayoutRec) ptr->lay_identifier = "X.org Configured"; { XF86ConfInputrefPtr iptr; iptr = xf86confmalloc (sizeof (XF86ConfInputrefRec)); iptr->list.next = NULL; iptr->iref_option_lst = NULL; iptr->iref_inputdev_str = "Mouse0"; iptr->iref_option_lst = xf86addNewOption (iptr->iref_option_lst, xstrdup("CorePointer"), NULL); ptr->lay_input_lst = (XF86ConfInputrefPtr) xf86addListItem ((glp) ptr->lay_input_lst, (glp) iptr); } { XF86ConfInputrefPtr iptr; iptr = xf86confmalloc (sizeof (XF86ConfInputrefRec)); iptr->list.next = NULL; iptr->iref_option_lst = NULL; iptr->iref_inputdev_str = "Keyboard0"; iptr->iref_option_lst = xf86addNewOption (iptr->iref_option_lst, xstrdup("CoreKeyboard"), NULL); ptr->lay_input_lst = (XF86ConfInputrefPtr) xf86addListItem ((glp) ptr->lay_input_lst, (glp) iptr); } for (scrnum = 0; scrnum < nDevToConfig; scrnum++) { XF86ConfAdjacencyPtr aptr; aptr = xf86confmalloc (sizeof (XF86ConfAdjacencyRec)); aptr->list.next = NULL; aptr->adj_x = 0; aptr->adj_y = 0; aptr->adj_scrnum = scrnum; aptr->adj_screen_str = xnfalloc(18); sprintf(aptr->adj_screen_str, "Screen%d", scrnum); if (scrnum == 0) { aptr->adj_where = CONF_ADJ_ABSOLUTE; aptr->adj_refscreen = NULL; } else { aptr->adj_where = CONF_ADJ_RIGHTOF; aptr->adj_refscreen = xnfalloc(18); sprintf(aptr->adj_refscreen, "Screen%d", scrnum - 1); } ptr->lay_adjacency_lst = (XF86ConfAdjacencyPtr)xf86addListItem((glp)ptr->lay_adjacency_lst, (glp)aptr); } return ptr; }
char * xf86configStrdup (const char *s) { char *tmp; if (!s) return NULL; tmp = xf86confmalloc (sizeof (char) * (strlen (s) + 1)); if (tmp) strcpy (tmp, s); return (tmp); }
static XF86ConfInputPtr configureInputSection (void) { XF86ConfInputPtr mouse = NULL; parsePrologue (XF86ConfInputPtr, XF86ConfInputRec) ptr->inp_identifier = "Keyboard0"; ptr->inp_driver = "kbd"; ptr->list.next = NULL; /* Crude mechanism to auto-detect mouse (os dependent) */ { int fd; #ifdef WSCONS_SUPPORT fd = open("/dev/wsmouse", 0); if (fd > 0) { DFLT_MOUSE_DEV = "/dev/wsmouse"; DFLT_MOUSE_PROTO = "wsmouse"; close(fd); } else { ErrorF("cannot open /dev/wsmouse\n"); } #endif #ifndef __SCO__ fd = open(DFLT_MOUSE_DEV, 0); if (fd != -1) { foundMouse = TRUE; close(fd); } #else foundMouse = TRUE; #endif } mouse = xf86confmalloc(sizeof(XF86ConfInputRec)); memset((XF86ConfInputPtr)mouse,0,sizeof(XF86ConfInputRec)); mouse->inp_identifier = "Mouse0"; mouse->inp_driver = "mouse"; mouse->inp_option_lst = xf86addNewOption(mouse->inp_option_lst, xstrdup("Protocol"), xstrdup(DFLT_MOUSE_PROTO)); #ifndef __SCO__ mouse->inp_option_lst = xf86addNewOption(mouse->inp_option_lst, xstrdup("Device"), xstrdup(DFLT_MOUSE_DEV)); #endif mouse->inp_option_lst = xf86addNewOption(mouse->inp_option_lst, xstrdup("ZAxisMapping"), xstrdup("4 5 6 7")); ptr = (XF86ConfInputPtr)xf86addListItem((glp)ptr, (glp)mouse); return ptr; }
XF86ConfInputPtr xf86parsePointerSection (void) { char *s, *s1, *s2; int l; int token; parsePrologue (XF86ConfInputPtr, XF86ConfInputRec) while ((token = xf86getToken (PointerTab)) != ENDSECTION) { switch (token) { case COMMENT: ptr->inp_comment = xf86addComment(ptr->inp_comment, val.str); break; case PROTOCOL: if (xf86getSubToken (&(ptr->inp_comment)) != STRING) Error (QUOTE_MSG, "Protocol"); ptr->inp_option_lst = xf86addNewOption(ptr->inp_option_lst, xf86configStrdup("Protocol"), val.str); break; case PDEVICE: if (xf86getSubToken (&(ptr->inp_comment)) != STRING) Error (QUOTE_MSG, "Device"); ptr->inp_option_lst = xf86addNewOption(ptr->inp_option_lst, xf86configStrdup("Device"), val.str); break; case EMULATE3: ptr->inp_option_lst = xf86addNewOption(ptr->inp_option_lst, xf86configStrdup("Emulate3Buttons"), NULL); break; case EM3TIMEOUT: if (xf86getSubToken (&(ptr->inp_comment)) != NUMBER || val.num < 0) Error (POSITIVE_INT_MSG, "Emulate3Timeout"); s = xf86uLongToString(val.num); ptr->inp_option_lst = xf86addNewOption(ptr->inp_option_lst, xf86configStrdup("Emulate3Timeout"), s); break; case CHORDMIDDLE: ptr->inp_option_lst = xf86addNewOption(ptr->inp_option_lst, xf86configStrdup("ChordMiddle"), NULL); break; case PBUTTONS: if (xf86getSubToken (&(ptr->inp_comment)) != NUMBER || val.num < 0) Error (POSITIVE_INT_MSG, "Buttons"); s = xf86uLongToString(val.num); ptr->inp_option_lst = xf86addNewOption(ptr->inp_option_lst, xf86configStrdup("Buttons"), s); break; case BAUDRATE: if (xf86getSubToken (&(ptr->inp_comment)) != NUMBER || val.num < 0) Error (POSITIVE_INT_MSG, "BaudRate"); s = xf86uLongToString(val.num); ptr->inp_option_lst = xf86addNewOption(ptr->inp_option_lst, xf86configStrdup("BaudRate"), s); break; case SAMPLERATE: if (xf86getSubToken (&(ptr->inp_comment)) != NUMBER || val.num < 0) Error (POSITIVE_INT_MSG, "SampleRate"); s = xf86uLongToString(val.num); ptr->inp_option_lst = xf86addNewOption(ptr->inp_option_lst, xf86configStrdup("SampleRate"), s); break; case PRESOLUTION: if (xf86getSubToken (&(ptr->inp_comment)) != NUMBER || val.num < 0) Error (POSITIVE_INT_MSG, "Resolution"); s = xf86uLongToString(val.num); ptr->inp_option_lst = xf86addNewOption(ptr->inp_option_lst, xf86configStrdup("Resolution"), s); break; case CLEARDTR: ptr->inp_option_lst = xf86addNewOption(ptr->inp_option_lst, xf86configStrdup("ClearDTR"), NULL); break; case CLEARRTS: ptr->inp_option_lst = xf86addNewOption(ptr->inp_option_lst, xf86configStrdup("ClearRTS"), NULL); break; case ZAXISMAPPING: switch (xf86getToken(ZMapTab)) { case NUMBER: if (val.num < 0) Error (ZAXISMAPPING_MSG, NULL); s1 = xf86uLongToString(val.num); if (xf86getSubToken (&(ptr->inp_comment)) != NUMBER || val.num < 0) { xf86conffree(s1); Error (ZAXISMAPPING_MSG, NULL); } s2 = xf86uLongToString(val.num); l = strlen(s1) + 1 + strlen(s2) + 1; s = xf86confmalloc(l); sprintf(s, "%s %s", s1, s2); xf86conffree(s1); xf86conffree(s2); break; case XAXIS: s = xf86configStrdup("x"); break; case YAXIS: s = xf86configStrdup("y"); break; default: Error (ZAXISMAPPING_MSG, NULL); break; } ptr->inp_option_lst = xf86addNewOption(ptr->inp_option_lst, xf86configStrdup("ZAxisMapping"), s); break; case ALWAYSCORE: break; case EOF_TOKEN: Error (UNEXPECTED_EOF_MSG, NULL); break; default: Error (INVALID_KEYWORD_MSG, xf86tokenString ()); break; } } ptr->inp_identifier = xf86configStrdup(CONF_IMPLICIT_POINTER); ptr->inp_driver = xf86configStrdup("mouse"); ptr->inp_option_lst = xf86addNewOption(ptr->inp_option_lst, xf86configStrdup("CorePointer"), NULL); #ifdef DEBUG printf ("Pointer section parsed\n"); #endif return ptr; }
static XF86ConfDevicePtr configureDeviceSection (int screennum) { char identifier[16]; OptionInfoPtr p; int i = 0; #ifdef DO_FBDEV_PROBE Bool foundFBDEV = FALSE; #endif parsePrologue (XF86ConfDevicePtr, XF86ConfDeviceRec) /* Move device info to parser structure */ sprintf(identifier, "Card%d", screennum); ptr->dev_identifier = strdup(identifier); /* ptr->dev_identifier = DevToConfig[screennum].GDev.identifier;*/ ptr->dev_vendor = DevToConfig[screennum].GDev.vendor; ptr->dev_board = DevToConfig[screennum].GDev.board; ptr->dev_chipset = DevToConfig[screennum].GDev.chipset; ptr->dev_busid = DevToConfig[screennum].GDev.busID; ptr->dev_driver = DevToConfig[screennum].GDev.driver; ptr->dev_ramdac = DevToConfig[screennum].GDev.ramdac; for (i = 0; (i < MAXDACSPEEDS) && (i < CONF_MAXDACSPEEDS); i++) ptr->dev_dacSpeeds[i] = DevToConfig[screennum].GDev.dacSpeeds[i]; ptr->dev_videoram = DevToConfig[screennum].GDev.videoRam; ptr->dev_textclockfreq = DevToConfig[screennum].GDev.textClockFreq; ptr->dev_bios_base = DevToConfig[screennum].GDev.BiosBase; ptr->dev_mem_base = DevToConfig[screennum].GDev.MemBase; ptr->dev_io_base = DevToConfig[screennum].GDev.IOBase; ptr->dev_clockchip = DevToConfig[screennum].GDev.clockchip; for (i = 0; (i < MAXCLOCKS) && (i < DevToConfig[screennum].GDev.numclocks); i++) ptr->dev_clock[i] = DevToConfig[screennum].GDev.clock[i]; ptr->dev_clocks = i; ptr->dev_chipid = DevToConfig[screennum].GDev.chipID; ptr->dev_chiprev = DevToConfig[screennum].GDev.chipRev; ptr->dev_irq = DevToConfig[screennum].GDev.irq; /* Make sure older drivers don't segv */ if (DevToConfig[screennum].GDev.options) { /* Fill in the available driver options for people to use */ const char *descrip = " ### Available Driver options are:-\n" " ### Values: <i>: integer, <f>: float, " "<bool>: \"True\"/\"False\",\n" " ### <string>: \"String\", <freq>: \"<f> Hz/kHz/MHz\"\n" " ### [arg]: arg optional\n"; ptr->dev_comment = xstrdup(descrip); if (ptr->dev_comment) { for (p = DevToConfig[screennum].GDev.options; p->name != NULL; p++) { char *p_e; const char *prefix = " #Option "; const char *middle = " \t# "; const char *suffix = "\n"; const char *opttype = optionTypeToSting(p->type); char *optname; int len = strlen(ptr->dev_comment) + strlen(prefix) + strlen(middle) + strlen(suffix) + 1; optname = xalloc(strlen(p->name) + 2 + 1); if (!optname) break; sprintf(optname, "\"%s\"", p->name); len += max(20, strlen(optname)); len += strlen(opttype); ptr->dev_comment = xrealloc(ptr->dev_comment, len); if (!ptr->dev_comment) break; p_e = ptr->dev_comment + strlen(ptr->dev_comment); sprintf(p_e, "%s%-20s%s%s%s", prefix, optname, middle, opttype, suffix); xfree(optname); } } } #ifdef DO_FBDEV_PROBE /* Crude mechanism to auto-detect fbdev (os dependent) */ /* Skip it for now. Options list it anyway, and we can't * determine which screen/driver this belongs too anyway. */ { int fd; fd = open("/dev/fb0", 0); if (fd != -1) { foundFBDEV = TRUE; close(fd); } } if (foundFBDEV) { XF86OptionPtr fbdev; fbdev = xf86confmalloc(sizeof(XF86OptionRec)); memset((XF86OptionPtr)fbdev,0,sizeof(XF86OptionRec)); fbdev->opt_name = "UseFBDev"; fbdev->opt_val = "ON"; ptr->dev_option_lst = (XF86OptionPtr)xf86addListItem( (glp)ptr->dev_option_lst, (glp)fbdev); } #endif return ptr; }
XF86ConfFilesPtr xf86parseFilesSection (void) { int i, j; int k, l; char *str; int token; parsePrologue (XF86ConfFilesPtr, XF86ConfFilesRec) while ((token = xf86getToken (FilesTab)) != ENDSECTION) { switch (token) { case COMMENT: ptr->file_comment = xf86addComment(ptr->file_comment, val.str); break; case FONTPATH: if (xf86getSubToken (&(ptr->file_comment)) != STRING) Error (QUOTE_MSG, "FontPath"); j = FALSE; str = prependRoot (val.str); if (ptr->file_fontpath == NULL) { ptr->file_fontpath = xf86confmalloc (1); ptr->file_fontpath[0] = '\0'; i = strlen (str) + 1; } else { i = strlen (ptr->file_fontpath) + strlen (str) + 1; if (ptr->file_fontpath[strlen (ptr->file_fontpath) - 1] != ',') { i++; j = TRUE; } } ptr->file_fontpath = xf86confrealloc (ptr->file_fontpath, i); if (j) strcat (ptr->file_fontpath, ","); strcat (ptr->file_fontpath, str); xf86conffree (val.str); break; case RGBPATH: if (xf86getSubToken (&(ptr->file_comment)) != STRING) Error (QUOTE_MSG, "RGBPath"); ptr->file_rgbpath = val.str; break; case MODULEPATH: if (xf86getSubToken (&(ptr->file_comment)) != STRING) Error (QUOTE_MSG, "ModulePath"); l = FALSE; str = prependRoot (val.str); if (ptr->file_modulepath == NULL) { ptr->file_modulepath = xf86confmalloc (1); ptr->file_modulepath[0] = '\0'; k = strlen (str) + 1; } else { k = strlen (ptr->file_modulepath) + strlen (str) + 1; if (ptr->file_modulepath[strlen (ptr->file_modulepath) - 1] != ',') { k++; l = TRUE; } } ptr->file_modulepath = xf86confrealloc (ptr->file_modulepath, k); if (l) strcat (ptr->file_modulepath, ","); strcat (ptr->file_modulepath, str); xf86conffree (val.str); break; case INPUTDEVICES: if (xf86getSubToken (&(ptr->file_comment)) != STRING) Error (QUOTE_MSG, "InputDevices"); l = FALSE; str = prependRoot (val.str); if (ptr->file_inputdevs == NULL) { ptr->file_inputdevs = xf86confmalloc (1); ptr->file_inputdevs[0] = '\0'; k = strlen (str) + 1; } else { k = strlen (ptr->file_inputdevs) + strlen (str) + 1; if (ptr->file_inputdevs[strlen (ptr->file_inputdevs) - 1] != ',') { k++; l = TRUE; } } ptr->file_inputdevs = xf86confrealloc (ptr->file_inputdevs, k); if (l) strcat (ptr->file_inputdevs, ","); strcat (ptr->file_inputdevs, str); xf86conffree (val.str); break; case LOGFILEPATH: if (xf86getSubToken (&(ptr->file_comment)) != STRING) Error (QUOTE_MSG, "LogFile"); ptr->file_logfile = val.str; break; case EOF_TOKEN: Error (UNEXPECTED_EOF_MSG, NULL); break; default: Error (INVALID_KEYWORD_MSG, xf86tokenString ()); break; } } #ifdef DEBUG printf ("File section parsed\n"); #endif return ptr; }
XF86ConfInputPtr xf86parseKeyboardSection (void) { char *s, *s1, *s2; int l; int token, ntoken; parsePrologue (XF86ConfInputPtr, XF86ConfInputRec) while ((token = xf86getToken (KeyboardTab)) != ENDSECTION) { switch (token) { case COMMENT: ptr->inp_comment = xf86addComment(ptr->inp_comment, val.str); break; case KPROTOCOL: if (xf86getSubToken (&(ptr->inp_comment)) != STRING) Error (QUOTE_MSG, "Protocol"); ptr->inp_option_lst = xf86addNewOption(ptr->inp_option_lst, xf86configStrdup("Protocol"), val.str); break; case AUTOREPEAT: if (xf86getSubToken (&(ptr->inp_comment)) != NUMBER) Error (AUTOREPEAT_MSG, NULL); s1 = xf86uLongToString(val.num); if (xf86getSubToken (&(ptr->inp_comment)) != NUMBER) Error (AUTOREPEAT_MSG, NULL); s2 = xf86uLongToString(val.num); l = strlen(s1) + 1 + strlen(s2) + 1; s = xf86confmalloc(l); sprintf(s, "%s %s", s1, s2); xf86conffree(s1); xf86conffree(s2); ptr->inp_option_lst = xf86addNewOption(ptr->inp_option_lst, xf86configStrdup("AutoRepeat"), s); break; case XLEDS: if (xf86getSubToken (&(ptr->inp_comment)) != NUMBER) Error (XLEDS_MSG, NULL); s = xf86uLongToString(val.num); l = strlen(s) + 1; while ((token = xf86getSubToken (&(ptr->inp_comment))) == NUMBER) { s1 = xf86uLongToString(val.num); l += (1 + strlen(s1)); s = xf86confrealloc(s, l); strcat(s, " "); strcat(s, s1); xf86conffree(s1); } xf86unGetToken (token); break; case SERVERNUM: xf86parseWarning(OBSOLETE_MSG, xf86tokenString()); break; case LEFTALT: case RIGHTALT: case SCROLLLOCK_TOK: case RIGHTCTL: xf86parseWarning(OBSOLETE_MSG, xf86tokenString()); break; ntoken = xf86getToken (KeyMapTab); switch (ntoken) { case EOF_TOKEN: xf86parseError (UNEXPECTED_EOF_MSG); CLEANUP (ptr); return (NULL); break; default: Error (INVALID_KEYWORD_MSG, xf86tokenString ()); break; } break; case VTINIT: if (xf86getSubToken (&(ptr->inp_comment)) != STRING) Error (QUOTE_MSG, "VTInit"); xf86parseWarning(MOVED_TO_FLAGS_MSG, "VTInit"); break; case VTSYSREQ: xf86parseWarning(MOVED_TO_FLAGS_MSG, "VTSysReq"); break; case XKBDISABLE: ptr->inp_option_lst = xf86addNewOption(ptr->inp_option_lst, xf86configStrdup("XkbDisable"), NULL); break; case XKBKEYMAP: if (xf86getSubToken (&(ptr->inp_comment)) != STRING) Error (QUOTE_MSG, "XKBKeymap"); ptr->inp_option_lst = xf86addNewOption(ptr->inp_option_lst, xf86configStrdup("XkbKeymap"), val.str); break; case XKBCOMPAT: if (xf86getSubToken (&(ptr->inp_comment)) != STRING) Error (QUOTE_MSG, "XKBCompat"); ptr->inp_option_lst = xf86addNewOption(ptr->inp_option_lst, xf86configStrdup("XkbCompat"), val.str); break; case XKBTYPES: if (xf86getSubToken (&(ptr->inp_comment)) != STRING) Error (QUOTE_MSG, "XKBTypes"); ptr->inp_option_lst = xf86addNewOption(ptr->inp_option_lst, xf86configStrdup("XkbTypes"), val.str); break; case XKBKEYCODES: if (xf86getSubToken (&(ptr->inp_comment)) != STRING) Error (QUOTE_MSG, "XKBKeycodes"); ptr->inp_option_lst = xf86addNewOption(ptr->inp_option_lst, xf86configStrdup("XkbKeycodes"), val.str); break; case XKBGEOMETRY: if (xf86getSubToken (&(ptr->inp_comment)) != STRING) Error (QUOTE_MSG, "XKBGeometry"); ptr->inp_option_lst = xf86addNewOption(ptr->inp_option_lst, xf86configStrdup("XkbGeometry"), val.str); break; case XKBSYMBOLS: if (xf86getSubToken (&(ptr->inp_comment)) != STRING) Error (QUOTE_MSG, "XKBSymbols"); ptr->inp_option_lst = xf86addNewOption(ptr->inp_option_lst, xf86configStrdup("XkbSymbols"), val.str); break; case XKBRULES: if (xf86getSubToken (&(ptr->inp_comment)) != STRING) Error (QUOTE_MSG, "XKBRules"); ptr->inp_option_lst = xf86addNewOption(ptr->inp_option_lst, xf86configStrdup("XkbRules"), val.str); break; case XKBMODEL: if (xf86getSubToken (&(ptr->inp_comment)) != STRING) Error (QUOTE_MSG, "XKBModel"); ptr->inp_option_lst = xf86addNewOption(ptr->inp_option_lst, xf86configStrdup("XkbModel"), val.str); break; case XKBLAYOUT: if (xf86getSubToken (&(ptr->inp_comment)) != STRING) Error (QUOTE_MSG, "XKBLayout"); ptr->inp_option_lst = xf86addNewOption(ptr->inp_option_lst, xf86configStrdup("XkbLayout"), val.str); break; case XKBVARIANT: if (xf86getSubToken (&(ptr->inp_comment)) != STRING) Error (QUOTE_MSG, "XKBVariant"); ptr->inp_option_lst = xf86addNewOption(ptr->inp_option_lst, xf86configStrdup("XkbVariant"), val.str); break; case XKBOPTIONS: if (xf86getSubToken (&(ptr->inp_comment)) != STRING) Error (QUOTE_MSG, "XKBOptions"); ptr->inp_option_lst = xf86addNewOption(ptr->inp_option_lst, xf86configStrdup("XkbOptions"), val.str); break; case PANIX106: ptr->inp_option_lst = xf86addNewOption(ptr->inp_option_lst, xf86configStrdup("Panix106"), NULL); break; case EOF_TOKEN: Error (UNEXPECTED_EOF_MSG, NULL); break; default: Error (INVALID_KEYWORD_MSG, xf86tokenString ()); break; } } ptr->inp_identifier = xf86configStrdup(CONF_IMPLICIT_KEYBOARD); ptr->inp_driver = xf86configStrdup("keyboard"); ptr->inp_option_lst = xf86addNewOption(ptr->inp_option_lst, xf86configStrdup("CoreKeyboard"), NULL); #ifdef DEBUG printf ("Keyboard section parsed\n"); #endif return ptr; }
XF86ConfFlagsPtr xf86parseFlagsSection (void) { int has_ident = FALSE; int token; parsePrologue (XF86ConfFlagsPtr, XF86ConfFlagsRec) while ((token = xf86getToken (ServerFlagsTab)) != ENDSECTION) { int hasvalue = FALSE; int strvalue = FALSE; int tokentype; switch (token) { case COMMENT: ptr->flg_comment = xf86addComment(ptr->flg_comment, val.str); break; case IDENTIFIER: if (xf86getSubToken (&(ptr->flg_comment)) != STRING) Error (QUOTE_MSG, "Identifier"); if (has_ident) Error (MULTIPLE_MSG, "Identifier"); ptr->flg_identifier = val.str; has_ident = TRUE; break; /* * These old keywords are turned into standard generic options. * We fall through here on purpose. */ case DEFAULTLAYOUT: strvalue = TRUE; case BLANKTIME: case STANDBYTIME: case SUSPENDTIME: case OFFTIME: hasvalue = TRUE; case NOTRAPSIGNALS: case DONTZAP: case DONTZOOM: case DISABLEVIDMODE: case ALLOWNONLOCAL: case DISABLEMODINDEV: case MODINDEVALLOWNONLOCAL: case ALLOWMOUSEOPENFAIL: { int i = 0; while (ServerFlagsTab[i].token != -1) { char *tmp; if (ServerFlagsTab[i].token == token) { char *valstr = NULL; /* can't use strdup because it calls malloc */ tmp = xf86configStrdup (ServerFlagsTab[i].name); if (hasvalue) { tokentype = xf86getSubToken(&(ptr->flg_comment)); if (strvalue) { if (tokentype != STRING) Error (QUOTE_MSG, tmp); valstr = val.str; } else { if (tokentype != NUMBER) Error (NUMBER_MSG, tmp); valstr = xf86confmalloc(16); if (valstr) sprintf(valstr, "%d", val.num); } } ptr->flg_option_lst = xf86addNewOption (ptr->flg_option_lst, tmp, valstr); } i++; } } break; case OPTION: ptr->flg_option_lst = xf86parseOption(ptr->flg_option_lst); break; case EOF_TOKEN: Error (UNEXPECTED_EOF_MSG, NULL); break; default: Error (INVALID_KEYWORD_MSG, xf86tokenString ()); break; } } #ifdef DEBUG printf ("Flags section parsed\n"); #endif return ptr; }
static XF86ConfInputPtr configureInputSection (void) { XF86ConfInputPtr mouse = NULL; parsePrologue (XF86ConfInputPtr, XF86ConfInputRec) ptr->inp_identifier = "Keyboard0"; #ifdef USE_DEPRECATED_KEYBOARD_DRIVER ptr->inp_driver = "keyboard"; #else ptr->inp_driver = "kbd"; #endif ptr->list.next = NULL; /* Crude mechanism to auto-detect mouse (os dependent) */ { int fd; #if 0 && defined linux /* Our autodetection code can do a better job */ int len; char path[32]; if ((len = readlink(DFLT_MOUSE_DEV, path, sizeof(path) - 1)) > 0) { path[len] = '\0'; if (strstr(path, "psaux") != NULL) DFLT_MOUSE_PROTO = "PS/2"; } #endif #ifdef WSCONS_SUPPORT fd = open("/dev/wsmouse", 0); if (fd > 0) { DFLT_MOUSE_DEV = "/dev/wsmouse"; DFLT_MOUSE_PROTO = "wsmouse"; close(fd); } else { ErrorF("cannot open /dev/wsmouse\n"); } #endif #ifndef __SCO__ fd = open(DFLT_MOUSE_DEV, 0); if (fd != -1) { foundMouse = TRUE; close(fd); } #else foundMouse = TRUE; #endif } mouse = xf86confmalloc(sizeof(XF86ConfInputRec)); memset((XF86ConfInputPtr)mouse,0,sizeof(XF86ConfInputRec)); mouse->inp_identifier = "Mouse0"; mouse->inp_driver = "mouse"; mouse->inp_option_lst = xf86addNewOption(mouse->inp_option_lst, "Protocol", DFLT_MOUSE_PROTO); #ifndef __SCO__ mouse->inp_option_lst = xf86addNewOption(mouse->inp_option_lst, "Device", DFLT_MOUSE_DEV); #endif mouse->inp_option_lst = xf86addNewOption(mouse->inp_option_lst, "ZAxisMapping", "4 5 6 7"); ptr = (XF86ConfInputPtr)xf86addListItem((glp)ptr, (glp)mouse); return ptr; }
/* * xf86getToken -- * Read next Token from the config file. Handle the global variable * pushToken. */ int xf86getToken (xf86ConfigSymTabRec * 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 * oth * case the next token must be read from the input. */ if (pushToken == EOF_TOKEN) return (EOF_TOKEN); else if (pushToken == LOCK_TOKEN) { /* * eol_seen is only set for the first token after a newline. */ eol_seen = 0; c = configBuf[configPos]; /* * Get start of next Token. EOF is handled, * whitespaces are skipped. */ again: if (!c) { char *ret; if (configFile) ret = xf86getNextLine(); else { if (builtinConfig[builtinIndex] == NULL) ret = NULL; else { ret = strncpy(configBuf, builtinConfig[builtinIndex], CONFIG_BUF_LEN); builtinIndex++; } } if (ret == NULL) { return (pushToken = EOF_TOKEN); } configLineNo++; configPos = 0; eol_seen = 1; } i = 0; for (;;) { c = configBuf[configPos++]; configRBuf[i++] = c; switch (c) { case ' ': case '\t': case '\r': continue; case '\n': i = 0; continue; } break; } if (c == '\0') goto again; if (c == '#') { do { configRBuf[i++] = (c = configBuf[configPos++]); } while ((c != '\n') && (c != '\r') && (c != '\0')); configRBuf[i] = '\0'; /* XXX no private copy. * Use xf86addComment when setting a comment. */ val.str = configRBuf; return (COMMENT); } /* GJA -- handle '-' and ',' * Be careful: "-hsync" is a keyword. */ else if ((c == ',') && !isalpha (configBuf[configPos])) { return COMMA; } else if ((c == '-') && !isalpha (configBuf[configPos])) { return DASH; } /* * Numbers are returned immediately ... */ if (isdigit (c)) { int base; if (c == '0') if ((configBuf[configPos] == 'x') || (configBuf[configPos] == 'X')) { base = 16; val.numType = PARSE_HEX; } else { base = 8; val.numType = PARSE_OCTAL; } else { base = 10; val.numType = PARSE_DECIMAL; } configRBuf[0] = c; i = 1; while (isdigit (c = configBuf[configPos++]) || (c == '.') || (c == 'x') || (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 = xf86strToUL (configRBuf); val.realnum = atof (configRBuf); return (NUMBER); } /* * All Strings START with a \" ... */ else if (c == '\"') { i = -1; do { configRBuf[++i] = (c = configBuf[configPos++]); } while ((c != '\"') && (c != '\n') && (c != '\r') && (c != '\0')); configRBuf[i] = '\0'; val.str = xf86confmalloc (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++]); } while ((c != ' ') && (c != '\t') && (c != '\n') && (c != '\r') && (c != '\0') && (c != '#')); --configPos; 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 (xf86nameCompare (configRBuf, tab[i].name) == 0) return (tab[i].token); else i++; } return (ERROR_TOKEN); /* Error catcher */ }
static char* xf86getNextLine(void) { static int configBufLen = CONFIG_BUF_LEN; char *tmpConfigBuf, *tmpConfigRBuf; int c, i, pos = 0, eolFound = 0; char *ret = NULL; /* * reallocate the string if it was grown last time (i.e., is no * longer CONFIG_BUF_LEN); we malloc the new strings first, so * that if either of the mallocs fail, we can fall back on the * existing buffer allocations */ if (configBufLen != CONFIG_BUF_LEN) { tmpConfigBuf = xf86confmalloc(CONFIG_BUF_LEN); tmpConfigRBuf = xf86confmalloc(CONFIG_BUF_LEN); if (!tmpConfigBuf || !tmpConfigRBuf) { /* * at least one of the mallocs failed; keep the old buffers * and free any partial allocations */ xf86conffree(tmpConfigBuf); xf86conffree(tmpConfigRBuf); } else { /* * malloc succeeded; free the old buffers and use the new * buffers */ configBufLen = CONFIG_BUF_LEN; xf86conffree(configBuf); xf86conffree(configRBuf); configBuf = tmpConfigBuf; configRBuf = tmpConfigRBuf; } } /* read in another block of chars */ do { ret = fgets(configBuf + pos, configBufLen - pos - 1, configFile); if (!ret) break; /* search for EOL in the new block of chars */ for (i = pos; i < (configBufLen - 1); i++) { c = configBuf[i]; if (c == '\0') break; if ((c == '\n') || (c == '\r')) { eolFound = 1; break; } } /* * if we didn't find EOL, then grow the string and * read in more */ if (!eolFound) { tmpConfigBuf = xf86confrealloc(configBuf, configBufLen + CONFIG_BUF_LEN); tmpConfigRBuf = xf86confrealloc(configRBuf, configBufLen + CONFIG_BUF_LEN); if (!tmpConfigBuf || !tmpConfigRBuf) { /* * at least one of the reallocations failed; use the * new allocation that succeeded, but we have to * fallback to the previous configBufLen size and use * the string we have, even though we don't have an * EOL */ if (tmpConfigBuf) configBuf = tmpConfigBuf; if (tmpConfigRBuf) configRBuf = tmpConfigRBuf; break; } else { /* reallocation succeeded */ configBuf = tmpConfigBuf; configRBuf = tmpConfigRBuf; pos = i; configBufLen += CONFIG_BUF_LEN; } } } while (!eolFound); return (ret); }