Training courses

Kernel and Embedded Linux

Bootlin training courses

Embedded Linux, kernel,
Yocto Project, Buildroot, real-time,
graphics, boot time, debugging...

Bootlin logo

Elixir Cross Referencer

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
/*	$NetBSD: curses_private.h,v 1.80 2022/05/03 07:25:34 blymn Exp $	*/

/*-
 * Copyright (c) 1998-2000 Brett Lymn
 *                         (blymn@baea.com.au, brett_lymn@yahoo.com.au)
 * All rights reserved.
 *
 * This code has been donated to The NetBSD Foundation by the Author.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. The name of the author may not be used to endorse or promote products
 *    derived from this software without specific prior written permission
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 *
 */

/* Modified by Ruibiao Qiu <ruibiao@arl.wustl.edu,ruibiao@gmail.com>
 * to add support for wide characters
 * Changes:
 * - Add a compiler variable HAVE_WCHAR for wide character only code
 * - Add a pointer to liked list of non-spacing characters in __ldata
 *   and the macro to access the width field in the attribute field
 * - Add a circular input character buffer in __screen to handle
 *   wide-character input (used in get_wch())
 */

#include <term.h>
#include <termios.h>

/* Private structure definitions for curses. */

/* Termcap capabilities. */
#ifdef HAVE_WCHAR
/*
 * Add a list of non-spacing characters to each spacing
 * character in a singly linked list
 */
typedef struct nschar_t {
	wchar_t			ch;		/* Non-spacing character */
	struct nschar_t	*next;	/* Next non-spacing character */
} nschar_t;
#endif /* HAVE_WCHAR */

/*
 * A window is an array of __LINE structures pointed to by the 'lines' pointer.
 * A line is an array of __LDATA structures pointed to by the 'line' pointer.
 *
 * IMPORTANT: the __LDATA structure must NOT induce any padding, so if new
 * fields are added -- padding fields with *constant values* should ensure
 * that the compiler will not generate any padding when storing an array of
 *  __LDATA structures.  This is to enable consistent use of memcmp, and memcpy
 * for comparing and copying arrays.
 */

struct __ldata {
	wchar_t	ch;			/* Character */
	attr_t	attr;			/* Attributes */
#define CA_CONTINUATION		0x0001	/* a continuation cell */
#define CA_BACKGROUND		0x0002	/* background char */
	int16_t		cflags;		/* internal attributes for wide char */
#ifdef HAVE_WCHAR
	nschar_t	*nsp;	/* Foreground non-spacing character pointer */
	int16_t		wcols;		/* display width of a wide char */
#endif /* HAVE_WCHAR */
};

#define __LDATASIZE	(sizeof(__LDATA))

struct __line {
#ifdef DEBUG
#define SENTINEL_VALUE 0xaac0ffee

	unsigned int sentinel;          /* try to catch line overflows */
#endif
#define	__ISDIRTY	0x01		/* Line is dirty. */
#define __ISPASTEOL	0x02		/* Cursor is past end of line */
#define __ISFORCED	0x04		/* Force update, no optimisation */
	unsigned int flags;
	unsigned int hash;		/* Hash value for the line. */
	int *firstchp, *lastchp;	/* First and last chngd columns ptrs */
	int firstch, lastch;		/* First and last changed columns. */
	__LDATA *line;			/* Pointer to the line text. */
};

