wez             Fri Sep 27 18:33:14 2002 EDT

  Modified files:              
    /php4/ext/ncurses   ncurses.c ncurses_fe.c ncurses_functions.c 
                        php_ncurses.h php_ncurses_fe.h 
  Log:
  More ncurses functions and constants.
  
  
Index: php4/ext/ncurses/ncurses.c
diff -u php4/ext/ncurses/ncurses.c:1.17 php4/ext/ncurses/ncurses.c:1.18
--- php4/ext/ncurses/ncurses.c:1.17     Fri Sep 27 13:03:53 2002
+++ php4/ext/ncurses/ncurses.c  Fri Sep 27 18:33:14 2002
@@ -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: php4/ext/ncurses/ncurses_fe.c
diff -u php4/ext/ncurses/ncurses_fe.c:1.15 php4/ext/ncurses/ncurses_fe.c:1.16
--- php4/ext/ncurses/ncurses_fe.c:1.15  Fri Sep 27 13:03:53 2002
+++ php4/ext/ncurses/ncurses_fe.c       Fri Sep 27 18:33:14 2002
@@ -171,6 +171,10 @@
        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: php4/ext/ncurses/ncurses_functions.c
diff -u php4/ext/ncurses/ncurses_functions.c:1.20 
php4/ext/ncurses/ncurses_functions.c:1.21
--- php4/ext/ncurses/ncurses_functions.c:1.20   Fri Sep 27 13:03:53 2002
+++ php4/ext/ncurses/ncurses_functions.c        Fri Sep 27 18:33:14 2002
@@ -44,6 +44,26 @@
 }
 /* }}} */
 
+/* {{{ 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 @@
    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 @@
 }
 /* }}} */
 
+/* {{{ 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)
@@ -1446,6 +1529,43 @@
        RETURN_LONG(vline(i1,i2));
 }
 /* }}} */
+
+/* {{{ 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 */
Index: php4/ext/ncurses/php_ncurses.h
diff -u php4/ext/ncurses/php_ncurses.h:1.6 php4/ext/ncurses/php_ncurses.h:1.7
--- php4/ext/ncurses/php_ncurses.h:1.6  Fri Sep 27 13:03:53 2002
+++ php4/ext/ncurses/php_ncurses.h      Fri Sep 27 18:33:14 2002
@@ -47,15 +47,9 @@
 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 @@
 #define NCURSES_LS_FETCH()
 #endif
 
+ZEND_EXTERN_MODULE_GLOBALS(ncurses);
+       
 #endif  /* PHP_NCURSES_H */
 
 
Index: php4/ext/ncurses/php_ncurses_fe.h
diff -u php4/ext/ncurses/php_ncurses_fe.h:1.15 php4/ext/ncurses/php_ncurses_fe.h:1.16
--- php4/ext/ncurses/php_ncurses_fe.h:1.15      Fri Sep 27 13:03:53 2002
+++ php4/ext/ncurses/php_ncurses_fe.h   Fri Sep 27 18:33:14 2002
@@ -157,6 +157,10 @@
 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);



-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to