コード例 #1
0
ファイル: mycodo-1.2.c プロジェクト: kkelly51/Mycodo
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;
}
コード例 #2
0
ファイル: config.c プロジェクト: shalecraig/updatemgr
// 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;
}
コード例 #3
0
ファイル: session.c プロジェクト: evomonza/opendomo
// {{{ session_is_valid_sessid()
int session_is_valid_sessid(const char *sessid)
{
	// TODO use timestamp: session not expires.
	
   struct config_t cfg;
   config_init(&cfg);
   config_setting_t *cs;
   config_setting_t *vs;

   if(!config_read_file(&cfg, OD_SESSION_FILE))
      return 0;

   int i=0;
   for(i=0; ;i++)
   {
      if( !(cs = config_setting_get_elem(cfg.root, i)) )
         break;

      if( !(vs = config_setting_get_member(cs, "sessid")) )
         continue;

      const char *res = config_setting_get_string(vs);
      if(res)
         if(strcmp(res, sessid)==0)
         {
            config_destroy(&cfg);
            return 1;
         }

   }

   config_destroy(&cfg);
   return 0;
}
コード例 #4
0
ファイル: common.c プロジェクト: derek-chou/TSECDecoder
void get_conf_int (char *key, int *value) {
  config_t *conf = &(config_t) {};
  config_init (conf);
  config_read_file (conf, "TSECDecoder.conf");
  config_lookup_int(conf, key, value);
  config_destroy (conf);
}
コード例 #5
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;
}
コード例 #6
0
ファイル: read_conf.c プロジェクト: radioanonymous/mpd
int main(int argc, char **argv)
{
	if (argc != 3) {
		g_printerr("Usage: read_conf FILE SETTING\n");
		return 1;
	}

	const char *path = argv[1];
	const char *name = argv[2];

	g_log_set_default_handler(my_log_func, NULL);

	config_global_init();

	GError *error = NULL;
	bool success = config_read_file(path, &error);
	if (!success) {
		g_printerr("%s:", error->message);
		g_error_free(error);
		return 1;
	}

	const char *value = config_get_string(name, NULL);
	int ret;
	if (value != NULL) {
		g_print("%s\n", value);
		ret = 0;
	} else {
		g_printerr("No such setting: %s\n", name);
		ret = 2;
	}

	config_global_finish();
	return ret;
}
コード例 #7
0
ファイル: smaller.c プロジェクト: SwitchCase/SnowFlake
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);
	}
	
	
}
コード例 #8
0
ファイル: sample2.c プロジェクト: aveek0218/ImpalaPythia
int main()
{
  /* Initialize the configuration */
  config_init(&cfg);

  /* Load the file */
  printf("loading [sample.cfg]..");
  if (!config_read_file(&cfg, "sample.cfg"))
    printf("failed\n");
  else
  {
    printf("ok\n");
    
    /* Display the "values" array */
    printf("display \"values\"..");
    config_setting_t *array = config_lookup(&cfg, "values");
    if (!array)
      printf("failed\n");
    else
    {
      long value1,value2;
      value1 = config_setting_get_int_elem(array, 0);
      value2 = config_setting_get_int_elem(array, 1);
      printf("[%lu %lu]..ok\n", value1, value2);

      printf("Done!\n");
    }

  }

  /* Free the configuration */
  config_destroy(&cfg);

  return 0;
}
コード例 #9
0
ファイル: config.c プロジェクト: peplin/spade
int configure_server(spade_server* server, char* configuration_path,
        unsigned int override_port) {
    config_t configuration_struct, *configuration;
    configuration = &configuration_struct;
    config_init(configuration);

    if (!config_read_file(configuration, configuration_path)) {
        log4c_category_log(log4c_category_get("spade"), LOG4C_PRIORITY_ERROR,
                "Configuration error: %s:%d - %s",
                configuration_path,
                config_error_line(configuration),
                config_error_text(configuration));
        config_destroy(configuration);
        return(EXIT_FAILURE);
    }

    configure_hostname(server, configuration);
    configure_port(server, override_port, configuration);
    configure_reverse_lookups(server, configuration);
    configure_static_file_path(server, configuration);
    configure_dynamic_file_paths(server, configuration);
    configure_dynamic_handlers(server, configuration);

    config_destroy(configuration);
    return 0;
}
コード例 #10
0
static const config_t * load_config(char * filename)
{
	int ret;
	config_t * config = NULL;
	struct stat sts;
	char * fullname;

	fullname = strconcat(base_directory,"/",filename,NULL);

	config = (config_t*)malloc(sizeof(config_t));
	if(config == NULL) {
		free(fullname);
		return NULL;
	}
	bzero(config,sizeof(config_t));

	ret = config_read_file (config, fullname);
	if( ret == CONFIG_FALSE ) {
		// For client, only print errors when file is present
		// If file is not present, let get_config ask for a network update
		if(stat(fullname,&sts) != -1 || client_server == SERVER) {
			config_print_error(fullname,config);
		}
		free(fullname);
		return NULL;
	}

	free(fullname);
	return config;
}
コード例 #11
0
ファイル: database.c プロジェクト: sanek701/CCTV-linux-msiu
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);
  }
}
コード例 #12
0
ファイル: startup.c プロジェクト: Rabbitlancer/qdb
static int qdb_config() {
	config_t cfg;
	config_setting_t *cfg_qdb;
	config_setting_t *cfg_interfaces;
	int status = 0;

	config_init(&cfg);
	if (config_read_file(&cfg,CONFPATH) == CONFIG_FALSE)
		goto err;

	cfg_qdb = config_lookup(&cfg,"qdb");
	if (cfg_qdb == NULL) goto err;
	cfg_interfaces = config_lookup(&cfg,"qdb/interfaces");
	if (cfg_interfaces == NULL) goto err;

	goto done;
err:
	printerr(config_error_text(&cfg));
	status = -1;

done:
	config_destroy(&cfg);

	return status;
}
コード例 #13
0
ファイル: GameLoop.cpp プロジェクト: aaraddhyanb/GreenLagoon
	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();
	}
