blob: 95b2142ee6af005e24d725b645456b61d241475d [file] [log] [blame]
micky3879b9f5e72025-07-08 18:04:53 -04001.\"***************************************************************************
2.\" Copyright 2018-2023,2024 Thomas E. Dickey *
3.\" Copyright 2017 Free Software Foundation, Inc. *
4.\" *
5.\" Permission is hereby granted, free of charge, to any person obtaining a *
6.\" copy of this software and associated documentation files (the *
7.\" "Software"), to deal in the Software without restriction, including *
8.\" without limitation the rights to use, copy, modify, merge, publish, *
9.\" distribute, distribute with modifications, sublicense, and/or sell *
10.\" copies of the Software, and to permit persons to whom the Software is *
11.\" furnished to do so, subject to the following conditions: *
12.\" *
13.\" The above copyright notice and this permission notice shall be included *
14.\" in all copies or substantial portions of the Software. *
15.\" *
16.\" THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
17.\" OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
18.\" MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
19.\" IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
20.\" DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
21.\" OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
22.\" THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
23.\" *
24.\" Except as contained in this notice, the name(s) of the above copyright *
25.\" holders shall not be used in advertising or otherwise to promote the *
26.\" sale, use or other dealings in this Software without prior written *
27.\" authorization. *
28.\"***************************************************************************
29.\"
30.\" $Id: scr_dump.5,v 1.46 2024/03/23 20:42:29 tom Exp $
31.TH scr_dump 5 2024-03-23 "ncurses @NCURSES_MAJOR@.@NCURSES_MINOR@" "File formats"
32.ie \n(.g \{\
33.ds `` \(lq
34.ds '' \(rq
35.\}
36.el \{\
37.ie t .ds `` ``
38.el .ds `` ""
39.ie t .ds '' ''
40.el .ds '' ""
41.\}
42.
43.de bP
44.ie n .IP \(bu 4
45.el .IP \(bu 2
46..
47.SH NAME
48scr_dump \-
49\fIcurses\fR screen dump
50.\"SH SYNOPSIS
51.SH DESCRIPTION
52The curses library provides applications with the ability to write the
53contents of a window to an external file using \fBscr_dump\fP or \fBputwin\fP,
54and read it back using \fBscr_restore\fP or \fBgetwin\fP.
55.PP
56The \fBputwin\fP and \fBgetwin\fP functions do the work;
57while \fBscr_dump\fP and \fBscr_restore\fP conveniently save and restore
58the whole screen, i.e., \fBstdscr\fP.
59.SS ncurses6
60A longstanding implementation of screen-dump was
61revised with ncurses6 to remedy problems with the earlier approach:
62.IP \(bu 4
63A \*(``magic number\*('' is written to the beginning of the dump file,
64allowing applications (such as \fBfile\fP(1)) to recognize curses dump files.
65.IP
66Because ncurses6 uses a new format,
67that requires a new magic number
68was unused by other applications.
69This 16-bit number was unused:
70.RS 4
71.PP
72.RS 4
73.EX
740x8888 (octal \*(``\e210\e210\*('')
75.EE
76.RE
77.PP
78but to be more certain, this 32-bit number was chosen:
79.PP
80.RS 4
81.EX
820x88888888 (octal \*(``\e210\e210\e210\e210\*('')
83.EE
84.RE
85.PP
86This is the pattern submitted to the maintainers of the \fBfile\fP program:
87.PP
88.RS 4
89.EX
90#
91# ncurses5 (and before) did not use a magic number,
92# making screen dumps "data".
93#
94# ncurses6 (2015) uses this format, ignoring byte-order
950 string \e210\e210\e210\e210ncurses ncurses6 screen image
96#
97.EE
98.RE
99.RE
100.bP
101The screen dumps are written in textual form,
102so that internal data sizes are not directly related to the dump-format, and
103enabling the library to read dumps from either narrow- or wide-character-
104configurations.
105.IP
106The \fInarrow\fP library configuration holds characters and video attributes
107in a 32-bit \fBchtype\fP, while the \fIwide-character\fP library stores
108this information in the \fBcchar_t\fP structure, which is much larger than
10932-bits.
110.bP
111It is possible to read a screen dump into a terminal with a different
112screen-size,
113because the library truncates or fills the screen as necessary.
114.bP
115The ncurses6 \fBgetwin\fP reads the legacy screen dumps from ncurses5.
116.SS "ncurses5 (Legacy)"
117The screen-dump feature was added to \fI\%ncurses\fP in June 1995.
118While there were fixes and improvements in succeeding years,
119the basic scheme was unchanged:
120.bP
121The \fI\%WINDOW\fP structure was written in binary form.
122.bP
123The \fI\%WINDOW\fP structure refers to lines of data,
124which were written as an array of binary data following the \fI\%WINDOW\fP.
125.bP
126When \fBgetwin\fP restored the window,
127it would keep track of offsets into the array of line-data
128and adjust the \fI\%WINDOW\fP structure which was read back into memory.
129.PP
130This is similar to Unix System\ V,
131but does not write a \*(``magic number\*('' to identify the file format.
132.SH PORTABILITY
133There is no standard format for
134.I curses
135screen dumps.
136A brief survey of the existing implementations follows.
137.SS "X/Open Curses"
138X/Open Curses, Issue 7 specifies little.
139It says
140(boldface emphasis added)
141.RS 3
142.PP
143\*(``[t]he \fI\%getwin()\fP function reads window-related data stored in
144the file by \fI\%putwin()\fP.
145The function then creates and initializes a new window using that data.
146.PP
147The \fI\%putwin()\fP function writes all data associated with \fIwin\fP
148into the \fI\%stdio\fP stream to which \fIfilep\fP points,
149using an \fBunspecified format\fP.
150This information can be retrieved later using \fI\%getwin()\fP.\*(''
151.RE
152.PP
153In the mid-1990s when the X/Open Curses document was written,
154there were still System\ V systems using older,
155less capable
156.I curses
157libraries.
158BSD
159.I curses
160was not relevant to X/Open because it did not meet the criteria
161for base-level conformance;
162see \fB\%ncurses\fP(3X).
163.SS "System V"
164System\ V
165.I curses
166identified the file format by writing a \*(``magic number\*('' at the
167beginning of the dump.
168The \fI\%WINDOW\fP data and the lines of text follow, all in binary form.
169.PP
170Solaris
171.I curses
172has the following definitions.
173.PP
174.RS 4
175.EX
176/* terminfo magic number */
177#define MAGNUM 0432
178
179/* curses screen dump magic number */
180#define SVR2_DUMP_MAGIC_NUMBER 0433
181#define SVR3_DUMP_MAGIC_NUMBER 0434
182.EE
183.RE
184.PP
185That is, the feature was likely introduced in SVr2 (1984),
186and improved in SVr3 (1987).
187Solaris
188.I curses
189has no magic number for SVr4 (1989).
190Other System\ V operating systems
191(AIX and HP-UX)
192use a magic number that would correspond to the following.
193.PP
194.RS 4
195.EX
196/* curses screen dump magic number */
197#define SVR4_DUMP_MAGIC_NUMBER 0435
198.EE
199.RE
200.PP
201That octal number in bytes is 001, 035.
202Because most Unix vendors at the time used big-endian hardware,
203the magic number is written with the high-order byte first.
204.PP
205.RS 4
206.EX
207\e001\e035
208.EE
209.RE
210.PP
211After the magic number,
212the \fI\%WINDOW\fP structure and line data are written in binary format.
213While the magic number used by these systems can be observed with
214\fIod\fP(1),
215none of them documents the format used for screen dumps.
216.PP
217Nor do they use an identical format,
218even with the System\ V family.
219The
220.I \%ncurses
221.I \%savescreen
222test program was used to collect information for this manual page.
223It produced dumps of different size
224(all on 64-bit hardware,
225on 40x80 screens):
226.bP
227AIX (51817 bytes)
228.bP
229HP-UX (90093 bytes)
230.bP
231Solaris 10 (13273 bytes)
232.bP
233\fI\%ncurses\fP5 (12888 bytes)
234.SS Solaris
235As noted above,
236Solaris
237.I curses
238has no magic number corresponding to SVr4
239.IR curses .
240This is odd,
241since Solaris was the first operating system to meet the SVr4
242guidelines.
243Solaris furthermore supplies two versions of
244.IR curses .
245.bP
246The default
247.I curses
248library uses the SVr3 magic number.
249.bP
250An alternate
251.I curses
252library
253(which we term
254.I \%xcurses),
255available in
256.IR /usr/xpg4 ,
257uses a textual format with no magic number.
258.IP
259According to its copyright notice,
260this
261.I \%xcurses
262library was developed by MKS
263(Mortice Kern Systems) from 1990 to 1995.
264.IP
265Like ncurses6,
266it includes a header with parameters.
267Unlike ncurses6,
268the contents of the window are written piecemeal,
269with coordinates and attributes for each chunk of text rather than
270writing the whole window from top to bottom.
271.SS PDCurses
272.I \%PDCurses
273added support for screen dumps in version 2.7 (2005).
274Like System\ V and ncurses5,
275it writes the \fI\%WINDOW\fP structure in binary,
276but begins the file with its three-byte identifier \*(``PDC\*('',
277followed by a single-byte version number.
278.PP
279.RS 4
280.EX
281 \*(``PDC\e001\*(''
282.EE
283.RE
284.SS NetBSD
285As of April 2017,
286NetBSD
287.I curses
288does not support \fB\%scr_dump\fP and \fB\%scr_restore\fP
289(or \fB\%scr_init\fP,
290\fB\%scr_set\fP),
291although it has \fB\%putwin\fP and \fB\%getwin\fP.
292.PP
293Like ncurses5,
294NetBSD \fB\%putwin\fP does not identify its dumps with a useful magic
295number.
296It writes
297.bP
298the
299.I curses
300shared library major and minor versions as the first two bytes
301(for example,
3027 and 1),
303.bP
304followed by a binary dump of the \fI\%WINDOW\fP,
305.bP
306some data for wide characters referenced by the \fI\%WINDOW\fP
307structure,
308and
309.bP
310finally,
311lines as done by other implementations.
312.SH EXAMPLES
313Given a simple program which writes text to the screen
314(and for the sake of example, limiting the screen-size to 10x20):
315.PP
316.RS 4
317.EX
318#include <curses.h>
319
320int
321main(void)
322{
323 putenv("LINES=10");
324 putenv("COLUMNS=20");
325 initscr();
326 start_color();
327 init_pair(1, COLOR_WHITE, COLOR_BLUE);
328 init_pair(2, COLOR_RED, COLOR_BLACK);
329 bkgd(COLOR_PAIR(1));
330 move(4, 5);
331 attron(A_BOLD);
332 addstr("Hello");
333 move(5, 5);
334 attroff(A_BOLD);
335 attrset(A_REVERSE | COLOR_PAIR(2));
336 addstr("World!");
337 refresh();
338 scr_dump("foo.out");
339 endwin();
340 return 0;
341}
342.EE
343.RE
344.PP
345When run using ncurses6, the output looks like this:
346.PP
347.RS 4
348.EX
349\e210\e210\e210\e210ncurses 6.0.20170415
350_cury=5
351_curx=11
352_maxy=9
353_maxx=19
354_flags=14
355_attrs=\e{REVERSE|C2}
356flag=_idcok
357_delay=-1
358_regbottom=9
359_bkgrnd=\e{NORMAL|C1}\es
360rows:
3611:\e{NORMAL|C1}\es\es\es\es\es\es\es\es\es\es\es\es\es\es\es\es\es\es\es\es
3622:\es\es\es\es\es\es\es\es\es\es\es\es\es\es\es\es\es\es\es\es
3633:\es\es\es\es\es\es\es\es\es\es\es\es\es\es\es\es\es\es\es\es
3644:\es\es\es\es\es\es\es\es\es\es\es\es\es\es\es\es\es\es\es\es
3655:\es\es\es\es\es\e{BOLD}Hello\e{NORMAL}\es\es\es\es\es\es\es\es\es\es
3666:\es\es\es\es\es\e{REVERSE|C2}World!\e{NORMAL|C1}\es\es\es\es\es\es\es\es\es
3677:\es\es\es\es\es\es\es\es\es\es\es\es\es\es\es\es\es\es\es\es
3688:\es\es\es\es\es\es\es\es\es\es\es\es\es\es\es\es\es\es\es\es
3699:\es\es\es\es\es\es\es\es\es\es\es\es\es\es\es\es\es\es\es\es
37010:\es\es\es\es\es\es\es\es\es\es\es\es\es\es\es\es\es\es\es\es
371.EE
372.RE
373.PP
374The first four octal escapes are actually nonprinting characters,
375while the remainder of the file is printable text.
376You may notice:
377.bP
378The actual color pair values are not written to the file.
379.bP
380All characters are shown in printable form; spaces are \*(``\es\*('' to
381ensure they are not overlooked.
382.bP
383Attributes are written in escaped curly braces, e.g., \*(``\e{BOLD}\*('',
384and may include a color pair (C1 or C2 in this example).
385.bP
386The parameters in the header are written out only if they are nonzero.
387When reading back, order does not matter.
388.ne 10
389.PP
390Running the same program with Solaris \fIxpg4\fP curses gives this dump:
391.PP
392.RS 4
393.EX
394MAX=10,20
395BEG=0,0
396SCROLL=0,10
397VMIN=1
398VTIME=0
399FLAGS=0x1000
400FG=0,0
401BG=0,0,
4020,0,0,1,
4030,19,0,0,
4041,0,0,1,
4051,19,0,0,
4062,0,0,1,
4072,19,0,0,
4083,0,0,1,
4093,19,0,0,
4104,0,0,1,
4114,5,0x20,0,Hello
4124,10,0,1,
4134,19,0,0,
4145,0,0,1,
4155,5,0x4,2,World!
4165,11,0,1,
4175,19,0,0,
4186,0,0,1,
4196,19,0,0,
4207,0,0,1,
4217,19,0,0,
4228,0,0,1,
4238,19,0,0,
4249,0,0,1,
4259,19,0,0,
426CUR=11,5
427.EE
428.RE
429.PP
430Solaris \fBgetwin\fP requires that all parameters are present, and
431in the same order.
432The \fIxpg4\fP curses library does not know about the \fBbce\fP
433(back color erase) capability, and does not color the window background.
434.ne 10
435.PP
436On the other hand, the SVr4 curses library does know about the background color.
437However, its screen dumps are in binary.
438Here is the corresponding dump (using \*(``od \-t x1\*(''):
439.PP
440.RS 4
441.EX
4420000000 1c 01 c3 d6 f3 58 05 00 0b 00 0a 00 14 00 00 00
4430000020 00 00 02 00 00 00 00 00 00 00 00 00 00 00 00 00
4440000040 00 00 b8 1a 06 08 cc 1a 06 08 00 00 09 00 10 00
4450000060 00 00 00 80 00 00 20 00 00 00 ff ff ff ff 00 00
4460000100 ff ff ff ff 00 00 00 00 20 80 00 00 20 80 00 00
4470000120 20 80 00 00 20 80 00 00 20 80 00 00 20 80 00 00
448*
4490000620 20 80 00 00 20 80 00 00 20 80 00 00 48 80 00 04
4500000640 65 80 00 04 6c 80 00 04 6c 80 00 04 6f 80 00 04
4510000660 20 80 00 00 20 80 00 00 20 80 00 00 20 80 00 00
452*
4530000740 20 80 00 00 20 80 00 00 20 80 00 00 57 00 81 00
4540000760 6f 00 81 00 72 00 81 00 6c 00 81 00 64 00 81 00
4550001000 21 00 81 00 20 80 00 00 20 80 00 00 20 80 00 00
4560001020 20 80 00 00 20 80 00 00 20 80 00 00 20 80 00 00
457*
4580001540 20 80 00 00 20 80 00 00 00 00 f6 d1 01 00 f6 d1
4590001560 08 00 00 00 40 00 00 00 00 00 00 00 00 00 00 07
4600001600 00 04 00 01 00 01 00 00 00 01 00 00 00 00 00 00
4610001620 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
462*
4630002371
464.EE
465.RE
466.SH AUTHORS
467Thomas E. Dickey
468.br
469extended screen-dump format for \fI\%ncurses\fP 6.0 (2015)
470.sp
471Eric S. Raymond
472.br
473screen dump feature in \fI\%ncurses\fP 1.9.2d (1995)
474.SH SEE ALSO
475\fB\%curs_scr_dump\fP(3X),
476\fB\%curs_util\fP(3X)