Annotation of researchv10no/cmd/hoc/symbol.c, revision 1.1.1.1

1.1       root        1: #include "hoc.h"
                      2: #include "y.tab.h"
                      3: 
                      4: static Symbol *symlist = 0;  /* symbol table: linked list */
                      5: 
                      6: Symbol *lookup(s)      /* find s in symbol table */
                      7:        char *s;
                      8: {
                      9:        Symbol *sp;
                     10: 
                     11:        for (sp = symlist; sp != (Symbol *) 0; sp = sp->next)
                     12:                if (strcmp(sp->name, s) == 0)
                     13:                        return sp;
                     14:        return 0;       /* 0 ==> not found */   
                     15: }
                     16: 
                     17: Symbol *install(s, t, d)  /* install s in symbol table */
                     18:        char *s;
                     19:        int t;
                     20:        double d;
                     21: {
                     22:        Symbol *sp;
                     23:        char *emalloc();
                     24: 
                     25:        sp = (Symbol *) emalloc(sizeof(Symbol));
                     26:        sp->name = emalloc(strlen(s)+1); /* +1 for '\0' */
                     27:        strcpy(sp->name, s);
                     28:        sp->type = t;
                     29:        sp->u.val = d;
                     30:        sp->next = symlist; /* put at front of list */
                     31:        symlist = sp;
                     32:        return sp;
                     33: }
                     34: 
                     35: char *emalloc(n)       /* check return from malloc */
                     36:        unsigned n;
                     37: {
                     38:        char *p, *malloc();
                     39: 
                     40:        p = malloc(n);
                     41:        if (p == 0)
                     42:                execerror("out of memory", (char *) 0);
                     43:        return p;
                     44: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.