150276Speter/****************************************************************************
2184989Srafan * Copyright (c) 1998-2007,2008 Free Software Foundation, Inc.              *
350276Speter *                                                                          *
450276Speter * Permission is hereby granted, free of charge, to any person obtaining a  *
550276Speter * copy of this software and associated documentation files (the            *
650276Speter * "Software"), to deal in the Software without restriction, including      *
750276Speter * without limitation the rights to use, copy, modify, merge, publish,      *
850276Speter * distribute, distribute with modifications, sublicense, and/or sell       *
950276Speter * copies of the Software, and to permit persons to whom the Software is    *
1050276Speter * furnished to do so, subject to the following conditions:                 *
1150276Speter *                                                                          *
1250276Speter * The above copyright notice and this permission notice shall be included  *
1350276Speter * in all copies or substantial portions of the Software.                   *
1450276Speter *                                                                          *
1550276Speter * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS  *
1650276Speter * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF               *
1750276Speter * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.   *
1850276Speter * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,   *
1950276Speter * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR    *
2050276Speter * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR    *
2150276Speter * THE USE OR OTHER DEALINGS IN THE SOFTWARE.                               *
2250276Speter *                                                                          *
2350276Speter * Except as contained in this notice, the name(s) of the above copyright   *
2450276Speter * holders shall not be used in advertising or otherwise to promote the     *
2550276Speter * sale, use or other dealings in this Software without prior written       *
2650276Speter * authorization.                                                           *
2750276Speter ****************************************************************************/
2850276Speter
2950276Speter/****************************************************************************
3050276Speter *  Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995               *
3150276Speter *     and: Eric S. Raymond <esr@snark.thyrsus.com>                         *
32166124Srafan *     and: Thomas E. Dickey                        1996-on                 *
3350276Speter ****************************************************************************/
3450276Speter
3550276Speter/*
3650276Speter *	lib_tracechr.c - Tracing/Debugging routines
3750276Speter */
3850276Speter#include <curses.priv.h>
3950276Speter
40166124Srafan#include <ctype.h>
4150276Speter
42184989SrafanMODULE_ID("$Id: lib_tracechr.c,v 1.19 2008/08/03 15:39:29 tom Exp $")
43166124Srafan
4450276Speter#ifdef TRACE
45174993Srafan
4676726SpeterNCURSES_EXPORT(char *)
47184989Srafan_nc_tracechar(SCREEN *sp, int ch)
4850276Speter{
49166124Srafan    NCURSES_CONST char *name;
50184989Srafan    char *MyBuffer = ((sp != 0)
51184989Srafan		      ? sp->tracechr_buf
52184989Srafan		      : _nc_globals.tracechr_buf);
53166124Srafan
54166124Srafan    if (ch > KEY_MIN || ch < 0) {
55184989Srafan	name = _nc_keyname(sp, ch);
56166124Srafan	if (name == 0 || *name == '\0')
57166124Srafan	    name = "NULL";
58174993Srafan	(void) sprintf(MyBuffer, "'%.30s' = %#03o", name, ch);
59166124Srafan    } else if (!is8bits(ch) || !isprint(UChar(ch))) {
60166124Srafan	/*
61166124Srafan	 * workaround for glibc bug:
62166124Srafan	 * sprintf changes the result from unctrl() to an empty string if it
63166124Srafan	 * does not correspond to a valid multibyte sequence.
64166124Srafan	 */
65174993Srafan	(void) sprintf(MyBuffer, "%#03o", ch);
66166124Srafan    } else {
67184989Srafan	name = _nc_unctrl(sp, (chtype) ch);
68166124Srafan	if (name == 0 || *name == 0)
69166124Srafan	    name = "null";	/* shouldn't happen */
70174993Srafan	(void) sprintf(MyBuffer, "'%.30s' = %#03o", name, ch);
71166124Srafan    }
72174993Srafan    return (MyBuffer);
7350276Speter}
74184989Srafan
75184989SrafanNCURSES_EXPORT(char *)
76184989Srafan_tracechar(int ch)
77184989Srafan{
78184989Srafan    return _nc_tracechar(SP, ch);
79184989Srafan}
8050276Speter#else
81184989SrafanEMPTY_MODULE(_nc_lib_tracechr)
8250276Speter#endif
83