'
' CURSES definitions based on ncurses 5.7 - their license below.
'
' Website:
'   http://www.gnu.org/software/ncurses/
'   http://en.wikipedia.org/wiki/Ncurses
'
' Ported to BaCon INCLUDE file by Peter van Eerten - GPL.
'
' Version 1.0: Initial release - most functions implemented, please send
'       bugs to bugs@basic-converter.org
' Version 1.1: - Fixes in external variable 'stdscr'
'              - Removed redundant DEF FN functions
' Version 1.2: - Removed redundant SYSV defines
' Version 1.3: - Completed VT100 symbols
' Version 1.4: - Adapted for BaCon 3.0 and higher
'
' ncurses.h
'
'***************************************************************************
' Copyright (c) 1998-2008,2009 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            *
' "Software"), to deal in the Software without restriction, including      *
' without limitation the rights to use, copy, modify, merge, publish,      *
' distribute, distribute with modifications, sublicense, and/or sell       *
' copies of the Software, and to permit persons to whom the Software is    *
' furnished to do so, subject to the following conditions:                 *
'                                                                          *
' The above copyright notice and this permission notice shall be included  *
' in all copies or substantial portions of the Software.                   *
'                                                                          *
' THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS  *
' OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF               *
' MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.   *
' IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,   *
' DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR    *
' OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR    *
' THE USE OR OTHER DEALINGS IN THE SOFTWARE.                               *
'                                                                          *
' Except as contained in this notice, the name(s) of the above copyright   *
' holders shall not be used in advertising or otherwise to promote the     *
' sale, use or other dealings in this Software without prior written       *
' authorization.                                                           *
'***************************************************************************

'***************************************************************************
'  Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995               *
'     and: Eric S. Raymond <esr@snark.thyrsus.com>                         *
'     and: Thomas E. Dickey                        1996-on                 *
'***************************************************************************

CATCH GOTO ncurses_handle_error

ncurses_LIB$ = "libncurses.so"
ncurses_seq = -1

LABEL ncurses_import_retry
    INCR ncurses_seq
    ncurses_retry = FALSE
    IMPORT "initscr(void)" FROM ncurses_LIB$ TYPE long
    IF ncurses_retry THEN GOTO ncurses_import_retry

GOTO ncurses_continue

LABEL ncurses_handle_error
    IF ncurses_seq = 0 THEN ncurses_LIB$ = "libncurses.so.0"
    ELSE ncurses_LIB$ = LEFT$(ncurses_LIB$, INSTRREV(ncurses_LIB$, ".")) & STR$(ncurses_seq)
    IF ncurses_seq < 10 THEN
        ncurses_retry = TRUE
    ELSE
        PRINT "No ncurses library found!"
        END
    END IF
    RESUME

LABEL ncurses_continue

' some variables must be declared in the client program
USEC
    extern long curscr;
    extern long newscr;
    extern long stdscr;
END USEC

CONST COLS = COLUMNS
' CONST ESCDELAY
CONST LINES = ROWS
CONST TABSIZE = LEN(TAB$(1))

' version
CONST NCURSES_VERSION_MAJOR = 5
CONST NCURSES_VERSION_MINOR = 7
CONST NCURSES_VERSION_PATCH = 20090803
CONST NCURSES_VERSION$ = "5.7"
CONST NCURSES_MOUSE_VERSION = 1
CONST NCURSES_OPAQUE = 0

' colors
CONST COLOR_BLACK = 0
CONST COLOR_RED = 1
CONST COLOR_GREEN = 2
CONST COLOR_YELLOW = 3
CONST COLOR_BLUE = 4
CONST COLOR_MAGENTA = 5
CONST COLOR_CYAN = 6
CONST COLOR_WHITE = 7

' VT100 symbols begin here
CONST ACS_ULCORNER = 43
CONST ACS_LLCORNER = 43
CONST ACS_URCORNER = 43
CONST ACS_LRCORNER = 43
CONST ACS_LTEE = 43
CONST ACS_RTEE = 43
CONST ACS_BTEE = 43
CONST ACS_TTEE = 43
CONST ACS_HLINE = 45
CONST ACS_VLINE = 124
CONST ACS_PLUS = 43
CONST ACS_S1 = 126
CONST ACS_S9 = 95
CONST ACS_DIAMOND = 43
CONST ACS_CKBOARD = 58
CONST ACS_DEGREE = 44
CONST ACS_PLMINUS = 35
CONST ACS_BULLET = 111

' Teletype 5410v1 symbols begin here
CONST ACS_LARROW = 60
CONST ACS_RARROW = 62
CONST ACS_DARROW = 118
CONST ACS_UARROW = 94
CONST ACS_BOARD = 35
CONST ACS_LANTERN = 35
CONST ACS_BLOCK = 35

' These aren't documented, but a lot of System Vs have them anyway
CONST ACS_S3 = 45
CONST ACS_S7 = 45
CONST ACS_LEQUAL = 60
CONST ACS_GEQUAL = 62
CONST ACS_PI = 42
CONST ACS_NEQUAL = 33
CONST ACS_STERLING = 102

CONST ACS_BSSB = ACS_ULCORNER
CONST ACS_SSBB = ACS_LLCORNER
CONST ACS_BBSS = ACS_URCORNER
CONST ACS_SBBS = ACS_LRCORNER
CONST ACS_SBSS = ACS_RTEE
CONST ACS_SSSB = ACS_LTEE
CONST ACS_SSBS = ACS_BTEE
CONST ACS_BSSS = ACS_TTEE
CONST ACS_BSBS = ACS_HLINE
CONST ACS_SBSB = ACS_VLINE
CONST ACS_SSSS = ACS_PLUS

CONST ERR = -1
CONST OK = 0

