• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ cfg_parse函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中cfg_parse函数的典型用法代码示例。如果您正苦于以下问题:C++ cfg_parse函数的具体用法?C++ cfg_parse怎么用?C++ cfg_parse使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了cfg_parse函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: main

int main(void)
{
	cfg_t *acfg, *bcfg;
	cfg_t *sec;

	acfg = create_config();
	fail_unless(cfg_parse(acfg, SRC_DIR "/a.conf") == 0);

	bcfg = create_config();
	fail_unless(cfg_parse(bcfg, SRC_DIR "/b.conf") == 0);

	sec = cfg_getnsec(acfg, "sec", 0);
	fail_unless(sec != 0);
	fail_unless(cfg_size(acfg, "sec") == 1);
	fail_unless(strcmp(cfg_title(sec), "acfg") == 0);
	fail_unless(cfg_getint(sec, "a") == 5);
	fail_unless(cfg_getint(sec, "b") == 2);

	sec = cfg_getnsec(bcfg, "sec", 0);
	fail_unless(sec != 0);
	fail_unless(cfg_size(bcfg, "sec") == 1);
	fail_unless(strcmp(cfg_title(sec), "bcfg") == 0);
	fail_unless(cfg_getint(sec, "a") == 1);
	fail_unless(cfg_getint(sec, "b") == 9);

	cfg_free(acfg);
	cfg_free(bcfg);

	return 0;
}
开发者ID:Gikoskos,项目名称:libconfuse,代码行数:30,代码来源:suite_dup.c


示例2: CFG_STR

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;
}
开发者ID:se-bi,项目名称:offlinefs,代码行数:33,代码来源:synclogger.cpp


示例3: read_config

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;
}
开发者ID:oioi,项目名称:zbx_tools,代码行数:35,代码来源:config.cpp


示例4: CFG_STR_LIST

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;
}
开发者ID:troglobit,项目名称:toolbox,代码行数:33,代码来源:confuse.c


示例5: CFG_STR

cfg_t *parse_conf(const char *filename)
{
    cfg_opt_t process_opts[] = {
        CFG_STR("comm", 0, CFGF_NODEFAULT),
        CFG_STR("args", 0, CFGF_NODEFAULT),
        CFG_STR("pre", 0, CFGF_NONE),
        CFG_END()
    };

    cfg_opt_t opts[] = {
        CFG_SEC("process", process_opts, CFGF_MULTI | CFGF_TITLE),
        CFG_INT("frequency", 10, CFGF_NONE),
        CFG_END()
    };

    cfg_t *cfg = cfg_init(opts, CFGF_NONE);
    //cfg_set_validate_func(cfg, "bookmark|port", conf_validate_port);
    //cfg_set_validate_func(cfg, "bookmark", conf_validate_bookmark);

    switch(cfg_parse(cfg, filename))
    {
        case CFG_FILE_ERROR:
            printf("warning: configuration file '%s' could not be read: %s\n",
                    filename, strerror(errno));
            printf("continuing with default values...\n\n");
        case CFG_SUCCESS:
            break;
        case CFG_PARSE_ERROR:
            return 0;
    }

    return cfg;
}
开发者ID:submorino,项目名称:daemon,代码行数:33,代码来源:daemond.c


示例6: parse_config

/*
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;
}
开发者ID:darakian,项目名称:cmtp,代码行数:39,代码来源:server_functions.c


示例7: read_config

void read_config(void)
{
    static cfg_opt_t arg_opts[] = {
        CFG_STR("value", "default", CFGF_NONE),
        CFG_END()
    };
    cfg_opt_t opts[] = {
        CFG_INT("delay", 3, CFGF_NONE),
        CFG_STR("message", "This is a message", CFGF_NONE),
        CFG_SEC("argument", arg_opts, CFGF_MULTI | CFGF_TITLE),
        CFG_END()
    };

    char *buf = "" \
        " delay = 3\n" \
        "# message = \"asdfasfasfd tersf\"\n" \
        " argument one { value = 1 }\n" \
        " argument two { value=foo}\n";

    cfg_free(cfg);

    cfg = cfg_init(opts, 0);
    cfg_parse_buf(cfg, buf);
    cfg_parse(cfg, config_filename);
}
开发者ID:DSMan195276,项目名称:libconfuse,代码行数:25,代码来源:reread.c


示例8: parse_script

int parse_script(char *filename, script_ent_t * script) {
    cfg_t *pcfg;
    int i;

    memset(script, 0, sizeof(script_ent_t));

    printf("eins\n");
    pcfg = cfg_init(script_opts, CFGF_NONE);
    printf("zwei\n");
    if (cfg_parse(pcfg, filename) == CFG_PARSE_ERROR)
	return -1;

    strcpy(script->name, cfg_getstr(pcfg, "name"));	/* max 28 chars !!! */
    strcpy(script->org_name, cfg_getstr(pcfg, "org_name"));	/* max 64 chars !!! */
    strcpy(script->comment, cfg_getstr(pcfg, "comment"));	/* max 128 chars !!! */

    script->script_num = cfg_getint(pcfg, "id");
    script->version = cfg_getint(pcfg, "version");
    script->unused1 = cfg_getint(pcfg, "unused1");

    script->script_length = cfg_size(pcfg, "script");
    if (script->script_length & 1) {
	printf("WARNING: odd number of bytes in script ... truncating\n");
    }
    script->script_length >>= 1;
    for (i = 0; i < (script->script_length << 1); i++)
	script->script[i] = (uint8_t) cfg_getnint(pcfg, "script", i);

    cfg_free(pcfg);
    return 0;
}
开发者ID:GBert,项目名称:misc,代码行数:31,代码来源:pk2dft.c


