- static char crep[20];
- /*
- * We can show the actual character if it's either an ordinary printable
- * or one of the high-half characters.
- */
- if (isprint(ch) || (ch & 0x80))
- {
- crep[0] = '\'';
- crep[1] = ch; /* necessary; printf tries too hard on metachars */
- (void) sprintf(crep + 2, "' = 0x%02x", (unsigned)ch);
+ NCURSES_CONST char *name;
+ char *MyBuffer = ((sp != 0)
+ ? sp->tracechr_buf
+ : _nc_globals.tracechr_buf);
+
+ if (ch > KEY_MIN || ch < 0) {
+ name = safe_keyname(SP_PARM, ch);
+ if (name == 0 || *name == '\0')
+ name = "NULL";
+ _nc_SPRINTF(MyBuffer, _nc_SLIMIT(MyBufSize)
+ "'%.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.
+ */
+ _nc_SPRINTF(MyBuffer, _nc_SLIMIT(MyBufSize)
+ "%#03o", ch);
+ } else {
+ name = safe_unctrl(SP_PARM, (chtype) ch);
+ if (name == 0 || *name == 0)
+ name = "null"; /* shouldn't happen */
+ _nc_SPRINTF(MyBuffer, _nc_SLIMIT(MyBufSize)
+ "'%.30s' = %#03o", name, ch);