struct __window {		/* Window structure. */
	struct __window	*nextp, *orig;	/* Subwindows list and parent. */
	int begy, begx;			/* Window home. */
	int cury, curx;			/* Current x, y coordinates. */
	int maxy, maxx;			/* Maximum values for curx, cury. */
	int reqy, reqx;			/* Size requested when created */
	int ch_off;			/* x offset for firstch/lastch. */
	__LINE **alines;		/* Array of pointers to the lines */
	__LINE  *lspace;		/* line space (for cleanup) */
	__LDATA *wspace;		/* window space (for cleanup) */

#define	__ENDLINE	0x00000001	/* End of screen. */
#define	__FLUSH		0x00000002	/* Fflush(stdout) after refresh. */
#define	__FULLWIN	0x00000004	/* Window is a screen. */
#define	__IDLINE	0x00000008	/* Insert/delete sequences. */
#define	__SCROLLWIN	0x00000010	/* Last char will scroll window. */
#define	__SCROLLOK	0x00000020	/* Scrolling ok. */
#define	__CLEAROK	0x00000040	/* Clear on next refresh. */
#define	__LEAVEOK	0x00000100	/* If cursor left */
#define	__KEYPAD	0x00010000	/* If interpreting keypad codes */
#define	__NOTIMEOUT	0x00020000	/* Wait indefinitely for func keys */
#define __IDCHAR	0x00040000	/* insert/delete char sequences */
#define __ISPAD		0x00080000	/* "window" is a pad */
#define __ISDERWIN	0x00100000	/* "window" is derived from parent */
#define __IMMEDOK	0x00200000	/* refreshed when changed */
#define __SYNCOK	0x00400000	/* sync when changed */
#define __HALFDELAY	0x00800000	/* In half delay mode */
	unsigned int flags;
	int	delay;			/* delay for getch() */
	attr_t	wattr;			/* Character attributes */
	wchar_t	bch;			/* Background character */
	attr_t	battr;			/* Background attributes */
	uint32_t wcols;			/* Background column width */
	int	scr_t, scr_b;		/* Scrolling region top, bottom */
	SCREEN	*screen;		/* Screen for this window */
	int	pbegy, pbegx,
		sbegy, sbegx,
		smaxy, smaxx;		/* Saved prefresh() values */
	int	dery, derx;		/* derived window coordinates
					   - top left corner of source 
					   relative to parent win */
#ifdef HAVE_WCHAR
	nschar_t *bnsp;			/* Background non-spacing char list */
#endif /* HAVE_WCHAR */
	FILE	*fp;			/* for window formatted printf */
	char	*buf;			/* buffer for window formatted printf */
	size_t	 buflen;		/* length of above buffer */
};

/* Set of attributes unset by 'me' - 'mb', 'md', 'mh', 'mk', 'mp' and 'mr'. */
#ifndef HAVE_WCHAR
#define	__TERMATTR \
	(__REVERSE | __BLINK | __DIM | __BOLD | __BLANK | __PROTECT)
#else
#define	__TERMATTR \
	(__REVERSE | __BLINK | __DIM | __BOLD | __BLANK | __PROTECT \
	| WA_TOP | WA_LOW | WA_LEFT | WA_RIGHT | WA_HORIZONTAL | WA_VERTICAL)
#endif /* HAVE_WCHAR */

struct __winlist {
	struct __window		*winp;	/* The window. */
	struct __winlist	*nextp;	/* Next window. */
};

struct __color {
	short	num;
	short	red;
	short	green;
	short	blue;
	int	flags;
};

/* List of colour pairs */
struct __pair {
	short	fore;
	short	back;
	int	flags;
};

/* Maximum colours */
#define	MAX_COLORS	256
/* Maximum colour pairs - determined by number of colour bits in attr_t */
#define	MAX_PAIRS	PAIR_NUMBER(__COLOR)

typedef struct keymap keymap_t;

/* POSIX allows up to 8 columns in a label. */
#define	MAX_SLK_COLS	8
#ifdef HAVE_WCHAR
#define	MAX_SLK_LABEL	sizeof(wchar_t) * MAX_SLK_COLS
#else
#define	MAX_SLK_LABEL	MAX_SLK_COLS
#endif
struct __slk_label {
	char	*text;
	int	 justify;
#define	SLK_JUSTIFY_LEFT	0
#define	SLK_JUSTIFY_CENTER	1
#define	SLK_JUSTIFY_RIGHT	2
	char	 label[MAX_SLK_LABEL + 1];
	int	 x;
};

#define	MAX_RIPS	5
struct __ripoff {
	int	nlines;
	WINDOW	*win;
};

/* this is the encapsulation of the terminal definition, one for
 * each terminal that curses talks to.
 */
struct __screen {
	FILE    *infd, *outfd;  /* input and output file descriptors */
	WINDOW	*curscr;	/* Current screen. */
	WINDOW	*stdscr;	/* Standard screen. */
	WINDOW	*__virtscr;	/* Virtual screen (for doupdate()). */
	int      curwin;        /* current window for refresh */
	int      lx, ly;        /* loop parameters for refresh */
	int	 COLS;		/* Columns on the screen. */
	int	 LINES;		/* Lines on the screen. */
	int	 nripped;	/* Number of ripofflines. */
	struct __ripoff ripped[MAX_RIPS];	/* ripofflines. */
	int	 ESCDELAY;	/* Delay between keys in esc seq's. */
#define	ESCDELAY_DEFAULT	300 /* milliseconds. */
	int	 TABSIZE;	/* Size of a tab. */
#define	TABSIZE_DEFAULT		8   /* spaces. */
	int	 COLORS;	/* Maximum colors on the screen */
	int	 COLOR_PAIRS;	/* Maximum color pairs on the screen */
	int	 My_term;	/* Use Def_term regardless. */
	char	 GT;		/* Gtty indicates tabs. */
	char	 NONL;		/* Term can't hack LF doing a CR. */
	char	 UPPERCASE;	/* Terminal is uppercase only. */

