Annotation of researchv10no/cmd/adb/cray/hksyminit.c, revision 1.1

1.1     ! root        1: /*
        !             2:  * set up the symbol table
        !             3:  * very cheap hack version for cray:
        !             4:  * read the loader map
        !             5:  */
        !             6: 
        !             7: #include "defs.h"
        !             8: #include "sym.h"
        !             9: #include <stdio.h>
        !            10: #include "machine.h"
        !            11: 
        !            12: #define        NMFMT   "%s %lo%c"      /* name value (junk) */
        !            13: 
        !            14: #define        NSYMS   20
        !            15: 
        !            16: static lcopy();
        !            17: 
        !            18: /*
        !            19:  * `fn' is the name of the a.out file.
        !            20:  * if it was a valid a.out, look for a map in `fn'.map
        !            21:  * else see if fn itself is a map
        !            22:  */
        !            23: 
        !            24: hksyminit(fn, isexec)
        !            25: char *fn;
        !            26: int isexec;
        !            27: {
        !            28:        FILE *fp;
        !            29:        register struct sym *p;
        !            30:        struct sym *syms;
        !            31:        char buf[ARB];
        !            32:        long val;
        !            33:        char flag;
        !            34:        char name[ARB];
        !            35:        int inmap = 0;
        !            36:        char *malloc();
        !            37: 
        !            38:        symtab = NULL;
        !            39:        strcpy(name, fn);
        !            40:        if (isexec)
        !            41:                strcat(name, ".map");
        !            42:        if ((fp = fopen(name, "r")) == NULL)
        !            43:                return;
        !            44:        if (fgets(buf, ARB, fp) == NULL
        !            45:        ||  (buf[0] != '1' || buf[2] != ' ')) {
        !            46:                fclose(fp);
        !            47:                return;         /* probably not a loader map */
        !            48:        }
        !            49:        syms = NULL;
        !            50:        while (fgets(buf, ARB, fp)) {
        !            51:                if (inmap == 0) {
        !            52:                        if (maphdr(buf) == 0)
        !            53:                                continue;
        !            54:                        inmap++;
        !            55:                }
        !            56:                if (sscanf(buf, NMFMT, name, &val, &flag) != 3)
        !            57:                        continue;
        !            58:                if (!isalpha(name[0]))
        !            59:                        continue;
        !            60:                if (syms == NULL || p >= syms + NSYMS) {
        !            61:                        if ((syms = (struct sym *)malloc(NSYMS * sizeof(struct sym))) == NULL) {
        !            62:                                printf("out of mem for syms");
        !            63:                                break;
        !            64:                        }
        !            65:                        p = syms;
        !            66:                }
        !            67:                if ((p->y_name = malloc(strlen(name) + 1)) == NULL) {
        !            68:                        printf("out of mem for syms");
        !            69:                        break;
        !            70:                }
        !            71:                lcopy(p->y_name, name);
        !            72:                p->y_value = watoba(val);
        !            73:                if (flag == ' ')
        !            74:                        p->y_type = S_DATA;
        !            75:                else
        !            76:                        p->y_type = S_TEXT;     /* parcel addr */
        !            77:                p->y_next = symtab;
        !            78:                symtab = p;
        !            79:                p++;
        !            80:        }
        !            81:        fclose(fp);
        !            82: }
        !            83: 
        !            84: /*
        !            85:  * look for the beginning of the interesting part
        !            86:  * this is just to cut down on specious syms
        !            87:  */
        !            88: 
        !            89: maphdr(s)
        !            90: register char *s;
        !            91: {
        !            92: 
        !            93:        while (*s == ' ')
        !            94:                s++;
        !            95:        return (strncmp(s, "ENTRY POINT CROSS-", 18) == 0);
        !            96: }
        !            97: 
        !            98: static
        !            99: lcopy(s, t)
        !           100: register char *s, *t;
        !           101: {
        !           102: 
        !           103:        while (*t) {
        !           104:                if (*t == '$') {
        !           105:                        *s++ = '_';
        !           106:                        t++;
        !           107:                }
        !           108:                else
        !           109:                        *s++ = *t++;
        !           110:        }
        !           111:        *s = 0;
        !           112: }
        !           113: 
        !           114: /*
        !           115:  * compare sym entry name with one the user typed
        !           116:  */
        !           117: eqsym(sp, n)
        !           118: struct sym *sp;
        !           119: char *n;
        !           120: {
        !           121: 
        !           122:        return (strncmp(sp->y_name, n, 8) == 0);
        !           123: }

unix.superglobalmegacorp.com

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