Home | History | Annotate | Line # | Download | only in libcurses
insdelln.c revision 1.1.2.1
      1 /*	$NetBSD: insdelln.c,v 1.1.2.1 2000/03/05 23:27:11 jdc Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 2000 The NetBSD Foundation, Inc.
      5  * All rights reserved.
      6  *
      7  * This code is derived from software contributed to The NetBSD Foundation
      8  * by Julian Coleman.
      9  *
     10  * Redistribution and use in source and binary forms, with or without
     11  * modification, are permitted provided that the following conditions
     12  * are met:
     13  * 1. Redistributions of source code must retain the above copyright
     14  *    notice, this list of conditions and the following disclaimer.
     15  * 2. Redistributions in binary form must reproduce the above copyright
     16  *    notice, this list of conditions and the following disclaimer in the
     17  *    documentation and/or other materials provided with the distribution.
     18  * 3. All advertising materials mentioning features or use of this software
     19  *    must display the following acknowledgement:
     20  *        This product includes software developed by the NetBSD
     21  *        Foundation, Inc. and its contributors.
     22  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23  *    contributors may be used to endorse or promote products derived
     24  *    from this software without specific prior written permission.
     25  *
     26  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36  * POSSIBILITY OF SUCH DAMAGE.
     37  */
     38 
     39 /*
     40  * Based on deleteln.c and insertln.c -
     41  * Copyright (c) 1981, 1993, 1994
     42  *	The Regents of the University of California.  All rights reserved.
     43  */
     44 
     45 #include <string.h>
     46 
     47 #include "curses.h"
     48 
     49 /*
     50  * winsdelln --
     51  *	Insert or delete lines on the window, leaving (cury, curx) unchanged.
     52  */
     53 int
     54 winsdelln(win, lines)
     55 	WINDOW *win;
     56 	int	lines;
     57 {
     58 	int     y, i;
     59 	__LINE *temp;
     60 
     61 #ifdef DEBUG
     62 	__CTRACE("winsdelln: (%0.2o) cury=%d lines=%d\n", win, win->cury,
     63 	    lines);
     64 #endif
     65 
     66 	if (!lines)
     67 		return(OK);
     68 
     69 	if (lines > 0) {
     70 		/* Insert lines */
     71 		if (lines > win->maxy - win->cury)
     72 			lines = win->maxy - win->cury;
     73 		for (y = win->maxy - lines - 1 ; y >= win->cury; --y) {
     74 			win->lines[y]->flags &= ~__ISPASTEOL;
     75 			win->lines[y + lines]->flags &= ~__ISPASTEOL;
     76 			if (win->orig == NULL) {
     77 				temp = win->lines[y + lines];
     78 				win->lines[y + lines] = win->lines[y];
     79 				win->lines[y] = temp;
     80 			} else {
     81 				(void) memcpy(win->lines[y + lines]->line,
     82 				    win->lines[y]->line,
     83 				    (size_t) win->maxx * __LDATASIZE * lines);
     84 				temp = win->lines[y];
     85 			}
     86 		}
     87 		for (y = win->cury - 1 + lines; y >= win->cury; --y)
     88 			for (i = 0; i < win->maxx; i++) {
     89 				win->lines[y]->line[i].ch = ' ';
     90 				win->lines[y]->line[i].attr = 0;
     91 			}
     92 		for (y = win->maxy - 1; y >= win->cury; --y)
     93 			__touchline(win, y, 0, (int) win->maxx - 1, 0);
     94 	} else {
     95 		/* Delete lines */
     96 		lines = 0 - lines;
     97 		if (lines > win->maxy - win->cury)
     98 			lines = win->maxy - win->cury;
     99 		for (y = win->cury; y < win->maxy - lines; y++) {
    100 			win->lines[y]->flags &= ~__ISPASTEOL;
    101 			win->lines[y + lines]->flags &= ~__ISPASTEOL;
    102 			if (win->orig == NULL) {
    103 				temp = win->lines[y];
    104 				win->lines[y] = win->lines[y + lines];
    105 				win->lines[y + lines] = temp;
    106 			} else {
    107 				(void) memcpy(win->lines[y]->line,
    108 				    win->lines[y + lines]->line,
    109 				    (size_t) win->maxx * __LDATASIZE * lines);
    110 				temp = win->lines[y + lines];
    111 			}
    112 		}
    113 		for (y = win->maxy - lines; y < win->maxy; y++)
    114 			for (i = 0; i < win->maxx; i++) {
    115 				win->lines[y]->line[i].ch = ' ';
    116 				win->lines[y]->line[i].attr = 0;
    117 			}
    118 		for (y = win->cury; y < win->maxy; y++)
    119 			__touchline(win, y, 0, (int) win->maxx - 1, 0);
    120 	}
    121 	if (win->orig == NULL)
    122 		__id_subwins(win);
    123 	return (OK);
    124 }
    125