1*14469Ssam #ifndef lint 2*14469Ssam static char sccsid[] = "@(#)format.c 4.2 08/11/83"; 3*14469Ssam #endif 43756Sroot /* 53756Sroot * 63756Sroot * UNIX debugger 73756Sroot * 83756Sroot */ 93756Sroot 103756Sroot #include "defs.h" 113756Sroot 123756Sroot MSG BADMOD; 133756Sroot MSG NOFORK; 143756Sroot MSG ADWRAP; 153756Sroot 163756Sroot INT mkfault; 173756Sroot CHAR *lp; 183756Sroot L_INT maxoff; 193756Sroot ADDR sigint; 203756Sroot ADDR sigqit; 213756Sroot STRING errflg; 223756Sroot CHAR lastc,peekc; 233756Sroot L_INT dot; 243756Sroot INT dotinc; 253756Sroot L_INT expv; 263756Sroot L_INT var[]; 273756Sroot 283756Sroot 293756Sroot STRING fphack; 303756Sroot rdfp() 313756Sroot { 323756Sroot return(lastc= *fphack++); 333756Sroot } 343756Sroot 353756Sroot scanform(icount,ifp,itype,ptype) 363756Sroot L_INT icount; 373756Sroot STRING ifp; 383756Sroot { 393756Sroot STRING fp; 403756Sroot CHAR modifier; 413756Sroot INT fcount, init=1; 423756Sroot L_INT savdot; 433756Sroot BOOL exact; 443756Sroot BOOL doit = 1; 453756Sroot 463756Sroot WHILE icount 473756Sroot DO fp=ifp; 483756Sroot savdot=dot; init=0; 493756Sroot 503756Sroot IF init==0 ANDF (exact=(findsym(dot,ptype)==0)) ANDF maxoff 513756Sroot THEN printf("\n%s:%16t",cursym->n_un.n_name); 523756Sroot FI 533756Sroot 543756Sroot /*now loop over format*/ 553756Sroot WHILE *fp ANDF errflg==0 563756Sroot DO IF digit(modifier = *fp) 573756Sroot THEN fcount = 0; 583756Sroot WHILE digit(modifier = *fp++) 593756Sroot DO fcount *= 10; 603756Sroot fcount += modifier-'0'; 613756Sroot OD 623756Sroot fp--; 633756Sroot ELSE fcount = 1; 643756Sroot FI 653756Sroot 663756Sroot IF *fp==0 THEN break; FI 673756Sroot IF exact ANDF dot==savdot ANDF itype==ISP ANDF cursym->n_un.n_name[0]=='_' ANDF *fp=='i' 683756Sroot THEN exform(1,"x",itype,ptype); fp++; printc(EOR); /* entry mask */ 693756Sroot ELSE fp=exform(fcount,fp,itype,ptype); 703756Sroot FI 713756Sroot OD 723756Sroot dotinc=dot-savdot; 733756Sroot dot=savdot; 743756Sroot 753756Sroot IF errflg 763756Sroot THEN IF icount<0 773756Sroot THEN errflg=0; break; 783756Sroot ELSE error(errflg); 793756Sroot FI 803756Sroot FI 813756Sroot IF --icount 823756Sroot THEN dot=inkdot(dotinc); 833756Sroot FI 843756Sroot IF mkfault THEN error(0); FI 853756Sroot OD 863756Sroot } 873756Sroot 883756Sroot STRING 893756Sroot exform(fcount,ifp,itype,ptype) 903756Sroot INT fcount; 913756Sroot STRING ifp; 923756Sroot { 933756Sroot /* execute single format item `fcount' times 943756Sroot * sets `dotinc' and moves `dot' 953756Sroot * returns address of next format item 963756Sroot */ 973756Sroot POS w; 983756Sroot L_INT savdot, wx; 993756Sroot STRING fp; 1003756Sroot CHAR c, modifier, longpr; 1013756Sroot L_REAL fw; 1023756Sroot struct{ 1033756Sroot L_INT sa; 1043756Sroot INT sb,sc; 1053756Sroot }; 1063756Sroot 1073756Sroot WHILE fcount>0 1083756Sroot DO fp = ifp; c = *fp; 1093756Sroot longpr=(c>='A')&(c<='Z')|(c=='f')|(c=='4')|(c=='p'); 1103756Sroot IF itype==NSP ORF *fp=='a' 1113756Sroot THEN wx=dot; w=dot; 1123756Sroot ELSE w=get(dot,itype); 1133756Sroot IF longpr 1143756Sroot THEN wx=itol(get(inkdot(2),itype),w); 1153756Sroot ELSE wx=w; 1163756Sroot FI 1173756Sroot FI 1183756Sroot IF c=='F' 1193756Sroot THEN fw.sb=get(inkdot(4),itype); 1203756Sroot fw.sc=get(inkdot(6),itype); 1213756Sroot FI 1223756Sroot IF errflg THEN return(fp); FI 1233756Sroot IF mkfault THEN error(0); FI 1243756Sroot var[0]=wx; 1253756Sroot modifier = *fp++; 1263756Sroot dotinc=(longpr?4:2);; 1273756Sroot 1283756Sroot IF charpos()==0 ANDF modifier!='a' THEN printf("%16m"); FI 1293756Sroot 1303756Sroot switch(modifier) { 1313756Sroot 1323756Sroot case SP: case TB: 1333756Sroot break; 1343756Sroot 1353756Sroot case 't': case 'T': 1363756Sroot printf("%T",fcount); return(fp); 1373756Sroot 1383756Sroot case 'r': case 'R': 1393756Sroot printf("%M",fcount); return(fp); 1403756Sroot 1413756Sroot case 'a': 1423756Sroot psymoff(dot,ptype,":%16t"); dotinc=0; break; 1433756Sroot 1443756Sroot case 'p': 1453756Sroot psymoff(var[0],ptype,"%16t"); break; 1463756Sroot 1473756Sroot case 'u': 1483756Sroot printf("%-8u",w); break; 1493756Sroot 1503756Sroot case 'U': 1513756Sroot printf("%-16U",wx); break; 1523756Sroot 1533756Sroot case 'c': case 'C': 1543756Sroot IF modifier=='C' 1553756Sroot THEN printesc(w&LOBYTE); 1563756Sroot ELSE printc(w&LOBYTE); 1573756Sroot FI 1583756Sroot dotinc=1; break; 1593756Sroot 1603756Sroot case 'b': case 'B': 1613756Sroot printf("%-8o", w&LOBYTE); dotinc=1; break; 1623756Sroot 1633756Sroot case '1': 1643756Sroot printf("%-8r", w&LOBYTE); dotinc=1; break; 1653756Sroot 1663756Sroot case '2': 1673756Sroot case 'w': 1683756Sroot printf("%-8r", w); break; 1693756Sroot 1703756Sroot case '4': 1713756Sroot case 'W': 1723756Sroot printf("%-16R", wx); break; 1733756Sroot 1743756Sroot case 's': case 'S': 1753756Sroot savdot=dot; dotinc=1; 1763756Sroot WHILE (c=get(dot,itype)&LOBYTE) ANDF errflg==0 1773756Sroot DO dot=inkdot(1); 1783756Sroot IF modifier == 'S' 1793756Sroot THEN printesc(c); 1803756Sroot ELSE printc(c); 1813756Sroot FI 1823756Sroot endline(); 1833756Sroot OD 1843756Sroot dotinc=dot-savdot+1; dot=savdot; break; 1853756Sroot 1863756Sroot case 'x': 1873756Sroot printf("%-8x",w); break; 1883756Sroot 1893756Sroot case 'X': 1903756Sroot printf("%-16X", wx); break; 1913756Sroot 1923756Sroot case 'Y': 1933756Sroot printf("%-24Y", wx); break; 1943756Sroot 1953756Sroot case 'q': 1963756Sroot printf("%-8q", w); break; 1973756Sroot 1983756Sroot case 'Q': 1993756Sroot printf("%-16Q", wx); break; 2003756Sroot 2013756Sroot case 'o': 2023756Sroot printf("%-8o", w); break; 2033756Sroot 2043756Sroot case 'O': 2053756Sroot printf("%-16O", wx); break; 2063756Sroot 2073756Sroot case 'i': 2083756Sroot printins(0,itype,w); printc(EOR); break; 2093756Sroot 2103756Sroot case 'd': 2113756Sroot printf("%-8d", w); break; 2123756Sroot 2133756Sroot case 'D': 2143756Sroot printf("%-16D", wx); break; 2153756Sroot 2163756Sroot case 'f': 2173756Sroot fw = 0; 2183756Sroot fw.sa = wx; 2193756Sroot printf("%-16.9f", fw); 2203756Sroot dotinc=4; break; 2213756Sroot 2223756Sroot case 'F': 2233756Sroot fw.sa = wx; 2243756Sroot printf("%-32.18F", fw); 2253756Sroot dotinc=8; break; 2263756Sroot 2273756Sroot case 'n': case 'N': 2283756Sroot printc('\n'); dotinc=0; break; 2293756Sroot 2303756Sroot case '"': 2313756Sroot dotinc=0; 2323756Sroot WHILE *fp != '"' ANDF *fp 2333756Sroot DO printc(*fp++); OD 2343756Sroot IF *fp THEN fp++; FI 2353756Sroot break; 2363756Sroot 2373756Sroot case '^': 2383756Sroot dot=inkdot(-dotinc*fcount); return(fp); 2393756Sroot 2403756Sroot case '+': 2413756Sroot dot=inkdot(fcount); return(fp); 2423756Sroot 2433756Sroot case '-': 2443756Sroot dot=inkdot(-fcount); return(fp); 2453756Sroot 2463756Sroot default: error(BADMOD); 2473756Sroot } 2483756Sroot IF itype!=NSP 2493756Sroot THEN dot=inkdot(dotinc); 2503756Sroot FI 2513756Sroot fcount--; endline(); 2523756Sroot OD 2533756Sroot 2543756Sroot return(fp); 2553756Sroot } 2563756Sroot 2573756Sroot shell() 2583756Sroot { 2593756Sroot #ifndef EDDT 2603756Sroot INT rc, status, unixpid; 2613756Sroot STRING argp = lp; 2623756Sroot STRING getenv(), shell = getenv("SHELL"); 2633756Sroot #ifdef VFORK 2643756Sroot char oldstlp; 2653756Sroot #endif 2663756Sroot 2673756Sroot if (shell == 0) 2683756Sroot shell = "/bin/sh"; 2693756Sroot WHILE lastc!=EOR DO rdc(); OD 2703756Sroot #ifndef VFORK 2713756Sroot IF (unixpid=fork())==0 2723756Sroot #else 2733756Sroot oldstlp = *lp; 2743756Sroot IF (unixpid=vfork())==0 2753756Sroot #endif 2763756Sroot THEN signal(SIGINT,sigint); signal(SIGQUIT,sigqit); 2773756Sroot *lp=0; execl(shell, "sh", "-c", argp, 0); 2783756Sroot _exit(16); 2793756Sroot #ifndef VFORK 2803756Sroot ELIF unixpid == -1 2813756Sroot #else 2823756Sroot ELIF *lp = oldstlp, unixpid == -1 2833756Sroot #endif 2843756Sroot THEN error(NOFORK); 2853756Sroot ELSE signal(SIGINT,1); 2863756Sroot WHILE (rc = wait(&status)) != unixpid ANDF rc != -1 DONE 2873756Sroot signal(SIGINT,sigint); 2883756Sroot prints("!"); lp--; 2893756Sroot FI 2903756Sroot #endif 2913756Sroot } 2923756Sroot 2933756Sroot 2943756Sroot printesc(c) 2953756Sroot { 2963756Sroot c &= STRIP; 2973756Sroot IF c==0177 THEN printf("^?"); 2983756Sroot ELIF c<SP 2993756Sroot THEN printf("^%c", c + '@'); 3003756Sroot ELSE printc(c); 3013756Sroot FI 3023756Sroot } 3033756Sroot 3043756Sroot L_INT inkdot(incr) 3053756Sroot { 3063756Sroot L_INT newdot; 3073756Sroot 3083756Sroot newdot=dot+incr; 3093756Sroot IF (dot NEQ newdot) >> 24 THEN error(ADWRAP); FI 3103756Sroot return(newdot); 3113756Sroot } 3123756Sroot 3133756Sroot digit(c) 3143756Sroot { 3153756Sroot return c >= '0' && c <= '9'; 3163756Sroot } 317