wez             Thu Jan 30 07:51:30 2003 EDT

  Modified files:              
    /embed/php-irssi    php-core.c 
  Log:
  Add some helpful comments
  
  
Index: embed/php-irssi/php-core.c
diff -u embed/php-irssi/php-core.c:1.3 embed/php-irssi/php-core.c:1.4
--- embed/php-irssi/php-core.c:1.3      Thu Jan 30 07:25:39 2003
+++ embed/php-irssi/php-core.c  Thu Jan 30 07:51:30 2003
@@ -14,7 +14,7 @@
   +----------------------------------------------------------------------+
   | Author: Wez Furlong <[EMAIL PROTECTED]>                                    |
   +----------------------------------------------------------------------+
-  $Id: php-core.c,v 1.3 2003/01/30 12:25:39 wez Exp $
+  $Id: php-core.c,v 1.4 2003/01/30 12:51:30 wez Exp $
 */
 #define MODULE_NAME "php/core"
 #include "common.h"
@@ -45,7 +45,8 @@
 int signal_php_error;
 WINDOW_REC *target_win;
 
-/* output to irssi crap output.
+/* Catch output pushed from the output buffer mechanism.
+ * Route it to "php output" signal.
  * TODO: this should line-buffer the output */
 static int ub_write(const char *str, unsigned int str_length TSRMLS_DC)
 {
@@ -53,11 +54,13 @@
        return SUCCESS;
 }
 
+/* Catch log-errors and route them to the "php error" signal */
 static void log_message(char *message)
 {
        signal_emit_id(signal_php_error, 1, message);
 }
 
+/* Catch general php errors, format them and route them to "php error" signal */
 static void sapi_error(int type, const char *fmt, ...)
 {
        char *buf;
@@ -70,6 +73,9 @@
        va_end(ap);
 }
 
+/* Eval some PHP code, but do it in such a way that an engine bail event wont
+ * kill off process.  Returns a tristate indicating success, error and fatal
+ * doom. */
 static enum eval_ret_t php_eval_string(const char *source, const char *fmt, ...)
 {
        enum eval_ret_t retval;
@@ -121,11 +127,15 @@
 
 static void fini_php(void)
 {
+       /* This is not an MSHUTDOWN function because there were issues with the 
+resource
+        * destruction order.  Explicitly calling this before the sapi is closed down
+        * saves that nightmare */
        php_irssi_module_shutdown();    
        
        php_embed_shutdown(TSRMLS_C);
 }
 
+/* Handler for the "/php" command */
 static void cmd_php(const char *data)
 {
        target_win = active_win;
@@ -142,16 +152,19 @@
        }
 }
 
+/* default "php error" signal handler */
 static void error_handler(char *message)
 {
        printtext_window(target_win, MSGLEVEL_CLIENTCRAP, "-!- php error: %s", 
message);
 }
 
+/* default "php output" signal handler */
 static void output_handler(const char *str, unsigned int str_length)
 {
        printtext_window(target_win, MSGLEVEL_CLIENTCRAP, "%s", str);
 }
 
+/* autorun any .php scripts found in the users scripts/autorun dir */
 static void do_autorun(void)
 {
        target_win = active_win;
@@ -171,13 +184,16 @@
        }
 }
 
+/* "irssi init finished" event handler.
+ * This is used to ensure that the whole of irssi has completed its
+ * init prior to launching autorun */
 static void sig_autorun(void)
 {
        signal_remove("irssi init finished", (SIGNAL_FUNC)sig_autorun);
        do_autorun();
 }
 
-/* Module init */
+/* Module init: called by irssi when the user types "/load php" */
 void php_core_init(void)
 {
        init_php();
@@ -190,15 +206,23 @@
        command_bind("php", NULL, (SIGNAL_FUNC)cmd_php);
 
        if (irssi_init_finished) {
+               /* if the module is being loaded manually execute autorun directly */
                do_autorun();
        } else {
+               /* otherwise arrange for it to be run when init is completed */
                signal_add("irssi init finished", (SIGNAL_FUNC)sig_autorun);
                settings_check();
        }
        
+       /* Tell irssi that we are loaded and ready */
        module_register("php", "core");
 }
 
+/* Called by irssi when the user types "/unload php".
+ * It is *absolutely essential* that *all* signal and command bindings are
+ * removed before this function exits, otherwise you will encounter random
+ * crashes.
+ * */
 void php_core_deinit(void)
 {
        /* bind to this event to implement destructors for your scripts,
@@ -209,6 +233,8 @@
        command_unbind("php", (SIGNAL_FUNC)cmd_php);
        signal_remove("php output", (SIGNAL_FUNC)output_handler);
        signal_remove("php error", (SIGNAL_FUNC)error_handler);
+
+
        fini_php();
 
        signal_emit("php unloaded", 0);



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

Reply via email to