xref: /original-bsd/old/lib2648/rdchar.c (revision e59fb703)
1 /*
2  * Copyright (c) 1980 Regents of the University of California.
3  * All rights reserved.  The Berkeley software License Agreement
4  * specifies the terms and conditions for redistribution.
5  */
6 
7 #ifndef lint
8 static char sccsid[] = "@(#)rdchar.c	5.1 (Berkeley) 04/26/85";
9 #endif not lint
10 
11 /*
12  * rdchar: returns a readable representation of an ASCII char, using ^ notation.
13  */
14 
15 #include <ctype.h>
16 
17 char *rdchar(c)
18 char c;
19 {
20 	static char ret[4];
21 	register char *p;
22 
23 	/*
24 	 * Due to a bug in isprint, this prints spaces as ^`, but this is OK
25 	 * because we want something to show up on the screen.
26 	 */
27 	ret[0] = ((c&0377) > 0177) ? '\'' : ' ';
28 	c &= 0177;
29 	ret[1] = isprint(c) ? ' ' : '^';
30 	ret[2] = isprint(c) ?  c  : c^0100;
31 	ret[3] = 0;
32 	for (p=ret; *p==' '; p++)
33 		;
34 	return (p);
35 }
36