int main(int argc, char **argv) { char SRVR[1000]; char *p=SRVR; config_t config; config_init(&config); if ( config_read_file(&config, "/etc/snowflake.conf") == CONFIG_TRUE ) { printf("PARt 1\n"); const config_setting_t *setting = config_lookup(&config, "server"); if( setting != NULL) { p = config_setting_get_string(setting); printf("opened file\n"); printf("SERVER ADDRESS = %s\n",p); } else { printf("ERROR\n"); } } else { fprintf(stderr, "%s:%d - %s\n", config_error_file(&config), config_error_line(&config), config_error_text(&config)); config_destroy(&config); return(1); } }
// TODO: audit exit routes to "unset"/"unalloc" values. int upd8_config_parse(upd8_config_t *config, const char *config_file) { // TODO: check that config is not null. config_t *cfg = malloc(sizeof(config_t)); config_init(cfg); if (!config_read_file(cfg, config_file)) { fprintf(stderr, "%s:%d - %s\n", config_error_file(cfg), config_error_line(cfg), config_error_text(cfg)); config_destroy(cfg); return EXIT_FAILURE; } config->cfg = cfg; config_setting_t *settings; settings = config_lookup(cfg, settings_path); if (settings == NULL) { fprintf(stderr, "Unable to find %s in %s\n", settings_path, config_file); config_destroy(cfg); return EXIT_FAILURE; } config->num_sources = config_setting_length(settings); config->sources = malloc(config->num_sources * sizeof(upd8_source_t)); for (int i = 0; i < config->num_sources; ++i) { config_setting_t *individual_config = config_setting_get_elem(settings, i); upd8_source_parse(&(config->sources[i]), individual_config); } return 0; }
int readCfgState (void) { config_t cfg; config_init(&cfg); /* Read the file. If there is an error, report it and exit. */ if (!config_read_file(&cfg, config_state_path)) { printf("\n%s:%d - %s", config_error_file(&cfg), config_error_line(&cfg), config_error_text(&cfg)); config_destroy(&cfg); return -1; } /* */ if (!config_lookup_int(&cfg, "tempState", &tempState)) printf("\nNo 'tempState' setting in configuration file."); if (!config_lookup_int(&cfg, "humState", &humState)) printf("\nNo 'humState' setting in configuration file."); if (!config_lookup_int(&cfg, "relay1o", &relay1o)) printf("\nNo 'relay1o' setting in configuration file."); if (!config_lookup_int(&cfg, "relay2o", &relay2o)) printf("\nNo 'relay2o' setting in configuration file."); if (!config_lookup_int(&cfg, "relay3o", &relay3o)) printf("\nNo 'relay3o' setting in configuration file."); if (!config_lookup_int(&cfg, "relay4o", &relay4o)) printf("\nNo 'relay4o' setting in configuration file."); if (!config_lookup_int(&cfg, "relay5o", &relay5o)) printf("\nNo 'relay5o' setting in configuration file."); if (!config_lookup_int(&cfg, "relay6o", &relay6o)) printf("\nNo 'relay6o' setting in configuration file."); if (!config_lookup_int(&cfg, "relay7o", &relay7o)) printf("\nNo 'relay7o' setting in configuration file."); if (!config_lookup_int(&cfg, "relay8o", &relay8o)) printf("\nNo 'relay8o' setting in configuration file."); if (!config_lookup_int(&cfg, "RHeatTS", &RHeatTS)) printf("\nNo 'RHeatTS' setting in configuration file."); if (!config_lookup_int(&cfg, "RHumTS", &RHumTS)) printf("\nNo 'RHumTS' setting in configuration file."); if (!config_lookup_int(&cfg, "RHepaTS", &RHepaTS)) printf("\nNo 'RHepaTS' setting in configuration file."); if (!config_lookup_int(&cfg, "RFanTS", &RFanTS)) printf("\nNo 'RFanTS' setting in configuration file."); if (!config_lookup_float(&cfg, "wfactor", &wfactor)) printf("\nNo 'wfactor' setting in configuration file."); config_destroy(&cfg); return 0; }
void Init(HINSTANCE i_thisInstanceOfTheApplication, HINSTANCE i_thisIsNothing, char* i_commandLineArguments, int i_initialWindowDisplayState) { config_t cfg; int Screenwidth; int Screenheight; config_init(&cfg); if(! config_read_file(&cfg, "config.cfg")) { fprintf(stderr, "%s:%d - %s\n", config_error_file(&cfg), config_error_line(&cfg), config_error_text(&cfg)); config_destroy(&cfg); } config_lookup_int(&cfg, "ScreenWidth", &Screenwidth); config_lookup_int(&cfg, "ScreenHeight", &Screenheight); config_destroy(&cfg); Renderer::width=Screenwidth; Renderer::height=Screenheight; Singleton<Time>::getInstance().Init(); Singleton<Physics>::getInstance().Init(); Singleton<Renderer>::getInstance().Init( i_thisInstanceOfTheApplication, i_thisIsNothing, i_commandLineArguments, i_initialWindowDisplayState); Singleton<World>::getInstance().Init(); Singleton<Collision>::getInstance().Init(); Singleton<EventHandler>::getInstance().Init(); SoundManager::Manager().Init(); }
void db_init_pg_conn(const char *conf_file) { if(config_read_file(&config, conf_file) != CONFIG_TRUE) { fprintf(stderr, "%s:%d %s\n", config_error_file(&config), config_error_line(&config), config_error_text(&config)); config_destroy(&config); exit(EXIT_FAILURE); } conn = PQsetdbLogin( read_db_setting("db_host"), read_db_setting("db_port"), NULL, NULL, read_db_setting("db_name"), read_db_setting("db_login"), read_db_setting("db_password")); const char *store_dir_tmp = read_db_setting("store_dir"); store_dir = (char*)malloc(strlen(store_dir_tmp)+1); strcpy(store_dir, store_dir_tmp); if(PQstatus(conn) != CONNECTION_OK) { fprintf(stderr, "Connection to database failed: %s\n", PQerrorMessage(conn)); config_destroy(&config); exit(EXIT_FAILURE); } else { fprintf(stderr, "database OK\n"); } if(pthread_mutex_init(&db_lock, NULL) < 0) { fprintf(stderr, "pthread_mutex_init failed\n"); exit(EXIT_FAILURE); } }
int readCfg (void) { config_t cfg; config_init(&cfg); /* Read the file. If there is an error, report it and exit. */ if (!config_read_file(&cfg, config_file_name)) { printf("\n%s:%d - %s", config_error_file(&cfg), config_error_line(&cfg), config_error_text(&cfg)); config_destroy(&cfg); return -1; } if (!config_lookup_int(&cfg, "onTemp", &onTemp)) printf("\nNo 'onTemp' setting in configuration file."); if (!config_lookup_int(&cfg, "offTemp", &offTemp)) printf("\nNo 'offTemp' setting in configuration file."); if (!config_lookup_int(&cfg, "highTemp", &highTemp)) printf("\nNo 'highTemp' setting in configuration file."); if (!config_lookup_int(&cfg, "onHum", &onHum)) printf("\nNo 'onHum' setting in configuration file."); if (!config_lookup_int(&cfg, "offHum", &offHum)) printf("\nNo 'offHum' setting in configuration file."); if (!config_lookup_int(&cfg, "webOR", &webOR)) printf("\nNo 'webOR' setting in configuration file."); if (!config_lookup_int(&cfg, "tempState", &tempState)) printf("\nNo 'tempState' setting in configuration file."); if (!config_lookup_int(&cfg, "humState", &humState)) printf("\nNo 'humState' setting in configuration file."); config_destroy(&cfg); return 0; }
int main () { config_t cfg; laser_container_t *lasers = NULL; config_init (&cfg); if(! config_read_file(&cfg, "test.cfg")) { fprintf(stderr, "%s:%d - %s\n", config_error_file(&cfg), config_error_line(&cfg), config_error_text(&cfg)); config_destroy(&cfg); exit(EXIT_FAILURE); } lasers = laser_container_cfg_parse_ctor(&cfg); config_destroy (&cfg); if (lasers == NULL) { fprintf(stderr, "Failed to parse laser configuration.\n"); exit (EXIT_FAILURE); } printf ("nlasers: %d\n", lasers->nlasers); laser_container_dtor(lasers); return 0; }
// Leitura de configurações exclusivas do brAthena. void read_brathena_config(void) { const char *tmpchar; int tmpint; config_t configbrA; memset(&bra_config, 0, sizeof(bra_config)); config_init(&configbrA); if(!libconfig->read_file_src(&configbrA, "conf/battle/brathena.conf")) { ShowError("read_brathena_config erro: %s:%d - %s\n", config_error_file(&configbrA), config_error_line(&configbrA), config_error_text(&configbrA)); libconfig->destroy(&configbrA); } if(libconfig->lookup_int(&configbrA, "max_rename_char", &tmpint)) bra_config.max_rename_char = tmpint; if(libconfig->lookup_string(&configbrA, "lang_file", &tmpchar)) strncpy(bra_config.lang_file, tmpchar, sizeof(bra_config.lang_file)); if(libconfig->lookup_int(&configbrA, "enable_system_vip", &tmpint)) bra_config.enable_system_vip = tmpint; if(libconfig->lookup_int(&configbrA, "level_vip", &tmpint)) bra_config.level_vip = tmpint; if(libconfig->lookup_int(&configbrA, "extra_exp_vip_base", &tmpint))bra_config.extra_exp_vip_base = tmpint; if(libconfig->lookup_int(&configbrA, "extra_exp_vip_job", &tmpint))bra_config.extra_exp_vip_job = tmpint; if(libconfig->lookup_int(&configbrA, "penalty_exp_vip_base", &tmpint))bra_config.penalty_exp_vip_base = tmpint; if(libconfig->lookup_int(&configbrA, "penalty_exp_vip_job", &tmpint))bra_config.penalty_exp_vip_job = tmpint; if(libconfig->lookup_int(&configbrA, "msg_maps_removed", &tmpint)) bra_config.msg_maps_removed = tmpint; if(libconfig->lookup_int(&configbrA, "show_message_exp", &tmpint)) bra_config.show_message_exp = tmpint; libconfig->destroy(&configbrA); }
int main(int argc, char **argv) { static const char *output_file = "updated.cfg"; config_t cfg; config_setting_t *root, *setting, *movie; config_init(&cfg); /* Read the file. If there is an error, report it and exit. */ if(! config_read_file(&cfg, "example.cfg")) { fprintf(stderr, "%s:%d - %s\n", config_error_file(&cfg), config_error_line(&cfg), config_error_text(&cfg)); config_destroy(&cfg); return(EXIT_FAILURE); } /* Find the 'movies' setting. Add intermediate settings if they don't yet * exist. */ root = config_root_setting(&cfg); setting = config_setting_get_member(root, "inventory"); if(!setting) setting = config_setting_add(root, "inventory", CONFIG_TYPE_GROUP); setting = config_setting_get_member(setting, "movies"); if(!setting) setting = config_setting_add(setting, "movies", CONFIG_TYPE_LIST); /* Create the new movie entry. */ movie = config_setting_add(setting, NULL, CONFIG_TYPE_GROUP); setting = config_setting_add(movie, "title", CONFIG_TYPE_STRING); config_setting_set_string(setting, "Buckaroo Banzai"); setting = config_setting_add(movie, "media", CONFIG_TYPE_STRING); config_setting_set_string(setting, "DVD"); setting = config_setting_add(movie, "price", CONFIG_TYPE_FLOAT); config_setting_set_float(setting, 12.99); setting = config_setting_add(movie, "qty", CONFIG_TYPE_INT); config_setting_set_float(setting, 20); /* Write out the updated configuration. */ if(! config_write_file(&cfg, output_file)) { fprintf(stderr, "Error while writing file.\n"); config_destroy(&cfg); return(EXIT_FAILURE); } fprintf(stderr, "Updated configuration successfully written to: %s\n", output_file); config_destroy(&cfg); return(EXIT_SUCCESS); }
static int read_settings_file(config_t *cfg, const char *filename) { int ret; /* Read the file. If there is an error, report it and exit. */ ret = config_read_file(cfg, filename); if (ret != CONFIG_TRUE) { fprintf(stderr, "%s ", config_error_file(cfg)); fprintf(stderr, "%d ", config_error_line(cfg)); fprintf(stderr, "%s ", config_error_text(cfg)); fprintf(stderr, "%s:%d - %s\n", config_error_file(cfg), config_error_line(cfg), config_error_text(cfg)); } return ret; }
int writeCfgCond(void) { config_t cfg; config_setting_t *tminTemp = 0; config_setting_t *tmaxTemp = 0; config_setting_t *tminHum = 0; config_setting_t *tmaxHum = 0; config_setting_t *twebOR = 0; config_init(&cfg); if (!config_read_file(&cfg, config_cond_path)) { printf("\n%s:%d - %s", config_error_file(&cfg), config_error_line(&cfg), config_error_text(&cfg)); config_destroy(&cfg); return -1; } /* lookup variables in config file */ tminTemp = config_lookup(&cfg, "minTemp"); tmaxTemp = config_lookup(&cfg, "maxTemp"); tminHum = config_lookup(&cfg, "minHum"); tmaxHum = config_lookup(&cfg, "maxHum"); twebOR = config_lookup(&cfg, "webOR"); /* get variables from config file then print the variables that changed */ if (config_setting_get_int(tminTemp) != minTemp) { printf("\nminTemp: %i -> ", config_setting_get_int(tminTemp)); config_setting_set_int(tminTemp, minTemp); printf("%i", config_setting_get_int(tminTemp)); } if (config_setting_get_int(tmaxTemp) != maxTemp) { printf("\nmaxTemp: %i -> ", config_setting_get_int(tmaxTemp)); config_setting_set_int(tmaxTemp, maxTemp); printf("%i", config_setting_get_int(tmaxTemp)); } if (config_setting_get_int(tminHum) != minHum) { printf("\nminHum: %i -> ", config_setting_get_int(tminHum)); config_setting_set_int(tminHum, minHum); printf("%i", config_setting_get_int(tminHum)); } if (config_setting_get_int(tmaxHum) != maxHum) { printf("\nmaxHum: %i -> ", config_setting_get_int(tmaxHum)); config_setting_set_int(tmaxHum, maxHum); printf("%i", config_setting_get_int(tmaxHum)); } if (config_setting_get_int(twebOR) != webOR) { printf("\nwebOR: %i -> ", config_setting_get_int(twebOR)); config_setting_set_int(twebOR, webOR); printf("%i", config_setting_get_int(twebOR)); } /* write the modified config file */ config_write_file(&cfg, config_cond_path); config_destroy(&cfg); return 0; }
int conf_read_file(config_t *config, const char *config_filename) { libconfig->init(config); if (!libconfig->read_file_src(config, config_filename)) { ShowError("%s:%d - %s\n", config_error_file(config), config_error_line(config), config_error_text(config)); libconfig->destroy(config); return 1; } return 0; }
int conf_read_file(config_t *config, const char *config_filename) { config_init(config); if (!config_read_file(config, config_filename)) { ShowError("%s:%d - %s\n", config_error_file(config), config_error_line(config), config_error_text(config)); config_destroy(config); return 1; } return 0; }
/** * Initializes 'config' and loads a configuration file. * * Shows error and destroys 'config' in case of failure. * It is the caller's care to destroy 'config' in case of success. * * @param config The config file to initialize. * @param config_filename The file to read. * * @retval CONFIG_TRUE in case of success. * @retval CONFIG_FALSE in case of failure. */ int config_load_file(struct config_t *config, const char *config_filename) { libconfig->init(config); if (libconfig->read_file_src(config, config_filename) != CONFIG_TRUE) { ShowError("%s:%d - %s\n", config_error_file(config), config_error_line(config), config_error_text(config)); libconfig->destroy(config); return CONFIG_FALSE; } return CONFIG_TRUE; }
/** * Re-reads configuration from the given file */ int read_config() { config_t cfg; config_init(&cfg); if (config_read_file(&cfg, conf.config_file) == CONFIG_FALSE) { if (config_error_type(&cfg) == CONFIG_ERR_FILE_IO) { log_error("Configuration file not found: %s", conf.config_file); config_destroy(&cfg); return -1; } log_error("%s:%d - %s", config_error_file(&cfg), config_error_line(&cfg), config_error_text(&cfg)); config_destroy(&cfg); return -1; } int intVal; const char* charVal; if (config_lookup_int(&cfg, "num_connections", &intVal) == CONFIG_TRUE) { conf.num_connections = intVal; } if (config_lookup_int(&cfg, "report_freq", &intVal) == CONFIG_TRUE) { conf.report_freq = intVal; } if (config_lookup_int(&cfg, "packet_size", &intVal) == CONFIG_TRUE) { if (intVal > MAXPACKET) { log_error("packet_size: %d exceeds maximal packet size (%d)", intVal, MAXPACKET); config_destroy(&cfg); return -1; } conf.packet_size = intVal; } if (config_lookup_int(&cfg, "packets_count", &intVal) == CONFIG_TRUE) { conf.packets_count = intVal; } if (config_lookup_string(&cfg, "reports_dir", &charVal) == CONFIG_TRUE) { free(conf.reports_dir); conf.reports_dir = strdup(charVal); } if (config_lookup_string(&cfg, "hosts_file", &charVal) == CONFIG_TRUE) { free(conf.hosts_file); conf.hosts_file = strdup(charVal); } if (config_lookup_string(&cfg, "log_file", &charVal) == CONFIG_TRUE) { free(conf.log_file); conf.log_file = strdup(charVal); } config_destroy(&cfg); if (read_hosts() == -1) { return -1; } return 0; }
void patch_initialise() { config_init(&patch_config); if (access(PATCH_FILE, F_OK) != -1) { if (config_read_file(&patch_config, PATCH_FILE) != CONFIG_TRUE) { LOG_ERROR("Patch load error in %s at line %d: %s", config_error_file(&patch_config), config_error_line(&patch_config), config_error_text(&patch_config)); exit(EXIT_FAILURE); } } }
static void init(void) { int i; double bpm; double decay; int samp_rate; int min_burst; int burst_increase; int min_gain; int gain_increase; int detune; config_init(&cfg); if(!config_read_file(&cfg, CONFIG_FILE)) { fprintf(stderr, "%s:%d - %s\n", config_error_file(&cfg), config_error_line(&cfg), config_error_text(&cfg)); config_destroy(&cfg); exit(EXIT_FAILURE); } if(!config_lookup_float(&cfg, "bpm", &bpm)) config_die("bpm"); if(!config_lookup_float(&cfg, "subdiv", &subdiv)) config_die("subdiv"); if(!config_lookup_int(&cfg, "samp_rate", &samp_rate)) config_die("samp_rate"); if(!config_lookup_int(&cfg, "min_burst", &min_burst)) config_die("min_burst"); if(!config_lookup_int(&cfg, "burst_increase", &burst_increase)) config_die("burst_increase"); if(!config_lookup_float(&cfg, "decay", &decay)) config_die("decay"); if(!config_lookup_int(&cfg, "min_gain", &min_gain)) config_die("min_gain"); if(!config_lookup_int(&cfg, "gain_increase", &gain_increase)) config_die("gain_increase"); if(!config_lookup_int(&cfg, "detune", &detune)) config_die("detune"); note_length = (float)samp_rate * 60 * subdiv / bpm; system_init(); agent_count = system_get_agent_count(); synths = calloc(agent_count, sizeof(Synth *)); for(i = 0; i < agent_count; i ++) { float pan = ((float)i / 20) * ((i % 2) * 2 - 1) + .5; synths[i] = synth_create(samp_rate, min_burst + i * burst_increase, decay, pan, min_gain + gain_increase * i, detune); } }
int main() { config_t cfg; /*Returns all parameters in this structure */ config_setting_t *setting; const char *str1, *str2; int tmp; char *config_file_name = "config.ini"; /*Initialization */ config_init(&cfg); /* Read the file. If there is an error, report it and exit. */ if (!config_read_file(&cfg, config_file_name)) { printf("\n%s:%d - %s", config_error_file(&cfg), config_error_line(&cfg), config_error_text(&cfg)); config_destroy(&cfg); return -1; } /* Get the configuration file name. */ if (config_lookup_string(&cfg, "filename", &str1)) printf("\nFile Type: %s", str1); else printf("\nNo 'filename' setting in configuration file."); /*Read the parameter group*/ setting = config_lookup(&cfg, "params"); if (setting != NULL) { /*Read the string*/ if (config_setting_lookup_string(setting, "param1", &str2)) { printf("\nParam1: %s", str2); } else printf("\nNo 'param1' setting in configuration file."); /*Read the integer*/ if (config_setting_lookup_int(setting, "param2", &tmp)) { printf("\nParam2: %d", tmp); } else printf("\nNo 'param2' setting in configuration file."); printf("\n"); } config_destroy(&cfg); }
int write_configurations() { config_t cfg; //config_setting_t *setting; //const char *str; config_init(&cfg); /* Read the file. If there is an error, report it and exit. */ if (!config_write_file(&cfg, "fins.cfg")) { PRINT_ERROR("%s:%d - %s\n", config_error_file(&cfg), config_error_line(&cfg), config_error_text(&cfg)); config_destroy(&cfg); return EXIT_FAILURE; } config_destroy(&cfg); return EXIT_SUCCESS; }
int main(int argc, char **argv) { if (logging_initialise() != RESULT_OK) { exit(EXIT_FAILURE); } const char* config_file = RESOURCES_SYNTH_CFG; if (argc > 1) { config_file = argv[1]; } char config_dir[PATH_MAX]; realpath(config_file, config_dir); dirname(config_dir); config_init(&app_config); config_set_include_dir(&app_config, config_dir); if (config_read_file(&app_config, config_file) != CONFIG_TRUE) { LOG_ERROR("Config error in %s at line %d: %s", config_error_file(&app_config), config_error_line(&app_config), config_error_text(&app_config)); exit(EXIT_FAILURE); } config_setting_t *setting_tests = config_lookup(&app_config, CFG_TESTS); if (setting_tests != NULL) { config_setting_t *setting_code_timing_tests = config_setting_get_member(setting_tests, CFG_CODE_TIMING_TESTS); if (setting_code_timing_tests != NULL) { code_timing_tests_main(setting_code_timing_tests); } } else { recording_initialise(&app_config, WAVE_RENDERER_ID); synth_main(); recording_deinitialise(); } return 0; }
int readCfgCond (void) { config_t cfg; config_init(&cfg); /* Read the file. If there is an error, report it and exit. */ if (!config_read_file(&cfg, config_cond_path)) { printf("\n%s:%d - %s", config_error_file(&cfg), config_error_line(&cfg), config_error_text(&cfg)); config_destroy(&cfg); return -1; } /* */ if (!config_lookup_int(&cfg, "minTemp", &minTemp)) printf("\nNo 'minTemp' setting in configuration file."); if (!config_lookup_int(&cfg, "maxTemp", &maxTemp)) printf("\nNo 'maxTemp' setting in configuration file."); if (!config_lookup_int(&cfg, "minHum", &minHum)) printf("\nNo 'minHum' setting in configuration file."); if (!config_lookup_int(&cfg, "maxHum", &maxHum)) printf("\nNo 'maxHum' setting in configuration file."); if (!config_lookup_int(&cfg, "webOR", &webOR)) printf("\nNo 'webOR' setting in configuration file."); config_destroy(&cfg); return 0; }
static int read_config_auth(char config_file[BUFSIZE], struct config_auth* s_auth) { config_t cfg; const char* buf; config_init(&cfg); if (!config_read_file(&cfg, config_file)) { pam_http_syslog(LOG_ALERT, "%s:%d - %s\n", config_error_file(&cfg), config_error_line(&cfg), config_error_text(&cfg)); config_destroy(&cfg); return 0; } if (!config_lookup_string(&cfg, "auth_url", &buf)) { pam_http_syslog(LOG_ALERT, "No 'auth_url' setting in configuration file."); config_destroy(&cfg); return 0; } s_auth->c_auth_url = strndup(buf, BUFSIZE); s_auth->c_method = config_get_string(&cfg, "auth_method", DEFAULT_METHOD); if (strncmp(s_auth->c_method, HTTP_METHOD_GET, 3) != 0 && strncmp(s_auth->c_method, HTTP_METHOD_POST, 4) != 0) { pam_http_syslog(LOG_ALERT, "Wrong 'auth_method' setting in configuration file (%s).", s_auth->c_method); config_destroy(&cfg); return 0; } s_auth->c_username_field = config_get_string(&cfg, "auth_username_field", DEFAULT_USERNAME_FIELD); s_auth->c_password_field = config_get_string(&cfg, "auth_password_field", DEFAULT_PASSWORD_FIELD); if (!config_lookup_int64(&cfg, "auth_timeout", &s_auth->timeout)) { s_auth->timeout = DEFAULT_CURL_TIMEOUT; } if (!config_lookup_int64(&cfg, "auth_success_code", &s_auth->success_code)) { s_auth->success_code = DEFAULT_HTTP_SUCCESS_CODE; } config_destroy(&cfg); return 1; }
bool configuracion_cargar(const char *ruta, config_t* cf) { if ( !ruta || !ficheroExiste(ruta) ) return false; //Inicializo el parser de configuracion config_init(cf); //Intento leer el archivo if (!config_read_file(cf, ruta )) { if (DEBUG){ int linea = config_error_line(cf); const char* fichero = config_error_file(cf); const char* texto = config_error_text(cf); LOG_PRINT("ERROR CONFIG: %s:%d %s.",fichero, linea, texto); } config_destroy(cf); return false; } return true; }//configuracion_cargar
int main(int argc, char **argv) { config_t cfg, *cf; const config_setting_t *figuras, *figura_actual; const char *base = NULL; int count, n, enabled; int xInit,yInit; cf = &cfg; config_init(cf); if (!config_read_file(cf, "Archivos de Configuracion/test.cfg")) { fprintf(stderr, "%s:%d - %s\n", config_error_file(cf), config_error_line(cf), config_error_text(cf)); config_destroy(cf); return(EXIT_FAILURE); } figuras = config_lookup(cf, "Figuras"); count = config_setting_length(figuras); for (n = 0; n < count; n++) { figura_actual = config_setting_get_elem(figuras,n); config_setting_lookup_int(figura_actual,"Xinit",&xInit); printf("x: %d \n",xInit); //printf("\t#%d. %d\n", n + 1, // config_setting_get_int_elem(figuras, n)); } config_destroy(cf); return 0; }
int parse_data_files(int option) { int ret; cf = (config_t *) gtmalloc(sizeof(config_t)); config_init(cf); if (!config_read_file(cf, MAIN_DATA_FILE)) { fprintf(stderr, "%s:%d - %s\n", config_error_file(cf), config_error_line(cf), config_error_text(cf)); config_destroy(cf); return(1); } objid = 1; printf("Reading %s\n", MAIN_DATA_FILE); if(option == ONLY_CONFIG) { ret = parse_configfile(); config_destroy(cf); return ret; } /* TODO: This return value stuff makes rather little sense!! */ ret = parse_configfile(); ret = parse_objects(); ret = parse_monsters(); config_destroy(cf); ret = parse_roomdef_files(); return ret; }
int load_config(CustomData *d) { config_t cfg, *cf; // CustomData *d=*data; const config_setting_t *logos,*logo; int count, n; cf = &cfg; config_init(cf); if (!config_read_file(cf, "kiosk.ini")) { fprintf(stderr, "%s:%d - %s\n", config_error_file(cf), config_error_line(cf), config_error_text(cf)); config_destroy(cf); return -1; } logos = config_lookup(cf, "logos"); d->logo_count = config_setting_length(logos); g_print("%d logos configured.\n", d->logo_count); // d->config= malloc(sizeof(ConfigItem[10])); ConfigItem *ci; char *b,*i,*p; for (n = 0; n < d->logo_count; n++) { logo=config_setting_get_elem(logos, n); ci=&d->config[n]; config_setting_lookup_string(logo,"background", &b); config_setting_lookup_string(logo,"intro",&i); config_setting_lookup_string(logo,"prompter",&p); config_setting_lookup_int(logo,"duration",&d->config[n].duration); strcpy(d->config[n].background,b); strcpy(d->config[n].intro,i); strcpy(d->config[n].prompter,p); } config_destroy(cf); return 0; }
int* print_colour() { config_setting_t *color_list, *layout; config_t layout_config; int color_len, i; const char* color_value; int* RGB_array; config_init(&layout_config); if (!config_read_file(&layout_config, "./layout.cfg")) { fprintf(stderr, "%s:%d - %s\n", config_error_file(&layout_config), config_error_line(&layout_config), config_error_text(&layout_config)); config_destroy(&layout_config); return NULL; } color_list = config_lookup(&layout_config, "application.colors"); color_len = config_setting_length(color_list); RGB_array=malloc(sizeof (int)*3*color_len); for(i = 0; i < color_len; i++) { layout = config_setting_get_elem(color_list, i); config_setting_lookup_string(layout, "name", &color_value); printf(" %i)\t", i+1); printf("%s\n", color_value); config_setting_lookup_int(layout, "r", &RGB_array[i*3]); config_setting_lookup_int(layout, "g", &RGB_array[i*3+1]); config_setting_lookup_int(layout, "b", &RGB_array[i*3+2]); printf("\tR-G-B: %i-%i-%i\n",RGB_array[i*3],RGB_array[i*3+1],RGB_array[i*3+2]); } config_destroy(&layout_config); return RGB_array; }
// ---------------------------------------------------------------------------------------- // Sistema Multilinguagem // ---------------------------------------------------------------------------------------- // read_message("Grupo.SubGrupo.String"); // ---------------------------------------------------------------------------------------- // http://www.hyperrealm.com/libconfig/libconfig_manual.html // ---------------------------------------------------------------------------------------- char *read_message(const char *param) { static char message[512]; config_setting_t *str; config_t configLang; config_init(&configLang); if(!config_read_file(&configLang, (!strlen(bra_config.lang_file)?"conf/lang/pt_br.conf":bra_config.lang_file))) { ShowError("read_message erro: %s:%d - %s\n", config_error_file(&configLang), config_error_line(&configLang), config_error_text(&configLang)); config_destroy(&configLang); return ""; } if(!(str = config_lookup(&configLang, param))) { ShowError("read_message erro: %s\n", param); config_destroy(&configLang); return ""; } strncpy(message, config_setting_get_string(str), sizeof(message)); config_destroy(&configLang); return message; }
int writeCfg (void) { config_t cfg; config_setting_t *tonTemp = 0; config_setting_t *toffTemp = 0; config_setting_t *thighTemp = 0; config_setting_t *tonHum = 0; config_setting_t *toffHum = 0; config_setting_t *twebOR = 0; config_setting_t *ttempState = 0; config_setting_t *thumState = 0; config_init(&cfg); if (!config_read_file(&cfg, config_file_name)) { printf("\n%s:%d - %s", config_error_file(&cfg), config_error_line(&cfg), config_error_text(&cfg)); config_destroy(&cfg); return -1; } /* lookup variables in config file */ tonTemp = config_lookup(&cfg, "onTemp"); toffTemp = config_lookup(&cfg, "offTemp"); thighTemp = config_lookup(&cfg, "highTemp"); tonHum = config_lookup(&cfg, "onHum"); toffHum = config_lookup(&cfg, "offHum"); twebOR = config_lookup(&cfg, "webOR"); ttempState = config_lookup(&cfg, "tempState"); thumState = config_lookup(&cfg, "humState"); /* get variables from config file then print the variables that changed */ if (config_setting_get_int(tonTemp) != onTemp) { printf("\nonTemp: %i -> ", config_setting_get_int(tonTemp)); config_setting_set_int(tonTemp, onTemp); printf("%i", config_setting_get_int(tonTemp)); } if (config_setting_get_int(toffTemp) != offTemp) { printf("\noffTemp: %i -> ", config_setting_get_int(toffTemp)); config_setting_set_int(toffTemp, offTemp); printf("%i", config_setting_get_int(toffTemp)); } if (config_setting_get_int(thighTemp) != highTemp) { printf("\nhighTemp: %i -> ", config_setting_get_int(thighTemp)); config_setting_set_int(thighTemp, highTemp); printf("%i", config_setting_get_int(thighTemp)); } if (config_setting_get_int(tonHum) != onHum) { printf("\nonHum: %i -> ", config_setting_get_int(tonHum)); config_setting_set_int(tonHum, onHum); printf("%i", config_setting_get_int(tonHum)); } if (config_setting_get_int(toffHum) != offHum) { printf("\noffHum: %i -> ", config_setting_get_int(toffHum)); config_setting_set_int(toffHum, offHum); printf("%i", config_setting_get_int(toffHum)); } if (config_setting_get_int(twebOR) != webOR) { printf("\nwebOR: %i -> ", config_setting_get_int(twebOR)); config_setting_set_int(twebOR, webOR); printf("%i", config_setting_get_int(twebOR)); } if (config_setting_get_int(ttempState) != tempState) { printf("\ntempState: %i -> ", config_setting_get_int(ttempState)); config_setting_set_int(ttempState, tempState); printf("%i", config_setting_get_int(ttempState)); } if (config_setting_get_int(thumState) != humState) { printf("\nhumState: %i -> ", config_setting_get_int(thumState)); config_setting_set_int(thumState, humState); printf("%i", config_setting_get_int(thumState)); } /* write the modified config file */ config_write_file(&cfg, config_file_name); config_destroy(&cfg); return 0; }
/** * Initialize the application configuration based on the config file content * Read the config file, get mandatory variables and devices */ int build_config_from_file(struct config_elements * config) { config_t cfg; config_setting_t * root, * database; const char * cur_prefix, * cur_log_mode, * cur_log_level, * cur_log_file = NULL, * one_log_mode, * db_type, * db_sqlite_path, * db_mariadb_host = NULL, * db_mariadb_user = NULL, * db_mariadb_password = NULL, * db_mariadb_dbname = NULL; int db_mariadb_port = 0; config_init(&cfg); if (!config_read_file(&cfg, config->config_file)) { fprintf(stderr, "Error parsing config file %s\nOn line %d error: %s\n", config_error_file(&cfg), config_error_line(&cfg), config_error_text(&cfg)); config_destroy(&cfg); return 0; } if (config->instance->port == -1) { // Get Port number to listen to int port; config_lookup_int(&cfg, "port", &port); config->instance->port = port; } if (config->url_prefix == NULL) { // Get prefix url if (config_lookup_string(&cfg, "url_prefix", &cur_prefix)) { config->url_prefix = o_strdup(cur_prefix); if (config->url_prefix == NULL) { fprintf(stderr, "Error allocating config->url_prefix, exiting\n"); config_destroy(&cfg); return 0; } } } if (config->log_mode == Y_LOG_MODE_NONE) { // Get log mode if (config_lookup_string(&cfg, "log_mode", &cur_log_mode)) { one_log_mode = strtok((char *)cur_log_mode, ","); while (one_log_mode != NULL) { if (0 == strncmp("console", one_log_mode, strlen("console"))) { config->log_mode |= Y_LOG_MODE_CONSOLE; } else if (0 == strncmp("syslog", one_log_mode, strlen("syslog"))) { config->log_mode |= Y_LOG_MODE_SYSLOG; } else if (0 == strncmp("file", one_log_mode, strlen("file"))) { config->log_mode |= Y_LOG_MODE_FILE; // Get log file path if (config->log_file == NULL) { if (config_lookup_string(&cfg, "log_file", &cur_log_file)) { config->log_file = o_strdup(cur_log_file); if (config->log_file == NULL) { fprintf(stderr, "Error allocating config->log_file, exiting\n"); config_destroy(&cfg); return 0; } } } } one_log_mode = strtok(NULL, ","); } } } if (config->log_level == Y_LOG_LEVEL_NONE) { // Get log level if (config_lookup_string(&cfg, "log_level", &cur_log_level)) { if (0 == strncmp("NONE", cur_log_level, strlen("NONE"))) { config->log_level = Y_LOG_LEVEL_NONE; } else if (0 == strncmp("ERROR", cur_log_level, strlen("ERROR"))) { config->log_level = Y_LOG_LEVEL_ERROR; } else if (0 == strncmp("WARNING", cur_log_level, strlen("WARNING"))) { config->log_level = Y_LOG_LEVEL_WARNING; } else if (0 == strncmp("INFO", cur_log_level, strlen("INFO"))) { config->log_level = Y_LOG_LEVEL_INFO; } else if (0 == strncmp("DEBUG", cur_log_level, strlen("DEBUG"))) { config->log_level = Y_LOG_LEVEL_DEBUG; } } } if (!y_init_logs(GARETH_LOG_NAME, config->log_mode, config->log_level, config->log_file, "Starting Gareth alert and messenger service")) { fprintf(stderr, "Error initializing logs\n"); exit_server(&config, GARETH_ERROR); } root = config_root_setting(&cfg); database = config_setting_get_member(root, "database"); if (database != NULL) { if (config_setting_lookup_string(database, "type", &db_type) == CONFIG_TRUE) { if (0 == strncmp(db_type, "sqlite3", strlen("sqlite3"))) { if (config_setting_lookup_string(database, "path", &db_sqlite_path) == CONFIG_TRUE) { config->conn = h_connect_sqlite(db_sqlite_path); if (config->conn == NULL) { config_destroy(&cfg); fprintf(stderr, "Error opening sqlite database %s\n", db_sqlite_path); return 0; } } else { config_destroy(&cfg); fprintf(stderr, "Error, no sqlite database specified\n"); return 0; } } else if (0 == strncmp(db_type, "mariadb", strlen("mariadb"))) { config_setting_lookup_string(database, "host", &db_mariadb_host); config_setting_lookup_string(database, "user", &db_mariadb_user); config_setting_lookup_string(database, "password", &db_mariadb_password); config_setting_lookup_string(database, "dbname", &db_mariadb_dbname); config_setting_lookup_int(database, "port", &db_mariadb_port); config->conn = h_connect_mariadb(db_mariadb_host, db_mariadb_user, db_mariadb_password, db_mariadb_dbname, db_mariadb_port, NULL); if (config->conn == NULL) { fprintf(stderr, "Error opening mariadb database %s\n", db_mariadb_dbname); config_destroy(&cfg); return 0; } } else { config_destroy(&cfg); fprintf(stderr, "Error, database type unknown\n"); return 0; } } else { config_destroy(&cfg); fprintf(stderr, "Error, no database type found\n"); return 0; } } else { config_destroy(&cfg); fprintf(stderr, "Error, no database setting found\n"); return 0; } config_destroy(&cfg); return 1; }