wez Fri Sep 27 13:03:54 2002 EDT Modified files: /php4/ext/ncurses config.m4 ncurses.c ncurses_fe.c ncurses_functions.c php_ncurses.h php_ncurses_fe.h Log: Implement some more window routines, add pad functions. Add panel functions when libpanel is also detected. Register STDSCR constant during ncurses_init().
Index: php4/ext/ncurses/config.m4 diff -u php4/ext/ncurses/config.m4:1.12 php4/ext/ncurses/config.m4:1.13 --- php4/ext/ncurses/config.m4:1.12 Wed Jun 26 18:22:47 2002 +++ php4/ext/ncurses/config.m4 Fri Sep 27 13:03:53 2002 @@ -1,5 +1,5 @@ dnl -dnl $Id: config.m4,v 1.12 2002/06/26 22:22:47 avsm Exp $ +dnl $Id: config.m4,v 1.13 2002/09/27 17:03:53 wez Exp $ dnl PHP_ARG_WITH(ncurses, for ncurses support, @@ -37,13 +37,23 @@ PHP_CHECK_LIBRARY($LIBNAME, $LIBSYMBOL, [ AC_DEFINE(HAVE_NCURSESLIB,1,[ ]) - PHP_ADD_LIBRARY_WITH_PATH($LIBNAME, $NCURSES_DIR/lib, NCURSES_SHARED_LIBADD) + + PHP_ADD_LIBRARY_WITH_PATH($LIBNAME, $NCURSES_DIR/lib, NCURSES_SHARED_LIBADD) + + PHP_CHECK_LIBRARY(panel, new_panel, [ + AC_DEFINE(HAVE_NCURSES_PANEL,1,[ ]) + PHP_ADD_LIBRARY_WITH_PATH(panel, $NCURSES_DIR/lib, NCURSES_SHARED_LIBADD) + ], [ + ], [ -L$NCURSES_DIR/lib -l$LIBNAME -lm + ]) + + ], [ AC_MSG_ERROR(Wrong ncurses lib version or lib not found) ], [ -L$NCURSES_DIR/lib -lm ]) - + AC_CHECK_LIB($LIBNAME, color_set, [AC_DEFINE(HAVE_NCURSES_COLOR_SET, 1, [ ])]) AC_CHECK_LIB($LIBNAME, slk_color, [AC_DEFINE(HAVE_NCURSES_SLK_COLOR, 1, [ ])]) AC_CHECK_LIB($LIBNAME, asume_default_colors, [AC_DEFINE(HAVE_NCURSES_ASSUME_DEFAULT_COLORS, 1, [ ])]) Index: php4/ext/ncurses/ncurses.c diff -u php4/ext/ncurses/ncurses.c:1.16 php4/ext/ncurses/ncurses.c:1.17 --- php4/ext/ncurses/ncurses.c:1.16 Thu Feb 28 03:26:26 2002 +++ php4/ext/ncurses/ncurses.c Fri Sep 27 13:03:53 2002 @@ -30,10 +30,12 @@ */ /* True global resources - no need for thread safety here */ -int le_ncurses; - +int le_ncurses_windows; +#if HAVE_NCURSES_PANEL +int le_ncurses_panels; +#endif -static void ncurses_destruct(zend_rsrc_list_entry *rsrc TSRMLS_DC) +static void ncurses_destruct_window(zend_rsrc_list_entry *rsrc TSRMLS_DC) { WINDOW **pwin = (WINDOW **)rsrc->ptr; @@ -41,6 +43,15 @@ efree(pwin); } +#if HAVE_NCURSES_PANEL +static void ncurses_destruct_panel(zend_rsrc_list_entry *rsrc TSRMLS_DC) +{ + PANEL **ppanel = (PANEL **)rsrc->ptr; + + del_panel(*ppanel); + efree(ppanel); +} +#endif /* {{{ ncurses_module_entry */ @@ -238,7 +249,10 @@ PHP_NCURSES_CONST(ALL_MOUSE_EVENTS); PHP_NCURSES_CONST(REPORT_MOUSE_POSITION); - le_ncurses = zend_register_list_destructors_ex(ncurses_destruct, NULL, "ncurses_handle", module_number); + le_ncurses_windows = zend_register_list_destructors_ex(ncurses_destruct_window, +NULL, "ncurses_window", module_number); +#if HAVE_NCURSES_PANEL + le_ncurses_panels = zend_register_list_destructors_ex(ncurses_destruct_panel, +NULL, "ncurses_panel", module_number); +#endif return SUCCESS; } Index: php4/ext/ncurses/ncurses_fe.c diff -u php4/ext/ncurses/ncurses_fe.c:1.14 php4/ext/ncurses/ncurses_fe.c:1.15 --- php4/ext/ncurses/ncurses_fe.c:1.14 Thu Feb 28 03:26:27 2002 +++ php4/ext/ncurses/ncurses_fe.c Fri Sep 27 13:03:53 2002 @@ -162,6 +162,31 @@ PHP_FE(ncurses_wgetch, NULL) PHP_FE(ncurses_keypad, NULL) PHP_FE(ncurses_wmove, NULL) + + PHP_FE(ncurses_newpad, NULL) + PHP_FE(ncurses_prefresh, NULL) + PHP_FE(ncurses_pnoutrefresh, NULL) + PHP_FE(ncurses_wstandout, NULL) + PHP_FE(ncurses_wstandend, NULL) + PHP_FE(ncurses_wattrset, NULL) + PHP_FE(ncurses_wattron, NULL) + PHP_FE(ncurses_wattroff, NULL) + +#if HAVE_NCURSES_PANEL + PHP_FE(ncurses_update_panels, NULL) + PHP_FE(ncurses_panel_window, NULL) + PHP_FE(ncurses_panel_below, NULL) + PHP_FE(ncurses_panel_above, NULL) + PHP_FE(ncurses_replace_panel, NULL) + PHP_FE(ncurses_move_panel, NULL) + PHP_FE(ncurses_bottom_panel, NULL) + PHP_FE(ncurses_top_panel, NULL) + PHP_FE(ncurses_show_panel, NULL) + PHP_FE(ncurses_hide_panel, NULL) + PHP_FE(ncurses_del_panel, NULL) + PHP_FE(ncurses_new_panel, NULL) +#endif + {NULL, NULL, NULL} /* Must be the last line in ncurses_functions[] */ }; Index: php4/ext/ncurses/ncurses_functions.c diff -u php4/ext/ncurses/ncurses_functions.c:1.19 php4/ext/ncurses/ncurses_functions.c:1.20 --- php4/ext/ncurses/ncurses_functions.c:1.19 Thu Aug 22 08:15:20 2002 +++ php4/ext/ncurses/ncurses_functions.c Fri Sep 27 13:03:53 2002 @@ -25,9 +25,10 @@ #include "php_ini.h" #include "php_ncurses.h" -#define FETCH_WINRES(r, z) ZEND_FETCH_RESOURCE((void**)r, WINDOW *, z, -1, "ncurses_handle", le_ncurses); \ - if(!r) RETURN_FALSE; - +#define FETCH_WINRES(r, z) ZEND_FETCH_RESOURCE(r, WINDOW **, z, -1, +"ncurses_window", le_ncurses_windows) +#if HAVE_NCURSES_PANEL +# define FETCH_PANEL(r, z) ZEND_FETCH_RESOURCE(r, PANEL **, z, -1, "ncurses_panel", +le_ncurses_panels) +#endif /* {{{ proto int ncurses_addch(int ch) Adds character at current position and advance cursor */ @@ -65,7 +66,7 @@ PHP_FUNCTION(ncurses_delwin) { zval **handle; - WINDOW *w; + WINDOW **w; if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &handle) == FAILURE){ WRONG_PARAM_COUNT; @@ -105,10 +106,27 @@ Initializes ncurses */ PHP_FUNCTION(ncurses_init) { + zend_constant c; + WINDOW **pscr = (WINDOW**)emalloc(sizeof(WINDOW *)); + zval *zscr; + initscr(); /* initialize the curses library */ keypad(stdscr, TRUE); /* enable keyboard mapping */ (void) nonl(); /* tell curses not to do NL->CR/NL on output */ - (void) cbreak(); /* take input chars one at a time, no wait for \n */} + (void) cbreak(); /* take input chars one at a time, no wait for \n */ + + *pscr = stdscr; + MAKE_STD_ZVAL(zscr); + ZEND_REGISTER_RESOURCE(zscr, pscr, le_ncurses_windows); + c.value = *zscr; + zval_copy_ctor(&c.value); + c.flags = CONST_CS; + c.name = zend_strndup("STDSCR", 7); + c.name_len = 7; + zend_register_constant(&c TSRMLS_CC); + + FREE_ZVAL(zscr); +} /* }}} */ /* {{{ proto int ncurses_init_pair(int pair, int fg, int bg) @@ -137,6 +155,68 @@ } /* }}} */ +/* {{{ proto resource ncurses_newpad(int rows, int cols) + Creates a new pad (window) */ +PHP_FUNCTION(ncurses_newpad) +{ + long rows,cols; + WINDOW **pwin = (WINDOW **)emalloc(sizeof(WINDOW *)); + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, +"ll",&rows,&cols)==FAILURE) { + return; + } + + *pwin = newpad(rows,cols); + + if(!*pwin) { + efree(pwin); + RETURN_FALSE; + } + + ZEND_REGISTER_RESOURCE(return_value, pwin, le_ncurses_windows); + +} +/* }}} */ + +/* {{{ proto int ncurses_prefresh(resource pad, int pminrow, int pmincol, int +sminrow, int smincol, int smaxrow, int smaxcol) + Copys a region from a pad into the virtual screen */ +PHP_FUNCTION(ncurses_prefresh) +{ + WINDOW **pwin; + zval *phandle; + long pminrow, pmincol, sminrow, smincol, smaxrow, smaxcol; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rllllll", &phandle, +&pminrow, + &pmincol, &sminrow, &smincol, &smaxrow, &smaxcol) == +FAILURE) { + return; + } + + FETCH_WINRES(pwin, &phandle); + + RETURN_LONG(prefresh(*pwin, pminrow, pmincol, sminrow, smincol, smaxrow, +smaxcol)); +} +/* }}} */ + +/* {{{ proto int ncurses_pnoutrefresh(resource pad, int pminrow, int pmincol, int +sminrow, int smincol, int smaxrow, int smaxcol) + Copys a region from a pad into the virtual screen */ +PHP_FUNCTION(ncurses_pnoutrefresh) +{ + WINDOW **pwin; + zval *phandle; + long pminrow, pmincol, sminrow, smincol, smaxrow, smaxcol; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rllllll", &phandle, +&pminrow, + &pmincol, &sminrow, &smincol, &smaxrow, &smaxcol) == +FAILURE) { + return; + } + + FETCH_WINRES(pwin, &phandle); + + RETURN_LONG(pnoutrefresh(*pwin, pminrow, pmincol, sminrow, smincol, smaxrow, +smaxcol)); +} +/* }}} */ + + /* {{{ proto int ncurses_newwin(int rows, int cols, int y, int x) Creates a new window */ @@ -156,7 +236,7 @@ RETURN_FALSE; } - ZEND_REGISTER_RESOURCE(return_value, pwin, le_ncurses); + ZEND_REGISTER_RESOURCE(return_value, pwin, le_ncurses_windows); } /* }}} */ @@ -361,6 +441,7 @@ RETURN_STRINGL (temp, 1, 1); } +/* }}} */ /* {{{ proto bool ncurses_insertln(void) Inserts a line, move rest of screen down */ @@ -471,9 +552,6 @@ } /* }}} */ -/* {{{ proto bool ncurses_slk_clear(void) - */ - /* {{{ proto bool ncurses_slk_attr(void) Returns current soft label keys attribute */ PHP_FUNCTION(ncurses_slk_attr) @@ -1617,6 +1695,7 @@ RETURN_LONG(wmove(*win, Z_LVAL_PP(y), Z_LVAL_PP(x))); } +/* }}} */ /* {{{ proto int ncurses_keypad(resource window, bool bf) Turns keypad on or off */ @@ -1649,7 +1728,7 @@ if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2,&handle, &color_pair) == FAILURE) WRONG_PARAM_COUNT; - FETCH_WINRES(win, handle); + FETCH_WINRES(win, handle); convert_to_long_ex(color_pair); RETURN_LONG(wcolor_set(*win, Z_LVAL_PP(color_pair), 0)); @@ -1734,6 +1813,333 @@ } /* }}} */ +/* {{{ proto int wattroff(resource window, int attrs) + Turns off attributes for a window */ +PHP_FUNCTION(ncurses_wattroff) +{ + zval *handle; + WINDOW **win; + long attrs; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl", &handle, &attrs) == +FAILURE) { + return; + } + + FETCH_WINRES(win, &handle); + + RETURN_LONG(wattroff(*win, attrs)); +} +/* }}} */ + +/* {{{ proto int wattron(resource window, int attrs) + Turns on attributes for a window */ +PHP_FUNCTION(ncurses_wattron) +{ + zval *handle; + WINDOW **win; + long attrs; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl", &handle, &attrs) == +FAILURE) { + return; + } + + FETCH_WINRES(win, &handle); + + RETURN_LONG(wattron(*win, attrs)); +} +/* }}} */ + +/* {{{ proto int wattrset(resource window, int attrs) + Set the attributes for a window */ +PHP_FUNCTION(ncurses_wattrset) +{ + zval *handle; + WINDOW **win; + long attrs; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl", &handle, &attrs) == +FAILURE) { + return; + } + + FETCH_WINRES(win, &handle); + + RETURN_LONG(wattrset(*win, attrs)); +} +/* }}} */ + +/* {{{ proto int wstandend(resource window) + End standout mode for a window */ +PHP_FUNCTION(ncurses_wstandend) +{ + zval *handle; + WINDOW **win; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &handle) == FAILURE) +{ + return; + } + + FETCH_WINRES(win, &handle); + + RETURN_LONG(wstandend(*win)); +} +/* }}} */ + +/* {{{ proto int wstandout(resource window) + Enter standout mode for a window */ +PHP_FUNCTION(ncurses_wstandout) +{ + zval *handle; + WINDOW **win; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &handle) == FAILURE) +{ + return; + } + + FETCH_WINRES(win, &handle); + + RETURN_LONG(wstandout(*win)); +} +/* }}} */ + + + +#if HAVE_NCURSES_PANEL +/* {{{ proto resource ncurses_new_panel(resource window) + Create a new panel and associate it with window */ +PHP_FUNCTION(ncurses_new_panel) +{ + zval **handle; + WINDOW **win; + PANEL **panel = (PANEL **)emalloc(sizeof(PANEL *)); + + if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &handle) == FAILURE) + WRONG_PARAM_COUNT; + + FETCH_WINRES(win, handle); + + *panel = new_panel(*win); + + if (*panel == NULL) { + efree(panel); + RETURN_FALSE; + } else { + ZEND_REGISTER_RESOURCE(return_value, panel, le_ncurses_panels); + } + +} +/* }}} */ + +/* {{{ proto int ncurses_del_panel(resource panel) + Remove panel from the stack and delete it (but not the associated window) */ +PHP_FUNCTION(ncurses_del_panel) +{ + zval **handle; + PANEL **panel; + + if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &handle) == FAILURE) + WRONG_PARAM_COUNT; + + FETCH_PANEL(panel, handle); + + RETURN_LONG(del_panel(*panel)); +} +/* }}} */ + +/* {{{ proto int ncurses_hide_panel(resource panel) + Remove panel from the stack, making it invisible */ +PHP_FUNCTION(ncurses_hide_panel) +{ + zval **handle; + PANEL **panel; + + if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &handle) == FAILURE) + WRONG_PARAM_COUNT; + + FETCH_PANEL(panel, handle); + + RETURN_LONG(hide_panel(*panel)); + +} +/* }}} */ + +/* {{{ proto int ncurses_show_panel(resource panel) + Places an invisible panel on top of the stack, making it visible */ +PHP_FUNCTION(ncurses_show_panel) +{ + zval **handle; + PANEL **panel; + + if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &handle) == FAILURE) + WRONG_PARAM_COUNT; + + FETCH_PANEL(panel, handle); + + RETURN_LONG(show_panel(*panel)); + +} +/* }}} */ + +/* {{{ proto int ncurses_top_panel(resource panel) + Moves a visible panel to the top of the stack */ +PHP_FUNCTION(ncurses_top_panel) +{ + zval **handle; + PANEL **panel; + + if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &handle) == FAILURE) + WRONG_PARAM_COUNT; + + FETCH_PANEL(panel, handle); + + RETURN_LONG(top_panel(*panel)); + +} +/* }}} */ + +/* {{{ proto int ncurses_bottom_panel(resource panel) + Moves a visible panel to the bottom of the stack */ +PHP_FUNCTION(ncurses_bottom_panel) +{ + zval **handle; + PANEL **panel; + + if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &handle) == FAILURE) + WRONG_PARAM_COUNT; + + FETCH_PANEL(panel, handle); + + RETURN_LONG(bottom_panel(*panel)); + +} +/* }}} */ + +/* {{{ proto int ncurses_move_panel(resource panel, int startx, int starty) + Moves a panel so that it's upper-left corner is at [startx, starty] */ +PHP_FUNCTION(ncurses_move_panel) +{ + zval *handle; + PANEL **panel; + long startx, starty; + + if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rll", +&handle, &startx, &starty)) { + return; + } + + FETCH_PANEL(panel, &handle); + + RETURN_LONG(move_panel(*panel, startx, starty)); + +} +/* }}} */ + +/* {{{ proto int ncurses_replace_panel(resource panel, resource window) + Replaces the window associated with panel */ +PHP_FUNCTION(ncurses_replace_panel) +{ + zval *phandle, *whandle; + PANEL **panel; + WINDOW **window; + + if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rr", +&phandle, &whandle)) { + return; + } + + FETCH_PANEL(panel, &phandle); + FETCH_WINRES(window, &whandle); + + RETURN_LONG(replace_panel(*panel, *window)); + +} +/* }}} */ + +/* {{{ proto int ncurses_panel_above(resource panel) + Returns the panel above panel. If panel is null, returns the bottom panel in the +stack */ +PHP_FUNCTION(ncurses_panel_above) +{ + zval *phandle = NULL; + PANEL **panel; + PANEL **above = (PANEL **)emalloc(sizeof(PANEL *)); + + if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r!", +&phandle)) { + return; + } + + if (phandle) { + FETCH_PANEL(panel, &phandle); + *above = panel_above(*panel); + } else { + *above = panel_above((PANEL *)0); + } + + if (*above == NULL) { + efree(above); + RETURN_FALSE; + } + ZEND_REGISTER_RESOURCE(return_value, above, le_ncurses_panels); +} +/* }}} */ + +/* {{{ proto int ncurses_panel_below(resource panel) + Returns the panel below panel. If panel is null, returns the top panel in the +stack */ +PHP_FUNCTION(ncurses_panel_below) +{ + zval *phandle = NULL; + PANEL **panel; + PANEL **below = (PANEL **)emalloc(sizeof(PANEL *)); + + if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r!", +&phandle)) { + return; + } + + if (phandle) { + FETCH_PANEL(panel, &phandle); + *below = panel_below(*panel); + } else { + *below = panel_below((PANEL *)0); + } + + if (*below == NULL) { + efree(below); + RETURN_FALSE; + } + ZEND_REGISTER_RESOURCE(return_value, below, le_ncurses_panels); +} +/* }}} */ + +/* {{{ proto int ncurses_panel_window(resource panel) + Returns the window associated with panel */ +PHP_FUNCTION(ncurses_panel_window) +{ + zval *phandle = NULL; + PANEL **panel; + WINDOW **win = (WINDOW **)emalloc(sizeof(WINDOW *)); + + if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", +&phandle)) { + return; + } + + FETCH_PANEL(panel, &phandle); + *win = panel_window(*panel); + + if (*win == NULL) { + efree(win); + RETURN_FALSE; + } + ZEND_REGISTER_RESOURCE(return_value, win, le_ncurses_windows); +} +/* }}} */ + +/* {{{ proto void ncurses_update_panels(void) + Refreshes the virtual screen to reflect the relations between panels in the stack. +*/ +PHP_FUNCTION(ncurses_update_panels) +{ + if (ZEND_NUM_ARGS() != 0) { + WRONG_PARAM_COUNT; + } + update_panels(); +} +/* }}} */ +#endif /* HAVE_NCURSES_PANEL */ /* * Local variables: Index: php4/ext/ncurses/php_ncurses.h diff -u php4/ext/ncurses/php_ncurses.h:1.5 php4/ext/ncurses/php_ncurses.h:1.6 --- php4/ext/ncurses/php_ncurses.h:1.5 Thu Feb 28 03:26:27 2002 +++ php4/ext/ncurses/php_ncurses.h Fri Sep 27 13:03:53 2002 @@ -21,7 +21,13 @@ #include <curses.h> -extern int le_ncurses; +extern int le_ncurses_windows; + +#if HAVE_NCURSES_PANEL +# include <panel.h> +extern int le_ncurses_panels; +#endif + extern zend_module_entry ncurses_module_entry; #define phpext_ncurses_ptr &ncurses_module_entry Index: php4/ext/ncurses/php_ncurses_fe.h diff -u php4/ext/ncurses/php_ncurses_fe.h:1.14 php4/ext/ncurses/php_ncurses_fe.h:1.15 --- php4/ext/ncurses/php_ncurses_fe.h:1.14 Thu Feb 28 03:26:27 2002 +++ php4/ext/ncurses/php_ncurses_fe.h Fri Sep 27 13:03:53 2002 @@ -148,6 +148,30 @@ PHP_FUNCTION(ncurses_keypad); PHP_FUNCTION(ncurses_wmove); +PHP_FUNCTION(ncurses_newpad); +PHP_FUNCTION(ncurses_prefresh); +PHP_FUNCTION(ncurses_pnoutrefresh); + +PHP_FUNCTION(ncurses_wstandout); +PHP_FUNCTION(ncurses_wstandend); +PHP_FUNCTION(ncurses_wattrset); +PHP_FUNCTION(ncurses_wattron); +PHP_FUNCTION(ncurses_wattroff); +#if HAVE_NCURSES_PANEL +PHP_FUNCTION(ncurses_update_panels); +PHP_FUNCTION(ncurses_panel_window); +PHP_FUNCTION(ncurses_panel_below); +PHP_FUNCTION(ncurses_panel_above); +PHP_FUNCTION(ncurses_replace_panel); +PHP_FUNCTION(ncurses_move_panel); +PHP_FUNCTION(ncurses_bottom_panel); +PHP_FUNCTION(ncurses_top_panel); +PHP_FUNCTION(ncurses_show_panel); +PHP_FUNCTION(ncurses_hide_panel); +PHP_FUNCTION(ncurses_del_panel); +PHP_FUNCTION(ncurses_new_panel); +#endif + #endif
-- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php