xref: /csrg-svn/old/adb/adb.vax/output.c (revision 6416)
13762Sroot #
23762Sroot /*
33762Sroot  *
43762Sroot  *	UNIX debugger
53762Sroot  *
63762Sroot  */
73762Sroot 
83762Sroot #include "defs.h"
9*6416Sroot static	char sccsid[] = "@(#)output.c 4.2 04/01/82";
103762Sroot #include <stdio.h>
113762Sroot 
123762Sroot 
133762Sroot INT		mkfault;
143762Sroot INT		infile;
153762Sroot INT		outfile = 1;
163762Sroot L_INT		maxpos;
173762Sroot L_INT		maxoff;
183762Sroot INT		radix = 16;
193762Sroot 
203762Sroot CHAR		printbuf[MAXLIN];
213762Sroot CHAR		*printptr = printbuf;
223762Sroot CHAR		*digitptr;
233762Sroot MSG		TOODEEP;
243762Sroot 
253762Sroot 
263762Sroot eqstr(s1, s2)
273762Sroot 	REG STRING	s1, s2;
283762Sroot {
293762Sroot 	REG STRING	 es1;
303762Sroot 	WHILE *s1++ == *s2
313762Sroot 	DO IF *s2++ == 0
323762Sroot 	   THEN return(1);
333762Sroot 	   FI
343762Sroot 	OD
353762Sroot 	return(0);
363762Sroot }
373762Sroot 
383762Sroot length(s)
393762Sroot 	REG STRING		s;
403762Sroot {
413762Sroot 	INT		n = 0;
423762Sroot 	WHILE *s++ DO n++; OD
433762Sroot 	return(n);
443762Sroot }
453762Sroot 
463762Sroot printc(c)
473762Sroot 	CHAR		c;
483762Sroot {
493762Sroot 	CHAR		d;
503762Sroot 	STRING		q;
513762Sroot 	INT		posn, tabs, p;
523762Sroot 
533762Sroot 	IF mkfault
543762Sroot 	THEN	return;
553762Sroot 	ELIF (*printptr=c)==EOR
563762Sroot 	THEN tabs=0; posn=0; q=printbuf;
573762Sroot 	     FOR p=0; p<printptr-printbuf; p++
583762Sroot 	     DO d=printbuf[p];
593762Sroot 		IF (p&7)==0 ANDF posn
603762Sroot 		THEN tabs++; posn=0;
613762Sroot 		FI
623762Sroot 		IF d==SP
633762Sroot 		THEN posn++;
643762Sroot 		ELSE WHILE tabs>0 DO *q++=TB; tabs--; OD
653762Sroot 		     WHILE posn>0 DO *q++=SP; posn--; OD
663762Sroot 		     *q++=d;
673762Sroot 		FI
683762Sroot 	     OD
693762Sroot 	     *q++=EOR;
703762Sroot #ifdef EDDT
713762Sroot 		printptr=printbuf; do putchar(*printptr++); while (printptr<q);
723762Sroot #else
733762Sroot 	     write(outfile,printbuf,q-printbuf);
743762Sroot #endif
753762Sroot 	     printptr=printbuf;
763762Sroot 	ELIF c==TB
773762Sroot 	THEN *printptr++=SP;
783762Sroot 	     WHILE (printptr-printbuf)&7 DO *printptr++=SP; OD
793762Sroot 	ELIF c
803762Sroot 	THEN printptr++;
813762Sroot 	FI
82*6416Sroot 	IF printptr >= &printbuf[MAXLIN-9] THEN
83*6416Sroot 		write(outfile, printbuf, printptr - printbuf);
84*6416Sroot 		printptr = printbuf;
85*6416Sroot 	FI
863762Sroot }
873762Sroot 
883762Sroot charpos()
893762Sroot {	return(printptr-printbuf);
903762Sroot }
913762Sroot 
923762Sroot flushbuf()
933762Sroot {	IF printptr!=printbuf
943762Sroot 	THEN printc(EOR);
953762Sroot 	FI
963762Sroot }
973762Sroot 
983762Sroot printf(fmat,a1)
993762Sroot 	STRING		fmat;
1003762Sroot 	STRING		*a1;
1013762Sroot {
1023762Sroot 	STRING		fptr, s;
1033762Sroot 	INT		*vptr;
1043762Sroot 	L_INT		*dptr;
1053762Sroot 	L_REAL		*rptr;
1063762Sroot 	INT		width, prec;
1073762Sroot 	CHAR		c, adj;
1083762Sroot 	INT		x, decpt, n;
1093762Sroot 	L_INT		lx;
1103762Sroot 	CHAR		digits[64];
1113762Sroot 
1123762Sroot 	fptr = fmat; dptr = vptr = &a1;
1133762Sroot 
1143762Sroot 	WHILE c = *fptr++
1153762Sroot 	DO  IF c!='%'
1163762Sroot 	    THEN printc(c);
1173762Sroot 	    ELSE IF *fptr=='-' THEN adj='l'; fptr++; ELSE adj='r'; FI
1183762Sroot 		 width=convert(&fptr);
1193762Sroot 		 IF *fptr=='.' THEN fptr++; prec=convert(&fptr); ELSE prec = -1; FI
1203762Sroot 		 digitptr=digits;
1213762Sroot #ifndef vax
1223762Sroot 		 dptr=rptr=vptr; lx = *dptr; x = *vptr++;
1233762Sroot #else
1243762Sroot 		 rptr=dptr; x = shorten(lx = *dptr++);
1253762Sroot #endif
1263762Sroot 		 s=0;
1273762Sroot 		 switch (c = *fptr++) {
1283762Sroot 
1293762Sroot 		    case 'd':
1303762Sroot 		    case 'u':
1313762Sroot 			printnum(x,c,10); break;
1323762Sroot 		    case 'o':
1333762Sroot #ifndef vax
1343762Sroot 			printoct(0,x,0); break;
1353762Sroot #else
1363762Sroot 			printoct(itol(0,x),0); break;
1373762Sroot #endif
1383762Sroot 		    case 'q':
1393762Sroot 			lx=x; printoct(lx,-1); break;
1403762Sroot 		    case 'x':
1413762Sroot #ifndef vax
1423762Sroot 			printdbl(0,x,c,16); break;
1433762Sroot #else
1443762Sroot 			printdbl(itol(0,x),c,16); break;
1453762Sroot #endif
1463762Sroot 			case 'r':
1473762Sroot 			printdbl(lx=x,c,radix); break;
1483762Sroot 			case 'R':
1493762Sroot 			printdbl(lx,c,radix); vptr++; break;
1503762Sroot 		    case 'Y':
1513762Sroot 			printdate(lx); vptr++; break;
1523762Sroot 		    case 'D':
1533762Sroot 		    case 'U':
1543762Sroot 			printdbl(lx,c,10); vptr++; break;
1553762Sroot 		    case 'O':
1563762Sroot 			printoct(lx,0); vptr++; break;
1573762Sroot 		    case 'Q':
1583762Sroot 			printoct(lx,-1); vptr++; break;
1593762Sroot 		    case 'X':
1603762Sroot 			printdbl(lx,'x',16); vptr++; break;
1613762Sroot 		    case 'c':
1623762Sroot 			printc(x); break;
1633762Sroot 		    case 's':
1643762Sroot #ifndef vax
1653762Sroot 			s=x; break;
1663762Sroot #else
1673762Sroot 			s=lx; break;
1683762Sroot #endif
1693762Sroot #ifndef EDDT
1703762Sroot 		    case 'f':
1713762Sroot 		    case 'F':
1723762Sroot #ifdef vax
1733762Sroot 			dptr++;
1743762Sroot 			sprintf(s=digits,"%+.16e",*rptr,*(rptr+4)); prec= -1; break;
1753762Sroot #else
1763762Sroot 			vptr += 7;
1773762Sroot 			s=ecvt(*rptr, prec, &decpt, &n);
1783762Sroot 			*digitptr++=(n?'-':'+');
1793762Sroot 			*digitptr++ = (decpt<=0 ? '0' : *s++);
1803762Sroot 			IF decpt>0 THEN decpt--; FI
1813762Sroot 			*digitptr++ = '.';
1823762Sroot 			WHILE *s ANDF prec-- DO *digitptr++ = *s++; OD
1833762Sroot 			WHILE *--digitptr=='0' DONE
1843762Sroot 			digitptr += (digitptr-digits>=3 ? 1 : 2);
1853762Sroot 			IF decpt
1863762Sroot 			THEN *digitptr++ = 'e'; printnum(decpt,'d',10);
1873762Sroot 			FI
1883762Sroot 			s=0; prec = -1; break;
1893762Sroot #endif
1903762Sroot #endif
1913762Sroot 		    case 'm':
1923762Sroot 			vptr--; break;
1933762Sroot 		    case 'M':
1943762Sroot 			width=x; break;
1953762Sroot 		    case 'T':
1963762Sroot 		    case 't':
1973762Sroot 			IF c=='T'
1983762Sroot 			THEN width=x;
1993762Sroot #ifndef vax
2003762Sroot 			ELSE vptr--;
2013762Sroot #else
2023762Sroot 			ELSE dptr--;
2033762Sroot #endif
2043762Sroot 			FI
2053762Sroot 			IF width
2063762Sroot 			THEN width -= charpos()%width;
2073762Sroot 			FI
2083762Sroot 			break;
2093762Sroot 		    default:
2103762Sroot #ifndef vax
2113762Sroot 			printc(c); vptr--;
2123762Sroot #else
2133762Sroot 			printc(c); dptr--;
2143762Sroot #endif
2153762Sroot 		}
2163762Sroot 
2173762Sroot 		IF s==0
2183762Sroot 		THEN *digitptr=0; s=digits;
2193762Sroot 		FI
2203762Sroot 		n=length(s);
2213762Sroot 		n=(prec<n ANDF prec>=0 ? prec : n);
2223762Sroot 		width -= n;
2233762Sroot 		IF adj=='r'
2243762Sroot 		THEN WHILE width-- > 0
2253762Sroot 		     DO printc(SP); OD
2263762Sroot 		FI
2273762Sroot 		WHILE n-- DO printc(*s++); OD
2283762Sroot 		WHILE width-- > 0 DO printc(SP); OD
2293762Sroot 		digitptr=digits;
2303762Sroot 	    FI
2313762Sroot 	OD
2323762Sroot }
2333762Sroot 
2343762Sroot printdate(tvec)
2353762Sroot 	L_INT		tvec;
2363762Sroot {
2373762Sroot 	REG INT		i;
2383762Sroot 	REG STRING	timeptr;
2393762Sroot #ifndef EDDT
2403762Sroot 	timeptr = ctime(&tvec);
2413762Sroot #else
2423762Sroot 	timeptr="????????????????????????";
2433762Sroot #endif
2443762Sroot 	FOR i=20; i<24; i++ DO *digitptr++ = *(timeptr+i); OD
2453762Sroot 	FOR i=3; i<19; i++ DO *digitptr++ = *(timeptr+i); OD
2463762Sroot } /*printdate*/
2473762Sroot 
2483762Sroot prints(s)
2493762Sroot char *s;
2503762Sroot {	printf("%s",s);
2513762Sroot }
2523762Sroot 
2533762Sroot newline()
2543762Sroot {
2553762Sroot 	printc(EOR);
2563762Sroot }
2573762Sroot 
2583762Sroot convert(cp)
2593762Sroot REG STRING	*cp;
2603762Sroot {
2613762Sroot 	REG CHAR	c;
2623762Sroot 	INT		n;
2633762Sroot 	n=0;
2643762Sroot 	WHILE ((c = *(*cp)++)>='0') ANDF (c<='9') DO n=n*10+c-'0'; OD
2653762Sroot 	(*cp)--;
2663762Sroot 	return(n);
2673762Sroot }
2683762Sroot 
2693762Sroot printnum(n,fmat,base)
2703762Sroot 	REG INT		n;
2713762Sroot {
2723762Sroot 	REG CHAR	k;
2733762Sroot 	REG INT		*dptr;
2743762Sroot 	INT		digs[15];
2753762Sroot 	dptr=digs;
2763762Sroot 	IF n<0 ANDF fmat=='d' THEN n = -n; *digitptr++ = '-'; FI
2773762Sroot 	n &= 0xffff;
2783762Sroot 	WHILE n
2793762Sroot 	DO  *dptr++ = ((POS)(n&0xffff))%base;
2803762Sroot 	    n=((POS)(n&0xffff))/base;
2813762Sroot 	OD
2823762Sroot 	IF dptr==digs THEN *dptr++=0; FI
2833762Sroot 	WHILE dptr!=digs
2843762Sroot 	DO  k = *--dptr;
2853762Sroot 	    *digitptr++ = (k+(k<=9 ? '0' : 'a'-10));
2863762Sroot 	OD
2873762Sroot }
2883762Sroot 
2893762Sroot printoct(o,s)
2903762Sroot 	L_INT		o;
2913762Sroot 	INT		s;
2923762Sroot {
2933762Sroot 	INT		i;
2943762Sroot 	L_INT		po = o;
2953762Sroot 	CHAR		digs[12];
2963762Sroot 
2973762Sroot 	IF s
2983762Sroot 	THEN IF po<0
2993762Sroot 	     THEN po = -po; *digitptr++='-';
3003762Sroot 	     ELSE IF s>0 THEN *digitptr++='+'; FI
3013762Sroot 	     FI
3023762Sroot 	FI
3033762Sroot 	FOR i=0;i<=11;i++
3043762Sroot 	DO digs[i] = po&7; po >>= 3; OD
3053762Sroot 	digs[10] &= 03; digs[11]=0;
3063762Sroot 	FOR i=11;i>=0;i--
3073762Sroot 	DO IF digs[i] THEN break; FI OD
3083762Sroot 	FOR i++;i>=0;i--
3093762Sroot 	DO *digitptr++=digs[i]+'0'; OD
3103762Sroot }
3113762Sroot 
3123762Sroot #ifndef vax
3133762Sroot printdbl(lx,ly,fmat,base)
3143762Sroot INT lx, ly; char fmat; int base;
3153762Sroot #else
3163762Sroot printdbl(lxy,fmat,base)
3173762Sroot L_INT lxy; char fmat; int base;
3183762Sroot #endif
3193762Sroot {	int digs[20]; int *dptr; char k;
3203762Sroot #ifndef MULD2
3213762Sroot 	register char *cp1;
3223762Sroot 	cp1=digs; if ((lxy&0xFFFF0000L)==0xFFFF0000L) {*cp1++='-'; lxy= -lxy;}
3233762Sroot 	sprintf(cp1,base==16 ? "%X" : "%D",lxy);
3243762Sroot 	cp1=digs; while (*digitptr++= *cp1++); --digitptr;
3253762Sroot #else
3263762Sroot 	L_REAL f ,g; long q;
3273762Sroot #ifdef vax
3283762Sroot 	INT lx,ly;
3293762Sroot 	ly=lxy; lx=(lxy>>16)&0xFFFF;
3303762Sroot #endif
3313762Sroot 	dptr=digs;
3323762Sroot 	IF fmat=='D' ORF fmat=='r'
3333762Sroot 	THEN	f=itol(lx,ly);
3343762Sroot 		IF f<0 THEN *digitptr++='-'; f = -f; FI
3353762Sroot 	ELSE
3363762Sroot 		IF lx==-1
3373762Sroot 		THEN *digitptr++='-'; f=leng(-ly);
3383762Sroot 		ELSE f=leng(lx); f *= itol(1,0); f += leng(ly);
3393762Sroot 		FI
3403762Sroot 		IF fmat=='x' THEN *digitptr++='#'; FI
3413762Sroot 	FI
3423762Sroot 	WHILE f
3433762Sroot 	DO  q=f/base; g=q;
3443762Sroot 	    *dptr++ = f-g*base;
3453762Sroot 	    f=q;
3463762Sroot 	OD
3473762Sroot 	IF dptr==digs ORF dptr[-1]>9 THEN *dptr++=0; FI
3483762Sroot 	WHILE dptr!=digs
3493762Sroot 	DO  k = *--dptr;
3503762Sroot 	    *digitptr++ = (k+(k<=9 ? '0' : 'a'-10));
3513762Sroot 	OD
3523762Sroot #endif
3533762Sroot }
3543762Sroot 
3553762Sroot #define	MAXIFD	5
3563762Sroot struct {
3573762Sroot 	int	fd;
3583762Sroot 	int	r9;
3593762Sroot } istack[MAXIFD];
3603762Sroot int	ifiledepth;
3613762Sroot 
3623762Sroot iclose(stack, err)
3633762Sroot {
3643762Sroot 	IF err
3653762Sroot 	THEN	IF infile
3663762Sroot 		THEN	close(infile); infile=0;
3673762Sroot 		FI
3683762Sroot 		WHILE --ifiledepth >= 0
3693762Sroot 		DO	IF istack[ifiledepth].fd
3703762Sroot 			THEN	close(istack[ifiledepth].fd);
3713762Sroot 			FI
3723762Sroot 		OD
3733762Sroot 		ifiledepth = 0;
3743762Sroot 	ELIF stack == 0
3753762Sroot 	THEN	IF infile
3763762Sroot 		THEN	close(infile); infile=0;
3773762Sroot 		FI
3783762Sroot 	ELIF stack > 0
3793762Sroot 	THEN	IF ifiledepth >= MAXIFD
3803762Sroot 		THEN	error(TOODEEP);
3813762Sroot 		FI
3823762Sroot 		istack[ifiledepth].fd = infile;
3833762Sroot 		istack[ifiledepth].r9 = var[9];
3843762Sroot 		ifiledepth++;
3853762Sroot 		infile = 0;
3863762Sroot 	ELSE	IF infile
3873762Sroot 		THEN	close(infile); infile=0;
3883762Sroot 		FI
3893762Sroot 		IF ifiledepth > 0
3903762Sroot 		THEN	infile = istack[--ifiledepth].fd;
3913762Sroot 			var[9] = istack[ifiledepth].r9;
3923762Sroot 		FI
3933762Sroot 	FI
3943762Sroot }
3953762Sroot 
3963762Sroot oclose()
3973762Sroot {
3983762Sroot 	IF outfile!=1
3993762Sroot 	THEN	flushbuf(); close(outfile); outfile=1;
4003762Sroot 	FI
4013762Sroot }
4023762Sroot 
4033762Sroot endline()
4043762Sroot {
4053762Sroot 
4063762Sroot 	if (maxpos <= charpos())
4073762Sroot 		printf("\n");
4083762Sroot }
409