- /*
- * 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->_bkgd = tmp._bkgd;
-
- nwin->_clear = tmp._clear;
- nwin->_scroll = tmp._scroll;
- nwin->_leaveok = tmp._leaveok;
+NCURSES_EXPORT(WINDOW *)
+NCURSES_SP_NAME(getwin) (NCURSES_SP_DCLx FILE *filep)
+{
+ WINDOW tmp, *nwin;
+ int n;
+ bool old_format = FALSE;
+
+ T((T_CALLED("getwin(%p)"), (void *) filep));
+
+ if (filep == 0) {
+ returnWin(0);
+ }
+
+ /*
+ * Read the first 4 bytes to determine first if this is an old-format
+ * screen-dump, or new-format.
+ */
+ if (read_block(&tmp, 4, filep) < 0) {
+ returnWin(0);
+ }
+ /*
+ * If this is a new-format file, and we do not support it, give up.
+ */
+ if (!memcmp(&tmp, my_magic, 4)) {
+#if NCURSES_EXT_PUTWIN
+ if (read_win(&tmp, filep) < 0)
+#endif
+ returnWin(0);
+ } else if (read_block(((char *) &tmp) + 4, sizeof(WINDOW) - 4, filep) < 0) {
+ returnWin(0);
+ } else {
+ old_format = TRUE;
+ }
+
+ /*
+ * Check the window-size:
+ */
+ if (tmp._maxy == 0 ||
+ tmp._maxy > MAX_SIZE ||
+ tmp._maxx == 0 ||
+ tmp._maxx > MAX_SIZE) {
+ returnWin(0);
+ }
+
+ if (tmp._flags & _ISPAD) {
+ nwin = NCURSES_SP_NAME(newpad) (NCURSES_SP_ARGx
+ tmp._maxy + 1,
+ tmp._maxx + 1);
+ } else {
+ nwin = NCURSES_SP_NAME(newwin) (NCURSES_SP_ARGx
+ 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.
+ */
+ if (nwin != 0) {
+ size_t linesize = sizeof(NCURSES_CH_T) * (size_t) (tmp._maxx + 1);
+
+ 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;