'
' FORM 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
'
' form.h
'
'***************************************************************************
' Copyright (c) 1998-2003,2004 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:  Juergen Pfeifer, 1995,1997                                    *
'***************************************************************************

CATCH GOTO form_handle_error

form_LIB$ = "libform.so"
form_seq = -1

LABEL form_import_retry
    INCR form_seq
    form_retry = FALSE
    IMPORT "form_init(long)" FROM form_LIB$ TYPE long
    IF form_retry THEN GOTO form_import_retry

GOTO form_continue

LABEL form_handle_error
    IF form_seq IS 0 THEN form_LIB$ = "libform.so.0"
    ELSE form_LIB$ = CONCAT$(LEFT$(form_LIB$, INSTRREV(form_LIB$, ".")), STR$(form_seq))
    IF form_seq < 10 THEN
        form_retry = TRUE
    ELSE
        PRINT "No form library found!"
        END
    END IF
    RESUME

LABEL form_continue

' field justification
CONST NO_JUSTIFICATION =  0
CONST JUSTIFY_LEFT = 1
CONST JUSTIFY_CENTER = 2
CONST JUSTIFY_RIGHT = 3

' field options
CONST O_VISIBLE = 0x0001
CONST O_ACTIVE = 0x0002
CONST O_PUBLIC = 0x0004
CONST O_EDIT = 0x0008
CONST O_WRAP = 0x0010
CONST O_BLANK = 0x0020
CONST O_AUTOSKIP = 0x0040
CONST O_NULLOK = 0x0080U
CONST O_PASSOK = 0x0100U
CONST O_STATIC = 0x0200U

' form options
CONST O_NL_OVERLOAD = 0x0001
CONST O_BS_OVERLOAD = 0x0002

' form driver commands
CONST REQ_NEXT_PAGE = KEY_MAX + 1
CONST REQ_PREV_PAGE = KEY_MAX + 2
CONST REQ_FIRST_PAGE = KEY_MAX + 3
CONST REQ_LAST_PAGE = KEY_MAX + 4
CONST REQ_NEXT_FIELD = KEY_MAX + 5
CONST REQ_PREV_FIELD = KEY_MAX + 6
CONST REQ_FIRST_FIELD = KEY_MAX + 7
CONST REQ_LAST_FIELD = KEY_MAX + 8
CONST REQ_SNEXT_FIELD = KEY_MAX + 9
CONST REQ_SPREV_FIELD = KEY_MAX + 10
CONST REQ_SFIRST_FIELD = KEY_MAX + 11
CONST REQ_SLAST_FIELD = KEY_MAX + 12
CONST REQ_LEFT_FIELD = KEY_MAX + 13
CONST REQ_RIGHT_FIELD = KEY_MAX + 14
CONST REQ_UP_FIELD = KEY_MAX + 15
CONST REQ_DOWN_FIELD = KEY_MAX + 16
CONST REQ_NEXT_CHAR = KEY_MAX + 17
CONST REQ_PREV_CHAR = KEY_MAX + 18
CONST REQ_NEXT_LINE = KEY_MAX + 19
CONST REQ_PREV_LINE = KEY_MAX + 20
CONST REQ_NEXT_WORD = KEY_MAX + 21
CONST REQ_PREV_WORD = KEY_MAX + 22
CONST REQ_BEG_FIELD = KEY_MAX + 23
CONST REQ_END_FIELD = KEY_MAX + 24
CONST REQ_BEG_LINE = KEY_MAX + 25
CONST REQ_END_LINE = KEY_MAX + 26
CONST REQ_LEFT_CHAR = KEY_MAX + 27
CONST REQ_RIGHT_CHAR = KEY_MAX + 28
CONST REQ_UP_CHAR = KEY_MAX + 29
CONST REQ_DOWN_CHAR = KEY_MAX + 30
CONST REQ_NEW_LINE = KEY_MAX + 31
CONST REQ_INS_CHAR = KEY_MAX + 32
CONST REQ_INS_LINE = KEY_MAX + 33
CONST REQ_DEL_CHAR = KEY_MAX + 34
CONST REQ_DEL_PREV = KEY_MAX + 35
CONST REQ_DEL_LINE = KEY_MAX + 36
CONST REQ_DEL_WORD = KEY_MAX + 37
CONST REQ_CLR_EOL = KEY_MAX + 38
CONST REQ_CLR_EOF = KEY_MAX + 39
CONST REQ_CLR_FIELD = KEY_MAX + 40
CONST REQ_OVL_MODE = KEY_MAX + 41
CONST REQ_INS_MODE = KEY_MAX + 42
CONST REQ_SCR_FLINE = KEY_MAX + 43
CONST REQ_SCR_BLINE = KEY_MAX + 44
CONST REQ_SCR_FPAGE = KEY_MAX + 45
CONST REQ_SCR_BPAGE = KEY_MAX + 46
CONST REQ_SCR_FHPAGE = KEY_MAX + 47
CONST REQ_SCR_BHPAGE = KEY_MAX + 48
CONST REQ_SCR_FCHAR = KEY_MAX + 49
CONST REQ_SCR_BCHAR = KEY_MAX + 50
CONST REQ_SCR_HFLINE = KEY_MAX + 51
CONST REQ_SCR_HBLINE = KEY_MAX + 52
CONST REQ_SCR_HFHALF = KEY_MAX + 53
CONST REQ_SCR_HBHALF = KEY_MAX + 54
CONST REQ_VALIDATION = KEY_MAX + 55
CONST REQ_NEXT_CHOICE = KEY_MAX + 56
CONST REQ_PREV_CHOICE = KEY_MAX + 57
CONST MIN_FORM_COMMAND = KEY_MAX + 1
CONST MAX_FORM_COMMAND = KEY_MAX + 57
CONST MAX_COMMAND = KEY_MAX + 128

