]> mj.ucw.cz Git - umpf.git/commitdiff
some bugfixes
authorAnicka Bernathova <anicka@anicka.net>
Tue, 21 Jul 2009 17:11:00 +0000 (19:11 +0200)
committerAnicka Bernathova <anicka@anicka.net>
Tue, 21 Jul 2009 17:11:00 +0000 (19:11 +0200)
code.c
cond.y
int.c

diff --git a/code.c b/code.c
index 932bb9ab5d8766c3a43f508a43b5add5b27825ab..170fd3a9f686afcbde584880f83004cd69929aa4 100644 (file)
--- a/code.c
+++ b/code.c
@@ -272,10 +272,10 @@ do_if(struct tree *t, struct list* where)
 
        compile(t->pt.tif.i, if_branch);        
        compile(t->pt.tif.i, else_branch);      
-       new_instr(nop, if_branch);
        new_instr(nop, else_branch);
        jmp.u.jump.target = list_last(else_branch);
        new_instr(jmp, if_branch);
+       new_instr(nop, if_branch);
        
        ins.opcode = OPC_JUMP_UNLESS;
        ins.u.jump_unless.cond = c;
@@ -372,12 +372,39 @@ compile(struct tree* t, struct list* where)
        }
 }
 
+static char *
+lookup_var_name(int id)
+{
+       int h;
+
+       for (h=0; h<HASHSIZE; h++) {
+               struct variable *p;
+               LIST_FOREACH(p, var_hash + h)
+                       if (p->varcode == id)
+                               return p->name;
+       }
+       return "";
+}
+
 void
 print_code(void)
 {
        struct code* p;
+       int i;
+
+       printf("Known constants:\n");
+       for (i=1; i<cur_const_n; i++)
+               printf("-%d\t\"%s\"\n", i, const_tab[i]);
+       printf("\n");
+
+       printf("Known variables:\n");
+       // This is grossly inefficient...
+       for (i=0; i<temp_varcode_start; i++)
+               printf("%d\t%s\n", i, lookup_var_name(i));
+       printf("\n");
 
        LIST_FOREACH(p, &input_code) {
+               printf("%p: ", p);
                switch (p->opcode) {
                        case OPC_SET:
                                printf("SET %d %d\n", p->u.set.l, p->u.set.r);
@@ -387,10 +414,10 @@ print_code(void)
                                p->u.tpop.r, p->u.tpop.res);
                                break;
                        case OPC_JUMP:
-                               printf("JUMP %d\n", (int) p->u.jump.target);
+                               printf("JUMP %p\n", p->u.jump.target);
                                break;
                        case OPC_JUMP_UNLESS:
-                               printf("JUMP_UNLESS %d %d\n", p->u.jump_unless.cond,(int) p->u.jump_unless.target);
+                               printf("JUMP_UNLESS %d %p\n", p->u.jump_unless.cond, p->u.jump_unless.target);
                                break;
                        case OPC_GT:
                                printf("GT %d %d %d\n", p->u.tpop.l, p->u.tpop.r, p->u.tpop.res);
@@ -441,7 +468,7 @@ print_code(void)
                                printf("NOT %d %d\n", p->u.dpop.par, p->u.dpop.res);
                                break;
                        case OPC_NOP:
-                               puts("NOP");    
+                               printf("NOP\n");
                                break;
                        case OPC_PIPE:
                                printf("PIPE %d %d\n", p->u.arrow.what, p->u.arrow.copy);
diff --git a/cond.y b/cond.y
index 5e2cf400a2fe4bef664f82a0aea549a1153928de..e1390f83d2580e8eeb63cbc897f9137a41e08b74 100644 (file)
--- a/cond.y
+++ b/cond.y
@@ -75,7 +75,8 @@ command:       ';' { $$ = tree_malloc(ST_EMPTY); }
 ;
 
 next:  /* empty */ {$$ = tree_malloc(ST_EMPTY); }
-       | command
+       | input 
+       
        
 
 ;
diff --git a/int.c b/int.c
index d2146d754c042ffedab8b25fa234ce2677688365..60c40d502356c74e94a0080dda1ba1a46c3c42f5 100644 (file)
--- a/int.c
+++ b/int.c
@@ -75,7 +75,7 @@ set_cur_mail_length_var(int len, struct list* hash)
                return;
 
        buf = xmalloc(INT_TO_STRING_LEN);
-       sscanf(buf,"%d", &len);
+       sprintf(buf,"%d", len);
        set_var(pv->varcode, buf);
        free_string(buf);
 }
@@ -92,7 +92,7 @@ set_exit_code_var(int code, struct list* hash)
                return;
 
        buf = xmalloc(INT_TO_STRING_LEN);
-       sscanf(buf,"%d", &code);
+       sprintf(buf,"%d", code);
        set_var(pv->varcode, buf);
        free_string(buf);
 }
@@ -607,7 +607,7 @@ fix_content_length(struct list* h, int len)
                        found = 1;
                        free_string(ph->value);
                        ph->value = xmalloc(INT_TO_STRING_LEN);
-                       sscanf(ph->value, "%d", &len);
+                       sprintf(ph->value, "%d", len);
                        break;
                }
        }
@@ -615,7 +615,8 @@ fix_content_length(struct list* h, int len)
                char* buf, * tmpbuf;
                buf = xmalloc(INT_TO_STRING_LEN + strlen(clheader));
                tmpbuf = xmalloc(INT_TO_STRING_LEN);
-               sscanf(tmpbuf, "%d", &len);
+               sprintf(tmpbuf, "%d", len);
+               strcpy(buf, clheader);
                strcat(buf, tmpbuf);
                new_header(buf, h);
                free_string(buf); 
@@ -692,7 +693,9 @@ interp(struct list* ins, struct list* hash)
        LIST_FOREACH(p, ins) {
        switch (p->opcode) {
                case OPC_SET:
-                       set_var(p->u.set.l, get_var(p->u.set.r));
+                       result = get_var(p->u.set.r);
+                       set_var(p->u.set.l, result);
+                       free_string(result);
                        break;  
                case OPC_JUMP:
                        p = p->u.jump.target;
@@ -728,9 +731,11 @@ interp(struct list* ins, struct list* hash)
                        break;
                case OPC_NOT:
                        result = xmalloc(INT_TO_STRING_LEN);
-                       sscanf(get_var(p->u.tpop.l),"%d", &v);
+                       sscanf(get_var(p->u.dpop.par),"%d", &v);
                        sprintf(result, "%d", !v);
-                       set_var(p->u.tpop.res, result);
+                       set_var(p->u.dpop.res, result);
+                       free_string(result);
+                       break;
                case OPC_CAT:
                case OPC_RE:
                case OPC_NRE: