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


C++ regcomp函数代码示例

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


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

示例1: binaryExpr

/* binary operator expression */
Expr *
binaryExpr(int op, Expr *arg1, Expr *arg2)
{
    Expr	*x;
    Expr	*arg = arg1;
    int		sts = 0;

    /* error guard */
    if (arg1 == NULL) return NULL;

    if (arg1 != NULL && arg2 != NULL) {
	if (op != CND_MATCH && op != CND_NOMATCH) {
	    /* check domains */
	    sts = checkDoms(arg1, arg2);

	    /* decide primary argument for inheritance of Expr attributes */
	    arg = primary(arg1, arg2);
	}
	else {
	    regex_t	*pat;

	    pat = alloc(sizeof(*pat));
	    if (regcomp(pat, (char *)arg2->ring, REG_EXTENDED|REG_NOSUB) != 0) {
		/* bad pattern */
		fprintf(stderr, "illegal regular expression \"%s\"\n", (char *)arg2->ring);
		free(pat);
		return NULL;
	    }
#if PCP_DEBUG
	    if (pmDebug & DBG_TRACE_APPL1) {
		fprintf(stderr, "binaryExpr: regex=\"%s\" handle=" PRINTF_P_PFX "%p\n", (char *)arg2->ring, pat);
	    }
#endif
	    /*
	     * change operand from the string form of the pattern to the
	     * compiled regex
	     */
	    free(arg2->ring);
	    arg2->tspan = 1;
	    arg2->ring = pat;
	    arg2->sem = SEM_REGEX;
	    sts = 1;
	}
    }

    /* construct expression node */
    x = newExpr(op, arg1, arg2, arg->hdom, arg->e_idom, arg->tdom, abs(arg->tdom), arg->sem);
#if PCP_DEBUG
    if (sts == 0 && (pmDebug & DBG_TRACE_APPL1)) {
	fprintf(stderr, "binaryExpr: checkDoms(" PRINTF_P_PFX "%p, " PRINTF_P_PFX "%p) failed ...\n", arg1, arg2);
	__dumpTree(1, x);
    }
#endif
    newRingBfr(x);
    findEval(x);

    /* evaluate constant expression now */
    evalConst(x);

    return x;
}
开发者ID:ColeJackes,项目名称:pcp,代码行数:62,代码来源:syntax.c

示例2: debug_monitor

/* event parsing loop freely stolen from Zarf's glk example code */
void debug_monitor() {
    char commandbuf[256], lastcommand[256];
    char *cx, *cmd;
    int gotline, len, monitor, match;
    event_t ev;
    char *parser = "^([cfghlnoqsx])( +([0-9a-f]+))?";
    // char *parser = "\\([cghlnqsx]\\)\\( 0\\)?";
    char *matched;
    regex_t preg;
    size_t nmatch = 4;
    regmatch_t pmatch[4];
    
    monitor = TRUE;
    while(monitor) {
        glk_put_string("\nmonitor>");
        // if (cmd)
        //     strncpy(lastcommand, cmd, 256);
        glk_request_line_event(mainwin, commandbuf, 255, 0);
        gotline = FALSE;
        while (!gotline) {
            glk_select(&ev);
            if (ev.type == evtype_LineInput)
                gotline = TRUE;
        }

        len = ev.val1;
        commandbuf[len] = '\0';

        for (cx = commandbuf; *cx; cx++) { 
            *cx = glk_char_to_lower(*cx);
        }
        
        /* strip whitespace */
        for (cx = commandbuf; *cx == ' '; cx++) { };
        cmd = cx;
        for (cx = commandbuf+len-1; cx >= cmd && *cx == ' '; cx--) { };
        *(cx+1) = '\0';
        
        if (*cmd == '\0') {
            monitor = FALSE;
            continue;
        }
        
        if ((match = regcomp(&preg, parser, REG_EXTENDED | REG_ICASE)) != 0) {
            fatal_error("Bad regex\n");
        }

        if ((match = regexec(&preg, cmd, nmatch, pmatch, 0)) != 0) {
            glk_put_string("pardon? - try 'h' for help\n");
        } else {
            if(match_command("c")) {
                monitor = FALSE;
            } else if (match_command("f")) {
                match_args_and_call(debug_print_callstack, 0xffff)
            } else if (match_command("g")) {
                match_args_and_call(debug_print_global, 0xff)
            } else if (match_command("h")) {
                debug_print_help();
            } else if (match_command("l")) {
                match_args_and_call(debug_print_local, 0xff)
            } else if (match_command("n")) {
                monitor = FALSE;                
            } else if (match_command("o")) {
                match_args_and_call(debug_print_object, 1);         
            } else if (match_command("x")) {
                match_args_and_call(debug_print_memory, 0xdeadbeef)
            } else if (match_command("")) {
                match_args_and_call(debug_print_zstring, 0)
            } else if (match_command("q")) {
                fatal_error("Debugger terminated game.");
            } else if (match_command("s")) {
                debug_print_stack();
            } else if (match_command("x")) {
                match_args_and_call(debug_print_memory, 0xdeadbeef)
            }
        }
        regfree(&preg);
    }
}
开发者ID:purplefoot,项目名称:zerp,代码行数:80,代码来源:debug.c

示例3: cfg_load