IMPORT "addch(unsigned long)" FROM ncurses_LIB$ TYPE int
IMPORT "addchnstr(unsigned long*,int)" FROM ncurses_LIB$ TYPE int
IMPORT "addchstr(unsigned long*)" FROM ncurses_LIB$ TYPE int
IMPORT "addnstr(char*,int)" FROM ncurses_LIB$ TYPE int
IMPORT "addstr(char*)" FROM ncurses_LIB$ TYPE int
IMPORT "attroff(long)" FROM ncurses_LIB$ TYPE int
IMPORT "attron(long)" FROM ncurses_LIB$ TYPE int
IMPORT "attrset(long)" FROM ncurses_LIB$ TYPE int
IMPORT "attr_get(unsigned long*,short*,void*)" FROM ncurses_LIB$ TYPE int
IMPORT "attr_off(unsigned long,void*)" FROM ncurses_LIB$ TYPE int
IMPORT "attr_on(unsigned long,void*)" FROM ncurses_LIB$ TYPE int
IMPORT "attr_set(unsigned long,short,void*)" FROM ncurses_LIB$ TYPE int
IMPORT "baudrate(void)" FROM ncurses_LIB$ TYPE int
IMPORT "beep(void)" FROM ncurses_LIB$ TYPE int
IMPORT "bkgd(unsigned long)" FROM ncurses_LIB$ TYPE int
IMPORT "bkgdset(unsigned long)" FROM ncurses_LIB$ TYPE void
IMPORT "border(unsigned long,unsigned long,unsigned long,unsigned long,unsigned long,unsigned long,unsigned long,unsigned long)" FROM ncurses_LIB$ TYPE int
IMPORT "box(long,unsigned long,unsigned long)" FROM ncurses_LIB$ TYPE int
IMPORT "can_change_color(void)" FROM ncurses_LIB$ TYPE int
IMPORT "cbreak(void)" FROM ncurses_LIB$ TYPE int
IMPORT "chgat(int,unsigned long,short,void*)" FROM ncurses_LIB$ TYPE int
IMPORT "clear(void)" FROM ncurses_LIB$ TYPE int
IMPORT "clearok(long,int)" FROM ncurses_LIB$ TYPE int
IMPORT "clrtobot(void)" FROM ncurses_LIB$ TYPE int
IMPORT "clrtoeol(void)" FROM ncurses_LIB$ TYPE int
IMPORT "color_content(short,short*,short*,short*)" FROM ncurses_LIB$ TYPE int
IMPORT "color_set(short,void*)" FROM ncurses_LIB$ TYPE int
IMPORT "COLOR_PAIR(int)" FROM ncurses_LIB$ TYPE int
IMPORT "copywin(long,long,int,int,int,int,int,int,int)" FROM ncurses_LIB$ TYPE int
IMPORT "curs_set(int)" FROM ncurses_LIB$ TYPE int
IMPORT "def_prog_mode(void)" FROM ncurses_LIB$ TYPE int
IMPORT "def_shell_mode(void)" FROM ncurses_LIB$ TYPE int
IMPORT "delay_output(int);" FROM ncurses_LIB$ TYPE int
IMPORT "delch(void)" FROM ncurses_LIB$ TYPE int
IMPORT "delscreen(long)" FROM ncurses_LIB$ TYPE void
IMPORT "delwin(long)" FROM ncurses_LIB$ TYPE int
IMPORT "deleteln(void)" FROM ncurses_LIB$ TYPE int
IMPORT "derwin(long,int,int,int,int)" FROM ncurses_LIB$ TYPE long
IMPORT "doupdate(void)" FROM ncurses_LIB$ TYPE int
IMPORT "dupwin(long)" FROM ncurses_LIB$ TYPE long
IMPORT "echo(void)" FROM ncurses_LIB$ TYPE int
IMPORT "echochar(unsigned long)" FROM ncurses_LIB$ TYPE int
IMPORT "erase(void)" FROM ncurses_LIB$ TYPE int
IMPORT "endwin(void)" FROM ncurses_LIB$ TYPE int
IMPORT "erasechar(void)" FROM ncurses_LIB$ TYPE char
IMPORT "filter(void)" FROM ncurses_LIB$ TYPE void
IMPORT "flash(void)" FROM ncurses_LIB$ TYPE int
IMPORT "flushinp(void)" FROM ncurses_LIB$ TYPE int
IMPORT "getbkgd(long)" FROM ncurses_LIB$ TYPE unsigned long
IMPORT "getch(void)" FROM ncurses_LIB$ TYPE int
IMPORT "getnstr(char*,int)" FROM ncurses_LIB$ TYPE int
IMPORT "getstr(char*)" FROM ncurses_LIB$ TYPE int
IMPORT "getwin(FILE*)" FROM ncurses_LIB$ TYPE long
IMPORT "halfdelay(int)" FROM ncurses_LIB$ TYPE int
IMPORT "has_colors(void)" FROM ncurses_LIB$ TYPE int
IMPORT "has_ic(void)" FROM ncurses_LIB$ TYPE int
IMPORT "has_il(void)" FROM ncurses_LIB$ TYPE int
IMPORT "hline(unsigned long,int)" FROM ncurses_LIB$ TYPE int
IMPORT "idcok(long,int)" FROM ncurses_LIB$ TYPE void
IMPORT "idlok(long,int)" FROM ncurses_LIB$ TYPE int
IMPORT "immedok(long,int)" FROM ncurses_LIB$ TYPE void
IMPORT "inch(void)" FROM ncurses_LIB$ TYPE unsigned long
IMPORT "inchnstr(unsigned long*,int)" FROM ncurses_LIB$ TYPE int
IMPORT "inchstr(unsigned long*)" FROM ncurses_LIB$ TYPE int
IMPORT "init_color(short,short,short,short)" FROM ncurses_LIB$ TYPE int
IMPORT "init_pair(short,short,short)" FROM ncurses_LIB$ TYPE int
IMPORT "innstr(char*,int)" FROM ncurses_LIB$ TYPE int
IMPORT "insch(unsigned long)" FROM ncurses_LIB$ TYPE int
IMPORT "insdelln(int)" FROM ncurses_LIB$ TYPE int
IMPORT "insertln(void)" FROM ncurses_LIB$ TYPE int
IMPORT "insnstr(char*,int)" FROM ncurses_LIB$ TYPE int
IMPORT "insstr(char*)" FROM ncurses_LIB$ TYPE int
IMPORT "instr(char*)" FROM ncurses_LIB$ TYPE int
IMPORT "intrflush(long,int)" FROM ncurses_LIB$ TYPE int
IMPORT "isendwin(void)" FROM ncurses_LIB$ TYPE int
IMPORT "is_linetouched(long,int)" FROM ncurses_LIB$ TYPE int
IMPORT "is_wintouched(long)" FROM ncurses_LIB$ TYPE int
IMPORT "keyname(int)" FROM ncurses_LIB$ TYPE char*
IMPORT "keypad(long,int)" FROM ncurses_LIB$ TYPE int
IMPORT "killchar(void)" FROM ncurses_LIB$ TYPE char
IMPORT "leaveok(long,int)" FROM ncurses_LIB$ TYPE int
IMPORT "longname(void)" FROM ncurses_LIB$ TYPE char*
IMPORT "meta(long,int)" FROM ncurses_LIB$ TYPE int
IMPORT "move(int,int)" FROM ncurses_LIB$ TYPE int
IMPORT "mvaddch(int,int,unsigned long)" FROM ncurses_LIB$ TYPE int
IMPORT "mvaddchnstr(int,int,unsigned long*,int)" FROM ncurses_LIB$ TYPE int
IMPORT "mvaddchstr(int,int,unsigned long*)" FROM ncurses_LIB$ TYPE int
IMPORT "mvaddnstr(int,int,char*,int)" FROM ncurses_LIB$ TYPE int
IMPORT "mvaddstr(int,int,char*)" FROM ncurses_LIB$ TYPE int
IMPORT "mvchgat(int,int,int,unsigned long,short,void*)" FROM ncurses_LIB$ TYPE int
IMPORT "mvcur(int,int,int,int)" FROM ncurses_LIB$ TYPE int
IMPORT "mvdelch(int,int)" FROM ncurses_LIB$ TYPE int
IMPORT "mvderwin(long,int,int)" FROM ncurses_LIB$ TYPE int
IMPORT "mvgetch(int,int)" FROM ncurses_LIB$ TYPE int
IMPORT "mvgetnstr(int,int,char*,int)" FROM ncurses_LIB$ TYPE int
IMPORT "mvgetstr(int,int,char*)" FROM ncurses_LIB$ TYPE int
IMPORT "mvhline(int,int,unsigned long,int)" FROM ncurses_LIB$ TYPE int
IMPORT "mvinch(int,int)" FROM ncurses_LIB$ TYPE unsigned long
IMPORT "mvinchnstr(int,int,unsigned long*,int)" FROM ncurses_LIB$ TYPE int
IMPORT "mvinchstr(int,int,unsigned long*)" FROM ncurses_LIB$ TYPE int
IMPORT "mvinnstr(int,int,char*,int)" FROM ncurses_LIB$ TYPE int
IMPORT "mvinsch(int,int,unsigned long)" FROM ncurses_LIB$ TYPE int
IMPORT "mvinsnstr(int,int,char*,int)" FROM ncurses_LIB$ TYPE int
IMPORT "mvinsstr(int,int,char*)" FROM ncurses_LIB$ TYPE int
IMPORT "mvinstr(int,int,char*)" FROM ncurses_LIB$ TYPE int
IMPORT "mvprintw(int,int,char*,...)" FROM ncurses_LIB$ TYPE int
IMPORT "mvscanw(int,int,char*,...)" FROM ncurses_LIB$ TYPE int
IMPORT "mvvline(int,int,unsigned long,int)" FROM ncurses_LIB$ TYPE int
IMPORT "mvwaddch(long,int,int,unsigned long)" FROM ncurses_LIB$ TYPE int
IMPORT "mvwaddchnstr(long,int,int,unsigned long*,int)" FROM ncurses_LIB$ TYPE int
IMPORT "mvwaddchstr(long,int,int,unsigned long*)" FROM ncurses_LIB$ TYPE int
IMPORT "mvwaddnstr(long,int,int,char*,int)" FROM ncurses_LIB$ TYPE int
IMPORT "mvwaddstr(long,int,int,char*)" FROM ncurses_LIB$ TYPE int
IMPORT "mvwchgat(long,int,int,int,unsigned long,short,void*)" FROM ncurses_LIB$ TYPE int
IMPORT "mvwdelch(long,int,int)" FROM ncurses_LIB$ TYPE int
IMPORT "mvwgetch(long,int,int)" FROM ncurses_LIB$ TYPE int
IMPORT "mvwgetnstr(long,int,int,char*,int)" FROM ncurses_LIB$ TYPE int
IMPORT "mvwgetstr(long,int,int,char*)" FROM ncurses_LIB$ TYPE int
IMPORT "mvwhline(long,int,int,unsigned long,int)" FROM ncurses_LIB$ TYPE int
IMPORT "mvwin(long,int,int)" FROM ncurses_LIB$ TYPE int
IMPORT "mvwinch(long,int,int)" FROM ncurses_LIB$ TYPE unsigned long
IMPORT "mvwinchnstr(long,int,int,unsigned long*,int)" FROM ncurses_LIB$ TYPE int
IMPORT "mvwinchstr(long,int,int,unsigned long*)" FROM ncurses_LIB$ TYPE int
IMPORT "mvwinnstr(long,int,int,char*,int)" FROM ncurses_LIB$ TYPE int
IMPORT "mvwinsch(long,int,int,unsigned long)" FROM ncurses_LIB$ TYPE int
IMPORT "mvwinsnstr(long,int,int,char*,int)" FROM ncurses_LIB$ TYPE int
IMPORT "mvwinsstr(long,int,int,char*)" FROM ncurses_LIB$ TYPE int
IMPORT "mvwinstr(long,int,int,char*)" FROM ncurses_LIB$ TYPE int
IMPORT "mvwprintw(long,int,int,char*,...)" FROM ncurses_LIB$ TYPE int
IMPORT "mvwscanw(long,int,int,char*,...)" FROM ncurses_LIB$ TYPE int
IMPORT "mvwvline(long,int,int,unsigned long,int)" FROM ncurses_LIB$ TYPE int
IMPORT "napms(int)" FROM ncurses_LIB$ TYPE int
IMPORT "newpad(int,int)" FROM ncurses_LIB$ TYPE long
IMPORT "newterm(char*,FILE*,FILE*)" FROM ncurses_LIB$ TYPE long
IMPORT "newwin(int,int,int,int)" FROM ncurses_LIB$ TYPE long
IMPORT "nl(void)" FROM ncurses_LIB$ TYPE int
IMPORT "nocbreak(void)" FROM ncurses_LIB$ TYPE int
IMPORT "nodelay(long,int)" FROM ncurses_LIB$ TYPE int
IMPORT "noecho(void)" FROM ncurses_LIB$ TYPE int
IMPORT "nonl(void)" FROM ncurses_LIB$ TYPE int
IMPORT "noqiflush(void)" FROM ncurses_LIB$ TYPE void
IMPORT "noraw(void)" FROM ncurses_LIB$ TYPE int
IMPORT "notimeout(long,int)" FROM ncurses_LIB$ TYPE int
IMPORT "overlay(long,long)" FROM ncurses_LIB$ TYPE int
IMPORT "overwrite(long,long)" FROM ncurses_LIB$ TYPE int
IMPORT "pair_content(short,short*,short*)" FROM ncurses_LIB$ TYPE int
IMPORT "PAIR_NUMBER(int)" FROM ncurses_LIB$ TYPE int
IMPORT "pechochar(long,unsigned long)" FROM ncurses_LIB$ TYPE int
IMPORT "pnoutrefresh(long,int,int,int,int,int,int)" FROM ncurses_LIB$ TYPE int
IMPORT "prefresh(long,int,int,int,int,int,int)" FROM ncurses_LIB$ TYPE int
IMPORT "printw(char*,...)" FROM ncurses_LIB$ TYPE int
IMPORT "putwin(long,FILE*)" FROM ncurses_LIB$ TYPE int
IMPORT "qiflush(void)" FROM ncurses_LIB$ TYPE void
IMPORT "raw(void)" FROM ncurses_LIB$ TYPE int
IMPORT "redrawwin(long)" FROM ncurses_LIB$ TYPE int
IMPORT "refresh(void)" FROM ncurses_LIB$ TYPE int
IMPORT "resetty(void)" FROM ncurses_LIB$ TYPE int
IMPORT "reset_prog_mode(void)" FROM ncurses_LIB$ TYPE int
IMPORT "reset_shell_mode(void)" FROM ncurses_LIB$ TYPE int
' IMPORT "ripoffline(int,int(*)(long,int))" FROM ncurses_LIB$ TYPE int
IMPORT "savetty(void)" FROM ncurses_LIB$ TYPE int
IMPORT "scanw(char*,...)" FROM ncurses_LIB$ TYPE int
IMPORT "scr_dump(char*)" FROM ncurses_LIB$ TYPE int
IMPORT "scr_init(char*)" FROM ncurses_LIB$ TYPE int
IMPORT "scrl(int)" FROM ncurses_LIB$ TYPE int
IMPORT "scroll(long)" FROM ncurses_LIB$ TYPE int
IMPORT "scrollok(long,int)" FROM ncurses_LIB$ TYPE int
IMPORT "scr_restore(char*)" FROM ncurses_LIB$ TYPE int
IMPORT "scr_set(char*)" FROM ncurses_LIB$ TYPE int
IMPORT "setscrreg(int,int)" FROM ncurses_LIB$ TYPE int
IMPORT "set_term(long)" FROM ncurses_LIB$ TYPE long
IMPORT "slk_attroff(unsigned long)" FROM ncurses_LIB$ TYPE int
IMPORT "slk_attr_off(unsigned long,void*)" FROM ncurses_LIB$ TYPE int
IMPORT "slk_attron(unsigned long)" FROM ncurses_LIB$ TYPE int
IMPORT "slk_attr_on(unsigned long,void*)" FROM ncurses_LIB$ TYPE int
IMPORT "slk_attrset(unsigned long)" FROM ncurses_LIB$ TYPE int
IMPORT "slk_attr(void)" FROM ncurses_LIB$ TYPE unsigned long
IMPORT "slk_attr_set(unsigned long,short,void*)" FROM ncurses_LIB$ TYPE int
IMPORT "slk_clear(void)" FROM ncurses_LIB$ TYPE int
IMPORT "slk_color(short)" FROM ncurses_LIB$ TYPE int
IMPORT "slk_init(int)" FROM ncurses_LIB$ TYPE int
IMPORT "slk_label(int)" FROM ncurses_LIB$ TYPE char*
IMPORT "slk_noutrefresh(void)" FROM ncurses_LIB$ TYPE int
IMPORT "slk_refresh(void)" FROM ncurses_LIB$ TYPE int
IMPORT "slk_restore(void)" FROM ncurses_LIB$ TYPE int
IMPORT "slk_set(int,char*,int)" FROM ncurses_LIB$ TYPE int
IMPORT "slk_touch(void)" FROM ncurses_LIB$ TYPE int
IMPORT "standout(void)" FROM ncurses_LIB$ TYPE int
IMPORT "standend(void)" FROM ncurses_LIB$ TYPE int
IMPORT "start_color(void)" FROM ncurses_LIB$ TYPE int
IMPORT "subpad(long,int,int,int,int)" FROM ncurses_LIB$ TYPE long
IMPORT "subwin(long,int,int,int,int)" FROM ncurses_LIB$ TYPE long
IMPORT "syncok(long,int)" FROM ncurses_LIB$ TYPE int
IMPORT "termattrs(void)" FROM ncurses_LIB$ TYPE unsigned long
IMPORT "termname(void)" FROM ncurses_LIB$ TYPE char*
IMPORT "timeout(int)" FROM ncurses_LIB$ TYPE void
IMPORT "touchline(long,int,int)" FROM ncurses_LIB$ TYPE int
IMPORT "touchwin(long)" FROM ncurses_LIB$ TYPE int
IMPORT "typeahead(int)" FROM ncurses_LIB$ TYPE int
IMPORT "ungetch(int)" FROM ncurses_LIB$ TYPE int
IMPORT "untouchwin(long)" FROM ncurses_LIB$ TYPE int
IMPORT "use_env(int)" FROM ncurses_LIB$ TYPE void
IMPORT "vidattr(unsigned long)" FROM ncurses_LIB$ TYPE int
IMPORT "vidputs(unsigned long,void*)" FROM ncurses_LIB$ TYPE int
IMPORT "vline(unsigned long,int)" FROM ncurses_LIB$ TYPE int
IMPORT "vwprintw(long,char*,va_list)" FROM ncurses_LIB$ TYPE int
IMPORT "vw_printw(long,char*,va_list)" FROM ncurses_LIB$ TYPE int
IMPORT "vwscanw(long,char*,va_list)" FROM ncurses_LIB$ TYPE int
IMPORT "vw_scanw(long,char*,va_list)" FROM ncurses_LIB$ TYPE int
IMPORT "waddch(long,unsigned long)" FROM ncurses_LIB$ TYPE int
IMPORT "waddchnstr(long,unsigned long*,int)" FROM ncurses_LIB$ TYPE int
IMPORT "waddchstr(long,unsigned long*)" FROM ncurses_LIB$ TYPE int
IMPORT "waddnstr(long,char*,int)" FROM ncurses_LIB$ TYPE int
IMPORT "waddstr(long,char*)" FROM ncurses_LIB$ TYPE int
IMPORT "wattron(long,int)" FROM ncurses_LIB$ TYPE int
IMPORT "wattroff(long,int)" FROM ncurses_LIB$ TYPE int
IMPORT "wattrset(long,int)" FROM ncurses_LIB$ TYPE int
IMPORT "wattr_get(long,unsigned long*,short*,void*)" FROM ncurses_LIB$ TYPE int
IMPORT "wattr_on(long,unsigned long,void*)" FROM ncurses_LIB$ TYPE int
IMPORT "wattr_off(long,unsigned long,void*)" FROM ncurses_LIB$ TYPE int
IMPORT "wattr_set(long,unsigned long,short,void*)" FROM ncurses_LIB$ TYPE int
IMPORT "wbkgd(long,unsigned long)" FROM ncurses_LIB$ TYPE int
IMPORT "wbkgdset(long,unsigned long)" FROM ncurses_LIB$ TYPE void
IMPORT "wborder(long,unsigned long,unsigned long,unsigned long,unsigned long,unsigned long,unsigned long,unsigned long,unsigned long)" FROM ncurses_LIB$ TYPE int
IMPORT "wchgat(long,int,unsigned long,short,void*)" FROM ncurses_LIB$ TYPE int
IMPORT "wclear(long)" FROM ncurses_LIB$ TYPE int
IMPORT "wclrtobot(long)" FROM ncurses_LIB$ TYPE int
IMPORT "wclrtoeol(long)" FROM ncurses_LIB$ TYPE int
IMPORT "wcolor_set(long,short,void*)" FROM ncurses_LIB$ TYPE int
IMPORT "wcursyncup(long)" FROM ncurses_LIB$ TYPE void
IMPORT "wdelch(long)" FROM ncurses_LIB$ TYPE int
IMPORT "wdeleteln(long)" FROM ncurses_LIB$ TYPE int
IMPORT "wechochar(long,unsigned long)" FROM ncurses_LIB$ TYPE int
IMPORT "werase(long)" FROM ncurses_LIB$ TYPE int
IMPORT "wgetch(long)" FROM ncurses_LIB$ TYPE int
IMPORT "wgetnstr(long,char*,int)" FROM ncurses_LIB$ TYPE int
IMPORT "wgetstr(long,char*)" FROM ncurses_LIB$ TYPE int
IMPORT "whline(long,unsigned long,int)" FROM ncurses_LIB$ TYPE int
IMPORT "winch(long)" FROM ncurses_LIB$ TYPE unsigned long
IMPORT "winchnstr(long,unsigned long*,int)" FROM ncurses_LIB$ TYPE int
IMPORT "winchstr(long,unsigned long*)" FROM ncurses_LIB$ TYPE int
IMPORT "winnstr(long,char*,int)" FROM ncurses_LIB$ TYPE int
IMPORT "winsch(long,unsigned long)" FROM ncurses_LIB$ TYPE int
IMPORT "winsdelln(long,int)" FROM ncurses_LIB$ TYPE int
IMPORT "winsertln(long)" FROM ncurses_LIB$ TYPE int
IMPORT "winsnstr(long,char*,int)" FROM ncurses_LIB$ TYPE int
IMPORT "winsstr(long,char*)" FROM ncurses_LIB$ TYPE int
IMPORT "winstr(long,char*)" FROM ncurses_LIB$ TYPE int
IMPORT "wmove(long,int,int)" FROM ncurses_LIB$ TYPE int
IMPORT "wnoutrefresh(long)" FROM ncurses_LIB$ TYPE int
IMPORT "wprintw(long,char*,...)" FROM ncurses_LIB$ TYPE int
IMPORT "wredrawln(long,int,int)" FROM ncurses_LIB$ TYPE int
IMPORT "wrefresh(long)" FROM ncurses_LIB$ TYPE int
IMPORT "wscanw(long,char*,...)" FROM ncurses_LIB$ TYPE int
IMPORT "wscrl(long,int)" FROM ncurses_LIB$ TYPE int
IMPORT "wsetscrreg(long,int,int)" FROM ncurses_LIB$ TYPE int
IMPORT "wstandout(long)" FROM ncurses_LIB$ TYPE int
IMPORT "wstandend(long)" FROM ncurses_LIB$ TYPE int
IMPORT "wsyncdown(long)" FROM ncurses_LIB$ TYPE void
IMPORT "wsyncup(long)" FROM ncurses_LIB$ TYPE void
IMPORT "wtimeout(long,int)" FROM ncurses_LIB$ TYPE void
IMPORT "wtouchln(long,int,int,int)" FROM ncurses_LIB$ TYPE int
IMPORT "wvline(long,unsigned long,int)" FROM ncurses_LIB$ TYPE int
IMPORT "tigetflag(char*)" FROM ncurses_LIB$ TYPE int
IMPORT "tigetnum(char*)" FROM ncurses_LIB$ TYPE int
IMPORT "tigetstr(char*)" FROM ncurses_LIB$ TYPE char*
IMPORT "putp(char*)" FROM ncurses_LIB$ TYPE int
IMPORT "tparm(char*, ...)" FROM ncurses_LIB$ TYPE char*
IMPORT "getattrs(long)" FROM ncurses_LIB$ TYPE int
IMPORT "getcurx(long)" FROM ncurses_LIB$ TYPE int
IMPORT "getcury(long)" FROM ncurses_LIB$ TYPE int
IMPORT "getbegx(long)" FROM ncurses_LIB$ TYPE int
IMPORT "getbegy(long)" FROM ncurses_LIB$ TYPE int
IMPORT "getmaxx(long)" FROM ncurses_LIB$ TYPE int
IMPORT "getmaxy(long)" FROM ncurses_LIB$ TYPE int
IMPORT "getparx(long)" FROM ncurses_LIB$ TYPE int
IMPORT "getpary(long)" FROM ncurses_LIB$ TYPE int

