2N/A/*
2N/A * CDDL HEADER START
2N/A *
2N/A * The contents of this file are subject to the terms of the
2N/A * Common Development and Distribution License, Version 1.0 only
2N/A * (the "License"). You may not use this file except in compliance
2N/A * with the License.
2N/A *
2N/A * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
2N/A * or http://www.opensolaris.org/os/licensing.
2N/A * See the License for the specific language governing permissions
2N/A * and limitations under the License.
2N/A *
2N/A * When distributing Covered Code, include this CDDL HEADER in each
2N/A * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
2N/A * If applicable, add the following below this CDDL HEADER, with the
2N/A * fields enclosed by brackets "[]" replaced with your own identifying
2N/A * information: Portions Copyright [yyyy] [name of copyright owner]
2N/A *
2N/A * CDDL HEADER END
2N/A */
2N/A/*
2N/A * Copyright (c) 1995-1998 by Sun Microsystems, Inc.
2N/A * All rights reserved.
2N/A */
2N/A
2N/A#pragma ident "%Z%%M% %I% %E% SMI"
2N/A
2N/A/* LINTLIBRARY */
2N/A
2N/A/*
2N/A * getwin.c
2N/A *
2N/A * XCurses Library
2N/A *
2N/A * Copyright 1990, 1995 by Mortice Kern Systems Inc. All rights reserved.
2N/A *
2N/A */
2N/A
2N/A#if M_RCSID
2N/A#ifndef lint
2N/Astatic char rcsID[] = "$Header: /rd/src/libc/xcurses/rcs/getwin.c 1.2 "
2N/A"1995/06/12 17:48:38 ant Exp $";
2N/A#endif
2N/A#endif
2N/A
2N/A#include <private.h>
2N/A#include <limits.h>
2N/A
2N/A#undef mvwaddstr
2N/A#undef wstandend
2N/A
2N/Astatic int
2N/Aget_cc(WINDOW *w, char *mbs, FILE *fp)
2N/A{
2N/A short co;
2N/A attr_t at;
2N/A int n, y, x;
2N/A
2N/A if (fscanf(fp, "%d,%d,%hx,%hd,", &y, &x, &at, &co) < 4)
2N/A return (0);
2N/A
2N/A if (fscanf(fp, "%[^\n]%n ", mbs, &n) < 1)
2N/A return (0);
2N/A
2N/A if (wattr_set(w, at, co, (void *) 0) == ERR)
2N/A return (0);
2N/A
2N/A if (mvwaddstr(w, y, x, mbs) == ERR)
2N/A return (0);
2N/A
2N/A (void) wstandend(w);
2N/A
2N/A return (n);
2N/A}
2N/A
2N/AWINDOW *
2N/Agetwin(FILE *fp)
2N/A{
2N/A char *mbs;
2N/A WINDOW *w;
2N/A unsigned short flags;
2N/A int by, bx, my, mx;
2N/A
2N/A /* Get window dimensions and location to create a new window. */
2N/A if (fscanf(fp, "MAX=%d,%d BEG=%d,%d ", &my, &mx, &by, &bx) < 4)
2N/A goto error1;
2N/A
2N/A if ((mbs = (char *) malloc((size_t) (LINE_MAX+1))) == NULL)
2N/A goto error1;
2N/A
2N/A if ((w = newwin(my, mx, by, bx)) == NULL)
2N/A goto error2;
2N/A
2N/A /* Read other window attributes. */
2N/A by = fscanf(fp,
2N/A "SCROLL=%hd,%hd VMIN=%hd VTIME=%hd FLAGS=%hx FG=%hx,%hd ",
2N/A &w->_top, &w->_bottom, &w->_vmin, &w->_vtime, &flags,
2N/A &w->_fg._at, &w->_fg._co);
2N/A if (by < 7)
2N/A goto error3;
2N/A
2N/A w->_flags &= ~W_CONFIG_MASK;
2N/A w->_flags |= flags;
2N/A
2N/A by = fscanf(fp, "BG=%hx,%hd,%[^\n] ", &w->_bg._at, &w->_bg._co, mbs);
2N/A if (by < 3)
2N/A goto error3;
2N/A
2N/A while (get_cc(w, mbs, fp))
2N/A ;
2N/A
2N/A if (fscanf(fp, "CUR=%hd,%hd", &w->_cury, &w->_curx) < 2)
2N/A goto error3;
2N/A
2N/A free(mbs);
2N/A
2N/A return (w);
2N/Aerror3:
2N/A (void) delwin(w);
2N/Aerror2:
2N/A free(mbs);
2N/Aerror1:
2N/A rewind(fp);
2N/A
2N/A return (NULL);
2N/A}
2N/A
2N/Astatic int
2N/Aput_cc(WINDOW *w, int y, int x,
2N/A char *mbs, int len, FILE *fp)
2N/A{
2N/A int i;
2N/A short co;
2N/A attr_t at;
2N/A
2N/A at = w->_line[y][x]._at;
2N/A co = w->_line[y][x]._co;
2N/A
2N/A /* Write first character as a multibyte string. */
2N/A (void) __m_cc_mbs(&w->_line[y][x], mbs, len);
2N/A
2N/A /* Write additional characters with same colour and attributes. */
2N/A for (i = x; ; ) {
2N/A i = __m_cc_next(w, y, i);
2N/A if (w->_maxx <= i)
2N/A break;
2N/A if (w->_line[y][i]._at != at || w->_line[y][i]._co != co)
2N/A break;
2N/A (void) __m_cc_mbs(&w->_line[y][i], mbs, 0);
2N/A }
2N/A
2N/A /* Terminate string. */
2N/A (void) __m_cc_mbs((const cchar_t *) 0, (char *) 0, 0);
2N/A
2N/A (void) fprintf(fp, "%d,%d,%#x,%d,%s\n", y, x, at, co, mbs);
2N/A
2N/A /* Return index of next unprocessed column. */
2N/A return (i);
2N/A}
2N/A
2N/Aint
2N/Aputwin(WINDOW *w, FILE *fp)
2N/A{
2N/A char *mbs;
2N/A size_t mbs_len;
2N/A int y, x;
2N/A
2N/A mbs_len = columns * _M_CCHAR_MAX * MB_LEN_MAX * sizeof (*mbs) + 1;
2N/A if ((mbs = (char *) malloc((size_t) mbs_len)) == (char *) 0)
2N/A return (ERR);
2N/A
2N/A (void) fprintf(fp,
2N/A "MAX=%d,%d\nBEG=%d,%d\nSCROLL=%d,%d\n",
2N/A w->_maxy, w->_maxx, w->_begy, w->_begx, w->_top, w->_bottom);
2N/A (void) fprintf(fp,
2N/A "VMIN=%d\nVTIME=%d\nFLAGS=%#x\nFG=%#x,%d\n",
2N/A w->_vmin, w->_vtime, w->_flags & W_CONFIG_MASK,
2N/A w->_fg._at, w->_fg._co);
2N/A
2N/A (void) __m_cc_mbs(&w->_bg, mbs, (int)mbs_len);
2N/A (void) __m_cc_mbs((const cchar_t *) 0, (char *) 0, 0);
2N/A (void) fprintf(fp, "BG=%#x,%d,%s\n", w->_bg._at, w->_bg._co, mbs);
2N/A
2N/A for (y = 0; y < w->_maxy; ++y) {
2N/A for (x = 0; x < w->_maxx; )
2N/A x = put_cc(w, y, x, mbs, (int)mbs_len, fp);
2N/A }
2N/A
2N/A (void) fprintf(fp, "CUR=%d,%d\n", w->_curx, w->_cury);
2N/A
2N/A free(mbs);
2N/A
2N/A return (OK);
2N/A}