'*********************************************
'  FIELDTYPE routines  unimplemented for now *
'*********************************************
'IMPORT(FIELDTYPE *) new_fieldtype(bool (* const field_check)(FIELD *,const void *),    bool (* const char_check)(int,const void *))  FROM form_LIB$ TYPE 
'IMPORT(FIELDTYPE *) link_fieldtype(    FIELDTYPE *, FIELDTYPE *) FROM form_LIB$ TYPE 
IMPORT "free_fieldtype(long)" FROM form_LIB$ TYPE int
'IMPORT set_fieldtype_arg (long,        void * (* const make_arg)(va_list *), void * (* const copy_arg)(const void *), void (* const free_arg)(void *)) FROM form_LIB$ TYPE int
'IMPORT set_fieldtype_choice(long, bool (* const next_choice)(FIELD *,const void *), bool (* const prev_choice)(FIELD *,const void *)) FROM form_LIB$ TYPE int

'*******************
'  FIELD routines  *
'*******************
IMPORT "new_field(int,int,int,int,int,int)" FROM form_LIB$ TYPE long
IMPORT "dup_field(long,int,int)" FROM form_LIB$ TYPE long
IMPORT "link_field(long,int,int)" FROM form_LIB$ TYPE long
IMPORT "free_field(long)" FROM form_LIB$ TYPE int
IMPORT "field_info(long,int*,int*,int*,int*,int*,int*)" FROM form_LIB$ TYPE int
IMPORT "dynamic_field_info(long,int*,int*,int*)" FROM form_LIB$ TYPE int
IMPORT "set_max_field(long,int)" FROM form_LIB$ TYPE int
IMPORT "move_field(long,int,int)" FROM form_LIB$ TYPE int
IMPORT "set_field_type(long,long,...)" FROM form_LIB$ TYPE int
IMPORT "set_new_page(long,int)" FROM form_LIB$ TYPE int
IMPORT "set_field_just(long,int)" FROM form_LIB$ TYPE int
IMPORT "field_just(long)" FROM form_LIB$ TYPE int
IMPORT "set_field_fore(long,long)" FROM form_LIB$ TYPE int
IMPORT "set_field_back(long,long)" FROM form_LIB$ TYPE int
IMPORT "set_field_pad(long,int)" FROM form_LIB$ TYPE int
IMPORT "field_pad (long)" FROM form_LIB$ TYPE int
IMPORT "set_field_buffer(long,int,char*)" FROM form_LIB$ TYPE int
IMPORT "set_field_status(long,int)" FROM form_LIB$ TYPE int
IMPORT "set_field_userptr(long,void*)" FROM form_LIB$ TYPE int
IMPORT "set_field_opts(long,long)" FROM form_LIB$ TYPE int
IMPORT "field_opts_on(long,long)" FROM form_LIB$ TYPE int
IMPORT "field_opts_off(long,long)" FROM form_LIB$ TYPE int
IMPORT "field_fore(long)" FROM form_LIB$ TYPE long
IMPORT "field_back(long)" FROM form_LIB$ TYPE long
IMPORT "new_page(long)" FROM form_LIB$ TYPE int
IMPORT "field_status(long)" FROM form_LIB$ TYPE int
IMPORT "field_arg(long)" FROM form_LIB$ TYPE void*
IMPORT "field_userptr(long)" FROM form_LIB$ TYPE void*
IMPORT "field_type(long)" FROM form_LIB$ TYPE long
IMPORT "field_buffer(long,int)" FROM form_LIB$ TYPE char*
IMPORT "field_opts(long)" FROM form_LIB$ TYPE long

