diff options
Diffstat (limited to 'lib/libcurses/trace/lib_tracechr.c')
-rw-r--r-- | lib/libcurses/trace/lib_tracechr.c | 55 |
1 files changed, 42 insertions, 13 deletions
diff --git a/lib/libcurses/trace/lib_tracechr.c b/lib/libcurses/trace/lib_tracechr.c index f69a9c59a1f..e909ab79262 100644 --- a/lib/libcurses/trace/lib_tracechr.c +++ b/lib/libcurses/trace/lib_tracechr.c @@ -1,5 +1,7 @@ +/* $OpenBSD: lib_tracechr.c,v 1.5 2010/01/12 23:22:07 nicm Exp $ */ + /**************************************************************************** - * Copyright (c) 1998,2000 Free Software Foundation, Inc. * + * Copyright (c) 1998-2007,2008 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * * copy of this software and associated documentation files (the * @@ -29,6 +31,7 @@ /**************************************************************************** * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * * and: Eric S. Raymond <esr@snark.thyrsus.com> * + * and: Thomas E. Dickey 1996-on * ****************************************************************************/ /* @@ -36,23 +39,49 @@ */ #include <curses.priv.h> -MODULE_ID("$From: lib_tracechr.c,v 1.4 2000/12/10 03:02:45 tom Exp $") +#include <ctype.h> + +MODULE_ID("$Id: lib_tracechr.c,v 1.5 2010/01/12 23:22:07 nicm Exp $") #ifdef TRACE + NCURSES_EXPORT(char *) -_tracechar(const unsigned char ch) +_nc_tracechar(SCREEN *sp, int ch) { - static char crep[20]; - (void) snprintf(crep, sizeof(crep), "'%s' = 0x%02x", unctrl(ch), - (unsigned) ch); - return (crep); + NCURSES_CONST char *name; + char *MyBuffer = ((sp != 0) + ? sp->tracechr_buf + : _nc_globals.tracechr_buf); + size_t len = ((sp != 0) + ? _nc_screen_tracechr_buf_size + : _nc_globals_traceatr_color_buf_size); + + if (ch > KEY_MIN || ch < 0) { + name = _nc_keyname(sp, ch); + if (name == 0 || *name == '\0') + name = "NULL"; + (void) snprintf(MyBuffer, len, "'%.30s' = %#03o", name, ch); + } else if (!is8bits(ch) || !isprint(UChar(ch))) { + /* + * workaround for glibc bug: + * sprintf changes the result from unctrl() to an empty string if it + * does not correspond to a valid multibyte sequence. + */ + (void) snprintf(MyBuffer, len, "%#03o", ch); + } else { + name = _nc_unctrl(sp, (chtype) ch); + if (name == 0 || *name == 0) + name = "null"; /* shouldn't happen */ + (void) snprintf(MyBuffer, len, "'%.30s' = %#03o", name, ch); + } + return (MyBuffer); } -#else -extern -NCURSES_EXPORT(void) -_nc_lib_tracechr(void); -NCURSES_EXPORT(void) -_nc_lib_tracechr(void) + +NCURSES_EXPORT(char *) +_tracechar(int ch) { + return _nc_tracechar(SP, ch); } +#else +EMPTY_MODULE(_nc_lib_tracechr) #endif |