	chtype acs_char[NUM_ACS];
#ifdef HAVE_WCHAR
	cchar_t wacs_char[ NUM_ACS ];
#endif /* HAVE_WCHAR */
	struct __color colours[MAX_COLORS];
	struct __pair  colour_pairs[MAX_PAIRS];
	attr_t	nca;

/* Style of colour manipulation */
#define COLOR_NONE	0
#define COLOR_ANSI	1	/* ANSI/DEC-style colour manipulation */
#define COLOR_HP	2	/* HP-style colour manipulation */
#define COLOR_TEK	3	/* Tektronix-style colour manipulation */
#define COLOR_OTHER	4	/* None of the others but can set fore/back */
	int color_type;

	attr_t mask_op;
	attr_t mask_me;
	attr_t mask_ue;
	attr_t mask_se;
	TERMINAL *term;
	int old_mode; /* old cursor visibility state for terminal */
	keymap_t *base_keymap;
	int echoit;
	int pfast;
	int rawmode;
	int nl;
	int noqch;
	int clearok;
	int useraw;
	struct __winlist *winlistp;
	struct   termios cbreakt, rawt, *curt, save_termios;
	struct termios orig_termios, baset, savedtty;
	int ovmin;
	int ovtime;
	char *stdbuf;
	unsigned int len;
	int meta_state;
	char padchar;
	int endwin;
	int notty;
	int resized;
	wchar_t *unget_list;
	int unget_len, unget_pos;
	int filtered;
	int checkfd;

	/* soft label key */
	bool		 is_term_slk;
	WINDOW		*slk_window;
	int		 slk_format;
#define	SLK_FMT_INVAL	-1
#define	SLK_FMT_3_2_3	0
#define	SLK_FMT_4_4	1
	int		 slk_nlabels;
	int		 slk_label_len;
	bool		 slk_hidden;
	struct __slk_label *slk_labels;

#define MAX_CBUF_SIZE 8
#ifdef HAVE_WCHAR
	int		cbuf_head;		/* header to cbuf */
	int		cbuf_tail;		/* tail to cbuf */
	int		cbuf_cur;		/* the current char in cbuf */
	mbstate_t	sp;			/* wide char processing state */
	char		cbuf[ MAX_CBUF_SIZE ];	/* input character buffer */
#endif /* HAVE_WCHAR */
};


extern char	 __GT;			/* Gtty indicates tabs. */
extern char	 __NONL;		/* Term can't hack LF doing a CR. */
extern char	 __UPPERCASE;		/* Terminal is uppercase only. */
extern int	 My_term;		/* Use Def_term regardless. */
extern const char	*Def_term;	/* Default terminal type. */
extern SCREEN   *_cursesi_screen;       /* The current screen in use */

/* Debugging options/functions. */
#ifdef DEBUG
#define __CTRACE_TSTAMP		0x00000001
#define __CTRACE_MISC		0x00000002
#define __CTRACE_INIT		0x00000004
#define __CTRACE_SCREEN		0x00000008
#define __CTRACE_WINDOW		0x00000010
#define __CTRACE_REFRESH	0x00000020
#define __CTRACE_COLOR		0x00000040
#define __CTRACE_INPUT		0x00000080
#define __CTRACE_OUTPUT		0x00000100
#define __CTRACE_LINE		0x00000200
#define __CTRACE_ATTR		0x00000400
#define __CTRACE_ERASE		0x00000800
#define __CTRACE_FILEIO		0x00001000
#define __CTRACE_ALL		0x7fffffff
void	 __CTRACE(int, const char *, ...) __attribute__((__format__(__printf__, 2, 3)));
#else
#define	__CTRACE(area, fmt, ...)	__nothing
#endif

/* Common erase logic */
#ifdef HAVE_WCHAR
#define __NEED_ERASE(_sp, _bch, _battr)				\
	((_sp)->ch != (_bch) ||					\
	(((_sp)->cflags & CA_BACKGROUND) != CA_BACKGROUND) ||	\
	    ((_sp)->attr & WA_ATTRIBUTES) != (_battr) ||	\
	    (_sp)->nsp != NULL ||				\
	    (_sp)->wcols < 0)
