void chomp(char *buf) { /* * Uses stripchar to remove any newlines from buf. */ stripchar(buf, '\n'); stripchar(buf, '\r'); return; }
void parse_config(char *valid_config_lines[], size_t valid_line_num, struct Calibration *calis[valid_line_num]) { int i; char **elements; size_t elements_num_per_line; if (valid_line_num == 0) { printf("No valid calibration line in config file!\n"); exit(EXIT_FAILURE); } for (i = 0; i < valid_line_num; i++) { // Remove trailing ';' if exists valid_config_lines[i] = stripchar(valid_config_lines[i], ';'); // elements: {"name_a", "name_b", "cali_info"} elements = split_by_delim(valid_config_lines[i], ",", &elements_num_per_line); if (elements_num_per_line != 3) { printf("Config file syntax error. Line: %d\n", i + 1); exit(1); } calis[i] = malloc(sizeof(struct Calibration)); calis[i]->name_a = elements[0]; calis[i]->name_b = elements[1]; calis[i]->cali_info = elements[2]; } }
AddNewGstr(gk_string *gstr) { char * news; Dialect d; news = gkstring_of(gstr); /* if( (d=AndDialect((Dialect)(ATTIC),dialect_of(gstr))) < 0) { return; } */ if( cur_endcnt >= MAXENDINGS ) { fprintf(stderr,"Hey! you only have space for %d endings!\n", MAXENDINGS ); fprintf(stderr,"Change to variable MAXENDINGS to reflect the actual number you want!\n"); return(-1); } if( strlen(news) + 1 >= maxstring ) maxstring = strlen(news) + 1; if( *news != '*' ) stripzeroend(news); hyphtodiaer(news); /* stripchar(news,'-'); */ stripchar(news,'!'); *(StoreGstr+cur_endcnt) = *gstr; cur_endcnt++; }
void timeMultv(const int num_trials /* = 1 */) { const std::string test_dir = "../test/test2/"; std::vector< std::string > text_filepaths; // text_filepaths.push_back("t1.fas"); // text_filepaths.push_back("t5.fas"); // text_filepaths.push_back("t10.fas"); // text_filepaths.push_back("t15.fas"); // text_filepaths.push_back("t20.fas"); // text_filepaths.push_back("t25.fas"); // text_filepaths.push_back("t30.fas"); std::vector< std::string > pattern_filepaths; // pattern_filepaths.push_back("p1.fas"); // pattern_filepaths.push_back("p5a.fas"); pattern_filepaths.push_back("p5b.fas"); pattern_filepaths.push_back("p5c.fas"); // pattern_filepaths.push_back("p10a.fas"); // pattern_filepaths.push_back("p10b.fas"); // pattern_filepaths.push_back("p10c.fas"); // pattern_filepaths.push_back("p15a.fas"); // pattern_filepaths.push_back("p15b.fas"); // pattern_filepaths.push_back("p15c.fas"); // pattern_filepaths.push_back("p20a.fas"); // pattern_filepaths.push_back("p20b.fas"); // pattern_filepaths.push_back("p20c.fas"); // pattern_filepaths.push_back("p25a.fas"); // pattern_filepaths.push_back("p25b.fas"); // pattern_filepaths.push_back("p25c.fas"); // pattern_filepaths.push_back("p30a.fas"); // pattern_filepaths.push_back("p30b.fas"); // pattern_filepaths.push_back("p30c.fas"); std::cout << "text, pattern, time, matches\n"; for (std::vector< std::string >::iterator iter_t = text_filepaths.begin(); iter_t != text_filepaths.end(); iter_t++) { std::string text = readFile(test_dir + *iter_t); stripchar(text, '\n'); for (std::vector< std::string >::iterator iter_p = pattern_filepaths.begin(); iter_p != pattern_filepaths.end(); iter_p++) { std::string pattern = readFile(test_dir + *iter_p); std::set<int> matches; clock_t t0 = 0, t1 = 0; t0 = clock(); for (int i = 0; i < num_trials; i++) { matches = cpm::multvMatch(text, pattern); } t1 = clock(); double avg_dt = ((double)(t1 - t0)) / CLOCKS_PER_SEC / num_trials; std::cout << *iter_t << ", " << *iter_p << ", " << avg_dt << ", " << setToStr(matches) << "\n"; } } }
ptr<const expr_t> regex_fn_t::v_eval_2 (eval_t *p, const vec<arg_t> &args) const { str target, opts, body; ptr<const expr_t> ret; bool tuple_out = false; body = args[0]._s; if (args.size () == 2) { target = args[1]._s; } else { target = args[2]._s; opts = args[1]._s; } if ((tuple_out = (opts && strchr (opts.cstr (), 'T')))) { opts = stripchar (opts, 'T'); } ptr<rxx> x = str2rxx (p, body, opts); if (!x) { report_error (p, "cannot parse regular expression"); } else { bool b = match() ? x->match (target) : x->search (target); // In the case of a 'T' argument, passed then we return as tuples // the match groups. if (tuple_out) { ptr<expr_list_t> l = expr_list_t::alloc (); if (b) { str s; size_t i (0); while ((s = x->at(i++))) { l->push_back (expr_str_t::alloc (s)); } } ret = l; } else { // Otherwise, let's return a bool, true for a match, and false // for a lack of match. ret = expr_bool_t::alloc (b); } } return ret; }