コード例 #1
0
ファイル: section_add.c プロジェクト: jqyy/libconfuse
int main(void)
{
	static cfg_opt_t section_opts[] = {
		CFG_STR("prop", 0, CFGF_NONE),
		CFG_END()
	};

	cfg_opt_t opts[] = {
		CFG_SEC("section", section_opts, CFGF_TITLE | CFGF_MULTI),
		CFG_END()
	};

	const char *config_data =
		"section title_one { prop = 'value_one' }\n"
		"section title_two { prop = 'value_two' }\n";

	int rc;
	cfg_t *cfg = cfg_init(opts, CFGF_NONE);

	fail_unless(cfg);

	rc = cfg_parse_buf(cfg, config_data);
	fail_unless(rc == CFG_SUCCESS);

	fail_unless(cfg_addtsec(cfg, "section", "title_three"));
	fail_unless(cfg_size(cfg, "section") == 3);
	fail_unless(cfg_title(cfg_gettsec(cfg, "section", "title_three")));

	/* attempt to add a pre-existing section should fail */
	fail_unless(!cfg_addtsec(cfg, "section", "title_three"));

	cfg_free(cfg);

	return 0;
}
コード例 #2
0
ファイル: config.cpp プロジェクト: oioi/zbx_tools
int read_config(const char *filename, section_t &config)
{
   static const char *funcname = "conf::read_config";

   section_ptrs ptrs;
   build_section(&config, ptrs);

   cfg_t *cfg = cfg_init(ptrs[0].get(), CFGF_NONE);
   cfg_set_error_function(cfg, cfg_error_fnc);

   switch(cfg_parse(cfg, filename))
   {
      case CFG_FILE_ERROR:
         throw logging::error(funcname, "Configuration file '%s' cannot be read: %s", filename, strerror(errno));
      case CFG_PARSE_ERROR:
         throw logging::error(funcname, "Errors were encountered during config reading.");
      default:
         throw logging::error(funcname, "cfg_parse() returned unexpected value");

      case CFG_SUCCESS: break;
   }   

   std::stringstream errors;
   read_cfg_section(&config, cfg, errors);
   cfg_free(cfg);

   errors.peek();
   if (!errors.eof())
   {
      for (std::string line; getline(errors, line); )
         logger.log_message(LOG_ERR, funcname, line.c_str());
      return 0;
   }
   return 1;
}
コード例 #3
0
ファイル: config.c プロジェクト: CristopherLeal/SVMClassifier
db_info * get_db_info(const char * filename){

   cfg_opt_t * opts = get_opt();

   cfg_t *cfg;

   cfg = cfg_init(opts, CFGF_NONE);
   cfg_parse(cfg, filename);

   db_info * info;
   info = (db_info*)malloc(sizeof(db_info));

   char * user = cfg_getstr(cfg, "user");
   char * password = cfg_getstr(cfg,"password");
   char * dbname = cfg_getstr(cfg,"dbname");
   char * ip = cfg_getstr(cfg,"ip");
   
   info->user = (char*)malloc(strlen(user)*sizeof(char));
   info->password = (char*)malloc(strlen(user)*sizeof(char));
   info->dbname = (char*)malloc(strlen(user)*sizeof(char));
   info->ip = (char*)malloc(strlen(user)*sizeof(char));
   
   strcpy(info->user,user);
   strcpy(info->password,password);
   strcpy(info->dbname,dbname);
   strcpy(info->ip,ip);
   info->port = cfg_getint(cfg,"port");

   cfg_free(cfg);

   return info;
}
コード例 #4
0
/* the main program... */
int main(int argc,char *argv[])
{
  char *srcdir;
  char fname[100];
  struct sigaction act;
  /* build the name of the file */
  srcdir=getenv("srcdir");
  if (srcdir==NULL)
    srcdir=".";
  snprintf(fname,sizeof(fname),"%s/nslcd-test.conf",srcdir);
  fname[sizeof(fname)-1]='\0';
  /* initialize configuration */
  cfg_init(fname);
  /* partially initialize logging */
  log_setdefaultloglevel(LOG_DEBUG);
  /* ignore SIGPIPE */
  memset(&act,0,sizeof(struct sigaction));
  act.sa_handler=SIG_IGN;
  sigemptyset(&act.sa_mask);
  act.sa_flags=SA_RESTART|SA_NOCLDSTOP;
  assert(sigaction(SIGPIPE,&act,NULL)==0);
  /* do tests */
  test_search();
  test_get();
  test_get_values();
  test_get_rdnvalues();
  test_two_searches();
  test_threads();
  test_connections();
  test_escape();
  return 0;
}
コード例 #5
0
ファイル: synclogger.cpp プロジェクト: se-bi/offlinefs
bool SyncLogger::ParseFile(const char* pszHash)
{
	if (strcmp(m_szCurShare, pszHash) == 0)
	{
		// File is currently parsed, there is no need to parse it again.
		return true;
	}

    cfg_opt_t modEntry[] =
    {
        // Parses within the group.
        CFG_STR(FILE_PATH_VARNAME, FILE_PATH_DEFAULT, CFGF_NONE),
        CFG_STR(MOD_TIME_VARNAME, MOD_TIME_DEFAULT, CFGF_NONE),
        CFG_STR(MOD_TYPE_VARNAME, MOD_TYPE_DEFAULT, CFGF_NONE),
        CFG_END()
    };
    cfg_opt_t entries[] =
    {
        // Parses the single groups.
        CFG_SEC(MOD_NUMBER_VARNAME, modEntry, CFGF_TITLE | CFGF_MULTI),
        CFG_END()
    };

    // Initializes the parser.
    m_pCFG = cfg_init(entries, CFGF_NONE);

    // Parses the file.
	char szLogName[MAX_PATH];
	CalcLogFileName(pszHash, szLogName);
    if (cfg_parse(m_pCFG, szLogName) == CFG_PARSE_ERROR)
        return false;
    return true;
}
コード例 #6
0
ファイル: SettingsConfuse.cpp プロジェクト: miivers/telldus
bool readVarConfig(cfg_t **cfg) {
	cfg_opt_t device_opts[] = {
		CFG_INT(const_cast<char *>("state"), 0, CFGF_NONE),
		CFG_STR(const_cast<char *>("stateValue"), const_cast<char *>(""), CFGF_NONE),
		CFG_END()
	};

	cfg_opt_t opts[] = {
		CFG_SEC(const_cast<char *>("device"), device_opts, CFGF_MULTI | CFGF_TITLE),
		CFG_END()
	};

	FILE *fp = fopen(VAR_CONFIG_FILE, "re");  // e for setting O_CLOEXEC on the file handle
	if (!fp) {
		return false;
	}
	(*cfg) = cfg_init(opts, CFGF_NOCASE);
	if (cfg_parse_fp((*cfg), fp) == CFG_PARSE_ERROR) {
		(*cfg) = 0;
		fclose(fp);
		return false;
	}

	fclose(fp);
	return true;
}
コード例 #7
0
int main(int argc, char **argv)
{
	char *cfgfile;
	
	if (sock_start())
		return -1;
	vlist_init(&pipes, pipe_destroy);
	cfg_init(&cfg, 0);
	atexit(cleanup);

	/* Look for the config file in the executable directory.  Windows
	 * uses it as the working directory, so we can use a relative
	 * filename.  On UNIX or the Mac, use the executable path and
	 * filename from argv[0].
	 */
#ifdef __WIN32__
	cfgfile = defcfgfile;
#else
	cfgfile = malloc(strlen(argv[0]) + 4 + 1);
	strcpy(cfgfile, argv[0]);
	strcat(cfgfile, ".cfg");
#endif
	/* Prefer a config file specified on the command line */
	readcfg(argc > 1 ? argv[argc - 1] : cfgfile);
#ifdef DEBUG
	debug();
#endif
	waitclients();
	
	return 0;
}
コード例 #8
0
ファイル: confuse.c プロジェクト: troglobit/toolbox
cfg_t *parse_conf(char *conf)
{
	cfg_opt_t provider_opts[] = {
		CFG_STR     ("username",  0, CFGF_NONE),
		CFG_STR     ("password",  0, CFGF_NONE),
		CFG_STR_LIST("alias",     0, CFGF_NONE),
		CFG_END()
	};
	cfg_opt_t opts[] = {
		CFG_BOOL("syslog",	  cfg_false, CFGF_NONE),
		CFG_BOOL("wildcard",	  cfg_false, CFGF_NONE),
		CFG_STR ("bind",	  0, CFGF_NONE),
		CFG_INT ("period",	  60, CFGF_NONE),
		CFG_INT ("startup-delay", 0, CFGF_NONE),
		CFG_INT ("forced-update", 720000, CFGF_NONE),
		CFG_SEC ("provider", provider_opts, CFGF_MULTI | CFGF_TITLE),
		CFG_END()
	};
	cfg_t *cfg = cfg_init(opts, CFGF_NONE);

	switch (cfg_parse(cfg, conf)) {
	case CFG_FILE_ERROR:
		fprintf(stderr, "Cannot read configuration file %s: %s\n", conf, strerror(errno));

	case CFG_PARSE_ERROR:
		return NULL;

	case CFG_SUCCESS:
		break;
	}

    return cfg;
}
コード例 #9
0
ファイル: main.c プロジェクト: md81544/c
int main(int argc, char *argv[])
{
    // Initialise the cfg structure (this sets up a linked list
    // of key / value pairs)
    struct Config *cfg = cfg_init("settings.cfg");

    // Search for a key. Note that the return value is a pointer
    // in the cfg structure so should NOT be freed (it is freed
    // eventually by cfg_free.);
    char *value = cfg_get_string(cfg, "barney", "The default value");
    printf("\"%s\"\n", value);

    // Search for a non-existent key to show default value being returned
    char *value2 = cfg_get_string(cfg, "non-existent", "A default value");
    printf("\"%s\"\n", value2);

    // Get a number
    long num = cfg_get_long(cfg, "NuMbEr", 69);
    printf("Number is %ld\n", num);

    // Dump everything - showing the cfg_foreach() function
    printf("DEBUG dump all:\n");
    cfg_foreach(cfg, callback);

    // Finally tear down the cfg structure. This will invalidate any 
    // strings we've been returned, so we should make copies of 
    // anything we want to keep first.
    cfg_free(cfg);

    return 0;
}
コード例 #10
0
ファイル: conf.c プロジェクト: noushi/bmon
static void __init __conf_init(void)
{
	cfg = cfg_init(global_opts, CFGF_NOCASE);

	/* FIXME: Add validation functions */
	//cfg_set_validate_func(cfg, "bookmark", &cb_validate_bookmark);
}
コード例 #11
0
ファイル: config.c プロジェクト: CharlesLio/schismtracker
void cfg_save(void)
{
        char *ptr;
        cfg_file_t cfg;

        ptr = dmoz_path_concat(cfg_dir_dotschism, "config");
        cfg_init(&cfg, ptr);
        free(ptr);

        // this wart is here because Storlek is retarded
        cfg_delete_key(&cfg, "Directories", "filename_pattern");

        cfg_set_string(&cfg, "Directories", "modules", cfg_dir_modules);
        cfg_set_string(&cfg, "Directories", "samples", cfg_dir_samples);
        cfg_set_string(&cfg, "Directories", "instruments", cfg_dir_instruments);
        /* No, it's not a directory, but whatever. */
        cfg_set_string(&cfg, "Directories", "module_pattern", cfg_module_pattern);
        cfg_set_string(&cfg, "Directories", "export_pattern", cfg_export_pattern);

        cfg_save_info(&cfg);
        cfg_save_patedit(&cfg);
        cfg_save_audio(&cfg);
        cfg_save_palette(&cfg);
        cfg_save_disko(&cfg);
        cfg_save_dmoz(&cfg);

        cfg_write(&cfg);
        cfg_free(&cfg);
}
コード例 #12
0
ファイル: server_functions.c プロジェクト: darakian/cmtp
/*
Function to parse the server config file.
@param Config file location in the file system.
@param Struct to write results into.
@return -1 on failure, 0 on success.
*/
int parse_config(char * config_file, struct config_struct * running_config)
{
  print_to_log("Parsing config file", LOG_INFO);
  cfg_opt_t opts[] =
	{
	  CFG_STR("domain", "", CFGF_NONE),
    CFG_INT("connection_timeout_in_seconds", 0, CFGF_NONE),
    CFG_INT("max_connections", 0, CFGF_NONE),
	  CFG_END()
	};
	cfg_t *cfg;
	cfg = cfg_init(opts, CFGF_NONE);
	 if(cfg_parse(cfg, config_file) == CFG_PARSE_ERROR)
   {
     printf("Reading config %s has failed\n", config_file);
     return -1;
   }
   if (strcmp(cfg_getstr(cfg, "domain"),"")!=0)
   {
     //Load domain into struct here.
   }
   if (cfg_getint(cfg, "connection_timeout_in_seconds")<=60)
   {
     //load connection_timeout_in_seconds into struct here.
     running_config->connection_timeout_in_seconds = cfg_getint(cfg, "connection_timeout_in_seconds");
   }
   if (cfg_getint(cfg, "max_connections")<=1000)
   {
     //load connection_timeout_in_seconds into struct here.
     running_config->max_connections = cfg_getint(cfg, "max_connections");
   }
   return 0;
}
コード例 #13
0
ファイル: SettingsConfuse.cpp プロジェクト: miivers/telldus
bool readConfig(cfg_t **cfg) {
	// All the const_cast keywords is to remove the compiler warnings generated by the C++-compiler.
	cfg_opt_t controller_opts[] = {
		CFG_INT(const_cast<char *>("id"), -1, CFGF_NONE),
		CFG_STR(const_cast<char *>("name"), const_cast<char *>(""), CFGF_NONE),
		CFG_INT(const_cast<char *>("type"), 0, CFGF_NONE),
		CFG_STR(const_cast<char *>("serial"), const_cast<char *>(""), CFGF_NONE),

		CFG_END()
	};

	cfg_opt_t device_parameter_opts[] = {
		// Groups
		CFG_STR(const_cast<char *>("devices"), 0, CFGF_NONE),

		CFG_STR(const_cast<char *>("house"), 0, CFGF_NONE),
		CFG_STR(const_cast<char *>("unit"), 0, CFGF_NONE),
		CFG_STR(const_cast<char *>("code"), 0, CFGF_NONE),
		CFG_STR(const_cast<char *>("system"), 0, CFGF_NONE),
		CFG_STR(const_cast<char *>("units"), 0, CFGF_NONE),
		CFG_STR(const_cast<char *>("fade"), 0, CFGF_NONE),

		CFG_END()
	};

	cfg_opt_t device_opts[] = {
		CFG_INT(const_cast<char *>("id"), -1, CFGF_NONE),
		CFG_STR(const_cast<char *>("name"), const_cast<char *>("Unnamed"), CFGF_NONE),
		CFG_INT(const_cast<char *>("controller"), 0, CFGF_NONE),
		CFG_STR(const_cast<char *>("protocol"), const_cast<char *>("arctech"), CFGF_NONE),
		CFG_STR(const_cast<char *>("model"), const_cast<char *>(""), CFGF_NONE),
		CFG_SEC(const_cast<char *>("parameters"), device_parameter_opts, CFGF_NONE),
		CFG_END()
	};

	cfg_opt_t opts[] = {
		CFG_STR(const_cast<char *>("user"), const_cast<char *>("nobody"), CFGF_NONE),
		CFG_STR(const_cast<char *>("group"), const_cast<char *>("plugdev"), CFGF_NONE),
		CFG_STR(const_cast<char *>("deviceNode"), const_cast<char *>("/dev/tellstick"), CFGF_NONE),
		CFG_STR(const_cast<char *>("ignoreControllerConfirmation"), const_cast<char *>("false"), CFGF_NONE),
		CFG_SEC(const_cast<char *>("device"), device_opts, CFGF_MULTI),
		CFG_SEC(const_cast<char *>("controller"), controller_opts, CFGF_MULTI),
		CFG_END()
	};

	FILE *fp = fopen(CONFIG_FILE, "re");  // e for setting O_CLOEXEC on the file handle
	if (!fp) {
		return false;
	}
	(*cfg) = cfg_init(opts, CFGF_NOCASE);
	if (cfg_parse_fp((*cfg), fp) == CFG_PARSE_ERROR) {
		(*cfg) = 0;
		fclose(fp);
		return false;
	}

	fclose(fp);
	return true;
}
コード例 #14
0
ファイル: config.c プロジェクト: CharlesLio/schismtracker
void cfg_atexit_save(void)
{
        char *ptr;
        cfg_file_t cfg;

        ptr = dmoz_path_concat(cfg_dir_dotschism, "config");
        cfg_init(&cfg, ptr);
        free(ptr);

        cfg_atexit_save_audio(&cfg);

        /* TODO: move these config options to video.c, this is lame :)
        Or put everything here, which is what the note in audio_loadsave.cc
        says. Very well, I contradict myself. */
        cfg_set_string(&cfg, "Video", "driver", video_driver_name());
        cfg_set_number(&cfg, "Video", "fullscreen", !!(video_is_fullscreen()));
        cfg_set_number(&cfg, "Video", "mouse_cursor", video_mousecursor_visible());
        cfg_set_number(&cfg, "Video", "lazy_redraw", !!(status.flags & LAZY_REDRAW));

        cfg_set_number(&cfg, "General", "vis_style", status.vis_style);
        cfg_set_number(&cfg, "General", "time_display", status.time_display);
        cfg_set_number(&cfg, "General", "classic_mode", !!(status.flags & CLASSIC_MODE));
        cfg_set_number(&cfg, "General", "make_backups", !!(status.flags & MAKE_BACKUPS));
        cfg_set_number(&cfg, "General", "numbered_backups", !!(status.flags & NUMBERED_BACKUPS));

        cfg_set_number(&cfg, "General", "accidentals_as_flats", !!(status.flags & ACCIDENTALS_AS_FLATS));
        cfg_set_number(&cfg, "General", "meta_is_ctrl", !!(status.flags & META_IS_CTRL));
        cfg_set_number(&cfg, "General", "altgr_is_alt", !!(status.flags & ALTGR_IS_ALT));

        cfg_set_number(&cfg, "General", "midi_like_tracker", !!(status.flags & MIDI_LIKE_TRACKER));
        /* Say, whose bright idea was it to make this a string setting?
        The config file is human editable but that's mostly for developer convenience and debugging
        purposes. These sorts of things really really need to be options in the GUI so that people
        don't HAVE to touch the settings. Then we can just use an enum (and we *could* in theory
        include comments to the config by default listing what the numbers are, but that shouldn't
        be necessary in most cases. */
        switch (status.fix_numlock_setting) {
        case NUMLOCK_ALWAYS_ON:
                cfg_set_string(&cfg, "General", "numlock_setting", "on");
                break;
        case NUMLOCK_ALWAYS_OFF:
                cfg_set_string(&cfg, "General", "numlock_setting", "off");
                break;
        case NUMLOCK_HONOR:
                cfg_set_string(&cfg, "General", "numlock_setting", "system");
                break;
        case NUMLOCK_GUESS:
                /* leave empty */
                break;
        };

        /* hm... most of the time probably nothing's different, so saving the
        config file here just serves to make the backup useless. maybe add a
        'dirty' flag to the config parser that checks if any settings are
        actually *different* from those in the file? */

        cfg_write(&cfg);
        cfg_free(&cfg);
}
コード例 #15
0
ファイル: cli.c プロジェクト: peda-r/libconfuse
int main(void)
{
	cfg_opt_t sub_opts[] = {
		CFG_BOOL("bool", cfg_false, CFGF_NONE),
		CFG_STR("string", NULL, CFGF_NONE),
		CFG_INT("int", 0, CFGF_NONE),
		CFG_FLOAT("float", 0.0, CFGF_NONE),
		CFG_END()
	};

	cfg_opt_t opts[] = {
		CFG_BOOL_LIST("bool", cfg_false, CFGF_NONE),
		CFG_STR_LIST("string", NULL, CFGF_NONE),
		CFG_INT_LIST("int", 0, CFGF_NONE),
		CFG_FLOAT_LIST("float", "0.0", CFGF_NONE),
		CFG_SEC("sub", sub_opts,
			CFGF_MULTI | CFGF_TITLE | CFGF_NO_TITLE_DUPES),
		CFG_END()
	};

	char *cmd = NULL;
	const char *reply;
	int res;
	int i;

	cfg = cfg_init(opts, CFGF_NONE);

	for (;;) {
		printf("cli> ");
		fflush(stdout);

		if (cmd)
			free(cmd);
		cmd = input_cmd();
		if (!cmd)
			exit(0);
		res = split_cmd(cmd);
		if (res < 0) {
			printf("Parse error\n");
			continue;
		}
		if (cmdc == 0)
			continue;
		for (i = 0; cmds[i].cmd; ++i) {
			if (strcmp(cmdv[0], cmds[i].cmd))
				continue;
			reply = cmds[i].handler(cmdc, cmdv);
			if (!reply)
				exit(0);
			printf("%s", reply);
			break;
		}
		if (!cmds[i].cmd)
			printf("Unknown command\n");
	}

	cfg_free(cfg);
	return 0;
}
コード例 #16
0
ファイル: section_remove.c プロジェクト: Gikoskos/libconfuse
int main(void)
{
	static cfg_opt_t section_opts[] = {
		CFG_STR("prop", 0, CFGF_NONE),
		CFG_END()
	};

	cfg_opt_t opts[] = {
		CFG_SEC("section", section_opts, CFGF_TITLE | CFGF_MULTI),
		CFG_END()
	};

	const char *config_data =
		"section title_one { prop = 'value_one' }\n"
		"section title_two { prop = 'value_two' }\n"
		"section title_one { prop = 'value_one' }\n";

	int rc;
	cfg_t *cfg = cfg_init(opts, CFGF_NONE);

	fail_unless(cfg);

	rc = cfg_parse_buf(cfg, config_data);
	fail_unless(rc == CFG_SUCCESS);

	cfg_rmtsec(cfg, "section", "title_two");
	fail_unless(cfg_size(cfg, "section") == 1);
	fail_unless(strcmp(cfg_title(cfg_getnsec(cfg, "section", 0)), "title_one") == 0);

	cfg_free(cfg);

	cfg = cfg_init(opts, CFGF_NONE);
	fail_unless(cfg);

	rc = cfg_parse_buf(cfg, config_data);
	fail_unless(rc == CFG_SUCCESS);

	cfg_rmsec(cfg, "section");
	fail_unless(cfg_size(cfg, "section") == 1);
	fail_unless(strcmp(cfg_title(cfg_getnsec(cfg, "section", 0)), "title_two") == 0);

	cfg_free(cfg);

	return 0;
}
コード例 #17
0
Test(wildcard_source, test_base_dir_required_options)
{
  start_grabbing_messages();
  cr_assert(_parse_config("filename-pattern(/tmp)"));
  cr_assert(!cfg_init(configuration), "Config initialization should be failed");
  stop_grabbing_messages();
  cr_assert(assert_grabbed_messages_contain_non_fatal("base-dir option is required", NULL));
  reset_grabbed_messages();
}
コード例 #18
0
ファイル: test_logqueue.c プロジェクト: balabit/syslog-ng
void
setup(void)
{
  app_startup();
  setenv("TZ", "MET-1METDST", TRUE);
  tzset();
  configuration = cfg_new_snippet();
  configuration->stats_options.level = 1;
  cr_assert(cfg_init(configuration), "cfg_init failed!");
}
コード例 #19
0
ファイル: main.c プロジェクト: Rapthera/warcog
static void loadconfig(config_t *cfg)
{
    char *cfg_str;
    bool res;

    cfg_str = file_text("config.txt");
    if (!cfg_str)
        printf("failed to load config file, using defaults\n");

    res = cfg_init(cfg, cfg_str);
    free(cfg_str);
    if (!res) {
        printf("invalid config file, using defaults\n");
        cfg_init(cfg, NULL);
    }

    printf("cfg.name %s\n", cfg->name);
    printf("cfg.dlrate %u\n", cfg->dlrate);
}
コード例 #20
0
ファイル: suite_validate.c プロジェクト: troglobit/libconfuse
void validate_setup(void)
{
	cfg_opt_t *opt = 0;

	static cfg_opt_t action_opts[] = {
		CFG_INT("speed", 0, CFGF_NONE),
		CFG_STR("name", 0, CFGF_NONE),
		CFG_INT("xspeed", 0, CFGF_NONE),
		CFG_END()
	};

	static cfg_opt_t multi_opts[] = {
		CFG_INT_LIST("speeds", 0, CFGF_NONE),
		CFG_SEC("options", action_opts, CFGF_NONE),
		CFG_END()
	};

	cfg_opt_t opts[] = {
		CFG_STR_LIST("ip-address", 0, CFGF_NONE),
		CFG_INT_CB("action", ACTION_NONE, CFGF_NONE, parse_action),
		CFG_SEC("options", action_opts, CFGF_NONE),
		CFG_SEC("multi_options", multi_opts, CFGF_MULTI),
		CFG_END()
	};

	cfg = cfg_init(opts, 0);

	cfg_set_validate_func(cfg, "ip-address", validate_ip);
	fail_unless(cfg_set_validate_func(cfg, "ip-address", validate_ip) == validate_ip);
	opt = cfg_getopt(cfg, "ip-address");
	fail_unless(opt != 0);
	fail_unless(opt->validcb == validate_ip);

	cfg_set_validate_func(cfg, "options", validate_action);
	fail_unless(cfg_set_validate_func(cfg, "options", validate_action) == validate_action);
	opt = cfg_getopt(cfg, "options");
	fail_unless(opt != 0);
	fail_unless(opt->validcb == validate_action);

	cfg_set_validate_func(cfg, "options|speed", validate_speed);
	fail_unless(cfg_set_validate_func(cfg, "options|speed", validate_speed) == validate_speed);
	opt = cfg_getopt(cfg, "options|speed");
	fail_unless(opt != 0);
	fail_unless(opt->validcb == validate_speed);

	cfg_set_validate_func(cfg, "multi_options|speeds", validate_speed);
	fail_unless(cfg_set_validate_func(cfg, "multi_options|speeds", validate_speed) == validate_speed);

	cfg_set_validate_func(cfg, "multi_options|options|xspeed", validate_speed);
	fail_unless(cfg_set_validate_func(cfg, "multi_options|options|xspeed", validate_speed) == validate_speed);

	/* Validate callbacks for *set*() functions, i.e. not when parsing file content */
	cfg_set_validate_func2(cfg, "multi_options|speed", validate_speed2);
	cfg_set_validate_func2(cfg, "multi_options|options|name", validate_name2);
}
コード例 #21
0
ファイル: practica4.c プロジェクト: Mithrandir0x/so2
RBTree *import_database()
{
  ProgressPtr process_file;
  FilePathList *list;
  char path[80];
  RBTree *tree;
  
  tree = malloc(sizeof(RBTree));
  list = malloc(sizeof(FilePathList));
  
  // For each file indicated by the file specified by argument, it will parse
  // its content, searching for words, and it will store them in the global
  // structure.
  process_file = ^(FilePathItem *item, int total_files){
      HashList hl;
      int result;

      printf("Reading file [%s] with id [%d/%d]\n", item->path, item->id + 1, total_files);
      
      hl_initialize(&hl, HASH_LIST_SIZE);
      
      result = create_local_structure(&hl, item->path);
      if ( result == 0 )
      {
          update_global_structure(tree, &hl, item->id);
          hl_free(&hl);
      }
  };
  
  cfg_init(list);

  printf("Mode multifil\n");

  printf("Nom del fitxer de configuració: ");
  scanf("%s", path);
  flush();
  
  cfg_import_config(path, list);
  //cfg_print(list);

  if ( list->size == 0 )
  {
    cfg_free(list);
    free(tree);
    return NULL;
  }

  initTree(tree, list->size);
  cfg_mt_iterate(list, process_file, 32);
  
  cfg_free(list);

  return tree;
}
コード例 #22
0
static WildcardSourceDriver *
_create_wildcard_filesource(const gchar *wildcard_config)
{
  cr_assert(_parse_config(wildcard_config), "Parsing the given configuration failed");
  cr_assert(cfg_init(configuration), "Config initialization failed");
  LogExprNode *expr_node = cfg_tree_get_object(&configuration->tree, ENC_SOURCE, "s_test");
  cr_assert(expr_node != NULL);
  WildcardSourceDriver *driver = (WildcardSourceDriver *)expr_node->children->children->object;
  cr_assert(driver != NULL);
  return driver;
}
コード例 #23
0
ファイル: configsys.c プロジェクト: RotStrom/tilda
/**
 * Start up the configuration system, using the configuration file given
 * to get the current values. If the configuration file given does not exist,
 * go ahead and write out the default config to the file.
 */