CONST NCURSES_EXT_FUNCS = 20090803

IMPORT "is_term_resized(int,int)" FROM ncurses_LIB$ TYPE int
IMPORT "keybound(int,int)" FROM ncurses_LIB$ TYPE char*
IMPORT "curses_version(void)" FROM ncurses_LIB$ TYPE char*
IMPORT "assume_default_colors(int,int)" FROM ncurses_LIB$ TYPE int
IMPORT "define_key(char*,int)" FROM ncurses_LIB$ TYPE int
IMPORT "get_escdelay(void)" FROM ncurses_LIB$ TYPE int
IMPORT "key_defined(char*)" FROM ncurses_LIB$ TYPE int
IMPORT "keyok(int,int)" FROM ncurses_LIB$ TYPE int
IMPORT "resize_term(int,int)" FROM ncurses_LIB$ TYPE int
IMPORT "resizeterm(int,int)" FROM ncurses_LIB$ TYPE int
IMPORT "set_escdelay(int)" FROM ncurses_LIB$ TYPE int
IMPORT "set_tabsize(int)" FROM ncurses_LIB$ TYPE int
IMPORT "use_default_colors(void)" FROM ncurses_LIB$ TYPE int
IMPORT "use_extended_names(int)" FROM ncurses_LIB$ TYPE int
IMPORT "use_legacy_coding(int)" FROM ncurses_LIB$ TYPE int
IMPORT "use_screen(long,long,void*)" FROM ncurses_LIB$ TYPE int
IMPORT "use_window(long,long,void*)" FROM ncurses_LIB$ TYPE int
IMPORT "wresize(long,int,int)" FROM ncurses_LIB$ TYPE int
IMPORT "nofilter(void)" FROM ncurses_LIB$ TYPE void
IMPORT "wgetparent(long)" FROM ncurses_LIB$ TYPE long
IMPORT "is_cleared(long)" FROM ncurses_LIB$ TYPE int
IMPORT "is_idcok (long)" FROM ncurses_LIB$ TYPE int
IMPORT "is_idlok (long)" FROM ncurses_LIB$ TYPE int
IMPORT "is_immedok (long)" FROM ncurses_LIB$ TYPE int
IMPORT "is_keypad (long)" FROM ncurses_LIB$ TYPE int
IMPORT "is_leaveok (long)" FROM ncurses_LIB$ TYPE int
IMPORT "is_nodelay (long)" FROM ncurses_LIB$ TYPE int
IMPORT "is_notimeout (long)" FROM ncurses_LIB$ TYPE int
IMPORT "is_scrollok (long)" FROM ncurses_LIB$ TYPE int
IMPORT "is_syncok (long)" FROM ncurses_LIB$ TYPE int
IMPORT "wgetscrreg (long,int*,int*)" FROM ncurses_LIB$ TYPE int

