]> mj.ucw.cz Git - umpf.git/commitdiff
variables to clist
authorAnicka Bernathova <anicka@anicka.net>
Sun, 13 Jul 2008 19:00:18 +0000 (21:00 +0200)
committerAnicka Bernathova <anicka@anicka.net>
Sun, 13 Jul 2008 19:00:18 +0000 (21:00 +0200)
brum.h
int.c

diff --git a/brum.h b/brum.h
index 95e8f16a5a0fa36609d21d708de2fbde3a2dcbfe..3692182d93f638e2b21cef5e0b742775419e1632 100644 (file)
--- a/brum.h
+++ b/brum.h
@@ -78,10 +78,10 @@ FILE* conf;
 
 /* int.c */
 struct variable {
+       struct node car;
        char* name;
        char* value;
        int modified;
-       struct variable* next;
 };
 
 struct hlist {
@@ -101,13 +101,13 @@ struct action {
        struct email e;
 };
 
-struct variable** var_hash;
+struct list* var_hash;
 
 void print_tree(struct tree* t, int ind);
-void interp(struct tree* t, struct variable** hash);
-struct variable** new_var_hash(void);
-void print_vars(struct variable** hash);
-void save_current_headers(struct variable** hash);
+void interp(struct tree* t, struct list* hash);
+struct list* new_var_hash(void);
+void print_vars(struct list* hash);
+void save_current_headers(struct list* hash);
 
 /* ham.c */
 struct list* current_headers;
diff --git a/int.c b/int.c
index fa7b08d668e9b171594260183a5a5706adf7c083..a9481808cb3b0b09cd888bdf76e0cc8511005cc6 100644 (file)
--- a/int.c
+++ b/int.c
 #define HASHSIZE 103
 #define MAGIC 19
 
-struct variable**
+struct list* 
 new_var_hash(void)
 {
-       struct variable** res;
+       struct list* res;
+       int i;
 
-       res = xmalloc (HASHSIZE * sizeof(struct variable*));
-       memset(res, 0, sizeof(struct variable*)*HASHSIZE);
+       res = xmalloc (HASHSIZE * sizeof(struct list));
+       for (i = 0; i < HASHSIZE; i++)
+               list_init(res + i);
+       
 
        return res;
 }
@@ -37,36 +40,40 @@ get_bucket_number(char* name)
 
 /* value NULL for finding without modyfiing */
 static struct variable*
-find_var(char* name, char* value, struct variable** hash)
+find_var(char* name, char* value, struct list* hash)
 {
-       int n;
+       int n, found = 0;
        struct variable *p;
 
        n = get_bucket_number(name);
 
-       p = hash[n];
-
        if (isupper(*name)){
-               while(p && strcasecmp(p->name,name))
-                       p = p->next;
+               LIST_FOREACH(p, hash + n)
+                       if (!strcasecmp(p->name,name)){
+                               found = 1;
+                               break;
+                       }
        } else {
-               while(p && strcmp(p->name,name))
-                       p = p->next;
+               LIST_FOREACH(p, hash + n)
+                       if (!strcmp(p->name, name)){
+                               found = 1;
+                               break;
+                       }
        }
 
-       if (p && value){
+       if (found && value){
                free(p->value);
                p->value = value;
                p->modified = 1;
-       } else if (p && !value)
+       } else if (found && !value)
                return p;
        else {
                p = xmalloc(sizeof(struct variable));
-               p->next = hash[n];
-               hash[n] = p;
                p->name = name; 
                p->value = (value? value:xstrdup(""));
                p->modified = 1;
+
+               list_add_last(hash+n, &p->car);
        }
 
        return p;
@@ -170,8 +177,8 @@ xcat(char* left, char* right)
        return res;
 }
 
-char*
-interp_ass_right(struct tree* t, struct variable** hash)
+static char*
+interp_ass_right(struct tree* t, struct list* hash)
 {
        switch (t->st){
                case ST_LEAF:
@@ -192,8 +199,8 @@ interp_ass_right(struct tree* t, struct variable** hash)
 }      
 
 // FIXME: we would like to be able also do things like ($a & $b) == $c
-int
-interp_cond(struct tree* t, struct variable** hash)
+static int
+interp_cond(struct tree* t, struct list* hash)
 {
        if (t->st != ST_COND)
                die("Muhehehechlemst?");
@@ -236,7 +243,7 @@ interp_cond(struct tree* t, struct variable** hash)
 }
 
 static void
-modify_headers(struct list* headers, struct variable** hash)
+modify_headers(struct list* headers, struct list* hash)
 {
        struct hlist* p;
        struct variable* pv;
@@ -253,7 +260,7 @@ modify_headers(struct list* headers, struct variable** hash)
 
        /* find new headers */
        for (i = 0; i < HASHSIZE; i++){
-               for(pv = hash[i]; pv; pv = pv->next){
+               LIST_FOREACH(pv, hash + i){
                        if (isupper(pv->name[0]) && pv->modified){
                                pv->modified = 0;
 
@@ -287,7 +294,7 @@ copy_headers(struct list* orig)
 }
 
 static void
-new_action(char* l, char* r, char* s, struct variable** hash)
+new_action(char* l, char* r, char* s, struct list* hash)
 {
        struct action* a;
 
@@ -303,7 +310,7 @@ new_action(char* l, char* r, char* s, struct variable** hash)
 }
 
 void
-interp(struct tree* t, struct variable** hash)
+interp(struct tree* t, struct list* hash)
 {
        if (!t)
                return;
@@ -334,17 +341,14 @@ interp(struct tree* t, struct variable** hash)
 }
 
 void
-print_vars(struct variable** hash)
+print_vars(struct list* hash)
 {
        int i;
        struct variable* p;
 
        for (i=0; i<HASHSIZE; i++){
-               p = hash[i];
-               while(p){
+               LIST_FOREACH(p, hash + i)
                        printf("%s=%s\n",p->name, p->value);
-                       p = p->next;
-               }               
        }
 }
 
@@ -378,7 +382,7 @@ unfold(char* u)
 }
 
 void
-save_current_headers(struct variable** hash)
+save_current_headers(struct list* hash)
 {
        struct hlist* p;
        struct variable* pv;