2 * $Id: trace.c,v 1.21 2015/05/29 00:17:11 Matthias.Scheler Exp $
4 * trace.c -- implements screen-dump and keystroke-logging
6 * Copyright 2007-2011,2015 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_win(WINDOW
*win
)
61 WINDOW
*top
= wgetparent(win
);
63 while (top
!= 0 && top
!= stdscr
) {
65 top
= wgetparent(win
);
69 int rc
= getmaxy(win
);
70 int cc
= getmaxx(win
);
73 fprintf(myFP
, "window %dx%d at %d,%d\n",
74 rc
, cc
, getbegy(win
), getbegx(win
));
77 for (j
= 0; j
< rc
; ++j
) {
78 fprintf(myFP
, "%3d:", j
);
79 for (k
= 0; k
< cc
; ++k
) {
80 #ifdef USE_WIDE_CURSES
83 ch
= mvwinch(win
, j
, k
) & (A_CHARTEXT
| A_ALTCHARSET
);
84 if (ch
& A_ALTCHARSET
) {
85 c2
= dlg_asciibox(ch
);
89 buffer
[0] = (char) ch
;
95 if (win_wch(win
, &cch
) == ERR
96 || (uc
= wunctrl((&cch
))) == 0
98 || wcwidth(uc
[0]) <= 0) {
103 const wchar_t *ucp
= uc
;
105 memset(&state
, 0, sizeof(state
));
106 wcsrtombs(buffer
, &ucp
, sizeof(buffer
), &state
);
107 k
+= wcwidth(uc
[0]) - 1;
112 ch
= mvwinch(win
, j
, k
) & (A_CHARTEXT
| A_ALTCHARSET
);
113 c2
= dlg_asciibox(ch
);
116 } else if (unctrl(ch
) == 0 || strlen(unctrl(ch
)) > 1) {
119 fputc((int) (ch
& 0xff), myFP
);
131 dlg_trace_chr(int ch
, int fkey
)
133 static int last_err
= 0;
136 * Do not bother to trace ERR's indefinitely, since those are usually due
137 * to relatively short polling timeouts.
139 if (last_err
&& !fkey
&& ch
== ERR
) {
141 } else if (myFP
!= 0) {
142 const char *fkey_name
= "?";
145 fprintf(myFP
, "skipped %d ERR's\n", last_err
);
150 if (fkey
> KEY_MAX
|| (fkey_name
= keyname(fkey
)) == 0) {
151 #define CASE(name) case name: fkey_name = #name; break
152 switch ((DLG_KEYS_ENUM
) fkey
) {
159 CASE(DLGK_PAGE_FIRST
);
160 CASE(DLGK_PAGE_LAST
);
161 CASE(DLGK_PAGE_NEXT
);
162 CASE(DLGK_PAGE_PREV
);
163 CASE(DLGK_ITEM_FIRST
);
164 CASE(DLGK_ITEM_LAST
);
165 CASE(DLGK_ITEM_NEXT
);
166 CASE(DLGK_ITEM_PREV
);
167 CASE(DLGK_FIELD_FIRST
);
168 CASE(DLGK_FIELD_LAST
);
169 CASE(DLGK_FIELD_NEXT
);
170 CASE(DLGK_FIELD_PREV
);
171 CASE(DLGK_FORM_FIRST
);
172 CASE(DLGK_FORM_LAST
);
173 CASE(DLGK_FORM_NEXT
);
174 CASE(DLGK_FORM_PREV
);
176 CASE(DLGK_GRID_DOWN
);
177 CASE(DLGK_GRID_LEFT
);
178 CASE(DLGK_GRID_RIGHT
);
179 CASE(DLGK_DELETE_LEFT
);
180 CASE(DLGK_DELETE_RIGHT
);
181 CASE(DLGK_DELETE_ALL
);
190 } else if (ch
== ERR
) {
194 fkey_name
= unctrl((chtype
) ch
);
196 fkey_name
= "UNKNOWN";
198 fprintf(myFP
, "chr %s (ch=%#x, fkey=%d)\n",
206 dlg_trace(const char *fname
)
210 myFP
= fopen(fname
, "a");
212 dlg_trace_time("** opened at");
213 dlg_trace_msg("** dialog %s\n", dialog_version());
216 } else if (myFP
!= 0) {
217 dlg_trace_time("** closed at");
224 extern void dlg_trace(const char *);
226 dlg_trace(const char *fname
)