rx enhancements.
authorPierre Habouzit <madcoder@debian.org>
Sun, 18 Mar 2007 23:05:46 +0000 (00:05 +0100)
committerPierre Habouzit <madcoder@debian.org>
Sun, 18 Mar 2007 23:05:46 +0000 (00:05 +0100)
lib-lib/rx.c
lib-lib/rx.h

index 0edce59..02a01d0 100644 (file)
@@ -38,6 +38,21 @@ rx_t *rx_compile(const char *s, int flags)
     return pp;
 }
 
     return pp;
 }
 
+int rx_validate(const char *s, char *errbuf, ssize_t errlen)
+{
+    regex_t re;
+    int res;
+
+    p_clear(&re, 1);
+    res = REGCOMP(&re, NONULL(s), 0);
+    if (res) {
+        regerror(res, &re, errbuf, errlen);
+    }
+    regfree(&re);
+
+    return res;
+}
+
 void rx_set_template(rx_t *rx, const char *tpl)
 {
     const char *p = tpl;
 void rx_set_template(rx_t *rx, const char *tpl)
 {
     const char *p = tpl;
@@ -58,13 +73,12 @@ void rx_set_template(rx_t *rx, const char *tpl)
     rx->nmatch++;     /* match 0 is always the whole expr */
 }
 
     rx->nmatch++;     /* match 0 is always the whole expr */
 }
 
-void rx_delete(rx_t **p)
+void rx_wipe(rx_t *rx)
 {
 {
-    p_delete(&(*p)->pattern);
-    regfree((*p)->rx);
-    p_delete(&(*p)->rx);
-    p_delete(&(*p)->template);
-    p_delete(p);
+    p_delete(&rx->pattern);
+    regfree(rx->rx);
+    p_delete(&rx->rx);
+    p_delete(&rx->template);
 }
 
 int rx_list_match(rx_t *l, const char *s)
 }
 
 int rx_list_match(rx_t *l, const char *s)
index af86374..b976fc1 100644 (file)
@@ -48,9 +48,12 @@ typedef struct rx_t {
     char *template;               /* out template */
 } rx_t;
 
     char *template;               /* out template */
 } rx_t;
 
-rx_t* rx_compile(const char*, int);
+rx_t *rx_compile(const char*, int);
+int rx_validate(const char*, char*, ssize_t);
 void rx_set_template(rx_t *, const char*);
 void rx_set_template(rx_t *, const char*);
-void rx_delete(rx_t **);
+void rx_wipe(rx_t *);
+DO_DELETE(rx_t, rx);
+
 DO_SLIST(rx_t, rx, rx_delete);
 
 /* for handling lists */
 DO_SLIST(rx_t, rx, rx_delete);
 
 /* for handling lists */