]> mj.ucw.cz Git - umpf.git/commitdiff
redo variables
authorAnicka Bernathova <anicka@anicka.net>
Tue, 21 Jul 2009 13:31:58 +0000 (15:31 +0200)
committerAnicka Bernathova <anicka@anicka.net>
Tue, 21 Jul 2009 13:31:58 +0000 (15:31 +0200)
code.c
cond.y
int.c
umpf.h

diff --git a/code.c b/code.c
index 2200d234dc8229f46172e576699f5499d56fb7d0..932bb9ab5d8766c3a43f508a43b5add5b27825ab 100644 (file)
--- a/code.c
+++ b/code.c
@@ -34,35 +34,34 @@ get_bucket_number(char* name)
 
 /* return var struct or NULL if not found */
 struct variable*
-get_var_struct(char* name, struct list* hash)
+get_var_struct(char* name, enum var_type type, struct list* hash)
 {
        int n;
        struct variable *p;
 
        n = get_bucket_number(name);
-       int nocase = isupper(*name);
        LIST_FOREACH(p, hash + n)
-               if (!(nocase ? strcasecmp : strcmp)(p->name,name))
+               if (!strcasecmp(p->name, name) && p->type == type)
                        return p;
 
        return NULL;
 }
 
 int
-find_var(char* name, struct list* hash)
+find_var(char* name, enum var_type type, struct list* hash)
 {
        int n;
        struct variable *p;
 
        n = get_bucket_number(name);
-       int nocase = isupper(*name);
        LIST_FOREACH(p, hash + n)
-               if (!(nocase ? strcasecmp : strcmp)(p->name,name))
+               if (!strcasecmp(p->name, name) && p->type == type)
                        return p->varcode;
 
        p = xmalloc(sizeof(struct variable));
        p->name = xstrdup(name);
        p->varcode = current_varcode++;
+       p->type = type;
        list_add_last(hash+n, &p->car);
 
        return p->varcode;
diff --git a/cond.y b/cond.y
index 38ec08c759112b110183dc1bebfbead8946fad5c..4c1d3d221d188a976ff7fd96d5b42e3e8c07a714 100644 (file)
--- a/cond.y
+++ b/cond.y
@@ -2,10 +2,12 @@
 
 #include <stdio.h>
 #include <string.h>
+#include <ctype.h>
 
 #include "umpf.h"
 
 static struct tree* tree_malloc(int type);
+static enum var_type get_var_type(char* var);
 
 %}
 %error-verbose
@@ -153,7 +155,7 @@ ass:
                                        $$->pt.ass.left = tree_malloc(ST_LEAF);
                                        $$->pt.ass.left->pt.leaf.type = L_VAR;
                                        $$->pt.ass.left->pt.leaf.value = $1;
-                                       $$->pt.ass.left->pt.leaf.n = find_var($1, var_hash);
+                                       $$->pt.ass.left->pt.leaf.n = find_var($1, get_var_type($1), var_hash);
                                        $$->pt.ass.right = $3;
                                }
 ;
@@ -162,7 +164,7 @@ leaves:             VAR     {
                                $$ = tree_malloc(ST_LEAF);
                                $$->pt.leaf.type = L_VAR;
                                $$->pt.leaf.value = $1;
-                               $$->pt.leaf.n = find_var($1, var_hash);
+                               $$->pt.leaf.n = find_var($1, get_var_type($1), var_hash);
                        }
                | CONST { 
                                $$ = tree_malloc(ST_LEAF);
@@ -246,6 +248,28 @@ tree_malloc(int type)
        return temp;
 }
 
+enum var_type
+get_var_type(char* var)
+{
+       int upper = 0;
+       int lower = 0;
+
+       if (islower(*var))
+               return VAR_USER;
+
+       while (*var) {
+               if (isupper(*var))      
+                       upper++;
+               if (islower(*var))
+                       lower++;
+               var++;
+       }
+       if (upper && lower)
+               return VAR_HEADER;
+
+       return VAR_INTERN;
+}
+
 void
 yyerror (char const *s)
 {
diff --git a/int.c b/int.c
index 5c9c33a71c78d5102042629ccec6e95655e0bf3c..59c1f93a396f011ff339c067773de3775199082a 100644 (file)
--- a/int.c
+++ b/int.c
@@ -192,7 +192,7 @@ modify_headers(struct list* headers, struct list* hash)
        
 
        LIST_FOREACH(p, headers){
-               pv = get_var_struct(p->name, hash);
+               pv = get_var_struct(p->name, VAR_HEADER, hash);
                if (!pv)
                        continue;
                u = unfold(p->value);
@@ -210,14 +210,14 @@ modify_headers(struct list* headers, struct list* hash)
        // find new headers 
        for (i = 0; i < HASHSIZE; i++){
                LIST_FOREACH(pv, hash + i){
-                       if (isupper(pv->name[0]) && pv->modified){
+                       if (pv->type == VAR_HEADER && pv->modified){
                                pv->modified = 0;
 
                                p = xmalloc(sizeof(struct hlist));
                                p->name = xstrdup(pv->name);
                                p->value = get_var(pv->varcode);
 
-                               list_add_last(headers,&p->car);
+                               list_add_last(headers, &p->car);
                        }
                }
        }
@@ -700,7 +700,7 @@ save_current_headers(struct list* hash)
        struct variable* pv;
 
        LIST_FOREACH(p, current_headers){
-               pv = get_var_struct(p->name, hash);
+               pv = get_var_struct(p->name, VAR_HEADER, hash);
                if (!pv)
                        continue;
                u = unfold(p->value);
diff --git a/umpf.h b/umpf.h
index e379c8400a0a1120f910c35e7abc044b4ccf3008..35f65ef7c352a39dbdfb9de0ea1636e02d267465 100644 (file)
--- a/umpf.h
+++ b/umpf.h
@@ -13,6 +13,12 @@ enum keyword {
        K_FILTER
 };
 
+enum var_type {
+       VAR_HEADER,
+       VAR_INTERN,
+       VAR_USER
+};
+
 struct tree {
        enum {
                ST_IF,
@@ -164,6 +170,7 @@ struct variable {
        char* name;
        int varcode;
        int modified;
+       enum var_type type;
 };
 
 struct list input_code;
@@ -179,8 +186,8 @@ char* empty;
 
 void init(void);
 void compile(struct tree* t, struct list* where);
-int find_var(char* name, struct list* hash);
-struct variable* get_var_struct(char* name, struct list* hash);
+int find_var(char* name, enum var_type type, struct list* hash);
+struct variable* get_var_struct(char* name, enum var_type type, struct list* hash);
 int store_const(char* c);
 struct list* new_var_hash(void);
 int get_bucket_number(char* name);