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