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