' attributes
CONST NCURSES_ATTR_SHIFT = 8
DEF FN NCURSES_BITS(mask,shift) = ((mask) << ((shift) + NCURSES_ATTR_SHIFT))

CONST A_NORMAL = 0
CONST A_ATTRIBUTES = NCURSES_BITS(~(1 - 1),0)
CONST A_CHARTEXT = (NCURSES_BITS(1,0) - 1)
CONST A_COLOR = NCURSES_BITS((1 << 8) - 1,0)
CONST A_STANDOUT = NCURSES_BITS(1,8)
CONST A_UNDERLINE = NCURSES_BITS(1,9)
CONST A_REVERSE = NCURSES_BITS(1,10)
CONST A_BLINK = NCURSES_BITS(1,11)
CONST A_DIM = NCURSES_BITS(1,12)
CONST A_BOLD = NCURSES_BITS(1,13)
CONST A_ALTCHARSET = NCURSES_BITS(1,14)
CONST A_INVIS = NCURSES_BITS(1,15)
CONST A_PROTECT = NCURSES_BITS(1,16)
CONST A_HORIZONTAL = NCURSES_BITS(1,17)
CONST A_LEFT = NCURSES_BITS(1,18)
CONST A_LOW = NCURSES_BITS(1,19)
CONST A_RIGHT = NCURSES_BITS(1,20)
CONST A_TOP = NCURSES_BITS(1,21)
CONST A_VERTICAL = NCURSES_BITS(1,22)