#else
#define __NEED_ERASE(_sp, _bch, _battr)				\
	((_sp)->ch != (_bch) || (_sp)->attr != (_battr))
#endif

/* Private functions. */
int     __cputchar_args(int, void *);
void     _cursesi_free_keymap(keymap_t *);
int      _cursesi_gettmode(SCREEN *);
void     _cursesi_reset_acs(SCREEN *);
int	_cursesi_addbyte(WINDOW *, __LINE **, int *, int *, int , attr_t, int);
int	_cursesi_addwchar(WINDOW *, __LINE **, int *, int *, const cchar_t *,
			  int);
int	_cursesi_waddbytes(WINDOW *, const char *, int, attr_t, int);
#ifdef HAVE_WCHAR
void     _cursesi_reset_wacs(SCREEN *);
#endif /* HAVE_WCHAR */
void     _cursesi_resetterm(SCREEN *);
int      _cursesi_setterm(char *, SCREEN *);
int	 __delay(void);
unsigned int	 __hash_more(const void *, size_t, unsigned int);
unsigned int	 __hash_line(const __LDATA *, int);
#define	__hash(s, len)	__hash_more((s), (len), 0u)
void	 __id_subwins(WINDOW *);
void	 __init_getch(SCREEN *);
void	 __init_acs(SCREEN *);
int	 _cursesi_celleq(__LDATA *, __LDATA *);
#ifdef HAVE_WCHAR
void	 __init_get_wch(SCREEN *);
void	 __init_wacs(SCREEN *);
int	__cputwchar_args( wchar_t, void * );
void	_cursesi_copy_wchar(__LDATA *, __LDATA *);
int     _cursesi_copy_nsp(nschar_t *, struct __ldata *);
void	__cursesi_free_nsp(nschar_t *);
void	__cursesi_win_free_nsp(WINDOW *);
void	__cursesi_putnsp(nschar_t *, const int, const int);
void	__cursesi_chtype_to_cchar(chtype, cchar_t *);
#endif /* HAVE_WCHAR */
int	 __fgetc_resize(FILE *);
int	 __unget(wint_t);
int	 __mvcur(int, int, int, int, int);
WINDOW  *__newwin(SCREEN *, int, int, int, int, int, int);
int	 __nodelay(void);
int	 __notimeout(void);
void	 __restartwin(void);
void	 __restore_colors(void);
void     __restore_cursor_vis(void);
void     __restore_meta_state(void);
void	 __restore_termios(void);
void	 __restore_stophandler(void);
void	 __restore_winchhandler(void);
int	 __ripoffscreen(SCREEN *);
int	 __ripoffresize(SCREEN *);
void	 __ripofftouch(SCREEN *);
int	 __rippedlines(const SCREEN *, int);
void	 __save_termios(void);
void	 __set_color(WINDOW *win, attr_t attr);
void	 __set_stophandler(void);
void	 __set_winchhandler(void);
void	 __set_subwin(WINDOW *, WINDOW *);
int	 __slk_init(SCREEN *);
void	 __slk_free(SCREEN *);
int	 __slk_resize(SCREEN *, int cols);
int	 __slk_noutrefresh(SCREEN *);
void	 __startwin(SCREEN *);
void	 __stop_signal_handler(int);
int	 __stopwin(void);
void	 __swflags(WINDOW *);
void	 __sync(WINDOW *);
int	 __timeout(int);
int	 __touchline(WINDOW *, int, int, int);
int	 __touchwin(WINDOW *, int);
int	 __unripoffline(int (*)(WINDOW *, int));
void	 __unsetattr(int);
void	 __unset_color(WINDOW *win);
int	 __waddch(WINDOW *, __LDATA *);
int	 __wgetnstr(WINDOW *, char *, int);
void	 __winch_signal_handler(int);

/* Private #defines. */
#define	min(a,b)	((a) < (b) ? (a) : (b))
#define	max(a,b)	((a) > (b) ? (a ): (b))

/* Private externs. */
extern int		 __echoit;
extern int		 __endwin;
extern int		 __pfast;
extern int		 __rawmode;
extern int		 __noqch;
extern attr_t		 __mask_op, __mask_me, __mask_ue, __mask_se;
extern WINDOW		*__virtscr;
extern int		 __using_color;
extern int		 __do_color_init;
extern attr_t		 __default_color;