]> gitweb.factorcode.org Git - factor.git/blobdiff - extra/curses/ffi/ffi.factor
use radix literals
[factor.git] / extra / curses / ffi / ffi.factor
index b1c481a5769c5333b3ce462ae47c3994f162a250..c3b0d42cd260b97529c67708352d053b01d794dd 100644 (file)
@@ -1,85 +1,94 @@
 ! Copyright (C) 2008 Doug Coleman.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: accessors alien alien.syntax combinators kernel system ;
+USING: accessors alien alien.c-types alien.libraries
+alien.syntax classes.struct combinators kernel math system unix.types ;
 IN: curses.ffi
 
 << "curses" {
-    { [ os winnt? ]  [ "libcurses.dll" ] }
+    { [ os windows? ]  [ "libcurses.dll" ] }
     { [ os macosx? ] [ "libcurses.dylib" ] }
-    { [ os unix?  ]  [ "libcurses.so" ] }
-} cond "cdecl" add-library >>
+    { [ os unix?  ]  [ "libncursesw.so" ] }
+} cond cdecl add-library >>
 
-TYPEDEF: void* WINDOW*
-TYPEDEF: void* SCREEN*
+C-TYPE: SCREEN
 TYPEDEF: void* va_list
 
 TYPEDEF: uint chtype
 TYPEDEF: chtype attr_t
 TYPEDEF: short NCURSES_SIZE_T
 TYPEDEF: ushort wchar_t
+TYPEDEF: ulong mmask_t
 
 CONSTANT: CCHARW_MAX  5
 
-C-STRUCT: cchar_t
-    { "attr_t" "attr" }
-    { { "wchar_t" CCHARW_MAX } "chars" } ;
+CONSTANT: ERR -1
+CONSTANT: FALSE 0
+CONSTANT: TRUE 1
 
-C-STRUCT: pdat
-    { "NCURSES_SIZE_T" "_pad_y" }
-    { "NCURSES_SIZE_T" "_pad_x" }
-    { "NCURSES_SIZE_T" "_pad_top" }
-    { "NCURSES_SIZE_T" "_pad_left" }
-    { "NCURSES_SIZE_T" "_pad_bottom" }
-    { "NCURSES_SIZE_T" "_pad_right" } ;
+STRUCT: cchar_t
+{ attr attr_t }
+{ chars { wchar_t CCHARW_MAX } } ;
 
-C-STRUCT: c-window
-    { "NCURSES_SIZE_T" "_cury" }
-    { "NCURSES_SIZE_T" "_curx" }
+STRUCT: pdat
+{ _pad_y NCURSES_SIZE_T }
+{ _pad_x NCURSES_SIZE_T }
+{ _pad_top NCURSES_SIZE_T }
+{ _pad_left NCURSES_SIZE_T }
+{ _pad_bottom NCURSES_SIZE_T }
+{ _pad_right NCURSES_SIZE_T } ;
 
-    { "NCURSES_SIZE_T" "_maxy" }
-    { "NCURSES_SIZE_T" "_maxx" }
-    { "NCURSES_SIZE_T" "_begy" }
-    { "NCURSES_SIZE_T" "_begx" }
+STRUCT: WINDOW
+{ _cury NCURSES_SIZE_T }
+{ _curx NCURSES_SIZE_T }
 
-    { "short"  " _flags" }
+{ _maxy NCURSES_SIZE_T }
+{ _maxx NCURSES_SIZE_T }
+{ _begy NCURSES_SIZE_T }
+{ _begx NCURSES_SIZE_T }
 
-    { "attr_t"  "_attrs" }
-    { "chtype"  "_bkgd" }
+{ _flags short }
 
-    { "bool"    "_notimeout" }
-    { "bool"    "_clear" }
-    { "bool"    "_leaveok" }
-    { "bool"    "_scroll" }
-    { "bool"    "_idlok" }
-    { "bool"    "_idcok" }
-    { "bool"    "_immed" }
-    { "bool"    "_sync" }
-    { "bool"    "_use_keypad" }
-    { "int"     "_delay" }
+{ _attrs attr_t }
+{ _bkgd chtype }
 
