]> ncurses.scripts.mit.edu Git - ncurses.git/blobdiff - ncurses/curses.priv.h
ncurses 5.9 - patch 20110917
[ncurses.git] / ncurses / curses.priv.h
index dcc2b9fbd5d367200c923a52304096b535c893a1..309c3e82a3fd75238376e0d26df8cf42fb8efc77 100644 (file)
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 1998-2009,2010 Free Software Foundation, Inc.              *
+ * Copyright (c) 1998-2010,2011 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            *
@@ -33,9 +33,8 @@
  *     and: Juergen Pfeifer                                                 *
  ****************************************************************************/
 
-
 /*
- * $Id: curses.priv.h,v 1.459 2010/04/24 23:21:58 tom Exp $
+ * $Id: curses.priv.h,v 1.483 2011/09/17 19:08:20 tom Exp $
  *
  *     curses.priv.h
  *
@@ -46,6 +45,7 @@
 
 #ifndef CURSES_PRIV_H
 #define CURSES_PRIV_H 1
+/* *INDENT-OFF* */
 
 #include <ncurses_dll.h>
 
@@ -61,10 +61,15 @@ extern "C" {
 #define MODULE_ID(id) /*nothing*/
 #endif
 
+#if !(defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) || defined(_XOPEN_SOURCE))
+#define _POSIX_SOURCE
+#endif
+
 #include <stddef.h>            /* for offsetof */
 #include <stdlib.h>
 #include <string.h>
 #include <sys/types.h>
+#include <sys/stat.h>
 
 #if HAVE_UNISTD_H
 #include <unistd.h>
@@ -191,6 +196,18 @@ extern NCURSES_EXPORT(void *) _nc_memmove (void *, const void *, size_t);
 #define end_va_copy(dst)       /* nothing */
 #endif
 
+/*
+ * Either/both S_ISxxx and/or S_IFxxx are defined in sys/types.h; some systems
+ * lack one or the other.
+ */
+#ifndef S_ISDIR
+#define S_ISDIR(mode) ((mode & S_IFMT) == S_IFDIR)
+#endif
+
+#ifndef S_ISREG
+#define S_ISREG(mode) ((mode & S_IFMT) == S_IFREG)
+#endif
+
 /*
  * Scroll hints are useless when hashmap is used
  */
@@ -325,6 +342,7 @@ color_t;
 #endif
 
 #include <term.h>
+#include <nc_termios.h>
 
 /*
  * Reduce dependency on cur_term global by using terminfo data from SCREEN's
@@ -346,7 +364,7 @@ color_t;
  */
 #if 1
 #define ColorPair(n)           NCURSES_BITS(n, 0)
-#define PairNumber(a)          (NCURSES_CAST(int,(((a) & A_COLOR) >> NCURSES_ATTR_SHIFT)))
+#define PairNumber(a)          (NCURSES_CAST(int,(((unsigned long)(a) & A_COLOR) >> NCURSES_ATTR_SHIFT)))
 #else
 #define ColorPair(pair)                COLOR_PAIR(pair)
 #define PairNumber(attr)       PAIR_NUMBER(attr)
@@ -383,11 +401,11 @@ color_t;
 
 #define if_EXT_COLORS(stmt)    /* nothing */
 #define SetPair(value,p)       RemAttr(value, A_COLOR), \
-                               SetAttr(value, AttrOf(value) | (A_COLOR & ColorPair(p)))
+                               SetAttr(value, AttrOf(value) | (A_COLOR & (attr_t) ColorPair(p)))
 #define GetPair(value)         PairNumber(AttrOf(value))
 #define GET_WINDOW_PAIR(w)     PairNumber(WINDOW_ATTRS(w))
 #define SET_WINDOW_PAIR(w,p)   WINDOW_ATTRS(w) &= ALL_BUT_COLOR, \
-                               WINDOW_ATTRS(w) |= (A_COLOR & ColorPair(p))
+                               WINDOW_ATTRS(w) |= (A_COLOR & (attr_t) ColorPair(p))
 #define SameAttrOf(a,b)                (AttrOf(a) == AttrOf(b))
 
 #if NCURSES_SP_FUNCS
@@ -457,6 +475,19 @@ NCURSES_EXPORT(int *)        _nc_ptr_Escdelay (SCREEN *);
            data.__data.__nusers)
 #define TR_GLOBAL_MUTEX(name) TR_MUTEX(_nc_globals.mutex_##name)
 