コード例 #14
0
ファイル: mst_config.c プロジェクト: hi2arun/mstunnel
int mst_config_load(const char *conf_path)
{
    int rv = -1;

    config_init(&g_config);

    rv = config_read_file(&g_config, conf_path);

    if (CONFIG_FALSE == rv) {
        fprintf(stderr, "Failed to load config: %s @ %d\n", config_error_text(&g_config), config_error_line(&g_config));
        return -1;
    }

    if (CONFIG_TRUE != (rv = mst_read_version(&g_config))) {
        fprintf(stderr, "Error: %s @ %d\n", config_error_text(&g_config), config_error_line(&g_config));
        return -1;
    }
    if (CONFIG_TRUE != (rv = mst_read_type(&g_config))) {
        fprintf(stderr, "Error: %s @ %d\n", config_error_text(&g_config), config_error_line(&g_config));
        return -1;
    }
    if (CONFIG_TRUE != (rv = mst_read_globals(&g_config))) {
        fprintf(stderr, "Error: %s @ %d\n", config_error_text(&g_config), config_error_line(&g_config));
        return -1;
    }

    if (CONFIG_TRUE != (rv = mst_read_policy_details(&g_config))) {
        fprintf(stderr, "Error: %s @ %d\n", config_error_text(&g_config), config_error_line(&g_config));
        return -1;
    }

    return 0;
}
コード例 #15
0
ファイル: config.c プロジェクト: intersvyaz/zerod
/**
 * Load configuration file.
 * @param[in] path Configuration file location.
 * @param[in,out] zconf Parsed configuration storage.
 * @return True on success.
 */
