keep files by basename in lookup tree, store full pathname in rxpd_file
authorChristian Thaeter <ct@pipapo.org>
Sat, 6 Oct 2007 16:41:18 +0000 (18:41 +0200)
committerChristian Thaeter <ct@pipapo.org>
Sat, 6 Oct 2007 16:41:18 +0000 (18:41 +0200)
rxpd.c
rxpd.h

diff --git a/rxpd.c b/rxpd.c
index b9a0b48..e53c042 100644 (file)
--- a/rxpd.c
+++ b/rxpd.c
@@ -153,7 +153,13 @@ rxpd_file_new (struct rxpd_base* base, const char* filename)
       self = malloc (sizeof (struct rxpd_file));
       if (self)
         {
-          psplay_init (&self->node, filename);
+          self->filename = filename;
+          const char* basename = strrchr (filename, '/');
+          if (basename)
+            ++basename;
+          else
+            basename = filename;
+          psplay_init (&self->node, basename);
           llist_init (&self->rules);
 
           psplay_insert (&base->files, &self->node);
@@ -173,7 +179,7 @@ rxpd_file_delete (PSplay f)
           struct rxpd_rule* node = (struct rxpd_rule*)n;
           rxpd_rule_delete (node);
         }
-      free ((void*)file->node.key);
+      free ((void*)file->filename);
       free (f);
     }
 }
@@ -181,9 +187,7 @@ rxpd_file_delete (PSplay f)
 int
 rxpd_file_load (struct rxpd_file* self)
 {
-  const char* filename = self->node.key;
-
-  FILE* f = fopen (filename, "r");
+  FILE* f = fopen (self->filename, "r");
   // TODO error handling
   if (f)
     {
diff --git a/rxpd.h b/rxpd.h
index ccfa107..ecc2036 100644 (file)
--- a/rxpd.h
+++ b/rxpd.h
@@ -100,7 +100,8 @@ rxpd_rule_delete (struct rxpd_rule*);
 //
 struct rxpd_file
 {
-  psplay node;
+  psplay node;          // key points to basename part of filename
+  const char* filename; // full filename
   //TODO later     struct stat last_stat;
   llist rules;
 };