insdelln.c revision 1.2
1/* $NetBSD: insdelln.c,v 1.2 2000/04/11 13:57:09 blymn 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#include "curses_private.h" 49 50/* 51 * winsdelln -- 52 * Insert or delete lines on the window, leaving (cury, curx) unchanged. 53 */ 54int 55winsdelln(win, lines) 56 WINDOW *win; 57 int lines; 58{ 59 int y, i; 60 __LINE *temp; 61 62#ifdef DEBUG 63 __CTRACE("winsdelln: (%0.2o) cury=%d lines=%d\n", win, win->cury, 64 lines); 65#endif 66 67 if (!lines) 68 return(OK); 69 70 if (lines > 0) { 71 /* Insert lines */ 72 if (lines > win->maxy - win->cury) 73 lines = win->maxy - win->cury; 74 for (y = win->maxy - lines - 1 ; y >= win->cury; --y) { 75 win->lines[y]->flags &= ~__ISPASTEOL; 76 win->lines[y + lines]->flags &= ~__ISPASTEOL; 77 if (win->orig == NULL) { 78 temp = win->lines[y + lines]; 79 win->lines[y + lines] = win->lines[y]; 80 win->lines[y] = temp; 81 } else { 82 (void) memcpy(win->lines[y + lines]->line, 83 win->lines[y]->line, 84 (size_t) win->maxx * __LDATASIZE * lines); 85 temp = win->lines[y]; 86 } 87 } 88 for (y = win->cury - 1 + lines; y >= win->cury; --y) 89 for (i = 0; i < win->maxx; i++) { 90 win->lines[y]->line[i].ch = ' '; 91 win->lines[y]->line[i].attr = 0; 92 } 93 for (y = win->maxy - 1; y >= win->cury; --y) 94 __touchline(win, y, 0, (int) win->maxx - 1, 0); 95 } else { 96 /* Delete lines */ 97 lines = 0 - lines; 98 if (lines > win->maxy - win->cury) 99 lines = win->maxy - win->cury; 100 for (y = win->cury; y < win->maxy - lines; y++) { 101 win->lines[y]->flags &= ~__ISPASTEOL; 102 win->lines[y + lines]->flags &= ~__ISPASTEOL; 103 if (win->orig == NULL) { 104 temp = win->lines[y]; 105 win->lines[y] = win->lines[y + lines]; 106 win->lines[y + lines] = temp; 107 } else { 108 (void) memcpy(win->lines[y]->line, 109 win->lines[y + lines]->line, 110 (size_t) win->maxx * __LDATASIZE * lines); 111 temp = win->lines[y + lines]; 112 } 113 } 114 for (y = win->maxy - lines; y < win->maxy; y++) 115 for (i = 0; i < win->maxx; i++) { 116 win->lines[y]->line[i].ch = ' '; 117 win->lines[y]->line[i].attr = 0; 118 } 119 for (y = win->cury; y < win->maxy; y++) 120 __touchline(win, y, 0, (int) win->maxx - 1, 0); 121 } 122 if (win->orig != NULL) 123 __id_subwins(win); 124 return (OK); 125} 126