+#if USE_WEAK_SYMBOLS
+#if defined(__GNUC__)
+#  if defined __USE_ISOC99
+#    define _cat_pragma(exp)   _Pragma(#exp)
+#    define _weak_pragma(exp)  _cat_pragma(weak name)
+#  else
+#    define _weak_pragma(exp)
+#  endif
+#  define _declare(name)       __extension__ extern __typeof__(name) name
+#  define weak_symbol(name)    _weak_pragma(name) _declare(name) __attribute__((weak))
+#endif
+#endif
+
 #ifdef USE_PTHREADS
 
 #if USE_REENTRANT
@@ -474,22 +505,10 @@ extern NCURSES_EXPORT(int) _nc_mutex_unlock(pthread_mutex_t *);
 #error POSIX threads requires --enable-reentrant option
 #endif
 
-#if USE_WEAK_SYMBOLS
-#if defined(__GNUC__)
-#  if defined __USE_ISOC99
-#    define _cat_pragma(exp)   _Pragma(#exp)
-#    define _weak_pragma(exp)  _cat_pragma(weak name)
-#  else
-#    define _weak_pragma(exp)
-#  endif
-#  define _declare(name)       __extension__ extern __typeof__(name) name
-#  define weak_symbol(name)    _weak_pragma(name) _declare(name) __attribute__((weak))
-#endif
-#endif
-
 #ifdef USE_PTHREADS
 #  if USE_WEAK_SYMBOLS
 weak_symbol(pthread_sigmask);
+weak_symbol(pthread_kill);
 weak_symbol(pthread_self);
 weak_symbol(pthread_equal);
 weak_symbol(pthread_mutex_init);
@@ -511,6 +530,19 @@ extern NCURSES_EXPORT(int) _nc_sigprocmask(int, const sigset_t *, sigset_t *);
 
 #else /* !USE_PTHREADS */
 
+#if USE_PTHREADS_EINTR
+#  if USE_WEAK_SYMBOLS
+#include <pthread.h>
+weak_symbol(pthread_sigmask);
+weak_symbol(pthread_kill);
+weak_symbol(pthread_self);
+weak_symbol(pthread_equal);
+extern NCURSES_EXPORT(int) _nc_sigprocmask(int, const sigset_t *, sigset_t *);
+#    undef  sigprocmask
+#    define sigprocmask _nc_sigprocmask
+#  endif
+#endif /* USE_PTHREADS_EINTR */
+
 #define _nc_init_pthreads()    /* nothing */
 #define _nc_mutex_init(obj)    /* nothing */
 
