AFFEND #define MAX_RS 32 value arc_regexp_match(arc *c, value regexp, value str) { Reprog *rp; Resub rs[MAX_RS]; int i, rv; struct regexp_t *rxdata; value subexprs = CNIL; rxdata = (struct regexp_t *)REP(regexp); rp = rxdata->rp; for (i=0; i<MAX_RS; i++) rs[i].csp = rs[i].cep = -1; if ((rv = rregexec(c, rp, str, rs, 10)) >= 0) { /* handle substring matches */ for (i=MAX_RS-1; i>=0; i--) { value sstr; if (rs[i].csp < 0) continue; sstr = arc_substr(c, str, rs[i].csp, rs[i].cep); subexprs = cons(c, sstr, subexprs); } return(cons(c, INT2FIX(rv), cons(c, subexprs, CNIL))); } if (rv == -1) return(CNIL); arc_err_cstrfmt(c, "out of relist space"); return(CNIL); }
int validurl(Rune *r) { Resub rs[10]; if(urlprog == nil) { urlprog = regcomp(urlexpr); if(urlprog == nil) error("regcomp"); } memset(rs, 0, sizeof(rs)); if(rregexec(urlprog, r, rs, nelem(rs)) == 0) return FALSE; return TRUE; }
int match(int *addr) { if(!pattern) return 0; if(addr){ if(addr == zero) return 0; subexp[0].s.rsp = getline(*addr); } else subexp[0].s.rsp = loc2; subexp[0].e.rep = 0; if(rregexec(pattern, linebuf, subexp, MAXSUB)) { loc1 = subexp[0].s.rsp; loc2 = subexp[0].e.rep; return 1; } loc1 = loc2 = 0; return 0; }