xref: /csrg-svn/old/lib2648/rdchar.c (revision 11490)
1*11490Sralph /*	rdchar.c	4.1	83/03/09	*/
2*11490Sralph /*
3*11490Sralph  * rdchar: returns a readable representation of an ASCII char, using ^ notation.
4*11490Sralph  */
5*11490Sralph 
6*11490Sralph #include <ctype.h>
7*11490Sralph 
8*11490Sralph char *rdchar(c)
9*11490Sralph char c;
10*11490Sralph {
11*11490Sralph 	static char ret[4];
12*11490Sralph 	register char *p;
13*11490Sralph 
14*11490Sralph 	/*
15*11490Sralph 	 * Due to a bug in isprint, this prints spaces as ^`, but this is OK
16*11490Sralph 	 * because we want something to show up on the screen.
17*11490Sralph 	 */
18*11490Sralph 	ret[0] = ((c&0377) > 0177) ? '\'' : ' ';
19*11490Sralph 	c &= 0177;
20*11490Sralph 	ret[1] = isprint(c) ? ' ' : '^';
21*11490Sralph 	ret[2] = isprint(c) ?  c  : c^0100;
22*11490Sralph 	ret[3] = 0;
23*11490Sralph 	for (p=ret; *p==' '; p++)
24*11490Sralph 		;
25*11490Sralph 	return (p);
26*11490Sralph }
27