diff options
Diffstat (limited to 'contrib/dialog/trace.c')
-rw-r--r-- | contrib/dialog/trace.c | 111 |
1 files changed, 88 insertions, 23 deletions
diff --git a/contrib/dialog/trace.c b/contrib/dialog/trace.c index a742ae8..50ccfac 100644 --- a/contrib/dialog/trace.c +++ b/contrib/dialog/trace.c @@ -1,5 +1,5 @@ /* - * $Id: trace.c,v 1.14 2011/06/21 21:12:56 tom Exp $ + * $Id: trace.c,v 1.20 2011/10/18 10:47:26 tom Exp $ * * trace.c -- implements screen-dump and keystroke-logging * @@ -24,6 +24,10 @@ #ifdef HAVE_DLG_TRACE +#ifdef NEED_WCHAR_H +#include <wchar.h> +#endif + #include <dlg_keys.h> #include <time.h> @@ -54,38 +58,94 @@ dlg_trace_win(WINDOW *win) if (myFP != 0) { int y, x; int j, k; - int rc = getmaxy(win); - int cc = getmaxx(win); - chtype ch, c2; - - fprintf(myFP, "window %dx%d at %d,%d\n", - rc, cc, getbegy(win), getbegx(win)); - - getyx(win, y, x); - for (j = 0; j < rc; ++j) { - fprintf(myFP, "%3d:", j); - for (k = 0; k < cc; ++k) { - ch = mvwinch(win, j, k) & (A_CHARTEXT | A_ALTCHARSET); - c2 = dlg_asciibox(ch); - if (c2 != 0) { - ch = c2; - } else if (unctrl(ch) == 0 || strlen(unctrl(ch)) > 1) { - ch = '.'; + WINDOW *top = wgetparent(win); + + while (top != 0 && top != stdscr) { + win = top; + top = wgetparent(win); + } + + if (win != 0) { + int rc = getmaxy(win); + int cc = getmaxx(win); + chtype ch, c2; + + fprintf(myFP, "window %dx%d at %d,%d\n", + rc, cc, getbegy(win), getbegx(win)); + + getyx(win, y, x); + for (j = 0; j < rc; ++j) { + fprintf(myFP, "%3d:", j); + for (k = 0; k < cc; ++k) { +#ifdef USE_WIDE_CURSES + char buffer[80]; + + ch = mvwinch(win, j, k) & (A_CHARTEXT | A_ALTCHARSET); + if (ch & A_ALTCHARSET) { + c2 = dlg_asciibox(ch); + if (c2 != 0) { + ch = c2; + } + buffer[0] = (char) ch; + buffer[1] = '\0'; + } else { + cchar_t cch; + wchar_t *uc; + + if (win_wch(win, &cch) == ERR + || (uc = wunctrl(&cch)) == 0 + || uc[1] != 0 + || wcwidth(uc[0]) <= 0) { + buffer[0] = '.'; + buffer[1] = '\0'; + } else { + mbstate_t state; + const wchar_t *ucp = uc; + + memset(&state, 0, sizeof(state)); + wcsrtombs(buffer, &ucp, sizeof(buffer), &state); + k += wcwidth(uc[0]) - 1; + } + } + fputs(buffer, myFP); +#else + ch = mvwinch(win, j, k) & (A_CHARTEXT | A_ALTCHARSET); + c2 = dlg_asciibox(ch); + if (c2 != 0) { + ch = c2; + } else if (unctrl(ch) == 0 || strlen(unctrl(ch)) > 1) { + ch = '.'; + } + fputc((int) (ch & 0xff), myFP); +#endif } - fputc((int) (ch & 0xff), myFP); + fputc('\n', myFP); } - fputc('\n', myFP); + wmove(win, y, x); + fflush(myFP); } - wmove(win, y, x); - fflush(myFP); } } void dlg_trace_chr(int ch, int fkey) { - if (myFP != 0) { + static int last_err = 0; + + /* + * Do not bother to trace ERR's indefinitely, since those are usually due + * to relatively short polling timeouts. + */ + if (last_err && !fkey && ch == ERR) { + ++last_err; + } else if (myFP != 0) { const char *fkey_name = "?"; + + if (last_err) { + fprintf(myFP, "skipped %d ERR's\n", last_err); + last_err = 0; + } + if (fkey) { if (fkey > KEY_MAX || (fkey_name = keyname(fkey)) == 0) { #define CASE(name) case name: fkey_name = #name; break @@ -108,6 +168,10 @@ dlg_trace_chr(int ch, int fkey) CASE(DLGK_FIELD_LAST); CASE(DLGK_FIELD_NEXT); CASE(DLGK_FIELD_PREV); + CASE(DLGK_FORM_FIRST); + CASE(DLGK_FORM_LAST); + CASE(DLGK_FORM_NEXT); + CASE(DLGK_FORM_PREV); CASE(DLGK_GRID_UP); CASE(DLGK_GRID_DOWN); CASE(DLGK_GRID_LEFT); @@ -125,6 +189,7 @@ dlg_trace_chr(int ch, int fkey) } } else if (ch == ERR) { fkey_name = "ERR"; + last_err = 1; } else { fkey_name = unctrl((chtype) ch); if (fkey_name == 0) |