summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWez Furlong <wez@php.net>2002-09-27 22:33:14 +0000
committerWez Furlong <wez@php.net>2002-09-27 22:33:14 +0000
commit65d3e611f99616bdc5c7862c83cf6a1fc203efc0 (patch)
treed9598d178f8edcf4908c01723a930bc03df16e0c
parentdd6d22b6a103313aed54920f6927eb4439c3a493 (diff)
downloadphp-git-65d3e611f99616bdc5c7862c83cf6a1fc203efc0.tar.gz
More ncurses functions and constants.
-rw-r--r--ext/ncurses/ncurses.c2
-rw-r--r--ext/ncurses/ncurses_fe.c4
-rw-r--r--ext/ncurses/ncurses_functions.c150
-rw-r--r--ext/ncurses/php_ncurses.h10
-rw-r--r--ext/ncurses/php_ncurses_fe.h4
5 files changed, 146 insertions, 24 deletions
diff --git a/ext/ncurses/ncurses.c b/ext/ncurses/ncurses.c
index cdad69a1b6..59309da5cf 100644
--- a/ext/ncurses/ncurses.c
+++ b/ext/ncurses/ncurses.c
@@ -25,9 +25,7 @@
#include "php_ncurses.h"
#include "ext/standard/info.h"
-/* If you declare any globals in php_ncurses.h uncomment this:
ZEND_DECLARE_MODULE_GLOBALS(ncurses)
-*/
/* True global resources - no need for thread safety here */
int le_ncurses_windows;
diff --git a/ext/ncurses/ncurses_fe.c b/ext/ncurses/ncurses_fe.c
index c24dda4ec3..6f56a59341 100644
--- a/ext/ncurses/ncurses_fe.c
+++ b/ext/ncurses/ncurses_fe.c
@@ -171,6 +171,10 @@ function_entry ncurses_functions[] = {
PHP_FE(ncurses_wattrset, NULL)
PHP_FE(ncurses_wattron, NULL)
PHP_FE(ncurses_wattroff, NULL)
+ PHP_FE(ncurses_waddch, NULL)
+ PHP_FE(ncurses_wborder, NULL)
+ PHP_FE(ncurses_whline, NULL)
+ PHP_FE(ncurses_wvline, NULL)
#if HAVE_NCURSES_PANEL
PHP_FE(ncurses_update_panels, NULL)
diff --git a/ext/ncurses/ncurses_functions.c b/ext/ncurses/ncurses_functions.c
index 7946418bf0..073bcd8d96 100644
--- a/ext/ncurses/ncurses_functions.c
+++ b/ext/ncurses/ncurses_functions.c
@@ -44,6 +44,26 @@ PHP_FUNCTION(ncurses_addch)
}
/* }}} */
+/* {{{ proto int ncurses_waddch(resource window, int ch)
+ Adds character at current position in a window and advance cursor */
+PHP_FUNCTION(ncurses_waddch)
+{
+ long ch;
+ zval *handle;
+ WINDOW **win;
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl", &handle, &ch)==FAILURE) {
+ return;
+ }
+
+ FETCH_WINRES(win, &handle);
+
+ RETURN_LONG(waddch(*win, ch));
+}
+/* }}} */
+
+
+
/* {{{ proto int ncurses_color_set(int pair)
Sets fore- and background color */
PHP_FUNCTION(ncurses_color_set)
@@ -106,26 +126,69 @@ PHP_FUNCTION(ncurses_has_colors)
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 */
- *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);
+ if (!NCURSES_G(registered_constants)) {
+ zend_constant c;
+
+ WINDOW **pscr = (WINDOW**)emalloc(sizeof(WINDOW *));
+ zval *zscr;
+
+ *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);
+
+ /* we need this "interesting" arrangement because the
+ * underlying values of the ACS_XXX defines are not
+ * initialized until after ncurses has been initialized */
+
+#define PHP_NCURSES_DEF_CONST(x) \
+ ZVAL_LONG(zscr, x); \
+ c.value = *zscr; \
+ zval_copy_ctor(&c.value); \
+ c.flags = CONST_CS; \
+ c.name = zend_strndup("NCURSES_" #x, sizeof("NCURSES_" #x)); \
+ c.name_len = sizeof("NCURSES_" #x); \
+ zend_register_constant(&c TSRMLS_CC)
+
+ PHP_NCURSES_DEF_CONST(ACS_ULCORNER);
+ PHP_NCURSES_DEF_CONST(ACS_LLCORNER);
+ PHP_NCURSES_DEF_CONST(ACS_URCORNER);
+ PHP_NCURSES_DEF_CONST(ACS_LRCORNER);
+ PHP_NCURSES_DEF_CONST(ACS_LTEE);
+ PHP_NCURSES_DEF_CONST(ACS_RTEE);
+ PHP_NCURSES_DEF_CONST(ACS_BTEE);
+ PHP_NCURSES_DEF_CONST(ACS_TTEE);
+ PHP_NCURSES_DEF_CONST(ACS_HLINE);
+ PHP_NCURSES_DEF_CONST(ACS_VLINE);
+ PHP_NCURSES_DEF_CONST(ACS_PLUS);
+ PHP_NCURSES_DEF_CONST(ACS_S1);
+ PHP_NCURSES_DEF_CONST(ACS_S9);
+ PHP_NCURSES_DEF_CONST(ACS_DIAMOND);
+ PHP_NCURSES_DEF_CONST(ACS_CKBOARD);
+ PHP_NCURSES_DEF_CONST(ACS_DEGREE);
+ PHP_NCURSES_DEF_CONST(ACS_PLMINUS);
+ PHP_NCURSES_DEF_CONST(ACS_BULLET);
+ PHP_NCURSES_DEF_CONST(ACS_LARROW);
+ PHP_NCURSES_DEF_CONST(ACS_RARROW);
+ PHP_NCURSES_DEF_CONST(ACS_DARROW);
+ PHP_NCURSES_DEF_CONST(ACS_UARROW);
+ PHP_NCURSES_DEF_CONST(ACS_BOARD);
+ PHP_NCURSES_DEF_CONST(ACS_LANTERN);
+ PHP_NCURSES_DEF_CONST(ACS_BLOCK);
+
+ FREE_ZVAL(zscr);
+ NCURSES_G(registered_constants) = 1;
+ }
}
/* }}} */
@@ -1384,6 +1447,26 @@ PHP_FUNCTION(ncurses_border)
}
/* }}} */
+/* {{{ proto int ncurses_wborder(resource window, int left, int right, int top, int bottom, int tl_corner, int tr_corner, int bl_corner, int br_corner)
+ Draws a border around the window using attributed characters */
+PHP_FUNCTION(ncurses_wborder)
+{
+ long i1,i2,i3,i4,i5,i6,i7,i8;
+ zval *handle;
+ WINDOW **win;
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rllllllll",&handle,&i1,&i2,&i3,&i4,&i5,&i6,&i7,&i8)==FAILURE) {
+ return;
+ }
+
+ FETCH_WINRES(win,&handle);
+
+ RETURN_LONG(wborder(*win,i1,i2,i3,i4,i5,i6,i7,i8));
+}
+/* }}} */
+
+
+
/* {{{ proto int ncurses_assume_default_colors(int fg, int bg)
Defines default colors for color 0 */
PHP_FUNCTION(ncurses_assume_default_colors)
@@ -1447,6 +1530,43 @@ PHP_FUNCTION(ncurses_vline)
}
/* }}} */
+/* {{{ proto int ncurses_whline(resource window, int charattr, int n)
+ Draws a horizontal line in a window at current position using an attributed character and max. n characters long */
+PHP_FUNCTION(ncurses_whline)
+{
+ long i1,i2;
+ zval *handle;
+ WINDOW **win;
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rll",&handle,&i1,&i2)==FAILURE) {
+ return;
+ }
+
+ FETCH_WINRES(win,&handle);
+
+ RETURN_LONG(whline(*win,i1,i2));
+}
+/* }}} */
+
+/* {{{ proto int ncurses_wvline(resource window, int charattr, int n)
+ Draws a vertical line in a window at current position using an attributed character and max. n characters long */
+PHP_FUNCTION(ncurses_wvline)
+{
+ long i1,i2;
+ zval *handle;
+ WINDOW **win;
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rll",&handle,&i1,&i2)==FAILURE) {
+ return;
+ }
+ FETCH_WINRES(win,&handle);
+
+ RETURN_LONG(wvline(*win,i1,i2));
+}
+/* }}} */
+
+
+
/* {{{ proto int ncurses_keyok(int keycode, bool enable)
Enables or disable a keycode */
PHP_FUNCTION(ncurses_keyok)
diff --git a/ext/ncurses/php_ncurses.h b/ext/ncurses/php_ncurses.h
index 333b10efa7..24e147eda1 100644
--- a/ext/ncurses/php_ncurses.h
+++ b/ext/ncurses/php_ncurses.h
@@ -47,15 +47,9 @@ PHP_RINIT_FUNCTION(ncurses);
PHP_RSHUTDOWN_FUNCTION(ncurses);
PHP_MINFO_FUNCTION(ncurses);
-/*
- Declare any global variables you may need between the BEGIN
- and END macros here:
-
ZEND_BEGIN_MODULE_GLOBALS(ncurses)
- int global_value;
- char *global_string;
+ int registered_constants;
ZEND_END_MODULE_GLOBALS(ncurses)
-*/
/* In every function that needs to use variables in php_ncurses_globals,
do call NCURSES_LS_FETCH(); after declaring other variables used by
@@ -72,6 +66,8 @@ ZEND_END_MODULE_GLOBALS(ncurses)
#define NCURSES_LS_FETCH()
#endif
+ZEND_EXTERN_MODULE_GLOBALS(ncurses);
+
#endif /* PHP_NCURSES_H */
diff --git a/ext/ncurses/php_ncurses_fe.h b/ext/ncurses/php_ncurses_fe.h
index 818cc5d995..4facad7d25 100644
--- a/ext/ncurses/php_ncurses_fe.h
+++ b/ext/ncurses/php_ncurses_fe.h
@@ -157,6 +157,10 @@ PHP_FUNCTION(ncurses_wstandend);
PHP_FUNCTION(ncurses_wattrset);
PHP_FUNCTION(ncurses_wattron);
PHP_FUNCTION(ncurses_wattroff);
+PHP_FUNCTION(ncurses_waddch);
+PHP_FUNCTION(ncurses_wborder);
+PHP_FUNCTION(ncurses_whline);
+PHP_FUNCTION(ncurses_wvline);
#if HAVE_NCURSES_PANEL
PHP_FUNCTION(ncurses_update_panels);
PHP_FUNCTION(ncurses_panel_window);