//.........这里部分代码省略.........
        } else if (bool_val != 0) switch (hypercube_config_tokens[i].type)
            {
            case CFG_NONE:
                break;
            case CFG_INT:
            {
                if (tokenc != 2) {
                    CFG_ERR_HDR();
                    fprintf(stderr, "Invalid number of arguments (expected %s <number>)\n", tokenv[0]);
                    return -1;
                }
                *(int *)hypercube_config_tokens[i].val = atoi(tokenv[1]);
                break;
            }
            case CFG_STR:
            {
                unsigned char **dest;

                if (tokenc != 2) {
                    CFG_ERR_HDR();
                    fprintf(stderr, "Invalid number of arguments (expected %s <string>)\n", tokenv[0]);
                    return -1;
                }
                dest = hypercube_config_tokens[i].val;
                *dest = strdup(tokenv[1]);
                break;
            }
            case CFG_TABLE:
            {
                akbuf_table *tbl;
                unsigned char **dest;

                if (tokenc != 3) {
                    CFG_ERR_HDR();
                    fprintf(stderr, "Invalid number of arguments (expected %s <key> <value>)\n", tokenv[0]);
                    return -1;
                }
                dest = hypercube_config_tokens[i].val;
                tbl = (akbuf_table *)*dest;
                akbuf_table_entry_add_str(cfg_ctx, tbl, tokenv[1], tokenv[2]);
                break;
            }
            case CFG_REGEX_TABLE:
            {
                akbuf_table *tbl;
                unsigned char **dest;
                akbuf *compbuf, *valbuf;
                int ret;

                if (tokenc != 2 && tokenc != 3) {
                    CFG_ERR_HDR();
                    fprintf(stderr, "Invalid number of arguments (expected %s <regex> [arg])\n", tokenv[0]);
                    return -1;
                }
                compbuf = akbuf_init(cfg_ctx, sizeof(regex_t));
                if ((ret = regcomp((regex_t *)akbuf_data(compbuf), tokenv[1], REG_EXTENDED)) != 0)
                {
                    unsigned char errbuf[BUF_SIZE];

                    regerror(ret, (regex_t *)akbuf_data(compbuf), errbuf, sizeof(errbuf));
                    fprintf(stderr, "Parsing of regex '%s' failed: %s\n", tokenv[1], errbuf);
                    return -1;
                }
                akbuf_set_idx(compbuf, sizeof(regex_t));
                valbuf = akbuf_init(cfg_ctx, 0);
                akbuf_strcpy(valbuf, tokenv[2]);
                dest = hypercube_config_tokens[i].val;
                tbl = (akbuf_table *)*dest;
                akbuf_table_entry_add_buf(cfg_ctx, tbl, compbuf, valbuf);
                akbuf_free(cfg_ctx, valbuf);
                break;
            }
            case CFG_INADDR:
            {
                struct in_addr *addr;

                if (tokenc != 2) {
                    CFG_ERR_HDR();
                    fprintf(stderr, "Invalid number of arguments (expected %s <IP address>)\n", tokenv[0]);
                    return -1;
                }
                addr = hypercube_config_tokens[i].val;
                if ((addr->s_addr = inet_addr(tokenv[1])) == -1) {
                    CFG_ERR_HDR();
                    fprintf(stderr, "Invalid IP address '%s'\n", tokenv[1]);
                    return -1;
                }
                break;
            }
            case CFG_FUNC:
            {
                int (*func)();
                func = hypercube_config_tokens[i].val;
                if (func != NULL) if (func(filename, curline, tokenv, tokenc) != 0) return -1;
                break;
            }
            }
    }
    return 0;
}
开发者ID:srinathgs,项目名称:hypercube,代码行数:101,代码来源:cfg.c

示例4: main


