xref: /aosp_15_r20/external/coreboot/payloads/libpayload/curses/PDCurses/pdcurses/deleteln.c (revision b9411a12aaaa7e1e6a6fb7c5e057f44ee179a49c)
1 /* Public Domain Curses */
2 
3 #include <curspriv.h>
4 
5 RCSID("$Id: deleteln.c,v 1.35 2008/07/13 16:08:18 wmcbrine Exp $")
6 
7 /*man-start**************************************************************
8 
9   Name:                                                         deleteln
10 
11   Synopsis:
12         int deleteln(void);
13         int wdeleteln(WINDOW *win);
14         int insdelln(int n);
15         int winsdelln(WINDOW *win, int n);
16         int insertln(void);
17         int winsertln(WINDOW *win);
18 
19         int mvdeleteln(int y, int x);
20         int mvwdeleteln(WINDOW *win, int y, int x);
21         int mvinsertln(int y, int x);
22         int mvwinsertln(WINDOW *win, int y, int x);
23 
24   Description:
25         With the deleteln() and wdeleteln() functions, the line under
26         the cursor in the window is deleted.  All lines below the
27         current line are moved up one line.  The bottom line of the
28         window is cleared.  The cursor position does not change.
29 
30         With the insertln() and winsertn() functions, a blank line is
31         inserted above the current line and the bottom line is lost.
32 
33         mvdeleteln(), mvwdeleteln(), mvinsertln() and mvwinsertln()
34         allow moving the cursor and inserting/deleting in one call.
35 
36   Return Value:
37         All functions return OK on success and ERR on error.
38 
39   Portability                                X/Open    BSD    SYS V
40         deleteln                                Y       Y       Y
41         wdeleteln                               Y       Y       Y
42         mvdeleteln                              -       -       -
43         mvwdeleteln                             -       -       -
44         insdelln                                Y       -      4.0
45         winsdelln                               Y       -      4.0
46         insertln                                Y       Y       Y
47         winsertln                               Y       Y       Y
48         mvinsertln                              -       -       -
49         mvwinsertln                             -       -       -
50 
51 **man-end****************************************************************/
52 
wdeleteln(WINDOW * win)53 int wdeleteln(WINDOW *win)
54 {
55     chtype blank, *temp, *ptr;
56     int y;
57 
58     PDC_LOG(("wdeleteln() - called\n"));
59 
60     if (!win)
61         return ERR;
62 
63     /* wrs (4/10/93) account for window background */
64 
65     blank = win->_bkgd;
66 
67     temp = win->_y[win->_cury];
68 
69     for (y = win->_cury; y < win->_bmarg; y++)
70     {
71         win->_y[y] = win->_y[y + 1];
72         win->_firstch[y] = 0;
73         win->_lastch[y] = win->_maxx - 1;
74     }
75 
76     for (ptr = temp; (ptr - temp < win->_maxx); ptr++)
77         *ptr = blank;           /* make a blank line */
78 
79     if (win->_cury <= win->_bmarg)
80     {
81         win->_firstch[win->_bmarg] = 0;
82         win->_lastch[win->_bmarg] = win->_maxx - 1;
83         win->_y[win->_bmarg] = temp;
84     }
85 
86     return OK;
87 }
88 
deleteln(void)89 int deleteln(void)
90 {
91     PDC_LOG(("deleteln() - called\n"));
92 
93     return wdeleteln(stdscr);
94 }
95 
mvdeleteln(int y,int x)96 int mvdeleteln(int y, int x)
97 {
98     PDC_LOG(("mvdeleteln() - called\n"));
99 
100     if (move(y, x) == ERR)
101         return ERR;
102 
103     return wdeleteln(stdscr);
104 }
105 
mvwdeleteln(WINDOW * win,int y,int x)106 int mvwdeleteln(WINDOW *win, int y, int x)
107 {
108     PDC_LOG(("mvwdeleteln() - called\n"));
109 
110     if (wmove(win, y, x) == ERR)
111         return ERR;
112 
113     return wdeleteln(win);
114 }
115 
winsdelln(WINDOW * win,int n)116 int winsdelln(WINDOW *win, int n)
117 {
118     int i;
119 
120     PDC_LOG(("winsdelln() - called\n"));
121 
122     if (!win)
123         return ERR;
124 
125     if (n > 0)
126     {
127         for (i = 0; i < n; i++)
128             if (winsertln(win) == ERR)
129                 return ERR;
130     }
131     else if (n < 0)
132     {
133         n = -n;
134         for (i = 0; i < n; i++)
135             if (wdeleteln(win) == ERR)
136                 return ERR;
137     }
138 
139     return OK;
140 }
141 
insdelln(int n)142 int insdelln(int n)
143 {
144     PDC_LOG(("insdelln() - called\n"));
145 
146     return winsdelln(stdscr, n);
147 }
148 
winsertln(WINDOW * win)149 int winsertln(WINDOW *win)
150 {
151     chtype blank, *temp, *end;
152     int y;
153 
154     PDC_LOG(("winsertln() - called\n"));
155 
156     if (!win)
157         return ERR;
158 
159     /* wrs (4/10/93) account for window background */
160 
161     blank = win->_bkgd;
162 
163     temp = win->_y[win->_maxy - 1];
164 
165     for (y = win->_maxy - 1; y > win->_cury; y--)
166     {
167         win->_y[y] = win->_y[y - 1];
168         win->_firstch[y] = 0;
169         win->_lastch[y] = win->_maxx - 1;
170     }
171 
172     win->_y[win->_cury] = temp;
173 
174     for (end = &temp[win->_maxx - 1]; temp <= end; temp++)
175         *temp = blank;
176 
177     win->_firstch[win->_cury] = 0;
178     win->_lastch[win->_cury] = win->_maxx - 1;
179 
180     return OK;
181 }
182 
insertln(void)183 int insertln(void)
184 {
185     PDC_LOG(("insertln() - called\n"));
186 
187     return winsertln(stdscr);
188 }
189 
mvinsertln(int y,int x)190 int mvinsertln(int y, int x)
191 {
192     PDC_LOG(("mvinsertln() - called\n"));
193 
194     if (move(y, x) == ERR)
195         return ERR;
196 
197     return winsertln(stdscr);
198 }
199 
mvwinsertln(WINDOW * win,int y,int x)200 int mvwinsertln(WINDOW *win, int y, int x)
201 {
202     PDC_LOG(("mvwinsertln() - called\n"));
203 
204     if (wmove(win, y, x) == ERR)
205         return ERR;
206 
207     return winsertln(win);
208 }
209