bool zconfig_load(const char *path, zconfig_t *zconf)
{
    if (NULL == path) {
        ZLOG(LOG_ERR, "config: configuration file not specified");
        return false;
    }

    bool loaded = false;
    config_t config;
    config_init(&config);

    if (!config_read_file(&config, path)) {
        ZLOG(LOG_ERR, "config: failed to parse %s (error: %s at %d line)",
             path, config_error_text(&config), config_error_line(&config));
        goto end;
    }

    const config_setting_t *root = config_root_setting(&config);

    if (!zconfig_load_sections(root, zconf)) {
        zconfig_destroy(zconf);
    } else {
        loaded = true;
    }

    end:
    config_destroy(&config);

    return loaded;
}
コード例 #16
0
ファイル: read_configs.cpp プロジェクト: maxhowald/crts
int read_scenario_master_file(char scenario_list[30][60],
                              unsigned int scenario_reps[60]) {
  config_t cfg; // Returns all parameters in this structure
  char current_scenario[30];
  const char *tmpS;
  int num_scenarios = 1;
  int tmpI; // Stores the value of Integer Parameters from Config file

  config_init(&cfg);

  // Read the file. If there is an error, report it and exit.
  if (!config_read_file(&cfg, "master_scenario_file.cfg")) {
    printf("Error reading master scenario file on line %i\n",
           config_error_line(&cfg));
    exit(1);
  }

  // Read the parameter group
  if (config_lookup_int(&cfg, "NumberofScenarios", &tmpI))
    num_scenarios = (int)tmpI;

  for (int i = 0; i < num_scenarios; i++) {
    sprintf(current_scenario, "scenario_%d", i + 1);
    if (config_lookup_string(&cfg, current_scenario, &tmpS))
      strcpy(&scenario_list[i][0], tmpS);
  }
  for (int i = 0; i < num_scenarios; i++) {
    sprintf(current_scenario, "reps_scenario_%d", i + 1);
    if (config_lookup_int(&cfg, current_scenario, &tmpI))
      scenario_reps[i] = tmpI;
  }
  config_destroy(&cfg);
  return num_scenarios;
} // End readScMasterFile()
コード例 #17
0
int main(int argc, char ** argv)
{
  char * recname;
  config_t cfg;

  if(argc != 2)
    usage(argv[0]);
  
  recname = argv[1];
  
  err = open(STATEFILE,O_RDWR);
  CHECK_ERR_LTZ("Open schedule file");
  fd = err;
  err = flock(fd, LOCK_SH);
  CHECK_ERR("Lock statefile");

  err = atexit(&exitfunc);

  config_init(&cfg);
  config_read_file(&cfg, STATEFILE);
  config_setting_t *root;

  root = config_root_setting(&cfg);
  err = config_setting_remove(root, recname);
  CHECK_CFG("Remove recording from schedule");
  err = config_write_file(&cfg, STATEFILE);
  CHECK_CFG("Write config file");
  config_destroy(&cfg);

  return 0;
}
コード例 #18
0
ファイル: sally.c プロジェクト: yangke/sally
/**
 * Load the configuration of Sally
 * @param argc number of arguments
 * @param argv arguments
 */
static void sally_load_config(int argc, char **argv)
{
    char* cfg_file = NULL;
    int ch;

    /* Check for config file in command line */
    while ((ch = getopt_long(argc, argv, OPTSTRING, longopts, NULL)) != -1) {
        switch (ch) {
        case 'c':
            cfg_file = optarg;
            break;
        case '?':
            print_usage();
            exit(EXIT_SUCCESS);
            break;
        default:                                                                    
            /* empty */
            break;
        }
    }

    /* Init and load configuration */
    config_init(&cfg);

    if (cfg_file != NULL) {
        if (config_read_file(&cfg, cfg_file) != CONFIG_TRUE)
            fatal("Could not read configuration (%s in line %d)",
                  config_error_text(&cfg), config_error_line(&cfg));
    }

    /* Check configuration */
    if (!config_check(&cfg)) {
        exit(EXIT_FAILURE);
    }
}
コード例 #19
0
ファイル: layout.c プロジェクト: ChiaraCaiazza/collageMaker
void print_layouts(int num_frame)
{
	
	config_setting_t *category_list, *category, *layout_list, *layout;
	config_t layout_config;
	int layout_length, i;
	const char* ascii_image;

	config_init(&layout_config);
	config_read_file(&layout_config, "./layout.cfg");
	
	category_list = config_lookup(&layout_config, "application.layout_group");
	category = config_setting_get_elem(category_list, num_frame - MIN_NUM_FRAME);
	
	layout_list = config_setting_get_member(category, "layout");
	layout_length = config_setting_length(layout_list);
	for(i = 0; i < layout_length; i++)
	{
		layout = config_setting_get_elem(layout_list, i);
		config_setting_lookup_string(layout, "image", &ascii_image);
		printf(" %c)\n", 'a' + i);
		printf("%s\n", ascii_image);
	}
	
	config_destroy(&layout_config);
}
コード例 #20
0
ファイル: bkgd_mean_cat_val.c プロジェクト: gmcvicker/bkgd
/**
 * Main function
 */