' These pseudo functions are always implemented as macros:
DEF FN getyx(win,y,x) =  (y = getcury(win), x = getcurx(win))
DEF FN getbegyx(win,y,x) = (y = getbegy(win), x = getbegx(win))
DEF FN getmaxyx(win,y,x) = (y = getmaxy(win), x = getmaxx(win))
DEF FN getparyx(win,y,x) = (y = getpary(win), x = getparx(win))

DEF FN getsyx(y,x) = do { if (newscr) { \
                 if (is_leaveok(newscr)) \
                (y) = (x) = -1; \
                 else \
                 getyx(newscr,(y), (x)); \
            } \
            } while(0)

DEF FN setsyx(y,x) = do { if (newscr) { \
                if ((y) == -1 && (x) == -1) \
                leaveok(newscr, TRUE); \
                else { \
                leaveok(newscr, FALSE); \
                wmove(newscr, (y), (x)); \
                } \
            } \
            } while(0)

' These miscellaneous pseudo functions are provided for compatibility:
DEF FN wgetstr(w, s) = wgetnstr(w, s, -1)
DEF FN getnstr(s, n) = wgetnstr(stdscr, s, n)
DEF FN setterm(term) = setupterm(term, 1, (int *)0)
DEF FN fixterm() = reset_prog_mode()
DEF FN resetterm() = reset_shell_mode()
DEF FN saveterm() = def_prog_mode()
DEF FN crmode() = cbreak()
DEF FN nocrmode() = nocbreak()
DEF FN gettmode()

