aboutsummaryrefslogtreecommitdiff
path: root/contrib/ncurses/ncurses/base/lib_screen.c
diff options
context:
space:
mode:
authorRong-En Fan <rafan@FreeBSD.org>2007-01-20 07:32:02 +0000
committerRong-En Fan <rafan@FreeBSD.org>2007-01-20 07:32:02 +0000
commit4a1a95108dd76c4259fe6c37c4471f7969b17983 (patch)
tree1c6c3b549401156e1dbd96b9a6b18521f63ffb58 /contrib/ncurses/ncurses/base/lib_screen.c
parent555c9cae3cf9146482732c28c06a73314b618149 (diff)
downloadsrc-4a1a95108dd76c4259fe6c37c4471f7969b17983.tar.gz
src-4a1a95108dd76c4259fe6c37c4471f7969b17983.zip
Import ncurses 5.6-20061217 onto the vender branch
Approved by: delphij
Notes
Notes: svn path=/vendor/ncurses/dist/; revision=166124
Diffstat (limited to 'contrib/ncurses/ncurses/base/lib_screen.c')
-rw-r--r--contrib/ncurses/ncurses/base/lib_screen.c141
1 files changed, 75 insertions, 66 deletions
diff --git a/contrib/ncurses/ncurses/base/lib_screen.c b/contrib/ncurses/ncurses/base/lib_screen.c
index 3b2d9296a59a..5d67e1993cd9 100644
--- a/contrib/ncurses/ncurses/base/lib_screen.c
+++ b/contrib/ncurses/ncurses/base/lib_screen.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * Copyright (c) 1998,2000,2001 Free Software Foundation, Inc. *
+ * Copyright (c) 1998-2002,2006 Free Software Foundation, Inc. *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
* copy of this software and associated documentation files (the *
@@ -29,92 +29,105 @@
/****************************************************************************
* Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 *
* and: Eric S. Raymond <esr@snark.thyrsus.com> *
+ * and: Thomas E. Dickey 1996 on *
****************************************************************************/
#include <curses.priv.h>
-#include <sys/stat.h>
-#include <time.h>
-#include <term.h> /* exit_ca_mode, non_rev_rmcup */
-
-MODULE_ID("$Id: lib_screen.c,v 1.19 2001/12/19 00:55:28 tom Exp $")
-
-static time_t dumptime;
+MODULE_ID("$Id: lib_screen.c,v 1.29 2006/05/27 19:21:38 tom Exp $")
NCURSES_EXPORT(WINDOW *)
-getwin(FILE * filep)
+getwin(FILE *filep)
{
WINDOW tmp, *nwin;
int n;
T((T_CALLED("getwin(%p)"), filep));
+ clearerr(filep);
(void) fread(&tmp, sizeof(WINDOW), 1, filep);
if (ferror(filep))
returnWin(0);
- if ((nwin = newwin(tmp._maxy + 1, tmp._maxx + 1, 0, 0)) == 0)
- returnWin(0);
+ if (tmp._flags & _ISPAD) {
+ nwin = newpad(tmp._maxy + 1, tmp._maxx + 1);
+ } else {
+ nwin = newwin(tmp._maxy + 1, tmp._maxx + 1, 0, 0);
+ }
/*
* We deliberately do not restore the _parx, _pary, or _parent
* fields, because the window hierarchy within which they
* made sense is probably gone.
*/
- nwin->_curx = tmp._curx;
- nwin->_cury = tmp._cury;
- nwin->_maxy = tmp._maxy;
- nwin->_maxx = tmp._maxx;
- nwin->_begy = tmp._begy;
- nwin->_begx = tmp._begx;
- nwin->_yoffset = tmp._yoffset;
- nwin->_flags = tmp._flags & ~(_SUBWIN | _ISPAD);
-
- nwin->_attrs = tmp._attrs;
- nwin->_nc_bkgd = tmp._nc_bkgd;
-
- nwin->_clear = tmp._clear;
- nwin->_scroll = tmp._scroll;
- nwin->_leaveok = tmp._leaveok;
- nwin->_use_keypad = tmp._use_keypad;
- nwin->_delay = tmp._delay;
- nwin->_immed = tmp._immed;
- nwin->_sync = tmp._sync;
-
- nwin->_regtop = tmp._regtop;
- nwin->_regbottom = tmp._regbottom;
-
- for (n = 0; n < nwin->_maxy + 1; n++) {
- (void) fread(nwin->_line[n].text,
- sizeof(chtype), (size_t) (nwin->_maxx + 1), filep);
- if (ferror(filep)) {
- delwin(nwin);
- returnWin(0);
+ if (nwin != 0) {
+ nwin->_curx = tmp._curx;
+ nwin->_cury = tmp._cury;
+ nwin->_maxy = tmp._maxy;
+ nwin->_maxx = tmp._maxx;
+ nwin->_begy = tmp._begy;
+ nwin->_begx = tmp._begx;
+ nwin->_yoffset = tmp._yoffset;
+ nwin->_flags = tmp._flags & ~(_SUBWIN);
+
+ WINDOW_ATTRS(nwin) = WINDOW_ATTRS(&tmp);
+ nwin->_nc_bkgd = tmp._nc_bkgd;
+
+ nwin->_notimeout = tmp._notimeout;
+ nwin->_clear = tmp._clear;
+ nwin->_leaveok = tmp._leaveok;
+ nwin->_idlok = tmp._idlok;
+ nwin->_idcok = tmp._idcok;
+ nwin->_immed = tmp._immed;
+ nwin->_scroll = tmp._scroll;
+ nwin->_sync = tmp._sync;
+ nwin->_use_keypad = tmp._use_keypad;
+ nwin->_delay = tmp._delay;
+
+ nwin->_regtop = tmp._regtop;
+ nwin->_regbottom = tmp._regbottom;
+
+ if (tmp._flags & _ISPAD)
+ nwin->_pad = tmp._pad;
+
+ for (n = 0; n <= nwin->_maxy; n++) {
+ clearerr(filep);
+ (void) fread(nwin->_line[n].text,
+ sizeof(NCURSES_CH_T),
+ (size_t) (nwin->_maxx + 1),
+ filep);
+ if (ferror(filep)) {
+ delwin(nwin);
+ returnWin(0);
+ }
}
+ touchwin(nwin);
}
- touchwin(nwin);
-
returnWin(nwin);
}
NCURSES_EXPORT(int)
-putwin(WINDOW *win, FILE * filep)
+putwin(WINDOW *win, FILE *filep)
{
int code = ERR;
int n;
T((T_CALLED("putwin(%p,%p)"), win, filep));
- if (win) {
- (void) fwrite(win, sizeof(WINDOW), 1, filep);
- if (ferror(filep))
- returnCode(code);
+ if (win != 0) {
+ size_t len = (win->_maxx + 1);
+
+ clearerr(filep);
+ if (fwrite(win, sizeof(WINDOW), 1, filep) != 1
+ || ferror(filep))
+ returnCode(code);
- for (n = 0; n < win->_maxy + 1; n++) {
- (void) fwrite(win->_line[n].text,
- sizeof(chtype), (size_t) (win->_maxx + 1), filep);
- if (ferror(filep))
+ for (n = 0; n <= win->_maxy; n++) {
+ if (fwrite(win->_line[n].text,
+ sizeof(NCURSES_CH_T), len, filep) != len
+ || ferror(filep)) {
returnCode(code);
+ }
}
code = OK;
}
@@ -129,11 +142,11 @@ scr_restore(const char *file)
T((T_CALLED("scr_restore(%s)"), _nc_visbuf(file)));
if (_nc_access(file, R_OK) < 0
- || (fp = fopen(file, "rb")) == 0)
+ || (fp = fopen(file, "rb")) == 0) {
returnCode(ERR);
- else {
+ } else {
delwin(newscr);
- newscr = getwin(fp);
+ SP->_newscr = newscr = getwin(fp);
(void) fclose(fp);
returnCode(OK);
}
@@ -147,12 +160,11 @@ scr_dump(const char *file)
T((T_CALLED("scr_dump(%s)"), _nc_visbuf(file)));
if (_nc_access(file, W_OK) < 0
- || (fp = fopen(file, "wb")) == 0)
+ || (fp = fopen(file, "wb")) == 0) {
returnCode(ERR);
- else {
+ } else {
(void) putwin(newscr, fp);
(void) fclose(fp);
- dumptime = time((time_t *) 0);
returnCode(OK);
}
}
@@ -161,7 +173,6 @@ NCURSES_EXPORT(int)
scr_init(const char *file)
{
FILE *fp = 0;
- struct stat stb;
T((T_CALLED("scr_init(%s)"), _nc_visbuf(file)));
@@ -169,13 +180,11 @@ scr_init(const char *file)
returnCode(ERR);
if (_nc_access(file, R_OK) < 0
- || (fp = fopen(file, "rb")) == 0)
- returnCode(ERR);
- else if (fstat(STDOUT_FILENO, &stb) || stb.st_mtime > dumptime)
+ || (fp = fopen(file, "rb")) == 0) {
returnCode(ERR);
- else {
+ } else {
delwin(curscr);
- curscr = getwin(fp);
+ SP->_curscr = curscr = getwin(fp);
(void) fclose(fp);
returnCode(OK);
}
@@ -186,11 +195,11 @@ scr_set(const char *file)
{
T((T_CALLED("scr_set(%s)"), _nc_visbuf(file)));
- if (scr_init(file) == ERR)
+ if (scr_init(file) == ERR) {
returnCode(ERR);
- else {
+ } else {
delwin(newscr);
- newscr = dupwin(curscr);
+ SP->_newscr = newscr = dupwin(curscr);
returnCode(OK);
}
}