aruu

[MIRROR] Actual replacement for Busybox | suckless
git clone https://git.daat.foo/aruu.git
Log | Files | Refs | README | LICENSE

pattern.c (532B)


      1 #include "pattern.h"
      2 #include "in_all.h"
      3 #include <regex.h>
      4 
      5 /*
      6  * interface to POSIX regular expression routines
      7  */
      8 
      9 static regex_t pattern;
     10 static int     pattern_valid;
     11 
     12 char *
     13 re_comp(char *s)
     14 {
     15   if (!*s) {
     16     return (char *)0;
     17   }
     18   if (pattern_valid) {
     19     regfree(&pattern);
     20     pattern_valid = 0;
     21   }
     22   if (regcomp(&pattern, s, 0) == 0) {
     23     pattern_valid = 1;
     24     return (char *)0;
     25   }
     26   return "Error in pattern";
     27 }
     28 
     29 int
     30 re_exec(char *s)
     31 {
     32   return pattern_valid && regexec(&pattern, s, 0, (regmatch_t *)0, 0) == 0;
     33 }