|
|
1.1 ! root 1: /* Copyright Bell Telephone Laboratories Whippany, N.J. ! 2: ! 3: * ///////////////////////////////////// ! 4: * ///////////////////////////////////// ! 5: * ////////////// svars.c ////////////// ! 6: * /// J. P. Hawkins WH X4610 8C-001 /// ! 7: * ///// Sat Jan 31 14:59:54 1981 ////// ! 8: * ///////////////////////////////////// ! 9: * ///////////////////////////////////// ! 10: ! 11: * ! 12: * String variable Allocation and Fetch routines ! 13: * For BITE ! 14: * ! 15: */ ! 16: /* "@(#) svars.c: V 1.1 2/4/81" */ ! 17: ! 18: #include "bas.h" ! 19: /* ! 20: * this is the symbol table (table of pointers) for string ! 21: * variables. The first subscript 'j' is calculated by the ! 22: * alpha name, the second subscript 'k' is calculated by the ! 23: * numeric part + 1. If no numeric is specified, k = 0 ! 24: */ ! 25: char * ssymtab[26][11]; ! 26: extern char *hicore; /* pointer lowest used corespace from ! 27: top of user area */ ! 28: ! 29: ! 30: /* ! 31: * //////// FETCH VALUE OF VARIABLE //////// ! 32: * ! 33: * calling format: ! 34: * ! 35: * sgetvar(sname, &sptr); ! 36: * ! 37: * where: sname = string containing VALID variable name ! 38: * i.e. [a-z] or a[0-9] - z[0-9] ! 39: * sptr = pointer to string ! 40: */ ! 41: sgetvar(sname,sptr) ! 42: char sname[]; ! 43: char **sptr; /* pointer to string pointer */ ! 44: { ! 45: int j,k; /* symbol table indicies */ ! 46: ! 47: j = sname[0] - 'a'; /* compute j subscript */ ! 48: ! 49: /* ! 50: * compute k subscript ! 51: */ ! 52: if(sname[1] == '\0') /* if no numeric part */ ! 53: k = 0; /* then k = 0th column */ ! 54: else ! 55: k = sname[1] - '0' + 1; /* use numeric + 1th column */ ! 56: ! 57: if(ssymtab[j][k] == 0) /*if no pointer for this variable */ ! 58: /* (not allocated, yet) */ ! 59: { ! 60: error2(inst.thing.linno,7,' '); /* UNASSIGNED VARIABLE */ ! 61: printf("- '%s$'\n",sname); /* print variable name */ ! 62: *sptr = 0; /* return zero anyway */ ! 63: return(-1); ! 64: } ! 65: else ! 66: { ! 67: *sptr = ssymtab[j][k]; /* set ptr to data location */ ! 68: *sptr += 1; /* bump past size byte */ ! 69: } ! 70: return(0); ! 71: } ! 72: /* ! 73: * ! 74: * //// ASSIGN A VALUE TO A VARIABLE //// ! 75: * /////////// ALLOCATE SPACE ////////// ! 76: * ! 77: * Copy the string into the allocated location. ! 78: * ! 79: * calling format: ! 80: * ! 81: * sputvar(sname, sptr); ! 82: * ! 83: * where: sname = string pointer to VALID variable name ! 84: * sptr = pointer to string to be copied ! 85: */ ! 86: sputvar(sname,sptr) ! 87: char sname[]; /* valid variable string (name) */ ! 88: char *sptr; /* pointer to string */ ! 89: { ! 90: register char *ptr,*cptr; /* pointer used for string copy to mem */ ! 91: int ssize; /* string size */ ! 92: int useagain; /* flag to use space again */ ! 93: int j,k; /* symbol table indicies */ ! 94: ! 95: useagain = 0; ! 96: cptr = sptr; /* get source string pointer */ ! 97: j = sname[0] - 'a'; /* compute j subscript */ ! 98: ! 99: /* ! 100: * compute k subscript ! 101: */ ! 102: if(sname[1] == '\0') /* if no numeric part */ ! 103: k = 0; /* then k = 0th column */ ! 104: else ! 105: k = sname[1] - '0' + 1; ! 106: ! 107: ssize = strlen(sptr); /* get size of string */ ! 108: if(ssymtab[j][k] != 0) /* if this variable was used before */ ! 109: { ! 110: ptr = ssymtab[j][k]; /* point to old space */ ! 111: if(ssize <= *ptr) /* if there's enough room */ ! 112: { ! 113: useagain = 1; /* use same space */ ! 114: ptr++; /* bump past size */ ! 115: } ! 116: } ! 117: if(!useagain) /* if this is the first time this var was used */ ! 118: { ! 119: /* ! 120: * Return error if not enough space left ! 121: */ ! 122: if((hicore - (ssize+2)) <= linptr) ! 123: { ! 124: error(inst.thing.linno, 24); /* NOT ENOUGH ADD. CORE */ ! 125: return(-1); ! 126: } ! 127: hicore -= (ssize+2); /* set new hicore mark - */ ! 128: /* include space for null and size */ ! 129: ptr = hicore; /* set pointer for copy */ ! 130: *ptr = ssize; /* put size of 1st string in 1st loc */ ! 131: ssymtab[j][k] = ptr; /* put pointer in sym. table */ ! 132: ! 133: if((unsigned)hicore & 1) /* hicore to even boundry */ ! 134: hicore--; ! 135: ptr++; /* bump past size */ ! 136: } ! 137: ! 138: while(*ptr++ = *cptr++); /* copy string into storage */ ! 139: ! 140: return(0); ! 141: } ! 142: #ifdef notdef ! 143: /* ! 144: * Return size of string up to first null character ! 145: */ ! 146: static strlen(s) ! 147: char *s; ! 148: { ! 149: register count; ! 150: for(count = 0; s[count]; count++); ! 151: return(count); ! 152: } ! 153: #endif
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.