int main(int argc, char **argv) {
  double mean_cat;
  BkgdEvoMdlData *data;
  Config *config;
    
  if(argc != 2) {
    fprintf(stderr, "usage: %s <config>\n", 
	    argv[0]);
    exit(2);
  }

  config = config_read_file(argv[1], CONFIG_MISSING_KEY_ERROR);

  data = bkgd_data_read_data(config);

  mean_cat = bkgd_data_mean_cat_val(data);

  fprintf(stderr, "mean category value: %g\n", mean_cat);

  free(data->bin);
  free(data);


  return 0;
}
コード例 #21
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;
}
コード例 #22
0
ファイル: util_config.c プロジェクト: vysheng/vkconcli
void read_config (void) {
#ifdef ENABLE_LIBCONFIG
  config_file_name = makepath (config_file_name);
  config_setting_t *conf_setting;
  config_init (&conf);

  if (config_read_file (&conf, config_file_name) != CONFIG_TRUE) {
    vk_critical_error (ERROR_CONFIG, "error parsing config `%s`: %s\n", config_file_name, config_error_text (&conf));
  }
#endif
  BOOL_CONF_VAR (disable_net, "disable_net", 0);
  BOOL_CONF_VAR (disable_sql, "disable_sql", 0);
  BOOL_CONF_VAR (disable_audio, "disable_audio", 0);
  INT_CONF_VAR (default_history_limit, "default_history_limit", 100);
  INT_CONF_VAR (max_cached_items, "max_cached_items", 10000);
  STR_CONF_VAR0 (username, "username");
  STR_CONF_VAR0 (password, "password");
  STR_CONF_VAR0 (access_token, "access_token");
  STR_CONF_VAR0 (access_token_file, "access_token_file");
  if (access_token_file) {
    access_token_file = makepath (access_token_file); 
  }
  STR_CONF_VAR (db_file_name, "db_file_name", DEFAULT_DB_FILE_NAME);
  if (db_file_name) {
    db_file_name = makepath (db_file_name);
  }
  INT_CONF_VAR (connections, "connections", 10);
  if (connections <= 1) { connections = 2; }
  if (connections >= 1000) { connections = 1000; }
}
コード例 #23
0
ファイル: read_configs.cpp プロジェクト: maxhowald/crts
struct scenario_parameters read_scenario_parameters(char *scenario_file) {
  // configuration variable
  config_t cfg;
  config_init(&cfg);

  // string pointing to scenario file
  char scenario[100];
  strcpy(scenario, "scenarios/");
  strcat(scenario, scenario_file);

  // Read the file. If there is an error, report it and exit.
  if (!config_read_file(&cfg, scenario)) {
    printf("Error reading %s on line %i\n", scenario, config_error_line(&cfg));
    printf("%s\n", config_error_text(&cfg));
    config_destroy(&cfg);
    exit(1);
  }

  // Read scenario parameters
  struct scenario_parameters sp;
  int tmpI;
  double tmpD;

