Annotation of researchv10no/cmd/adb/v7/gensyminit.c, revision 1.1

1.1     ! root        1: /*
        !             2:  * set up the symbol table
        !             3:  * cheap hack version: let nm do the work
        !             4:  */
        !             5: 
        !             6: #include "defs.h"
        !             7: #include <a.out.h>
        !             8: #include "sym.h"
        !             9: #include <stdio.h>
        !            10: 
        !            11: #define        NMCMD   "PATH=/bin:/usr/bin: nm -p %s"
        !            12: #define        NMFMT   "%lx %s %s"     /* value type name */
        !            13: 
        !            14: #define        NSYMS   20
        !            15: 
        !            16: extern char *symfil;
        !            17: 
        !            18: syminit(h)
        !            19: struct exec *h;
        !            20: {
        !            21:        FILE *fp;
        !            22:        register struct sym *p;
        !            23:        struct sym *syms;
        !            24:        char buf[ARB];
        !            25:        long val;
        !            26:        char type[10];
        !            27:        char name[ARB];
        !            28:        char *malloc();
        !            29:        FILE *popen();
        !            30: 
        !            31:        symtab = NULL;
        !            32:        if (h->a_syms == 0)
        !            33:                return;         /* stripped */
        !            34:        syms = NULL;
        !            35:        sprintf(buf, NMCMD, symfil);
        !            36:        if ((fp = popen(buf, "r")) == NULL)
        !            37:                return;
        !            38:        while (fgets(buf, ARB, fp)) {
        !            39:                if (sscanf(buf, NMFMT, &val, type, name) != 3)
        !            40:                        continue;
        !            41:                if (type[0] != 'A' && type[0] != 'D' && type[0] != 'B' && type[0] != 'T')
        !            42:                        continue;
        !            43:                if (syms == NULL || p >= syms + NSYMS) {
        !            44:                        if ((syms = (struct sym *)malloc(NSYMS * sizeof(struct sym))) == NULL) {
        !            45:                                printf("out of mem for syms");
        !            46:                                break;
        !            47:                        }
        !            48:                        p = syms;
        !            49:                }
        !            50:                if ((p->y_name = malloc(strlen(name) + 1)) == NULL) {
        !            51:                        printf("out of mem for syms");
        !            52:                        break;
        !            53:                }
        !            54:                strcpy(p->y_name, name);
        !            55:                p->y_value = val;
        !            56:                switch (type[0]) {
        !            57:                case 'A':
        !            58:                        p->y_type = S_ABS;
        !            59:                        break;
        !            60: 
        !            61:                case 'B':
        !            62:                case 'D':
        !            63:                        p->y_type = S_DATA;
        !            64:                        break;
        !            65: 
        !            66: 
        !            67:                case 'T':
        !            68:                        p->y_type = S_TEXT;
        !            69:                        break;
        !            70:                }
        !            71:                p->y_next = symtab;
        !            72:                symtab = p;
        !            73:                p++;
        !            74:        }
        !            75:        while (fgets(buf, ARB, fp))
        !            76:                ;
        !            77:        pclose(fp);
        !            78: }
        !            79: 
        !            80: /*
        !            81:  * is symbol table entry s == name n?
        !            82:  * this may depend on awful symbol conventions
        !            83:  * e.g. _
        !            84:  */
        !            85: int
        !            86: eqsym(s, n)
        !            87: register struct sym *s;
        !            88: char *n;
        !            89: {
        !            90: 
        !            91:        if (strcmp(s->y_name, n) == 0)
        !            92:                return (1);
        !            93:        if (s->y_name[0] == '_' && strcmp(&s->y_name[1], n) == 0)
        !            94:                return (1);
        !            95:        return (0);
        !            96: }

unix.superglobalmegacorp.com

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