rule_acticvate function to 'uncomment' rules
authorChristian Thaeter <ct@pipapo.org>
Mon, 29 Oct 2007 05:26:43 +0000 (06:26 +0100)
committerChristian Thaeter <ct@pipapo.org>
Mon, 29 Oct 2007 05:26:43 +0000 (06:26 +0100)
src/rxpd.h
src/rxpd_rule.c

index 2a5a758..f4c0db0 100644 (file)
@@ -21,6 +21,8 @@
 #ifndef RXPD_H
 #define RXPD_H
 
+#define _GNU_SOURCE
+
 #include "llist.h"
 #include "psplay.h"
 
@@ -145,6 +147,9 @@ rxpd_rule_new (const char* buf);
 struct rxpd_rule*
 rxpd_rule_copy (const struct rxpd_rule* src);
 
+struct rxpd_rule*
+rxpd_rule_activate (struct rxpd_rule* self);
+
 struct rxpd_rule*
 rxpd_rule_comment (struct rxpd_rule* self, const char* comment);
 
index 3fc9d67..4dedc59 100644 (file)
@@ -55,7 +55,6 @@ rxpd_rule_new (const char* buf)
             self->string = rxpd_strdup (namestart+1);
           else
             {
-              regfree (&self->rx);
               char ebuf[256];
               size_t len = regerror (err, NULL, ebuf, 256);
               self->string = rxpd_malloc (len + strlen(namestart+1) + 14);
@@ -96,6 +95,47 @@ rxpd_rule_copy (const struct rxpd_rule* src)
   return self;
 }
 
+struct rxpd_rule*
+rxpd_rule_activate (struct rxpd_rule* self)
+{
+  if (self)
+    {
+      char* buf;
+      if (self->string[0] == '#' && (buf = strstr (self->string, ": ")+2) && *buf)
+        {
+          if (*buf != '#')
+            {
+              char* namestart = strchr (buf, ':');
+              char* rxstart = namestart? strchr (namestart+1, ':') : NULL;
+
+              if (!rxstart)
+                return NULL;
+
+              // TODO regflags from base
+              if (regcomp (&self->rx, rxstart+1, REG_EXTENDED|REG_ICASE|REG_NOSUB))
+                return NULL;
+
+              free (self->string);
+              self->string = rxpd_strdup (namestart+1);
+
+              if (namestart != buf)
+                {
+                  /* atime given */
+                  self->atime = atoi (buf);
+                  if (!self->atime)
+                    /* atime was zero or not set */
+                    self->atime = time (NULL)-1;
+                }
+            }
+          else
+            self->string = rxpd_strdup (buf);
+        }
+      else
+        return NULL;
+    }
+  return self;
+}
+
 struct rxpd_rule*
 rxpd_rule_comment (struct rxpd_rule* self, const char* comment)
 {