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; }
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; }
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); }