]> granicus.if.org Git - php/commitdiff
More ncurses functions and constants.
authorWez Furlong <wez@php.net>
Fri, 27 Sep 2002 22:33:14 +0000 (22:33 +0000)
committerWez Furlong <wez@php.net>
Fri, 27 Sep 2002 22:33:14 +0000 (22:33 +0000)
ext/ncurses/ncurses.c
ext/ncurses/ncurses_fe.c
ext/ncurses/ncurses_functions.c
ext/ncurses/php_ncurses.h
ext/ncurses/php_ncurses_fe.h

index cdad69a1b6b60ddc7c8ca68c7d5b56438f17e29a..59309da5cfd7536c19e8563ceff7f2b7e14e22b3 100644 (file)
@@ -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;
index c24dda4ec38fbe729735b13323c240a311512d72..6f56a5934174374722fbbd1256c2d7d04c39918e 100644 (file)
@@ -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)
index 7946418bf02d4c973bae81783e4aeb6d255ce18c..073bcd8d96087d39671a7f6d87ad07400dad66e2 100644 (file)
@@ -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)
index 333b10efa744dd9f4873cc8345cb9244cb3fd354..24e147eda11c43c4f851f144d6c8e367f7a6ea70 100644 (file)
@@ -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 */
 
 
index 818cc5d995f83d028431a22c230f3b677216435e..4facad7d25041249cc3abdbd0df796843a357690 100644 (file)
@@ -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);