Browse Source

lightweight xcurses implementation for etherboot (Michael made me do it...)

tags/v0.9.3
Dan Lynch 18 years ago
parent
commit
dccc6aed3a
2 changed files with 1169 additions and 0 deletions
  1. 298
    0
      src/core/curses.c
  2. 871
    0
      src/include/curses.h

+ 298
- 0
src/core/curses.c View File

@@ -0,0 +1,298 @@
1
+#include <curses.h>
2
+#include <malloc.h>
3
+#include <stddef.h>
4
+
5
+/** @file
6
+ *
7
+ * MuCurses: lightweight xcurses implementation for PXE ROMs
8
+ *
9
+ */
10
+
11
+WINDOW _stdscr = {
12
+	.attrs = A_DEFAULT,
13
+	.ori_y = 0,
14
+	.ori_x = 0,
15
+	.curs_y = 0,
16
+	.curs_x = 0,
17
+};
18
+
19
+/**
20
+ * get terminal baud rate
21
+ *
22
+ * @ret bps	return baud rate in bits per second
23
+ */
24
+int baudrate ( void ) {
25
+	return 0;
26
+}
27
+
28
+/**
29
+ * Audible (or visual) signal
30
+ *
31
+ * @ret rc	return status code
32
+ */
33
+int beep ( void ) {
34
+	/* ok, so I can't waste memory buffering the screen (or in
35
+	   this case, backing up the background colours of the screen
36
+	   elements), but maybe I can buffer the border and flash that
37
+	   - or maybe even just the top and bottom? Assuming I can't
38
+	   make the system speaker beep, of course... */
39
+	return OK;
40
+}
41
+
42
+/**
43
+ * Draw borders from single-byte characters and renditions around a
44
+ * window
45
+ *
46
+ * @v *win	window to be bordered
47
+ * @v verch	vertical chtype
48
+ * @v horch	horizontal chtype
49
+ * @ret rc	return status code
50
+ */
51
+int box ( WINDOW *win, chtype verch, chtype horch ) {
52
+	return OK;
53
+ err:
54
+	return ERR;
55
+}
56
+
57
+/**
58
+ * Indicates whether the attached terminal is capable of having
59
+ * colours redefined
60
+ *
61
+ * @ret bool	returns boolean dependent on colour changing caps of terminal
62
+ */
63
+bool can_change_colour ( void ) {
64
+	return (bool)TRUE;
65
+ err:
66
+	return (bool)FALSE;
67
+}
68
+
69
+/**
70
+ * Identifies the intensity components of colour number "colour" and
71
+ * stores the RGB intensity values in the respective addresses pointed
72
+ * to by "red", "green" and "blue" respectively
73
+ */
74
+int colour_content ( short colour, short *red, short *green, short *blue ) {
75
+	return OK;
76
+ err:
77
+	return ERR;
78
+}
79
+
80
+/**
81
+ * Window colour attribute control function
82
+ *
83
+ * @v colour_pair_number	colour pair integer
84
+ * @v *opts			pointer to options
85
+ * @ret rc			return status code
86
+ */
87
+int colour_set ( short colour_pair_number, void *opts ) {
88
+	return OK;
89
+}
90
+
91
+/**
92
+ * Delete a window
93
+ *
94
+ * @v *win	pointer to window being deleted
95
+ * @ret rc	return status code
96
+ */
97
+int delwin ( WINDOW *win ) {
98
+	if ( win == NULL )
99
+		goto err;
100
+	/* must free descendants first, but I haven't implemented descendants yet
101
+	   ... */
102
+	free(win);
103
+	return OK;
104
+ err:
105
+	return ERR;
106
+}
107
+
108
+/**
109
+ * Initialise console environment
110
+ *
111
+ * @ret *win	return pointer to stdscr
112
+ */
113
+WINDOW *initscr ( void ) {
114
+	/* determine console size */
115
+	/* initialise screen */
116
+	/* set previously unknown window attributes */
117
+	/* refresh screen */
118
+	return stdscr;
119
+}
120
+
121
+/**
122
+ * Create new WINDOW
123
+ *
124
+ * @v nlines	number of lines
125
+ * @v ncols	number of columns
126
+ * @v begin_y	column origin
127
+ * @v begin_x	line origin
128
+ * @ret *win	return pointer to new window
129
+ */
130
+WINDOW *newwin ( int nlines, int ncols, int begin_y, int begin_x ) {
131
+	WINDOW *win = calloc( 1, sizeof(WINDOW) );
132
+	win->ori_y = begin_y;
133
+	win->ori_x = begin_x;
134
+	win->height = nlines;
135
+	win->width = ncols;
136
+	win->scr = stdscr->scr;
137
+	return win;
138
+}
139
+
140
+/**
141
+ * Add a single-byte character and rendition to a window and advance
142
+ * the cursor
143
+ *
144
+ * @v *win	window to be rendered in
145
+ * @v ch	character to be added at cursor
146
+ * @ret rc	return status code
147
+ */
148
+int waddch ( WINDOW *win, const chtype ch ) {
149
+	_putc( win->scr, ch & A_CHARTEXT );
150
+	_advcurs_wrap( win );
151
+	return OK;
152
+ err:
153
+	return ERR;
154
+}
155
+
156
+/**
157
+ * Add string of single-byte characters and renditions to a window
158
+ *
159
+ * @v *win	window to be rendered in
160
+ * @v *chstr	pointer to first chtype in "string"
161
+ * @v n		max number of chars from chstr to render
162
+ * @ret rc	return status code
163
+ */
164
+int waddchnstr ( WINDOW *win, const chtype *chstr, int n ) {
165
+	unsigned int ch, pos, count = 0;
166
+	chtype *chptr = chstr;
167
+
168
+	pos = _store_curs_pos ( win );
169
+	while ( ( ( ( ch = ( *chptr & A_CHARTEXT ) ) ) != '\0' )
170
+		&& ( count++ < (unsigned)n ) ) {
171
+		_putc( win, ch );
172
+		_advcurs_nowrap( win );
173
+		/* set rendition code here */
174
+	}
175
+	_restore_curs_pos( win, pos ) && return OK;
176
+ err:
177
+	_restore_curs_pos( win, pos ) && return ERR;
178
+}
179
+
180
+/**
181
+ * Add string of single-byte characters to a window
182
+ *
183
+ * @v *win	window to be rendered in
184
+ * @v *str	standard c-style string
185
+ * @v n		max number of chars from string to render
186
+ * @ret rc	return status code
187
+ */
188
+int waddnstr ( WINDOW *win, const char *str, int n ) {
189
+	unsigned int ch, count = 0;
190
+	char *strptr = str;
191
+
192
+	while ( ( ( ch = *strptr ) != '\0' )
193
+		&& ( count++ < (unsigned)n ) ) {
194
+		_putc( win, ch );
195
+		_advcurs_wrap( win );
196
+	}
197
+
198
+	return OK;
199
+ err:
200
+	return ERR;
201
+}
202
+
203
+/**
204
+ * Turn off attributes
205
+ *
206
+ * @v win	subject window
207
+ * @v attrs	attributes to enable
208
+ * @ret rc	return status code
209
+ */
210
+int wattroff ( WINDOW *win, int attrs ) {
211
+	win->attrs &= ~attrs;
212
+	return 0;
213
+}
214
+
215
+/**
216
+ * Turn on attributes
217
+ *
218
+ * @v win	subject window
219
+ * @v attrs	attributes to enable
220
+ * @ret rc	return status code
221
+ */
222
+int wattron ( WINDOW *win, int attrs ) {
223
+	win->attrs |= attrs;
224
+	return OK;
225
+}
226
+
227
+/**
228
+ * Set attributes
229
+ *
230
+ * @v win	subject window
231
+ * @v attrs	attributes to enable
232
+ * @ret rc	return status code
233
+ */
234
+int wattrset ( WINDOW *win, int attrs ) {
235
+	win->attrs = attrs;
236
+	return OK;
237
+}
238
+
239
+/**
240
+ * Set background rendition attributes for a window and apply to
241
+ * contents
242
+ *
243
+ * @v *win	window to be operated on
244
+ * @v ch	chtype containing rendition attributes
245
+ * @ret rc	return status code
246
+ */
247
+int wbkgd ( WINDOW *win, chtype ch ) {
248
+	return OK;
249
+ err:
250
+	return ERR;
251
+}
252
+
253
+/**
254
+ * Set background rendition attributes for a window
255
+ *
256
+ * @v *win	window to be operated on
257
+ * @v ch	chtype containing rendition attributes
258
+ */
259
+void wbkgdset ( WINDOW *win, chtype ch ) {
260
+}
261
+
262
+/**
263
+ * Draw borders from single-byte characters and renditions around a
264
+ * window
265
+ *
266
+ * @v *win	window to be bordered
267
+ * @v ls	left side
268
+ * @v rs	right side
269
+ * @v ts	top
270
+ * @v bs	bottom
271
+ * @v tl	top left corner
272
+ * @v tr	top right corner
273
+ * @v bl	bottom left corner
274
+ * @v br	bottom right corner
275
+ * @ret rc	return status code
276
+ */
277
+int wborder ( WINDOW *win, chtype ls, chtype rs, 
278
+			   chtype ts, chtype bs, chtype tl,
279
+			   chtype tr, chtype bl, chtype br ) {
280
+	return OK;
281
+ err:
282
+	return ERR;
283
+}
284
+
285
+/**
286
+ * Move a window's cursor to the specified position
287
+ *
288
+ * @v *win	window to be operated on
289
+ * @v y		Y position
290
+ * @v x		X position
291
+ * @ret rc	return status code
292
+ */
293
+int wmove ( WINDOW *win, int y, int x ) {
294
+	_movetoyx( win->scr, y, x );
295
+	return OK;
296
+ err:
297
+	return ERR;
298
+}

