static void collectstring (lua_State *L, TString *ts) { int r = delstr(L, &L->strt, ts); LUA_ASSERT(r, "fail to collect a string"); }
void parse_config() { #define bufsize 1024 char buf[bufsize] = {0}; if (strlen(g_settings.cfgpath) == 0) { return; } FILE *fp = fopen(g_settings.cfgpath, "r+"); if (!fp) { return; } while (fgets(buf, bufsize, fp) != NULL) { buf[strlen(buf) - 1] = '\0'; if (buf[strlen(buf) - 1] == '\r') { buf[strlen(buf) - 1] = '\0'; } char *split = (char *)" \t"; delstr(buf, split); if (strlen(buf) == 0 || *buf == '#') { continue; } char equal = '='; char *result[MAX_KEYWORD_LENGTH]; int size; parse_string_fast(buf, &equal, result, &size); if (size != 2) { continue; } #define set_config_int(str, param) do{ \ if(!strncmp(str, result[0], strlen(str))) \ g_settings.param = (int)atoi(result[1]);\ } while(0) #define set_config_short(str, param) do{ \ if(!strncmp(str, result[0], strlen(str))) \ g_settings.param = (short)atoi(result[1]);\ } while(0) #define set_config_str(str, param) do{ \ if(!strncmp(str, result[0], strlen(str))) \ { \ g_settings.param = strdup(result[1]); \ } \ } while(0) set_config_str("username", username); set_config_str("pidfile", pidfile); set_config_str("unixpath", socketpath); set_config_int("port", port); set_config_int("verbose", verbose); set_config_int("maxconn", maxconns); set_config_int("verbose", verbose); set_config_int("threads", num_threads); set_config_int("backlog", backlog); set_config_int("max_requests", reqs_per_event); set_config_str("chinese_map_file", chinese_map_file); set_config_str("index_file", index_path); set_config_int("max_depth", max_depth); set_config_str("log_path", log_path); set_config_str("log_level", log_level); set_config_short("monitor_port", monitor_port); set_config_int("monitor_timeout", monitor_timeout); } fclose(fp); return; #undef set_config_int #undef set_config_short #undef set_config_str }