' Pseudo-character tokens outside ASCII range.  The curses wgetch() function
' will return any given one of these only if the corresponding k- capability
' is defined in your terminal's terminfo entry.
'
' Some keys (KEY_A1, etc) are arranged like this:
'   a1     up    a3
'   left   b2    right
'   c1     down  c3
'
' A few key codes do not depend upon the terminfo entry.
CONST KEY_CODE_YES = 0400
CONST KEY_MIN = 0401
CONST KEY_BREAK = 0401
CONST KEY_SRESET = 0530
CONST KEY_RESET = 0531

' These definitions were generated by /build/buildd/ncurses-5.7+20090803/include/MKkey_defs.sh /build/buildd/ncurses-5.7+20090803/include/Caps
CONST KEY_DOWN = 0402
CONST KEY_UP = 0403
CONST KEY_LEFT = 0404
CONST KEY_RIGHT = 0405
CONST KEY_HOME = 0406
CONST KEY_BACKSPACE = 0407
CONST KEY_F0 = 0410
DEF FN KEY_F(n) = KEY_F0 + n
CONST KEY_DL = 0510
CONST KEY_IL = 0511
CONST KEY_DC = 0512
CONST KEY_IC = 0513
CONST KEY_EIC = 0514
CONST KEY_CLEAR = 0515
CONST KEY_EOS = 0516
CONST KEY_EOL = 0517
CONST KEY_SF = 0520
CONST KEY_SR = 0521
CONST KEY_NPAGE = 0522
CONST KEY_PPAGE = 0523
CONST KEY_STAB = 0524
CONST KEY_CTAB = 0525
CONST KEY_CATAB = 0526
CONST KEY_ENTER = 0527
CONST KEY_PRINT = 0532
CONST KEY_LL = 0533
CONST KEY_A1 = 0534
CONST KEY_A3 = 0535
CONST KEY_B2 = 0536
CONST KEY_C1 = 0537
CONST KEY_C3 = 0540
CONST KEY_BTAB = 0541
CONST KEY_BEG = 0542
CONST KEY_CANCEL = 0543
CONST KEY_CLOSE = 0544
CONST KEY_COMMAND = 0545
CONST KEY_COPY = 0546
CONST KEY_CREATE = 0547
CONST KEY_END = 0550
CONST KEY_EXIT = 0551
CONST KEY_FIND = 0552
CONST KEY_HELP = 0553
CONST KEY_MARK = 0554
CONST KEY_MESSAGE = 0555
CONST KEY_MOVE = 0556
CONST KEY_NEXT = 0557
CONST KEY_OPEN = 0560
CONST KEY_OPTIONS = 0561
CONST KEY_PREVIOUS = 0562
CONST KEY_REDO = 0563
CONST KEY_REFERENCE = 0564
CONST KEY_REFRESH = 0565
CONST KEY_REPLACE = 0566
CONST KEY_RESTART = 0567
CONST KEY_RESUME = 0570
CONST KEY_SAVE = 0571
CONST KEY_SBEG = 0572
CONST KEY_SCANCEL = 0573
CONST KEY_SCOMMAND = 0574
CONST KEY_SCOPY = 0575
CONST KEY_SCREATE = 0576
CONST KEY_SDC = 0577
CONST KEY_SDL = 0600
CONST KEY_SELECT = 0601
CONST KEY_SEND = 0602
CONST KEY_SEOL = 0603
CONST KEY_SEXIT = 0604
CONST KEY_SFIND = 0605
CONST KEY_SHELP = 0606
CONST KEY_SHOME = 0607
CONST KEY_SIC = 0610
CONST KEY_SLEFT = 0611
CONST KEY_SMESSAGE = 0612
CONST KEY_SMOVE = 0613
CONST KEY_SNEXT = 0614
CONST KEY_SOPTIONS = 0615
CONST KEY_SPREVIOUS = 0616
CONST KEY_SPRINT = 0617
CONST KEY_SREDO = 0620
CONST KEY_SREPLACE = 0621
CONST KEY_SRIGHT = 0622
CONST KEY_SRSUME = 0623
CONST KEY_SSAVE = 0624
CONST KEY_SSUSPEND = 0625
CONST KEY_SUNDO = 0626
CONST KEY_SUSPEND = 0627
CONST KEY_UNDO = 0630
CONST KEY_MOUSE = 0631
CONST KEY_RESIZE = 0632
CONST KEY_EVENT = 0633
CONST KEY_MAX = 0777

