rule_acticvate function to 'uncomment' rules
[rxpd] / src / rxpd_rule.c
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)
 {