'******************
'  FORM routines  *
'******************
IMPORT "new_form(long)" FROM form_LIB$ TYPE long
IMPORT "form_fields(long)" FROM form_LIB$ TYPE long
IMPORT "current_field(long)" FROM form_LIB$ TYPE long
IMPORT "form_win(long)" FROM form_LIB$ TYPE long
IMPORT "form_sub(long)" FROM form_LIB$ TYPE long
IMPORT "form_term(long)" FROM form_LIB$ TYPE long
IMPORT "field_init(long)" FROM form_LIB$ TYPE long
IMPORT "field_term(long)" FROM form_LIB$ TYPE long

IMPORT "free_form(long)" FROM form_LIB$ TYPE int
IMPORT "set_form_fields(long,long)" FROM form_LIB$ TYPE int
IMPORT "field_count(long)" FROM form_LIB$ TYPE int
IMPORT "set_form_win(long,long)" FROM form_LIB$ TYPE int
IMPORT "set_form_sub(long,long)" FROM form_LIB$ TYPE int
IMPORT "set_current_field(long,long)" FROM form_LIB$ TYPE int
IMPORT "field_index(long)" FROM form_LIB$ TYPE int
IMPORT "set_form_page(long,int)" FROM form_LIB$ TYPE int
IMPORT "form_page(long)" FROM form_LIB$ TYPE int
IMPORT "scale_form(long,int*,int*)" FROM form_LIB$ TYPE int
IMPORT "set_form_init(long,long)" FROM form_LIB$ TYPE int
IMPORT "set_form_term(long,long)" FROM form_LIB$ TYPE int
IMPORT "set_field_init(long,long)" FROM form_LIB$ TYPE int
IMPORT "set_field_term(long,long)" FROM form_LIB$ TYPE int
IMPORT "post_form(long)" FROM form_LIB$ TYPE int
IMPORT "unpost_form(long)" FROM form_LIB$ TYPE int
IMPORT "pos_form_cursor(long)" FROM form_LIB$ TYPE int
IMPORT "form_driver(long,int)" FROM form_LIB$ TYPE int
IMPORT "set_form_userptr(long,void*)" FROM form_LIB$ TYPE int
IMPORT "set_form_opts(long,long)" FROM form_LIB$ TYPE int
IMPORT "form_opts_on(long,long)" FROM form_LIB$ TYPE int
IMPORT "form_opts_off(long,long)" FROM form_LIB$ TYPE int
IMPORT "form_request_by_name(char*)" FROM form_LIB$ TYPE int
IMPORT "form_request_name(int)" FROM form_LIB$ TYPE char*
IMPORT "form_userptr(long)" FROM form_LIB$ TYPE void*
IMPORT "form_opts(long)" FROM form_LIB$ TYPE long
IMPORT "data_ahead(long)" FROM form_LIB$ TYPE int
IMPORT "data_behind(long)" FROM form_LIB$ TYPE int

CATCH RESET