+ 871
- 0
src/include/curses.h View File

@@ -0,0 +1,871 @@
1
+#ifndef CURSES_H
2
+#define CURSES_H
3
+
4
+#include <stdint.h>
5
+#include <stdarg.h>
6
+
7
+/** @file
8
+ *
9
+ * MuCurses header file
10
+ *
11
+ */
12
+
13
+#undef  ERR
14
+#define ERR	(1)
15
+
16
+#undef  FALSE
17
+#define FALSE	(0)
18
+
19
+#undef  OK
20
+#define OK	(0)
21
+
22
+#undef  TRUE
23
+#define TRUE	(1)
24
+
25
+typedef uint32_t bool;
26
+typedef uint32_t chtype;
27
+typedef chtype attr_t;
28
+
29
+/** Curses SCREEN object */
30
+typedef struct _curses_screen {
31
+} SCREEN;
32
+
33
+/** Curses Window struct */
34
+typedef struct _curses_window {
35
+	/** screen with which window associates */
36
+	SCREEN *scr;
37
+	/** window attributes */
38
+	attr_t attrs;
39
+	/** window origin coordinates */
40
+	unsigned int ori_x, ori_y;
41
+	/** window cursor position */
42
+	unsigned int curs_x, curs_y;
43
+	/** window dimensions */
44
+	unsigned int width, height;
45
+} WINDOW;
46
+
47
+extern WINDOW _stdscr;
48
+#define stdscr ( &_stdscr )
49
+
50
+#define MUCURSES_ATTR_SHIFT	16
51
+#define MUCURSES_BITS( mask, shift ) (( mask ) << (( shift ) + MUCURSES_ATTR_SHIFT ))
52
+
53
+#define A_DEFAULT	( 1UL - 1UL )
54
+#define A_ALTCHARSET	MUCURSES_BITS( 1UL, 0 )
55
+#define A_BLINK		MUCURSES_BITS( 1UL, 1 )
56
+#define A_BOLD		MUCURSES_BITS( 1UL, 2 )
57
+#define A_DIM		MUCURSES_BITS( 1UL, 3 )
58
+#define A_INVIS		MUCURSES_BITS( 1UL, 4 )
59
+#define A_PROTECT	MUCURSES_BITS( 1UL, 5 )
60
+#define A_REVERSE	MUCURSES_BITS( 1UL, 6 )
61
+#define A_STANDOUT	MUCURSES_BITS( 1UL, 7 )
62
+#define A_UNDERLINE	MUCURSES_BITS( 1UL, 8 )
63
+
64
+#define WA_ALTCHARSET	A_ALTCHARSET
65
+#define WA_BLINK	A_BLINK
66
+#define WA_BOLD		A_BOLD
67
+#define WA_DIM		A_DIM
68
+#define WA_INVIS	A_INVIS
69
+#define WA_PROTECT	A_PROTECT
70
+#define WA_REVERSE	A_REVERSE
71
+#define WA_STANDOUT	A_STANDOUT
72
+#define WA_UNDERLINE	A_UNDERLINE
73
+#define WA_HORIZONTAL	MUCURSES_BITS( 1UL, 9 )
74
+#define WA_VERTICAL	MUCURSES_BITS( 1UL, 10 )
75
+#define WA_LEFT		MUCURSES_BITS( 1UL, 11 )
76
+#define WA_RIGHT	MUCURSES_BITS( 1UL, 12 )
77
+#define WA_LOW		MUCURSES_BITS( 1UL, 13 )
78
+#define WA_TOP		MUCURSES_BITS( 1UL, 14 )
79
+
80
+#define A_ATTRIBUTES	MUCURSES_BITS( ~( 1UL - 1UL ), 0 )
81
+#define A_CHARTEXT	( MUCURSES_BITS( 1UL, 0 ) - 1UL )
82
+#define A_COLOR		MUCURSES_BITS( ( 1UL << 8 ) - 1UL, 0 )
83
+
84
+#define ACS_ULCORNER	'+'
85
+#define ACS_LLCORNER	'+'
86
+#define ACS_URCORNER	'+'
87
+#define ACS_LRCORNER	'+'
88
+#define ACS_RTEE	'+'
89
+#define ACS_LTEE	'+'
90
+#define ACS_BTEE	'+'
91
+#define ACS_TTEE	'+'
92
+#define ACS_HLINE	'-'
93
+#define ACS_VLINE	'|'
94
+#define ACS_PLUS	'+'
95
+#define ACS_S1		'-'
96
+#define ACS_S9		'_'
97
+#define ACS_DIAMOND	'+'
98
+#define ACS_CKBOARD	':'
99
+#define ACS_DEGREE	'\''
100
+#define ACS_PLMINUS	'#'
101
+#define ACS_BULLET	'o'
102
+#define ACS_LARROW	'<'
103
+#define ACS_RARROW	'>'
104
+#define ACS_DARROW	'v'
105
+#define ACS_UARROW	'^'
106
+#define ACS_BOARD	'#'
107
+#define ACS_LANTERN	'#'
108
+#define ACS_BLOCK	'#'
109
+
110
+#define COLOUR_BLACK	0
111
+#define COLOUR_BLUE	1
112
+#define COLOUR_GREEN	2
113
+#define COLOUR_CYAN	3
114
+#define COLOUR_RED	4
115
+#define COLOUR_MAGENTA	5
116
+#define COLOUR_YELLOW	6
117
+#define COLOUR_WHITE	7
118
+
119
+#define COLOR_BLACK	COLOUR_BLACK
120
+#define COLOR_BLUE	COLOUR_BLUE
121
+#define COLOR_GREEN	COLOUR_GREEN
122
+#define COLOR_CYAN	COLOUR_CYAN
123
+#define COLOR_RED	COLOUR_RED
124
+#define COLOR_MAGENTA	COLOUR_MAGENTA
125
+#define COLOR_YELLOW	COLOUR_YELLOW
126
+#define COLOR_WHITE	COLOUR_WHITE
127
+
128
+/*
129
+ * KEY code constants
130
+ */
131
+#define KEY_BREAK	0401		/**< Break key */
132
+#define KEY_DOWN	0402		/**< down-arrow key */
133
+#define KEY_UP		0403		/**< up-arrow key */
134
+#define KEY_LEFT	0404		/**< left-arrow key */
135
+#define KEY_RIGHT	0405		/**< right-arrow key */
136
+#define KEY_HOME	0406		/**< home key */
137
+#define KEY_BACKSPACE	0407		/**< backspace key */
138
+#define KEY_F0		0410		/**< Function keys.  Space for 64 */
139
+#define KEY_F(n)	(KEY_F0+(n))	/**< Value of function key n */
140
+#define KEY_DL		0510		/**< delete-line key */
141
+#define KEY_IL		0511		/**< insert-line key */
142
+#define KEY_DC		0512		/**< delete-character key */
143
+#define KEY_IC		0513		/**< insert-character key */
144
+#define KEY_EIC		0514		/**< sent by rmir or smir in insert mode */
145
+#define KEY_CLEAR	0515		/**< clear-screen or erase key */
146
+#define KEY_EOS		0516		/**< clear-to-end-of-screen key */
147
+#define KEY_EOL		0517		/**< clear-to-end-of-line key */
148
+#define KEY_SF		0520		/**< scroll-forward key */
149
+#define KEY_SR		0521		/**< scroll-backward key */
150
+#define KEY_NPAGE	0522		/**< next-page key */
151
+#define KEY_PPAGE	0523		/**< previous-page key */
152
+#define KEY_STAB	0524		/**< set-tab key */
153
+#define KEY_CTAB	0525		/**< clear-tab key */
154
+#define KEY_CATAB	0526		/**< clear-all-tabs key */
155
+#define KEY_ENTER	0527		/**< enter/send key */
156
+#define KEY_PRINT	0532		/**< print key */
157
+#define KEY_LL		0533		/**< lower-left key (home down) */
158
+#define KEY_A1		0534		/**< upper left of keypad */
159
+#define KEY_A3		0535		/**< upper right of keypad */
160
+#define KEY_B2		0536		/**< center of keypad */
161
+#define KEY_C1		0537		/**< lower left of keypad */
162
+#define KEY_C3		0540		/**< lower right of keypad */
163
+#define KEY_BTAB	0541		/**< back-tab key */
164
+#define KEY_BEG		0542		/**< begin key */
165
+#define KEY_CANCEL	0543		/**< cancel key */
166
+#define KEY_CLOSE	0544		/**< close key */
167
+#define KEY_COMMAND	0545		/**< command key */
168
+#define KEY_COPY	0546		/**< copy key */
169
+#define KEY_CREATE	0547		/**< create key */
170
+#define KEY_END		0550		/**< end key */
171
+#define KEY_EXIT	0551		/**< exit key */
172
+#define KEY_FIND	0552		/**< find key */
173
+#define KEY_HELP	0553		/**< help key */
174
+#define KEY_MARK	0554		/**< mark key */
175
+#define KEY_MESSAGE	0555		/**< message key */
176
+#define KEY_MOVE	0556		/**< move key */
177
+#define KEY_NEXT	0557		/**< next key */
178
+#define KEY_OPEN	0560		/**< open key */
179
+#define KEY_OPTIONS	0561		/**< options key */
180
+#define KEY_PREVIOUS	0562		/**< previous key */
181
+#define KEY_REDO	0563		/**< redo key */
182
+#define KEY_REFERENCE	0564		/**< reference key */
183
+#define KEY_REFRESH	0565		/**< refresh key */
184
+#define KEY_REPLACE	0566		/**< replace key */
185
+#define KEY_RESTART	0567		/**< restart key */
186
+#define KEY_RESUME	0570		/**< resume key */
187
+#define KEY_SAVE	0571		/**< save key */
188
+#define KEY_SBEG	0572		/**< shifted begin key */
189
+#define KEY_SCANCEL	0573		/**< shifted cancel key */
190
+#define KEY_SCOMMAND	0574		/**< shifted command key */
191
+#define KEY_SCOPY	0575		/**< shifted copy key */
192
+#define KEY_SCREATE	0576		/**< shifted create key */
193
+#define KEY_SDC		0577		/**< shifted delete-character key */
194
+#define KEY_SDL		0600		/**< shifted delete-line key */
195
+#define KEY_SELECT	0601		/**< select key */
196
+#define KEY_SEND	0602		/**< shifted end key */
197
+#define KEY_SEOL	0603		/**< shifted clear-to-end-of-line key */
198
+#define KEY_SEXIT	0604		/**< shifted exit key */
199
+#define KEY_SFIND	0605		/**< shifted find key */
200
+#define KEY_SHELP	0606		/**< shifted help key */
201
+#define KEY_SHOME	0607		/**< shifted home key */
202
+#define KEY_SIC		0610		/**< shifted insert-character key */
203
+#define KEY_SLEFT	0611		/**< shifted left-arrow key */
204
+#define KEY_SMESSAGE	0612		/**< shifted message key */
205
+#define KEY_SMOVE	0613		/**< shifted move key */
206
+#define KEY_SNEXT	0614		/**< shifted next key */
207
+#define KEY_SOPTIONS	0615		/**< shifted options key */
208
+#define KEY_SPREVIOUS	0616		/**< shifted previous key */
209
+#define KEY_SPRINT	0617		/**< shifted print key */
210
+#define KEY_SREDO	0620		/**< shifted redo key */
211
+#define KEY_SREPLACE	0621		/**< shifted replace key */
212
+#define KEY_SRIGHT	0622		/**< shifted right-arrow key */
213
+#define KEY_SRSUME	0623		/**< shifted resume key */
214
+#define KEY_SSAVE	0624		/**< shifted save key */
215
+#define KEY_SSUSPEND	0625		/**< shifted suspend key */
216
+#define KEY_SUNDO	0626		/**< shifted undo key */
217
+#define KEY_SUSPEND	0627		/**< suspend key */
218
+#define KEY_UNDO	0630		/**< undo key */
219
+#define KEY_RESIZE	0632		/**< Terminal resize event */
220
+#define KEY_EVENT	0633		/**< We were interrupted by an event */
221
+
222
+#define KEY_MAX		0777		/* Maximum key value is 0633 */
223
+
224
+/*extern int addch ( const chtype * );*/
225
+/*extern int addchnstr ( const chtype *, int );*/
226
+/*extern int addchstr ( const chtype * );*/
227
+/*extern int addnstr ( const char *, int );*/
228
+/*extern int addstr ( const char * );*/
229
+/*extern int attroff ( int );*/
230
+/*extern int attron ( int );*/
231
+/*extern int attrset ( int );*/
232
+extern int attr_get ( attr_t *, short *, void * );
233
+extern int attr_off ( attr_t, void * );
234
+extern int attr_on ( attr_t, void * );
235
+extern int attr_set ( attr_t, short, void * );
236
+extern int baudrate ( void );
237
+extern int beep ( void );
238
+/*extern int bkgd ( chtype );*/
239
+/*extern void bkgdset ( chtype );*/
240
+/*extern int border ( chtype, chtype, chtype, chtype, chtype, chtype, chtype,
241
+  chtype );*/
242
+extern int box ( WINDOW *, chtype, chtype );
243
+extern bool can_change_colour ( void );
244
+#define can_change_color() can_change_colour()
245
+extern int cbreak ( void ); 
246
+extern int chgat ( int, attr_t, short, const void * );
247
+extern int clearok ( WINDOW *, bool );
248
+extern int clear ( void );
249
+extern int clrtobot ( void );
250
+extern int clrtoeol ( void );
251
+extern int colour_content ( short, short *, short *, short * );
252
+#define color_content( col, r, g, b ) colour_content( (col), (r), (g), (b) )
253
+extern int colour_set ( short, void * );
254
+#define color_set( cpno, opts ) colour_set( (cpno), (opts) )
255
+extern int copywin ( const WINDOW *, WINDOW *, int, int, int, 
256
+		     int, int, int, int );
257
+extern int curs_set ( int );
258
+extern int def_prog_mode ( void );
259
+extern int def_shell_mode ( void );
260
+extern int delay_output ( int );
261
+extern int delch ( void );
262
+extern int deleteln ( void );
263
+extern void delscreen ( SCREEN * ); 
264
+extern int delwin ( WINDOW * );
265
+extern WINDOW *derwin ( WINDOW *, int, int, int, int );
266
+extern int doupdate ( void );
267
+extern WINDOW *dupwin ( WINDOW * );
268
+extern int echo ( void );
269
+extern int echochar ( const chtype );
270
+extern int endwin ( void );
271
+extern char erasechar ( void );
272
+extern int erase ( void );
273
+extern void filter ( void );
274
+extern int flash ( void );
275
+extern int flushinp ( void );
276
+extern chtype getbkgd ( WINDOW * );
277
+extern int getch ( void );
278
+extern int getnstr ( char *, int );
279
+extern int getstr ( char * );
280
+extern int halfdelay ( int );
281
+extern bool has_colors ( void );
282
+extern bool has_ic ( void );
283
+extern bool has_il ( void );
284
+extern int hline ( chtype, int );
285
+extern void idcok ( WINDOW *, bool );
286
+extern int idlok ( WINDOW *, bool );
287
+extern void immedok ( WINDOW *, bool );
288
+extern chtype inch ( void );
289
+extern int inchnstr ( chtype *, int );
290
+extern int inchstr ( chtype * );
291
+extern WINDOW *initscr ( void );
292
+extern int init_color ( short, short, short, short );
293
+extern int init_pair ( short, short, short );
294
+extern int innstr ( char *, int );
295
+extern int insch ( chtype );
296
+extern int insdelln ( int );
297
+extern int insertln ( void );
298
+extern int insnstr ( const char *, int );
299
+extern int insstr ( const char * );
300
+extern int instr ( char * );
301
+extern int intrflush ( WINDOW *, bool );
302
+extern bool isendwin ( void );
303
+extern bool is_linetouched ( WINDOW *, int );
304
+extern bool is_wintouched ( WINDOW * );
305
+extern char *keyname ( int );
306
+extern int keypad ( WINDOW *, bool );
307
+extern char killchar ( void );
308
+extern int leaveok ( WINDOW *, bool );
309
+extern char *longname ( void );
310
+extern int meta ( WINDOW *, bool );
311
+/*extern int move ( int, int );*/
312
+/*extern int mvaddch ( int, int, const chtype );*/
313
+/*extern int mvaddchnstr ( int, int, const chtype *, int );*/
314
+/*extern int mvaddchstr ( int, int, const chtype * );*/
315
+/*extern int mvaddnstr ( int, int, const char *, int );*/
316
+/*extern int mvaddstr ( int, int, const char * );*/
317
+extern int mvchgat ( int, int, int, attr_t, short, const void * );
318
+extern int mvcur ( int, int, int, int );
319
+extern int mvdelch ( int, int );
320
+extern int mvderwin ( WINDOW *, int, int );
321
+extern int mvgetch ( int, int );
322
+extern int mvgetnstr ( int, int, char *, int );
323
+extern int mvgetstr ( int, int, char * );
324
+extern int mvhline ( int, int, chtype, int );
325
+extern chtype mvinch ( int, int );
326
+extern int mvinchnstr ( int, int, chtype *, int );
327
+extern int mvinchstr ( int, int, chtype * );
328
+extern int mvinnstr ( int, int, char *, int );
329
+extern int mvinsch ( int, int, chtype );
330
+extern int mvinsnstr ( int, int, const char *, int );
331
+extern int mvinsstr ( int, int, const char * );
332
+extern int mvinstr ( int, int, char * );
333
+extern int mvprintw ( int, int, char *,  ... );
334
+extern int mvscanw ( int, int, char *, ... );
335
+extern int mvvline ( int, int, chtype, int );
336
+/*extern int mvwaddch ( WINDOW *, int, int, const chtype );*/
337
+/*extern int mvwaddchnstr ( WINDOW *, int, int, const chtype *, int );*/
338
+/*extern int mvwaddchstr ( WINDOW *, int, int, const chtype * );*/
339
+/*extern int mvwaddnstr ( WINDOW *, int, int, const char *, int );*/
340
+/*extern int mvwaddstr ( WINDOW *, int, int, const char * );*/
341
+extern int mvwchgat ( WINDOW *, int, int, int, attr_t, short, const void * );
342
+extern int mvwdelch ( WINDOW *, int, int );
343
+extern int mvwgetch ( WINDOW *, int, int );
344
+extern int mvwgetnstr ( WINDOW *, int, int, char *, int );
345
+extern int mvwgetstr ( WINDOW *, int, int, char * );
346
+extern int mvwhline ( WINDOW *, int, int, chtype, int );
347
+extern int mvwin ( WINDOW *, int, int );
348
+extern chtype mvwinch ( WINDOW *, int, int );
349
+extern int mvwinchnstr ( WINDOW *, int, int, chtype *, int );
350
+extern int mvwinchstr ( WINDOW *, int, int, chtype * );
351
+extern int mvwinnstr ( WINDOW *, int, int, char *, int );
352
+extern int mvwinsch ( WINDOW *, int, int, chtype );
353
+extern int mvwinsnstr ( WINDOW *, int, int, const char *, int );
354
+extern int mvwinsstr ( WINDOW *, int, int, const char * );
355
+extern int mvwinstr ( WINDOW *, int, int, char * );
356
+extern int mvwprintw ( WINDOW *, int, int, char *, ... );
357
+extern int mvwscanw ( WINDOW *, int, int, char *, ... );
358
+extern int mvwvline ( WINDOW *, int, int, chtype, int );
359
+extern int napms ( int );
360
+extern WINDOW *newpad ( int, int );
361
+extern WINDOW *newwin ( int, int, int, int );
362
+extern int nl ( void );
363
+extern int nocbreak ( void );
364
+extern int nodelay ( WINDOW *, bool );
365
+extern int noecho ( void );
366
+extern int nonl ( void );
367
+extern void noqiflush ( void );
368
+extern int noraw ( void );
369
+extern int notimeout ( WINDOW *, bool );
370
+extern int overlay ( const WINDOW *, WINDOW * );
371
+extern int overwrite ( const WINDOW *, WINDOW * );
372
+extern int pair_content ( short, short *, short * );
373
+extern int PAIR_NUMBER ( int );
374
+extern int pechochar ( WINDOW *, chtype );
375
+extern int pnoutrefresh ( WINDOW *, int, int, int, int, int, int );
376
+extern int prefresh ( WINDOW *, int, int, int, int, int, int );
377
+extern int printw ( char *, ... );
378
+extern int putp ( const char * );
379
+extern void qiflush ( void );
380
+extern int raw ( void );
381
+extern int redrawwin ( WINDOW * );
382
+extern int refresh ( void );
383
+extern int reset_prog_mode ( void );
384
+extern int reset_shell_mode ( void );
385
+extern int resetty ( void );
386
+extern int ripoffline ( int, int  ( *) ( WINDOW *, int) );
387
+extern int savetty ( void );
388
+extern int scanw ( char *, ... );
389
+extern int scr_dump ( const char * );
390
+extern int scr_init ( const char * );
391
+extern int scrl ( int );
392
+extern int scroll ( WINDOW * );
393
+extern int scrollok ( WINDOW *, bool );
394
+extern int scr_restore ( const char * );
395
+extern int scr_set ( const char * );
396
+extern int setscrreg ( int, int );
397
+extern SCREEN *set_term ( SCREEN * );
398
+extern int setupterm ( char *, int, int * );
399
+extern int slk_attr_off ( const attr_t, void * );
400
+extern int slk_attroff ( const chtype );
401
+extern int slk_attr_on ( const attr_t, void * );
402
+extern int slk_attron ( const chtype );
403
+extern int slk_attr_set ( const attr_t, short, void * );
404
+extern int slk_attrset ( const chtype );
405
+extern int slk_clear ( void );
406
+extern int slk_color ( short );
407
+extern int slk_init ( int );
408
+extern char *slk_label ( int );
409
+extern int slk_noutrefresh ( void );
410
+extern int slk_refresh ( void );
411
+extern int slk_restore ( void );
412
+extern int slk_set ( int, const char *, int );
413
+extern int slk_touch ( void );
414
+extern int standend ( void );
415
+extern int standout ( void );
416
+extern int start_color ( void );
417
+extern WINDOW *subpad ( WINDOW *, int, int, int, int );
418
+extern WINDOW *subwin ( WINDOW *, int, int, int, int );
419
+extern int syncok ( WINDOW *, bool );
420
+extern chtype termattrs ( void );
421
+extern attr_t term_attrs ( void );
422
+extern char *termname ( void );
423
+extern int tigetflag ( char * );
424
+extern int tigetnum ( char * );
425
+extern char *tigetstr ( char * );
426
+extern void timeout ( int );
427
+extern int touchline ( WINDOW *, int, int );
428
+extern int touchwin ( WINDOW * );
429
+extern char *tparm ( char *, long, long, long, long, long, long, long, long,
430
+		   long );
431
+extern int typeahead ( int );
432
+extern int ungetch ( int );
433
+extern int untouchwin ( WINDOW * );
434
+extern void use_env ( bool );
435
+extern int vid_attr ( attr_t, short, void * );
436
+extern int vidattr ( chtype );
437
+extern int vid_puts ( attr_t, short, void *, int  ( *) ( int) );
438
+extern int vidputs ( chtype, int  ( *) ( int) );
439
+extern int vline ( chtype, int );
440
+extern int vwprintw ( WINDOW *, char *, va_list * );
441
+extern int vw_printw ( WINDOW *, char *, va_list * );
442
+extern int vwscanw ( WINDOW *, char *, va_list * );
443
+extern int vw_scanw ( WINDOW *, char *, va_list * );
444
+extern int waddch ( WINDOW *, const chtype );
445
+extern int waddchnstr ( WINDOW *, const chtype *, int );
446
+/*extern int waddchstr ( WINDOW *, const chtype * );*/
447
+extern int waddnstr ( WINDOW *, const char *, int );
448
+/*extern int waddstr ( WINDOW *, const char * );*/
449
+extern int wattroff ( WINDOW *, int );
450
+extern int wattron ( WINDOW *, int );
451
+extern int wattrset ( WINDOW *, int );
452
+extern int wattr_get ( WINDOW *, attr_t *, short *, void * );
453
+extern int wattr_off ( WINDOW *, attr_t, void * );
454
+extern int wattr_on ( WINDOW *, attr_t, void * );
455
+extern int wattr_set ( WINDOW *, attr_t, short, void * );
456
+extern int wbkgd ( WINDOW *, chtype );
457
+extern void wbkgdset ( WINDOW *, chtype );
458
+extern int wborder ( WINDOW *, chtype, chtype, chtype, chtype, chtype, chtype,
459
+		   chtype, chtype );
460
+extern int wchgat ( WINDOW *, int, attr_t, short, const void * );
461
+extern int wclear ( WINDOW * );
462
+extern int wclrtobot ( WINDOW * );
463
+extern int wclrtoeol ( WINDOW * );
464
+extern void wcursyncup ( WINDOW * );
465
+extern int wcolor_set ( WINDOW *, short, void * );
466
+extern int wdelch ( WINDOW * );
467
+extern int wdeleteln ( WINDOW * );
468
+extern int wechochar ( WINDOW *, const chtype );
469
+extern int werase ( WINDOW * );
470
+extern int wgetch ( WINDOW * );
471
+extern int wgetnstr ( WINDOW *, char *, int );
472
+extern int wgetstr ( WINDOW *, char * );
473
+extern int whline ( WINDOW *, chtype, int );
474
+extern chtype winch ( WINDOW * );
475
+extern int winchnstr ( WINDOW *, chtype *, int );
476
+extern int winchstr ( WINDOW *, chtype * );
477
+extern int winnstr ( WINDOW *, char *, int );
478
+extern int winsch ( WINDOW *, chtype );
479
+extern int winsdelln ( WINDOW *, int );
480
+extern int winsertln ( WINDOW * );
481
+extern int winsnstr ( WINDOW *, const char *, int );
482
+extern int winsstr ( WINDOW *, const char * );
483
+extern int winstr ( WINDOW *, char * );
484
+extern int wmove ( WINDOW *, int, int );
485
+extern int wnoutrefresh ( WINDOW * );
486
+extern int wprintw ( WINDOW *, char *, ... );
487
+extern int wredrawln ( WINDOW *, int, int );
488
+extern int wrefresh ( WINDOW * );
489
+extern int wscanw ( WINDOW *, char *, ... );
490
+extern int wscrl ( WINDOW *, int );
491
+extern int wsetscrreg ( WINDOW *, int, int );
492
+extern int wstandend ( WINDOW * );
493
+extern int wstandout ( WINDOW * );
494
+extern void wsyncup ( WINDOW * );
495
+extern void wsyncdown ( WINDOW * );
496
+extern void wtimeout ( WINDOW *, int );
497
+extern int wtouchln ( WINDOW *, int, int, int );
498
+extern int wvline ( WINDOW *, chtype, int );
499
+
500
+#define COLOUR_PAIR(n)	MUCURSES_BITS( (n), -8 )
501
+#define COLOR_PAIR(n)	COLOUR_PAIR(n)
502
+
503
+/*
504
+ * static inlines
505
+ */
506
+
507
+/**
508
+ * Add a single-byte character and rendition to stdscr and advance the
509
+ * cursor
510
+ *
511
+ * @v ch	character to be added at cursor
512
+ * @ret rc	return status code
513
+ */
514
+static inline int addch ( const chtype ch ) {
515
+	return waddch( stdscr, ch );
516
+}
517
+
518
+/**
519
+ * Add string of single-byte characters and renditions to stdscr
520
+ *
521
+ * @v *chstr	pointer to first chtype in "string"
522
+ * @v n		number of chars from chstr to render
523
+ * @ret rc	return status code
524
+ */
525
+static inline int addchnstr ( const chtype *chstr, int n ) {
526
+	return waddchnstr ( stdscr, chstr, n );
527
+}
528
+
529
+/**
530
+ * Add string of single-byte characters and renditions to stdscr
531
+ *
532
+ * @v *chstr	pointer to first chtype in "string"
533
+ * @ret rc	return status code
534
+ */
535
+static inline int addchstr ( const chtype *chstr ) {
536
+	return waddchnstr ( stdscr, chstr, -1 );
537
+}
538
+
539
+/**
540
+ * Add string of single-byte characters to stdscr
541
+ *
542
+ * @v *str	standard c-style string
543
+ * @v n		max number of chars from string to render
544
+ * @ret rc	return status code
545
+ */
546
+static inline int addnstr ( const char *str, int n ) {
547
+	return waddnstr ( stdscr, str, n );
548
+}
549
+
550
+/**
551
+ * Add string of single-byte characters to stdscr
552
+ *
553
+ * @v *str	standard c-style string
554
+ * @ret rc	return status code
555
+ */
556
+static inline int addstr ( const char *str ) {
557
+	return waddnstr ( stdscr, str, -1 );
558
+}
559
+
560
+/**
561
+ * Turn off attributes
562
+ *
563
+ * @v win	subject window
564
+ * @v attrs	attributes to enable
565
+ * @ret rc	return status code
566
+ */
567
+static inline int attroff ( int attrs ) {
568
+	return wattroff ( stdscr, attrs );
569
+}
570
+
571
+/**
572
+ * Turn on attributes
573
+ *
574
+ * @v win	subject window
575
+ * @v attrs	attributes to enable
576
+ * @ret rc	return status code
577
+ */
578
+static inline int attron ( int attrs ) {
579
+	return wattron ( stdscr, attrs );
580
+}
581
+
582
+/**
583
+ * Set attributes
584
+ *
585
+ * @v win	subject window
586
+ * @v attrs	attributes to enable
587
+ * @ret rc	return status code
588
+ */
589
+static inline int attrset ( int attrs ) {
590
+	return wattrset ( stdscr, attrs );
591
+}
592
+
593
+/**
594
+ * Set background rendition attributes for stdscr and apply to
595
+ * contents
596
+ *
597
+ * @v ch	chtype containing rendition attributes
598
+ * @ret rc	return status code
599
+ */
600
+static inline int bkgd ( chtype ch ) {
601
+	return wbkgd ( stdscr, ch );
602
+}
603
+
604
+/**
605
+ * Set background rendition attributes for stdscr
606
+ */
607
+static inline void bkgdset ( chtype ch ) {
608
+	wbkgdset ( stdscr, ch );
609
+}
610
+
611
+/**
612
+ * Draw borders from single-byte characters and renditions around
613
+ * stdscr
614
+ *
615
+ * @v ls	left side
616
+ * @v rs	right side
617
+ * @v ts	top
618
+ * @v bs	bottom
619
+ * @v tl	top left corner
620
+ * @v tr	top right corner
621
+ * @v bl	bottom left corner
622
+ * @v br	bottom right corner
623
+ * @ret rc	return status code
624
+ */
625
+static inline int border ( chtype ls, chtype rs, chtype ts, chtype bs,
626
+			   chtype tl, chtype tr, chtype bl, chtype br ) {
627
+	return wborder ( stdscr, ls, rs, ts, bs, tl, tr, bl, br );
628
+}
629
+
630
+/**
631
+ * Move stdscr cursor to the specified position
632
+ *
633
+ * @v y		Y position
634
+ * @v x		X position
635
+ * @ret rc	return status code
636
+ */
637
+static inline int move ( int y, int x ) {
638
+	return wmove ( stdscr, y, x );
639
+}
640
+
641
+/**
642
+ * Add a single-byte character and rendition to stdscr at the
643
+ * specified position and advance the cursor
644
+ *
645
+ * @v y		Y position
646
+ * @v x		X position
647
+ * @v ch	character to be added at cursor
648
+ * @ret rc	return status code
649
+ */
650
+static inline int mvaddch ( int y, int x, const chtype ch ) {
651
+	return ( wmove ( stdscr, y, x ) == ERR 
652
+		 ? ERR : waddch( stdscr, ch ) );
653
+}
654
+
655
+/**
656
+ * Add string of single-byte characters and renditions to stdscr at
657
+ * the specified position
658
+ *
659
+ * @v y		Y position
660
+ * @v x		X position
661
+ * @v *chstr	pointer to first chtype in "string"
662
+ * @v n		max number of chars from chstr to render
663
+ * @ret rc	return status code
664
+ */
665
+static inline int mvaddchnstr ( int y, int x, const chtype *chstr, int n ) {
666
+	return ( wmove ( stdscr, y, x ) == ERR
667
+		 ? ERR : waddchnstr ( stdscr, chstr, n ) );
668
+}
669
+
670
+/**
671
+ * Add string of single-byte characters and renditions to stdscr at
672
+ * the specified position
673
+ *
674
+ * @v y		Y position
675
+ * @v x		X position
676
+ * @v *chstr	pointer to first chtype in "string"
677
+ * @ret rc	return status code
678
+ */
679
+static inline int mvaddchstr ( int y, int x, const chtype *chstr ) {
680
+	return ( wmove ( stdscr, y, x ) == ERR
681
+		 ? ERR : waddchnstr ( stdscr, chstr, -1 ) );
682
+}
683
+
684
+/**
685
+ * Add string of single-byte characters to stdscr at the specified
686
+ * position
687
+ *
688
+ * @v y		Y position
689
+ * @v x		X position
690
+ * @v *str	standard c-style string
691
+ * @v n		max number of chars from string to render
692
+ * @ret rc	return status code
693
+ */
694
+static inline int mvaddnstr ( int y, int x, const char *str, int n ) {
695
+	return ( wmove ( stdscr, y, x ) == ERR
696
+		 ? ERR : waddnstr ( stdscr, str, n ) );
697
+}
698
+
699
+/**
700
+ * Add string of single-byte characters to stdscr at the specified
701
+ * position
702
+ *
703
+ * @v y		Y position
704
+ * @v x		X position
705
+ * @v *str	standard c-style string
706
+ * @ret rc	return status code
707
+ */
708
+static inline int mvaddstr ( int y, int x, const char *str ) {
709
+	return ( wmove ( stdscr, y, x ) == ERR
710
+		 ? ERR : waddnstr ( stdscr, str, -1 ) );
711
+}
712
+
713
+/**
714
+ * Add a single-byte character and rendition to a window at the
715
+ * specified position and advance the cursor
716
+ *
717
+ * @v *win	subject window
718
+ * @v y		Y position
719
+ * @v x		X position
720
+ * @v ch	character to be added at cursor
721
+ * @ret rc	return status code
722
+ */
723
+static inline int mvwaddch ( WINDOW *win, int y, int x, const chtype ch ) {
724
+	return ( wmove( win, y, x ) == ERR 
725
+		 ? ERR : waddch ( win, ch ) );
726
+}
727
+
728
+/**
729
+ * Add string of single-byte characters and renditions to a window at
730
+ * the specified position
731
+ *
732
+ * @v *win	subject window
733
+ * @v y		Y position
734
+ * @v x		X position
735
+ * @v *chstr	pointer to first chtype in "string"
736
+ * @v n		max number of chars from chstr to render
737
+ * @ret rc	return status code
738
+ */
739
+static inline int mvwaddchnstr ( WINDOW *win, int y, int x, const chtype *chstr, int n ) {
740
+	return ( wmove ( win, y, x ) == ERR 
741
+		 ? ERR : waddchnstr ( win, chstr, n ) );
742
+}
743
+
744
+/**
745
+ * Add string of single-byte characters and renditions to a window at
746
+ * the specified position
747
+ *
748
+ * @v *win	subject window
749
+ * @v y		Y position
750
+ * @v x		X position
751
+ * @v *chstr	pointer to first chtype in "string"
752
+ * @ret rc	return status code
753
+ */
754
+static inline int mvwaddchstr ( WINDOW *win, int y, int x, const chtype *chstr ) {
755
+	return ( wmove ( win, y, x ) == ERR 
756
+		 ? ERR : waddchnstr ( win, chstr, -1 ) );
757
+}
758
+
759
+/**
760
+ * Add string of single-byte characters to a window at the specified
761
+ * position
762
+ *
763
+ * @v *win	window to be rendered in
764
+ * @v y		Y position
765
+ * @v x		X position
766
+ * @v *str	standard c-style string
767
+ * @v n		max number of chars from string to render
768
+ * @ret rc	return status code
769
+ */
770
+static inline int mvwaddnstr ( WINDOW *win, int y, int x, const char *str, int n ) {
771
+	return ( wmove ( win, y, x ) == ERR
772
+		 ? ERR : waddnstr ( win, str, n ) );
773
+}
774
+
775
+/**
776
+ * Add string of single-byte characters to a window at the specified
777
+ * position
778
+ *
779
+ * @v *win	window to be rendered in
780
+ * @v y		Y position
781
+ * @v x		X position
782
+ * @v *str	standard c-style string
783
+ * @ret rc	return status code
784
+ */
785
+static inline int mvwaddstr ( WINDOW *win, int y, int x, const char *str ) {
786
+	return ( wmove ( win, y, x ) == ERR
787
+		 ? ERR : waddnstr ( win, str, -1 ) );
788
+}
789
+
790
+/**
791
+ * Add string of single-byte characters and renditions to a window
792
+ *
793
+ * @v *win	subject window
794
+ * @v *chstr	pointer to first chtype in "string"
795
+ * @ret rc	return status code
796
+ */
797
+static inline int waddchstr ( WINDOW *win, const chtype *chstr ) {
798
+	return waddchnstr ( win, chstr, -1 );
799
+}
800
+
801
+/**
802
+ * Add string of single-byte characters to a window
803
+ *
804
+ * @v *win	window to be rendered in
805
+ * @v *str	standard c-style string
806
+ * @ret rc	return status code
807
+ */
808
+static inline int waddstr ( WINDOW *win, const char *str ) {
809
+	return waddnstr ( win, str, -1 );
810
+}
811
+
812
+/*
813
+ * Primitives
814
+ */
815
+/**
816
+ * Move cursor to position specified by x,y coords
817
+ *
818
+ * @v *scr	screen on which to operate
819
+ * @v y		Y position
820
+ * @v x		X position
821
+ * @ret rc	void function
822
+ */
823
+void _movetoyx ( struct _curses_screen *scr, unsigned int y, unsigned int x );
824
+/**
825
+ * Write character (c) to current cursor position
826
+ *
827
+ * @v *scr	screen on which to operate
828
+ * @v c		character to be written
829
+ * @ret rc	void function
830
+ */
831
+void _putc ( struct _curses_screen *scr, unsigned int c );
832
+/**
833
+ * Retrieve a character from current cursor position and store
834
+ * it in c
835
+ *
836
+ * @v *scr	screen on which to operate
837
+ * @v *c	char ptr where retrieved character is to be stored
838
+ * @ret rc	void function
839
+ */
840
+void _getc ( struct _curses_screen *scr, unsigned int *c );
841
+/**
842
+ * Advance cursor (wrap text)
843
+ *
844
+ * @v *win	window in which to advance
845
+ * @ret rc	void function
846
+ */
847
+void _advcurs_wrap ( struct _curses_window *win );
848
+/**
849
+ * Advance cursor (no wrap text)
850
+ *
851
+ * @v *win	window in which to advance
852
+ * @ret rc	void function
853
+ */
854
+void _advcurs_nowrap ( struct _curses_window *win );
855
+/**
856
+ * Store cursor position for later restoration
857
+ *
858
+ * @v *win	window on which to operate
859
+ * @ret rc	return encoded position
860
+ */
861
+unsigned int _store_curs_pos ( WINDOW *win );
862
+/**
863
+ * Restore cursor position from encoded backup variable
864
+ *
865
+ * @v *win	window on which to operate
866
+ * @v pos	encoded position
867
+ * @ret rc	return status code
868
+ */
869
+int _restore_curs_pos ( WINDOW *win, unsigned int pos );
870
+
871
+#endif /* CURSES_H */

Loading…
Cancel
Save