' mouse interface
DEF FN NCURSES_MOUSE_MASK(b,m) = ((m) << (((b) - 1) * 6))
CONST NCURSES_BUTTON_RELEASED = 1
CONST NCURSES_BUTTON_PRESSED = 2
CONST NCURSES_BUTTON_CLICKED = 4
CONST NCURSES_DOUBLE_CLICKED = 8
CONST NCURSES_TRIPLE_CLICKED = 16
CONST NCURSES_RESERVED_EVENT = 32

' event masks
CONST BUTTON1_RELEASED = NCURSES_MOUSE_MASK(1, NCURSES_BUTTON_RELEASED)
CONST BUTTON1_PRESSED = NCURSES_MOUSE_MASK(1, NCURSES_BUTTON_PRESSED)
CONST BUTTON1_CLICKED = NCURSES_MOUSE_MASK(1, NCURSES_BUTTON_CLICKED)
CONST BUTTON1_DOUBLE_CLICKED = NCURSES_MOUSE_MASK(1, NCURSES_DOUBLE_CLICKED)
CONST BUTTON1_TRIPLE_CLICKED = NCURSES_MOUSE_MASK(1, NCURSES_TRIPLE_CLICKED)
CONST BUTTON2_RELEASED = NCURSES_MOUSE_MASK(2, NCURSES_BUTTON_RELEASED)
CONST BUTTON2_PRESSED = NCURSES_MOUSE_MASK(2, NCURSES_BUTTON_PRESSED)
CONST BUTTON2_CLICKED = NCURSES_MOUSE_MASK(2, NCURSES_BUTTON_CLICKED)
CONST BUTTON2_DOUBLE_CLICKED = NCURSES_MOUSE_MASK(2, NCURSES_DOUBLE_CLICKED)
CONST BUTTON2_TRIPLE_CLICKED = NCURSES_MOUSE_MASK(2, NCURSES_TRIPLE_CLICKED)
CONST BUTTON3_RELEASED = NCURSES_MOUSE_MASK(3, NCURSES_BUTTON_RELEASED)
CONST BUTTON3_PRESSED = NCURSES_MOUSE_MASK(3, NCURSES_BUTTON_PRESSED)
CONST BUTTON3_CLICKED = NCURSES_MOUSE_MASK(3, NCURSES_BUTTON_CLICKED)
CONST BUTTON3_DOUBLE_CLICKED = NCURSES_MOUSE_MASK(3, NCURSES_DOUBLE_CLICKED)
CONST BUTTON3_TRIPLE_CLICKED = NCURSES_MOUSE_MASK(3, NCURSES_TRIPLE_CLICKED)
CONST BUTTON4_RELEASED = NCURSES_MOUSE_MASK(4, NCURSES_BUTTON_RELEASED)
CONST BUTTON4_PRESSED = NCURSES_MOUSE_MASK(4, NCURSES_BUTTON_PRESSED)
CONST BUTTON4_CLICKED = NCURSES_MOUSE_MASK(4, NCURSES_BUTTON_CLICKED)
CONST BUTTON4_DOUBLE_CLICKED = NCURSES_MOUSE_MASK(4, NCURSES_DOUBLE_CLICKED)
CONST BUTTON4_TRIPLE_CLICKED = NCURSES_MOUSE_MASK(4, NCURSES_TRIPLE_CLICKED)