-    { "char*" "_line" }
-    { "NCURSES_SIZE_T" "_regtop" }
-    { "NCURSES_SIZE_T" "_regbottom" }
+{ _notimeout bool }
+{ _clear bool }
+{ _leaveok bool }
+{ _scroll bool }
+{ _idlok bool }
+{ _idcok bool }
+{ _immed bool }
+{ _sync bool }
+{ _use_keypad bool }
+{ _delay int }
 
-    { "int" "_parx" }
-    { "int" "_pary" }
-    { "WINDOW*" "_parent" }
+{ _line c-string }
+{ _regtop NCURSES_SIZE_T }
+{ _regbottom NCURSES_SIZE_T }
 
-    { "pdat" "_pad" }
+{ _parx int }
+{ _pary int }
+{ _parent WINDOW* }
 
-    { "NCURSES_SIZE_T" "_yoffset" }
+{ _pad pdat }
 
-    { "cchar_t"  "_bkgrnd" } ;
+{ _yoffset NCURSES_SIZE_T }
+
+{ _bkgrnd cchar_t } ;
+
+STRUCT: MEVENT
+    { id short }
+    { x int } { y int } { z int }
+    { bstate mmask_t } ;
 
 LIBRARY: curses
 
-: stdscr ( -- alien )
-    "stdscr" "curses" library dll>> dlsym ;
+C-GLOBAL: void* stdscr
 
 FUNCTION: WINDOW* initscr ( ) ;
 FUNCTION: int endwin ( ) ;
 FUNCTION: bool isendwin ( ) ;
-FUNCTION: SCREEN* newterm ( char* type, FILE* outfd, FILE* infd ) ;
+FUNCTION: SCREEN* newterm ( c-string type, FILE* outfd, FILE* infd ) ;
 FUNCTION: SCREEN* set_term ( SCREEN* new ) ;
 FUNCTION: void delscreen ( SCREEN* sp ) ;
 
@@ -134,13 +143,13 @@ FUNCTION: int scrollok ( WINDOW* win, bool bf ) ;
 FUNCTION: int nl ( ) ;
 FUNCTION: int nonl ( ) ;
 
-FUNCTION: int erase (  ) ;
+FUNCTION: int erase ( ) ;
 FUNCTION: int werase ( WINDOW* win ) ;
-FUNCTION: int clear (  ) ;
+FUNCTION: int clear ( ) ;
 FUNCTION: int wclear ( WINDOW* win ) ;
-FUNCTION: int clrtobot (  ) ;
+FUNCTION: int clrtobot ( ) ;
 FUNCTION: int wclrtobot ( WINDOW* win ) ;
-FUNCTION: int clrtoeol (  ) ;
+FUNCTION: int clrtoeol ( ) ;
 FUNCTION: int wclrtoeol ( WINDOW* win ) ;
 
 FUNCTION: int refresh ( ) ;
@@ -157,46 +166,45 @@ FUNCTION: int mvwgetch ( WINDOW* win, int y, int x ) ;
 FUNCTION: int ungetch ( int ch ) ;
 FUNCTION: int has_key ( int ch ) ;
 