@@ -762,7 +794,7 @@ typedef struct {
        bool            init_signals;
        bool            init_screen;
 
-       const char      *comp_sourcename;
+       char            *comp_sourcename;
        char            *comp_termtype;
 
        bool            have_tic_directory;
@@ -838,6 +870,9 @@ typedef struct {
        int             use_pthreads;
 #define _nc_use_pthreads       _nc_globals.use_pthreads
 #endif
+#if USE_PTHREADS_EINTR
+       pthread_t       read_thread;            /* The reading thread */
+#endif
 } NCURSES_GLOBALS;
 
 extern NCURSES_EXPORT_VAR(NCURSES_GLOBALS) _nc_globals;
@@ -998,6 +1033,7 @@ struct screen {
        int             _pair_count;    /* count of color pairs              */
        int             _pair_limit;    /* actual limit of color-pairs       */
 #if NCURSES_EXT_FUNCS
+       bool            _assumed_color; /* use assumed colors                */
        bool            _default_color; /* use default colors                */
        bool            _has_sgr_39_49; /* has ECMA default color support    */
        int             _default_fg;    /* assumed default foreground        */
@@ -1039,6 +1075,7 @@ struct screen {
        int             _mouse_fd;      /* file-descriptor, if any */
        bool            _mouse_active;  /* true if initialized */
        mmask_t         _mouse_mask;
+       mmask_t         _mouse_bstate;
        NCURSES_CONST char *_mouse_xtermcap; /* string to enable/disable mouse */
        MEVENT          _mouse_events[EV_MAX];  /* hold the last mouse event seen */
        MEVENT          *_mouse_eventp; /* next free slot in event queue */
@@ -1159,7 +1196,7 @@ extern NCURSES_EXPORT_VAR(SIG_ATOMIC_T) _nc_have_sigwinch;
 #endif
 };
 
-#define WINDOW_EXT(w,m) (((WINDOWLIST *)((char *)(w) - offsetof(WINDOWLIST, win)))->m)
+#define WINDOW_EXT(w,m) (((WINDOWLIST *)((void *)((char *)(w) - offsetof(WINDOWLIST, win))))->m)
 
 #define SP_PRE_INIT(sp)                         \
     sp->_cursrow = -1;                          \
@@ -1294,7 +1331,7 @@ extern NCURSES_EXPORT_VAR(SIG_ATOMIC_T) _nc_have_sigwinch;
 #define SetChar(ch,c,a) do {                                                       \
                            NCURSES_CH_T *_cp = &ch;                                \
                            memset(_cp, 0, sizeof(ch));                             \
-                           _cp->chars[0] = (c);                                            \
+                           _cp->chars[0] = (wchar_t) (c);                          \
                            _cp->attr = (a);                                        \
                            if_EXT_COLORS(SetPair(ch, PairNumber(a)));              \
                        } while (0)
@@ -1315,8 +1352,8 @@ extern NCURSES_EXPORT_VAR(SIG_ATOMIC_T) _nc_have_sigwinch;
                                PUTC_ch = (ch).chars[PUTC_i];                       \
                                if (PUTC_ch == L'\0')                               \
                                    break;                                          \
-                               PUTC_n = wcrtomb(PUTC_buf,                          \
-                                                (ch).chars[PUTC_i], &PUT_st);      \
+                               PUTC_n = (int) wcrtomb(PUTC_buf,                    \
+                                                      (ch).chars[PUTC_i], &PUT_st); \
                                if (PUTC_n <= 0) {                                  \
                                    if (PUTC_ch && is8bits(PUTC_ch) && PUTC_i == 0) \
                                        putc(PUTC_ch,b);                            \
@@ -1338,7 +1375,7 @@ extern NCURSES_EXPORT_VAR(SIG_ATOMIC_T) _nc_have_sigwinch;
         * zero.  Otherwise we can use those bits to tell if a cell is the
         * first or extension part of a wide character.
         */
-#define WidecExt(ch)   (AttrOf(ch) & A_CHARTEXT)
+#define WidecExt(ch)   (int) (AttrOf(ch) & A_CHARTEXT)
 #define isWidecBase(ch)        (WidecExt(ch) == 1)
 #define isWidecExt(ch) (WidecExt(ch) > 1 && WidecExt(ch) < 32)
 #define SetWidecExt(dst, ext)  AttrOf(dst) &= ~A_CHARTEXT,             \
@@ -1395,25 +1432,25 @@ extern NCURSES_EXPORT_VAR(SIG_ATOMIC_T) _nc_have_sigwinch;
 
 #define CHANGED_CELL(line,col) \
        if (line->firstchar == _NOCHANGE) \
-               line->firstchar = line->lastchar = (NCURSES_SIZE_T) col; \
+               line->firstchar = line->lastchar = (NCURSES_SIZE_T) (col); \
        else if ((col) < line->firstchar) \
-               line->firstchar = (NCURSES_SIZE_T) col; \
+               line->firstchar = (NCURSES_SIZE_T) (col); \
        else if ((col) > line->lastchar) \
-               line->lastchar = (NCURSES_SIZE_T) col
+               line->lastchar = (NCURSES_SIZE_T) (col)
 
 #define CHANGED_RANGE(line,start,end) \
        if (line->firstchar == _NOCHANGE \
         || line->firstchar > (start)) \
-               line->firstchar = start; \
+               line->firstchar = (NCURSES_SIZE_T) (start); \
        if (line->lastchar == _NOCHANGE \
         || line->lastchar < (end)) \
-               line->lastchar = end
+               line->lastchar = (NCURSES_SIZE_T) (end)
 
 #define CHANGED_TO_EOL(line,start,end) \
        if (line->firstchar == _NOCHANGE \
         || line->firstchar > (start)) \
-               line->firstchar = start; \
-       line->lastchar = end
+               line->firstchar = (NCURSES_SIZE_T) (start); \
+       line->lastchar = (NCURSES_SIZE_T) (end)
 
 #define SIZEOF(v) (sizeof(v)/sizeof(v[0]))
 
@@ -1489,7 +1526,9 @@ extern NCURSES_EXPORT(void)       _nc_locked_tracef (const char *, ...) GCC_PRINTFLIKE
 
 #define TR(n, a)       if (USE_TRACEF(n)) _nc_locked_tracef a
 #define T(a)           TR(TRACE_CALLS, a)
-#define TRACE_RETURN(value,type) return _nc_retrace_##type(value)
+#define TRACE_RETURN(value,type)     return _nc_retrace_##type(value)
+#define TRACE_RETURN2(value,dst,src) return _nc_retrace_##dst##_##src(value)
+#define TRACE_RETURN_SP(value,type)  return _nc_retrace_##type(SP_PARM, value)
 
 #define NonNull(s)     ((s) != 0 ? s : "<null>")
 
@@ -1501,6 +1540,8 @@ extern NCURSES_EXPORT(void)       _nc_locked_tracef (const char *, ...) GCC_PRINTFLIKE
 #define returnChar(code)       TRACE_RETURN(code,char)
 #define returnChtype(code)     TRACE_RETURN(code,chtype)
 #define returnCode(code)       TRACE_RETURN(code,int)
+#define returnIntAttr(code)    TRACE_RETURN2(code,int,attr_t)
+#define returnMMask(code)      TRACE_RETURN_SP(code,mmask_t)
 #define returnPtr(code)                TRACE_RETURN(code,ptr)
 #define returnSP(code)         TRACE_RETURN(code,sp)
 #define returnVoid             T((T_RETURN(""))); return
@@ -1520,6 +1561,8 @@ 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(int)              _nc_retrace_int_attr_t (attr_t);
+extern NCURSES_EXPORT(mmask_t)          _nc_retrace_mmask_t (SCREEN *, mmask_t);
 extern NCURSES_EXPORT(unsigned)         _nc_retrace_unsigned (unsigned);
 extern NCURSES_EXPORT(void *)           _nc_retrace_void_ptr (void *);
 extern NCURSES_EXPORT(void)             _nc_fifo_dump (SCREEN *);
@@ -1562,6 +1605,8 @@ extern NCURSES_EXPORT(const char *) _nc_viscbuf (const NCURSES_CH_T *, int);
 #define returnChar(code)       return ((char) code)
 #define returnChtype(code)     return code
 #define returnCode(code)       return code
+#define returnIntAttr(code)    return code
+#define returnMMask(code)      return code
 #define returnPtr(code)                return code
 #define returnSP(code)         return code
 #define returnVoid             return
@@ -1574,7 +1619,7 @@ extern NCURSES_EXPORT(const char *) _nc_viscbuf (const NCURSES_CH_T *, int);
  * Workaround for defective implementation of gcc attribute warn_unused_result
  */
 #if defined(__GNUC__) && defined(_FORTIFY_SOURCE)
-#define IGNORE_RC(func) errno = func
+#define IGNORE_RC(func) errno = (int) func
 #else
 #define IGNORE_RC(func) (void) func
 #endif /* gcc workarounds */
@@ -1599,9 +1644,9 @@ extern    NCURSES_EXPORT(void) name (void); \
 
 #define toggle_attr_on(S,at) {\
    if (PairNumber(at) > 0) {\
-      (S) = ((S) & ALL_BUT_COLOR) | (at);\
+      (S) = ((S) & ALL_BUT_COLOR) | (attr_t) (at);\
    } else {\
-      (S) |= (at);\
+      (S) |= (attr_t) (at);\
    }\
    TR(TRACE_ATTRS, ("new attribute is %s", _traceattr((S))));}
 
@@ -1686,7 +1731,7 @@ extern NCURSES_EXPORT(int) NCURSES_SP_NAME(_nc_InsCharCost) (NCURSES_SP_DCLx int
 #undef  UpdateAttrs
 #define UpdateAttrs(sp,c) NCURSES_SP_NAME(_nc_UpdateAttrs)(NCURSES_SP_ARGx CHREF(c))
 
-#if defined(NEED_NCURSES_CH_T)
+#if USE_WIDEC_SUPPORT || 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);
@@ -1762,7 +1807,7 @@ extern NCURSES_EXPORT(int) _nc_wchstrlen(const cchar_t *);
 extern NCURSES_EXPORT(bool) _nc_reset_colors(void);
 
 /* lib_getch.c */
-extern NCURSES_EXPORT(int) _nc_wgetch(WINDOW *, unsigned long *, int EVENTLIST_2nd(_nc_eventlist *));
+extern NCURSES_EXPORT(int) _nc_wgetch(WINDOW *, int *, int EVENTLIST_2nd(_nc_eventlist *));
 
 /* lib_insch.c */
 extern NCURSES_EXPORT(int) _nc_insert_ch(SCREEN *, WINDOW *, chtype);
@@ -1797,6 +1842,25 @@ extern NCURSES_EXPORT(void)   _nc_tinfo_cmdch(TERMINAL *, char);
 /* lib_set_term.c */
 extern NCURSES_EXPORT(int)    _nc_ripoffline(int, int(*)(WINDOW*, int));
 
+/* lib_setup.c */
+#define ret_error(code, fmt, arg)      if (errret) {\
+                                           *errret = code;\
+                                           returnCode(ERR);\
+                                       } else {\
+                                           fprintf(stderr, fmt, arg);\
+                                           exit(EXIT_FAILURE);\
+                                       }
+
+#define ret_error1(code, fmt, arg)     ret_error(code, "'%s': " fmt, arg)
+
+#define ret_error0(code, msg)          if (errret) {\
+                                           *errret = code;\
+                                           returnCode(ERR);\
+                                       } else {\
+                                           fprintf(stderr, msg);\
+                                           exit(EXIT_FAILURE);\
+                                       }
+
 /* lib_tstp.c */
 #if USE_SIGWINCH
 extern NCURSES_EXPORT(int) _nc_handle_sigwinch(SCREEN *);
