void verlet(const char* filename){ dictionary* ini; ini = iniparser_load(filename); iniparser_dump(ini, stdout); FILE *file; file = fopen(LOGFILE, "a"); iniparser_dump(ini, file); fclose(file); ReportMessage("\n"); t_key key = key_init(ini); t_pSys pSys = pSys_init (ini); t_opts opts = opts_init (ini); t_pair p = t_pair_init(ini); t_dump dump = dump_init(ini); t_fix fix = fix_init(ini); t_compute compute = compute_init(ini, &key); init (&key, &pSys, &opts, &p, &compute); if(key.dump) dump_run(&key, &pSys, &opts, &dump); // Make initial snapshot. while(opts.thisIter < opts.targIters){ // Repeat until iterational limit. verlet_iter (&key, &pSys, &opts, &p, &fix, &compute); if(key.dump) dump_run(&key, &pSys, &opts, &dump); resetStep(&pSys); } }
int main() { dictionary *ini = iniparser_load("config.ini"); iniparser_dump(ini, stdout); return 0; }
int log_manager::load_config() { if (this->ini_obj_) { iniparser_freedict(this->ini_obj_); this->ini_obj_ = 0; } this->ini_obj_ = iniparser_load(this->config_filename_.c_str()); if (this->ini_obj_ == 0) { ::fprintf(stderr, "cannot parse file: %s", this->config_filename_.c_str()); return -1; } #ifdef NDK_LOG_DEBUG iniparser_dump(this->ini_obj_, stderr); #endif // Global config if (this->load_cfg_global() != 0) return -1; if (this->load_cfg_modules() != 0) return -1; return 0; }
int dump_cfg(char* filepath) { FILE *tmp_cfg; int oldmask = umask(0); if (filepath == NULL) { char *tmp = malloc(strlen(CFG_TMP)+strlen("/tmp.conf") + 1); if (!snprintf(tmp, strlen(CFG_TMP)+strlen("/tmp.conf") + 1, "%s%s", CFG_TMP, "/tmp.conf")) { LOG(WARNING, "Unable to create tmp config filepath"); free(tmp); goto err; } if ((tmp_cfg = fopen(tmp, "w")) == NULL) { umask(oldmask); goto err; } free(tmp); } else { if ((tmp_cfg = fopen(filepath, "w")) == NULL) { umask(oldmask); goto err; } } umask(oldmask); iniparser_dump(ini, tmp_cfg); fclose(tmp_cfg); return 0; err: write_to_log(WARNING, "Unable to dump config file"); return -1; }
void setupRTPServers() { int i,j; int numServers; dictionary *ini ; int b ; char *s ; ini = iniparser_load(CONFIG_FILE); if (ini==NULL) { fprintf(stderr, "cannot parse file: %s\n", CONFIG_FILE); return -1 ; } iniparser_dump(ini, stderr); numServers = iniparser_getboolean(ini, "Rec Servers:numServers", -1); printf("numServers: [%d]\n", b); rtpServers.server = (struct rtpServer*)malloc(sizeof(struct rtpServer)*numServers); rtpServers.numServers = numServers; for(j=0;j<numServers;j++) { rtpServers.server[j].minPort = MIN_PORT_NO; rtpServers.server[j].numActiveChannels = 0; for(i=0;i<CHANNELS_PER_SERVER;i++) rtpServers.server[j].portActive[i] = 0; s = iniparser_getstring(ini,"Rec Servers:ipAddress","NULL"); strcpy(rtpServers.server[j].ip,s); } }
/** ****************************************************************************** * @brief 从配置文件中获取服务器ip字符串 * @param[out] *pserverip : 返回服务器ip字符串 * * @retval -1 失败 * @retval 0 成功 ****************************************************************************** */ int ini_get_server_ip(char * pserverip) { dictionary * ini ; char *pstr = NULL; ini = iniparser_load(DEFAULT_INI_FILE); if (NULL == ini) { create_example_ini_file(); ini = iniparser_load(DEFAULT_INI_FILE); if (ini == NULL) { return -1; } } iniparser_dump(ini, NULL); pstr = iniparser_getstring(ini, "client:ip", NULL); if (pstr == NULL) { return -1; } strncpy(pserverip, pstr, 16); //ip字符串最长16字节 iniparser_freedict(ini); return 0; }
int parse_ini_file(char * ini_name) { dictionary * ini ; /* Some temporary variables to hold query results */ int b ; int i ; double d ; char * s ; ini = iniparser_load(ini_name); if (ini==NULL) { fprintf(stderr, "cannot parse file: %s\n", ini_name); return -1 ; } iniparser_dump(ini, stderr); /* Get pizza attributes */ printf("Pizza:\n"); b = iniparser_getboolean(ini, "pizza:ham", -1); printf("Ham: [%d]\n", b); b = iniparser_getboolean(ini, "pizza:mushrooms", -1); printf("Mushrooms: [%d]\n", b); b = iniparser_getboolean(ini, "pizza:capres", -1); printf("Capres: [%d]\n", b); b = iniparser_getboolean(ini, "pizza:cheese", -1); printf("Cheese: [%d]\n", b); /* Get wine attributes */ printf("Wine:\n"); s = iniparser_getstring(ini, "wine:grape", NULL); printf("Grape: [%s]\n", s ? s : "UNDEF"); i = iniparser_getint(ini, "wine:year", -1); printf("Year: [%d]\n", i); s = iniparser_getstring(ini, "wine:country", NULL); printf("Country: [%s]\n", s ? s : "UNDEF"); d = iniparser_getdouble(ini, "wine:alcohol", -1.0); printf("Alcohol: [%g]\n", d); iniparser_freedict(ini); return 0 ; }
ttscpVoiceDialog::ttscpVoiceDialog(QWidget *parent) : QDialog(parent) { setupUi(this); dictionary * ini = iniparser_load("qenix.ini"); //Must deallocate manualy if (ini==NULL) { iniparser_freedict(ini); fprintf(stderr, "cannot parse file [%s]", "qenix.ini"); return; } iniparser_dump(ini, stderr); spinF->setValue(iniparser_getint(ini, "ttscp:init_f", 20)); spinI->setValue(iniparser_getint(ini, "ttscp:init_i", 20)); spinT->setValue(iniparser_getint(ini, "ttscp:init_t", 20)); //int timeout = iniparser_getstr(ini, "ttscp:timeout", -1); iniparser_freedict(ini); }
int loadconfig(const char* ini_name) { dictionary * ini ; ini = iniparser_load(ini_name); if (ini == NULL) { fprintf(stderr, "cannot parse file: %s\n", ini_name); return -1 ; } iniparser_dump(ini, stdout); global_ini.cfg_file = iniparser_getstring(ini, "log.cfg_file", 0); global_ini.listen_port = iniparser_getint(ini, "listen:port", -1); global_ini.backlog = iniparser_getint(ini, "listen:backlog", 1); global_ini.nworkers = iniparser_getint(ini, "concurrency:nworkers", 1); global_ini.nepolls_per_worker = iniparser_getint(ini, "concurrency:nepolls_per_worker", 1); global_ini.nconn_per_epoll = iniparser_getint(ini, "concurrency:nconn_per_epoll", 1); global_ini.nthreads_per_epoll = iniparser_getint(ini, "concurrency:nthreads_per_epoll", 1); iniparser_freedict(ini); return 0; }
/** * @brief Определяет параметры в ini файле * @return int */ int parse_ini_file() { dictionary *ini; /* Some temporary variables to hold query results */ int t; char *s; ini = iniparser_load(Ini_File); if (ini==NULL) { fprintf(stderr, "cannot parse file: %s\n", Ini_File); return -1; } //Получить поле для вызова сценария s = iniparser_getstring(ini, "script:line", NULL); strcpy(config_job.Script, s); //Получить временной период между запусками сценариев t = iniparser_getint(ini, "script:time", -1); config_job.Time = t; //Отладка парсинга параметров ini файла #if DEBUG_INI_PARS iniparser_dump(ini, stderr); printf("sh-script:\n"); printf("line: [%s]\n", s ? s : "UNDEF"); printf("time: [%d]\n", t); #endif iniparser_freedict(ini); return 0 ; }
bool ModSettings::load_mod() { char ini_name[MAX_PATH]; sprintf(ini_name, "%s\\%s\\%s", LauncherSettings::get_exe_pathonly(), LauncherSettings::get_active_mod(), const_cast<char*>(INI_MOD_DEFAULT)); dictionary *ini = iniparser_load(ini_name); if (ini == NULL) return false; iniparser_dump(ini, stderr); // read ini variables // TODO Int3(); // atomically assign all ini variables // TODO Int3(); iniparser_freedict(ini); return true; }
void ttscpVoiceDialog::accept() { QByteArray ba; tts.stopf(); //tts.stop(); dictionary * ini = iniparser_load("qenix.ini"); //Must deallocate manualy if (ini==NULL) { iniparser_freedict(ini); fprintf(stderr, "cannot parse file [%s]", "qenix.ini"); return; } iniparser_dump(ini, stderr); tts.setInit_f(spinF->value()); ba = QByteArray::number(spinF->value()); iniparser_setstr(ini, "ttscp:init_f", ba.data()); tts.setInit_i(spinI->value()); ba = QByteArray::number(spinI->value()); iniparser_setstr(ini, "ttscp:init_i", ba.data()); tts.setInit_t(spinT->value()); ba = QByteArray::number(spinT->value()); iniparser_setstr(ini, "ttscp:init_t", ba.data()); //msgbox(QString(t)); FILE *fw; fw = fopen("qenix.ini", "wb+"); iniparser_dump_ini(ini, fw); fclose(fw); iniparser_freedict(ini); done(Accepted); }
/** ****************************************************************************** * @brief 从配置文件中获取路由器牌子 * @param[out] *pserverip : 返回type * * @retval -1 失败 * @retval 0 成功 ****************************************************************************** */ int ini_get_log_type(int *ptype) { dictionary * ini ; ini = iniparser_load(DEFAULT_INI_FILE); if (NULL == ini) { create_example_ini_file(); ini = iniparser_load(DEFAULT_INI_FILE); if (ini == NULL) { return -1; } } iniparser_dump(ini, NULL);//stderr *ptype = iniparser_getint(ini, "client:type", -1); iniparser_freedict(ini); return 0; }
/** ****************************************************************************** * @brief 从配置文件中获取是否记入日志标志 * @param[out] *pserverip : 返回服务器ip字符串 * * @retval -1 失败 * @retval 0 成功 ****************************************************************************** */ int ini_get_log_flag(char *pflag) { dictionary * ini ; ini = iniparser_load(DEFAULT_INI_FILE); if (NULL == ini) { create_example_ini_file(); ini = iniparser_load(DEFAULT_INI_FILE); if (ini == NULL) { return -1; } } iniparser_dump(ini, NULL);//stderr *pflag = (char)iniparser_getboolean(ini, "client:log", -1); iniparser_freedict(ini); return 0; }
/** ****************************************************************************** * @brief 从配置文件中获取服务器端口 * @param[out] *pserverip : 返回服务器ip字符串 * * @retval -1 失败 * @retval 0 成功 ****************************************************************************** */ int ini_get_server_port(unsigned short *pport) { dictionary * ini ; ini = iniparser_load(DEFAULT_INI_FILE); if (NULL == ini) { create_example_ini_file(); ini = iniparser_load(DEFAULT_INI_FILE); if (ini == NULL) { return -1; } } iniparser_dump(ini, NULL); *pport = (unsigned short)iniparser_getint(ini, "client:port", -1); iniparser_freedict(ini); return 0; }
bool LauncherSettings::load() { dictionary *ini = iniparser_load(const_cast<char*>(INI_MAIN)); if (ini == NULL) return false; iniparser_dump(ini, stderr); // read ini variables char *exe_filepath = iniparser_getstr(ini, "launcher:exe_filepath"); char *active_mod = iniparser_getstr(ini, "launcher:active_mod"); bool showed_pilot_warning = (iniparser_getboolean(ini, "launcher:showed_pilot_warning", 0) != 0); if (exe_filepath == NULL || active_mod == NULL) return false; // atomically assign all ini variables set_exe_filepath(exe_filepath); set_active_mod(active_mod); m_showed_pilot_warning = showed_pilot_warning; iniparser_freedict(ini); return true; }
bool ModSettings::load_user_fso() { char ini_name[MAX_PATH]; sprintf(ini_name, "%s\\%s\\%s", LauncherSettings::get_exe_pathonly(), LauncherSettings::get_active_mod(), const_cast<char*>(INI_MOD_CUSTOM)); dictionary *ini = iniparser_load(ini_name); if (ini == NULL) return false; iniparser_dump(ini, stderr); // read ini variables char *standard_params = iniparser_getstr(ini, "settings:flags"); if (standard_params == NULL) return false; // atomically assign all ini variables strcpy(m_standard_params, standard_params); strcpy(m_custom_params, ""); iniparser_freedict(ini); return true; }
/************************************************************************************************************* ** @brief : Load all watch's in ini file ** #conf : ini file dictionary ** #watch : parser ini configure file data ** @return : how many item in conf file *************************************************************************************************************/ int conf_init(dictionary *conf, P_WATCH_INFO watch, const unsigned int size) { char entry[64]; char *cp = NULL; unsigned int i; #define GET_INT_ENTRY(v, d) do { v = iniparser_getint(conf, entry, (d)); } while(0) #define GET_BOOL_ENTRY(v, d) do { v = iniparser_getboolean(conf, entry, (d)); } while(0) #define GET_STR_ENTRY(s, d) do { cp = iniparser_getstring(conf, entry, (d)); bcopy(cp, s, strlen(cp)); } while (0) #define FORMAT_ENTRY(s, k) do { bzero(entry, sizeof(entry)); snprintf(entry, sizeof(entry), "%s:%s", (s), (k)); } while(0) /* Debug print all conf */ if (debug){ iniparser_dump(conf, stderr); } /* Get section name's */ for (i = 0; i < size; i++){ cp = iniparser_getsecname(conf, i); bcopy(cp, watch[i].name, strlen(cp)); } /* Get each of them data */ for (i = 0; i < size; i++){ /* Ignore ? */ FORMAT_ENTRY(watch[i].name, IGNORE_KEY); GET_BOOL_ENTRY(watch[i].ignore, 0); /* If ignore, do not read jump to next */ if (watch[i].ignore){ continue; } /* Path */ FORMAT_ENTRY(watch[i].name, PATH_KEY); GET_STR_ENTRY(watch[i].path, ""); /* Check if path is dir set is_dir mark */ watch[i].is_dir = conf_is_path_is_dir(watch[i].path); /* Comment */ FORMAT_ENTRY(watch[i].name, COMMENT_KEY); GET_STR_ENTRY(watch[i].comment, ""); /* Find if setting special file */ FORMAT_ENTRY(watch[i].name, SPECIAL_KEY); /* Only dir have this option */ if (watch[i].is_dir && iniparser_find_entry(conf, entry)){ /* Read form ini file */ if ((cp = iniparser_getstring(conf, entry, ""))){ /* Get special file name */ watch[i].spc_file_cnt = conf_get_words(cp, watch[i].spc_file, MAX_SPC_FILE); } } /* events */ FORMAT_ENTRY(watch[i].name, EVENTS_KEY); GET_STR_ENTRY(watch[i].events_str, ""); /* Parser events */ watch[i].events = conf_parser_events(watch[i].events_str, watch[i].is_dir); /* Debug */ if (debug){ conf_print_watch(&watch[i]); } } /* end for */ /* Arrange watching list */ return conf_arrange_watch(watch, (i == size) ? size : i); }
void finiparser_dump() { if(dic != NULL) iniparser_dump(dic,stdout); return; }
/** ****************************************************************************** * @brief 从配置文件中获取文件合并信息 * @param[out] *pinfo : 返回info * * @retval -1 失败 * @retval 0 成功 ****************************************************************************** */ int ini_get_info(filejoint_ini_t *pinfo) { dictionary * ini ; char *pstr = NULL; char ftmp[32]; int i; memset(pinfo, 0x00, sizeof(*pinfo)); ini = iniparser_load(DEFAULT_INI_FILE); if (NULL == ini) { create_example_ini_file(); ini = iniparser_load(DEFAULT_INI_FILE); if (ini == NULL) { return -1; } } iniparser_dump(ini, NULL);//stderr pinfo->files = iniparser_getint(ini, "cfg:Files", -1); if ((pinfo->files > DEFAULT_MAX_FILE) || (pinfo->files <= 0)) { iniparser_freedict(ini); return -1; } pinfo->blank = iniparser_getint(ini, "cfg:Blank", -1); if (pinfo->blank < 0) { iniparser_freedict(ini); return -1; } if (pinfo->blank > 255) { pinfo->blank = 255; } pinfo->islog = iniparser_getint(ini, "cfg:IsLog", -1); if (pinfo->islog == -1) { iniparser_freedict(ini); return -1; } pstr = iniparser_getstring(ini, "cfg:LogFile", NULL); if (pstr == NULL) { iniparser_freedict(ini); return -1; } strncpy(pinfo->logfile, pstr, sizeof(pinfo->logfile)); pstr = iniparser_getstring(ini, "cfg:OutFile", NULL); if (pstr == NULL) { strncpy(pinfo->outfile, DEFAULT_DEST_FILE, sizeof(pinfo->outfile)); } else { strncpy(pinfo->outfile, pstr, sizeof(pinfo->logfile)); } /* 扫描所以文件 */ for (i = 0; i < pinfo->files; i++) { sprintf(ftmp, "f%d:FileName", i + 1); pstr = iniparser_getstring(ini, ftmp, NULL); if (pstr == NULL) { iniparser_freedict(ini); return -1; } strncpy(pinfo->file[i].filename, pstr, sizeof(pinfo->file[i].filename)); sprintf(ftmp, "f%d:FileMaxSize", i + 1); pinfo->file[i].filemaxsize = iniparser_getint(ini, ftmp, -1); if (pinfo->file[i].filemaxsize == -1) { iniparser_freedict(ini); return -1; } } iniparser_freedict(ini); return 0; }
/* ... */ void CBaIniParse::TwistedIni() { IBaIniParser *pNewHdl = 0; dictionary *pOrgHdl = 0; std::string tmp; CPPUNIT_ASSERT(!IBaIniParserCreate("You/Shall/Not/Path")); CPPUNIT_ASSERT(!iniparser_load("You/Shall/Not/Path")); CPPUNIT_ASSERT(!IBaIniParserCreate(ERRORINI)); CPPUNIT_ASSERT(!iniparser_load(ERRORINI)); CPPUNIT_ASSERT(!iniparser_load(OFKEYINI)); CPPUNIT_ASSERT(!IBaIniParserCreate(OFKEYINI)); CPPUNIT_ASSERT(!IBaIniParserCreate(OFVALINI)); CPPUNIT_ASSERT(!iniparser_load(OFVALINI)); pNewHdl = IBaIniParserCreate(TWISTEDINI); pOrgHdl = iniparser_load(TWISTEDINI); CPPUNIT_ASSERT(pNewHdl); CPPUNIT_ASSERT(pOrgHdl); pNewHdl->Dump(stdout); std::cout << "a==============================================================\n\n"; iniparser_dump(pOrgHdl, stdout); std::cout << "a==============================================================\n\n"; pNewHdl->DumpIni(stdout); std::cout << "a==============================================================\n\n"; iniparser_dump_ini(pOrgHdl, stdout); CPPUNIT_ASSERT_EQUAL( (bool) iniparser_find_entry(pOrgHdl, "open["), pNewHdl->Exists("open[")); // Multi-lines tmp = pNewHdl->GetString("multi:multi line key", ""); CPPUNIT_ASSERT_MESSAGE(tmp, tmp == "multi line value"); tmp = pNewHdl->GetString("multi:visible", ""); CPPUNIT_ASSERT_MESSAGE(tmp, tmp == "1"); tmp = pNewHdl->GetString("multi:a", ""); CPPUNIT_ASSERT_MESSAGE(tmp, tmp == "beginend"); tmp = pNewHdl->GetString("multi:c", ""); CPPUNIT_ASSERT_MESSAGE(tmp, tmp == "begin end"); CPPUNIT_ASSERT(IBaIniParserDestroy(pNewHdl)); iniparser_freedict(pOrgHdl); pNewHdl = 0; pOrgHdl = 0; pNewHdl = IBaIniParserCreate(0); pOrgHdl = dictionary_new(10); CPPUNIT_ASSERT(pNewHdl); CPPUNIT_ASSERT(pOrgHdl); CPPUNIT_ASSERT_EQUAL(pNewHdl->Set(0, 0), !iniparser_set(pOrgHdl, 0, 0)); CPPUNIT_ASSERT_EQUAL(pNewHdl->Set("section", 0), !iniparser_set(pOrgHdl, "section", 0)); CPPUNIT_ASSERT_EQUAL(pNewHdl->Set("section:key", "value"), !iniparser_set(pOrgHdl, "section:key", "value")); tmp = pNewHdl->GetString("section:key", 0); CPPUNIT_ASSERT_MESSAGE(tmp, tmp == iniparser_getstring(pOrgHdl, "section:key", 0)); /* reset the key's value*/ CPPUNIT_ASSERT_EQUAL(pNewHdl->Set("section:key", 0), !iniparser_set(pOrgHdl, "section:key", 0)); tmp = iniparser_getstring(pOrgHdl, "section:key", "dummy") ? iniparser_getstring(pOrgHdl, "section:key", "dummy") : ""; CPPUNIT_ASSERT_MESSAGE(tmp, tmp == pNewHdl->GetString("section:key", "dummy")); CPPUNIT_ASSERT_EQUAL(pNewHdl->Set("section:key", "value"), !iniparser_set(pOrgHdl, "section:key", "value")); tmp = pNewHdl->GetString("section:key", 0); CPPUNIT_ASSERT_MESSAGE(tmp, tmp == iniparser_getstring(pOrgHdl, "section:key", 0)); iniparser_unset(pOrgHdl, "section:key"); pNewHdl->Reset("section:key"); tmp = pNewHdl->GetString("section:key", "dummy"); CPPUNIT_ASSERT_MESSAGE(tmp, tmp == iniparser_getstring(pOrgHdl, "section:key", "dummy")); CPPUNIT_ASSERT_EQUAL(pNewHdl->Set("section:key", 0), !iniparser_set(pOrgHdl, "section:key", 0)); CPPUNIT_ASSERT_EQUAL(pNewHdl->Set("section:key1", 0), !iniparser_set(pOrgHdl, "section:key1", 0)); CPPUNIT_ASSERT_EQUAL(pNewHdl->Set("section:key2", 0), !iniparser_set(pOrgHdl, "section:key2", 0)); }
void Config::dump() { iniparser_dump(ini, stdout); }