WIP: pth transistion, 3rd step, commands basically ported
[rxpd] / src / rxpd_file.c
index 0a78c72f296b039bd85acc68b6c5ba1f8cd38e91..d0341b15cb10e84fbac909e2c970c1e6204fbb8d 100644 (file)
@@ -57,19 +57,29 @@ rxpd_file_new (struct rxpd_base* base, const char* filename)
 }
 
 void
-rxpd_file_delete (PSplay f)
+rxpd_file_delete (struct rxpd_file* self)
 {
-  if (f)
+  if (self)
     {
-      struct rxpd_file* file = (struct rxpd_file*)f;
-      LLIST_WHILE_HEAD (&file->rules, n)
+      rxpd_file_rules_delete (self);
+      psplay_remove (&self->base->files, &self->node);
+      free ((void*)self->filename);
+      free (self);
+    }
+}
+
+struct rxpd_file*
+rxpd_file_rules_delete (struct rxpd_file* self)
+{
+  if (self)
+    {
+      LLIST_WHILE_HEAD (&self->rules, n)
         {
           struct rxpd_rule* node = (struct rxpd_rule*)n;
           rxpd_rule_delete (node);
         }
-      free ((void*)file->filename);
-      free (f);
     }
+  return self;
 }
 
 int
@@ -127,7 +137,12 @@ rxpd_file_save (struct rxpd_file* self)
       LLIST_FOREACH (&self->rules, n)
         {
           struct rxpd_rule* node = (struct rxpd_rule*)n;
-          fprintf (f, "%s\n", node->string);
+          if (node->atime != (time_t)-1)
+            fprintf (f, "%ld:%s\n", node->atime, node->string);
+          else if (*node->string != '#')
+            fprintf (f, ":%s\n", node->string);
+          else
+            fprintf (f, "%s\n", node->string);
         }
 
       fclose (f);