[BACK]Return to curses_private.h CVS log [TXT][DIR] Up to [cvs.NetBSD.org] / src / lib / libcurses

Annotation of src/lib/libcurses/curses_private.h, Revision 1.45

1.45    ! drochner    1: /*     $NetBSD: curses_private.h,v 1.44 2010/02/03 15:34:40 roy Exp $  */
1.1       blymn       2:
                      3: /*-
                      4:  * Copyright (c) 1998-2000 Brett Lymn
                      5:  *                         (blymn@baea.com.au, brett_lymn@yahoo.com.au)
                      6:  * All rights reserved.
                      7:  *
                      8:  * This code has been donated to The NetBSD Foundation by the Author.
                      9:  *
                     10:  * Redistribution and use in source and binary forms, with or without
                     11:  * modification, are permitted provided that the following conditions
                     12:  * are met:
                     13:  * 1. Redistributions of source code must retain the above copyright
                     14:  *    notice, this list of conditions and the following disclaimer.
                     15:  * 2. The name of the author may not be used to endorse or promote products
1.16      wiz        16:  *    derived from this software without specific prior written permission
1.1       blymn      17:  *
                     18:  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
                     19:  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
                     20:  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
                     21:  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
                     22:  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
                     23:  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
                     24:  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
                     25:  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
                     26:  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
                     27:  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
                     28:  *
                     29:  *
                     30:  */
                     31:
1.40      blymn      32: /* Modified by Ruibiao Qiu <ruibiao@arl.wustl.edu,ruibiao@gmail.com>
                     33:  * to add support for wide characters
                     34:  * Changes:
                     35:  * - Add a compiler variable HAVE_WCHAR for wide character only code
                     36:  * - Add a pointer to liked list of non-spacing characters in __ldata
                     37:  *   and the macro to access the width field in the attribute field
                     38:  * - Add a circular input character buffer in __screen to handle wide
                     39:  *   character input (used in get_wch())
                     40:  */
                     41:
1.44      roy        42: #include <term.h>
1.17      blymn      43: #include <termios.h>
                     44:
1.1       blymn      45: /* Private structure definitions for curses. */
1.18      blymn      46:
                     47: /* Termcap capabilities. */
1.40      blymn      48: #ifdef HAVE_WCHAR
                     49: /*
                     50:  * Add a list of non-spacing characters to each spacing
                     51:  * character in a singly linked list
                     52:  */
                     53: typedef struct nschar_t {
                     54:        wchar_t                 ch;             /* Non-spacing character */
                     55:        struct nschar_t *next;  /* Next non-spacing character */
                     56: } nschar_t;
                     57: #endif /* HAVE_WCHAR */
                     58:
1.1       blymn      59: /*
1.42      jdc        60:  * A window is an array of __LINE structures pointed to by the 'lines' pointer.
1.1       blymn      61:  * A line is an array of __LDATA structures pointed to by the 'line' pointer.
                     62:  *
                     63:  * IMPORTANT: the __LDATA structure must NOT induce any padding, so if new
                     64:  * fields are added -- padding fields with *constant values* should ensure
                     65:  * that the compiler will not generate any padding when storing an array of
                     66:  *  __LDATA structures.  This is to enable consistent use of memcmp, and memcpy
                     67:  * for comparing and copying arrays.
                     68:  */
                     69:
                     70: struct __ldata {
                     71:        wchar_t ch;                     /* Character */
                     72:        attr_t  attr;                   /* Attributes */
1.40      blymn      73: #ifdef HAVE_WCHAR
                     74:        nschar_t        *nsp;   /* Foreground non-spacing character pointer */
                     75: #endif /* HAVE_WCHAR */
1.1       blymn      76: };
                     77:
1.40      blymn      78: #ifdef HAVE_WCHAR
                     79: /* macros to extract the width of a wide character */
                     80: #define __WCWIDTH 0xfc000000
                     81: #define WCW_SHIFT 26
                     82: #define WCOL(wc) ((((unsigned) (wc).attr) >> WCW_SHIFT ) > MB_LEN_MAX ? ((int)(((unsigned) (wc).attr ) >> WCW_SHIFT )) - 64 : ((int)(((unsigned) (wc).attr ) >> WCW_SHIFT)))
                     83: #define SET_WCOL(c, w) do {                                            \
                     84:        ((c).attr) = ((((c).attr) & WA_ATTRIBUTES ) | ((w) << WCW_SHIFT )); \
                     85: } while(/*CONSTCOND*/0)
                     86: #define BGWCOL(wc) ((((wc).battr) >> WCW_SHIFT ) > MB_LEN_MAX ? (((wc).battr ) >> WCW_SHIFT ) - 64 : (((wc).battr ) >> WCW_SHIFT ))
                     87: #define SET_BGWCOL(c, w) do {                                          \
                     88:        ((c).battr) = ((((c).battr) & WA_ATTRIBUTES ) | ((w) << WCW_SHIFT )); \
                     89: } while(/*CONSTCOND*/0)
                     90: #endif /* HAVE_WCHAR */
                     91:
1.1       blymn      92: #define __LDATASIZE    (sizeof(__LDATA))
                     93:
                     94: struct __line {
1.24      blymn      95: #ifdef DEBUG
                     96: #define SENTINEL_VALUE 0xaac0ffee
1.40      blymn      97:
1.24      blymn      98:        unsigned int sentinel;          /* try to catch line overflows */
                     99: #endif
1.1       blymn     100: #define        __ISDIRTY       0x01            /* Line is dirty. */
                    101: #define __ISPASTEOL    0x02            /* Cursor is past end of line */
                    102:        unsigned int flags;
                    103:        unsigned int hash;              /* Hash value for the line. */
                    104:        int *firstchp, *lastchp;        /* First and last chngd columns ptrs */
                    105:        int firstch, lastch;            /* First and last changed columns. */
                    106:        __LDATA *line;                  /* Pointer to the line text. */
                    107: };
                    108:
                    109: struct __window {              /* Window structure. */
                    110:        struct __window *nextp, *orig;  /* Subwindows list and parent. */
                    111:        int begy, begx;                 /* Window home. */
                    112:        int cury, curx;                 /* Current x, y coordinates. */
                    113:        int maxy, maxx;                 /* Maximum values for curx, cury. */
1.29      dsl       114:        int reqy, reqx;                 /* Size requested when created */
                    115:        int ch_off;                     /* x offset for firstch/lastch. */
1.43      roy       116:        __LINE **alines;                /* Array of pointers to the lines */
1.1       blymn     117:        __LINE  *lspace;                /* line space (for cleanup) */
                    118:        __LDATA *wspace;                /* window space (for cleanup) */
                    119:
                    120: #define        __ENDLINE       0x00000001      /* End of screen. */
                    121: #define        __FLUSH         0x00000002      /* Fflush(stdout) after refresh. */
                    122: #define        __FULLWIN       0x00000004      /* Window is a screen. */
                    123: #define        __IDLINE        0x00000008      /* Insert/delete sequences. */
                    124: #define        __SCROLLWIN     0x00000010      /* Last char will scroll window. */
                    125: #define        __SCROLLOK      0x00000020      /* Scrolling ok. */
                    126: #define        __CLEAROK       0x00000040      /* Clear on next refresh. */
                    127: #define        __LEAVEOK       0x00000100      /* If cursor left */
                    128: #define        __KEYPAD        0x00010000      /* If interpreting keypad codes */
                    129: #define        __NOTIMEOUT     0x00020000      /* Wait indefinitely for func keys */
1.26      jdc       130: #define __IDCHAR       0x00040000      /* insert/delete char sequences */
                    131: #define __ISPAD                0x00080000      /* "window" is a pad */
1.1       blymn     132:        unsigned int flags;
                    133:        int     delay;                  /* delay for getch() */
                    134:        attr_t  wattr;                  /* Character attributes */
1.5       jdc       135:        wchar_t bch;                    /* Background character */
1.2       jdc       136:        attr_t  battr;                  /* Background attributes */
1.14      jdc       137:        int     scr_t, scr_b;           /* Scrolling region top, bottom */
1.32      dsl       138:        SCREEN  *screen;                /* Screen for this window */
1.36      jdc       139:        int     pbegy, pbegx,
                    140:                sbegy, sbegx,
                    141:                smaxy, smaxx;           /* Saved prefresh() values */
1.40      blymn     142: #ifdef HAVE_WCHAR
                    143:        nschar_t *bnsp;                 /* Background non-spacing char list */
                    144: #endif /* HAVE_WCHAR */
1.1       blymn     145: };
1.5       jdc       146:
                    147: /* Set of attributes unset by 'me' - 'mb', 'md', 'mh', 'mk', 'mp' and 'mr'. */
1.40      blymn     148: #ifndef HAVE_WCHAR
1.5       jdc       149: #define        __TERMATTR \
                    150:        (__REVERSE | __BLINK | __DIM | __BOLD | __BLANK | __PROTECT)
1.40      blymn     151: #else
                    152: #define        __TERMATTR \
                    153:        (__REVERSE | __BLINK | __DIM | __BOLD | __BLANK | __PROTECT \
                    154:        | WA_TOP | WA_LOW | WA_LEFT | WA_RIGHT | WA_HORIZONTAL | WA_VERTICAL)
                    155: #endif /* HAVE_WCHAR */
1.2       jdc       156:
1.3       jdc       157: struct __winlist {
                    158:        struct __window         *winp;  /* The window. */
                    159:        struct __winlist        *nextp; /* Next window. */
                    160: };
                    161:
1.17      blymn     162: struct __color {
                    163:        short   num;
                    164:        short   red;
                    165:        short   green;
                    166:        short   blue;
                    167:        int     flags;
                    168: };
                    169:
                    170: /* List of colour pairs */
                    171: struct __pair {
                    172:        short   fore;
                    173:        short   back;
                    174:        int     flags;
                    175: };
                    176:
                    177: /* Maximum colours */
                    178: #define        MAX_COLORS      64
                    179: /* Maximum colour pairs - determined by number of colour bits in attr_t */
1.25      jdc       180: #define        MAX_PAIRS       PAIR_NUMBER(__COLOR)
1.17      blymn     181:
                    182: typedef struct keymap keymap_t;
                    183:
                    184: /* this is the encapsulation of the terminal definition, one for
                    185:  * each terminal that curses talks to.
                    186:  */
                    187: struct __screen {
                    188:        FILE    *infd, *outfd;  /* input and output file descriptors */
                    189:        WINDOW  *curscr;        /* Current screen. */
                    190:        WINDOW  *stdscr;        /* Standard screen. */
                    191:        WINDOW  *__virtscr;     /* Virtual screen (for doupdate()). */
                    192:        int      curwin;        /* current window for refresh */
1.29      dsl       193:        int      lx, ly;        /* loop parameters for refresh */
1.17      blymn     194:        int      COLS;          /* Columns on the screen. */
                    195:        int      LINES;         /* Lines on the screen. */
                    196:        int      COLORS;        /* Maximum colors on the screen */
                    197:        int      COLOR_PAIRS;   /* Maximum color pairs on the screen */
                    198:        int      My_term;       /* Use Def_term regardless. */
                    199:        char     GT;            /* Gtty indicates tabs. */
                    200:        char     NONL;          /* Term can't hack LF doing a CR. */
                    201:        char     UPPERCASE;     /* Terminal is uppercase only. */
                    202:
                    203:        chtype acs_char[NUM_ACS];
1.40      blymn     204: #ifdef HAVE_WCHAR
                    205:        cchar_t wacs_char[ NUM_ACS ];
                    206: #endif /* HAVE_WCHAR */
1.17      blymn     207:        struct __color colours[MAX_COLORS];
                    208:        struct __pair  colour_pairs[MAX_PAIRS];
                    209:        attr_t  nca;
1.20      blymn     210:
1.17      blymn     211: /* Style of colour manipulation */
                    212: #define COLOR_NONE     0
                    213: #define COLOR_ANSI     1       /* ANSI/DEC-style colour manipulation */
                    214: #define COLOR_HP       2       /* HP-style colour manipulation */
                    215: #define COLOR_TEK      3       /* Tektronix-style colour manipulation */
                    216: #define COLOR_OTHER    4       /* None of the others but can set fore/back */
                    217:        int color_type;
1.20      blymn     218:
1.17      blymn     219:        attr_t mask_op;
                    220:        attr_t mask_me;
                    221:        attr_t mask_ue;
                    222:        attr_t mask_se;
1.44      roy       223:        TERMINAL *term;
1.17      blymn     224:        int old_mode; /* old cursor visibility state for terminal */
                    225:        keymap_t *base_keymap;
                    226:        int echoit;
                    227:        int pfast;
                    228:        int rawmode;
1.30      jdc       229:        int nl;
1.17      blymn     230:        int noqch;
                    231:        int clearok;
                    232:        int useraw;
                    233:        struct __winlist *winlistp;
                    234:        struct   termios cbreakt, rawt, *curt, save_termios;
                    235:        struct termios orig_termios, baset, savedtty;
                    236:        int ovmin;
                    237:        int ovtime;
                    238:        char *stdbuf;
                    239:        unsigned int len;
                    240:        int meta_state;
1.43      roy       241:        char padchar;
1.21      christos  242:        char ttytype[128];
1.17      blymn     243:        int endwin;
1.22      itojun    244:        int notty;
1.27      blymn     245:        int half_delay;
1.35      jdc       246:        int resized;
1.41      jdc       247:        wchar_t *unget_list;
                    248:        int unget_len, unget_pos;
1.40      blymn     249: #ifdef HAVE_WCHAR
                    250: #define MB_LEN_MAX 8
                    251: #define MAX_CBUF_SIZE MB_LEN_MAX
                    252:        int             cbuf_head;              /* header to cbuf */
                    253:        int             cbuf_tail;              /* tail to cbuf */
                    254:        int             cbuf_cur;               /* the current char in cbuf */
                    255:        mbstate_t       sp;                     /* wide char processing state */
                    256:        char            cbuf[ MAX_CBUF_SIZE ];  /* input character buffer */
                    257: #endif /* HAVE_WCHAR */
1.17      blymn     258: };
                    259:
                    260:
1.11      jdc       261: extern char     __GT;                  /* Gtty indicates tabs. */
                    262: extern char     __NONL;                /* Term can't hack LF doing a CR. */
                    263: extern char     __UPPERCASE;           /* Terminal is uppercase only. */
                    264: extern int      My_term;               /* Use Def_term regardless. */
                    265: extern const char      *Def_term;      /* Default terminal type. */
1.17      blymn     266: extern SCREEN   *_cursesi_screen;       /* The current screen in use */
1.11      jdc       267:
1.39      jdc       268: /* Debugging options/functions. */
1.2       jdc       269: #ifdef DEBUG
1.39      jdc       270: #define __CTRACE_TSTAMP                0x00000001
                    271: #define __CTRACE_MISC          0x00000002
                    272: #define __CTRACE_INIT          0x00000004
                    273: #define __CTRACE_SCREEN                0x00000008
                    274: #define __CTRACE_WINDOW                0x00000010
                    275: #define __CTRACE_REFRESH       0x00000020
                    276: #define __CTRACE_COLOR         0x00000040
                    277: #define __CTRACE_INPUT         0x00000080
                    278: #define __CTRACE_OUTPUT                0x00000100
                    279: #define __CTRACE_LINE          0x00000200
                    280: #define __CTRACE_ATTR          0x00000400
                    281: #define __CTRACE_ERASE         0x00000800
1.42      jdc       282: #define __CTRACE_FILEIO                0x00001000
1.39      jdc       283: #define __CTRACE_ALL           0x7fffffff
                    284: void    __CTRACE_init(void);
                    285: void    __CTRACE(int, const char *, ...) __attribute__((__format__(__printf__, 2, 3)));
1.2       jdc       286: #endif
1.39      jdc       287:
                    288: /* Private functions. */
1.44      roy       289: int     __cputchar_args(int, void *);
1.23      itojun    290: void     _cursesi_free_keymap(keymap_t *);
                    291: int      _cursesi_gettmode(SCREEN *);
                    292: void     _cursesi_reset_acs(SCREEN *);
1.40      blymn     293: int    _cursesi_addbyte(WINDOW *, __LINE **, int *, int *, int , attr_t);
                    294: int    _cursesi_addwchar(WINDOW *, __LINE **, int *, int *, const cchar_t *);
                    295: #ifdef HAVE_WCHAR
                    296: void     _cursesi_reset_wacs(SCREEN *);
                    297: #endif /* HAVE_WCHAR */
1.23      itojun    298: void     _cursesi_resetterm(SCREEN *);
                    299: int      _cursesi_setterm(char *, SCREEN *);
1.4       blymn     300: int     __delay(void);
1.37      dsl       301: u_int   __hash_more(const void *, size_t, u_int);
1.23      itojun    302: #define        __hash(s, len)  __hash_more((s), (len), 0u)
                    303: void    __id_subwins(WINDOW *);
                    304: void    __init_getch(SCREEN *);
                    305: void    __init_acs(SCREEN *);
1.40      blymn     306: #ifdef HAVE_WCHAR
                    307: void    __init_get_wch(SCREEN *);
                    308: void    __init_wacs(SCREEN *);
1.44      roy       309: int    __cputwchar_args( wchar_t, void * );
1.40      blymn     310: int     _cursesi_copy_nsp(nschar_t *, struct __ldata *);
                    311: void   __cursesi_free_nsp(nschar_t *);
                    312: void   __cursesi_win_free_nsp(WINDOW *);
                    313: void   __cursesi_putnsp(nschar_t *, const int, const int);
1.45    ! drochner  314: void   __cursesi_chtype_to_cchar(chtype, cchar_t *);
1.40      blymn     315: #endif /* HAVE_WCHAR */
1.41      jdc       316: int     __unget(wint_t);
1.23      itojun    317: char   *__longname(char *, char *);    /* Original BSD version */
                    318: int     __mvcur(int, int, int, int, int);
1.26      jdc       319: WINDOW  *__newwin(SCREEN *, int, int, int, int, int);
1.4       blymn     320: int     __nodelay(void);
                    321: int     __notimeout(void);
                    322: void    __restartwin(void);
                    323: void    __restore_colors(void);
1.6       blymn     324: void     __restore_cursor_vis(void);
                    325: void     __restore_meta_state(void);
1.4       blymn     326: void    __restore_termios(void);
                    327: void    __restore_stophandler(void);
1.35      jdc       328: void    __restore_winchhandler(void);
1.4       blymn     329: void    __save_termios(void);
1.25      jdc       330: void    __set_color(WINDOW *win, attr_t attr);
1.4       blymn     331: void    __set_stophandler(void);
1.35      jdc       332: void    __set_winchhandler(void);
1.23      itojun    333: void    __set_subwin(WINDOW *, WINDOW *);
                    334: void    __startwin(SCREEN *);
                    335: void    __stop_signal_handler(int);
1.4       blymn     336: int     __stopwin(void);
1.23      itojun    337: void    __swflags(WINDOW *);
                    338: int     __timeout(int);
                    339: int     __touchline(WINDOW *, int, int, int);
                    340: int     __touchwin(WINDOW *);
1.7       jdc       341: void    __unsetattr(int);
1.25      jdc       342: void    __unset_color(WINDOW *win);
1.23      itojun    343: int     __waddch(WINDOW *, __LDATA *);
1.15      jdc       344: int     __wgetnstr(WINDOW *, char *, int);
1.35      jdc       345: void    __winch_signal_handler(int);
1.2       jdc       346:
                    347: /* Private #defines. */
1.23      itojun    348: #define        min(a,b)        ((a) < (b) ? (a) : (b))
                    349: #define        max(a,b)        ((a) > (b) ? (a ): (b))
1.2       jdc       350:
                    351: /* Private externs. */
1.3       jdc       352: extern int              __echoit;
                    353: extern int              __endwin;
                    354: extern int              __pfast;
                    355: extern int              __rawmode;
                    356: extern int              __noqch;
1.11      jdc       357: extern attr_t           __mask_op, __mask_me, __mask_ue, __mask_se;
1.7       jdc       358: extern WINDOW          *__virtscr;
1.25      jdc       359: extern int              __using_color;
                    360: extern attr_t           __default_color;

CVSweb <webmaster@jp.NetBSD.org>