17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate * CDDL HEADER START
37c478bd9Sstevel@tonic-gate *
47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the
5*004388ebScasper * Common Development and Distribution License (the "License").
6*004388ebScasper * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate *
87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate * and limitations under the License.
127c478bd9Sstevel@tonic-gate *
137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate *
197c478bd9Sstevel@tonic-gate * CDDL HEADER END
207c478bd9Sstevel@tonic-gate */
217c478bd9Sstevel@tonic-gate /*
22*004388ebScasper * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
23*004388ebScasper * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate */
257c478bd9Sstevel@tonic-gate
267c478bd9Sstevel@tonic-gate /*
277c478bd9Sstevel@tonic-gate * scr_dump.c
28*004388ebScasper *
297c478bd9Sstevel@tonic-gate * XCurses Library
307c478bd9Sstevel@tonic-gate *
317c478bd9Sstevel@tonic-gate * Copyright 1990, 1995 by Mortice Kern Systems Inc. All rights reserved.
327c478bd9Sstevel@tonic-gate *
337c478bd9Sstevel@tonic-gate */
347c478bd9Sstevel@tonic-gate
357c478bd9Sstevel@tonic-gate #if M_RCSID
367c478bd9Sstevel@tonic-gate #ifndef lint
377c478bd9Sstevel@tonic-gate static char rcsID[] = "$Header: /rd/src/libc/xcurses/rcs/scr_dump.c 1.1 1995/06/21 16:19:43 ant Exp $";
387c478bd9Sstevel@tonic-gate #endif
397c478bd9Sstevel@tonic-gate #endif
407c478bd9Sstevel@tonic-gate
417c478bd9Sstevel@tonic-gate #include <private.h>
427c478bd9Sstevel@tonic-gate #include <sys/types.h>
437c478bd9Sstevel@tonic-gate #include <sys/stat.h>
447c478bd9Sstevel@tonic-gate
457c478bd9Sstevel@tonic-gate /*
467c478bd9Sstevel@tonic-gate * Save the current screen image.
477c478bd9Sstevel@tonic-gate */
487c478bd9Sstevel@tonic-gate int
scr_dump(f)497c478bd9Sstevel@tonic-gate scr_dump(f)
507c478bd9Sstevel@tonic-gate const char *f;
517c478bd9Sstevel@tonic-gate {
527c478bd9Sstevel@tonic-gate int code;
537c478bd9Sstevel@tonic-gate FILE *fp;
547c478bd9Sstevel@tonic-gate
557c478bd9Sstevel@tonic-gate #ifdef M_CURSES_TRACE
567c478bd9Sstevel@tonic-gate __m_trace("scr_dump(%p=\"%s\")", f);
577c478bd9Sstevel@tonic-gate #endif
587c478bd9Sstevel@tonic-gate
597c478bd9Sstevel@tonic-gate code = ERR;
607c478bd9Sstevel@tonic-gate
61*004388ebScasper if ((fp = fopen(f, "wF")) != (FILE *) 0) {
627c478bd9Sstevel@tonic-gate code = putwin(curscr, fp);
637c478bd9Sstevel@tonic-gate (void) fclose(fp);
647c478bd9Sstevel@tonic-gate }
657c478bd9Sstevel@tonic-gate
667c478bd9Sstevel@tonic-gate return __m_return_code("scr_dump", code);
677c478bd9Sstevel@tonic-gate }
687c478bd9Sstevel@tonic-gate
697c478bd9Sstevel@tonic-gate static int
scr_replace(w,f)707c478bd9Sstevel@tonic-gate scr_replace(w, f)
717c478bd9Sstevel@tonic-gate WINDOW *w;
727c478bd9Sstevel@tonic-gate const char *f;
737c478bd9Sstevel@tonic-gate {
747c478bd9Sstevel@tonic-gate int i;
757c478bd9Sstevel@tonic-gate FILE *fp;
767c478bd9Sstevel@tonic-gate WINDOW *new;
777c478bd9Sstevel@tonic-gate
78*004388ebScasper if ((fp = fopen(f, "rF")) == (FILE *) 0)
797c478bd9Sstevel@tonic-gate return ERR;
807c478bd9Sstevel@tonic-gate
817c478bd9Sstevel@tonic-gate new = getwin(fp);
827c478bd9Sstevel@tonic-gate (void) fclose(fp);
837c478bd9Sstevel@tonic-gate
847c478bd9Sstevel@tonic-gate if (new == (WINDOW *) 0)
857c478bd9Sstevel@tonic-gate return ERR;
867c478bd9Sstevel@tonic-gate
877c478bd9Sstevel@tonic-gate if (new->_maxy != w->_maxy || new->_maxx != w->_maxx) {
887c478bd9Sstevel@tonic-gate (void) delwin(new);
897c478bd9Sstevel@tonic-gate return ERR;
907c478bd9Sstevel@tonic-gate }
917c478bd9Sstevel@tonic-gate
927c478bd9Sstevel@tonic-gate /* Replace contents of curscr window structure. */
937c478bd9Sstevel@tonic-gate free(w->_base);
947c478bd9Sstevel@tonic-gate free(w->_line);
957c478bd9Sstevel@tonic-gate free(w->_first);
967c478bd9Sstevel@tonic-gate *w = *new;
977c478bd9Sstevel@tonic-gate
987c478bd9Sstevel@tonic-gate /* Rehash the current screen? */
997c478bd9Sstevel@tonic-gate if (w == curscr)
1007c478bd9Sstevel@tonic-gate for (i = 0; i < w->_maxy; ++i)
1017c478bd9Sstevel@tonic-gate __m_cc_hash(w, __m_screen->_hash, i);
1027c478bd9Sstevel@tonic-gate
1037c478bd9Sstevel@tonic-gate /* Discard the working window. */
1047c478bd9Sstevel@tonic-gate new->_base = (cchar_t *) 0;
1057c478bd9Sstevel@tonic-gate new->_line = (cchar_t **) 0;
1067c478bd9Sstevel@tonic-gate new->_first = (short *) 0;
1077c478bd9Sstevel@tonic-gate (void) delwin(new);
1087c478bd9Sstevel@tonic-gate
1097c478bd9Sstevel@tonic-gate return OK;
1107c478bd9Sstevel@tonic-gate }
1117c478bd9Sstevel@tonic-gate
1127c478bd9Sstevel@tonic-gate /*
1137c478bd9Sstevel@tonic-gate * A picture of what scr_restore(), scr_init(), and scr_set() do :
1147c478bd9Sstevel@tonic-gate *
1157c478bd9Sstevel@tonic-gate * scr_restore() scr_init()
1167c478bd9Sstevel@tonic-gate * | |
1177c478bd9Sstevel@tonic-gate * stdscr V V
1187c478bd9Sstevel@tonic-gate * +----+ newscr curscr
1197c478bd9Sstevel@tonic-gate * | | +-------+ +-------+
1207c478bd9Sstevel@tonic-gate * +----+ refresh() -> | | | |
1217c478bd9Sstevel@tonic-gate * | | doupdate() -> | |
1227c478bd9Sstevel@tonic-gate * w | | | |
1237c478bd9Sstevel@tonic-gate * +----+ wrefresh(w) -> | | | |
1247c478bd9Sstevel@tonic-gate * | | +-------+ +-------+
1257c478bd9Sstevel@tonic-gate * +----+ ^ ^
1267c478bd9Sstevel@tonic-gate * | |
1277c478bd9Sstevel@tonic-gate * \---- scr_set() ----/
1287c478bd9Sstevel@tonic-gate */
1297c478bd9Sstevel@tonic-gate
1307c478bd9Sstevel@tonic-gate /*
1317c478bd9Sstevel@tonic-gate * Get a screen image that will appear next doupdate(),
1327c478bd9Sstevel@tonic-gate * replacing the current screen.
1337c478bd9Sstevel@tonic-gate */
1347c478bd9Sstevel@tonic-gate int
scr_restore(f)1357c478bd9Sstevel@tonic-gate scr_restore(f)
1367c478bd9Sstevel@tonic-gate const char *f;
1377c478bd9Sstevel@tonic-gate {
1387c478bd9Sstevel@tonic-gate int code;
1397c478bd9Sstevel@tonic-gate
1407c478bd9Sstevel@tonic-gate #ifdef M_CURSES_TRACE
1417c478bd9Sstevel@tonic-gate __m_trace("scr_restore(%p=\"%s\")", f);
1427c478bd9Sstevel@tonic-gate #endif
1437c478bd9Sstevel@tonic-gate
1447c478bd9Sstevel@tonic-gate code = scr_replace(__m_screen->_newscr, f);
1457c478bd9Sstevel@tonic-gate
1467c478bd9Sstevel@tonic-gate return __m_return_code("scr_restore", code);
1477c478bd9Sstevel@tonic-gate }
1487c478bd9Sstevel@tonic-gate
1497c478bd9Sstevel@tonic-gate /*
150*004388ebScasper * Get the screen image that really reflects what is on the screen,
151*004388ebScasper * though the applicatiion may not want it. A subsequent doupdate()
1527c478bd9Sstevel@tonic-gate * will compared and make changes against this image.
1537c478bd9Sstevel@tonic-gate */
1547c478bd9Sstevel@tonic-gate int
scr_init(f)1557c478bd9Sstevel@tonic-gate scr_init(f)
1567c478bd9Sstevel@tonic-gate const char *f;
1577c478bd9Sstevel@tonic-gate {
1587c478bd9Sstevel@tonic-gate int code;
1597c478bd9Sstevel@tonic-gate struct stat tty, dump;
1607c478bd9Sstevel@tonic-gate
1617c478bd9Sstevel@tonic-gate #ifdef M_CURSES_TRACE
1627c478bd9Sstevel@tonic-gate __m_trace("scr_init(%p=\"%s\")", f);
1637c478bd9Sstevel@tonic-gate #endif
1647c478bd9Sstevel@tonic-gate
165*004388ebScasper if ((non_rev_rmcup && exit_ca_mode != (char *) 0)
166*004388ebScasper || stat(f, &dump) != 0 || stat(ctermid((char *) 0), &tty) != 0
167*004388ebScasper || dump.st_mtime < tty.st_mtime)
1687c478bd9Sstevel@tonic-gate code = ERR;
169*004388ebScasper else
1707c478bd9Sstevel@tonic-gate code = scr_replace(__m_screen->_curscr, f);
1717c478bd9Sstevel@tonic-gate
1727c478bd9Sstevel@tonic-gate return __m_return_code("scr_init", code);
1737c478bd9Sstevel@tonic-gate }
1747c478bd9Sstevel@tonic-gate
1757c478bd9Sstevel@tonic-gate /*
1767c478bd9Sstevel@tonic-gate * Get the screen image that is really on the screen and that the
177*004388ebScasper * application wants on the screen.
1787c478bd9Sstevel@tonic-gate */
1797c478bd9Sstevel@tonic-gate int
scr_set(f)1807c478bd9Sstevel@tonic-gate scr_set(f)
1817c478bd9Sstevel@tonic-gate const char *f;
1827c478bd9Sstevel@tonic-gate {
1837c478bd9Sstevel@tonic-gate int code;
1847c478bd9Sstevel@tonic-gate
1857c478bd9Sstevel@tonic-gate #ifdef M_CURSES_TRACE
1867c478bd9Sstevel@tonic-gate __m_trace("scr_set(%p=\"%s\")", f);
1877c478bd9Sstevel@tonic-gate #endif
1887c478bd9Sstevel@tonic-gate
1897c478bd9Sstevel@tonic-gate if ((code = scr_init(f)) == OK)
1907c478bd9Sstevel@tonic-gate code = scr_restore(f);
1917c478bd9Sstevel@tonic-gate
1927c478bd9Sstevel@tonic-gate return __m_return_code("scr_set", code);
1937c478bd9Sstevel@tonic-gate }
1947c478bd9Sstevel@tonic-gate
195