1 /****************************************************************************
2 * Copyright 2018-2020,2023 Thomas E. Dickey *
4 * Permission is hereby granted, free of charge, to any person obtaining a *
5 * copy of this software and associated documentation files (the *
6 * "Software"), to deal in the Software without restriction, including *
7 * without limitation the rights to use, copy, modify, merge, publish, *
8 * distribute, distribute with modifications, sublicense, and/or sell *
9 * copies of the Software, and to permit persons to whom the Software is *
10 * furnished to do so, subject to the following conditions: *
12 * The above copyright notice and this permission notice shall be included *
13 * in all copies or substantial portions of the Software. *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
16 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
18 * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
19 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
20 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
21 * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
23 * Except as contained in this notice, the name(s) of the above copyright *
24 * holders shall not be used in advertising or otherwise to promote the *
25 * sale, use or other dealings in this Software without prior written *
27 ****************************************************************************/
29 * $Id: dump_window.c,v 1.5 2023/11/11 00:30:50 tom Exp $
31 #include <dump_window.h>
36 open_dump(const char *fn)
40 if ((dumpfp = fopen(fn, "a")) != 0)
55 dump_window(WINDOW *w)
72 fprintf(dumpfp, "Window %p\n", (void *) w);
75 getmaxyx(w, maxy, maxx);
76 fprintf(dumpfp, "size (%dx%d)\n", maxy, maxx);
78 fprintf(dumpfp, "begin (%dx%d)\n", maxy, maxx);
80 fprintf(dumpfp, "position (%d,%d)\n", y, x);
82 if (maxy > 0 && maxx > 0) {
83 for (pass = 0; pass < 2; ++pass) {
84 for (y = 0; y < maxy; ++y) {
87 memset(cvec, 0, (size_t) maxx + 1);
89 memset(avec, 0, (size_t) maxx + 1);
91 memset(pvec, 0, (size_t) maxx + 1);
93 for (x = 0; x < maxx; ++x) {
94 chtype data = mvwinch(w, y, x);
96 char cc = (char) ((data & 0xff) ? (data & 0xff) : ' ');
100 temp = ((data & A_ATTRIBUTES) & (chtype) (~A_COLOR));
102 if (temp & A_ALTCHARSET) {
103 aa = (temp & A_BOLD) ? 'A' : 'a';
104 } else if (temp & A_STANDOUT) {
105 aa = (temp & A_BOLD) ? 'S' : 's';
106 } else if (temp & A_REVERSE) {
107 aa = (temp & A_BOLD) ? 'R' : 'r';
108 } else if (temp & A_UNDERLINE) {
109 aa = (temp & A_BOLD) ? 'U' : 'u';
111 aa = (temp & A_BOLD) ? 'b' : '?';
116 if (data & A_COLOR) {
117 if (PAIR_NUMBER((int) data) < 8) {
118 pp = (char) ('0' + PAIR_NUMBER((int) data));
134 if (cc != ' ' || aa != ' ' || pp != ' ') {
146 fprintf(dumpfp, "%3d", y + 1);
148 fprintf(dumpfp, "\tc|%.*s|\n", maxx, cvec);
150 fprintf(dumpfp, "\ta|%.*s|\n", maxx, avec);
152 fprintf(dumpfp, "\tp|%.*s|\n", maxx, pvec);
160 fprintf(dumpfp, "%d cells with characters\n", ccnt);
161 fprintf(dumpfp, "%d cells with video-attributes\n", acnt);
162 fprintf(dumpfp, "%d cells with color-attributes\n", pcnt);
163 if (endy < 0 || endx < 0)
165 /* reduce the dump a little, ignore really blank cells */
169 cvec = malloc((size_t) maxx + 1);
171 avec = malloc((size_t) maxx + 1);
173 pvec = malloc((size_t) maxx + 1);
177 wmove(w, oldy, oldx);