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