]> ncurses.scripts.mit.edu Git - ncurses.git/blob - man/scr_dump.5
ncurses 6.1 - patch 20180630
[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.13 2018/05/19 21:10:21 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,
159 relating to interfaces included to provide enhanced capabilities
160 for applications originally written to be compiled on systems
161 based on the UNIX operating system.
162 Therefore, the features described may not be present on systems
163 that conform to \fBXPG4 or to earlier XPG releases\fP.
164 The relevant reference pages may provide additional
165 or more specific portability warnings about use of the material.
166 .RE
167 .PP
168 In the foregoing, emphasis was added to \fBunspecified format\fP
169 and to \fBXPG4 or to earlier XPG releases\fP,
170 for clarity.
171 .SS Unix SystemV
172 .PP
173 Unix SystemV curses identified the file format by writing a
174 \*(``magic number\*('' at the beginning of the dump.
175 The \fBWINDOW\fP data and the lines of text follow, all in binary form.
176 .PP
177 The Solaris curses source has these definitions:
178 .NS
179 /* terminfo magic number */
180 #define MAGNUM  0432
181
182 /* curses screen dump magic number */
183 #define SVR2_DUMP_MAGIC_NUMBER  0433
184 #define SVR3_DUMP_MAGIC_NUMBER  0434
185 .NE
186 .PP
187 That is, the feature was likely introduced in SVr2 (1984),
188 and improved in SVr3 (1987).
189 The Solaris curses source has no magic number for SVr4 (1989).
190 Other operating systems (AIX and HPUX) use a magic number which would
191 correspond to this definition:
192 .NS
193 /* curses screen dump magic number */
194 #define SVR4_DUMP_MAGIC_NUMBER  0435
195 .NE
196 .PP
197 That octal number in bytes is 001, 035.
198 Because most Unix vendors use big-endian hardware,
199 the magic number is written with the high-order byte first, e.g.,
200 .NS
201 \001\035
202 .NE
203 .PP
204 After the magic number, the \fBWINDOW\fP structure and line-data are
205 written in binary format.
206 While the magic number used by the Unix systems can be seen using \fBod\fP(1),
207 none of the Unix systems documents the format used for screen-dumps.
208 .PP
209 The Unix systems do not use identical formats.
210 While collecting information for for this manual page,
211 the \fIsavescreen\fP test-program
212 produced dumps of different size
213 (all on 64-bit hardware, on 40x80 screens):
214 .bP
215 AIX (51817 bytes)
216 .bP
217 HPUX (90093 bytes)
218 .bP
219 Solaris 10 (13273 bytes)
220 .bP
221 ncurses5 (12888 bytes)
222 .SS Solaris
223 .PP
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 .PP
244 PDCurses added support for screen dumps in version 2.7 (2005).
245 Like Unix SystemV and ncurses5,
246 it writes the \fBWINDOW\fP structure in binary,
247 but begins the file with its three-byte identifier \*(``PDC\*('',
248 followed by a one-byte version,
249 e.g.,
250 .NS
251         \*(``PDC\\001\*(''
252 .NE
253 .SS NetBSD
254 .PP
255 As of April 2017, NetBSD curses does
256 not support \fBscr_dump\fP and \fBscr_restore\fP
257 (or \fBscr_init\fP, \fBscr_set\fP),
258 although it has \fBputwin\fP and \fBgetwin\fP.
259 .PP
260 Like ncurses5, NetBSD \fBputwin\fP does not identify its dumps with a
261 useful magic number.
262 It writes
263 .bP
264 the curses shared library major and minor versions
265 as the first two bytes (e.g., 7 and 1),
266 .bP
267 followed by a binary dump of the \fBWINDOW\fP,
268 .bP
269 some data for wide-characters referenced by the \fBWINDOW\fP structure, and
270 .bP
271 finally, lines as done by other implementations.
272 .SH EXAMPLE
273 .PP
274 Given a simple program which writes text to the screen
275 (and for the sake of example, limiting the screen-size to 10x20):
276 .NS
277 #include <curses.h>
278
279 int
280 main(void)
281 {
282     putenv("LINES=10");
283     putenv("COLUMNS=20");
284     initscr();
285     start_color();
286     init_pair(1, COLOR_WHITE, COLOR_BLUE);
287     init_pair(2, COLOR_RED, COLOR_BLACK);
288     bkgd(COLOR_PAIR(1));
289     move(4, 5);
290     attron(A_BOLD);
291     addstr("Hello");
292     move(5, 5);
293     attroff(A_BOLD);
294     attrset(A_REVERSE | COLOR_PAIR(2));
295     addstr("World!");
296     refresh();
297     scr_dump("foo.out");
298     endwin();
299     return 0;
300 }
301 .NE
302 .PP
303 When run using ncurses6, the output looks like this:
304 .NS
305 \\210\\210\\210\\210ncurses 6.0.20170415
306 _cury=5
307 _curx=11
308 _maxy=9
309 _maxx=19
310 _flags=14
311 _attrs=\\{REVERSE|C2}
312 flag=_idcok
313 _delay=-1
314 _regbottom=9
315 _bkgrnd=\\{NORMAL|C1}\\s
316 rows:
317 1:\\{NORMAL|C1}\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s
318 2:\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s
319 3:\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s
320 4:\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s
321 5:\\s\\s\\s\\s\\s\\{BOLD}Hello\\{NORMAL}\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s
322 6:\\s\\s\\s\\s\\s\\{REVERSE|C2}World!\\{NORMAL|C1}\\s\\s\\s\\s\\s\\s\\s\\s\\s
323 7:\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s
324 8:\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s
325 9:\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s
326 10:\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s
327 .NE
328 .PP
329 The first four octal escapes are actually nonprinting characters,
330 while the remainder of the file is printable text.
331 You may notice:
332 .bP
333 The actual color pair values are not written to the file.
334 .bP
335 All characters are shown in printable form; spaces are \*(``\\s\*('' to
336 ensure they are not overlooked.
337 .bP
338 Attributes are written in escaped curly braces, e.g., \*(``\\{BOLD}\*('',
339 and may include a color-pair (C1 or C2 in this example).
340 .bP
341 The parameters in the header are written out only if they are nonzero.
342 When reading back, order does not matter.
343 .ne 10
344 .PP
345 Running the same program with Solaris \fIxpg4\fP curses gives this dump:
346 .NS
347 MAX=10,20
348 BEG=0,0
349 SCROLL=0,10
350 VMIN=1
351 VTIME=0
352 FLAGS=0x1000
353 FG=0,0
354 BG=0,0, 
355 0,0,0,1,
356 0,19,0,0, 
357 1,0,0,1,
358 1,19,0,0, 
359 2,0,0,1,
360 2,19,0,0, 
361 3,0,0,1,
362 3,19,0,0, 
363 4,0,0,1,
364 4,5,0x20,0,Hello
365 4,10,0,1,
366 4,19,0,0, 
367 5,0,0,1,
368 5,5,0x4,2,World!
369 5,11,0,1,
370 5,19,0,0, 
371 6,0,0,1,
372 6,19,0,0, 
373 7,0,0,1,
374 7,19,0,0, 
375 8,0,0,1,
376 8,19,0,0, 
377 9,0,0,1,
378 9,19,0,0, 
379 CUR=11,5
380 .NE
381 .PP
382 Solaris \fBgetwin\fP requires that all parameters are present, and
383 in the same order.
384 The \fIxpg4\fP curses library does not know about the \fBbce\fP
385 (back color erase) capability, and does not color the window background.
386 .ne 10
387 .PP
388 On the other hand, the SVr4 curses library does know about the background
389 color.  However, its screen dumps are in binary.
390 Here is the corresponding dump (using \*(``od -t x1\*(''):
391 .NS
392 0000000 1c 01 c3 d6 f3 58 05 00 0b 00 0a 00 14 00 00 00
393 0000020 00 00 02 00 00 00 00 00 00 00 00 00 00 00 00 00
394 0000040 00 00 b8 1a 06 08 cc 1a 06 08 00 00 09 00 10 00
395 0000060 00 00 00 80 00 00 20 00 00 00 ff ff ff ff 00 00
396 0000100 ff ff ff ff 00 00 00 00 20 80 00 00 20 80 00 00
397 0000120 20 80 00 00 20 80 00 00 20 80 00 00 20 80 00 00
398 *
399 0000620 20 80 00 00 20 80 00 00 20 80 00 00 48 80 00 04
400 0000640 65 80 00 04 6c 80 00 04 6c 80 00 04 6f 80 00 04
401 0000660 20 80 00 00 20 80 00 00 20 80 00 00 20 80 00 00
402 *
403 0000740 20 80 00 00 20 80 00 00 20 80 00 00 57 00 81 00
404 0000760 6f 00 81 00 72 00 81 00 6c 00 81 00 64 00 81 00
405 0001000 21 00 81 00 20 80 00 00 20 80 00 00 20 80 00 00
406 0001020 20 80 00 00 20 80 00 00 20 80 00 00 20 80 00 00
407 *
408 0001540 20 80 00 00 20 80 00 00 00 00 f6 d1 01 00 f6 d1
409 0001560 08 00 00 00 40 00 00 00 00 00 00 00 00 00 00 07
410 0001600 00 04 00 01 00 01 00 00 00 01 00 00 00 00 00 00
411 0001620 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
412 *
413 0002371
414 .NE
415 .SH SEE ALSO
416 .PP
417 \fBcurs_scr_dump\fR(3X),
418 \fBcurs_util\fR(3X).
419 .SH AUTHORS
420 .PP
421 Thomas E. Dickey
422 .br
423 extended screen-dump format for ncurses 6.0 (2015)
424 .sp
425 Eric S. Raymond
426 .br
427 screen dump feature in ncurses 1.9.2d (1995)