cvs: embed /php-irssi php-core.c
[email protected] ("Wez Furlong") Mon, 31 Mar 2003 23:23:52 -0000
| Newsgroups | php.embed.cvs |
|---|---|
| Message-ID | <cvswez1049153032@cvsserver> |
wez Mon Mar 31 18:23:52 2003 EDT
Modified files:
/embed/php-irssi php-core.c
Log:
Line buffer echo/print output (at last!).
Make the include_path settable via irssi settings (so user can /save it).
Index: embed/php-irssi/php-core.c
diff -u embed/php-irssi/php-core.c:1.18 embed/php-irssi/php-core.c:1.19
--- embed/php-irssi/php-core.c:1.18 Mon Mar 31 10:15:10 2003
+++ embed/php-irssi/php-core.c Mon Mar 31 18:23:52 2003
@@ -15,7 +15,7 @@
| Authors: Wez Furlong <[email protected]> |
| Tal Peer <[email protected]> |
+----------------------------------------------------------------------+
- $Id: php-core.c,v 1.18 2003/03/31 15:15:10 wez Exp $
+ $Id: php-core.c,v 1.19 2003/03/31 23:23:52 wez Exp $
*/
#define MODULE_NAME "php/core"
#include "common.h"
@@ -33,6 +33,8 @@
#include "php-irssi.h"
#include <php_embed.h>
+#include <ext/standard/php_smart_str.h>
+
extern void php_irssi_module_shutdown();
enum eval_ret_t { EVAL_RET_ERROR, EVAL_RET_OK, EVAL_RET_BAIL };
@@ -48,11 +50,31 @@
int signal_php_error;
/* Catch output pushed from the output buffer mechanism.
- * Route it to "php output" signal.
- * TODO: this should line-buffer the output */
+ * Route it to "php output" signal. */
+static smart_str ub_write_buffer = { NULL, 0, 0 };
static int ub_write(const char *str, unsigned int str_length TSRMLS_DC)
{
- signal_emit_id(signal_php_output, 2, str, str_length);
+ char *eol = NULL;
+ size_t len;
+
+ smart_str_appendl(&ub_write_buffer, str, str_length);
+ smart_str_0(&ub_write_buffer);
+
+ /* look for line breaks */
+ do {
+ eol = memchr(ub_write_buffer.c, '\n', ub_write_buffer.len);
+
+ if (eol) {
+ len = eol - ub_write_buffer.c;
+ *eol = '\0';
+ signal_emit_id(signal_php_output, 2, ub_write_buffer.c, len);
+
+ memmove(ub_write_buffer.c, eol + 1, ub_write_buffer.len - len + 1);
+ ub_write_buffer.len -= len + 1;
+ smart_str_0(&ub_write_buffer);
+ }
+ } while (eol);
+
return SUCCESS;
}
@@ -90,7 +112,7 @@
vspprintf(&data, 0, fmt, ap);
printtext_window(active_win, MSGLEVEL_CLIENTCRAP, "-!- eval: %s", data);
- retval = zend_eval_string((char*)data, NULL, (char*)source) == SUCCESS ? EVAL_RET_OK : EVAL_RET_ERROR;
+ retval = zend_eval_string(data, NULL, (char*)source) == SUCCESS ? EVAL_RET_OK : EVAL_RET_ERROR;
} zend_catch {
retval = EVAL_RET_BAIL;
@@ -282,13 +304,12 @@
command_bind("php version", NULL, (SIGNAL_FUNC)cmd_php_version);
command_bind("php set", NULL, (SIGNAL_FUNC)cmd_php_set);
- /* XXX: We need to make that changeable... */
spprintf(&include_path, -1, "%s/scripts:%s", get_irssi_dir(), SCRIPTDIR);
+ settings_add_str("php", "php_include_path", include_path);
+ efree(include_path);
- php_set_ini_entry("include_path", include_path, PHP_INI_STAGE_ACTIVATE);
+ php_set_ini_entry("include_path", (char*)settings_get_str("php_include_path"), PHP_INI_STAGE_ACTIVATE);
php_set_ini_entry("html_errors", "0", PHP_INI_STAGE_ACTIVATE);
-
- efree(include_path);
if (irssi_init_finished) {
/* if the module is being loaded manually execute autorun directly */
@@ -325,6 +346,7 @@
signal_remove("php output", (SIGNAL_FUNC)output_handler);
signal_remove("php error", (SIGNAL_FUNC)error_handler);
+ smart_str_free(&ub_write_buffer);
fini_php();