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