当前位置: 首页>>代码示例>>C++>>正文


C++ config_lookup_string函数代码示例

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


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

示例1: connect

void MysqlWriter::connect()
{
	const char *server;
	const char *user;
	const char *password;
	const char *database;
	
	if(!config_lookup_string(&this->cfg, "db.host", &server)) {
		throw "MySQL host is not defined";
	}
	if(!config_lookup_string(&this->cfg, "db.username", &user)) {
		throw "MySQL username is not defined";
	}
	if(!config_lookup_string(&this->cfg, "db.password", &password)) {
		throw "MySQL password is not defined";
	}
	if(!config_lookup_string(&this->cfg, "db.database", &database)) {
		throw "MySQL database is not defined";
	}

	this->conn = mysql_init(NULL);
	if (!mysql_real_connect(this->conn, server,
	                        user, password, database, 0, NULL, 0)) {
		throw mysql_error(this->conn);
	}
	
	time_t rawtime;
	struct tm *timeinfo;
	time (&rawtime);
	timeinfo = localtime(&rawtime);
	strftime(this->numeric_table_name, sizeof(this->numeric_table_name), "archive_numeric_%Y_%m", timeinfo);
}
开发者ID:aslubsky,项目名称:cpp-simple-scada,代码行数:32,代码来源:mysql_writer.cpp

示例2: sally_exit

/**
 * Exit Sally tool. Close open files and free memory.
 */
static void sally_exit()
{
    int ehash;
    const char *cfg_str, *hash_file;

    info_msg(1, "Flushing. Closing input and output.");
    input_close();
    output_close();

    config_lookup_string(&cfg, "features.vect_embed", &cfg_str);
    if (!strcasecmp(cfg_str, "tfidf"))
        idf_destroy(input);

    config_lookup_string(&cfg, "input.stopword_file", &cfg_str);
    if (strlen(cfg_str) > 0)
        stopwords_destroy();

    config_lookup_string(&cfg, "features.hash_file", &hash_file);
    if (strlen(hash_file) > 0) {
        info_msg(1, "Saving explicit hash table to '%s'.", hash_file);    
        gzFile z = gzopen(hash_file, "w9");
        if (!z)
            error("Could not open hash file '%s'", hash_file);
        fhash_write(z);
        gzclose(z);
    }
    
    config_lookup_int(&cfg, "features.explicit_hash", &ehash);
    if (ehash || strlen(hash_file) > 0)
        fhash_destroy();

    /* Destroy configuration */
    config_destroy(&cfg);

}
开发者ID:yangke,项目名称:sally,代码行数:38,代码来源:sally.c

示例3: kern_distance_config

/**
 * Initializes the similarity measure
 */
void kern_distance_config()
{
    const char *str;

    /* Distance measure */
    config_lookup_string(&cfg, "measures.kern_distance.dist", &str);
    dist = measure_match(str);
    func[dist].measure_config();

    /* Substitution type */
    config_lookup_string(&cfg, "measures.kern_distance.type", &str);
    if (!strcasecmp(str, "linear")) {
        subst = DS_LINEAR;
    } else if (!strcasecmp(str, "poly")) {
        subst = DS_POLY;
    } else if (!strcasecmp(str, "neg")) {
        subst = DS_NEG;
    } else if (!strcasecmp(str, "rbf")) {
        subst = DS_RBF;
    } else {
        warning("Unknown substitution type '%s'. Using 'linear'.", str);
        subst = DS_LINEAR;
    }

    /* Parameters */
    config_lookup_float(&cfg, "measures.kern_distance.fgamma", &fgamma);
    config_lookup_float(&cfg, "measures.kern_distance.degree", &degree);

    /* Normalization */
    config_lookup_string(&cfg, "measures.kern_distance.norm", &str);
    norm = knorm_get(str);

}
开发者ID:MLDroid,项目名称:harry,代码行数:36,代码来源:kern_distance.c

示例4: build_query_tree

/**
 * Parses the configuration file, specifically the 
 * ldap section. This function will produce a tree, 
 * or really a linked list, tree sounds cooler, of 
 * ldap_query_t structures. This will allow a series 
 * of events to happen sequentially just by adding a
 * few lines to the configuration file. The returned 
 * node is the head of the tree/list.
 */
