Annotation of 43BSD/contrib/icon/link/glob.c, revision 1.1

1.1     ! root        1: /*
        !             2:  * Routines for processing .u2 files.
        !             3:  */
        !             4: 
        !             5: #include "ilink.h"
        !             6: #include "opcode.h"
        !             7: 
        !             8: int trace = 0;                 /* initial setting of &trace */
        !             9: int nrecords = 0;              /* number of records in program */
        !            10: 
        !            11: /*
        !            12:  * globals reads the global information from infile (.u2) and merges it with
        !            13:  *  the global table and record table.
        !            14:  */
        !            15: globals(i)
        !            16: int i;
        !            17:    {
        !            18:    register char *id;
        !            19:    register int n, op;
        !            20:    int k;
        !            21:    int implicit;
        !            22:    char *name;
        !            23:    struct gentry *gp, *glocate();
        !            24:    extern char *getid(), *getstr();
        !            25:    extern struct gentry *putglob();
        !            26: 
        !            27:    while ((op = getop(&name)) != EOF) {
        !            28:       switch (op) {
        !            29:          case OP_RECORD:       /* a record declaration */
        !            30:             id = getid();      /* record name */
        !            31:             n = getdec();      /* number of fields */
        !            32:             newline();
        !            33:             gp = glocate(id);
        !            34:             /*
        !            35:              * It's ok if the name isn't already in use or if the
        !            36:              *  name is just used in a "global" declaration.  Otherwise,
        !            37:              *  it is an inconsistent redeclaration.
        !            38:              */
        !            39:             if (gp == NULL || (gp->g_flag & ~F_GLOBAL) == 0) {
        !            40:                putglob(id, F_RECORD, n, ++nrecords);
        !            41:                while (n--) {   /* loop reading field numbers and names */
        !            42:                   k = getdec();
        !            43:                   putfield(getid(), nrecords, k);
        !            44:                   newline();
        !            45:                   }
        !            46:                }
        !            47:             else {
        !            48:                err(id, "inconsistent redeclaration", 0);
        !            49:                while (n--)
        !            50:                   newline();
        !            51:                }
        !            52:             break;
        !            53: 
        !            54:          case OP_IMPL:         /* undeclared identifiers should be noted */
        !            55:             if (getop(&name) == OP_LOCAL)
        !            56:                implicit = 0;
        !            57:             else
        !            58:                implicit = F_IMPERROR;
        !            59:             break;
        !            60: 
        !            61:          case OP_TRACE:                /* turn on tracing */
        !            62:             trace = -1;
        !            63:             break;
        !            64: 
        !            65:          case OP_GLOBAL:       /* global variable declarations */
        !            66:             n = getdec();      /* number of global declarations */
        !            67:             newline();
        !            68:             while (n--) {      /* process each declaration */
        !            69:                getdec();       /* throw away sequence number */
        !            70:                k = getoct();   /* get flags */
        !            71:                if (k & (F_PROC & ~F_GLOBAL))
        !            72:                   k |= implicit;
        !            73:                id = getid();   /* get variable name */
        !            74:                gp = glocate(id);
        !            75:                /*
        !            76:                 * Check for conflicting declarations and install the
        !            77:                 *  variable.
        !            78:                 */
        !            79:                if (gp != NULL &&
        !            80:                    (k & (F_PROC & ~F_GLOBAL)) && gp->g_flag != F_GLOBAL)
        !            81:                   err(id, "inconsistent redeclaration", 0);
        !            82:                else if (gp == NULL || (k & (F_PROC & ~F_GLOBAL)))
        !            83:                   putglob(id, k, getdec(), 0);
        !            84:                newline();
        !            85:                }
        !            86:             break;
        !            87: 
        !            88:          case OP_LINK:         /* link the named file */
        !            89:             name = getstr();   /* get the name and */
        !            90:             addlfile(name);    /*  put it on the list of files to link */
        !            91:             newline();
        !            92:             break;
        !            93: 
        !            94:          default:
        !            95:             fprintf(stderr, "%s: ill-formed global file %s\n", pname, inname);
        !            96:             exit(1);
        !            97:          }
        !            98:       }
        !            99:    }

unix.superglobalmegacorp.com

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