示例9: config_init

/**
 * 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;

	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");
			g_printerr (_("Problem when opening config file\n"));
			return 1;
		} else if (ret != CFG_SUCCESS) {
            DEBUG_ERROR ("Problem parsing config.");
			g_printerr (_("An unexpected error occured while "
                "parsing the config file\n"));
        }
	}

    #ifndef NO_THREADSAFE
        g_mutex_init(&mutex);
    #endif

	return 0;
}
开发者ID:kokakoda,项目名称:tilda-gtk2,代码行数:34,代码来源:configsys.c


示例10: config_init

/**
 * 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;

	tc = cfg_init (config_opts, 0);

	/* I know that this is racy, but I can't think of a good
	 * way to fix it ... */
	if (g_file_test (config_file, G_FILE_TEST_IS_REGULAR)) {
		/* Read the file, and try to upgrade it */
		ret = cfg_parse (tc, config_file);

		if (ret == CFG_SUCCESS)
			try_to_update_config_file (config_file);
		else {
			DEBUG_ERROR ("Problem parsing config");
			g_printerr (_("Problem parsing config file\n"));
			return 1;
		}
	}
	/* This is commented out because we don't want to do this. Basically, there
	 * is no need to write the config until we have shown the wizard, which is
	 * automatically shown on the first run. */
#if 0
	else {
		/* Write out the defaults */
		config_write (config_file);
	}
#endif

	return 0;
}
开发者ID:Sitwon,项目名称:tilda,代码行数:37,代码来源:configsys.c


示例11: get_db_info

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;
}
开发者ID:CristopherLeal,项目名称:SVMClassifier,代码行数:32,代码来源:config.c


示例12: conf_read

static void conf_read(const char *path, int must)
{
	int err;

	DBG(1, "Reading configfile %s...\n", path);

	if (access(path, R_OK) != 0) {
		if (must)
			quit("Error: Unable to read configfile \"%s\": %s\n",
			     path, strerror(errno));
		else
			return;
	}

	err = cfg_parse(cfg, path);
	if (err == CFG_FILE_ERROR) {
		quit("Error while reading configfile \"%s\": %s\n",
		     path, strerror(errno));
	} else if (err == CFG_PARSE_ERROR) {
		quit("Error while reading configfile \"%s\": parse error\n",
		     path);
	}

	configfile_read_units();
	configfile_read_history();
	configfile_read_attrs();
	configfile_read_element_cfg();
}
开发者ID:noushi,项目名称:bmon,代码行数:28,代码来源:conf.c


示例13: cfg_load

int cfg_load(void)
{
	char *p = game_cfg_path();
	if (!p)
		return -1;
	if (access(p, R_OK))
		return 0;
	return cfg_parse(p);
}
开发者ID:Wuzzy2,项目名称:instead,代码行数:9,代码来源:config.c


示例14: E_ParseEDFFile

//
// E_ParseEDFFile
//
// Parses the specified file.
//
static void E_ParseEDFFile(cfg_t *cfg, const char *filename)
{
   int err;

   if((err = cfg_parse(cfg, filename)))
   {
      E_EDFLoggedErr(1, 
         "E_ParseEDFFile: failed to parse %s (code %d)\n",
         filename, err);
   }
}
开发者ID:fragglet,项目名称:autodoom,代码行数:16,代码来源:e_edf.cpp


示例15: get_db_query

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); 
}
开发者ID:CristopherLeal,项目名称:SVMClassifier,代码行数:12,代码来源:config.c