gint config_init (const gchar *config_file)
{
	gint ret = 0;

    // Can we use a more descriptive name than tc?
	tc = cfg_init (config_opts, 0);

	if (g_file_test (config_file,
        G_FILE_TEST_IS_REGULAR))
    {
		/* Read in the existing configuration options */
		ret = cfg_parse (tc, config_file);

		if (ret == CFG_PARSE_ERROR) {
			DEBUG_ERROR ("Problem parsing config");
            return ret;
		} else if (ret != CFG_SUCCESS) {
            DEBUG_ERROR ("Problem parsing config.");
            return ret;
        }
	}

    /* Deprecate old config settings
     * This is a lame work around until we get a permenant solution to
     * libconfuse lacking for this functionality
     */
    const gchar *deprecated_tilda_config_options[] = {"show_on_monitor_number"};
    remove_deprecated_config_options(deprecated_tilda_config_options, G_N_ELEMENTS(deprecated_tilda_config_options));

#if VTE_MINOR_VERSION >= 40
    /* Deprecate old config settings
     * This is a lame work around until we get a permenant solution to
     * libconfuse lacking for this functionality
     */
    const gchar *deprecated_vte_config_options[] = {"word_chars", "image", "scroll_background", "use_image"};
    remove_deprecated_config_options (deprecated_vte_config_options, G_N_ELEMENTS(deprecated_vte_config_options));
#else
    if (cfg_getopt(tc, "use_image")->nvalues < 1) {
        cfg_setbool(tc, "use_image", FALSE);
    }
    if (cfg_getopt(tc, "word_chars")->nvalues < 1) {
        cfg_setstr(tc, "word_chars", DEFAULT_WORD_CHARS);
    }
    if (cfg_getopt(tc, "scroll_background")->nvalues < 1) {
        cfg_setbool(tc, "scroll_background", TRUE);
    }
#endif
    #ifndef NO_THREADSAFE
        g_mutex_init(&mutex);
    #endif

	return ret;
}
コード例 #24
0
ファイル: main.c プロジェクト: Tayyib/uludag
int
main(int argc, char *argv[])
{
    // l10n
    setlocale(LC_MESSAGES, "");
    bindtextdomain("comar", "/usr/share/locale");
    bind_textdomain_codeset("comar", "UTF-8");
    bind_textdomain_codeset("libc", "UTF-8");
    textdomain("comar");

    // Parse commandline options
    cfg_init(argc, argv);

    // Only root can register bus
    if (getuid() != 0) {
        puts(_("System service should be started as root."));
        exit(1);
    }

    // Initialize main process
    if (proc_init(argc, argv, "Comar") != 0) {
        exit(1);
    }

    // Start logging
    if (log_start() != 0) {
        exit(1);
    }

    // Load models
    if (model_init() != 0) {
        exit(1);
    }

    // Initialize DB
    if (db_init() != 0) {
        exit(1);
    }

    while (!shutdown_activated) {
        // Listen for DBus calls
        dbus_listen();
        if (!shutdown_activated) {
            log_info("DBus connection is lost. Waiting 5 seconds and trying again...\n");
            sleep(5);
        }
    }

    model_free();
    proc_finish();

    return 0;
}
コード例 #25
0
ファイル: e_edf.cpp プロジェクト: fragglet/autodoom
//
// E_CreateCfg
//
// haleyjd 03/21/10: Separated from E_ParseEDF[File|Lump]. Creates and 
// initializes a libConfuse cfg_t object for use by EDF. All definitions
// are now accumulated into this singular cfg_t, as opposed to being
// merged from separately allocated ones for secondary EDF sources such
// as wad lumps.
//
static cfg_t *E_CreateCfg(cfg_opt_t *opts)
{
   cfg_t *cfg;

   E_EDFLogPuts("Creating global cfg_t object\n");

   cfg = cfg_init(opts, CFGF_NOCASE);
   cfg_set_error_function(cfg, edf_error);
   cfg_set_lexer_callback(cfg, E_CheckRoot);

   return cfg;
}
コード例 #26
0
ファイル: config.c プロジェクト: CristopherLeal/SVMClassifier
void get_db_query(const char * filename, char * query){

  cfg_opt_t * opts = get_opt();
  cfg_t *cfg;

  cfg = cfg_init(opts, CFGF_NONE);
  cfg_parse(cfg, filename);

  strcpy(query,cfg_getstr(cfg, "db_query"));

  free(cfg); 
}
コード例 #27
0
ファイル: config.c プロジェクト: CristopherLeal/SVMClassifier
void get_model_filename(const char * filename, char * model_filename){

  cfg_opt_t * opts = get_opt();
  cfg_t *cfg;

  cfg = cfg_init(opts, CFGF_NONE);
  cfg_parse(cfg, filename);

  strcpy(model_filename ,cfg_getstr(cfg, "model_filename"));

  free(cfg);
}
コード例 #28
0
ファイル: 2p.c プロジェクト: rsampaio/locker
int main(int argc, char **argv) 
{
  int i, c;
  char *optvalue = NULL;
  char *p, *line, *cfg_file;
  db_list_t *list;  
  struct passwd *pwdent;
  
  pwdent = getpwuid(getuid());

  cfg_file = (char *) malloc(strlen(pwdent->pw_dir) + 5);
  snprintf(cfg_file, strlen(pwdent->pw_dir) + 9, "%s/.locker", pwdent->pw_dir);
  
  if (cfg_init(cfg_file, &cfg) < 0) {
    fprintf(stderr, "could not open config file\n");
    return EXIT_FAILURE;
  }

  if (!db_init(cfg.db_file)) {
    fprintf(stderr, "cound not init db\n");
    return EXIT_FAILURE;
  }

  while ((c = getopt(argc, argv, "a:s:p:c:")) != -1) {
    switch (c) {
    case 'a':
      optvalue = optarg;
      db_list(optvalue, db_list_callback);
      break;

    case 's':
      optvalue = optarg;
      printf("password:"******"");
      
      db_set(optvalue, encrypt_text(line, cfg.gpg_key));
      break;

    case 'p':
      optvalue = optarg;
      db_get(optvalue, db_get_callback);
      break;
    
    default:
      fprintf(stderr, "Usage:\n\t-s <name>\tSet password\n\t-p <name>\tPrint decrypted password\n\t-a <prefix>\tList all names\n");
    }
  }
  
  db_close();
  return EXIT_SUCCESS;
}
コード例 #29
0
ファイル: ignore_parm.c プロジェクト: Gikoskos/libconfuse
static int testconfig(const char *buf)
{
	cfg_t *cfg = cfg_init(opts, CFGF_IGNORE_UNKNOWN);

	if (!cfg)
		return 0;

	if (cfg_parse_buf(cfg, buf) != CFG_SUCCESS)
		return 0;

	cfg_free(cfg);
	return 1;
}
コード例 #30
0
ファイル: test_rewrite.c プロジェクト: jbfuzier/syslog-ng
LogRewrite *
create_rewrite_rule(const char *raw_rewrite_rule)
{
  char raw_config[1024];

  configuration = cfg_new(VERSION_VALUE);
  snprintf(raw_config, sizeof(raw_config), "rewrite s_test{ %s }; log{ rewrite(s_test); };", raw_rewrite_rule);
  assert_true(parse_config(raw_config, LL_CONTEXT_ROOT, NULL, NULL), ASSERTION_ERROR("Parsing the given configuration failed"));
  assert_true(cfg_init(configuration), ASSERTION_ERROR("Config initialization failed"));

  LogExprNode *expr_node = cfg_tree_get_object(&configuration->tree, ENC_REWRITE, "s_test");
  return (LogRewrite *)expr_node->children->object;
}