wez Wed Apr 2 05:35:04 2003 EDT
Added files:
/embed/php-irssi statusbar.c
/embed/php-irssi/examples rotator.php
Modified files:
/embed/php-irssi Makefile.am ext-irssi.c genobjdefs.php
php-irssi-obj.c php-irssi-obj.h php-irssi.h
typemap.php
Log:
Add support for statusbar items.
Index: embed/php-irssi/Makefile.am
diff -u embed/php-irssi/Makefile.am:1.7 embed/php-irssi/Makefile.am:1.8
--- embed/php-irssi/Makefile.am:1.7 Tue Apr 1 12:10:29 2003
+++ embed/php-irssi/Makefile.am Wed Apr 2 05:35:04 2003
@@ -19,7 +19,7 @@
core_sources=\
php-core.c ext-irssi.c php-irssi-obj.c server.c channel.c nick.c win-item.c window.c \
- theme.c settings.c
+ theme.c settings.c statusbar.c
libphp_core_la_SOURCES = \
$(core_sources) fe.c
Index: embed/php-irssi/ext-irssi.c
diff -u embed/php-irssi/ext-irssi.c:1.31 embed/php-irssi/ext-irssi.c:1.32
--- embed/php-irssi/ext-irssi.c:1.31 Tue Apr 1 14:36:20 2003
+++ embed/php-irssi/ext-irssi.c Wed Apr 2 05:35:04 2003
@@ -14,7 +14,7 @@
+----------------------------------------------------------------------+
| Author: Wez Furlong <[email protected]> |
+----------------------------------------------------------------------+
- $Id: ext-irssi.c,v 1.31 2003/04/01 19:36:20 wez Exp $
+ $Id: ext-irssi.c,v 1.32 2003/04/02 10:35:04 wez Exp $
*/
#include "php-irssi.h"
#include "php-signals-list.h" /* generated by php during make */
@@ -45,7 +45,7 @@
} v;
};
-HashTable *php_irssi_bound_signals, *php_irssi_registered_themes;
+HashTable *php_irssi_bound_signals, *php_irssi_registered_themes, *php_irssi_statusbar_items;
void php_irssi_export_GList(zval *val, GSList *the_list, int type TSRMLS_DC)
{
@@ -853,9 +853,11 @@
{
ALLOC_HASHTABLE(php_irssi_bound_signals);
ALLOC_HASHTABLE(php_irssi_registered_themes);
+ ALLOC_HASHTABLE(php_irssi_statusbar_items);
zend_hash_init(php_irssi_bound_signals, 0, NULL, sig_rec_dtor, 0);
zend_hash_init(php_irssi_registered_themes, 0, NULL, php_irssi_themes_dtor, 0);
+ zend_hash_init(php_irssi_statusbar_items, 0, NULL, php_irssi_statusbar_dtor, 0);
php_irssi_init_objects();
@@ -920,6 +922,12 @@
FREE_HASHTABLE(php_irssi_registered_themes);
php_irssi_registered_themes = NULL;
}
+ if (php_irssi_statusbar_items) {
+ zend_hash_destroy(php_irssi_statusbar_items);
+ FREE_HASHTABLE(php_irssi_statusbar_items);
+ php_irssi_statusbar_items = NULL;
+ }
+
php_irssi_fini_objects();
}
Index: embed/php-irssi/genobjdefs.php
diff -u embed/php-irssi/genobjdefs.php:1.10 embed/php-irssi/genobjdefs.php:1.11
--- embed/php-irssi/genobjdefs.php:1.10 Wed Mar 12 11:37:04 2003
+++ embed/php-irssi/genobjdefs.php Wed Apr 2 05:35:04 2003
@@ -15,7 +15,7 @@
+----------------------------------------------------------------------+
| Author: Wez Furlong <[email protected]> |
+----------------------------------------------------------------------+
- $Id: genobjdefs.php,v 1.10 2003/03/12 16:37:04 tal Exp $
+ $Id: genobjdefs.php,v 1.11 2003/04/02 10:35:04 wez Exp $
*/
/* We build three sets of tables:
@@ -69,6 +69,7 @@
if ($srcmatch) {
preg_match($srcmatch, $source, $matches);
$source = $matches[1];
+ echo "#if 0\n$source\n#endif\n";
}
$rel = dirname($top_srcdir . DIRECTORY_SEPARATOR . $filename);
Index: embed/php-irssi/php-irssi-obj.c
diff -u embed/php-irssi/php-irssi-obj.c:1.10 embed/php-irssi/php-irssi-obj.c:1.11
--- embed/php-irssi/php-irssi-obj.c:1.10 Tue Apr 1 09:35:34 2003
+++ embed/php-irssi/php-irssi-obj.c Wed Apr 2 05:35:04 2003
@@ -14,7 +14,7 @@
+----------------------------------------------------------------------+
| Author: Wez Furlong <[email protected]> |
+----------------------------------------------------------------------+
- $Id: php-irssi-obj.c,v 1.10 2003/04/01 14:35:34 wez Exp $
+ $Id: php-irssi-obj.c,v 1.11 2003/04/02 10:35:04 wez Exp $
*/
#include "php-irssi.h"
#include "php-irssi-obj-defs.h"
@@ -64,6 +64,12 @@
break;
case PIAT_WINDOW:
php_irssi_export_WINDOW(val, (WINDOW_REC*)arg TSRMLS_CC);
+ break;
+ case PIAT_SBAR_ITEM:
+ php_irssi_export_SBAR_ITEM(val, (SBAR_ITEM_REC*)arg TSRMLS_CC);
+ break;
+ case PIAT_STATUSBAR:
+ php_irssi_export_STATUSBAR(val, (STATUSBAR_REC*)arg TSRMLS_CC);
break;
case PIAT_NICK:
/* We need some context for a NICK */
Index: embed/php-irssi/php-irssi-obj.h
diff -u embed/php-irssi/php-irssi-obj.h:1.2 embed/php-irssi/php-irssi-obj.h:1.3
--- embed/php-irssi/php-irssi-obj.h:1.2 Tue Mar 11 09:15:25 2003
+++ embed/php-irssi/php-irssi-obj.h Wed Apr 2 05:35:04 2003
@@ -14,7 +14,7 @@
+----------------------------------------------------------------------+
| Author: Wez Furlong <[email protected]> |
+----------------------------------------------------------------------+
- $Id: php-irssi-obj.h,v 1.2 2003/03/11 14:15:25 tal Exp $
+ $Id: php-irssi-obj.h,v 1.3 2003/04/02 10:35:04 wez Exp $
*/
extern zend_object_handlers php_irssi_handlers;
@@ -30,3 +30,7 @@
void php_irssi_export_WINDOW(zval *obj, WINDOW_REC *win TSRMLS_DC);
void php_irssi_export_WI_ITEM(zval *obj, WI_ITEM_REC *wi TSRMLS_DC);
void export_GList(zval *val, GSList *the_list TSRMLS_DC);
+void php_irssi_export_STATUSBAR(zval *obj, STATUSBAR_REC *si TSRMLS_DC);
+void php_irssi_export_SBAR_ITEM(zval *obj, SBAR_ITEM_REC *si TSRMLS_DC);
+
+
Index: embed/php-irssi/php-irssi.h
diff -u embed/php-irssi/php-irssi.h:1.12 embed/php-irssi/php-irssi.h:1.13
--- embed/php-irssi/php-irssi.h:1.12 Tue Apr 1 14:36:20 2003
+++ embed/php-irssi/php-irssi.h Wed Apr 2 05:35:04 2003
@@ -14,7 +14,7 @@
+----------------------------------------------------------------------+
| Author: Wez Furlong <[email protected]> |
+----------------------------------------------------------------------+
- $Id: php-irssi.h,v 1.12 2003/04/01 19:36:20 wez Exp $
+ $Id: php-irssi.h,v 1.13 2003/04/02 10:35:04 wez Exp $
*/
#define MODULE_NAME "php/core"
@@ -35,6 +35,7 @@
#include "commands.h"
#include "levels.h"
#include "fe-windows.h"
+#include "fe-text/statusbar.h"
#include "lib-config/iconfig.h" /* FIXME: remove before .99 */
#include "printtext.h"
@@ -54,6 +55,8 @@
PIAT_WI_ITEM,
PIAT_WINDOW,
PIAT_ARRAY_OF_NICK,
+ PIAT_STATUSBAR,
+ PIAT_SBAR_ITEM,
};
struct php_irssi_signal_args {
@@ -116,7 +119,9 @@
};
extern void php_irssi_themes_dtor(void *pDest);
+extern void php_irssi_statusbar_dtor(void *pDest);
extern HashTable *php_irssi_registered_themes;
+extern HashTable *php_irssi_statusbar_items;
#include "php-irssi-obj.h"
@@ -133,4 +138,6 @@
#define WI_FETCH() WI_ITEM_REC *wi = map_wi_item(getThis() TSRMLS_CC); if (wi == NULL) RETURN_NULL();
#define WINDOW_FETCH() WINDOW_REC *window = map_window(getThis() TSRMLS_CC); if (window == NULL) RETURN_NULL();
+
+#define SBI_FETCH() SBAR_ITEM_REC *sbi = map_sbar_item(getThis() TSRMLS_CC); if (sbi == NULL) RETURN_NULL();
Index: embed/php-irssi/typemap.php
diff -u embed/php-irssi/typemap.php:1.8 embed/php-irssi/typemap.php:1.9
--- embed/php-irssi/typemap.php:1.8 Mon Mar 31 15:16:50 2003
+++ embed/php-irssi/typemap.php Wed Apr 2 05:35:04 2003
@@ -15,7 +15,7 @@
+----------------------------------------------------------------------+
| Author: Wez Furlong <[email protected]> |
+----------------------------------------------------------------------+
- $Id: typemap.php,v 1.8 2003/03/31 20:16:50 wez Exp $
+ $Id: typemap.php,v 1.9 2003/04/02 10:35:04 wez Exp $
*/
/* This array describes the functions that can be used to convert between
@@ -27,6 +27,8 @@
"src/core/nick-rec.h" => array("NICK_REC", "irssi_nick"),
"src/core/window-item-rec.h" => array("WI_ITEM_REC", "irssi_windowitem"),
"src/fe-common/core/fe-windows.h" => array("WINDOW_REC", "irssi_window", null, "/struct _WINDOW_REC {([^}]+)}/sm"),
+ "./src/fe-text/statusbar.h" => array("STATUSBAR_REC", "irssi_statusbar", null, "/typedef struct {([^}]+)} STATUSBAR_REC;/sm"),
+ "src/fe-text/statusbar.h" => array("SBAR_ITEM_REC", "irssi_sbar_item_rec", null, "/struct SBAR_ITEM_REC {([^}]+)};/sm"),
);
Index: embed/php-irssi/statusbar.c
+++ embed/php-irssi/statusbar.c
/*
+----------------------------------------------------------------------+
| PHP for IRSSI |
+----------------------------------------------------------------------+
| Copyright (c) 1997-2003 The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 2.02 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available at through the world-wide-web at |
| http://www.php.net/license/2_02.txt. |
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| [email protected] so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
| Author: Wez Furlong <[email protected]> |
+----------------------------------------------------------------------+
$Id: statusbar.c,v 1.1 2003/04/02 10:35:04 wez Exp $
*/
#include "php-irssi.h"
#define PHP_IRSSI_PROTOS_ONLY
#include "php-irssi-obj-defs.h"
typedef struct {
zval *cb;
} php_irssi_statusbar_rec;
void php_irssi_statusbar_dtor(void *pDest)
{
php_irssi_statusbar_rec *rec = *(php_irssi_statusbar_rec**)pDest;
zval_ptr_dtor(&rec->cb);
efree(rec->cb);
efree(rec);
}
SBAR_ITEM_REC *map_sbar_item(zval *object TSRMLS_DC)
{
struct php_irssi_obj_ref *ref;
ref = php_irssi_ref_from_wrapper(object, "SBAR_ITEM" TSRMLS_CC);
if (ref == NULL) {
return NULL;
}
return ref->actual_ptr;
}
void *php_irssi_resolve_to_SBAR_ITEM_REC(struct php_irssi_obj_ref *ref)
{
return ref->actual_ptr;
}
/* Handle property reads */
int php_irssi_SBAR_ITEM_REC_prop_reader(char *member, int type, zval **retval, void *obj TSRMLS_DC)
{
PHP_IRSSI_SBAR_ITEM_REC_PROP_READER_HEAD();
PHP_IRSSI_SBAR_ITEM_REC_PROP_READER_FOOT();
}
void php_irssi_export_SBAR_ITEM(zval *obj, SBAR_ITEM_REC *si TSRMLS_DC)
{
struct php_irssi_obj_ref *ref;
if (si == NULL) {
ZVAL_NULL(obj);
return;
}
php_irssi_create_wrapper(&ref, "SBAR_ITEM", obj TSRMLS_CC);
if (ref) {
ref->actual_ptr = si;
}
}
/* proto void default_handler(bool get_size_only, string str, string data, bool escape_vars)
Set text for a status bar item */
PHP_FUNCTION(sbar_item_default_handler)
{
zend_bool get_size_only, escape_vars;
char *str, *data = NULL;
long strleng, datalen;
SBI_FETCH();
if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "bssb",
&get_size_only, &str, &strleng, &data, &datalen, &escape_vars)) {
return;
}
statusbar_item_default_handler(sbi, get_size_only, str, data, escape_vars);
}
/* proto void redraw()
redraw this item */
PHP_FUNCTION(sbar_item_redraw)
{
SBI_FETCH();
if (ZEND_NUM_ARGS() != 0) {
WRONG_PARAM_COUNT;
}
statusbar_item_redraw(sbi);
}
function_entry php_irssi_SBAR_ITEM_funcs[] = {
PHP_NAMED_FE(default_handler, PHP_FN(sbar_item_default_handler), NULL)
PHP_NAMED_FE(redraw, PHP_FN(sbar_item_redraw), NULL)
{NULL, NULL, NULL}
};
void *php_irssi_resolve_to_STATUSBAR_REC(struct php_irssi_obj_ref *ref)
{
return ref->actual_ptr;
}
/* Handle property reads */
int php_irssi_STATUSBAR_REC_prop_reader(char *member, int type, zval **retval, void *obj TSRMLS_DC)
{
PHP_IRSSI_STATUSBAR_REC_PROP_READER_HEAD();
PHP_IRSSI_STATUSBAR_REC_PROP_READER_FOOT();
}
/* Given a nick record, create a PHP nick object */
void php_irssi_export_STATUSBAR(zval *obj, STATUSBAR_REC *si TSRMLS_DC)
{
struct php_irssi_obj_ref *ref;
if (si == NULL) {
ZVAL_NULL(obj);
return;
}
php_irssi_create_wrapper(&ref, "STATUSBAR", obj TSRMLS_CC);
if (ref) {
ref->actual_ptr = si;
}
}
function_entry php_irssi_STATUSBAR_funcs[] = {
{NULL, NULL, NULL}
};
static void php_irssi_statusbar_handler(SBAR_ITEM_REC *item, int get_size_only)
{
php_irssi_statusbar_rec **rec;
zval **zargs[2];
zval *retval = NULL, *tmp;
int call_result;
if (FAILURE == zend_hash_find(php_irssi_statusbar_items, item->config->name, strlen(item->config->name)+1, (void**)&rec)) {
statusbar_item_default_handler(item, get_size_only, NULL, "", TRUE);
return;
}
zargs[0] = emalloc(sizeof(zval *));
MAKE_STD_ZVAL(*zargs[0]);
zargs[1] = emalloc(sizeof(zval *));
MAKE_STD_ZVAL(*zargs[1]);
tmp = *zargs[0];
php_irssi_export_SBAR_ITEM(tmp, item TSRMLS_CC);
tmp = *zargs[1];
ZVAL_BOOL(tmp, get_size_only);
zend_first_try {
call_result = call_user_function_ex(EG(function_table),
NULL,
(*rec)->cb,
&retval,
2,
zargs,
0, NULL TSRMLS_CC);
} zend_catch {
call_result = FAILURE;
} zend_end_try();
if (retval) {
zval_ptr_dtor(&retval);
}
zval_ptr_dtor(zargs[0]);
zval_ptr_dtor(zargs[1]);
efree(zargs[0]);
efree(zargs[1]);
}
/* proto void irssi_statusbar_item_register(string name, string value, mixed callback)
Register a statusbar item */
PHP_FUNCTION(irssi_statusbar_item_register)
{
char *name, *value;
long namelen, valuelen;
zval *cb;
php_irssi_statusbar_rec *rec;
if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ssz",
&name, &namelen, &value, &valuelen, &cb)) {
return;
}
statusbar_item_register(name, value, php_irssi_statusbar_handler);
rec = emalloc(sizeof(*rec));
MAKE_STD_ZVAL(rec->cb);
*(rec->cb) = *cb;
zval_copy_ctor(rec->cb);
zend_hash_update(php_irssi_statusbar_items, name, namelen+1, &rec, sizeof(rec), NULL);
}
/* proto void irssi_statusbar_items_redraw(string name)
Redraws all status bar items in a particular class */
PHP_FUNCTION(irssi_statusbar_items_redraw)
{
char *name;
long namelen;
if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s",
&name, &namelen)) {
return;
}
statusbar_items_redraw(name);
}
/*
* Local variables:
* tab-width: 4
* c-basic-offset: 4
* indent-tabs-mode: t
* End:
*/
Index: embed/php-irssi/examples/rotator.php
+++ embed/php-irssi/examples/rotator.php
<?php
/* Rotator displays a small statusbar item to show that irssi is still running */
namespace SampleRotator {
var $R = "foo";
class Rotator {
var $pos = 0;
var $display = '';
var $width = 10;
var $charset = 'hey there, this is a scrolling message';
function scroll()
{
$this->pos++;
if ($this->pos > strlen($this->charset)) {
$this->pos = 0;
}
$this->display = substr($this->charset, $this->pos, $this->width);
irssi_statusbar_items_redraw('php_rotator');
}
function draw_bar($item, $get_size_only)
{
$item->min_size = $this->width;
$item->default_handler($get_size_only, '{sb ' . $this->display . '}', '', true);
}
}
function init()
{
SampleRotator::$R = new SampleRotator::Rotator;
irssi_statusbar_item_register('php_rotator', '$0', array(SampleRotator::$R, 'draw_bar'));
irssi_timeout_add(800, array(SampleRotator::$R, 'scroll'));
}
}
SampleRotator::init();
?>