version 1.25, 2002/08/04 16:43:08 |
version 1.40, 2007/05/28 15:01:55 |
|
|
* |
* |
*/ |
*/ |
|
|
|
/* 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 <termios.h> |
#include <termios.h> |
|
|
/* Private structure definitions for curses. */ |
/* Private structure definitions for curses. */ |
Line 59 extern char *__tc_ac, *__tc_AB, *__tc_ae |
|
Line 69 extern char *__tc_ac, *__tc_AB, *__tc_ae |
|
*__tc_uc, *__tc_ue, *__tc_UP, *__tc_up, *__tc_us, |
*__tc_uc, *__tc_ue, *__tc_UP, *__tc_up, *__tc_us, |
*__tc_vb, *__tc_ve, *__tc_vi, *__tc_vs; |
*__tc_vb, *__tc_ve, *__tc_vi, *__tc_vs; |
|
|
|
#ifdef HAVE_WCHAR |
|
extern char *__tc_Xh, *__tc_Xl, *__tc_Xo, *__tc_Xr, *__tc_Xt, |
|
*__tc_Xv; |
|
/* |
|
* 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 an array of __LINE structures pointed to by the 'lines' pointer. |
* A window 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. |
* A line is an array of __LDATA structures pointed to by the 'line' pointer. |
Line 73 extern char *__tc_ac, *__tc_AB, *__tc_ae |
|
Line 96 extern char *__tc_ac, *__tc_AB, *__tc_ae |
|
struct __ldata { |
struct __ldata { |
wchar_t ch; /* Character */ |
wchar_t ch; /* Character */ |
attr_t attr; /* Attributes */ |
attr_t attr; /* Attributes */ |
wchar_t bch; /* Background character */ |
#ifdef HAVE_WCHAR |
attr_t battr; /* Background attributes */ |
nschar_t *nsp; /* Foreground non-spacing character pointer */ |
|
#endif /* HAVE_WCHAR */ |
}; |
}; |
|
|
|
#ifdef HAVE_WCHAR |
|
/* macros to extract the width of a wide character */ |
|
#define __WCWIDTH 0xfc000000 |
|
#define WCW_SHIFT 26 |
|
#define WCOL(wc) ((((unsigned) (wc).attr) >> WCW_SHIFT ) > MB_LEN_MAX ? ((int)(((unsigned) (wc).attr ) >> WCW_SHIFT )) - 64 : ((int)(((unsigned) (wc).attr ) >> WCW_SHIFT))) |
|
#define SET_WCOL(c, w) do { \ |
|
((c).attr) = ((((c).attr) & WA_ATTRIBUTES ) | ((w) << WCW_SHIFT )); \ |
|
} while(/*CONSTCOND*/0) |
|
#define BGWCOL(wc) ((((wc).battr) >> WCW_SHIFT ) > MB_LEN_MAX ? (((wc).battr ) >> WCW_SHIFT ) - 64 : (((wc).battr ) >> WCW_SHIFT )) |
|
#define SET_BGWCOL(c, w) do { \ |
|
((c).battr) = ((((c).battr) & WA_ATTRIBUTES ) | ((w) << WCW_SHIFT )); \ |
|
} while(/*CONSTCOND*/0) |
|
#endif /* HAVE_WCHAR */ |
|
|
#define __LDATASIZE (sizeof(__LDATA)) |
#define __LDATASIZE (sizeof(__LDATA)) |
|
|
struct __line { |
struct __line { |
#ifdef DEBUG |
#ifdef DEBUG |
#define SENTINEL_VALUE 0xaac0ffee |
#define SENTINEL_VALUE 0xaac0ffee |
|
|
unsigned int sentinel; /* try to catch line overflows */ |
unsigned int sentinel; /* try to catch line overflows */ |
#endif |
#endif |
#define __ISDIRTY 0x01 /* Line is dirty. */ |
#define __ISDIRTY 0x01 /* Line is dirty. */ |
Line 99 struct __window { /* Window structure. |
|
Line 137 struct __window { /* Window structure. |
|
int begy, begx; /* Window home. */ |
int begy, begx; /* Window home. */ |
int cury, curx; /* Current x, y coordinates. */ |
int cury, curx; /* Current x, y coordinates. */ |
int maxy, maxx; /* Maximum values for curx, cury. */ |
int maxy, maxx; /* Maximum values for curx, cury. */ |
short ch_off; /* x offset for firstch/lastch. */ |
int reqy, reqx; /* Size requested when created */ |
|
int ch_off; /* x offset for firstch/lastch. */ |
__LINE **lines; /* Array of pointers to the lines */ |
__LINE **lines; /* Array of pointers to the lines */ |
__LINE *lspace; /* line space (for cleanup) */ |
__LINE *lspace; /* line space (for cleanup) */ |
__LDATA *wspace; /* window space (for cleanup) */ |
__LDATA *wspace; /* window space (for cleanup) */ |
Line 114 struct __window { /* Window structure. |
|
Line 153 struct __window { /* Window structure. |
|
#define __LEAVEOK 0x00000100 /* If cursor left */ |
#define __LEAVEOK 0x00000100 /* If cursor left */ |
#define __KEYPAD 0x00010000 /* If interpreting keypad codes */ |
#define __KEYPAD 0x00010000 /* If interpreting keypad codes */ |
#define __NOTIMEOUT 0x00020000 /* Wait indefinitely for func keys */ |
#define __NOTIMEOUT 0x00020000 /* Wait indefinitely for func keys */ |
#define __IDCHAR 0x00040000 /* insert/delete char sequences */ |
#define __IDCHAR 0x00040000 /* insert/delete char sequences */ |
|
#define __ISPAD 0x00080000 /* "window" is a pad */ |
unsigned int flags; |
unsigned int flags; |
int delay; /* delay for getch() */ |
int delay; /* delay for getch() */ |
attr_t wattr; /* Character attributes */ |
attr_t wattr; /* Character attributes */ |
wchar_t bch; /* Background character */ |
wchar_t bch; /* Background character */ |
attr_t battr; /* Background attributes */ |
attr_t battr; /* Background attributes */ |
int scr_t, scr_b; /* Scrolling region top, bottom */ |
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 */ |
|
#ifdef HAVE_WCHAR |
|
nschar_t *bnsp; /* Background non-spacing char list */ |
|
#endif /* HAVE_WCHAR */ |
}; |
}; |
|
|
/* Set of attributes unset by 'me' - 'mb', 'md', 'mh', 'mk', 'mp' and 'mr'. */ |
/* Set of attributes unset by 'me' - 'mb', 'md', 'mh', 'mk', 'mp' and 'mr'. */ |
|
#ifndef HAVE_WCHAR |
#define __TERMATTR \ |
#define __TERMATTR \ |
(__REVERSE | __BLINK | __DIM | __BOLD | __BLANK | __PROTECT) |
(__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 __winlist { |
struct __window *winp; /* The window. */ |
struct __window *winp; /* The window. */ |
Line 163 struct __screen { |
|
Line 216 struct __screen { |
|
WINDOW *stdscr; /* Standard screen. */ |
WINDOW *stdscr; /* Standard screen. */ |
WINDOW *__virtscr; /* Virtual screen (for doupdate()). */ |
WINDOW *__virtscr; /* Virtual screen (for doupdate()). */ |
int curwin; /* current window for refresh */ |
int curwin; /* current window for refresh */ |
short lx, ly; /* loop parameters for refresh */ |
int lx, ly; /* loop parameters for refresh */ |
int COLS; /* Columns on the screen. */ |
int COLS; /* Columns on the screen. */ |
int LINES; /* Lines on the screen. */ |
int LINES; /* Lines on the screen. */ |
int COLORS; /* Maximum colors on the screen */ |
int COLORS; /* Maximum colors on the screen */ |
Line 199 struct __screen { |
|
Line 252 struct __screen { |
|
*tc_SF, *tc_Sf, *tc_sf, *tc_so, *tc_sp, |
*tc_SF, *tc_Sf, *tc_sf, *tc_so, *tc_sp, |
*tc_SR, *tc_sr, *tc_ta, *tc_te, *tc_ti, |
*tc_SR, *tc_sr, *tc_ta, *tc_te, *tc_ti, |
*tc_uc, *tc_ue, *tc_UP, *tc_up, *tc_us, |
*tc_uc, *tc_ue, *tc_UP, *tc_up, *tc_us, |
|
#ifndef HAVE_WCHAR |
*tc_vb, *tc_ve, *tc_vi, *tc_vs; |
*tc_vb, *tc_ve, *tc_vi, *tc_vs; |
|
#else |
|
*tc_vb, *tc_ve, *tc_vi, *tc_vs, *tc_Xh, |
|
*tc_Xl, *tc_Xo, *tc_Xr, *tc_Xt, *tc_Xv; |
|
#endif /* HAVE_WCHAR */ |
char CA; |
char CA; |
int str_count; |
int str_count; |
chtype acs_char[NUM_ACS]; |
chtype acs_char[NUM_ACS]; |
|
#ifdef HAVE_WCHAR |
|
cchar_t wacs_char[ NUM_ACS ]; |
|
#endif /* HAVE_WCHAR */ |
struct __color colours[MAX_COLORS]; |
struct __color colours[MAX_COLORS]; |
struct __pair colour_pairs[MAX_PAIRS]; |
struct __pair colour_pairs[MAX_PAIRS]; |
attr_t nca; |
attr_t nca; |
Line 225 struct __screen { |
|
Line 286 struct __screen { |
|
int echoit; |
int echoit; |
int pfast; |
int pfast; |
int rawmode; |
int rawmode; |
|
int nl; |
int noqch; |
int noqch; |
int clearok; |
int clearok; |
int useraw; |
int useraw; |
Line 240 struct __screen { |
|
Line 302 struct __screen { |
|
char ttytype[128]; |
char ttytype[128]; |
int endwin; |
int endwin; |
int notty; |
int notty; |
|
int half_delay; |
|
int resized; |
|
#ifdef HAVE_WCHAR |
|
#define MB_LEN_MAX 8 |
|
#define MAX_CBUF_SIZE MB_LEN_MAX |
|
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 */ |
}; |
}; |
|
|
|
|
Line 250 extern int My_term; /* Use Def_term re |
|
Line 323 extern int My_term; /* Use Def_term re |
|
extern const char *Def_term; /* Default terminal type. */ |
extern const char *Def_term; /* Default terminal type. */ |
extern SCREEN *_cursesi_screen; /* The current screen in use */ |
extern SCREEN *_cursesi_screen; /* The current screen in use */ |
|
|
/* Private functions. */ |
/* Debugging options/functions. */ |
#ifdef DEBUG |
#ifdef DEBUG |
void __CTRACE(const char *, ...); |
#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_ALL 0x7fffffff |
|
void __CTRACE_init(void); |
|
void __CTRACE(int, const char *, ...) __attribute__((__format__(__printf__, 2, 3))); |
#endif |
#endif |
|
|
|
/* Private functions. */ |
void __cputchar_args(char, void *); |
void __cputchar_args(char, void *); |
void _cursesi_free_keymap(keymap_t *); |
void _cursesi_free_keymap(keymap_t *); |
int _cursesi_gettmode(SCREEN *); |
int _cursesi_gettmode(SCREEN *); |
void _cursesi_reset_acs(SCREEN *); |
void _cursesi_reset_acs(SCREEN *); |
|
int _cursesi_addbyte(WINDOW *, __LINE **, int *, int *, int , attr_t); |
|
int _cursesi_addwchar(WINDOW *, __LINE **, int *, int *, const cchar_t *); |
|
#ifdef HAVE_WCHAR |
|
void _cursesi_reset_wacs(SCREEN *); |
|
#endif /* HAVE_WCHAR */ |
void _cursesi_resetterm(SCREEN *); |
void _cursesi_resetterm(SCREEN *); |
int _cursesi_setterm(char *, SCREEN *); |
int _cursesi_setterm(char *, SCREEN *); |
int _cursesi_wnoutrefresh(SCREEN *, WINDOW *); |
|
int __delay(void); |
int __delay(void); |
u_int __hash_more(char *, size_t, u_int); |
u_int __hash_more(const void *, size_t, u_int); |
#define __hash(s, len) __hash_more((s), (len), 0u) |
#define __hash(s, len) __hash_more((s), (len), 0u) |
void __id_subwins(WINDOW *); |
void __id_subwins(WINDOW *); |
void __init_getch(SCREEN *); |
void __init_getch(SCREEN *); |
void __init_acs(SCREEN *); |
void __init_acs(SCREEN *); |
|
#ifdef HAVE_WCHAR |
|
void __init_get_wch(SCREEN *); |
|
void __init_wacs(SCREEN *); |
|
void __cputwchar_args( wchar_t, void * ); |
|
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); |
|
#endif /* HAVE_WCHAR */ |
char *__longname(char *, char *); /* Original BSD version */ |
char *__longname(char *, char *); /* Original BSD version */ |
int __mvcur(int, int, int, int, int); |
int __mvcur(int, int, int, int, int); |
WINDOW *__newwin(SCREEN *, int, int, int, int); |
WINDOW *__newwin(SCREEN *, int, int, int, int, int); |
int __nodelay(void); |
int __nodelay(void); |
int __notimeout(void); |
int __notimeout(void); |
char *__parse_cap(const char *, ...); |
char *__parse_cap(const char *, ...); |
Line 279 void __restore_cursor_vis(void); |
|
Line 381 void __restore_cursor_vis(void); |
|
void __restore_meta_state(void); |
void __restore_meta_state(void); |
void __restore_termios(void); |
void __restore_termios(void); |
void __restore_stophandler(void); |
void __restore_stophandler(void); |
|
void __restore_winchhandler(void); |
void __save_termios(void); |
void __save_termios(void); |
void __set_color(WINDOW *win, attr_t attr); |
void __set_color(WINDOW *win, attr_t attr); |
void __set_stophandler(void); |
void __set_stophandler(void); |
|
void __set_winchhandler(void); |
void __set_subwin(WINDOW *, WINDOW *); |
void __set_subwin(WINDOW *, WINDOW *); |
void __startwin(SCREEN *); |
void __startwin(SCREEN *); |
void __stop_signal_handler(int); |
void __stop_signal_handler(int); |
Line 295 void __unsetattr(int); |
|
Line 399 void __unsetattr(int); |
|
void __unset_color(WINDOW *win); |
void __unset_color(WINDOW *win); |
int __waddch(WINDOW *, __LDATA *); |
int __waddch(WINDOW *, __LDATA *); |
int __wgetnstr(WINDOW *, char *, int); |
int __wgetnstr(WINDOW *, char *, int); |
|
#ifdef HAVE_WCHAR |
|
int __wgetn_wstr(WINDOW *, wchar_t *, int); |
|
#endif /* HAVE_WCHAR */ |
|
void __winch_signal_handler(int); |
|
|
/* Private #defines. */ |
/* Private #defines. */ |
#define min(a,b) ((a) < (b) ? (a) : (b)) |
#define min(a,b) ((a) < (b) ? (a) : (b)) |
Line 306 extern int __endwin; |
|
Line 414 extern int __endwin; |
|
extern int __pfast; |
extern int __pfast; |
extern int __rawmode; |
extern int __rawmode; |
extern int __noqch; |
extern int __noqch; |
extern attr_t __nca; |
|
extern attr_t __mask_op, __mask_me, __mask_ue, __mask_se; |
extern attr_t __mask_op, __mask_me, __mask_ue, __mask_se; |
extern struct __winlist *__winlistp; |
|
extern WINDOW *__virtscr; |
extern WINDOW *__virtscr; |
extern int __using_color; |
extern int __using_color; |
extern attr_t __default_color; |
extern attr_t __default_color; |