]> ncurses.scripts.mit.edu Git - ncurses.git/blob - man/scr_dump.5
2a2203be52ba62aa79031a52639460839f2047c9
[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.27 2023/09/09 21:20:16 tom Exp $
31 .TH scr_dump 5 2023-09-09 "ncurses 6.4" "File formats"
32 .ie \n(.g .ds `` \(lq
33 .el       .ds `` ``
34 .ie \n(.g .ds '' \(rq
35 .el       .ds '' ''
36 .ie n .ds CW R
37 .el   \{
38 .ie \n(.g .ds CW CR
39 .el       .ds CW CW
40 .\}
41 .de NS
42 .ie n  .sp
43 .el    .sp .5
44 .ie n  .in +4
45 .el    .in +2
46 .nf
47 .ft \*(CW
48 ..
49 .de NE
50 .fi
51 .ft R
52 .ie n  .in -4
53 .el    .in -2
54 ..
55 .de bP
56 .ie n  .IP \(bu 4
57 .el    .IP \(bu 2
58 ..
59 .SH NAME
60 scr_dump \- format of curses screen-dumps.
61 .SH SYNOPSIS
62 .B scr_dump
63 .SH DESCRIPTION
64 The curses library provides applications with the ability to write the
65 contents of a window to an external file using \fBscr_dump\fP or \fBputwin\fP,
66 and read it back using \fBscr_restore\fP or \fBgetwin\fP.
67 .PP
68 The \fBputwin\fP and \fBgetwin\fP functions do the work;
69 while \fBscr_dump\fP and \fBscr_restore\fP conveniently save and restore
70 the whole screen, i.e., \fBstdscr\fP.
71 .SS ncurses6
72 A longstanding implementation of screen-dump was
73 revised with ncurses6 to remedy problems with the earlier approach:
74 .bP
75 A \*(``magic number\*('' is written to the beginning of the dump file,
76 allowing applications (such as \fBfile\fP(1)) to recognize curses dump files.
77 .IP
78 Because ncurses6 uses a new format,
79 that requires a new magic number
80 was unused by other applications.
81 This 16-bit number was unused:
82 .NS
83 0x8888 (octal \*(``\\210\\210\*('')
84 .NE
85 .IP
86 but to be more certain, this 32-bit number was chosen:
87 .NS
88 0x88888888 (octal \*(``\\210\\210\\210\\210\*('')
89 .NE
90 .IP
91 This is the pattern submitted to the maintainers of the \fBfile\fP program:
92 .NS
93 #
94 # ncurses5 (and before) did not use a magic number,
95 # making screen dumps "data".
96 #
97 # ncurses6 (2015) uses this format, ignoring byte-order
98 0    string    \\210\\210\\210\\210ncurses    ncurses6 screen image
99 #
100 .NE
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 SystemV,
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 SystemV
174 Unix SystemV 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 .NS
180 /* terminfo magic number */
181 #define MAGNUM  0432
182
183 /* curses screen dump magic number */
184 #define SVR2_DUMP_MAGIC_NUMBER  0433
185 #define SVR3_DUMP_MAGIC_NUMBER  0434
186 .NE
187 .PP
188 That is, the feature was likely introduced in SVr2 (1984),
189 and improved in SVr3 (1987).
190 The Solaris curses source has no magic number for SVr4 (1989).
191 Other operating systems (AIX and HPUX) use a magic number which would
192 correspond to this definition:
193 .NS
194 /* curses screen dump magic number */
195 #define SVR4_DUMP_MAGIC_NUMBER  0435
196 .NE
197 .PP
198 That octal number in bytes is 001, 035.
199 Because most Unix vendors use big-endian hardware,
200 the magic number is written with the high-order byte first, e.g.,
201 .NS
202 \001\035
203 .NE
204 .PP
205 After the magic number, the \fBWINDOW\fP structure and line-data are
206 written in binary format.
207 While the magic number used by the Unix systems can be seen using \fBod\fP(1),
208 none of the Unix systems documents the format used for screen-dumps.
209 .PP
210 The Unix systems do not use identical formats.
211 While collecting information for for this manual page,
212 the \fIsavescreen\fP test-program
213 produced dumps of different size
214 (all on 64-bit hardware, on 40x80 screens):
215 .bP
216 AIX (51817 bytes)
217 .bP
218 HPUX (90093 bytes)
219 .bP
220 Solaris 10 (13273 bytes)
221 .bP
222 ncurses5 (12888 bytes)
223 .SS Solaris
224 As noted above, Solaris curses has no magic number corresponding
225 to SVr4 curses.
226 This is odd since Solaris was the first operating system
227 to pass the SVr4 guidelines.
228 Solaris has two versions of curses:
229 .bP
230 The default curses library uses the SVr3 magic number.
231 .bP
232 There is an alternate curses library in \fB/usr/xpg4\fP.
233 This uses a textual format with no magic number.
234 .IP
235 According to the copyright notice, the \fIxpg4\fP Solaris curses library was
236 developed by MKS (Mortice Kern Systems) from 1990 to 1995.
237 .IP
238 Like ncurses6, there is a file-header with parameters.
239 Unlike ncurses6, the contents of the window are written piecemeal,
240 with coordinates and attributes for each chunk of text rather
241 than writing the whole window from top to bottom.
242 .SS PDCurses
243 PDCurses added support for screen dumps in version 2.7 (2005).
244 Like Unix SystemV and ncurses5,
245 it writes the \fBWINDOW\fP structure in binary,
246 but begins the file with its three-byte identifier \*(``PDC\*('',
247 followed by a one-byte version,
248 e.g.,
249 .NS
250         \*(``PDC\\001\*(''
251 .NE
252 .SS NetBSD
253 As of April 2017, NetBSD curses does
254 not support \fBscr_dump\fP and \fBscr_restore\fP
255 (or \fBscr_init\fP, \fBscr_set\fP),
256 although it has \fBputwin\fP and \fBgetwin\fP.
257 .PP
258 Like ncurses5, NetBSD \fBputwin\fP does not identify its dumps with a
259 useful magic number.
260 It writes
261 .bP
262 the curses shared library major and minor versions
263 as the first two bytes (e.g., 7 and 1),
264 .bP
265 followed by a binary dump of the \fBWINDOW\fP,
266 .bP
267 some data for wide-characters referenced by the \fBWINDOW\fP structure, and
268 .bP
269 finally, lines as done by other implementations.
270 .SH EXAMPLE
271 Given a simple program which writes text to the screen
272 (and for the sake of example, limiting the screen-size to 10x20):
273 .NS
274 #include <curses.h>
275
276 int
277 main(void)
278 {
279     putenv("LINES=10");
280     putenv("COLUMNS=20");
281     initscr();
282     start_color();
283     init_pair(1, COLOR_WHITE, COLOR_BLUE);
284     init_pair(2, COLOR_RED, COLOR_BLACK);
285     bkgd(COLOR_PAIR(1));
286     move(4, 5);
287     attron(A_BOLD);
288     addstr("Hello");
289     move(5, 5);
290     attroff(A_BOLD);
291     attrset(A_REVERSE | COLOR_PAIR(2));
292     addstr("World!");
293     refresh();
294     scr_dump("foo.out");
295     endwin();
296     return 0;
297 }
298 .NE
299 .PP
300 When run using ncurses6, the output looks like this:
301 .NS
302 \\210\\210\\210\\210ncurses 6.0.20170415
303 _cury=5
304 _curx=11
305 _maxy=9
306 _maxx=19
307 _flags=14
308 _attrs=\\{REVERSE|C2}
309 flag=_idcok
310 _delay=-1
311 _regbottom=9
312 _bkgrnd=\\{NORMAL|C1}\\s
313 rows:
314 1:\\{NORMAL|C1}\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s
315 2:\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s
316 3:\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s
317 4:\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s
318 5:\\s\\s\\s\\s\\s\\{BOLD}Hello\\{NORMAL}\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s
319 6:\\s\\s\\s\\s\\s\\{REVERSE|C2}World!\\{NORMAL|C1}\\s\\s\\s\\s\\s\\s\\s\\s\\s
320 7:\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s
321 8:\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s
322 9:\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s
323 10:\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s
324 .NE
325 .PP
326 The first four octal escapes are actually nonprinting characters,
327 while the remainder of the file is printable text.
328 You may notice:
329 .bP
330 The actual color pair values are not written to the file.
331 .bP
332 All characters are shown in printable form; spaces are \*(``\\s\*('' to
333 ensure they are not overlooked.
334 .bP
335 Attributes are written in escaped curly braces, e.g., \*(``\\{BOLD}\*('',
336 and may include a color-pair (C1 or C2 in this example).
337 .bP
338 The parameters in the header are written out only if they are nonzero.
339 When reading back, order does not matter.
340 .ne 10
341 .PP
342 Running the same program with Solaris \fIxpg4\fP curses gives this dump:
343 .NS
344 MAX=10,20
345 BEG=0,0
346 SCROLL=0,10
347 VMIN=1
348 VTIME=0
349 FLAGS=0x1000
350 FG=0,0
351 BG=0,0,
352 0,0,0,1,
353 0,19,0,0,
354 1,0,0,1,
355 1,19,0,0,
356 2,0,0,1,
357 2,19,0,0,
358 3,0,0,1,
359 3,19,0,0,
360 4,0,0,1,
361 4,5,0x20,0,Hello
362 4,10,0,1,
363 4,19,0,0,
364 5,0,0,1,
365 5,5,0x4,2,World!
366 5,11,0,1,
367 5,19,0,0,
368 6,0,0,1,
369 6,19,0,0,
370 7,0,0,1,
371 7,19,0,0,
372 8,0,0,1,
373 8,19,0,0,
374 9,0,0,1,
375 9,19,0,0,
376 CUR=11,5
377 .NE
378 .PP
379 Solaris \fBgetwin\fP requires that all parameters are present, and
380 in the same order.
381 The \fIxpg4\fP curses library does not know about the \fBbce\fP
382 (back color erase) capability, and does not color the window background.
383 .ne 10
384 .PP
385 On the other hand, the SVr4 curses library does know about the background color.
386 However, its screen dumps are in binary.
387 Here is the corresponding dump (using \*(``od -t x1\*(''):
388 .NS
389 0000000 1c 01 c3 d6 f3 58 05 00 0b 00 0a 00 14 00 00 00
390 0000020 00 00 02 00 00 00 00 00 00 00 00 00 00 00 00 00
391 0000040 00 00 b8 1a 06 08 cc 1a 06 08 00 00 09 00 10 00
392 0000060 00 00 00 80 00 00 20 00 00 00 ff ff ff ff 00 00
393 0000100 ff ff ff ff 00 00 00 00 20 80 00 00 20 80 00 00
394 0000120 20 80 00 00 20 80 00 00 20 80 00 00 20 80 00 00
395 *
396 0000620 20 80 00 00 20 80 00 00 20 80 00 00 48 80 00 04
397 0000640 65 80 00 04 6c 80 00 04 6c 80 00 04 6f 80 00 04
398 0000660 20 80 00 00 20 80 00 00 20 80 00 00 20 80 00 00
399 *
400 0000740 20 80 00 00 20 80 00 00 20 80 00 00 57 00 81 00
401 0000760 6f 00 81 00 72 00 81 00 6c 00 81 00 64 00 81 00
402 0001000 21 00 81 00 20 80 00 00 20 80 00 00 20 80 00 00
403 0001020 20 80 00 00 20 80 00 00 20 80 00 00 20 80 00 00
404 *
405 0001540 20 80 00 00 20 80 00 00 00 00 f6 d1 01 00 f6 d1
406 0001560 08 00 00 00 40 00 00 00 00 00 00 00 00 00 00 07
407 0001600 00 04 00 01 00 01 00 00 00 01 00 00 00 00 00 00
408 0001620 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
409 *
410 0002371
411 .NE
412 .SH SEE ALSO
413 \fBcurs_scr_dump\fP(3X),
414 \fBcurs_util\fP(3X).
415 .SH AUTHORS
416 Thomas E. Dickey
417 .br
418 extended screen-dump format for ncurses 6.0 (2015)
419 .sp
420 Eric S. Raymond
421 .br
422 screen dump feature in ncurses 1.9.2d (1995)