]> ncurses.scripts.mit.edu Git - ncurses.git/blob - ncurses/lib_tracechr.c
ncurses 4.1
[ncurses.git] / ncurses / lib_tracechr.c
1
2 /***************************************************************************
3 *                            COPYRIGHT NOTICE                              *
4 ****************************************************************************
5 *                ncurses is copyright (C) 1992-1995                        *
6 *                          Zeyd M. Ben-Halim                               *
7 *                          zmbenhal@netcom.com                             *
8 *                          Eric S. Raymond                                 *
9 *                          esr@snark.thyrsus.com                           *
10 *                                                                          *
11 *        Permission is hereby granted to reproduce and distribute ncurses  *
12 *        by any means and for any fee, whether alone or as part of a       *
13 *        larger distribution, in source or in binary form, PROVIDED        *
14 *        this notice is included with any such distribution, and is not    *
15 *        removed from any of its header files. Mention of ncurses in any   *
16 *        applications linked with it is highly appreciated.                *
17 *                                                                          *
18 *        ncurses comes AS IS with no warranty, implied or expressed.       *
19 *                                                                          *
20 ***************************************************************************/
21
22
23
24 /*
25  *      lib_tracechr.c - Tracing/Debugging routines
26  */
27
28 #ifndef TRACE
29 #define TRACE                   /* turn on internal defs for this module */
30 #endif
31
32 #include <curses.priv.h>
33
34 #include <ctype.h>
35
36 char *_tracechar(const unsigned char ch)
37 {
38     static char crep[20];
39     /* 
40      * We can show the actual character if it's either an ordinary printable
41      * or one of the high-half characters.
42      */
43     if (isprint(ch) || (ch & 0x80))
44     {
45         crep[0] = '\'';
46         crep[1] = ch;   /* necessary; printf tries too hard on metachars */
47         (void) sprintf(crep + 2, "' = 0x%02x", (unsigned)ch);
48     }
49     else
50         (void) sprintf(crep, "0x%02x", (unsigned)ch);
51     return(crep);
52 }