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