1: /*
   2:  * Copyright (C) 1984 by Eric C. Cooper.
   3:  * All rights reserved.
   4:  */
   5: #ifndef lint
   6: static char RCSid[] = "$Header: symbols.c,v 2.0 85/11/21 07:21:46 jqj Exp $";
   7: #endif
   8: 
   9: /* $Log:	symbols.c,v $
  10:  * Revision 2.0  85/11/21  07:21:46  jqj
  11:  * 4.3BSD standard release
  12:  *
  13:  * Revision 1.4  85/03/26  06:10:36  jqj
  14:  * *** empty log message ***
  15:  *
  16:  * Revision 1.4  85/03/26  06:10:36  jqj
  17:  * Revised public alpha-test version, released 26 March 1985
  18:  *
  19:  * Revision 1.3  85/03/11  16:40:14  jqj
  20:  * Public alpha-test version, released 11 March 1985
  21:  *
  22:  * Revision 1.2  85/02/21  11:06:00  jqj
  23:  * alpha test version
  24:  *
  25:  * Revision 1.1  85/02/15  13:55:40  jqj
  26:  * Initial revision
  27:  *
  28:  */
  29: 
  30: /*
  31:  * Symbol table management routines
  32:  */
  33: 
  34: #include "compiler.h"
  35: 
  36: struct object *SymbolTables;
  37: struct object EnumSymbols;
  38: /*
  39: 
  40:  * Symbol table management.  Find a symbol given a known symbol table.
  41:  * The routines lookup() and addsymbol() are the ONLY routines that
  42:  * understand the format of the symbol table, and should be the only
  43:  * routines that use ocar() and ocdr().
  44:  */
  45: static struct object *
  46: lookup(name, symlist)
  47:     char *name;
  48:     struct object *symlist;
  49: {
  50:     struct object *op;
  51: 
  52:     for (op = symlist; op != ONIL; op = ocdr(op)) {
  53:         if (streq(op->o_name, name))
  54:             return (op);
  55:     }
  56:     return (ONIL);
  57: }
  58: 
  59: static struct object *
  60: addsymbol(name,osymp)
  61:     char *name;
  62:     struct object **osymp;
  63: {
  64:     struct object *o;
  65: 
  66:     o = New(struct object);
  67:     o->o_class = O_UNKNOWN;
  68:     /* (jqj)? use binary-tree symboltable here */
  69:     ocdr(o) = *osymp;
  70:     *osymp = o;
  71:     o->o_name = copy(name);
  72:     return(o);
  73: }
  74: 
  75: struct object *
  76: make_symbol(name,symboltablename)
  77:     char *name;
  78:     char *symboltablename;
  79: {
  80:     struct object *osym, *rsym;
  81: 
  82:     if (symboltablename == NULL) {
  83:         rsym = addsymbol(name, &(EnumSymbols.o_symboltable));
  84:         rsym->o_module = "";    /* not NULL */
  85:         rsym->o_modnumber = 0;
  86:         rsym->o_modversion = 0;
  87:         return(rsym);
  88:     }
  89:     else if ((osym = lookup(symboltablename, SymbolTables))) {
  90:         rsym = addsymbol(name, &(osym->o_symboltable));
  91:         rsym->o_module = osym->o_module;
  92:         rsym->o_modnumber = osym->o_modnumber;
  93:         rsym->o_modversion = osym->o_modversion;
  94:         return(rsym);
  95:     }
  96:     else {
  97:         error(ERROR,"Internal error:  Symbol table %s undefined.",
  98:             symboltablename);
  99:         return(ONIL);
 100:     }
 101: }
 102: 
 103: struct object *
 104: make_module(name,number,version)
 105:     char *name;     /* Courier module name */
 106:     char *number;       /* Courier program number */
 107:     char *version;
 108: {
 109:     struct object *symbol;
 110: 
 111:     symbol = addsymbol(name, &SymbolTables);
 112:     symbol->o_class = O_SYMBOLTABLE;
 113:     symbol->o_name = name;
 114:     symbol->o_module = name;
 115:     symbol->o_modnumber = stringtocard(number);
 116:     symbol->o_modversion = stringtocard(version);
 117:     return(symbol);
 118: }
 119: 
 120: /*
 121:  * Check that a program name, number, version group is already defined.
 122:  * Returns TRUE if name, number, and version all match
 123:  */
 124:  check_module_def(name,number,version)
 125:     char *name, *number, *version;
 126: {
 127:     struct object *module;
 128: 
 129:     if ((module = lookup(name, SymbolTables)) == (struct object *) NULL)
 130:         return(0);
 131:     if (stringtocard(version) != module->o_modversion ||
 132:         stringtocard(number) != module->o_modnumber)
 133:         return(0);
 134:     return(1);  /* for now */
 135: }
 136: 
 137: /*
 138:  * Check that a program name was listed in the DEPENDS UPON list.
 139:  * returns a pointer to the symbol if defined, else 0.
 140:  */
 141: check_dependency(name)
 142:     char *name;
 143: {
 144:     return((int) lookup(name, SymbolTables));
 145: }
 146: 
 147: /* (jqj) */
 148: struct object *
 149: check_def(symbol,symboltablename)
 150:     char *symbol;       /* name of the symbol */
 151:     char *symboltablename;  /* symbol table to examine */
 152: {
 153:     struct object *osym;
 154: 
 155:     if (symboltablename == NULL) {
 156:         osym = &EnumSymbols;
 157:     }
 158:     else if (! (osym = lookup(symboltablename, SymbolTables))) {
 159:         error(ERROR,"Internal error:  Symbol table %s undefined.",symboltablename);
 160:         return(ONIL);
 161:     }
 162:     return(lookup(symbol, osym->o_symboltable));
 163: }
 164: 
 165: 
 166: static char gensymstr[MAXSTR];
 167: 
 168: char *
 169: gensym(leader)
 170:     char *leader;
 171: {
 172:     static int n;
 173:     char buf[MAXSTR];
 174: 
 175:     (void) sprintf(buf, "%s%s_%d", leader, gensymstr, ++n);
 176:     return (copy(buf));
 177: }
 178: 
 179: setgensym(number,version)
 180:     char *number, *version;
 181: {
 182:     (void) sprintf(gensymstr,"%s",number);
 183: }
 184: 
 185: define_enumeration_symbol(sym, value)
 186:     struct object *sym;
 187:     char *value;
 188: {
 189:     class_of(sym) = O_ENUMTAG;
 190:     sym->o_enum = New(struct enumtag);
 191:     sym->o_enum->en_name = name_of(sym);
 192:     sym->o_enum->en_value = stringtocard(value);
 193: }

Defined functions

addsymbol defined in line 59; used 3 times
check_module_def defined in line 124; used 1 times
lookup defined in line 45; used 5 times
setgensym defined in line 179; used 1 times

Defined variables

EnumSymbols defined in line 37; used 2 times
RCSid defined in line 6; never used
SymbolTables defined in line 36; used 5 times
gensymstr defined in line 166; used 2 times
Last modified: 1986-03-13
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 1051
Valid CSS Valid XHTML 1.0 Strict