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 1997 Sun Microsystems, Inc. All rights reserved.
2N/A * Use is subject to license terms.
2N/A */
2N/A
2N/A/* Copyright (c) 1988 AT&T */
2N/A/* All Rights Reserved */
2N/A
2N/A/*
2N/A * University Copyright- Copyright (c) 1982, 1986, 1988
2N/A * The Regents of the University of California
2N/A * All Rights Reserved
2N/A *
2N/A * University Acknowledgment- Portions of this document are derived from
2N/A * software developed by the University of California, Berkeley, and its
2N/A * contributors.
2N/A */
2N/A
2N/A#pragma ident "%Z%%M% %I% %E% SMI"
2N/A
2N/A/*LINTLIBRARY*/
2N/A
2N/A#include <stdlib.h>
2N/A#include <string.h>
2N/A#include <sys/types.h>
2N/A#include "curses_inc.h"
2N/A
2N/A/*
2N/A * Duplicate a window.
2N/A *
2N/A * SS: calling makenew to allocate a new window is wastefull, since
2N/A * makenew initializes all the variables, and then we re-initialize
2N/A * the desired values to these variables.
2N/A */
2N/A
2N/AWINDOW *
2N/Adupwin(WINDOW *win)
2N/A{
2N/A WINDOW *new;
2N/A int i, ncolumns = win->_maxx, nlines = win->_maxy;
2N/A size_t line_size = nlines * sizeof (short);
2N/A chtype **wincp, **newcp;
2N/A int ncolsav = ncolumns;
2N/A
2N/A /* allocate storage for new window and do block copy of */
2N/A /* old one into new */
2N/A
2N/A if ((new = (WINDOW *) malloc(sizeof (WINDOW))) == NULL)
2N/A goto out0;
2N/A
2N/A (void) memcpy(new, win, sizeof (WINDOW));
2N/A
2N/A /* allocate storage for "malloced" fields of the new window */
2N/A
2N/A if ((new->_firstch = (short *)malloc((unsigned)2 * line_size)) == NULL)
2N/A goto out1;
2N/A else
2N/A win->_lastch = win->_firstch + nlines;
2N/A
2N/A if ((new->_y = (chtype **) malloc(nlines * sizeof (chtype *))) ==
2N/A NULL) {
2N/A /*
2N/A * We put the free's here rather than after the image call, this
2N/A * is because _image free's all the rest of the malloc'ed areas.
2N/A */
2N/A free((char *)new->_firstch);
2N/Aout1:
2N/A free((char *)new);
2N/A goto out0;
2N/A }
2N/A
2N/A if (_image(new) == ERR) {
2N/Aout0:
2N/A curs_errno = CURS_BAD_MALLOC;
2N/A#ifdef DEBUG
2N/A strcpy(curs_parm_err, "dupwin");
2N/A curserr();
2N/A#endif /* DEBUG */
2N/A return ((WINDOW *) NULL);
2N/A }
2N/A
2N/A /* copy information from "malloced" areas of the old window into new */
2N/A
2N/A wincp = win->_y;
2N/A newcp = new->_y;
2N/A for (i = 0; i < nlines; ++i, ++wincp, ++newcp) {
2N/A chtype *ws, *we, *ns, *ne, wc;
2N/A int n;
2N/A
2N/A ws = *wincp;
2N/A we = ws + ncolsav - 1;
2N/A /* skip partial characters */
2N/A for (; ws <= we; ++ws)
2N/A if (!ISCBIT(*ws))
2N/A break;
2N/A for (; we >= ws; --we)
2N/A if (!ISCBIT(*we))
2N/A break;
2N/A if (we >= ws) {
2N/A wc = *we;
2N/A n = _curs_scrwidth[TYPE(wc)];
2N/A if ((we + n) <= (*wincp + ncolsav))
2N/A we += n;
2N/A ns = *newcp + (ws - *wincp);
2N/A ne = *newcp + (we - *wincp);
2N/A (void) memcpy((char *)ns, (char *)ws,
2N/A (ne-ns)*sizeof (chtype));
2N/A } else
2N/A ns = ne = *newcp + ncolsav;
2N/A /* fill the rest with background chars */
2N/A wc = win->_bkgd;
2N/A for (ws = *newcp; ws < ns; ++ws)
2N/A *ws = wc;
2N/A for (ws = *newcp+ncolsav-1; ws >= ne; --ws)
2N/A *ws = wc;
2N/A }
2N/A
2N/A (void) memcpy((char *)new->_firstch, (char *)win->_firstch,
2N/A 2 * line_size);
2N/A
2N/A new->_flags |= _WINCHANGED;
2N/A new->_ndescs = 0;
2N/A /*
2N/A * Just like we don't create this window as a subwin if the one
2N/A * sent is, we don't create a padwin. Besides, if the user
2N/A * calls p*refresh a padwin will be created then.
2N/A */
2N/A new->_padwin = new->_parent = (WINDOW *) NULL;
2N/A new->_pary = new->_parx = -1;
2N/A
2N/A new->_index = win->_index;
2N/A new->_nbyte = win->_nbyte;
2N/A new->_insmode = win->_insmode;
2N/A (void) memcpy((char *)new->_waitc, (char *)win->_waitc,
2N/A _csmax * sizeof (char));
2N/A
2N/A return (new);
2N/A}