]>
git.proxmox.com Git - mirror_ovs.git/blob - extras/ezio/ezio.c
1 /* Copyright (c) 2008, 2009 Nicira Networks, Inc.
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, either version 3 of the License, or
6 * (at your option) any later version.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 * In addition, as a special exception, Nicira Networks gives permission
17 * to link the code of its release of vswitchd with the OpenSSL project's
18 * "OpenSSL" library (or with modified versions of it that use the same
19 * license as the "OpenSSL" library), and distribute the linked
20 * executables. You must obey the GNU General Public License in all
21 * respects for all of the code used other than "OpenSSL". If you modify
22 * this file, you may extend this exception to your version of the file,
23 * but you are not obligated to do so. If you do not wish to do so,
24 * delete this exception statement from your version.
35 static void remove_elements(uint8_t *p
, size_t n_elems
, size_t elem_size
,
37 static void insert_elements(uint8_t *p
, size_t n_elems
, size_t elem_size
,
38 int pos
, int n_insert
);
39 static int range(int value
, int min
, int max
);
42 ezio_init(struct ezio
*e
)
44 memset(e
->icons
, 0, sizeof e
->icons
);
47 e
->show_cursor
= true;
48 e
->blink_cursor
= false;
52 ezio_set_icon(struct ezio
*e
, int idx
,
53 int row0
, int row1
, int row2
, int row3
,
54 int row4
, int row5
, int row6
, int row7
)
56 e
->icons
[idx
][0] = row0
;
57 e
->icons
[idx
][1] = row1
;
58 e
->icons
[idx
][2] = row2
;
59 e
->icons
[idx
][3] = row3
;
60 e
->icons
[idx
][4] = row4
;
61 e
->icons
[idx
][5] = row5
;
62 e
->icons
[idx
][6] = row6
;
63 e
->icons
[idx
][7] = row7
;
67 ezio_set_default_icon(struct ezio
*e
, int idx
)
71 assert(idx
>= 0 && idx
< 8);
83 } else if (idx
== 7) {
107 ezio_clear(struct ezio
*e
)
109 memset(e
->chars
, ' ', sizeof e
->chars
);
114 ezio_put_char(struct ezio
*e
, int x
, int y
, uint8_t c
)
116 assert(x
>= 0 && x
<= 39);
117 assert(y
>= 0 && y
<= 1);
118 e
->chars
[y
][x
] = c
!= 0xfe ? c
: 0xff;
122 ezio_line_feed(struct ezio
*e
)
126 ezio_scroll_up(e
, 1);
131 ezio_newline(struct ezio
*e
)
138 ezio_delete_char(struct ezio
*e
, int x
, int y
, int n
)
140 remove_elements(&e
->chars
[y
][0], 40, 1, x
, n
);
144 ezio_delete_line(struct ezio
*e
, int y
, int n
)
146 remove_elements(e
->chars
[0], 2, 40, y
, n
);
150 ezio_insert_char(struct ezio
*e
, int x
, int y
, int n
)
152 insert_elements(&e
->chars
[y
][0], 40, 1, x
, n
);
156 ezio_insert_line(struct ezio
*e
, int y
, int n
)
158 insert_elements(&e
->chars
[0][0], 2, 40, y
, n
);
162 ezio_scroll_left(struct ezio
*e
, int n
)
165 for (y
= 0; y
< 2; y
++) {
166 ezio_delete_char(e
, 0, y
, n
);
171 ezio_scroll_right(struct ezio
*e
, int n
)
175 for (y
= 0; y
< 2; y
++) {
176 ezio_insert_char(e
, 0, y
, n
);
181 ezio_scroll_up(struct ezio
*e
, int n
)
183 ezio_delete_line(e
, 0, n
);
187 ezio_scroll_down(struct ezio
*e
, int n
)
189 ezio_insert_line(e
, 0, n
);
193 ezio_chars_differ(const struct ezio
*a
, const struct ezio
*b
, int x0
, int x1
,
198 x0
= range(x0
, 0, 39);
199 x1
= range(x1
, 1, 40);
200 for (y
= 0; y
< 2; y
++) {
201 for (x
= x0
; x
< x1
; x
++) {
202 if (a
->chars
[y
][x
] != b
->chars
[y
][x
]) {
213 remove_elements(uint8_t *p
, size_t n_elems
, size_t elem_size
,
216 if (pos
>= 0 && pos
< n_elems
) {
217 n_del
= MIN(n_del
, n_elems
- pos
);
218 memmove(p
+ elem_size
* pos
,
219 p
+ elem_size
* (pos
+ n_del
),
220 elem_size
* (n_elems
- pos
- n_del
));
221 memset(p
+ elem_size
* (n_elems
- n_del
), ' ', n_del
* elem_size
);
226 insert_elements(uint8_t *p
, size_t n_elems
, size_t elem_size
,
227 int pos
, int n_insert
)
229 if (pos
>= 0 && pos
< n_elems
) {
230 n_insert
= MIN(n_insert
, n_elems
- pos
);
231 memmove(p
+ elem_size
* (pos
+ n_insert
),
233 elem_size
* (n_elems
- pos
- n_insert
));
234 memset(p
+ elem_size
* pos
, ' ', n_insert
* elem_size
);
239 range(int value
, int min
, int max
)
241 return value
< min
? min
: value
> max
? max
: value
;