2 /***************************************************************************
4 ****************************************************************************
5 * ncurses is copyright (C) 1992-1995 *
7 * zmbenhal@netcom.com *
9 * esr@snark.thyrsus.com *
11 * Permission is hereby granted to reproduce and distribute ncurses *
12 * by any means and for any fee, whether alone or as part of a *
13 * larger distribution, in source or in binary form, PROVIDED *
14 * this notice is included with any such distribution, and is not *
15 * removed from any of its header files. Mention of ncurses in any *
16 * applications linked with it is highly appreciated. *
18 * ncurses comes AS IS with no warranty, implied or expressed. *
20 ***************************************************************************/
23 #include <curses.priv.h>
27 #include <term.h> /* exit_ca_mode, non_rev_rmcup */
29 MODULE_ID("$Id: lib_screen.c,v 1.7 1997/02/02 00:41:10 tom Exp $")
31 static time_t dumptime;
33 WINDOW *getwin(FILE *filep)
38 T((T_CALLED("getwin(%p)"), filep));
40 (void) fread(&try, sizeof(WINDOW), 1, filep);
44 if ((nwin = newwin(try._maxy+1, try._maxx+1, 0, 0)) == 0)
48 * We deliberately do not restore the _parx, _pary, or _parent
49 * fields, because the window hierarchy within which they
50 * made sense is probably gone.
52 nwin->_curx = try._curx;
53 nwin->_cury = try._cury;
54 nwin->_maxy = try._maxy;
55 nwin->_maxx = try._maxx;
56 nwin->_begy = try._begy;
57 nwin->_begx = try._begx;
58 nwin->_yoffset = try._yoffset;
59 nwin->_flags = try._flags & ~(_SUBWIN|_ISPAD);
61 nwin->_attrs = try._attrs;
62 nwin->_bkgd = try._bkgd;
64 nwin->_clear = try._clear;
65 nwin->_scroll = try._scroll;
66 nwin->_leaveok = try._leaveok;
67 nwin->_use_keypad = try._use_keypad;
68 nwin->_delay = try._delay;
69 nwin->_immed = try._immed;
70 nwin->_sync = try._sync;
72 nwin->_regtop = try._regtop;
73 nwin->_regbottom = try._regbottom;
75 for (n = 0; n < nwin->_maxy + 1; n++)
77 (void) fread(nwin->_line[n].text,
78 sizeof(chtype), (size_t)(nwin->_maxx + 1), filep);
90 int putwin(WINDOW *win, FILE *filep)
94 T((T_CALLED("putwin(%p,%p)"), win, filep));
96 (void) fwrite(win, sizeof(WINDOW), 1, filep);
100 for (n = 0; n < win->_maxy + 1; n++)
102 (void) fwrite(win->_line[n].text,
103 sizeof(chtype), (size_t)(win->_maxx + 1), filep);
111 int scr_restore(const char *file)
115 T((T_CALLED("scr_restore(%s)"), _nc_visbuf(file)));
117 if ((fp = fopen(file, "r")) == 0)
128 int scr_dump(const char *file)
132 T((T_CALLED("scr_dump(%s)"), _nc_visbuf(file)));
134 if ((fp = fopen(file, "w")) == 0)
138 (void) putwin(newscr, fp);
140 dumptime = time((time_t *)0);
145 int scr_init(const char *file)
150 T((T_CALLED("scr_init(%s)"), _nc_visbuf(file)));
153 if (exit_ca_mode && non_rev_rmcup)
155 #endif /* exit_ca_mode */
157 if ((fp = fopen(file, "r")) == 0)
159 else if (fstat(STDOUT_FILENO, &stb) || stb.st_mtime > dumptime)
170 int scr_set(const char *file)
172 T((T_CALLED("scr_set(%s)"), _nc_visbuf(file)));
174 if (scr_init(file) == ERR)
179 newscr = dupwin(curscr);