slack_ldap_query_t
build_query_tree() { 
    syslog(LOG_INFO, "Building query event tree..."); 
    static slack_ldap_query_t head; 
    slack_ldap_query_t *tail = &head; 
    config_setting_t *setting = config_lookup(&config, "ldap.queries"); 
    int i = 0; 
    do { /* The caveat, and requirement, is that there be at least
            one ldap query parameter, otherwise you just shouldn't
            include the ldap module...*/
        const char *query = config_setting_get_string_elem(setting, i);
        if(query != NULL) { 
            char query_param[strlen("ldap.query") //GCC/clang will optimize
                + strlen(query)+1]; // +1 for dot op
            sprintf(query_param, "ldap.query.%s", query);
            syslog(LOG_INFO, "Parsed LDAP query %s", query_param); 
            syslog(LOG_INFO, "Building LDAP query node..."); 

            /* Each of the string must have a +1 for dot operator */
            char basednstr[strlen(query_param) + 8]; //length of 'basedn'
            sprintf(basednstr, "%s.%s", query_param, "basedn"); 
            syslog(LOG_INFO, "Parsing %s", basednstr); 
            char filterstr[strlen(query_param) + 6]; //length of 'filter'
            sprintf(filterstr, "%s.%s", query_param, "filter"); 
            syslog(LOG_INFO, "Parsing %s", filterstr); 
            char eventstr[strlen(query_param) + 5]; //length of 'event'
            sprintf(eventstr, "%s.%s", query_param, "event"); 
            syslog(LOG_INFO, "Parsing %s", eventstr); 

            syslog(LOG_INFO, "Building query node..."); 
            config_lookup_string(&config, basednstr, 
                    (const char **)&(tail->basednstr)); 
            config_lookup_string(&config, filterstr, 
                    (const char **)&(tail->filterstr)); 
            config_lookup_string(&config, eventstr, 
                    (const char **)&(tail->eventstr)); 
            tail->next = malloc(sizeof(slack_ldap_query_t));

            /* By this point the new node, TODO: write a failure method 
             * if we don't make it to this point. I beleive the only 
             * alternative to correct configuration is segfault :(
             */
            syslog(LOG_INFO, "Success, New Node:"); 
            syslog(LOG_INFO, "--->basedn = %s", tail->basednstr); 
            syslog(LOG_INFO, "--->filter = %s", tail->filterstr); 
            syslog(LOG_INFO, "--->event = %s", tail->eventstr); 
            /* Move onto the next node */ 
            tail = tail->next; 

            i++;
        } else { 
            syslog(LOG_INFO, "Parsed all ldap queries.");
            i = -1; 
            tail->next = NULL;
        } 
    } while(i != -1);

    return head;
}
开发者ID:KWMalik,项目名称:slackbot,代码行数:68,代码来源:modLdap.c

示例5: assert

/**
 * Internal: Allocates and extracts a feature vector from a string without
 * postprocessing and no blended n-grams.
 * @param x String of bytes (with space delimiters)
 * @param l Length of sequence
 * @param n N-gram length
 * @return feature vector
 */
fvec_t *fvec_extract_intern2(char *x, int l, int n)
{
    fvec_t *fv;
    int pos;
    cfg_int shift;
    const char *dlm_str;
    assert(x && l >= 0);

    /* Allocate feature vector */
    fv = calloc(1, sizeof(fvec_t));
    if (!fv) {
        error("Could not extract feature vector");
        return NULL;
    }

    /* Get configuration */
    config_lookup_string(&cfg, "features.ngram_delim", &dlm_str);
    config_lookup_bool(&cfg, "features.ngram_pos", &pos);
    config_lookup_int(&cfg, "features.pos_shift", &shift);

    /* Check for empty sequence */
    if (l == 0)
        return fv;

    /* Sanitize shift value */
    if (!pos)
        shift = 0;

    /* Allocate arrays */
    int space = 2 * shift + 1;
    fv->dim = (feat_t *) malloc(l * sizeof(feat_t) * space);
    fv->val = (float *) malloc(l * sizeof(float) * space);

    if (!fv->dim || !fv->val) {
        error("Could not allocate feature vector contents");
        fvec_destroy(fv);
        return NULL;
    }

    /* Get configuration */
    config_lookup_string(&cfg, "features.ngram_delim", &dlm_str);

    /* Loop over position shifts (0 if pos is disabled) */
    for (int s = -shift; s <= shift; s++) {
        if (!dlm_str || strlen(dlm_str) == 0) {
            extract_ngrams(fv, x, l, n, pos, s);
        } else {
            extract_wgrams(fv, x, l, n, pos, s);
        }
    }

    /* Sort extracted features */
    qsort(fv->dim, fv->len, sizeof(feat_t), cmp_feat);

    /* Count features  */
    count_feat(fv);

    return fv;
}
开发者ID:MLDroid,项目名称:sally,代码行数:67,代码来源:fvec.c

示例6: read_config

/**
 * 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;
}
开发者ID:spektom,项目名称:pingerd,代码行数:57,代码来源:pingerd_conf.c

示例7: load_ldap_module

/**
 * Load the ldap modules, passing in any arguments 
 * given initially, which are to be used in the 
 * ldap module. 
 */
