2 * $Id: trace.c,v 1.14 2011/06/21 21:12:56 tom Exp $
4 * trace.c -- implements screen-dump and keystroke-logging
6 * Copyright 2007-2010,2011 Thomas E. Dickey
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU Lesser General Public License, version 2.1
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this program; if not, write to
18 * Free Software Foundation, Inc.
19 * 51 Franklin St., Fifth Floor
20 * Boston, MA 02110, USA.
30 #define myFP dialog_state.trace_output
33 dlg_trace_time(const char *tag)
35 time_t now = time((time_t *) 0);
36 fprintf(myFP, "%s %s", tag, ctime(&now));
40 dlg_trace_msg(const char *fmt,...)
45 vfprintf(myFP, fmt, ap);
52 dlg_trace_win(WINDOW *win)
57 int rc = getmaxy(win);
58 int cc = getmaxx(win);
61 fprintf(myFP, "window %dx%d at %d,%d\n",
62 rc, cc, getbegy(win), getbegx(win));
65 for (j = 0; j < rc; ++j) {
66 fprintf(myFP, "%3d:", j);
67 for (k = 0; k < cc; ++k) {
68 ch = mvwinch(win, j, k) & (A_CHARTEXT | A_ALTCHARSET);
69 c2 = dlg_asciibox(ch);
72 } else if (unctrl(ch) == 0 || strlen(unctrl(ch)) > 1) {
75 fputc((int) (ch & 0xff), myFP);
85 dlg_trace_chr(int ch, int fkey)
88 const char *fkey_name = "?";
90 if (fkey > KEY_MAX || (fkey_name = keyname(fkey)) == 0) {
91 #define CASE(name) case name: fkey_name = #name; break
92 switch ((DLG_KEYS_ENUM) fkey) {
99 CASE(DLGK_PAGE_FIRST);
100 CASE(DLGK_PAGE_LAST);
101 CASE(DLGK_PAGE_NEXT);
102 CASE(DLGK_PAGE_PREV);
103 CASE(DLGK_ITEM_FIRST);
104 CASE(DLGK_ITEM_LAST);
105 CASE(DLGK_ITEM_NEXT);
106 CASE(DLGK_ITEM_PREV);
107 CASE(DLGK_FIELD_FIRST);
108 CASE(DLGK_FIELD_LAST);
109 CASE(DLGK_FIELD_NEXT);
110 CASE(DLGK_FIELD_PREV);
112 CASE(DLGK_GRID_DOWN);
113 CASE(DLGK_GRID_LEFT);
114 CASE(DLGK_GRID_RIGHT);
115 CASE(DLGK_DELETE_LEFT);
116 CASE(DLGK_DELETE_RIGHT);
117 CASE(DLGK_DELETE_ALL);
126 } else if (ch == ERR) {
129 fkey_name = unctrl((chtype) ch);
131 fkey_name = "UNKNOWN";
133 fprintf(myFP, "chr %s (ch=%#x, fkey=%d)\n",
141 dlg_trace(const char *fname)
145 myFP = fopen(fname, "a");
147 dlg_trace_time("** opened at");
148 dlg_trace_msg("** dialog %s\n", dialog_version());
151 } else if (myFP != 0) {
152 dlg_trace_time("** closed at");
159 extern void dlg_trace(const char *);
161 dlg_trace(const char *fname)