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