示例16: get_model_filename

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);
}
开发者ID:CristopherLeal,项目名称:SVMClassifier,代码行数:12,代码来源:config.c


示例17: config_init

/**
 * 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;
}
开发者ID:RotStrom,项目名称:tilda,代码行数:58,代码来源:configsys.c


示例18: transfer_params

static void transfer_params(char *config_file)
{
    int n;
    char *bitmap_file, *opt;
    char *cp;
    int cfd;

    cfg_bitmap_only();		/* disable everything but cf_bitmap */
    
    cfd = cfg_open(config_file);
    if (verbose >= 3) printf("cfg_open returns: %d\n", cfd);
    n = cfg_parse(cf_bitmap);
    if (verbose >= 3) printf("cfg_parse returns: %d\n", n);
    if (n != 0) {
	die("Illegal token in '%s'", config_file);
    }
    if ((bitmap_file = cfg_get_strg(cf_bitmap, "bitmap")) != NULL) {
	opt = "Using";
	cp = strrchr(config_file, '/');
	if (cp && bitmap_file[0] != '/') {
	    *++cp = 0;
	    bitmap_file = strcat(strcpy(alloc(strlen(config_file) + strlen(bitmap_file) + 1),
					config_file),
				 bitmap_file);
	    *cp = '/';
	}
    } else {
	opt = "Assuming";
	cp = strrchr(config_file, '.');
	if (cp) *cp = 0;
	bitmap_file = alloc(strlen(config_file) + strlen(BMP_BMP) + 1);
	strcpy(bitmap_file, config_file);
	strcat(bitmap_file, BMP_BMP);
	if (cp) *cp = '.';
    }

    printf("Transfer parameters from '%s' to '%s'", config_file, bitmap_file);
    if (yesno("?", 0)==0) exit(0);

    if (verbose > 0) printf("%s bitmap file:  %s\n", opt, bitmap_file);
    
    bmp_file_open(bitmap_file);
    
    bmp_do_table(cfg_get_strg(cf_bitmap, "bmp-table"), menu);
    bmp_do_colors(cfg_get_strg(cf_bitmap, "bmp-colors"), menu);
    bmp_do_timer(cfg_get_strg(cf_bitmap, "bmp-timer"), menu);
    
    bmp_file_close(1);  /* update */
    
    exit(0);
}
开发者ID:OPSF,项目名称:uClinux,代码行数:51,代码来源:edit.c


示例19: load_config

void load_config(god_t* god){
	check_dirs();

	char *home_dir = getenv("HOME");
	char *conf_file = "/.local/share/crunchball/crunchball.cfg";
	char tmp_path[500] = {0};
	
	cp_str(tmp_path, home_dir);	
	cat_to_str(tmp_path, conf_file);

	long int video_mode;
	long int audio_level;
	long int fullscreen;
	long int high_score;

	cfg_opt_t opts[] = {
		CFG_SIMPLE_INT("video_mode", &video_mode),
		CFG_SIMPLE_INT("audio_level", &audio_level),
		CFG_SIMPLE_INT("fullscreen", &fullscreen),
		CFG_SIMPLE_INT("high_score", &high_score),
		CFG_END()
	};
	cfg_t *cfg;

	cfg = cfg_init(opts, 0);
	int rc = cfg_parse(cfg, tmp_path);

	if ( rc != 0 ){
		video_mode = 2;
		audio_level = 5;
		fullscreen = 0;
		high_score = 0;
	}
	
	if (video_mode == 0)
		video_mode = 2;

	god->scalar.scale = video_mode;
	god->state.settings_volume = audio_level;
	god->state.high_score = high_score;
	god->scalar.fs = fullscreen;
	
	FILE *fp = fopen(tmp_path, "w");
	cfg_print(cfg, fp);

	fclose(fp);

	cfg_free(cfg);

}
开发者ID:computermouth,项目名称:shortstack,代码行数:50,代码来源:config.c


示例20: main

int main(void)
{
    /* ... setup options ... */

    cfg = cfg_init(opts, CFGF_NONE);
    cfg_parse(cfg, "hello.conf");

    if(cfg_size(cfg, "greeting") == 0)
    {
        cfg_parse_buf(cfg, "greeting Hello {}");
    }

    /* ... print the greetings ... */
}
开发者ID:5StringsOfDoom,项目名称:SNESDev-RPi,代码行数:14,代码来源:listing6.c



注:本文中的cfg_parse函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ cfg_size函数代码示例发布时间:2022-05-30
下一篇:
C++ cfg_obj_log函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap