/*----------------------------------------------------------------
 *  ecurses.h
 *
 *  Location: /usr/local/include/ecurses.h
 *
 *  Author: Frank Meyer
 *  (c) Copyright 1992 textware GmbH Koeln
 *--------------------------------------------------------------*/

/*----------------------------------------------------------------
 * ZUR BEACHTUNG:
 * Dieses Listing bildet die Fortsetzung der in iX 11/92
 * abgedruckten include-Datei ECURSES.H:
 *--------------------------------------------------------------*/

#define bool            char             /* compatibility with  */
#define reg             register         /* standard CURSES     */
#define chtype          unsigned int

/* attributes: */

#define A_UNDEFINED     -1

#define A_NORMAL        000000000000L
#define A_UNDERLINE     000000200000L    /* 65536               */
#define A_REVERSE       000000400000L
#define A_BLINK         000001000000L
#define A_BOLD          000002000000L
#define A_DIM           000004000000L
#define A_STANDOUT      000010000000L
#define A_INVIS         000020000000L
#define A_PROTECT       000040000000L

#define F_WHITE         000000000000L
#define F_RED           000100000000L
#define F_GREEN         000200000000L
#define F_BROWN         000300000000L
#define F_BLUE          000400000000L
#define F_MAGENTA       000500000000L
#define F_CYAN          000600000000L
#define F_BLACK         000700000000L

#define B_BLACK         000000000000L
#define B_RED           001000000000L
#define B_GREEN         002000000000L
#define B_BROWN         003000000000L
#define B_BLUE          004000000000L
#define B_MAGENTA       005000000000L
#define B_CYAN          006000000000L
#define B_WHITE         007000000000L

#define F_COLOR         000700000000L
#define B_COLOR         007000000000L

#define A_ATTRIBUTES    037777600000L           /* 0xFFFF0000 */
#define A_CHARTEXT      000000177777L           /* 0x0000FFFF */

#define COLOR_MASK (ECURSES_USES_COLOR ?                       \
        A_ATTRIBUTES                                           \
    :                                                          \
        A_ATTRIBUTES & (~(F_COLOR | B_COLOR)))

#ifdef CURSES_DEFINED
#define CURSES_EXT
#define CURSES_INIT(x) = x
#else
#define CURSES_EXT extern
#define CURSES_INIT(x)
#endif

struct _win_st
{
    int     cury;       /* current y position   */
    int     curx;       /* current x position   */
    int     attrs;      /* current attributes   */
    int     starty;     /* upper left corner    */
    int     startx;
    int     endy;       /* lower right corner   */
    int     endx;
    int     flags;      /* some flags           */
    chtype  **image;    /* image of screen      */
};

typedef struct _win_st          WINDOW;
CURSES_EXT WINDOW *             stdscr;
CURSES_EXT WINDOW *             curscr;

CURSES_EXT int LINES            CURSES_INIT(-1);
CURSES_EXT int COLS             CURSES_INIT(-1);

#define move(y,x)               wmove(stdscr, y, x)
#define wmove(win,y,x)          (win->cury = y), (win->curx = x)

#define attron(a)               wattron(stdscr,a)
#define attroff(a)              wattroff(stdscr,a)
#define attrset(a)              wattrset(stdscr,a)
#define standout()              wstandout(stdscr)
#define standend()              wstandend(stdscr)

#define wattron(win,a)          win->attrs |= ((a) & COLOR_MASK)
#define wattroff(win,a)         win->attrs &= ~((a) & COLOR_MASK)
#define wattrset(win,a)         win->attrs = ((a) & COLOR_MASK)
#define wstandout(win)          wattron(win,A_STANDOUT)
#define wstandend(win)          wattrset(win,A_NORMAL)

/* TTY specific functions : */

CURSES_EXT int (*getch_func) ();
CURSES_EXT int (*addch_func) ();
CURSES_EXT int (*raw_func) ();
CURSES_EXT int (*noraw_func) ();
CURSES_EXT int (*echo_func) ();
CURSES_EXT int (*noecho_func) ();

#define getch()         (*getch_func)  ()
#define addch(ch)       (*addch_func)  (ch)
#define raw()           (*raw_func)    ()
#define noraw()         (*noraw_func)  ()
#define echo()          (*echo_func)   ()
#define noecho()        (*noecho_func) ()

#undef CURSES_EXT
#undef CURSES_INIT
