1: static  char sccsid[] = "@(#)sub.c 4.2 8/17/82";
   2: #include "head.h"
   3: #include <a.out.h>
   4: #include <stab.h>
   5: #include "cdefs.h"
   6: #include <stdio.h>
   7: struct user u;
   8: 
   9: char *
  10: readline(f)
  11: FILE *f; {
  12:     static char buff[128];
  13: 
  14:     register char *p;
  15:     register int i;
  16: 
  17:     p = buff;
  18:     do {
  19:         if ((i = getc(f)) == EOF) {
  20:             *p++ = '\004';
  21:             *p = '\n';
  22:         }
  23:         else *p = i;
  24:     } while (*p++ != '\n');
  25: 
  26:     return(buff);
  27: }
  28: 
  29: char *
  30: cpname(p, q)
  31: char *p, *q; {
  32:     while(varchar(*q) || number(*q))
  33:         *p++ = *q++;
  34:     *p = '\0';
  35:     return(q);
  36: }
  37: 
  38: char *
  39: cpall(p, q)
  40: char *p, *q; {
  41:     while (*q != '\n')
  42:         *p++ = *q++;
  43:     *p = '\0';
  44:     return(q);
  45: }
  46: 
  47: eqany(c, s)
  48: char c, *s; {
  49:     while(*s != '\0')
  50:         if (c == *s++) return(1);
  51:     return(0);
  52: }
  53: 
  54: error(s)
  55: char *s; {
  56:     printf("%s\n", s);
  57: }
  58: 
  59: char *
  60: cpstr(p,q)
  61: char *p, *q; {
  62:     do {
  63:         *p++ = *q++;
  64:     } while (*q != '\0');
  65:     *p = '\0';
  66: }
  67: L_INT
  68: round(a,b)
  69: REG L_INT a, b;
  70: {
  71:     REG L_INT w;
  72:     w = (a/b)*b;
  73:     IF a!=w THEN w += b; FI
  74:     return(w);
  75: }
  76: 
  77: /* error handling */
  78: 
  79: chkerr()
  80: {
  81:     IF errflg ORF mkfault
  82:     THEN    error(errflg);
  83:         longjmp(env, 0);
  84:     FI
  85: }
  86: 
  87: eqstr(s1, s2)
  88:     REG STRING  s1, s2;
  89: {
  90: #ifndef FLEXNAMES
  91:     REG STRING   es1;
  92: #endif
  93:     if (s2 == (STRING) -1) return(0);
  94: #ifndef FLEXNAMES
  95:     es1 = s1+8;
  96: #endif
  97:     WHILE *s1++ == *s2
  98: #ifndef FLEXNAMES
  99:     DO IF *s2++ == 0 ORF s1>=es1
 100: #else
 101:     DO IF *s2++ == 0
 102: #endif
 103:        THEN return(1);
 104:        FI
 105:     OD
 106:     return(0);
 107: }
 108: 
 109: longseek(f, a)
 110: L_INT a;
 111: {
 112:     return(lseek(f,(long) a,0) != -1);
 113: }
 114: 
 115: 
 116: /* descriptor format to length */
 117: dtol(d)
 118: char d; {
 119:     switch(d) {
 120: 
 121:     case 'a':
 122:     case 's':
 123:         return(0);
 124: 
 125:     case 'b':
 126:     case 'c':
 127:         return(1);
 128: 
 129:     case 'h':
 130:         return(2);
 131: 
 132:     case 'l':
 133:     case 'f':
 134:         return(4);
 135: 
 136:     case 'g':
 137:         return(8);
 138: 
 139:     default:
 140:         return(WORDSIZE);
 141:     }
 142: }
 143: 
 144: /*
 145:  * checks equality of pattern pat with str,
 146:  * assuming str is tructaed at length 8
 147:  */
 148: eqpat(pat, str)
 149: char *pat, *str; {
 150: #ifndef FLEXNAMES
 151:     return(eqpatr(pat, str, 0));
 152: #else
 153:     return(eqpatr(pat, str));
 154: #endif
 155: }
 156: 
 157: #ifndef FLEXNAMES
 158: eqpatr(pat, str, cnt)
 159: #else
 160: eqpatr(pat, str)
 161: #endif
 162: char *pat, *str; {
 163:     register int i;
 164:     register char p, s;
 165: 
 166:     p = pat[0];
 167:     s = str[0];
 168: #ifndef FLEXNAMES
 169:     if (cnt == 8) return(1);
 170: #endif
 171:     if (p == '?') {
 172:         if (s == '\0') return(0);
 173: #ifndef FLEXNAMES
 174:         return(eqpatr(pat+1, str+1, cnt+1));
 175: #else
 176:         return(eqpatr(pat+1, str+1));
 177: #endif
 178:     }
 179:     if (p == '*') {
 180:         if (pat[1] == '\0') return(1);
 181: #ifndef FLEXNAMES
 182:         for(i=1; i<8-cnt; i++) {
 183:             if (eqpatr(pat+1, str+i, cnt+i)) return(1);
 184: #else
 185:         for(i=1; ; i++) {
 186:             if (eqpatr(pat+1, str+i)) return(1);
 187: #endif
 188:             if (str[i] == '\0') return(0);
 189:         }
 190: #ifndef FLEXNAMES
 191:         return(0);
 192: #else
 193:         /*NOTREACHED*/
 194: #endif
 195:     }
 196:     if ((eqany(p, ".[->") || p == '\0') && s == '\0') return(1);
 197:     if (p != s) return(0);
 198: #ifndef FLEXNAMES
 199:     return(eqpatr(pat+1, str+1, cnt+1));
 200: #else
 201:     return(eqpatr(pat+1, str+1));
 202: #endif
 203: }
 204: 
 205: /* gets indirect address for pointers and subscripts */
 206: getindir(class, addr, type)
 207: u_char class;
 208: ADDR addr; {
 209:     if (ISARY(type)) return(addr);
 210:     if (class == N_RSYM)
 211:         return(*(ADDR *)(((ADDR) &u) + R0 + (WORDSIZE)*addr));
 212:     return(getval(addr, 'd', DSP));
 213: }
 214: 
 215: long
 216: readint(p)
 217: char **p; {
 218:     int sign;
 219: 
 220:     if (**p == '-') {
 221:         sign = -1;
 222:         (*p)++;
 223:     } else {
 224:         sign = 1;
 225:     }
 226:     if (**p == '0') {
 227:         (*p)++;
 228:         if (**p == 'x' || **p == 'X') {
 229:             (*p)++;
 230:             return(sign * rint(p, 16, hexdigit, hexconv));
 231:         }
 232:         else return(sign * rint(p, 8, octdigit, octconv));
 233:     }
 234:     else return(sign * rint(p, 10, decdigit, decconv));
 235: }
 236: 
 237: long
 238: rint(p, base, digit, conv)
 239: char **p;
 240: int (*digit)(), (*conv)(); {
 241:     long value;
 242: 
 243:     value = 0;
 244:     while ((*digit)(**p)) value = base*value + (*conv)(*(*p)++);
 245:     return(value);
 246: }
 247: 
 248: octdigit(c)
 249: char c; {
 250:     return(c >= '0' && c <= '7');
 251: }
 252: 
 253: octconv(c)
 254: char c; {
 255:     return(c - '0');
 256: }
 257: 
 258: decdigit(c)
 259: char c; {
 260:     return(c >= '0' && c <= '9');
 261: }
 262: 
 263: decconv(c)
 264: char c; {
 265:     return(c - '0');
 266: }
 267: 
 268: hexdigit(c)
 269: char c; {
 270:     return((c >= '0' && c <= '9') || (c >= 'a' && c <= 'f') ||
 271:         (c >= 'A' && c <= 'F'));
 272: }
 273: 
 274: hexconv(c)
 275: char c; {
 276:     if (c >= '0' && c <= '9') return(c - '0');
 277:     if (c >= 'a' && c <= 'f') return(c - 'a' + 10);
 278:     if (c >= 'A' && c <= 'F') return(c - 'A' + 10);
 279:     error("hex conversion error");
 280:     return(0);
 281: }
 282: 
 283: /* decodes number, character or variable */
 284: long
 285: argvalue(p)
 286: char *p; {
 287:     register char ch;
 288:     register long value;
 289:     register ADDR j;
 290:     char var[30];
 291: 
 292:     ch = *p;
 293:     if (ch == '\'') {
 294:         value = *(p+1);
 295:     } else if ((ch >= '0' && ch <= '9') || ch == '-') {
 296:         value = readint(&p);
 297:     } else if ((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z') ||
 298:         ch == '_') {
 299:         cpname(var, p);
 300:         j = varaddr(curproc()->pname, var);
 301:         if (j == -1) {
 302:             printf("Unknown variable: %s\n", argsp);
 303:             return(-1);
 304:         }
 305:         value = getval(j, typetodesc(sl_type, 0)[0], DSP);
 306:         do {
 307:             p++;
 308:         } while (varchar(*p) || number(*p));
 309:     }
 310:     return(value);
 311: }
 312: 
 313: prhex(v)
 314: long v; {
 315:     if (v < 0)  {
 316:         v = -v;
 317:         printf("-");
 318:     }
 319:     if (v <= 9)
 320:         printf("%d", v);
 321:     else
 322:         printf("0x%x", v);
 323: }
 324: 
 325: /* print hex number in field of length 12 */
 326: prhex12(v)
 327: long v; {
 328:     if (v >= -9 && v <= 9)
 329:         printf("%-12d", v);
 330:     else
 331:         printf("0x%-12x", v);
 332: }
 333: 
 334: /* print line number followed by offset */
 335: prlnoff(procp, v)
 336: struct proct *procp; ADDR v; {
 337:     int lineno, diff;
 338:     char *name;
 339:     name = procp->pname;
 340:     if (name[0] == '_') {
 341: #ifndef FLEXNAMES
 342:         printf("%.7s", name+1);
 343: #else
 344:         printf("%s", name+1);
 345: #endif
 346:         lineno = -1;
 347:     } else {
 348: #ifndef FLEXNAMES
 349:         printf("%8s", name);
 350: #else
 351:         printf("%s", name);
 352: #endif
 353:         lineno = adrtolineno((ADDR) v);
 354:     }
 355:     if (lineno == -1)
 356:         diff = v - procp->paddr;
 357:     else {
 358:         printf(":%d", lineno);
 359:         diff = v - lnfaddr;  /* set by adrtolineno() */
 360:     }
 361:     if (diff) {
 362:         printf("+");
 363:         prhex(diff);
 364:     }
 365: }

Defined functions

argvalue defined in line 284; used 4 times
chkerr defined in line 79; used 3 times
cpall defined in line 38; used 6 times
cpname defined in line 29; used 7 times
decconv defined in line 263; used 2 times
decdigit defined in line 258; used 2 times
dtol defined in line 117; used 5 times
eqpat defined in line 148; used 8 times
eqpatr defined in line 158; used 12 times
getindir defined in line 206; used 3 times
hexconv defined in line 274; used 2 times
hexdigit defined in line 268; used 2 times
longseek defined in line 109; used 1 times
octconv defined in line 253; used 2 times
octdigit defined in line 248; used 2 times
prhex defined in line 313; used 4 times
prhex12 defined in line 326; used 1 times
prlnoff defined in line 335; used 3 times
readline defined in line 9; used 2 times
rint defined in line 237; used 4 times
round defined in line 67; used 3 times

Defined variables

sccsid defined in line 1; never used
u defined in line 7; used 1 times
Last modified: 1982-10-04
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 1309
Valid CSS Valid XHTML 1.0 Strict