int 
load_ldap_module( arguments *args ) { 

    syslog(LOG_INFO, "LDAP Module initalizing"); 
    
    /* Sets the protocol version based on ldap.version */
    config_lookup_int(&config, "ldap.version", &version); 
    switch(version) { 
        case 1: 
            ldap_set_option(ldap, LDAP_OPT_PROTOCOL_VERSION, &version);
            syslog(LOG_INFO, "LDAP Protocol Version: 1"); 
            break; 
        case 2: 
            ldap_set_option(ldap, LDAP_OPT_PROTOCOL_VERSION, &version);
            syslog(LOG_INFO, "LDAP Protocol Version: 2"); 
            break; 
        case 3: 
            ldap_set_option(ldap, LDAP_OPT_PROTOCOL_VERSION, &version);
            syslog(LOG_INFO, "LDAP Protocol Version: 3");
            break; 
        default: 
            version = 3;
            ldap_set_option(ldap, LDAP_OPT_PROTOCOL_VERSION, &version);
            syslog(LOG_INFO, "Invalid value, setting LDAP Protocol\
                Version to 3"); 
            break;
    }

    config_lookup_string(&config, "ldap.uri", &uri);
    syslog(LOG_INFO, "LDAP URI: %s\n", uri); 
    config_lookup_string(&config, "ldap.binddn", &binddn); 
    syslog(LOG_INFO, "LDAP BINDDN: %s\n", binddn); 
    config_lookup_string(&config, "ldap.password", &password);
    // Removed displaying password 
    
    syslog(LOG_INFO, "Initializing LDAP Connection...%s\n", 
        ldap_err2string(ldap_initialize(&ldap, uri)));
    
    syslog(LOG_INFO, "Binding to URI...%s\n", 
        ldap_err2string(ldap_simple_bind_s(ldap, binddn, password)));

    syslog(LOG_INFO, "Building LDAP query tree..."); 
    head = build_query_tree(); 
    log_query_tree(&head);  

    timeout.tv_sec = 10; 
    timeout.tv_usec = 0; 

    slack_ldap_search("slackwill"); 

    return 0;
}
开发者ID:KWMalik,项目名称:slackbot,代码行数:57,代码来源:modLdap.c

示例8: configfile_get_string

bool configfile_get_string( const char *path, const char **str ) {
	if( config_lookup_string(config, path, str) == CONFIG_FALSE ) {
		pline("Config setting %s not found or wrong type", path);
		return false;
	}
	return true;
}
开发者ID:ekosz,项目名称:bingehack,代码行数:7,代码来源:configfile.c

示例9: read_scenario_master_file

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()
开发者ID:maxhowald,项目名称:crts,代码行数:34,代码来源:read_configs.cpp

示例10: parse_config_val

void parse_config_val (config_t *conf, char **s, char *param_name, const char *default_name, const char *path) {
  static char buf[1000]; 
  int l = 0;
  if (prefix) {
    l = strlen (prefix);
    memcpy (buf, prefix, l);
    buf[l ++] = '.';
  }
  *s = 0;
  const char *r = 0;
  strcpy (buf + l, param_name);
  config_lookup_string (conf, buf, &r);
  if (r) {
    if (path && *r != '/') {
      tasprintf (s, "%s/%s", path, r);
    } else {
      *s = tstrdup (r);
    }
  } else {
    if (path && default_name) {
      tasprintf (s, "%s/%s", path, default_name);
    } else {
      *s  = default_name ? tstrdup (default_name) : 0;
    }
  }
}
开发者ID:analani,项目名称:tg,代码行数:26,代码来源:main.c

示例11: dist_kernel_config

/**
 * Initializes the similarity measure
 */
void dist_kernel_config()
{
    const char *str;

    /* Kernel measure */
    config_lookup_string(&cfg, "measures.dist_kernel.kern", &str);
    kern = measure_match(str);
    func[kern].measure_config();

    /* Parameters */
    config_lookup_bool(&cfg, "measures.dist_kernel.squared", &squared);

    /* Normalization */
    config_lookup_string(&cfg, "measures.dist_kernel.norm", &str);
    norm = knorm_get(str);
}
开发者ID:MLDroid,项目名称:harry,代码行数:19,代码来源:dist_kernel.c

示例12: parse_rarity

short parse_rarity(obj_t *o, char *name)
{
        const char *value;
        short rarity;

        config_lookup_string(cf, name, &value);
        if(!strcmp(value, "very common"))
                rarity = VERYCOMMON;
        else if(!strcmp(value, "common"))
                rarity = COMMON;
        else if(!strcmp(value, "uncommon"))
                rarity = UNCOMMON;
        else if(!strcmp(value, "rare"))
                rarity = RARE;
        else if(!strcmp(value, "very rare"))
                rarity = VERYRARE;
        else {                                          // assume it's common if nothing else is specified
                if(!hasbit(o->flags, OF_UNIQUE))
                        rarity = COMMON;
                else
                        rarity = UNIQUE;
        }

        return rarity;
}
开发者ID:abstrakct,项目名称:gt2,代码行数:25,代码来源:datafiles.c

