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