]> ncurses.scripts.mit.edu Git - ncurses.git/blob - doc/html/man/scr_dump.5.html
ncurses 6.2 - patch 20210626
[ncurses.git] / doc / html / man / scr_dump.5.html
1 <!--
2   ****************************************************************************
3   * Copyright 2018-2020,2021 Thomas E. Dickey                                *
4   * Copyright 2017 Free Software Foundation, Inc.                            *
5   *                                                                          *
6   * Permission is hereby granted, free of charge, to any person obtaining a  *
7   * copy of this software and associated documentation files (the            *
8   * "Software"), to deal in the Software without restriction, including      *
9   * without limitation the rights to use, copy, modify, merge, publish,      *
10   * distribute, distribute with modifications, sublicense, and/or sell       *
11   * copies of the Software, and to permit persons to whom the Software is    *
12   * furnished to do so, subject to the following conditions:                 *
13   *                                                                          *
14   * The above copyright notice and this permission notice shall be included  *
15   * in all copies or substantial portions of the Software.                   *
16   *                                                                          *
17   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS  *
18   * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF               *
19   * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.   *
20   * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,   *
21   * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR    *
22   * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR    *
23   * THE USE OR OTHER DEALINGS IN THE SOFTWARE.                               *
24   *                                                                          *
25   * Except as contained in this notice, the name(s) of the above copyright   *
26   * holders shall not be used in advertising or otherwise to promote the     *
27   * sale, use or other dealings in this Software without prior written       *
28   * authorization.                                                           *
29   ****************************************************************************
30   * @Id: scr_dump.5,v 1.17 2021/06/17 21:26:02 tom Exp @
31 -->
32 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN">
33 <HTML>
34 <HEAD>
35 <meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
36 <meta name="generator" content="Manpage converted by man2html - see https://invisible-island.net/scripts/readme.html#others_scripts">
37 <TITLE>scr_dump 5</TITLE>
38 <link rel="author" href="mailto:bug-ncurses@gnu.org">
39 <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
40 </HEAD>
41 <BODY>
42 <H1 class="no-header">scr_dump 5</H1>
43 <PRE>
44 <STRONG><A HREF="scr_dump.5.html">scr_dump(5)</A></STRONG>                   File Formats Manual                  <STRONG><A HREF="scr_dump.5.html">scr_dump(5)</A></STRONG>
45
46
47
48
49 </PRE><H2><a name="h2-NAME">NAME</a></H2><PRE>
50        scr_dump - format of curses screen-dumps.
51
52
53 </PRE><H2><a name="h2-SYNOPSIS">SYNOPSIS</a></H2><PRE>
54        <STRONG>scr_dump</STRONG>
55
56
57 </PRE><H2><a name="h2-DESCRIPTION">DESCRIPTION</a></H2><PRE>
58        The  curses library provides applications with the ability to write the
59        contents of a window to an external file using <STRONG>scr_dump</STRONG> or <STRONG>putwin</STRONG>,  and
60        read it back using <STRONG>scr_restore</STRONG> or <STRONG>getwin</STRONG>.
61
62        The  <STRONG>putwin</STRONG>  and  <STRONG>getwin</STRONG>  functions  do  the  work;  while <STRONG>scr_dump</STRONG> and
63        <STRONG>scr_restore</STRONG> conveniently save  and  restore  the  whole  screen,  i.e.,
64        <STRONG>stdscr</STRONG>.
65
66
67 </PRE><H3><a name="h3-ncurses6">ncurses6</a></H3><PRE>
68        A  longstanding implementation of screen-dump was revised with ncurses6
69        to remedy problems with the earlier approach:
70
71        <STRONG>o</STRONG>   A "magic number" is written to the  beginning  of  the  dump  file,
72            allowing  applications  (such  as <STRONG>file(1)</STRONG>) to recognize curses dump
73            files.
74
75            Because ncurses6 uses a new  format,  that  requires  a  new  magic
76            number  was  unused  by other applications.  This 16-bit number was
77            unused:
78
79                0x8888 (octal "\210\210")
80
81            but to be more certain, this 32-bit number was chosen:
82
83                0x88888888 (octal "\210\210\210\210")
84
85            This is the pattern  submitted  to  the  maintainers  of  the  <STRONG>file</STRONG>
86            program:
87
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
96        <STRONG>o</STRONG>   The screen dumps are written in textual form, so that internal data
97            sizes are not directly related to the dump-format, and enabling the
98            library  to  read  dumps  from  either  narrow-  or wide-character-
99            configurations.
100
101            The  <EM>narrow</EM>  library  configuration  holds  characters  and   video
102            attributes  in  a  32-bit  <STRONG>chtype</STRONG>, while the <EM>wide-character</EM> library
103            stores this information in the <STRONG>cchar_t</STRONG>  structure,  which  is  much
104            larger than 32-bits.
105
106        <STRONG>o</STRONG>   It  is  possible  to  read  a  screen  dump  into a terminal with a
107            different screen-size, because the library truncates or  fills  the
108            screen as necessary.
109
110        <STRONG>o</STRONG>   The ncurses6 <STRONG>getwin</STRONG> reads the legacy screen dumps from ncurses5.
111
112
113 </PRE><H3><a name="h3-ncurses5-_legacy_">ncurses5 (legacy)</a></H3><PRE>
114        The screen-dump feature was added to ncurses in June 1995.  While there
115        were fixes and improvements in succeeding years, the basic  scheme  was
116        unchanged:
117
118        <STRONG>o</STRONG>   The <STRONG>WINDOW</STRONG> structure was written in binary form.
119
120        <STRONG>o</STRONG>   The <STRONG>WINDOW</STRONG> structure refers to lines of data, which were written as
121            an array of binary data following the <STRONG>WINDOW</STRONG>.
122
123        <STRONG>o</STRONG>   When <STRONG>getwin</STRONG> restored the window, it would  keep  track  of  offsets
124            into  the  array of line-data and adjust the <STRONG>WINDOW</STRONG> structure which
125            was read back into memory.
126
127        This is similar to Unix SystemV, but does not write a "magic number" to
128        identify the file format.
129
130
131 </PRE><H2><a name="h2-PORTABILITY">PORTABILITY</a></H2><PRE>
132        There  is  no  standard  format for <STRONG>putwin</STRONG>.  This section gives a brief
133        description of the existing formats.
134
135
136 </PRE><H3><a name="h3-X_Open-Curses">X/Open Curses</a></H3><PRE>
137        Refer to <EM>X/Open</EM> <EM>Curses,</EM> <EM>Issue</EM> <EM>7</EM> (2009).
138
139        X/Open's documentation for <EM>enhanced</EM> <EM>curses</EM> says only:
140
141           The <EM>getwin(</EM> <EM>)</EM> function reads window-related data stored in the  file
142           by  <EM>putwin(</EM> <EM>)</EM>.   The  function  then  creates  and initializes a new
143           window using that data.
144
145           The <EM>putwin(</EM> <EM>)</EM> function writes all data associated with <EM>win</EM> into  the
146           <EM>stdio</EM>  stream  to  which  <EM>filep</EM> points, using an <STRONG>unspecified</STRONG> <STRONG>format</STRONG>.
147           This information can be retrieved later using <EM>getwin(</EM> <EM>)</EM>.
148
149        In the mid-1990s when the X/Open Curses  document  was  written,  there
150        were  still  systems  using older, less capable curses libraries (aside
151        from the BSD curses library which was not relevant to X/Open because it
152        did not meet the criteria for <EM>base</EM> <EM>curses</EM>).  The document explained the
153        term "enhanced" as follows:
154
155           <STRONG>o</STRONG>   Shading is used to identify  <EM>X/Open</EM>  <EM>Enhanced</EM>  <EM>Curses</EM>  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.  Therefore, the features
159               described may not be present on systems that conform to <STRONG>XPG4</STRONG>  <STRONG>or</STRONG>
160               <STRONG>to</STRONG>  <STRONG>earlier</STRONG>  <STRONG>XPG</STRONG>  <STRONG>releases</STRONG>.   The  relevant  reference pages may
161               provide additional or more specific portability  warnings  about
162               use of the material.
163
164        In  the foregoing, emphasis was added to <STRONG>unspecified</STRONG> <STRONG>format</STRONG> and to <STRONG>XPG4</STRONG>
165        <STRONG>or</STRONG> <STRONG>to</STRONG> <STRONG>earlier</STRONG> <STRONG>XPG</STRONG> <STRONG>releases</STRONG>, for clarity.
166
167
168 </PRE><H3><a name="h3-Unix-SystemV">Unix SystemV</a></H3><PRE>
169        Unix SystemV curses identified the file  format  by  writing  a  "magic
170        number" at the beginning of the dump.  The <STRONG>WINDOW</STRONG> data and the lines of
171        text follow, all in binary form.
172
173        The Solaris curses source has these definitions:
174
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
182        That is, the feature was likely introduced in SVr2 (1984), and improved
183        in SVr3 (1987).  The Solaris curses source has no magic number for SVr4
184        (1989).  Other operating systems (AIX and  HPUX)  use  a  magic  number
185        which would correspond to this definition:
186
187            /* curses screen dump magic number */
188            #define SVR4_DUMP_MAGIC_NUMBER  0435
189
190        That  octal number in bytes is 001, 035.  Because most Unix vendors use
191        big-endian hardware, the magic number is written  with  the  high-order
192        byte first, e.g.,
193
194             01 35
195
196        After  the magic number, the <STRONG>WINDOW</STRONG> structure and line-data are written
197        in binary format.  While the magic number used by the Unix systems  can
198        be seen using <STRONG>od(1)</STRONG>, none of the Unix systems documents the format used
199        for screen-dumps.
200
201        The Unix systems  do  not  use  identical  formats.   While  collecting
202        information  for  for  this  manual  page,  the <EM>savescreen</EM> test-program
203        produced dumps of different size (all  on  64-bit  hardware,  on  40x80
204        screens):
205
206        <STRONG>o</STRONG>   AIX (51817 bytes)
207
208        <STRONG>o</STRONG>   HPUX (90093 bytes)
209
210        <STRONG>o</STRONG>   Solaris 10 (13273 bytes)
211
212        <STRONG>o</STRONG>   ncurses5 (12888 bytes)
213
214
215 </PRE><H3><a name="h3-Solaris">Solaris</a></H3><PRE>
216        As  noted  above,  Solaris  curses has no magic number corresponding to
217        SVr4 curses.  This is odd since Solaris was the first operating  system
218        to pass the SVr4 guidelines.  Solaris has two versions of curses:
219
220        <STRONG>o</STRONG>   The default curses library uses the SVr3 magic number.
221
222        <STRONG>o</STRONG>   There  is  an  alternate  curses library in <STRONG>/usr/xpg4</STRONG>.  This uses a
223            textual format with no magic number.
224
225            According to the copyright notice, the <EM>xpg4</EM> Solaris curses  library
226            was developed by MKS (Mortice Kern Systems) from 1990 to 1995.
227
228            Like  ncurses6,  there  is  a  file-header with parameters.  Unlike
229            ncurses6, the contents of the window are  written  piecemeal,  with
230            coordinates  and  attributes  for  each  chunk  of text rather than
231            writing the whole window from top to bottom.
232
233
234 </PRE><H3><a name="h3-PDCurses">PDCurses</a></H3><PRE>
235        PDCurses added support for screen dumps in version  2.7  (2005).   Like
236        Unix  SystemV  and  ncurses5, it writes the <STRONG>WINDOW</STRONG> structure in binary,
237        but begins the file with its three-byte identifier "PDC", followed by a
238        one-byte version, e.g.,
239
240                 "PDC\001"
241
242
243 </PRE><H3><a name="h3-NetBSD">NetBSD</a></H3><PRE>
244        As  of  April  2017,  NetBSD  curses  does  not  support  <STRONG>scr_dump</STRONG>  and
245        <STRONG>scr_restore</STRONG> (or <STRONG>scr_init</STRONG>, <STRONG>scr_set</STRONG>), although it has <STRONG>putwin</STRONG> and <STRONG>getwin</STRONG>.
246
247        Like ncurses5, NetBSD <STRONG>putwin</STRONG> does not identify its dumps with a  useful
248        magic number.  It writes
249
250        <STRONG>o</STRONG>   the curses shared library major and minor versions as the first two
251            bytes (e.g., 7 and 1),
252
253        <STRONG>o</STRONG>   followed by a binary dump of the <STRONG>WINDOW</STRONG>,
254
255        <STRONG>o</STRONG>   some data for wide-characters referenced by the  <STRONG>WINDOW</STRONG>  structure,
256            and
257
258        <STRONG>o</STRONG>   finally, lines as done by other implementations.
259
260
261 </PRE><H2><a name="h2-EXAMPLE">EXAMPLE</a></H2><PRE>
262        Given  a  simple  program  which writes text to the screen (and for the
263        sake of example, limiting the screen-size to 10x20):
264
265            #include &lt;curses.h&gt;
266
267            int
268            main(void)
269            {
270                putenv("LINES=10");
271                putenv("COLUMNS=20");
272                initscr();
273                start_color();
274                init_pair(1, COLOR_WHITE, COLOR_BLUE);
275                init_pair(2, COLOR_RED, COLOR_BLACK);
276                bkgd(<STRONG>COLOR_PAIR(1)</STRONG>);
277                move(4, 5);
278                attron(A_BOLD);
279                addstr("Hello");
280                move(5, 5);
281                attroff(A_BOLD);
282                attrset(A_REVERSE | <STRONG>COLOR_PAIR(2)</STRONG>);
283                addstr("World!");
284                refresh();
285                scr_dump("foo.out");
286                endwin();
287                return 0;
288            }
289
290        When run using ncurses6, the output looks like this:
291
292            \210\210\210\210ncurses 6.0.20170415
293            _cury=5
294            _curx=11
295            _maxy=9
296            _maxx=19
297            _flags=14
298            _attrs=\{REVERSE|C2}
299            flag=_idcok
300            _delay=-1
301            _regbottom=9
302            _bkgrnd=\{NORMAL|C1}\s
303            rows:
304            1:\{NORMAL|C1}\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s
305            2:\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s
306            3:\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s
307            4:\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s
308            5:\s\s\s\s\s\{BOLD}Hello\{NORMAL}\s\s\s\s\s\s\s\s\s\s
309            6:\s\s\s\s\s\{REVERSE|C2}World!\{NORMAL|C1}\s\s\s\s\s\s\s\s\s
310            7:\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s
311            8:\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s
312            9:\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s
313            10:\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s
314
315        The first four octal escapes are actually nonprinting characters, while
316        the remainder of the file is printable text.  You may notice:
317
318        <STRONG>o</STRONG>   The actual color pair values are not written to the file.
319
320        <STRONG>o</STRONG>   All  characters  are  shown  in  printable form; spaces are "\s" to
321            ensure they are not overlooked.
322
323        <STRONG>o</STRONG>   Attributes are written in escaped curly  braces,  e.g.,  "\{BOLD}",
324            and may include a color-pair (C1 or C2 in this example).
325
326        <STRONG>o</STRONG>   The  parameters  in  the  header  are  written out only if they are
327            nonzero.  When reading back, order does not matter.
328
329        Running the same program with Solaris <EM>xpg4</EM> curses gives this dump:
330
331            MAX=10,20
332            BEG=0,0
333            SCROLL=0,10
334            VMIN=1
335            VTIME=0
336            FLAGS=0x1000
337            FG=0,0
338            BG=0,0,
339            0,0,0,1,
340            0,19,0,0,
341            1,0,0,1,
342            1,19,0,0,
343            2,0,0,1,
344            2,19,0,0,
345            3,0,0,1,
346            3,19,0,0,
347            4,0,0,1,
348            4,5,0x20,0,Hello
349            4,10,0,1,
350            4,19,0,0,
351            5,0,0,1,
352            5,5,0x4,2,World!
353            5,11,0,1,
354            5,19,0,0,
355            6,0,0,1,
356            6,19,0,0,
357            7,0,0,1,
358            7,19,0,0,
359            8,0,0,1,
360            8,19,0,0,
361            9,0,0,1,
362            9,19,0,0,
363            CUR=11,5
364
365        Solaris <STRONG>getwin</STRONG> requires that all parameters are  present,  and  in  the
366        same  order.  The <EM>xpg4</EM> curses library does not know about the <STRONG>bce</STRONG> (back
367        color erase) capability, and does not color the window background.
368
369        On the other  hand,  the  SVr4  curses  library  does  know  about  the
370        background  color.   However,  its screen dumps are in binary.  Here is
371        the corresponding dump (using "od -t x1"):
372
373            0000000 1c 01 c3 d6 f3 58 05 00 0b 00 0a 00 14 00 00 00
374            0000020 00 00 02 00 00 00 00 00 00 00 00 00 00 00 00 00
375            0000040 00 00 b8 1a 06 08 cc 1a 06 08 00 00 09 00 10 00
376            0000060 00 00 00 80 00 00 20 00 00 00 ff ff ff ff 00 00
377            0000100 ff ff ff ff 00 00 00 00 20 80 00 00 20 80 00 00
378            0000120 20 80 00 00 20 80 00 00 20 80 00 00 20 80 00 00
379            *
380            0000620 20 80 00 00 20 80 00 00 20 80 00 00 48 80 00 04
381            0000640 65 80 00 04 6c 80 00 04 6c 80 00 04 6f 80 00 04
382            0000660 20 80 00 00 20 80 00 00 20 80 00 00 20 80 00 00
383            *
384            0000740 20 80 00 00 20 80 00 00 20 80 00 00 57 00 81 00
385            0000760 6f 00 81 00 72 00 81 00 6c 00 81 00 64 00 81 00
386            0001000 21 00 81 00 20 80 00 00 20 80 00 00 20 80 00 00
387            0001020 20 80 00 00 20 80 00 00 20 80 00 00 20 80 00 00
388            *
389            0001540 20 80 00 00 20 80 00 00 00 00 f6 d1 01 00 f6 d1
390            0001560 08 00 00 00 40 00 00 00 00 00 00 00 00 00 00 07
391            0001600 00 04 00 01 00 01 00 00 00 01 00 00 00 00 00 00
392            0001620 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
393            *
394            0002371
395
396
397 </PRE><H2><a name="h2-SEE-ALSO">SEE ALSO</a></H2><PRE>
398        <STRONG><A HREF="curs_scr_dump.3x.html">curs_scr_dump(3x)</A></STRONG>, <STRONG><A HREF="curs_util.3x.html">curs_util(3x)</A></STRONG>.
399
400
401 </PRE><H2><a name="h2-AUTHORS">AUTHORS</a></H2><PRE>
402        Thomas E. Dickey
403        extended screen-dump format for ncurses 6.0 (2015)
404
405        Eric S. Raymond
406        screen dump feature in ncurses 1.9.2d (1995)
407
408
409
410                                                                    <STRONG><A HREF="scr_dump.5.html">scr_dump(5)</A></STRONG>
411 </PRE>
412 <div class="nav">
413 <ul>
414 <li><a href="#h2-NAME">NAME</a></li>
415 <li><a href="#h2-SYNOPSIS">SYNOPSIS</a></li>
416 <li><a href="#h2-DESCRIPTION">DESCRIPTION</a>
417 <ul>
418 <li><a href="#h3-ncurses6">ncurses6</a></li>
419 <li><a href="#h3-ncurses5-_legacy_">ncurses5 (legacy)</a></li>
420 </ul>
421 </li>
422 <li><a href="#h2-PORTABILITY">PORTABILITY</a>
423 <ul>
424 <li><a href="#h3-X_Open-Curses">X/Open Curses</a></li>
425 <li><a href="#h3-Unix-SystemV">Unix SystemV</a></li>
426 <li><a href="#h3-Solaris">Solaris</a></li>
427 <li><a href="#h3-PDCurses">PDCurses</a></li>
428 <li><a href="#h3-NetBSD">NetBSD</a></li>
429 </ul>
430 </li>
431 <li><a href="#h2-EXAMPLE">EXAMPLE</a></li>
432 <li><a href="#h2-SEE-ALSO">SEE ALSO</a></li>
433 <li><a href="#h2-AUTHORS">AUTHORS</a></li>
434 </ul>
435 </div>
436 </BODY>
437 </HTML>