/****************************************************************************
- * Copyright (c) 1998-2008,2009 Free Software Foundation, Inc. *
+ * Copyright (c) 1998-2009,2010 Free Software Foundation, Inc. *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
* copy of this software and associated documentation files (the *
/*
- * $Id: curses.priv.h,v 1.417 2009/05/23 23:01:44 tom Exp $
+ * $Id: curses.priv.h,v 1.452 2010/03/06 19:15:50 tom Exp $
*
* curses.priv.h
*
#define MODULE_ID(id) /*nothing*/
#endif
+#include <stddef.h> /* for offsetof */
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
extern NCURSES_EXPORT(void *) _nc_memmove (void *, const void *, size_t);
#endif
+/*
+ * If we have va_copy(), use it for assigning va_list's.
+ */
+#if defined(HAVE___VA_COPY)
+#define begin_va_copy(dst,src) __va_copy(dst, src)
+#define end_va_copy(dst) va_end(dst)
+#elif defined(va_copy) || defined(HAVE_VA_COPY)
+#define begin_va_copy(dst,src) va_copy(dst, src)
+#define end_va_copy(dst) va_end(dst)
+#else
+#define begin_va_copy(dst,src) (dst) = (src)
+#define end_va_copy(dst) /* nothing */
+#endif
+
/*
* Scroll hints are useless when hashmap is used
*/
/*
* Options for terminal drivers, etc...
*/
-#if 0
+#ifdef USE_TERM_DRIVER
#define USE_SP_RIPOFF 1
#define USE_SP_TERMTYPE 1
#define USE_SP_WINDOWLIST 1
-#define USE_TERM_DRIVER 1
#endif
/*
#endif
#else /* !(NCURSES_EXT_COLORS && USE_WIDEC_SUPPORT) */
+
#define if_EXT_COLORS(stmt) /* nothing */
#define SetPair(value,p) RemAttr(value, A_COLOR), \
SetAttr(value, AttrOf(value) | (A_COLOR & COLOR_PAIR(p)))
#define GET_SCREEN_PAIR(s) GetPair(SCREEN_ATTRS(s))
#define SET_SCREEN_PAIR(s,p) SetPair(SCREEN_ATTRS(s), p)
+#if USE_REENTRANT || NCURSES_SP_FUNCS
+NCURSES_EXPORT(int *) _nc_ptr_Lines (SCREEN *);
+NCURSES_EXPORT(int *) _nc_ptr_Cols (SCREEN *);
+NCURSES_EXPORT(int *) _nc_ptr_Tabsize (SCREEN *);
+NCURSES_EXPORT(int *) _nc_ptr_Escdelay (SCREEN *);
+#endif
+
#if USE_REENTRANT
-NCURSES_EXPORT(int *) _nc_ptr_Lines (void);
-NCURSES_EXPORT(int *) _nc_ptr_Cols (void);
+
#define ptrLines(sp) (sp ? &(sp->_LINES) : &(_nc_prescreen._LINES))
#define ptrCols(sp) (sp ? &(sp->_COLS) : &(_nc_prescreen._COLS))
-#define SET_LINES(value) *_nc_ptr_Lines() = value
-#define SET_COLS(value) *_nc_ptr_Cols() = value
+#define ptrTabsize(sp) (sp ? &(sp->_TABSIZE) : &(_nc_prescreen._TABSIZE))
+#define ptrEscdelay(sp) (sp ? &(sp->_ESCDELAY) : &(_nc_prescreen._ESCDELAY))
+
+#define SET_LINES(value) *_nc_ptr_Lines(SP_PARM) = value
+#define SET_COLS(value) *_nc_ptr_Cols(SP_PARM) = value
+#define SET_TABSIZE(value) *_nc_ptr_Tabsize(SP_PARM) = value
+#define SET_ESCDELAY(value) *_nc_ptr_Escdelay(SP_PARM) = value
+
#else
+
#define ptrLines(sp) &LINES
#define ptrCols(sp) &COLS
+#define ptrTabsize(sp) &TABSIZE
+#define ptrEscdelay(sp) &ESCDELAY
+
#define SET_LINES(value) LINES = value
#define SET_COLS(value) COLS = value
+#define SET_TABSIZE(value) TABSIZE = value
+#define SET_ESCDELAY(value) ESCDELAY = value
+
#endif
#define TR_MUTEX(data) _tracef("%s@%d: me:%08lX COUNT:%2u/%2d/%6d/%2d/%s%9u: " #data, \
#endif /* USE_PTHREADS */
+/*
+ * When using sp-funcs, locks are targeted to SCREEN-level granularity.
+ * So the locking is done in the non-sp-func (which calls the sp-func) rather
+ * than in the sp-func itself.
+ *
+ * Use the _nc_nonsp_XXX functions in the function using "NCURSES_SP_NAME()".
+ * Use the _nc_sp_XXX functions in the function using "#if NCURSES_SP_FUNCS".
+ */
+#if NCURSES_SP_FUNCS
+
+#define _nc_nonsp_lock_global(name) /* nothing */
+#define _nc_nonsp_try_global(name) 0
+#define _nc_nonsp_unlock_global(name) /* nothing */
+
+#define _nc_sp_lock_global(name) _nc_lock_global(name)
+#define _nc_sp_try_global(name) _nc_try_global(name)
+#define _nc_sp_unlock_global(name) _nc_unlock_global(name)
+
+#else
+
+#define _nc_nonsp_lock_global(name) _nc_lock_global(name)
+#define _nc_nonsp_try_global(name) _nc_try_global(name)
+#define _nc_nonsp_unlock_global(name) _nc_unlock_global(name)
+
+#define _nc_sp_lock_global(name) /* nothing */
+#define _nc_sp_try_global(name) 0
+#define _nc_sp_unlock_global(name) /* nothing */
+
+#endif
+
#if HAVE_GETTIMEOFDAY
# define PRECISE_GETTIME 1
# define TimeType struct timeval
#if USE_SYSMOUSE
,M_SYSMOUSE /* FreeBSD sysmouse on console */
#endif
+#ifdef USE_TERM_DRIVER
+ ,M_TERM_DRIVER /* Win32 console, etc */
+#endif
} MouseType;
/*
*/
#if MIXEDCASE_FILENAMES
#define LEAF_FMT "%c"
+#define LEAF_LEN 1
#else
#define LEAF_FMT "%02x"
+#define LEAF_LEN 2
#endif
/*
#define TRACEMSE_MAX (80 + (5 * 10) + (32 * 15))
#define TRACEMSE_FMT "id %2d at (%2d, %2d, %2d) state %4lx = {" /* } */
+#ifdef USE_TERM_DRIVER
+struct DriverTCB; /* Terminal Control Block forward declaration */
+#define INIT_TERM_DRIVER() _nc_globals.term_driver = _nc_get_driver
+#else
+#define INIT_TERM_DRIVER() /* nothing */
+#endif
+
/*
* Global data which is not specific to a screen.
*/
int safeprint_rows;
#endif
+#ifdef USE_TERM_DRIVER
+ int (*term_driver)(struct DriverTCB*, const char*, int*);
+#endif
+
#ifdef TRACE
bool init_trace;
char trace_fname[PATH_MAX];
#if NCURSES_NO_PADDING
bool _no_padding; /* flag to set if padding disabled */
#endif
+ NCURSES_SP_OUTC _outch; /* output handler if not putc */
#if BROKEN_LINKER || USE_REENTRANT
chtype *real_acs_map;
int _LINES;
int _COLS;
+ int _TABSIZE;
+ int _ESCDELAY;
TERMINAL *_cur_term;
#ifdef TRACE
long _outchars;
*/
bool _nc_sp_idlok;
bool _nc_sp_idcok;
-#define _nc_idlok SP->_nc_sp_idlok
-#define _nc_idcok SP->_nc_sp_idcok
/*
* These are the data that support the mouse interface.
int _sysmouse_new_buttons;
#endif
+#ifdef USE_TERM_DRIVER
+ MEVENT _drv_mouse_fifo[FIFO_SIZE];
+ int _drv_mouse_head;
+ int _drv_mouse_tail;
+ int _drv_mouse_old_buttons;
+ int _drv_mouse_new_buttons;
+#endif
/*
* This supports automatic resizing
*/
#if USE_SIZECHANGE
- int (*_resize)(int,int);
+ int (*_resize)(NCURSES_SP_DCLx int y, int x);
#endif
/*
extern NCURSES_EXPORT_VAR(SIG_ATOMIC_T) _nc_have_sigwinch;
WINDOWLIST {
- WINDOW win; /* first, so WINDOW_EXT() works */
WINDOWLIST *next;
SCREEN *screen; /* screen containing the window */
+ WINDOW win; /* WINDOW_EXT() needs to account for offset */
#ifdef _XOPEN_SOURCE_EXTENDED
char addch_work[(MB_LEN_MAX * 9) + 1];
unsigned addch_used; /* number of bytes in addch_work[] */
#endif
};
-#define WINDOW_EXT(win,field) (((WINDOWLIST *)(win))->field)
+#define WINDOW_EXT(w,m) (((WINDOWLIST *)((char *)(w) - offsetof(WINDOWLIST, win)))->m)
#define SP_PRE_INIT(sp) \
sp->_cursrow = -1; \
putc(PUTC_ch,b); \
break; \
} \
- fwrite(PUTC_buf, (unsigned) PUTC_n, 1, b); \
+ IGNORE_RC(fwrite(PUTC_buf, (unsigned) PUTC_n, 1, b)); \
} \
COUNT_OUTCHARS(PUTC_i); \
} } } while (0)
#define T(a) TR(TRACE_CALLS, a)
#define TRACE_RETURN(value,type) return _nc_retrace_##type(value)
+#define NonNull(s) ((s) != 0 ? s : "<null>")
+
#define returnAttr(code) TRACE_RETURN(code,attr_t)
#define returnBits(code) TRACE_RETURN(code,unsigned)
#define returnBool(code) TRACE_RETURN(code,bool)
#define returnCPtr(code) TRACE_RETURN(code,cptr)
#define returnCVoidPtr(code) TRACE_RETURN(code,cvoid_ptr)
+#define returnChar(code) TRACE_RETURN(code,char)
#define returnChtype(code) TRACE_RETURN(code,chtype)
#define returnCode(code) TRACE_RETURN(code,int)
#define returnPtr(code) TRACE_RETURN(code,ptr)
extern NCURSES_EXPORT(chtype) _nc_retrace_chtype (chtype);
extern NCURSES_EXPORT(const char *) _nc_altcharset_name(attr_t, chtype);
extern NCURSES_EXPORT(const char *) _nc_retrace_cptr (const char *);
+extern NCURSES_EXPORT(char) _nc_retrace_char (char);
extern NCURSES_EXPORT(int) _nc_retrace_int (int);
extern NCURSES_EXPORT(unsigned) _nc_retrace_unsigned (unsigned);
extern NCURSES_EXPORT(void *) _nc_retrace_void_ptr (void *);
#define returnBool(code) return code
#define returnCPtr(code) return code
#define returnCVoidPtr(code) return code
+#define returnChar(code) return ((char) code)
#define returnChtype(code) return code
#define returnCode(code) return code
#define returnPtr(code) return code
#endif /* TRACE/!TRACE */
+/*
+ * Workaround for defective implementation of gcc attribute warn_unused_result
+ */
+#if defined(__GNUC__) && defined(_FORTIFY_SOURCE)
+#define IGNORE_RC(func) errno = func
+#else
+#define IGNORE_RC(func) (void) func
+#endif /* gcc workarounds */
+
/*
* Return-codes for tgetent() and friends.
*/
extern NCURSES_EXPORT(void) _nc_toggle_attr_off (attr_t *, attr_t);
#undef DelCharCost
-#define DelCharCost(count) _nc_DelCharCost(count)
-extern NCURSES_EXPORT(int) _nc_DelCharCost (int);
+#define DelCharCost(sp, count) NCURSES_SP_NAME(_nc_DelCharCost)(NCURSES_SP_ARGx count)
#undef InsCharCost
-#define InsCharCost(count) _nc_InsCharCost(count)
-extern NCURSES_EXPORT(int) _nc_InsCharCost (int);
+#define InsCharCost(sp, count) NCURSES_SP_NAME(_nc_InsCharCost)(NCURSES_SP_ARGx count)
+
+extern NCURSES_EXPORT(int) NCURSES_SP_NAME(_nc_DelCharCost) (NCURSES_SP_DCLx int _c);
+extern NCURSES_EXPORT(int) NCURSES_SP_NAME(_nc_InsCharCost) (NCURSES_SP_DCLx int _c);
#undef UpdateAttrs
-#define UpdateAttrs(c) _nc_UpdateAttrs(c)
-extern NCURSES_EXPORT(void) _nc_UpdateAttrs (NCURSES_CH_T);
+#define UpdateAttrs(sp,c) NCURSES_SP_NAME(_nc_UpdateAttrs)(NCURSES_SP_ARGx CHREF(c))
+
+#if defined(NEED_NCURSES_CH_T)
+extern NCURSES_EXPORT(void) NCURSES_SP_NAME(_nc_UpdateAttrs) (NCURSES_SP_DCLx CARG_CH_T _c);
+#else
+extern NCURSES_EXPORT(void) NCURSES_SP_NAME(_nc_UpdateAttrs) (NCURSES_SP_DCLx chtype c);
+#endif
+
+#if NCURSES_SP_FUNCS
+extern NCURSES_EXPORT(int) _nc_DelCharCost (int);
+extern NCURSES_EXPORT(int) _nc_InsCharCost (int);
+extern NCURSES_EXPORT(void) _nc_UpdateAttrs (CARG_CH_T);
+#endif /* NCURSES_SP_FUNCS */
#else
extern NCURSES_EXPORT(int) _nc_wgetch(WINDOW *, unsigned long *, int EVENTLIST_2nd(_nc_eventlist *));
/* lib_insch.c */
-extern NCURSES_EXPORT(int) _nc_insert_ch(WINDOW *, chtype);
+extern NCURSES_EXPORT(int) _nc_insert_ch(SCREEN *, WINDOW *, chtype);
/* lib_mvcur.c */
#define INFINITY 1000000 /* cost: too high to use */
extern NCURSES_EXPORT(int) _nc_unicode_locale(void);
extern NCURSES_EXPORT(int) _nc_locale_breaks_acs(TERMINAL *);
extern NCURSES_EXPORT(int) _nc_setupterm(NCURSES_CONST char *, int, int *, bool);
-extern NCURSES_EXPORT(void) _nc_get_screensize(SCREEN *, int *, int *);
+extern NCURSES_EXPORT(void) _nc_tinfo_cmdch(TERMINAL *, char);
+
+/* lib_set_term.c */
+extern NCURSES_EXPORT(int) _nc_ripoffline(int, int(*)(WINDOW*, int));
/* lib_tstp.c */
#if USE_SIGWINCH
/* elsewhere ... */
extern NCURSES_EXPORT(ENTRY *) _nc_delink_entry (ENTRY *, TERMTYPE *);
extern NCURSES_EXPORT(SCREEN *) _nc_screen_of (WINDOW *);
+extern NCURSES_EXPORT(TERMINAL*) _nc_get_cur_term (void);
extern NCURSES_EXPORT(WINDOW *) _nc_makenew (int, int, int, int, int);
extern NCURSES_EXPORT(char *) _nc_trace_buf (int, size_t);
extern NCURSES_EXPORT(char *) _nc_trace_bufcat (int, const char *);
extern NCURSES_EXPORT(void) _nc_scroll_window (WINDOW *, int const, NCURSES_SIZE_T const, NCURSES_SIZE_T const, NCURSES_CH_T);
#endif
+#if USE_WIDEC_SUPPORT
+extern NCURSES_EXPORT(int) _nc_insert_wch(WINDOW *, const cchar_t *);
+#endif
+
#if USE_WIDEC_SUPPORT && !defined(USE_TERMLIB)
extern NCURSES_EXPORT(size_t) _nc_wcrtomb (char *, wchar_t, mbstate_t *);
#endif
#define wgetnstr_events(win, str, maxlen, evl) wgetnstr(win, str, maxlen)
#endif
+/*
+ * Wide-character macros to hide some platform-differences.
+ */
+#if USE_WIDEC_SUPPORT
+#if HAVE_MBTOWC && HAVE_MBLEN
+#define reset_mbytes(state) IGNORE_RC(mblen(NULL, 0)), IGNORE_RC(mbtowc(NULL, NULL, 0))
+#define count_mbytes(buffer,length,state) mblen(buffer,length)
+#define check_mbytes(wch,buffer,length,state) \
+ (int) mbtowc(&wch, buffer, length)
+#define state_unused
+#elif HAVE_MBRTOWC && HAVE_MBRLEN
+#define reset_mbytes(state) init_mb(state)
+#define count_mbytes(buffer,length,state) mbrlen(buffer,length,&state)
+#define check_mbytes(wch,buffer,length,state) \
+ (int) mbrtowc(&wch, buffer, length, &state)
+#else
+make an error
+#endif
+#endif
+
/*
* Not everyone has vsscanf(), but we'd like to use it for scanw().
*/
* On systems with a broken linker, define 'SP' as a function to force the
* linker to pull in the data-only module with 'SP'.
*/
+#define _nc_alloc_screen_sp() typeCalloc(SCREEN, 1)
+
#if BROKEN_LINKER
-#define SP _nc_screen()
extern NCURSES_EXPORT(SCREEN *) _nc_screen (void);
extern NCURSES_EXPORT(int) _nc_alloc_screen (void);
extern NCURSES_EXPORT(void) _nc_set_screen (SCREEN *);
/* current screen is private data; avoid possible linking conflicts too */
extern NCURSES_EXPORT_VAR(SCREEN *) SP;
#define CURRENT_SCREEN SP
-#define _nc_alloc_screen() ((SP = typeCalloc(SCREEN, 1)) != 0)
+#define _nc_alloc_screen() ((SP = _nc_alloc_screen_sp()) != 0)
#define _nc_set_screen(sp) SP = sp
#endif
-#if NCURSES_SP_FUNCS && 0
+#if NCURSES_SP_FUNCS
#define CURRENT_SCREEN_PRE (IsPreScreen(CURRENT_SCREEN) ? CURRENT_SCREEN : new_prescr())
#else
#define CURRENT_SCREEN_PRE CURRENT_SCREEN
#define screen_columns(sp) (sp)->_columns
extern NCURSES_EXPORT(int) _nc_slk_initialize (WINDOW *, int);
-extern NCURSES_EXPORT(int) _nc_format_slks (SCREEN *, int);
+extern NCURSES_EXPORT(int) _nc_format_slks (NCURSES_SP_DCLx int _c);
/*
* Some constants related to SLK's
#define MAX_SKEY(fmt) (SLK_STDFMT(fmt)? MAX_SKEY_OLD : MAX_SKEY_PC)
#define MAX_SKEY_LEN(fmt) (SLK_STDFMT(fmt)? MAX_SKEY_LEN_OLD : MAX_SKEY_LEN_PC)
-extern NCURSES_EXPORT(int) _nc_ripoffline (int line, int (*init)(WINDOW *,int));
-
/*
* Common error messages
*/
}\
sp->jump = outc
-struct DriverTCB; /* Terminal Control Block forward declaration */
+#ifdef USE_TERM_DRIVER
typedef void* TERM_HANDLE;
typedef struct _termInfo
bool (*kyExist)(struct DriverTCB*, int);
} TERM_DRIVER;
-
typedef struct DriverTCB
{
TERMINAL term; /* needs to be the first Element !!! */
extern NCURSES_EXPORT_VAR(const color_t*) _nc_cga_palette;
extern NCURSES_EXPORT_VAR(const color_t*) _nc_hls_palette;
-#ifdef USE_TERM_DRIVER
-extern NCURSES_EXPORT(int) _nc_tinfo_has_key(SCREEN*, int);
-extern NCURSES_EXPORT(int) _nc_tinfo_doupdate(SCREEN *sp);
-extern NCURSES_EXPORT(int) _nc_tinfo_mvcur(SCREEN*,int,int,int,int);
extern NCURSES_EXPORT(int) _nc_get_driver(TERMINAL_CONTROL_BLOCK*, const char*, int*);
+extern NCURSES_EXPORT(void) _nc_get_screensize_ex(SCREEN *, TERMINAL *, int *, int *);
+#endif /* USE_TERM_DRIVER */
+
+/*
+ * Entrypoints which are actually provided in the terminal driver, which would
+ * be an sp-name otherwise.
+ */
+#ifdef USE_TERM_DRIVER
+#define TINFO_HAS_KEY _nc_tinfo_has_key
+#define TINFO_DOUPDATE _nc_tinfo_doupdate
+#define TINFO_MVCUR _nc_tinfo_mvcur
+extern NCURSES_EXPORT(int) TINFO_HAS_KEY(SCREEN*, int);
+extern NCURSES_EXPORT(int) TINFO_DOUPDATE(SCREEN *);
+extern NCURSES_EXPORT(int) TINFO_MVCUR(SCREEN*, int, int, int, int);
+#else
+#define TINFO_HAS_KEY NCURSES_SP_NAME(has_key)
+#define TINFO_DOUPDATE NCURSES_SP_NAME(doupdate)
+#define TINFO_MVCUR NCURSES_SP_NAME(mvcur)
#endif
+/*
+ * Entrypoints using an extra parameter with the terminal driver.
+ */
+#ifdef USE_TERM_DRIVER
+extern NCURSES_EXPORT(void) _nc_get_screensize(SCREEN *, TERMINAL *, int *, int *);
+extern NCURSES_EXPORT(int) _nc_setupterm_ex(TERMINAL **, NCURSES_CONST char *, int , int *, bool);
+#define TINFO_GET_SIZE(sp, tp, lp, cp) \
+ _nc_get_screensize(sp, tp, lp, cp)
+#define TINFO_SET_CURTERM(sp, tp) \
+ NCURSES_SP_NAME(set_curterm)(sp, tp)
+#define TINFO_SETUP_TERM(tpp, name, fd, err, reuse) \
+ _nc_setupterm_ex(tpp, name, fd, err, reuse)
+#else /* !USE_TERM_DRIVER */
+extern NCURSES_EXPORT(void) _nc_get_screensize(SCREEN *, int *, int *);
+#define TINFO_GET_SIZE(sp, tp, lp, cp) \
+ _nc_get_screensize(sp, lp, cp)
+#define TINFO_SET_CURTERM(sp, tp) \
+ set_curterm(tp)
+#define TINFO_SETUP_TERM(tpp, name, fd, err, reuse) \
+ _nc_setupterm(name, fd, err, reuse)
+#endif /* !USE_TERM_DRIVER */
+
+#ifdef USE_TERM_DRIVER
#ifdef __MINGW32__
#include <nc_mingw.h>
extern NCURSES_EXPORT_VAR(TERM_DRIVER) _nc_WIN_DRIVER;
#endif
extern NCURSES_EXPORT_VAR(TERM_DRIVER) _nc_TINFO_DRIVER;
+#endif
#ifdef USE_TERM_DRIVER
#define IsTermInfo(sp) (TCBOf(sp) && ((TCBOf(sp)->drv->isTerminfo)))
extern NCURSES_EXPORT(int) _nc_outc_wrapper(SCREEN*,int);
#if USE_REENTRANT
-extern NCURSES_EXPORT(char *) NCURSES_SP_NAME(_nc_ttytype)(SCREEN*);
extern NCURSES_EXPORT(int) NCURSES_SP_NAME(_nc_TABSIZE)(SCREEN*);
extern NCURSES_EXPORT(char *) NCURSES_SP_NAME(longname)(SCREEN*);
#endif
* We put the safe versions of various calls here as they are not published
* part of the API up to now
*/
-extern NCURSES_EXPORT(SCREEN*) _nc_SP(void);
-
-extern NCURSES_EXPORT(TERMINAL*) NCURSES_SP_NAME(_nc_set_curterm)(SCREEN*,TERMINAL*);
-extern NCURSES_EXPORT(TERMINAL*) NCURSES_SP_NAME(cur_term)(SCREEN *sp);
+extern NCURSES_EXPORT(TERMINAL*) NCURSES_SP_NAME(_nc_get_cur_term) (SCREEN *sp);
extern NCURSES_EXPORT(WINDOW *) NCURSES_SP_NAME(_nc_makenew) (SCREEN*, int, int, int, int, int);
extern NCURSES_EXPORT(bool) NCURSES_SP_NAME(_nc_reset_colors)(SCREEN*);
extern NCURSES_EXPORT(char *) NCURSES_SP_NAME(_nc_printf_string)(SCREEN*, const char *, va_list);