2 * $Id: trace.c,v 1.26 2018/06/13 00:06:48 tom Exp $
4 * trace.c -- implements screen-dump and keystroke-logging
6 * Copyright 2007-2017,2018 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.
34 #define myFP dialog_state.trace_output
37 dlg_trace_time(const char *tag)
39 time_t now = time((time_t *) 0);
40 fprintf(myFP, "%s %s", tag, ctime(&now));
44 dlg_trace_msg(const char *fmt,...)
49 vfprintf(myFP, fmt, ap);
56 dlg_trace_2s(const char *name, const char *value)
65 while (value[right] != '\0') {
67 if ((next = strchr(value, '\n')) != 0) {
68 left = (int) (next - value);
71 left = (int) strlen(value);
76 dlg_trace_msg("#%14s=%.*s\n", name, left, value);
78 dlg_trace_msg("#+\t\t%.*s\n", left, value);
84 dlg_trace_2n(const char *name, int value)
86 dlg_trace_msg("#\t%7s=%d\n", name, value);
90 dlg_trace_win(WINDOW *win)
95 WINDOW *top = wgetparent(win);
97 while (top != 0 && top != stdscr) {
99 top = wgetparent(win);
103 int rc = getmaxy(win);
104 int cc = getmaxx(win);
107 fprintf(myFP, "window %dx%d at %d,%d\n",
108 rc, cc, getbegy(win), getbegx(win));
111 for (j = 0; j < rc; ++j) {
112 fprintf(myFP, "%3d:", j);
113 for (k = 0; k < cc; ++k) {
114 #ifdef USE_WIDE_CURSES
117 ch = mvwinch(win, j, k) & (A_CHARTEXT | A_ALTCHARSET);
118 if (ch & A_ALTCHARSET) {
119 c2 = dlg_asciibox(ch);
123 buffer[0] = (char) ch;
129 if (win_wch(win, &cch) == ERR
130 || (uc = wunctrl((&cch))) == 0
132 || wcwidth(uc[0]) <= 0) {
137 const wchar_t *ucp = uc;
139 memset(&state, 0, sizeof(state));
140 wcsrtombs(buffer, &ucp, sizeof(buffer), &state);
141 k += wcwidth(uc[0]) - 1;
146 ch = mvwinch(win, j, k) & (A_CHARTEXT | A_ALTCHARSET);
147 c2 = dlg_asciibox(ch);
150 } else if (unctrl(ch) == 0 || strlen(unctrl(ch)) > 1) {
153 fputc((int) (ch & 0xff), myFP);
165 dlg_trace_chr(int ch, int fkey)
167 static int last_err = 0;
170 * Do not bother to trace ERR's indefinitely, since those are usually due
171 * to relatively short polling timeouts.
173 if (last_err && !fkey && ch == ERR) {
175 } else if (myFP != 0) {
176 const char *fkey_name = "?";
179 fprintf(myFP, "skipped %d ERR's\n", last_err);
184 if (fkey > KEY_MAX || (fkey_name = keyname(fkey)) == 0) {
185 #define CASE(name) case name: fkey_name = #name; break
186 switch ((DLG_KEYS_ENUM) fkey) {
193 CASE(DLGK_PAGE_FIRST);
194 CASE(DLGK_PAGE_LAST);
195 CASE(DLGK_PAGE_NEXT);
196 CASE(DLGK_PAGE_PREV);
197 CASE(DLGK_ITEM_FIRST);
198 CASE(DLGK_ITEM_LAST);
199 CASE(DLGK_ITEM_NEXT);
200 CASE(DLGK_ITEM_PREV);
201 CASE(DLGK_FIELD_FIRST);
202 CASE(DLGK_FIELD_LAST);
203 CASE(DLGK_FIELD_NEXT);
204 CASE(DLGK_FIELD_PREV);
205 CASE(DLGK_FORM_FIRST);
206 CASE(DLGK_FORM_LAST);
207 CASE(DLGK_FORM_NEXT);
208 CASE(DLGK_FORM_PREV);
210 CASE(DLGK_GRID_DOWN);
211 CASE(DLGK_GRID_LEFT);
212 CASE(DLGK_GRID_RIGHT);
213 CASE(DLGK_DELETE_LEFT);
214 CASE(DLGK_DELETE_RIGHT);
215 CASE(DLGK_DELETE_ALL);
225 } else if (ch == ERR) {
229 fkey_name = unctrl((chtype) ch);
231 fkey_name = "UNKNOWN";
234 fprintf(myFP, "chr %s (ch=%#x, fkey=%d)\n", fkey_name, ch, fkey);
236 fprintf(myFP, "chr %s (ch=%d, fkey=%d)\n", fkey_name, ch, fkey);
243 dlg_trace(const char *fname)
247 myFP = fopen(fname, "a");
249 dlg_trace_time("## opened at");
250 DLG_TRACE(("## dialog %s\n", dialog_version()));
251 DLG_TRACE(("## vile: confmode\n"));
254 } else if (myFP != 0) {
255 dlg_trace_time("## closed at");
262 extern void dlg_trace(const char *);
264 dlg_trace(const char *fname)