h24893
s 00084/00000/00000
d D 1.1 80/05/15 14:26:54 lcd 1 0
e
u
sunix
lcd
U
t
T
I 1
#

#include "globals.h"
#include <stdio.h>

/*
 *	format.c: format output to terminal
 */

CONST	char	*_S_format	"%W%";

/*
 *	format: format and print to terminal
 */

PROCEDURE format( src, last )

CONST	char	src[];
	boolean	last;

BEGIN	VAR	integer	pword;

	/*	printf("%o,%o\n", (src[0]&0377), (src[1]&0377) );	*/
	pword = ( src[0]&0377 ) + ( src[1]*256 );

	CASE mode OF

	case OCTAL	: BEGIN
				printf("%o\n",pword);
			  ENDCASE;
	case HEX	: BEGIN
				printf("%x\n",pword);
			  ENDCASE;
	case DECIMAL	: BEGIN
				printf("%d\n",pword);
			  ENDCASE;
	case BYTE	: BEGIN
				printf("%o\n", (src[0]&0377) );
			  ENDCASE;
	case CHAR	: BEGIN
				IF src[0] < blank
				THEN	printf("\\%o", (src[0]&0377) );
				ELSE	putchar( src[0] );
				END;

				IF last
				THEN	putchar( eoln );
				END;
			  ENDCASE;
	END;
END

/*
 *	setmode: set mode of print outs
 */

PROCEDURE setmode()

BEGIN	VAR	char	word[ MAXLINELENGTH ];

	getword( word );

	CASE word[0] OF

	case 'o'	: BEGIN	mode = OCTAL;
				step = 2;
			  ENDCASE;
	case 'h'	: BEGIN	mode = HEX;
				step = 2;
			  ENDCASE;
	case 'd'	: BEGIN	mode = DECIMAL;
				step = 2;
			  ENDCASE;
	case 'b'	: BEGIN mode = BYTE;
				step = 1;
			  ENDCASE;
	case 'c'	: BEGIN mode = CHAR;
				step = 1;
			  ENDCASE;
	default		: BEGIN	mode = OCTAL;
				step = 2;
			  ENDCASE;
	END;
END
E 1
