本文整理汇总了C++中cfg_parse函数的典型用法代码示例。如果您正苦于以下问题:C++ cfg_parse函数的具体用法?C++ cfg_parse怎么用?C++ cfg_parse使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了cfg_parse函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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);
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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();
}
示例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);
}
示例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);
}
}
示例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);
}