@@ -1857,6 +1921,7 @@ extern NCURSES_EXPORT(int) _nc_putp(const char *, const char *);
 extern NCURSES_EXPORT(int) _nc_putp_flush(const char *, const char *);
 extern NCURSES_EXPORT(int) _nc_read_termcap_entry (const char *const, TERMTYPE *const);
 extern NCURSES_EXPORT(int) _nc_setupscreen (int, int, FILE *, bool, int);
+extern NCURSES_EXPORT(int) _nc_setup_tinfo(const char *, TERMTYPE *);
 extern NCURSES_EXPORT(int) _nc_timed_wait (SCREEN *, int, int, int * EVENTLIST_2nd(_nc_eventlist *));
 extern NCURSES_EXPORT(void) _nc_do_color (short, short, bool, NCURSES_OUTC);
 extern NCURSES_EXPORT(void) _nc_flush (void);
@@ -1959,6 +2024,7 @@ extern NCURSES_EXPORT_VAR(int *) _nc_oldnums;
 #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 *);
@@ -2280,4 +2346,6 @@ extern NCURSES_EXPORT(NCURSES_CONST char *) _nc_unctrl (SCREEN *, chtype);
 }
 #endif
 
+/* *INDENT-ON* */
+
 #endif /* CURSES_PRIV_H */