//.........这里部分代码省略.........
  regex_str_oth = "^----[ ]+[0-9]+[ ]+([^\n\r]*)";
  regex_str_loo = "^[ ]+L O O P S[ ]+([^ \n\r]+)[ ]+([^\n\r]+)";
  regex_str_loo_sub = "^[ ]+([^ \n\r]+)[ ]+([^\n\r]+)";
  regex_str_rep = "REPORT SUMMARY :[ ]+([0-9])";
  regex_str_rep_sub = "^[ ]+([0-9]+)[ ]+[^\n\r]+";
  regex_str_rep_sub2 = "^[ ]+([A-Za-z]+)[ ]+";
  regex_str_sum = "^               S O L V E      S U M M A R Y";
  regex_str_sum_sol = " SOLVER STATUS[ ]+([0-9]*)";
  regex_str_sum_mod = " MODEL STATUS[ ]+([0-9]*)";
  regex_str_com = "^----[ ]+[0-9]+[ ]+com:[ ]*([^\n\r]*)";
  regex_str_irr = "^[A-Za-z0-9\n\r\f]+";
  regex_str_emp = "^[\n\r\f\r]";
  regex_str_tmp1 = "^[^ *-]+";
  regex_str_tmp2 = "^----[ ]+";

  /* Determin from where to read */
  if (argc!=3 && argc!=2){
    usage();
    exit(1);
  }
  if((fin=fopen(argv[1],"r"))==NULL){
    printf("Cannot open the input file.\n");
    exit(1);
  }
  if(argc==3 && (fout=fopen(argv[2],"w"))==NULL){
    printf("Cannot open the output file.\n");
    exit(1);
  }
  if (argc == 2) {
    fout=stdout;
  }
  
  /* Compile regular expression */
  regcomp(&preg_par, regex_str_par, REG_EXTENDED);
  regcomp(&preg_vri, regex_str_vri, REG_EXTENDED);
  regcomp(&preg_vre, regex_str_vre, REG_EXTENDED);
  regcomp(&preg_var, regex_str_var, REG_EXTENDED);
  regcomp(&preg_set, regex_str_set, REG_EXTENDED);
  regcomp(&preg_equ, regex_str_equ, REG_EXTENDED);
  regcomp(&preg_oth, regex_str_oth, REG_EXTENDED);
  regcomp(&preg_loo, regex_str_loo, REG_EXTENDED);
  regcomp(&preg_sum, regex_str_sum, REG_EXTENDED);
  regcomp(&preg_rep, regex_str_rep, REG_EXTENDED);
  regcomp(&preg_com, regex_str_com, REG_EXTENDED);
  regcomp(&preg_irr, regex_str_irr, REG_EXTENDED);
  regcomp(&preg_loo_sub, regex_str_loo_sub, REG_EXTENDED);
  regcomp(&preg_sum_sol, regex_str_sum_sol, REG_EXTENDED);
  regcomp(&preg_sum_mod, regex_str_sum_mod, REG_EXTENDED);
  regcomp(&preg_rep_sub, regex_str_rep_sub, REG_EXTENDED);
  regcomp(&preg_rep_sub2, regex_str_rep_sub2, REG_EXTENDED);
  regcomp(&preg_par_sub, regex_str_par_sub, REG_EXTENDED);
  regcomp(&preg_vri_sub, regex_str_vri_sub, REG_EXTENDED);
  regcomp(&preg_vre_sub, regex_str_vre_sub, REG_EXTENDED);
  regcomp(&preg_emp, regex_str_emp, REG_EXTENDED);
  regcomp(&preg_tmp1, regex_str_tmp1, REG_EXTENDED);
  regcomp(&preg_tmp2, regex_str_tmp2, REG_EXTENDED);
  
  fprintf(fout,"(setq gams-ol-alist-temp-alist '(\n");
  
  /* */
  while(NULL != fgets(line, PAGEW, fin)){
    linum++;
    if((0 == regexec(&preg_irr, line, 1, pmatch, 0))
       || (0 == regexec(&preg_tmp1, line, 1, pmatch, 0))) {
      /*       Do nothing */
      ;
开发者ID:emacsmirror,项目名称:gams-mode,代码行数:67,代码来源:gamsolc.c

示例5: parse_genomic_coordinates_helper

/******************************************************************************
 * This function attempts to parse genomic coordinates from the
 * current sequence header. If successful it will return the 
 * chromosome name, name length and starting position.
 *
 * There are two supported formats.
 * The first is the UCSC/fastaFromBed style: name:start-stop[(+|-)][_id]
 * e.g., ">chr1:1000-1010(-)_xyz"
 * The second is the Galaxy "Fetch sequence" style: genome_name_start_stop_strand
 * where strand is +|-.
 * e.g., ">mm9_chr18_75759530_7575972>mm9_chr18_75759530_757597299"
 *
 * Returns TRUE if it was able to find genomic coordinates, FALSE otherwise.
 *****************************************************************************/
BOOLEAN_T parse_genomic_coordinates_helper(
  char*  header,	  // sequence name 
  char** chr_name_ptr,    // chromosome name ((chr[^:]))
  size_t * chr_name_len_ptr,// number of characters in chromosome name
  int *  start_ptr,	  // start position of sequence (chr:(\d+)-)
  int *  end_ptr	  // end position of sequence (chr:\d+-(\d+))
) {

  #define NUM_SUBMATCHES 6
  #define ERROR_MESSAGE_SIZE 100
  #define BUFFER_SIZE 512

  static BOOLEAN_T first_time = TRUE;
  static regex_t ucsc_header_regex;
  static regex_t galaxy_header_regex;
  static regmatch_t matches[NUM_SUBMATCHES];

  char error_message[ERROR_MESSAGE_SIZE];
  int status = 0;

  if (first_time == TRUE) {

    // Initialize regular express for extracting chromsome coordinates;

    status = regcomp(
      &ucsc_header_regex, 
      "([^[:space:]:]+):([[:digit:]]+)-([[:digit:]]+)(\\([+-]\\))?(_[^[:space:]]+)?", 
      REG_EXTENDED | REG_ICASE | REG_NEWLINE
    );

    if (status != 0) {
      regerror(status, &ucsc_header_regex, error_message, ERROR_MESSAGE_SIZE);
      die(
        "Error while intitializing regular expression\n"
        "for parsing UCSC style genome coordinates from FASTA header: %s\n", 
        error_message
      );
    }

    status = regcomp(
      &galaxy_header_regex, 
      "([^[:space:]_]+_[^[:space:]_]+)_([[:digit:]]+)_([[:digit:]]+)(_[+-])?", 
      REG_EXTENDED | REG_ICASE | REG_NEWLINE
    );

    if (status != 0) {
      regerror(status, &galaxy_header_regex, error_message, ERROR_MESSAGE_SIZE);
      die(
        "Error while intitializing regular expression\n"
        "for parsing Galaxy style genome coordinates from FASTA header: %s\n", 
        error_message
      );
    }

    first_time = FALSE;
  }

  BOOLEAN_T found_coordinates = FALSE;

  // Try UCSC style first
  status = regexec(&ucsc_header_regex, header, NUM_SUBMATCHES, matches, 0);
  if(status && status != REG_NOMATCH ){
    regerror(status, &ucsc_header_regex, error_message, 100);
    die("Error trying to parse UCSC style genome coordinates from sequence header: %s\n"
        "error message is %s\n",
        header, 
        error_message
    );
  }

  if (status == REG_NOMATCH) {
    // UCSC didn't work, try GALAXY style
    status = regexec(&galaxy_header_regex, header, NUM_SUBMATCHES, matches, 0);
    if(status && status != REG_NOMATCH ){
      regerror(status, &ucsc_header_regex, error_message, 100);
      die("Error trying to parse GALAXY style genome coordinates from sequence header: %s\n"
          "error message is %s\n",
          header, 
          error_message
      );
    }
  }

  if(!status) {

    // The sequence header contains genomic coordinates
//.........这里部分代码省略.........
开发者ID:a1aks,项目名称:Haystack,代码行数:101,代码来源:seq-reader-from-fasta.c

示例6: add_to_patterns

void add_to_patterns(char *pattern)
{
  char first[MAX_BUFF];
  char second[MAX_BUFF];
  char type[MAX_BUFF];
  char accel[MAX_BUFF];
  regex_t compiled;
  struct REGEX_pattern rpattern;
  int abort_type = 0;
  int parenthesis;
  int stored;
  
  /*  The regex_flags that we use are:
      REG_EXTENDED 
      REG_NOSUB 
      REG_ICASE; */

  int regex_flags = REG_NOSUB;
  
  rpattern.type = NORMAL;
  rpattern.case_sensitive = 1;
  
  stored = sscanf(pattern, "%s %s %s %s", type, first, second, accel);
  
  
  if((stored < 2) || (stored > 4)) {
    log(LOG_ERROR, 
	"unable to get a pair of patterns in add_to_patterns() "
	"for [%s]\n", pattern);
    dodo_mode = 1;
    return;
  }
  
  if(stored == 2)
    strcpy(second, "");
  
  if(strcmp(type, "abort") == 0) {
    rpattern.type = ABORT;
    abort_type = 1;
  }
  
  if(strcmp(type, "regexi") == 0) {
    regex_flags |= REG_ICASE;
    rpattern.case_sensitive = 0;
  }

  
  if(!abort_type) {

    parenthesis = count_parenthesis (first);

    if (parenthesis < 0) {
      
      /* The function returned an invalid result, 
	 indicating an invalid string */
      
      log (LOG_ERROR, "count_parenthesis() returned "
	   "left count did not match right count for line: [%s]\n",
	   pattern);
      dodo_mode = 1;
      return;

    } else if (parenthesis > 0) {

      regex_flags |= REG_EXTENDED;
      rpattern.type = EXTENDED;
      regex_flags ^= REG_NOSUB;

    }
  }
  
  
  if(regcomp(&compiled, first, regex_flags)) {
    log(LOG_ERROR, "Invalid regex [%s] in pattern file\n", first);
    dodo_mode = 1;
    return;
  }
  
  
  rpattern.cpattern = compiled;

  
  rpattern.pattern = (char *)malloc(sizeof(char) * (strlen(first) +1));
  if(rpattern.pattern == NULL) {
    log(LOG_ERROR, "unable to allocate memory in add_to_patterns()\n");
    dodo_mode = 1;
    return;
  }
  strcpy(rpattern.pattern, first);
  

  rpattern.replacement = (char *)malloc(sizeof(char) * (strlen(second) +1));
  if(rpattern.replacement == NULL) {
    log(LOG_ERROR, "unable to allocate memory in add_to_patterns()\n");
    dodo_mode = 1;
    return;
  }
  strcpy(rpattern.replacement, second);
  

//.........这里部分代码省略.........
开发者ID:OS2World,项目名称:APP-SERVER-SQUIRM,代码行数:101,代码来源:config.c

示例7: init_kill

int
init_kill(void)
{
    FILE           *killf;
    comp_kill_header header;
    comp_kill_entry entry;
    register kill_list_entry *kl;
    register kill_group_regexp *tb;
    register group_header *gh;
    time_t          kill_age, comp_age;
    register long   n;
    int             first_try = 1;

    Loop_Groups_Header(gh)
    gh->kill_list = NULL;

    kill_age = file_exist(relative(nn_directory, KILL_FILE), "frw");
    if (kill_age == 0)
        return 0;

    comp_age = file_exist(relative(nn_directory, COMPILED_KILL), "fr");
again:
    if (comp_age < kill_age && !compile_kill_file())
        return 0;

    kill_tab = NULL;
    kill_patterns = NULL;
    group_regexp_table = NULL;
    regexp_table_size = 0;

    killf = open_file(relative(nn_directory, COMPILED_KILL), OPEN_READ);
    if (killf == NULL)
        return 0;

    if (fread((char *) &header, sizeof(header), 1, killf) != 1)
        goto err;
    /* MAGIC check: format changed or using different hardware */
    if (header.ckh_magic != COMP_KILL_MAGIC)
        goto err;

#ifndef NOV
    /* DB check: if database is rebuilt, group numbers may change */
    if (header.ckh_db_check != master.db_created)
        goto err;
#else
    /* ugly hack for NOV as there isn't a master to check */
    if (first_try)
        goto err;
#endif

    if (header.ckh_entries == 0) {
        fclose(killf);
        kill_file_loaded = 1;
        return 0;
    }
    if (header.ckh_pattern_size > 0) {
        kill_patterns = newstr(header.ckh_pattern_size);
        fseek(killf, header.ckh_entries * sizeof(entry), 1);
        if (fread(kill_patterns, sizeof(char), (int) header.ckh_pattern_size, killf)
                != header.ckh_pattern_size)
            goto err;
    } else
        kill_patterns = newstr(1);

    kill_tab = newobj(kill_list_entry, header.ckh_entries);
    if ((regexp_table_size = header.ckh_regexp_size))
        group_regexp_table = newobj(kill_group_regexp, header.ckh_regexp_size);

    tb = group_regexp_table;

    fseek(killf, sizeof(header), 0);
    for (n = header.ckh_entries, kl = kill_tab; --n >= 0; kl++) {
        if (fread((char *) &entry, sizeof(entry), 1, killf) != 1)
            goto err;
        if (header.ckh_pattern_size <= entry.ck_pattern_index ||
                entry.ck_pattern_index < 0)
            goto err;

        kl->kill_pattern = kill_patterns + entry.ck_pattern_index;
        kl->kill_flag = entry.ck_flag;

        if (kl->kill_flag & KILL_ON_REGEXP)
            kl->kill_regexp = regcomp(kl->kill_pattern);
        else
            kl->kill_regexp = NULL;

        if (kl->kill_flag & GROUP_REGEXP) {
            if (kl->kill_flag & GROUP_REGEXP_HDR) {
                if (header.ckh_pattern_size <= entry.ck_group ||
                        entry.ck_group < 0)
                    goto err;
                tb->group_regexp = regcomp(kill_patterns + entry.ck_group);
            } else
                tb->group_regexp = NULL;
            tb->kill_entry = kl;
            tb++;
        } else if (entry.ck_group >= 0) {
            gh = ACTIVE_GROUP(entry.ck_group);
            kl->next_kill = (kill_list_entry *) (gh->kill_list);
            gh->kill_list = (char *) kl;
//.........这里部分代码省略.........
开发者ID:jheiss,项目名称:nn,代码行数:101,代码来源:kill.c

示例8: strchr

static path *palloc(char *cline, int lno)
{
	int c;
	char *s;
	char *key;
	path *p;
	char **ap;

	/*
	 * Implement comment chars
	 */
	s = strchr(cline, '#');
	if (s)
		*s = 0;

	/*
	 * Do a pass through the string to count the number
	 * of arguments
	 */
	c = 0;
	key = strdup(cline);
	for (s = key; s != NULL; ) {
		char *val;
		while ((val = strsep(&s, " \t\n")) != NULL && *val == '\0')
			;
		if (val)
			c++;
	}
	c++;
	free(key);

	if (c <= 1)
		return (0);

	/*
	 * Now do another pass and generate a new path structure
	 */
	p = ALLOC(path);
	p->p_argc = 0;
	p->p_argv = xmalloc(c * sizeof(char *));
	p->p_args = strdup(cline);
	ap = p->p_argv;
	for (s = p->p_args; s != NULL; ) {
		char *val;
		while ((val = strsep(&s, " \t\n")) != NULL && *val == '\0')
			;
		if (val) {
			*ap++ = val;
			p->p_argc++;
		}
	}
	*ap = 0;

#ifdef DEBUG
	for (c = 0; c < p->p_argc; c++)
		printf("%sv[%d] = %s\n", c?"\t":"", c, p->p_argv[c]);
#endif

	p->p_key = p->p_argv[0];
	if (strpbrk(p->p_key, RE_CHARS)) {
		int val;

		curp = p;			/* XXX */
		val = regcomp(&p->p_rx, p->p_key, REG_EXTENDED | REG_NOSUB);
		if (val) {
			char errbuf[_POSIX2_LINE_MAX];
			regerror(val, &p->p_rx, errbuf, sizeof errbuf);
			syslog(LOG_ERR, "%s:%d: regcomp %s: %s",
			       conf_file, curp->p_lno, curp->p_key, errbuf);
			regfree(&p->p_rx);
			p->p_rxvalid = 0;
		} else {
			p->p_rxvalid = 1;
		}
		curp = 0;			/* XXX */
	} else {
		p->p_rxvalid = 0;
	}
	p->p_lno = lno;

	return (p);
}
开发者ID:edgar-pek,项目名称:PerspicuOS,代码行数:82,代码来源:conf.c

示例9: virStringSearch

/**
 * virStringSearch:
 * @str: string to search
 * @regexp: POSIX Extended regular expression pattern used for matching
 * @max_matches: maximum number of substrings to return
 * @result: pointer to an array to be filled with NULL terminated list of matches
 *
 * Performs a POSIX extended regex search against a string and return all matching substrings.
 * The @result value should be freed with virStringFreeList() when no longer
 * required.
 *
 * @code
 *  char *source = "6853a496-1c10-472e-867a-8244937bd6f0
 *                  773ab075-4cd7-4fc2-8b6e-21c84e9cb391
 *                  bbb3c75c-d60f-43b0-b802-fd56b84a4222
 *                  60c04aa1-0375-4654-8d9f-e149d9885273
 *                  4548d465-9891-4c34-a184-3b1c34a26aa8";
 *  char **matches = NULL;
 *  virStringSearch(source,
 *                  "([a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12})",
 *                  3,
 *                  &matches);
 *
 *  // matches[0] == "6853a496-1c10-472e-867a-8244937bd6f0";
 *  // matches[1] == "773ab075-4cd7-4fc2-8b6e-21c84e9cb391";
 *  // matches[2] == "bbb3c75c-d60f-43b0-b802-fd56b84a4222"
 *  // matches[3] == NULL;
 *
 *  virStringFreeList(matches);
 * @endcode
 *
 * Returns: -1 on error, or number of matches
 */
ssize_t
virStringSearch(const char *str,
                const char *regexp,
                size_t max_matches,
                char ***matches)
{
    regex_t re;
    regmatch_t rem;
    size_t nmatches = 0;
    ssize_t ret = -1;
    int rv = -1;

    *matches = NULL;

    VIR_DEBUG("search '%s' for '%s'", str, regexp);

    if ((rv = regcomp(&re, regexp, REG_EXTENDED)) != 0) {
        char error[100];
        regerror(rv, &re, error, sizeof(error));
        virReportError(VIR_ERR_INTERNAL_ERROR,
                       _("Error while compiling regular expression '%s': %s"),
                       regexp, error);
        return -1;
    }

    if (re.re_nsub != 1) {
        virReportError(VIR_ERR_INTERNAL_ERROR,
                       _("Regular expression '%s' must have exactly 1 match group, not %zu"),
                       regexp, re.re_nsub);
        goto cleanup;
    }

    /* '*matches' must always be NULL terminated in every iteration
     * of the loop, so start by allocating 1 element
     */
    if (VIR_EXPAND_N(*matches, nmatches, 1) < 0)
        goto cleanup;

    while ((nmatches - 1) < max_matches) {
        char *match;

        if (regexec(&re, str, 1, &rem, 0) != 0)
            break;

        if (VIR_EXPAND_N(*matches, nmatches, 1) < 0)
            goto cleanup;

        if (VIR_STRNDUP(match, str + rem.rm_so,
                        rem.rm_eo - rem.rm_so) < 0)
            goto cleanup;

        VIR_DEBUG("Got '%s'", match);

        (*matches)[nmatches-2] = match;

        str = str + rem.rm_eo;
    }

    ret = nmatches - 1; /* don't count the trailing null */

 cleanup:
    regfree(&re);
    if (ret < 0) {
        virStringFreeList(*matches);
        *matches = NULL;
    }
    return ret;
//.........这里部分代码省略.........
开发者ID:zirandu,项目名称:libvirt,代码行数:101,代码来源:virstring.c

示例10: pairmove


//.........这里部分代码省略.........
				tailfrom = i;
				continue;
				break;

/* really HAVE_REGEX_H */
#if 0
				/*
				 *  Attr-Name =~ "s/find/replace/"
				 *
				 *  Very bad code.  Barely working,
				 *  if at all.
				 */

			case T_OP_REG_EQ:
			  if (found &&
			      (i->vp_strvalue[0] == 's')) {
			    regex_t		reg;
			    regmatch_t		match[1];

			    char *str;
			    char *p, *q;

			    p = i->vp_strvalue + 1;
			    q = strchr(p + 1, *p);
			    if (!q || (q[strlen(q) - 1] != *p)) {
			      tailfrom = i;
			      continue;
			    }
			    str = strdup(i->vp_strvalue + 2);
			    q = strchr(str, *p);
			    *(q++) = '\0';
			    q[strlen(q) - 1] = '\0';

			    regcomp(&reg, str, 0);
			    if (regexec(&reg, found->vp_strvalue,
					1, match, 0) == 0) {
			      fprintf(stderr, "\"%s\" will have %d to %d replaced with %s\n",
				      found->vp_strvalue, match[0].rm_so,
				      match[0].rm_eo, q);

			    }
			    regfree(&reg);
			    free(str);
			  }
			  tailfrom = i;	/* don't copy it over */
			  continue;
			  break;
#endif
			case T_OP_EQ:		/* = */
				/*
				 *  FIXME: Tunnel attributes with
				 *  different tags are different
				 *  attributes.
				 */
				if (found) {
					tailfrom = i;
					continue; /* with the loop */
				}
				break;

			  /*
			   *  If a similar attribute is found,
			   *  replace it with the new one.  Otherwise,
			   *  add the new one to the list.
			   */
			case T_OP_SET:		/* := */
开发者ID:rogerhu,项目名称:dd-wrt,代码行数:67,代码来源:valuepair.c

示例11: paircmp

/*
 *	Compare two pairs, using the operator from "one".
 *
 *	i.e. given two attributes, it does:
 *
 *	(two->data) (one->operator) (one->data)
 *
 *	e.g. "foo" != "bar"
 *
 *	Returns true (comparison is true), or false (comparison is not true);
 *
 *	FIXME: Ignores tags!
 */
int paircmp(VALUE_PAIR *one, VALUE_PAIR *two)
{
	int compare;

	switch (one->operator) {
	case T_OP_CMP_TRUE:
		return (two != NULL);

	case T_OP_CMP_FALSE:
		return (two == NULL);

		/*
		 *	One is a regex, compile it, print two to a string,
		 *	and then do string comparisons.
		 */
	case T_OP_REG_EQ:
	case T_OP_REG_NE:
#ifndef HAVE_REGEX_H
		return -1;
#else
		{
			regex_t reg;
			char buffer[MAX_STRING_LEN * 4 + 1];

			compare = regcomp(&reg, one->vp_strvalue,
					  REG_EXTENDED);
			if (compare != 0) {
				regerror(compare, &reg, buffer, sizeof(buffer));
				fr_strerror_printf("Illegal regular expression in attribute: %s: %s",
					   one->name, buffer);
				return -1;
			}

			vp_prints_value(buffer, sizeof(buffer), two, 0);

			/*
			 *	Don't care about substring matches,
			 *	oh well...
			 */
			compare = regexec(&reg, buffer, 0, NULL, 0);

			regfree(&reg);
			if (one->operator == T_OP_REG_EQ) return (compare == 0);
			return (compare != 0);
		}
#endif

	default:		/* we're OK */
		break;
	}

	/*
	 *	After doing the previous check for special comparisons,
	 *	do the per-type comparison here.
	 */
	switch (one->type) {
	case PW_TYPE_ABINARY:
	case PW_TYPE_OCTETS:
	{
		size_t length;

		if (one->length < two->length) {
			length = one->length;
		} else {
			length = two->length;
		}

		if (length) {
			compare = memcmp(two->vp_octets, one->vp_octets,
					 length);
			if (compare != 0) break;
		}

		/*
		 *	Contents are the same.  The return code
		 *	is therefore the difference in lengths.
		 *
		 *	i.e. "0x00" is smaller than "0x0000"
		 */
		compare = two->length - one->length;
	}
		break;

	case PW_TYPE_STRING:
		compare = strcmp(two->vp_strvalue, one->vp_strvalue);
		break;

//.........这里部分代码省略.........
开发者ID:rogerhu,项目名称:dd-wrt,代码行数:101,代码来源:valuepair.c

示例12: radius_compare_vps

/** Compares check and vp by value.
 *
 * Does not call any per-attribute comparison function, but does honour
 * check.operator. Basically does "vp.value check.op check.value".
 *
 * @param request Current request.
 * @param check rvalue, and operator.
 * @param vp lvalue.
 * @return 0 if check and vp are equal, -1 if vp value is less than check value, 1 is vp value is more than check
 *	value, -2 on error.
 */
int radius_compare_vps(REQUEST *request, VALUE_PAIR *check, VALUE_PAIR *vp)
{
	int ret = 0;

	/*
	 *      Check for =* and !* and return appropriately
	 */
	if (check->op == T_OP_CMP_TRUE)  return 0;
	if (check->op == T_OP_CMP_FALSE) return 1;

#ifdef HAVE_REGEX_H
	if (check->op == T_OP_REG_EQ) {
		int compare;
		regex_t reg;
		char value[1024];
		regmatch_t rxmatch[REQUEST_MAX_REGEX + 1];

		vp_prints_value(value, sizeof(value), vp, -1);

		/*
		 *	Include substring matches.
		 */
		compare = regcomp(&reg, check->vp_strvalue, REG_EXTENDED);
		if (compare != 0) {
			char buffer[256];
			regerror(compare, &reg, buffer, sizeof(buffer));

			RDEBUG("Invalid regular expression %s: %s", check->vp_strvalue, buffer);
			return -2;
		}

		memset(&rxmatch, 0, sizeof(rxmatch));	/* regexec does not seem to initialise unused elements */
		compare = regexec(&reg, value, REQUEST_MAX_REGEX + 1, rxmatch, 0);
		regfree(&reg);
		rad_regcapture(request, compare, value, rxmatch);

		ret = (compare == 0) ? 0 : -1;
		goto finish;
	}

	if (check->op == T_OP_REG_NE) {
		int compare;
		regex_t reg;
		char value[1024];
		regmatch_t rxmatch[REQUEST_MAX_REGEX + 1];

		vp_prints_value(value, sizeof(value), vp, -1);

		/*
		 *	Include substring matches.
		 */
		compare = regcomp(&reg, check->vp_strvalue, REG_EXTENDED);
		if (compare != 0) {
			char buffer[256];
			regerror(compare, &reg, buffer, sizeof(buffer));

			RDEBUG("Invalid regular expression %s: %s", check->vp_strvalue, buffer);
			return -2;
		}
		compare = regexec(&reg, value,  REQUEST_MAX_REGEX + 1, rxmatch, 0);
		regfree(&reg);

		ret = (compare != 0) ? 0 : -1;
	}
#endif

	/*
	 *	Attributes must be of the same type.
	 *
	 *	FIXME: deal with type mismatch properly if one side contain
	 *	ABINARY, OCTETS or STRING by converting the other side to
	 *	a string
	 *
	 */
	if (vp->da->type != check->da->type) return -1;

	/*
	 *	Tagged attributes are equal if and only if both the
	 *	tag AND value match.
	 */
	if (check->da->flags.has_tag) {
		ret = ((int) vp->tag) - ((int) check->tag);
		if (ret != 0) goto finish;
	}

	/*
	 *	Not a regular expression, compare the types.
	 */
	switch(check->da->type) {
//.........这里部分代码省略.........
开发者ID:AirspeedTelecom,项目名称:freeradius,代码行数:101,代码来源:valuepair.c

示例13: attrd_client_update

/*!
 * \internal
 * \brief Respond to a client update request
 *
 * \param[in] xml         Root of request XML
 *
 * \return void
 */
void
attrd_client_update(xmlNode *xml)
{
    attribute_t *a = NULL;
    char *host = crm_element_value_copy(xml, F_ATTRD_HOST);
    const char *attr = crm_element_value(xml, F_ATTRD_ATTRIBUTE);
    const char *value = crm_element_value(xml, F_ATTRD_VALUE);
    const char *regex = crm_element_value(xml, F_ATTRD_REGEX);

    /* If a regex was specified, broadcast a message for each match */
    if ((attr == NULL) && regex) {
        GHashTableIter aIter;
        regex_t *r_patt = calloc(1, sizeof(regex_t));

        crm_debug("Setting %s to %s", regex, value);
        if (regcomp(r_patt, regex, REG_EXTENDED|REG_NOSUB)) {
            crm_err("Bad regex '%s' for update", regex);

        } else {
            g_hash_table_iter_init(&aIter, attributes);
            while (g_hash_table_iter_next(&aIter, (gpointer *) & attr, NULL)) {
                int status = regexec(r_patt, attr, 0, NULL, 0);

                if (status == 0) {
                    crm_trace("Matched %s with %s", attr, regex);
                    crm_xml_add(xml, F_ATTRD_ATTRIBUTE, attr);
                    send_attrd_message(NULL, xml);
                }
            }
        }

        free(host);
        regfree(r_patt);
        free(r_patt);
        return;

    } else if (attr == NULL) {
        crm_err("Update request did not specify attribute or regular expression");
        free(host);
        return;
    }

    if (host == NULL) {
        crm_trace("Inferring host");
        host = strdup(attrd_cluster->uname);
        crm_xml_add(xml, F_ATTRD_HOST, host);
        crm_xml_add_int(xml, F_ATTRD_HOST_ID, attrd_cluster->nodeid);
    }

    a = g_hash_table_lookup(attributes, attr);

    /* If value was specified using ++ or += notation, expand to real value */
    if (value) {
        if (attrd_value_needs_expansion(value)) {
            int int_value;
            attribute_value_t *v = NULL;

            if (a) {
                v = g_hash_table_lookup(a->values, host);
            }
            int_value = attrd_expand_value(value, (v? v->current : NULL));

            crm_info("Expanded %s=%s to %d", attr, value, int_value);
            crm_xml_add_int(xml, F_ATTRD_VALUE, int_value);

            /* Replacing the value frees the previous memory, so re-query it */
            value = crm_element_value(xml, F_ATTRD_VALUE);
        }
    }

    crm_debug("Broadcasting %s[%s]=%s%s", attr, host, value,
              (attrd_election_won()? " (writer)" : ""));

    free(host);

    send_attrd_message(NULL, xml); /* ends up at attrd_peer_message() */
}
开发者ID:ClusterLabs,项目名称:pacemaker,代码行数:85,代码来源:attrd_commands.c

示例14: main

int main(int argc, char **argv)
{
    /* I18n */
    setlocale(LC_ALL, "");
#if ENABLE_NLS
    bindtextdomain(PACKAGE, LOCALEDIR);
    textdomain(PACKAGE);
#endif

    abrt_init(argv);

    /* Can't keep these strings/structs static: _() doesn't support that */
    const char *program_usage_string = _(
        "& [-vusoxm] [-d DIR]/[-D] [FILE]\n"
        "\n"
        "Extract oops from FILE (or standard input)"
    );
    enum {
        OPT_v = 1 << 0,
        OPT_s = 1 << 1,
        OPT_o = 1 << 2,
        OPT_d = 1 << 3,
        OPT_D = 1 << 4,
        OPT_u = 1 << 5,
        OPT_x = 1 << 6,
        OPT_t = 1 << 7,
        OPT_m = 1 << 8,
    };
    char *problem_dir = NULL;
    char *dump_location = NULL;
    /* Keep enum above and order of options below in sync! */
    struct options program_options[] = {
        OPT__VERBOSE(&g_verbose),
        OPT_BOOL(  's', NULL, NULL, _("Log to syslog")),
        OPT_BOOL(  'o', NULL, NULL, _("Print found oopses on standard output")),
        /* oopses don't contain any sensitive info, and even
         * the old koops app was showing the oopses to all users
         */
        OPT_STRING('d', NULL, &dump_location, "DIR", _("Create new problem directory in DIR for every oops found")),
        OPT_BOOL(  'D', NULL, NULL, _("Same as -d DumpLocation, DumpLocation is specified in abrt.conf")),
        OPT_STRING('u', NULL, &problem_dir, "PROBLEM", _("Save the extracted information in PROBLEM")),
        OPT_BOOL(  'x', NULL, NULL, _("Make the problem directory world readable")),
        OPT_BOOL(  't', NULL, NULL, _("Throttle problem directory creation to 1 per second")),
        OPT_BOOL(  'm', NULL, NULL, _("Print search string(s) to stdout and exit")),
        OPT_END()
    };
    unsigned opts = parse_opts(argc, argv, program_options, program_usage_string);

    export_abrt_envvars(0);

    msg_prefix = g_progname;
    if ((opts & OPT_s) || getenv("ABRT_SYSLOG"))
    {
        logmode = LOGMODE_JOURNAL;
    }

    if (opts & OPT_m)
    {
        char *oops_string_filter_regex = abrt_oops_string_filter_regex();
        if (oops_string_filter_regex)
        {
            regex_t filter_re;
            if (regcomp(&filter_re, oops_string_filter_regex, REG_NOSUB) != 0)
                perror_msg_and_die(_("Failed to compile regex"));

            const regex_t *filter[] = { &filter_re, NULL };

            koops_print_suspicious_strings_filtered(filter);

            regfree(&filter_re);
            free(oops_string_filter_regex);
        }
        else
            koops_print_suspicious_strings();

        return 1;
    }

    if (opts & OPT_D)
    {
        if (opts & OPT_d)
            show_usage_and_die(program_usage_string, program_options);
        load_abrt_conf();
        dump_location = g_settings_dump_location;
        g_settings_dump_location = NULL;
        free_abrt_conf_data();
    }

    int oops_utils_flags = 0;
    if ((opts & OPT_x))
        oops_utils_flags |= ABRT_OOPS_WORLD_READABLE;

    if ((opts & OPT_t))
        oops_utils_flags |= ABRT_OOPS_THROTTLE_CREATION;

    if ((opts & OPT_o))
        oops_utils_flags |= ABRT_OOPS_PRINT_STDOUT;

    argv += optind;
    if (argv[0])
//.........这里部分代码省略.........
开发者ID:RavenB,项目名称:abrt,代码行数:101,代码来源:abrt-dump-oops.c

示例15: main

int
main (int argc, char *argv[])
{
  struct stat st;
  static const char *pat[] = {
    ".?.?.?.?.?.?.?argc",
    "(.?)(.?)(.?)(.?)(.?)(.?)(.?)argc",
    "((((((((((.?))))))))))((((((((((.?))))))))))((((((((((.?))))))))))"
    "((((((((((.?))))))))))((((((((((.?))))))))))((((((((((.?))))))))))"
    "((((((((((.?))))))))))argc" };

  size_t len;
  int fd;
  int testno, i, j, k, l;
  char *string;
  char *buf;

  if (argc < 2)
    abort ();

  fd = open (argv[1], O_RDONLY);
  if (fd < 0)
    {
      printf ("Couldn't open %s: %s\n", argv[1], strerror (errno));
      abort ();
    }

  if (fstat (fd, &st) < 0)
    {
      printf ("Couldn't fstat %s: %s\n", argv[1], strerror (errno));
      abort ();
    }

  buf = malloc (st.st_size + 1);
  if (buf == NULL)
    {
      printf ("Couldn't allocate buffer: %s\n", strerror (errno));
      abort ();
    }

  if (read (fd, buf, st.st_size) != (ssize_t) st.st_size)
    {
      printf ("Couldn't read %s", argv[1]);
      abort ();
    }

  close (fd);
  buf[st.st_size] = '\0';

  string = buf;
  len = st.st_size;

  for (testno = 0; testno < 4; ++testno)
    for (i = 0; i < sizeof (pat) / sizeof (pat[0]); ++i)
      {
	regex_t rbuf;
	struct re_pattern_buffer rpbuf;
	int err;

	printf ("test %d pattern %d", testno, i);
	if (testno < 2)
	  {
	    err = regcomp (&rbuf, pat[i],
			   REG_EXTENDED | (testno ? REG_NOSUB : 0));
	    if (err != 0)
	      {
		char errstr[300];
		putchar ('\n');
		regerror (err, &rbuf, errstr, sizeof (errstr));
		puts (errstr);
		return err;
	      }
	  }
	else
	  {
	    const char *s;
	    re_set_syntax (RE_SYNTAX_POSIX_EGREP
			   | (testno == 3 ? RE_NO_SUB : 0));

	    memset (&rpbuf, 0, sizeof (rpbuf));
	    s = re_compile_pattern (pat[i], strlen (pat[i]), &rpbuf);
	    if (s != NULL)
	      {
		printf ("\n%s\n", s);
		abort ();
	      }

	    /* Just so that this can be tested with earlier glibc as well.  */
	    if (testno == 3)
	      rpbuf.no_sub = 1;
	  }

      if (testno < 2)
	{
	  regmatch_t pmatch[71];
	  err = regexec (&rbuf, string, 71, pmatch, 0);
	  if (err == REG_NOMATCH)
	    {
	      puts ("\nregexec failed");
	      abort ();
//.........这里部分代码省略.........
开发者ID:Distrotech,项目名称:sed,代码行数:101,代码来源:tst-regex2.c


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