' In 32 bits the version-1 scheme does not provide enough space for a 5th
' button, unless we choose to change the ABI by omitting the reserved-events.
CONST BUTTON1_RESERVED_EVENT = NCURSES_MOUSE_MASK(1, NCURSES_RESERVED_EVENT)
CONST BUTTON2_RESERVED_EVENT = NCURSES_MOUSE_MASK(2, NCURSES_RESERVED_EVENT)
CONST BUTTON3_RESERVED_EVENT = NCURSES_MOUSE_MASK(3, NCURSES_RESERVED_EVENT)
CONST BUTTON4_RESERVED_EVENT = NCURSES_MOUSE_MASK(4, NCURSES_RESERVED_EVENT)

CONST BUTTON_CTRL = NCURSES_MOUSE_MASK(5, 1)
CONST BUTTON_SHIFT = NCURSES_MOUSE_MASK(5, 2)
CONST BUTTON_ALT = NCURSES_MOUSE_MASK(5, 4)
CONST REPORT_MOUSE_POSITION = NCURSES_MOUSE_MASK(5, 8)
CONST ALL_MOUSE_EVENTS = (REPORT_MOUSE_POSITION - 1)

' macros to extract single event-bits from masks
DEF FN BUTTON_RELEASE(e, x) = ((e) & NCURSES_MOUSE_MASK(x, 001))
DEF FN BUTTON_PRESS(e, x) = ((e) & NCURSES_MOUSE_MASK(x, 002))
DEF FN BUTTON_CLICK(e, x) = ((e) & NCURSES_MOUSE_MASK(x, 004))
DEF FN BUTTON_DOUBLE_CLICK(e, x) = ((e) & NCURSES_MOUSE_MASK(x, 010))
DEF FN BUTTON_TRIPLE_CLICK(e, x) = ((e) & NCURSES_MOUSE_MASK(x, 020))
DEF FN BUTTON_RESERVED_EVENT(e, x) = ((e) & NCURSES_MOUSE_MASK(x, 040))

IMPORT "has_mouse(void)" FROM ncurses_LIB$ TYPE int
IMPORT "getmouse(long)" FROM ncurses_LIB$ TYPE int
IMPORT "ungetmouse(long)" FROM ncurses_LIB$ TYPE int
IMPORT "mousemask(long, long)" FROM ncurses_LIB$ TYPE long
IMPORT "wenclose(long, int, int)" FROM ncurses_LIB$ TYPE  int
IMPORT "mouseinterval(int)" FROM ncurses_LIB$ TYPE int
IMPORT "wmouse_trafo(long,int*,int*,int)" FROM ncurses_LIB$ TYPE int
IMPORT "mouse_trafo(int*,int*,int)" FROM ncurses_LIB$ TYPE int

DEF FN mouse_trafo(y,x,to_screen) = wmouse_trafo(stdscr,y,x,to_screen)

' other non-XSI functions
IMPORT "mcprint(char*,int)" FROM ncurses_LIB$ TYPE int
IMPORT "has_key(int)" FROM ncurses_LIB$ TYPE int

CATCH RESET