/[anubis]/anubis/src/regex.c
ViewVC logotype

Diff of /anubis/src/regex.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.1.1.1 by polak, Thu Jan 30 10:41:13 2003 UTC revision 1.2 by gray, Wed Feb 5 21:46:41 2003 UTC
# Line 24  Line 24 
24    
25  #include "headers.h"  #include "headers.h"
26  #include "extern.h"  #include "extern.h"
27    #include "rcfile.h"
28    
29  /****************************  /****************************
30   Regular Expressions support   Regular Expressions support
# Line 35  static int perlre_match(char *, char *); Line 36  static int perlre_match(char *, char *);
36  #endif /* HAVE_PCRE */  #endif /* HAVE_PCRE */
37    
38  int  int
39    anubis_regexp_match(RC_REGEX *re, char *line, int *refc, char ***refv)
40    {
41    #ifdef HAVE_PCRE
42            if (re->perlre)
43                    return !_perl_match(re->v.pcre, line, refc, refv);
44    #endif
45            return !_posix_match(&re->v.re, line, refc, refv);
46    }
47    
48    int
49    _posix_match(regex_t *re, char *line, int *refc, char ***refv)
50    {
51            regmatch_t *rmp;
52            int rc;
53                    
54            rmp = xmalloc((re->re_nsub + 1) * sizeof(*rmp));
55            rc = regexec(re, line, re->re_nsub + 1, rmp, 0);
56            if (rc == 0 && re->re_nsub) {
57                    int i;
58                    *refv = xmalloc((re->re_nsub + 2) * sizeof(**refv));
59                    for (i = 0; i <= re->re_nsub; i++) {
60                            if (rmp[i].rm_so != -1) {
61                                    size_t matchlen = rmp[i].rm_eo - rmp[i].rm_so;
62                                    (*refv)[i] = xmalloc(matchlen + 1);
63                                    memcpy((*refv)[i], line + rmp[i].rm_so,
64                                           matchlen);
65                                    (*refv)[i][matchlen] = 0;
66                                    remcrlf((*refv)[i]);
67                            } else
68                                    (*refv)[i] = strdup("");
69                    }
70                    *refc = re->re_nsub;
71            }
72            xfree(rmp);
73            return rc;
74    }
75    
76    int
77  regex_match(char *regex, char *line)  regex_match(char *regex, char *line)
78  {  {
79          int rs = 0;          int rs = 0;

Legend:
Removed from v.1.1.1.1  
changed lines
  Added in v.1.2

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26