1 /* $NetBSD: insdelln.c,v 1.7 2000/05/20 15:12:15 mycroft 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 #include <sys/cdefs.h> 40 #ifndef lint 41 __RCSID("$NetBSD: insdelln.c,v 1.7 2000/05/20 15:12:15 mycroft Exp $"); 42 #endif /* not lint */ 43 44 /* 45 * Based on deleteln.c and insertln.c - 46 * Copyright (c) 1981, 1993, 1994 47 * The Regents of the University of California. All rights reserved. 48 */ 49 50 #include <string.h> 51 52 #include "curses.h" 53 #include "curses_private.h" 54 55 #ifndef _CURSES_USE_MACROS 56 57 /* 58 * insdelln -- 59 * Insert or delete lines on stdscr, leaving (cury, curx) unchanged. 60 */ 61 int 62 insdelln(int lines) 63 { 64 return winsdelln(stdscr, lines); 65 } 66 67 #endif 68 69 /* 70 * winsdelln -- 71 * Insert or delete lines on the window, leaving (cury, curx) unchanged. 72 */ 73 int 74 winsdelln(WINDOW *win, int lines) 75 { 76 int y, i; 77 __LINE *temp; 78 79 #ifdef DEBUG 80 __CTRACE("winsdelln: (%0.2o) cury=%d lines=%d\n", win, win->cury, 81 lines); 82 #endif 83 84 if (!lines) 85 return(OK); 86 87 if (lines > 0) { 88 /* Insert lines */ 89 if (lines > win->maxy - win->cury) 90 lines = win->maxy - win->cury; 91 for (y = win->maxy - lines - 1 ; y >= win->cury; --y) { 92 win->lines[y]->flags &= ~__ISPASTEOL; 93 win->lines[y + lines]->flags &= ~__ISPASTEOL; 94 if (win->orig == NULL) { 95 temp = win->lines[y + lines]; 96 win->lines[y + lines] = win->lines[y]; 97 win->lines[y] = temp; 98 } else { 99 (void) memcpy(win->lines[y + lines]->line, 100 win->lines[y]->line, 101 (size_t) win->maxx * __LDATASIZE * lines); 102 temp = win->lines[y]; 103 } 104 } 105 for (y = win->cury - 1 + lines; y >= win->cury; --y) 106 for (i = 0; i < win->maxx; i++) { 107 win->lines[y]->line[i].ch = ' '; 108 win->lines[y]->line[i].bch = win->bch; 109 win->lines[y]->line[i].attr = 0; 110 win->lines[y]->line[i].battr = win->battr; 111 } 112 for (y = win->maxy - 1; y >= win->cury; --y) 113 __touchline(win, y, 0, (int) win->maxx - 1); 114 } else { 115 /* Delete lines */ 116 lines = 0 - lines; 117 if (lines > win->maxy - win->cury) 118 lines = win->maxy - win->cury; 119 for (y = win->cury; y < win->maxy - lines; y++) { 120 win->lines[y]->flags &= ~__ISPASTEOL; 121 win->lines[y + lines]->flags &= ~__ISPASTEOL; 122 if (win->orig == NULL) { 123 temp = win->lines[y]; 124 win->lines[y] = win->lines[y + lines]; 125 win->lines[y + lines] = temp; 126 } else { 127 (void) memcpy(win->lines[y]->line, 128 win->lines[y + lines]->line, 129 (size_t) win->maxx * __LDATASIZE * lines); 130 temp = win->lines[y + lines]; 131 } 132 } 133 for (y = win->maxy - lines; y < win->maxy; y++) 134 for (i = 0; i < win->maxx; i++) { 135 win->lines[y]->line[i].ch = ' '; 136 win->lines[y]->line[i].bch = win->bch; 137 win->lines[y]->line[i].attr = 0; 138 win->lines[y]->line[i].battr = win->battr; 139 } 140 for (y = win->cury; y < win->maxy; y++) 141 __touchline(win, y, 0, (int) win->maxx - 1); 142 } 143 if (win->orig != NULL) 144 __id_subwins(win->orig); 145 return (OK); 146 } 147