-FUNCTION: int getstr ( char* str ) ;
-FUNCTION: int getnstr ( char* str, int n ) ;
-FUNCTION: int wgetstr ( WINDOW* win, char* str ) ;
-FUNCTION: int wgetnstr ( WINDOW* win, char* str, int n ) ;
-FUNCTION: int mvgetstr ( int y, int x, char* str ) ;
-FUNCTION: int mvwgetstr ( WINDOW* win, int y, int x, char* str ) ;
-FUNCTION: int mvgetnstr ( int y, int x, char* str, int n ) ;
-FUNCTION: int mvwgetnstr ( WINDOW* win, int y, int x, char* str, int n ) ;
-
-FUNCTION: int printw ( char* fmt, int lol ) ;
-FUNCTION: int wprintw ( WINDOW* win, char* fmt, int lol ) ;
-FUNCTION: int mvprintw ( int y, int x, char* fmt, int lol ) ;
-FUNCTION: int mvwprintw ( WINDOW* win, int y, int x, char* fmt, int lol ) ;
-FUNCTION: int vwprintw ( WINDOW* win, char* fmt, va_list varglist ) ;
-FUNCTION: int vw_printw ( WINDOW* win, char* fmt, va_list varglist ) ;
+FUNCTION: int getstr ( c-string str ) ;
+FUNCTION: int getnstr ( c-string str, int n ) ;
+FUNCTION: int wgetstr ( WINDOW* win, c-string str ) ;
+FUNCTION: int wgetnstr ( WINDOW* win, c-string str, int n ) ;
+FUNCTION: int mvgetstr ( int y, int x, c-string str ) ;
+FUNCTION: int mvwgetstr ( WINDOW* win, int y, int x, c-string str ) ;
+FUNCTION: int mvgetnstr ( int y, int x, c-string str, int n ) ;
+FUNCTION: int mvwgetnstr ( WINDOW* win, int y, int x, c-string str, int n ) ;
+
+FUNCTION: int printw ( c-string fmt, int lol ) ;
+FUNCTION: int wprintw ( WINDOW* win, c-string fmt, int lol ) ;
+FUNCTION: int mvprintw ( int y, int x, c-string fmt, int lol ) ;
+FUNCTION: int mvwprintw ( WINDOW* win, int y, int x, c-string fmt, int lol ) ;
+FUNCTION: int vwprintw ( WINDOW* win, c-string fmt, va_list varglist ) ;
+FUNCTION: int vw_printw ( WINDOW* win, c-string fmt, va_list varglist ) ;
 
 FUNCTION: int move ( int y, int x ) ;
 FUNCTION: int wmove ( WINDOW* win, int y, int x ) ;
 
-
 FUNCTION: int scroll ( WINDOW* win ) ;
 FUNCTION: int scrl ( int n ) ;
 FUNCTION: int wscrl ( WINDOW* win, int n ) ;
 
-       ! int setupterm(char *term, int fildes, int *errret);
-       ! int setterm(char *term);
-       ! TERMINAL *set_curterm(TERMINAL *nterm);
-       ! int del_curterm(TERMINAL *oterm);
-       ! int restartterm(const char *term, int fildes, int *errret);
-       ! char *tparm(char *str, ...);
-       ! int tputs(const char *str, int affcnt, int (*putc)(int));
-       ! int putp(const char *str);
-       ! int vidputs(chtype attrs, int (*putc)(int));
-       ! int vidattr(chtype attrs);
-       ! int vid_puts(attr_t attrs, short pair, void *opts, int (*putc)(char));
-       ! int vid_attr(attr_t attrs, short pair, void *opts);
+! int setupterm(char *term, int fildes, int *errret);
+! int setterm(char *term);
+! TERMINAL *set_curterm(TERMINAL *nterm);
+! int del_curterm(TERMINAL *oterm);
+! int restartterm(const char *term, int fildes, int *errret);
+! char *tparm(char *str, ...);
+! int tputs(const char *str, int affcnt, int (*putc)(int));
+! int putp(const char *str);
+! int vidputs(chtype attrs, int (*putc)(int));
+! int vidattr(chtype attrs);
+! int vid_puts(attr_t attrs, short pair, void *opts, int (*putc)(char));
+! int vid_attr(attr_t attrs, short pair, void *opts);
 FUNCTION: int mvcur ( int oldrow, int oldcol, int newrow, int newcol ) ;
-       ! int tigetflag(char *capname);
-       ! int tigetnum(char *capname);
-       ! char *tigetstr(char *capname);
+! int tigetflag(char *capname);
+! int tigetnum(char *capname);
+! char *tigetstr(char *capname);
 
 FUNCTION: int touchwin ( WINDOW* win ) ;
 FUNCTION: int touchline ( WINDOW* win, int start, int count ) ;
@@ -221,11 +229,54 @@ FUNCTION: int winsdelln ( WINDOW* win, int n ) ;
 FUNCTION: int insertln ( ) ;
 FUNCTION: int winsertln ( WINDOW* win ) ;
 
