1: #ifndef lint
   2: static  char sccsid[] = "@(#)format.c	4.3 2/27/86";
   3: #endif
   4: /*
   5:  *
   6:  *	UNIX debugger
   7:  *
   8:  */
   9: 
  10: #include "defs.h"
  11: 
  12: MSG     BADMOD;
  13: MSG     NOFORK;
  14: MSG     ADWRAP;
  15: 
  16: INT     mkfault;
  17: CHAR        *lp;
  18: L_INT       maxoff;
  19: ADDR        sigint;
  20: ADDR        sigqit;
  21: STRING      errflg;
  22: CHAR        lastc,peekc;
  23: L_INT       dot;
  24: INT     dotinc;
  25: L_INT       expv;
  26: L_INT       var[];
  27: 
  28: 
  29: STRING      fphack;
  30: rdfp()
  31: {
  32:     return(lastc= *fphack++);
  33: }
  34: 
  35: scanform(icount,ifp,itype,ptype)
  36: L_INT       icount;
  37: STRING      ifp;
  38: {
  39:     STRING      fp;
  40:     CHAR        modifier;
  41:     INT     fcount, init=1;
  42:     L_INT       savdot;
  43:     BOOL exact;
  44:     BOOL doit = 1;
  45: 
  46:     WHILE icount
  47:     DO  fp=ifp;
  48:         savdot=dot; init=0;
  49: 
  50:         IF init==0 ANDF (exact=(findsym(dot,ptype)==0)) ANDF maxoff
  51:         THEN printf("\n%s:%16t",cursym->n_un.n_name);
  52:         FI
  53: 
  54:         /*now loop over format*/
  55:         WHILE *fp ANDF errflg==0
  56:         DO  IF digit(modifier = *fp)
  57:         THEN fcount = 0;
  58:             WHILE digit(modifier = *fp++)
  59:             DO fcount *= 10;
  60:                fcount += modifier-'0';
  61:             OD
  62:             fp--;
  63:             IF fcount==0 THEN fcount = 1; FI
  64:         ELSE fcount = 1;
  65:         FI
  66: 
  67:         IF *fp==0 THEN break; FI
  68:         IF exact ANDF dot==savdot ANDF itype==ISP ANDF cursym->n_un.n_name[0]=='_' ANDF *fp=='i'
  69:         THEN exform(1,"x",itype,ptype); fp++; printc(EOR); /* entry mask */
  70:         ELSE fp=exform(fcount,fp,itype,ptype);
  71:         FI
  72:         OD
  73:         dotinc=dot-savdot;
  74:         dot=savdot;
  75: 
  76:         IF errflg
  77:         THEN IF icount<0
  78:          THEN errflg=0; break;
  79:          ELSE error(errflg);
  80:          FI
  81:         FI
  82:         IF --icount
  83:         THEN dot=inkdot(dotinc);
  84:         FI
  85:         IF mkfault THEN error(0); FI
  86:     OD
  87: }
  88: 
  89: STRING
  90: exform(fcount,ifp,itype,ptype)
  91: INT     fcount;
  92: STRING      ifp;
  93: {
  94:     /* execute single format item `fcount' times
  95: 	 * sets `dotinc' and moves `dot'
  96: 	 * returns address of next format item
  97: 	 */
  98:     POS     w;
  99:     L_INT       savdot, wx;
 100:     STRING      fp;
 101:     CHAR        c, modifier, longpr;
 102:     L_REAL      fw;
 103:     struct{
 104:         L_INT   sa;
 105:         INT sb,sc;
 106:     };
 107: 
 108:     WHILE fcount>0
 109:     DO  fp = ifp; c = *fp;
 110:         longpr=(c>='A')&(c<='Z')|(c=='f')|(c=='4')|(c=='p');
 111:         IF itype==NSP ORF *fp=='a'
 112:         THEN wx=dot; w=dot;
 113:         ELSE w=get(dot,itype);
 114:              IF longpr
 115:              THEN wx=itol(get(inkdot(2),itype),w);
 116:              ELSE wx=w;
 117:              FI
 118:         FI
 119:         IF c=='F'
 120:         THEN fw.sb=get(inkdot(4),itype);
 121:              fw.sc=get(inkdot(6),itype);
 122:         FI
 123:         IF errflg THEN return(fp); FI
 124:         IF mkfault THEN error(0); FI
 125:         var[0]=wx;
 126:         modifier = *fp++;
 127:         dotinc=(longpr?4:2);;
 128: 
 129:         IF charpos()==0 ANDF modifier!='a' THEN printf("%16m"); FI
 130: 
 131:         switch(modifier) {
 132: 
 133:             case SP: case TB:
 134:             break;
 135: 
 136:             case 't': case 'T':
 137:             printf("%T",fcount); return(fp);
 138: 
 139:             case 'r': case 'R':
 140:             printf("%M",fcount); return(fp);
 141: 
 142:             case 'a':
 143:             psymoff(dot,ptype,":%16t"); dotinc=0; break;
 144: 
 145:             case 'p':
 146:             psymoff(var[0],ptype,"%16t"); break;
 147: 
 148:             case 'u':
 149:             printf("%-8u",w); break;
 150: 
 151:             case 'U':
 152:             printf("%-16U",wx); break;
 153: 
 154:             case 'c': case 'C':
 155:             IF modifier=='C'
 156:             THEN printesc(w&LOBYTE);
 157:             ELSE printc(w&LOBYTE);
 158:             FI
 159:             dotinc=1; break;
 160: 
 161:             case 'b': case 'B':
 162:             printf("%-8o", w&LOBYTE); dotinc=1; break;
 163: 
 164:             case '1':
 165:             printf("%-8r", w&LOBYTE); dotinc=1; break;
 166: 
 167:             case '2':
 168:             case 'w':
 169:             printf("%-8r", w); break;
 170: 
 171:             case '4':
 172:             case 'W':
 173:             printf("%-16R", wx); break;
 174: 
 175:             case 's': case 'S':
 176:             savdot=dot; dotinc=1;
 177:             WHILE (c=get(dot,itype)&LOBYTE) ANDF errflg==0
 178:             DO dot=inkdot(1);
 179:                IF modifier == 'S'
 180:                THEN printesc(c);
 181:                ELSE printc(c);
 182:                FI
 183:                endline();
 184:             OD
 185:             dotinc=dot-savdot+1; dot=savdot; break;
 186: 
 187:             case 'x':
 188:             printf("%-8x",w); break;
 189: 
 190:             case 'X':
 191:             printf("%-16X", wx); break;
 192: 
 193:             case 'Y':
 194:             printf("%-24Y", wx); break;
 195: 
 196:             case 'q':
 197:             printf("%-8q", w); break;
 198: 
 199:             case 'Q':
 200:             printf("%-16Q", wx); break;
 201: 
 202:             case 'o':
 203:             printf("%-8o", w); break;
 204: 
 205:             case 'O':
 206:             printf("%-16O", wx); break;
 207: 
 208:             case 'i':
 209:             printins(0,itype,w); printc(EOR); break;
 210: 
 211:             case 'd':
 212:             printf("%-8d", w); break;
 213: 
 214:             case 'D':
 215:             printf("%-16D", wx); break;
 216: 
 217:             case 'f':
 218:             fw = 0;
 219:             fw.sa = wx;
 220:             IF (wx & ~0xFFFF00FF) == 0x8000
 221:             THEN printf("(reserved oprnd)");
 222:             ELSE printf("%-16.9f", fw);
 223:             FI
 224:             dotinc=4; break;
 225: 
 226:             case 'F':
 227:             fw.sa = wx;
 228:             IF (wx & ~0xFFFF00FF) == 0x8000
 229:             THEN printf("%-32s", "(reserved oprnd)");
 230:             ELSE printf("%-32.18F", fw);
 231:             FI
 232:             dotinc=8; break;
 233: 
 234:             case 'n': case 'N':
 235:             printc('\n'); dotinc=0; break;
 236: 
 237:             case '"':
 238:             dotinc=0;
 239:             WHILE *fp != '"' ANDF *fp
 240:             DO printc(*fp++); OD
 241:             IF *fp THEN fp++; FI
 242:             break;
 243: 
 244:             case '^':
 245:             dot=inkdot(-dotinc*fcount); return(fp);
 246: 
 247:             case '+':
 248:             dot=inkdot(fcount); return(fp);
 249: 
 250:             case '-':
 251:             dot=inkdot(-fcount); return(fp);
 252: 
 253:             default: error(BADMOD);
 254:         }
 255:         IF itype!=NSP
 256:         THEN    dot=inkdot(dotinc);
 257:         FI
 258:         fcount--; endline();
 259:     OD
 260: 
 261:     return(fp);
 262: }
 263: 
 264: shell()
 265: {
 266: #ifndef EDDT
 267:     INT     rc, status, unixpid;
 268:     STRING      argp = lp;
 269:     STRING      getenv(), shell = getenv("SHELL");
 270: #ifdef VFORK
 271:     char        oldstlp;
 272: #endif
 273: 
 274:     if (shell == 0)
 275:         shell = "/bin/sh";
 276:     WHILE lastc!=EOR DO rdc(); OD
 277: #ifndef VFORK
 278:     IF (unixpid=fork())==0
 279: #else
 280:     oldstlp = *lp;
 281:     IF (unixpid=vfork())==0
 282: #endif
 283:     THEN    signal(SIGINT,sigint); signal(SIGQUIT,sigqit);
 284:         *lp=0; execl(shell, "sh", "-c", argp, 0);
 285:         _exit(16);
 286: #ifndef VFORK
 287:     ELIF unixpid == -1
 288: #else
 289:     ELIF *lp = oldstlp, unixpid == -1
 290: #endif
 291:     THEN    error(NOFORK);
 292:     ELSE    signal(SIGINT,1);
 293:         WHILE (rc = wait(&status)) != unixpid ANDF rc != -1 DONE
 294:         signal(SIGINT,sigint);
 295:         prints("!"); lp--;
 296:     FI
 297: #endif
 298: }
 299: 
 300: 
 301: printesc(c)
 302: {
 303:     c &= STRIP;
 304:     IF c==0177 THEN printf("^?");
 305:     ELIF c<SP
 306:     THEN printf("^%c", c + '@');
 307:     ELSE printc(c);
 308:     FI
 309: }
 310: 
 311: L_INT   inkdot(incr)
 312: {
 313:     L_INT       newdot;
 314: 
 315:     newdot=dot+incr;
 316:     IF (dot NEQ newdot) >> 24 THEN error(ADWRAP); FI
 317:     return(newdot);
 318: }
 319: 
 320: digit(c)
 321: {
 322:     return c >= '0' && c <= '9';
 323: }

Defined functions

digit defined in line 320; used 2 times
exform defined in line 89; used 5 times
inkdot defined in line 311; used 14 times
printesc defined in line 301; used 2 times
rdfp defined in line 30; never used
scanform defined in line 35; used 1 times
shell defined in line 264; used 5 times

Defined variables

sccsid defined in line 2; never used
Last modified: 1986-02-28
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 1203
Valid CSS Valid XHTML 1.0 Strict