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