  config_lookup_int(&cfg, "num_nodes", &tmpI);
  sp.num_nodes = tmpI;
  config_lookup_float(&cfg, "run_time", &tmpD);
  sp.runTime = (time_t)tmpD;
  config_destroy(&cfg);

  return sp;
} // End readScConfigFile()
コード例 #24
0
ファイル: example2.c プロジェクト: anagno/imretOpenMVG
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);
}
コード例 #25
0
int cfgReadFile(config_t *config, const TCHAR *filename)
{
	char uFileName[MAX_PATH];

	UTF8_Encode(filename, uFileName, MAX_PATH);

	return config_read_file(config, uFileName);
}
コード例 #26
0
ファイル: config.c プロジェクト: asqz/tint2
int config_read ()
{
	const gchar * const * system_dirs;
	char *path1;
	gint i;

	// follow XDG specification
	// check tint2rc in user directory
	path1 = g_build_filename (g_get_user_config_dir(), "tint2", "tint2rc", NULL);
	if (g_file_test (path1, G_FILE_TEST_EXISTS)) {
		i = config_read_file (path1);
		config_path = strdup(path1);
		g_free(path1);
		return i;
	}
	g_free(path1);

	// copy tint2rc from system directory to user directory
	char *path2 = 0;
	system_dirs = g_get_system_config_dirs();
	for (i = 0; system_dirs[i]; i++) {
		path2 = g_build_filename(system_dirs[i], "tint2", "tint2rc", NULL);

		if (g_file_test(path2, G_FILE_TEST_EXISTS)) break;
		g_free (path2);
		path2 = 0;
	}

	if (path2) {
		// copy file in user directory (path1)
		char *dir = g_build_filename (g_get_user_config_dir(), "tint2", NULL);
		if (!g_file_test (dir, G_FILE_TEST_IS_DIR)) g_mkdir(dir, 0777);
		g_free(dir);

		path1 = g_build_filename (g_get_user_config_dir(), "tint2", "tint2rc", NULL);
		copy_file(path2, path1);
		g_free(path2);

		i = config_read_file (path1);
		config_path = strdup(path1);
		g_free(path1);
		return i;
	}
	return 0;
}
コード例 #27
0
ファイル: user_settings.c プロジェクト: gnaservicesinc/tpad
int cfg_get_show_full_path(char *cfg_file){
	if(!config_read_file(&userCfg.cfg, (char*)cfg_file )) return(1);
	else {
		int ShowFullPath;	
		userCfg.setting = config_lookup(&userCfg.cfg,"User_Pref");
		config_setting_lookup_int(userCfg.setting,"Show_Full_Path", &ShowFullPath);
		return ShowFullPath;
	}
}
コード例 #28
0
ファイル: misc.c プロジェクト: yangkkokk/Beagle_SDR_GPS
void cfg_init()
{
	config_init(&cfg);
	if (!config_read_file(&cfg, CFG_FILE)) {
		lprintf("check that config file is installed in %s\n", CFG_FILE);
		cfg_error("kiwi.cfg");
	}
	lprintf("reading configuration from file %s\n", CFG_FILE);
}
コード例 #29
0
ファイル: config.c プロジェクト: ifzz/yabtorrent
int config_read(config_t* cfg, const char *dir, const char *file)
{
	char path[BUFSIZ];

	if (config_get_default_path(cfg, path, BUFSIZ, dir, file) < 0)
		return -1;

	return config_read_file(cfg, path);
}
コード例 #30
0
ファイル: user_settings.c プロジェクト: gnaservicesinc/tpad
int cfg_get_default_auto_tab(char *cfg_file){
	if(!config_read_file(&userCfg.cfg, (char*)cfg_file )) return(0);
	else {
		int DefaultAutoTab;	
		userCfg.setting = config_lookup(&userCfg.cfg,"User_Pref");
		config_setting_lookup_int(userCfg.setting,"Auto_Tab", &DefaultAutoTab);
		return DefaultAutoTab;
	}
}