-FUNCTION: int addstr ( char* str ) ;
-FUNCTION: int addnstr ( char* str, int n ) ;
-FUNCTION: int waddstr ( WINDOW* win, char* str ) ;
-FUNCTION: int waddnstr ( WINDOW* win, char* str, int n ) ;
-FUNCTION: int mvaddstr ( int y, int x, char* str ) ;
-FUNCTION: int mvaddnstr ( int y, int x, char* str, int n ) ;
-FUNCTION: int mvwaddstr ( WINDOW* win, int y, int x, char* str ) ;
-FUNCTION: int mvwaddnstr ( WINDOW* win, int y, int x, char* str, int n ) ;
+FUNCTION: int addstr ( c-string str ) ;
+FUNCTION: int addnstr ( c-string str, int n ) ;
+FUNCTION: int waddstr ( WINDOW* win, c-string str ) ;
+FUNCTION: int waddnstr ( WINDOW* win, c-string str, int n ) ;
+FUNCTION: int mvaddstr ( int y, int x, c-string str ) ;
+FUNCTION: int mvaddnstr ( int y, int x, c-string str, int n ) ;
+FUNCTION: int mvwaddstr ( WINDOW* win, int y, int x, c-string str ) ;
+FUNCTION: int mvwaddnstr ( WINDOW* win, int y, int x, c-string str, int n ) ;
+
+FUNCTION: int waddch ( WINDOW* win, chtype ch ) ;
+
+FUNCTION: int start_color ( ) ;
+FUNCTION: int init_pair ( short pair, short f, short b ) ;
+FUNCTION: int init_color ( short color, short r, short g, short b ) ;
+FUNCTION: bool has_colors ( ) ;
+FUNCTION: bool can_change_color ( ) ;
+FUNCTION: int color_content ( short color, short* r, short* g, short* b ) ;
+FUNCTION: int pair_content ( short pair, short* f, short* b ) ;
+
+C-GLOBAL: int COLORS
+C-GLOBAL: int COLOR_PAIRS
+
+: COLOR_PAIR ( n -- n' ) 8 shift ; inline foldable
+
+FUNCTION: int wcolor_set ( WINDOW* win, short color_pair_number, void* opts ) ;
+
+FUNCTION: int wattron ( WINDOW* win, int attrs ) ;
+FUNCTION: int wattroff ( WINDOW* win, int attrs ) ;
+FUNCTION: int wattrset ( WINDOW* win, int attrs ) ;
+
+: NCURSES_MOUSE_MASK ( b m -- mask ) swap 1 - 6 * shift ; inline
+
+CONSTANT: NCURSES_BUTTON_RELEASED 0o01
+CONSTANT: NCURSES_BUTTON_PRESSED  0o02
+CONSTANT: NCURSES_BUTTON_CLICKED  0o04
+CONSTANT: NCURSES_DOUBLE_CLICKED  0o10
+CONSTANT: NCURSES_TRIPLE_CLICKED  0o20
+CONSTANT: NCURSES_RESERVED_EVENT  0o40
+
+FUNCTION: int getmouse ( MEVENT* event ) ;
+FUNCTION: int ungetmouse ( MEVENT* event ) ;
+FUNCTION: mmask_t mousemask ( mmask_t newmask, mmask_t* oldmask ) ;
+FUNCTION: bool wenclose ( WINDOW* win, int y, int x ) ;
+FUNCTION: bool mouse_trafo ( int* pY, int* pX, bool to_screen ) ;
+FUNCTION: bool wmouse_trafo ( WINDOW* win, int* pY, int* pX, bool to_screen ) ;
+FUNCTION: int mouseinterval ( int erval ) ;
+
+FUNCTION: int wborder ( WINDOW* win, chtype ls, chtype rs, chtype ts, chtype bs, chtype tl, chtype tr, chtype bl, chtype br ) ;
+FUNCTION: int box ( WINDOW* win, chtype verch, chtype horch ) ;
+FUNCTION: int whline ( WINDOW* win, chtype ch, int n ) ;
+FUNCTION: int wvline ( WINDOW* win, chtype ch, int n ) ;