xref: /csrg-svn/old/lib2648/rdchar.c (revision 18782)
111490Sralph /*
2*18782Sdist  * Copyright (c) 1980 Regents of the University of California.
3*18782Sdist  * All rights reserved.  The Berkeley software License Agreement
4*18782Sdist  * specifies the terms and conditions for redistribution.
5*18782Sdist  */
6*18782Sdist 
7*18782Sdist #ifndef lint
8*18782Sdist static char sccsid[] = "@(#)rdchar.c	5.1 (Berkeley) 04/26/85";
9*18782Sdist #endif not lint
10*18782Sdist 
11*18782Sdist /*
1211490Sralph  * rdchar: returns a readable representation of an ASCII char, using ^ notation.
1311490Sralph  */
1411490Sralph 
1511490Sralph #include <ctype.h>
1611490Sralph 
rdchar(c)1711490Sralph char *rdchar(c)
1811490Sralph char c;
1911490Sralph {
2011490Sralph 	static char ret[4];
2111490Sralph 	register char *p;
2211490Sralph 
2311490Sralph 	/*
2411490Sralph 	 * Due to a bug in isprint, this prints spaces as ^`, but this is OK
2511490Sralph 	 * because we want something to show up on the screen.
2611490Sralph 	 */
2711490Sralph 	ret[0] = ((c&0377) > 0177) ? '\'' : ' ';
2811490Sralph 	c &= 0177;
2911490Sralph 	ret[1] = isprint(c) ? ' ' : '^';
3011490Sralph 	ret[2] = isprint(c) ?  c  : c^0100;
3111490Sralph 	ret[3] = 0;
3211490Sralph 	for (p=ret; *p==' '; p++)
3311490Sralph 		;
3411490Sralph 	return (p);
3511490Sralph }
36