]> ncurses.scripts.mit.edu Git - ncurses.git/blob - man/scr_dump.5
ncurses 6.4 - patch 20231125
[ncurses.git] / man / scr_dump.5
1 .\"***************************************************************************
2 .\" Copyright 2018-2021,2023 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.39 2023/11/25 14:21:48 tom Exp $
31 .TH scr_dump 5 2023-11-25 "ncurses 6.4" "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
48 scr_dump \-
49 \fIcurses\fR screen dump
50 .SH SYNOPSIS
51 .B scr_dump
52 .SH DESCRIPTION
53 The curses library provides applications with the ability to write the
54 contents of a window to an external file using \fBscr_dump\fP or \fBputwin\fP,
55 and read it back using \fBscr_restore\fP or \fBgetwin\fP.
56 .PP
57 The \fBputwin\fP and \fBgetwin\fP functions do the work;
58 while \fBscr_dump\fP and \fBscr_restore\fP conveniently save and restore
59 the whole screen, i.e., \fBstdscr\fP.
60 .SS ncurses6
61 A longstanding implementation of screen-dump was
62 revised with ncurses6 to remedy problems with the earlier approach:
63 .IP \(bu 4
64 A \*(``magic number\*('' is written to the beginning of the dump file,
65 allowing applications (such as \fBfile\fP(1)) to recognize curses dump files.
66 .IP
67 Because ncurses6 uses a new format,
68 that requires a new magic number
69 was unused by other applications.
70 This 16-bit number was unused:
71 .RS 4
72 .PP
73 .RS 4
74 .EX
75 0x8888 (octal \*(``\e210\e210\*('')
76 .EE
77 .RE
78 .PP
79 but to be more certain, this 32-bit number was chosen:
80 .PP
81 .RS 4
82 .EX
83 0x88888888 (octal \*(``\e210\e210\e210\e210\*('')
84 .EE
85 .RE
86 .PP
87 This is the pattern submitted to the maintainers of the \fBfile\fP program:
88 .PP
89 .RS 4
90 .EX
91 #
92 # ncurses5 (and before) did not use a magic number,
93 # making screen dumps "data".
94 #
95 # ncurses6 (2015) uses this format, ignoring byte-order
96 0    string    \e210\e210\e210\e210ncurses    ncurses6 screen image
97 #
98 .EE
99 .RE
100 .RE
101 .bP
102 The screen dumps are written in textual form,
103 so that internal data sizes are not directly related to the dump-format, and
104 enabling the library to read dumps from either narrow- or wide-character-
105 configurations.
106 .IP
107 The \fInarrow\fP library configuration holds characters and video attributes
108 in a 32-bit \fBchtype\fP, while the \fIwide-character\fP library stores
109 this information in the \fBcchar_t\fP structure, which is much larger than
110 32-bits.
111 .bP
112 It is possible to read a screen dump into a terminal with a different
113 screen-size,
114 because the library truncates or fills the screen as necessary.
115 .bP
116 The ncurses6 \fBgetwin\fP reads the legacy screen dumps from ncurses5.
117 .SS ncurses5 (legacy)
118 The screen-dump feature was added to ncurses in June 1995.
119 While there were fixes and improvements in succeeding years,
120 the basic scheme was unchanged:
121 .bP
122 The \fBWINDOW\fP structure was written in binary form.
123 .bP
124 The \fBWINDOW\fP structure refers to lines of data,
125 which were written as an array of binary data following the \fBWINDOW\fP.
126 .bP
127 When \fBgetwin\fP restored the window,
128 it would keep track of offsets into the array of line-data
129 and adjust the \fBWINDOW\fP structure which was read back into memory.
130 .PP
131 This is similar to Unix System\ V,
132 but does not write a \*(``magic number\*('' to identify the file format.
133 .SH PORTABILITY
134 There is no standard format for \fBputwin\fP.
135 This section gives a brief description of the existing formats.
136 .SS X/Open Curses
137 Refer to \fIX/Open Curses, Issue 7\fP (2009).
138 .PP
139 X/Open's documentation for \fIenhanced curses\fP says only:
140 .RS 3
141 .PP
142 The \fBgetwin(\ ) \fPfunction reads window-related data
143 stored in the file by \fIputwin(\ )\fP.
144 The function
145 then creates and initializes a new window using that data.
146 .PP
147 The \fBputwin(\ )\fP function writes all data associated
148 with \fIwin\fP into the \fBstdio\fP(3) stream to which \fIfilep\fP
149 points, using an \fBunspecified format\fP.
150 This information can be retrieved later using \fBgetwin(\ )\fP.
151 .RE
152 .PP
153 In the mid-1990s when the X/Open Curses document was written,
154 there were still systems using older, less capable curses libraries
155 (aside from the BSD curses library which was not relevant to X/Open
156 because it did not meet the criteria for \fIbase curses\fP).
157 The document explained the term \*(``enhanced\*('' as follows:
158 .RS 3
159 .bP
160 Shading is used to identify \fIX/Open Enhanced Curses\fP material,
161 relating to interfaces included to provide enhanced capabilities
162 for applications originally written to be compiled on systems
163 based on the Unix operating system.
164 Therefore, the features described may not be present on systems
165 that conform to \fBXPG4 or to earlier XPG releases\fP.
166 The relevant reference pages may provide additional
167 or more specific portability warnings about use of the material.
168 .RE
169 .PP
170 In the foregoing, emphasis was added to \fBunspecified format\fP
171 and to \fBXPG4 or to earlier XPG releases\fP,
172 for clarity.
173 .SS Unix System V
174 Unix System\ V curses identified the file format by writing a
175 \*(``magic number\*('' at the beginning of the dump.
176 The \fBWINDOW\fP data and the lines of text follow, all in binary form.
177 .PP
178 The Solaris curses source has these definitions:
179 .PP
180 .RS 4
181 .EX
182 /* terminfo magic number */
183 #define MAGNUM  0432
184
185 /* curses screen dump magic number */
186 #define SVR2_DUMP_MAGIC_NUMBER  0433
187 #define SVR3_DUMP_MAGIC_NUMBER  0434
188 .EE
189 .RE
190 .PP
191 That is, the feature was likely introduced in SVr2 (1984),
192 and improved in SVr3 (1987).
193 The Solaris curses source has no magic number for SVr4 (1989).
194 Other operating systems (AIX and HP-UX) use a magic number which would
195 correspond to this definition:
196 .PP
197 .RS 4
198 .EX
199 /* curses screen dump magic number */
200 #define SVR4_DUMP_MAGIC_NUMBER  0435
201 .EE
202 .RE
203 .PP
204 That octal number in bytes is 001, 035.
205 Because most Unix vendors use big-endian hardware,
206 the magic number is written with the high-order byte first, e.g.,
207 .PP
208 .RS 4
209 .EX
210 \e001\e035
211 .EE
212 .RE
213 .PP
214 After the magic number, the \fBWINDOW\fP structure and line-data are
215 written in binary format.
216 While the magic number used by the Unix systems can be seen using \fBod\fP(1),
217 none of the Unix systems documents the format used for screen-dumps.
218 .PP
219 The Unix systems do not use identical formats.
220 While collecting information for for this manual page,
221 the \fIsavescreen\fP test-program
222 produced dumps of different size
223 (all on 64-bit hardware, on 40x80 screens):
224 .bP
225 AIX (51817 bytes)
226 .bP
227 HP-UX (90093 bytes)
228 .bP
229 Solaris 10 (13273 bytes)
230 .bP
231 ncurses5 (12888 bytes)
232 .SS Solaris
233 As noted above, Solaris curses has no magic number corresponding
234 to SVr4 curses.
235 This is odd since Solaris was the first operating system
236 to pass the SVr4 guidelines.
237 Solaris has two versions of curses:
238 .bP
239 The default curses library uses the SVr3 magic number.
240 .bP
241 There is an alternate curses library in \fB/usr/xpg4\fP.
242 This uses a textual format with no magic number.
243 .IP
244 According to the copyright notice, the \fIxpg4\fP Solaris curses library was
245 developed by MKS (Mortice Kern Systems) from 1990 to 1995.
246 .IP
247 Like ncurses6, there is a file-header with parameters.
248 Unlike ncurses6, the contents of the window are written piecemeal,
249 with coordinates and attributes for each chunk of text rather
250 than writing the whole window from top to bottom.
251 .SS PDCurses
252 PDCurses added support for screen dumps in version 2.7 (2005).
253 Like Unix System\ V and ncurses5,
254 it writes the \fBWINDOW\fP structure in binary,
255 but begins the file with its three-byte identifier \*(``PDC\*('',
256 followed by a one-byte version,
257 e.g.,
258 .PP
259 .RS 4
260 .EX
261         \*(``PDC\e001\*(''
262 .EE
263 .RE
264 .SS NetBSD
265 As of April 2017, NetBSD curses does
266 not support \fBscr_dump\fP and \fBscr_restore\fP
267 (or \fBscr_init\fP, \fBscr_set\fP),
268 although it has \fBputwin\fP and \fBgetwin\fP.
269 .PP
270 Like ncurses5, NetBSD \fBputwin\fP does not identify its dumps with a
271 useful magic number.
272 It writes
273 .bP
274 the curses shared library major and minor versions
275 as the first two bytes (e.g., 7 and 1),
276 .bP
277 followed by a binary dump of the \fBWINDOW\fP,
278 .bP
279 some data for wide-characters referenced by the \fBWINDOW\fP structure, and
280 .bP
281 finally, lines as done by other implementations.
282 .SH EXAMPLES
283 Given a simple program which writes text to the screen
284 (and for the sake of example, limiting the screen-size to 10x20):
285 .PP
286 .RS 4
287 .EX
288 #include <curses.h>
289
290 int
291 main(void)
292 {
293     putenv("LINES=10");
294     putenv("COLUMNS=20");
295     initscr();
296     start_color();
297     init_pair(1, COLOR_WHITE, COLOR_BLUE);
298     init_pair(2, COLOR_RED, COLOR_BLACK);
299     bkgd(COLOR_PAIR(1));
300     move(4, 5);
301     attron(A_BOLD);
302     addstr("Hello");
303     move(5, 5);
304     attroff(A_BOLD);
305     attrset(A_REVERSE | COLOR_PAIR(2));
306     addstr("World!");
307     refresh();
308     scr_dump("foo.out");
309     endwin();
310     return 0;
311 }
312 .EE
313 .RE
314 .PP
315 When run using ncurses6, the output looks like this:
316 .PP
317 .RS 4
318 .EX
319 \e210\e210\e210\e210ncurses 6.0.20170415
320 _cury=5
321 _curx=11
322 _maxy=9
323 _maxx=19
324 _flags=14
325 _attrs=\e{REVERSE|C2}
326 flag=_idcok
327 _delay=-1
328 _regbottom=9
329 _bkgrnd=\e{NORMAL|C1}\es
330 rows:
331 1:\e{NORMAL|C1}\es\es\es\es\es\es\es\es\es\es\es\es\es\es\es\es\es\es\es\es
332 2:\es\es\es\es\es\es\es\es\es\es\es\es\es\es\es\es\es\es\es\es
333 3:\es\es\es\es\es\es\es\es\es\es\es\es\es\es\es\es\es\es\es\es
334 4:\es\es\es\es\es\es\es\es\es\es\es\es\es\es\es\es\es\es\es\es
335 5:\es\es\es\es\es\e{BOLD}Hello\e{NORMAL}\es\es\es\es\es\es\es\es\es\es
336 6:\es\es\es\es\es\e{REVERSE|C2}World!\e{NORMAL|C1}\es\es\es\es\es\es\es\es\es
337 7:\es\es\es\es\es\es\es\es\es\es\es\es\es\es\es\es\es\es\es\es
338 8:\es\es\es\es\es\es\es\es\es\es\es\es\es\es\es\es\es\es\es\es
339 9:\es\es\es\es\es\es\es\es\es\es\es\es\es\es\es\es\es\es\es\es
340 10:\es\es\es\es\es\es\es\es\es\es\es\es\es\es\es\es\es\es\es\es
341 .EE
342 .RE
343 .PP
344 The first four octal escapes are actually nonprinting characters,
345 while the remainder of the file is printable text.
346 You may notice:
347 .bP
348 The actual color pair values are not written to the file.
349 .bP
350 All characters are shown in printable form; spaces are \*(``\es\*('' to
351 ensure they are not overlooked.
352 .bP
353 Attributes are written in escaped curly braces, e.g., \*(``\e{BOLD}\*('',
354 and may include a color-pair (C1 or C2 in this example).
355 .bP
356 The parameters in the header are written out only if they are nonzero.
357 When reading back, order does not matter.
358 .ne 10
359 .PP
360 Running the same program with Solaris \fIxpg4\fP curses gives this dump:
361 .PP
362 .RS 4
363 .EX
364 MAX=10,20
365 BEG=0,0
366 SCROLL=0,10
367 VMIN=1
368 VTIME=0
369 FLAGS=0x1000
370 FG=0,0
371 BG=0,0,
372 0,0,0,1,
373 0,19,0,0,
374 1,0,0,1,
375 1,19,0,0,
376 2,0,0,1,
377 2,19,0,0,
378 3,0,0,1,
379 3,19,0,0,
380 4,0,0,1,
381 4,5,0x20,0,Hello
382 4,10,0,1,
383 4,19,0,0,
384 5,0,0,1,
385 5,5,0x4,2,World!
386 5,11,0,1,
387 5,19,0,0,
388 6,0,0,1,
389 6,19,0,0,
390 7,0,0,1,
391 7,19,0,0,
392 8,0,0,1,
393 8,19,0,0,
394 9,0,0,1,
395 9,19,0,0,
396 CUR=11,5
397 .EE
398 .RE
399 .PP
400 Solaris \fBgetwin\fP requires that all parameters are present, and
401 in the same order.
402 The \fIxpg4\fP curses library does not know about the \fBbce\fP
403 (back color erase) capability, and does not color the window background.
404 .ne 10
405 .PP
406 On the other hand, the SVr4 curses library does know about the background color.
407 However, its screen dumps are in binary.
408 Here is the corresponding dump (using \*(``od \-t x1\*(''):
409 .PP
410 .RS 4
411 .EX
412 0000000 1c 01 c3 d6 f3 58 05 00 0b 00 0a 00 14 00 00 00
413 0000020 00 00 02 00 00 00 00 00 00 00 00 00 00 00 00 00
414 0000040 00 00 b8 1a 06 08 cc 1a 06 08 00 00 09 00 10 00
415 0000060 00 00 00 80 00 00 20 00 00 00 ff ff ff ff 00 00
416 0000100 ff ff ff ff 00 00 00 00 20 80 00 00 20 80 00 00
417 0000120 20 80 00 00 20 80 00 00 20 80 00 00 20 80 00 00
418 *
419 0000620 20 80 00 00 20 80 00 00 20 80 00 00 48 80 00 04
420 0000640 65 80 00 04 6c 80 00 04 6c 80 00 04 6f 80 00 04
421 0000660 20 80 00 00 20 80 00 00 20 80 00 00 20 80 00 00
422 *
423 0000740 20 80 00 00 20 80 00 00 20 80 00 00 57 00 81 00
424 0000760 6f 00 81 00 72 00 81 00 6c 00 81 00 64 00 81 00
425 0001000 21 00 81 00 20 80 00 00 20 80 00 00 20 80 00 00
426 0001020 20 80 00 00 20 80 00 00 20 80 00 00 20 80 00 00
427 *
428 0001540 20 80 00 00 20 80 00 00 00 00 f6 d1 01 00 f6 d1
429 0001560 08 00 00 00 40 00 00 00 00 00 00 00 00 00 00 07
430 0001600 00 04 00 01 00 01 00 00 00 01 00 00 00 00 00 00
431 0001620 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
432 *
433 0002371
434 .EE
435 .RE
436 .SH AUTHORS
437 Thomas E. Dickey
438 .br
439 extended screen-dump format for ncurses 6.0 (2015)
440 .sp
441 Eric S. Raymond
442 .br
443 screen dump feature in ncurses 1.9.2d (1995)
444 .SH SEE ALSO
445 \fB\%curs_scr_dump\fP(3X),
446 \fB\%curs_util\fP(3X)