示例13: assert

/**
 * Cluster feature vectors using linkage clustering. The function uses
 * the feature vectors for computing a linkage clustering
 * @param fa Array of prototypes
 * @param r Run of clustering
 * @return clustering structure
 */
cluster_t *cluster_linkage(farray_t *fa, int r)
{
    assert(fa);
    double dmin;
    const char *mode;

    /* Get cluster configuration */
    config_lookup_float(&cfg, "cluster.min_dist", (double *) &dmin);
    config_lookup_string(&cfg, "cluster.link_mode", &mode);

    /* Allocate cluster structure */
    cluster_t *c = cluster_create(fa->len, r);

    /* Allocate distances */
    double *dist = malloc(sizeof(double) * tria_size(fa->len));
    if (!dist) {
        error("Could not allocate distance matrix.");
        return NULL;
    }

    /* Compute distances */
    farray_dist_tria(fa, dist);

    if (verbose > 0)
        printf("Clustering (%s linkage) with minimum distance %4.2f.\n",
               mode, dmin);

    /* Run clustering */
    cluster_murtagh(c, dist, dmin, mode[0]);

    free(dist);
    return c;
}
开发者ID:JaonLin,项目名称:malheur,代码行数:40,代码来源:cluster.c

示例14: input_lines_open

/**
 * Opens a file for reading text lines. 
 * @param name File name
 * @return number of lines or -1 on error
 */
int input_lines_open(char *name)
{
    assert(name);
    const char *pattern;

    in = gzopen(name, "r");
    if (!in) {
        error("Could not open '%s' for reading", name);
        return -1;
    }

    /* Compile regular expression for label */
    config_lookup_string(&cfg, "input.lines_regex", &pattern);
    if (regcomp(&re, pattern, REG_EXTENDED) != 0) {
        error("Could not compile regex for label");
        return -1;
    }

    /* Count lines in file (I hope this is buffered)*/
    int c = -1, prev, num_lines = 0;
    do {
        prev = c;
        c = gzgetc(in);
        if (c == '\n')
            num_lines++;
    } while(c != -1);

    if (prev >= 0 && prev != '\n') num_lines++;

    /* Prepare reading */
    gzrewind(in);
    line_num = 0;

    return num_lines;
}
开发者ID:yangke,项目名称:sally,代码行数:40,代码来源:input_lines.c

示例15: read_call_config

/**
 * @brief Read module configure options
 *
 * This function will read CALLCONF file and fill app_call_conf
 * structure. Most of these values are using during call action process
 * @see call_exec
 *
 * @param cfile Full path to configuration file
 * @return 0 in case of read success, -1 otherwise
 */
int
read_call_config(const char *cfile)
{
    config_t cfg;
    const char *value;
    long int intvalue;

    // Initialize configuration
    config_init(&cfg);

    // Read configuraiton file
    if (config_read_file(&cfg, cfile) == CONFIG_FALSE) {
        isaac_log(LOG_ERROR, "Error parsing configuration file %s on line %d: %s\n", cfile,
                config_error_line(&cfg), config_error_text(&cfg));
        config_destroy(&cfg);
        return -1;
    }

    // Incoming context for first call leg in Originate @see call_exec
    if (config_lookup_string(&cfg, "originate.incontext", &value) == CONFIG_TRUE) {
        strcpy(call_config.incontext, value);
    }
    // Outgoing context for second call leg in Originate @see call_exec
    if (config_lookup_string(&cfg, "originate.outcontext", &value) == CONFIG_TRUE) {
        strcpy(call_config.outcontext, value);
    }
    // Rol variable (AGENTE, USUARIO) for incontext dialplan process
    //if (config_lookup_string(&cfg, "originate.rol", &value) == CONFIG_TRUE) {
    //    strcpy(call_config.rol, value);
    //}

    // Autoanwer variable (0,1) for incontext dialplan process
    if (config_lookup_int(&cfg, "originate.autoanswer", &intvalue) == CONFIG_TRUE) {
        call_config.autoanswer = intvalue;
    }

    // Filepat to store the recordings
    if (config_lookup_string(&cfg, "record.filepath", &value) == CONFIG_TRUE) {
        strcpy(call_config.record_path, value);
    }

    // Dealloc libconfig structure
    config_destroy(&cfg);

    isaac_log(LOG_VERBOSE_3, "Readed configuration from %s\n", cfile);
    return 0;
}
开发者ID:irontec,项目名称:isaac,代码行数:57,代码来源:app_call.c


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