xref: /csrg-svn/old/adb/adb.vax/format.c (revision 26430)
114469Ssam #ifndef lint
2*26430Smckusick static	char sccsid[] = "@(#)format.c	4.3 02/27/86";
314469Ssam #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--;
63*26430Smckusick 			IF fcount==0 THEN fcount = 1; FI
643756Sroot 		ELSE fcount = 1;
653756Sroot 		FI
663756Sroot 
673756Sroot 		IF *fp==0 THEN break; FI
683756Sroot 		IF exact ANDF dot==savdot ANDF itype==ISP ANDF cursym->n_un.n_name[0]=='_' ANDF *fp=='i'
693756Sroot 		THEN exform(1,"x",itype,ptype); fp++; printc(EOR); /* entry mask */
703756Sroot 		ELSE fp=exform(fcount,fp,itype,ptype);
713756Sroot 		FI
723756Sroot 	    OD
733756Sroot 	    dotinc=dot-savdot;
743756Sroot 	    dot=savdot;
753756Sroot 
763756Sroot 	    IF errflg
773756Sroot 	    THEN IF icount<0
783756Sroot 		 THEN errflg=0; break;
793756Sroot 		 ELSE error(errflg);
803756Sroot 		 FI
813756Sroot 	    FI
823756Sroot 	    IF --icount
833756Sroot 	    THEN dot=inkdot(dotinc);
843756Sroot 	    FI
853756Sroot 	    IF mkfault THEN error(0); FI
863756Sroot 	OD
873756Sroot }
883756Sroot 
893756Sroot STRING
903756Sroot exform(fcount,ifp,itype,ptype)
913756Sroot INT		fcount;
923756Sroot STRING		ifp;
933756Sroot {
943756Sroot 	/* execute single format item `fcount' times
953756Sroot 	 * sets `dotinc' and moves `dot'
963756Sroot 	 * returns address of next format item
973756Sroot 	 */
983756Sroot 	POS		w;
993756Sroot 	L_INT		savdot, wx;
1003756Sroot 	STRING		fp;
1013756Sroot 	CHAR		c, modifier, longpr;
1023756Sroot 	L_REAL		fw;
1033756Sroot 	struct{
1043756Sroot 		L_INT	sa;
1053756Sroot 		INT	sb,sc;
1063756Sroot 	};
1073756Sroot 
1083756Sroot 	WHILE fcount>0
1093756Sroot 	DO	fp = ifp; c = *fp;
1103756Sroot 		longpr=(c>='A')&(c<='Z')|(c=='f')|(c=='4')|(c=='p');
1113756Sroot 		IF itype==NSP ORF *fp=='a'
1123756Sroot 		THEN wx=dot; w=dot;
1133756Sroot 		ELSE w=get(dot,itype);
1143756Sroot 		     IF longpr
1153756Sroot 		     THEN wx=itol(get(inkdot(2),itype),w);
1163756Sroot 		     ELSE wx=w;
1173756Sroot 		     FI
1183756Sroot 		FI
1193756Sroot 		IF c=='F'
1203756Sroot 		THEN fw.sb=get(inkdot(4),itype);
1213756Sroot 		     fw.sc=get(inkdot(6),itype);
1223756Sroot 		FI
1233756Sroot 		IF errflg THEN return(fp); FI
1243756Sroot 		IF mkfault THEN error(0); FI
1253756Sroot 		var[0]=wx;
1263756Sroot 		modifier = *fp++;
1273756Sroot 		dotinc=(longpr?4:2);;
1283756Sroot 
1293756Sroot 		IF charpos()==0 ANDF modifier!='a' THEN printf("%16m"); FI
1303756Sroot 
1313756Sroot 		switch(modifier) {
1323756Sroot 
1333756Sroot 		    case SP: case TB:
1343756Sroot 			break;
1353756Sroot 
1363756Sroot 		    case 't': case 'T':
1373756Sroot 			printf("%T",fcount); return(fp);
1383756Sroot 
1393756Sroot 		    case 'r': case 'R':
1403756Sroot 			printf("%M",fcount); return(fp);
1413756Sroot 
1423756Sroot 		    case 'a':
1433756Sroot 			psymoff(dot,ptype,":%16t"); dotinc=0; break;
1443756Sroot 
1453756Sroot 		    case 'p':
1463756Sroot 			psymoff(var[0],ptype,"%16t"); break;
1473756Sroot 
1483756Sroot 		    case 'u':
1493756Sroot 			printf("%-8u",w); break;
1503756Sroot 
1513756Sroot 		    case 'U':
1523756Sroot 			printf("%-16U",wx); break;
1533756Sroot 
1543756Sroot 		    case 'c': case 'C':
1553756Sroot 			IF modifier=='C'
1563756Sroot 			THEN printesc(w&LOBYTE);
1573756Sroot 			ELSE printc(w&LOBYTE);
1583756Sroot 			FI
1593756Sroot 			dotinc=1; break;
1603756Sroot 
1613756Sroot 		    case 'b': case 'B':
1623756Sroot 			printf("%-8o", w&LOBYTE); dotinc=1; break;
1633756Sroot 
1643756Sroot 			case '1':
1653756Sroot 			printf("%-8r", w&LOBYTE); dotinc=1; break;
1663756Sroot 
1673756Sroot 			case '2':
1683756Sroot 		    case 'w':
1693756Sroot 			printf("%-8r", w); break;
1703756Sroot 
1713756Sroot 			case '4':
1723756Sroot 		    case 'W':
1733756Sroot 			printf("%-16R", wx); break;
1743756Sroot 
1753756Sroot 		    case 's': case 'S':
1763756Sroot 			savdot=dot; dotinc=1;
1773756Sroot 			WHILE (c=get(dot,itype)&LOBYTE) ANDF errflg==0
1783756Sroot 			DO dot=inkdot(1);
1793756Sroot 			   IF modifier == 'S'
1803756Sroot 			   THEN printesc(c);
1813756Sroot 			   ELSE printc(c);
1823756Sroot 			   FI
1833756Sroot 			   endline();
1843756Sroot 			OD
1853756Sroot 			dotinc=dot-savdot+1; dot=savdot; break;
1863756Sroot 
1873756Sroot 		    case 'x':
1883756Sroot 			printf("%-8x",w); break;
1893756Sroot 
1903756Sroot 		    case 'X':
1913756Sroot 			printf("%-16X", wx); break;
1923756Sroot 
1933756Sroot 		    case 'Y':
1943756Sroot 			printf("%-24Y", wx); break;
1953756Sroot 
1963756Sroot 		    case 'q':
1973756Sroot 			printf("%-8q", w); break;
1983756Sroot 
1993756Sroot 		    case 'Q':
2003756Sroot 			printf("%-16Q", wx); break;
2013756Sroot 
2023756Sroot 		    case 'o':
2033756Sroot 			printf("%-8o", w); break;
2043756Sroot 
2053756Sroot 		    case 'O':
2063756Sroot 			printf("%-16O", wx); break;
2073756Sroot 
2083756Sroot 		    case 'i':
2093756Sroot 			printins(0,itype,w); printc(EOR); break;
2103756Sroot 
2113756Sroot 		    case 'd':
2123756Sroot 			printf("%-8d", w); break;
2133756Sroot 
2143756Sroot 		    case 'D':
2153756Sroot 			printf("%-16D", wx); break;
2163756Sroot 
2173756Sroot 		    case 'f':
2183756Sroot 			fw = 0;
2193756Sroot 			fw.sa = wx;
220*26430Smckusick 			IF (wx & ~0xFFFF00FF) == 0x8000
221*26430Smckusick 			THEN printf("(reserved oprnd)");
222*26430Smckusick 			ELSE printf("%-16.9f", fw);
223*26430Smckusick 			FI
2243756Sroot 			dotinc=4; break;
2253756Sroot 
2263756Sroot 		    case 'F':
2273756Sroot 			fw.sa = wx;
228*26430Smckusick 			IF (wx & ~0xFFFF00FF) == 0x8000
229*26430Smckusick 			THEN printf("%-32s", "(reserved oprnd)");
230*26430Smckusick 			ELSE printf("%-32.18F", fw);
231*26430Smckusick 			FI
2323756Sroot 			dotinc=8; break;
2333756Sroot 
2343756Sroot 		    case 'n': case 'N':
2353756Sroot 			printc('\n'); dotinc=0; break;
2363756Sroot 
2373756Sroot 		    case '"':
2383756Sroot 			dotinc=0;
2393756Sroot 			WHILE *fp != '"' ANDF *fp
2403756Sroot 			DO printc(*fp++); OD
2413756Sroot 			IF *fp THEN fp++; FI
2423756Sroot 			break;
2433756Sroot 
2443756Sroot 		    case '^':
2453756Sroot 			dot=inkdot(-dotinc*fcount); return(fp);
2463756Sroot 
2473756Sroot 		    case '+':
2483756Sroot 			dot=inkdot(fcount); return(fp);
2493756Sroot 
2503756Sroot 		    case '-':
2513756Sroot 			dot=inkdot(-fcount); return(fp);
2523756Sroot 
2533756Sroot 		    default: error(BADMOD);
2543756Sroot 		}
2553756Sroot 		IF itype!=NSP
2563756Sroot 		THEN	dot=inkdot(dotinc);
2573756Sroot 		FI
2583756Sroot 		fcount--; endline();
2593756Sroot 	OD
2603756Sroot 
2613756Sroot 	return(fp);
2623756Sroot }
2633756Sroot 
2643756Sroot shell()
2653756Sroot {
2663756Sroot #ifndef EDDT
2673756Sroot 	INT		rc, status, unixpid;
2683756Sroot 	STRING		argp = lp;
2693756Sroot 	STRING		getenv(), shell = getenv("SHELL");
2703756Sroot #ifdef VFORK
2713756Sroot 	char		oldstlp;
2723756Sroot #endif
2733756Sroot 
2743756Sroot 	if (shell == 0)
2753756Sroot 		shell = "/bin/sh";
2763756Sroot 	WHILE lastc!=EOR DO rdc(); OD
2773756Sroot #ifndef VFORK
2783756Sroot 	IF (unixpid=fork())==0
2793756Sroot #else
2803756Sroot 	oldstlp = *lp;
2813756Sroot 	IF (unixpid=vfork())==0
2823756Sroot #endif
2833756Sroot 	THEN	signal(SIGINT,sigint); signal(SIGQUIT,sigqit);
2843756Sroot 		*lp=0; execl(shell, "sh", "-c", argp, 0);
2853756Sroot 		_exit(16);
2863756Sroot #ifndef VFORK
2873756Sroot 	ELIF unixpid == -1
2883756Sroot #else
2893756Sroot 	ELIF *lp = oldstlp, unixpid == -1
2903756Sroot #endif
2913756Sroot 	THEN	error(NOFORK);
2923756Sroot 	ELSE	signal(SIGINT,1);
2933756Sroot 		WHILE (rc = wait(&status)) != unixpid ANDF rc != -1 DONE
2943756Sroot 		signal(SIGINT,sigint);
2953756Sroot 		prints("!"); lp--;
2963756Sroot 	FI
2973756Sroot #endif
2983756Sroot }
2993756Sroot 
3003756Sroot 
3013756Sroot printesc(c)
3023756Sroot {
3033756Sroot 	c &= STRIP;
3043756Sroot 	IF c==0177 THEN printf("^?");
3053756Sroot 	ELIF c<SP
3063756Sroot 	THEN printf("^%c", c + '@');
3073756Sroot 	ELSE printc(c);
3083756Sroot 	FI
3093756Sroot }
3103756Sroot 
3113756Sroot L_INT	inkdot(incr)
3123756Sroot {
3133756Sroot 	L_INT		newdot;
3143756Sroot 
3153756Sroot 	newdot=dot+incr;
3163756Sroot 	IF (dot NEQ newdot) >> 24 THEN error(ADWRAP); FI
3173756Sroot 	return(newdot);
3183756Sroot }
3193756Sroot 
3203756Sroot digit(c)
3213756Sroot {
3223756Sroot 	return c >= '0' && c <= '9';
3233756Sroot }
324