ssb             Thu Mar 15 20:57:03 2001 EDT

  Modified files:              
    /pear/PEAR  pear.c php_pear.h 
  Log:
  * PEAR and PEAR_Error C implementations done
  
  
Index: pear/PEAR/pear.c
diff -u pear/PEAR/pear.c:1.3 pear/PEAR/pear.c:1.4
--- pear/PEAR/pear.c:1.3        Wed Mar 14 16:53:06 2001
+++ pear/PEAR/pear.c    Thu Mar 15 20:57:02 2001
@@ -24,6 +24,8 @@
 #include "build-defs.h"
 #include "ext/standard/info.h"
 
+/* {{{ structs and globals */
+
 ZEND_DECLARE_MODULE_GLOBALS(pear)
 
 /* Every user visible function must have an entry in pear_functions[].
@@ -33,28 +35,24 @@
 };
 
 static zend_function_entry php_class_functions_pear[] = {
-    PHP_FALIAS(pear,              pear_constructor, NULL)
-    PHP_FALIAS(_pear,             pear_destructor, NULL)
-    PHP_FALIAS(iserror,           pear_isError, first_arg_force_ref)
-    PHP_FALIAS(seterrorhandling,  pear_setErrorHandling, NULL)
-#if 0
-    PHP_FALIAS(raiseerror,        pear_raiseError, NULL)
-#endif
+    PHP_FALIAS(pear,              PEAR_constructor, NULL)
+    PHP_FALIAS(_pear,             PEAR_destructor, NULL)
+    PHP_FALIAS(iserror,           PEAR_isError, NULL)
+    PHP_FALIAS(seterrorhandling,  PEAR_setErrorHandling, NULL)
+    PHP_FALIAS(raiseerror,        PEAR_raiseError, NULL)
     {NULL, NULL, NULL}
 };
 
 static zend_function_entry php_class_functions_pear_error[] = {
-#if 0
-    PHP_FALIAS(pear_error,        pear_error_constructor, NULL)
-    PHP_FALIAS(getmode,           pear_error_getmode, NULL)
-    PHP_FALIAS(getcallback,       pear_error_getcallback, NULL)
-    PHP_FALIAS(getmessage,        pear_error_getmessage, NULL)
-    PHP_FALIAS(getcode,           pear_error_getcode, NULL)
-    PHP_FALIAS(gettype,           pear_error_gettype, NULL)
-    PHP_FALIAS(getuserinfo,       pear_error_getuserinfo, NULL)
-    PHP_FALIAS(getdebuginfo,      pear_error_getdebuginfo, NULL)
-    PHP_FALIAS(tostring,          pear_error_tostring, NULL)
-#endif
+    PHP_FALIAS(pear_error,        PEAR_Error_constructor, NULL)
+    PHP_FALIAS(getmode,           PEAR_Error_getMode, NULL)
+    PHP_FALIAS(getcallback,       PEAR_Error_getCallback, NULL)
+    PHP_FALIAS(getmessage,        PEAR_Error_getMessage, NULL)
+    PHP_FALIAS(getcode,           PEAR_Error_getCode, NULL)
+    PHP_FALIAS(gettype,           PEAR_Error_getType, NULL)
+    PHP_FALIAS(getuserinfo,       PEAR_Error_getUserInfo, NULL)
+    PHP_FALIAS(getdebuginfo,      PEAR_Error_getUserInfo, NULL)
+    PHP_FALIAS(tostring,          PEAR_Error_toString, NULL)
     {NULL, NULL, NULL}
 };
 
@@ -71,16 +69,27 @@
 
 static zend_class_entry *pear_ptr, *pear_error_ptr;
 
+/* }}} */
+
+/* {{{ get_module() */
 
 #ifdef COMPILE_DL_PEAR
 ZEND_GET_MODULE(pear)
 #endif
 
+/* }}} */
+
+/* {{{ ini entries */
+
 /* Remove comments and fill if you need to have entries in php.ini
 PHP_INI_BEGIN()
 PHP_INI_END()
 */
 
+/* }}} */
+
+/* {{{ minit */
+
 PHP_MINIT_FUNCTION(pear)
 {
     zend_class_entry pear, pear_error;
@@ -106,14 +115,14 @@
     pear_error.handle_property_get = NULL;
     pear_error.handle_property_set = NULL;
        pear_error_ptr = zend_register_internal_class(&pear_error);
+    EMPTY_STRING_PROPERTY(pear_error_ptr, tmp, "message");
     LONG_PROPERTY(pear_error_ptr, tmp, "code", -1);
-    NULL_PROPERTY(pear_error_ptr, tmp, "n2345678901234567");
-    NULL_PROPERTY(pear_error_ptr, tmp, "error_message_prefix");
-    NULL_PROPERTY(pear_error_ptr, tmp, "error_prepend");
-    NULL_PROPERTY(pear_error_ptr, tmp, "error_append");
     LONG_PROPERTY(pear_error_ptr, tmp, "mode", PEAR_ERROR_RETURN);
     LONG_PROPERTY(pear_error_ptr, tmp, "level", E_USER_NOTICE);
-    NULL_PROPERTY(pear_error_ptr, tmp, "debuginfo");
+    NULL_PROPERTY(pear_error_ptr, tmp, "userinfo");
+    EMPTY_STRING_PROPERTY(pear_error_ptr, tmp, "error_message_prefix");
+    EMPTY_STRING_PROPERTY(pear_error_ptr, tmp, "error_prepend");
+    EMPTY_STRING_PROPERTY(pear_error_ptr, tmp, "error_append");
 
     LONG_CONSTANT("PEAR_ERROR_RETURN",    PEAR_ERROR_RETURN);
     LONG_CONSTANT("PEAR_ERROR_PRINT",     PEAR_ERROR_PRINT);
@@ -125,6 +134,9 @@
        return SUCCESS;
 }
 
+/* }}} */
+/* {{{ mshutdown */
+
 PHP_MSHUTDOWN_FUNCTION(pear)
 {
 /* Remove comments if you have entries in php.ini
@@ -133,6 +145,10 @@
        return SUCCESS;
 }
 
+/* }}} */
+
+/* {{{ _destructor_objects_dtor() */
+
 static void
 _destructor_objects_dtor(void *data)
 {
@@ -140,35 +156,17 @@
     /*ZVAL_DELREF(object);*/
     zval_dtor(object);
 }
-
-/* Remove if there's nothing to do at request start */
-PHP_RINIT_FUNCTION(pear)
-{
-    zend_llist_init(&PEARG(destructor_objects), sizeof(zval), 
_destructor_objects_dtor, 0);
-       return SUCCESS;
-}
 
-static zval *_pear_string_zval(const char *str)
-{
-       zval *ret;
-       int len = strlen(str);
-       MAKE_STD_ZVAL(ret);
-
-       ret->type = IS_STRING;
-       ret->value.str.len = len;
-       ret->value.str.val = estrndup(str, len);
-       return ret;
-}
+/* }}} */
+/* {{{ _call_destructors() */
 
 static void
 _call_destructors(void *data)
 {
-    zval *object = (zval *)data, *funcname, *arg, *retval;
+    zval *object = (zval *)data, *funcname, *retval;
     int res;
     
     MAKE_STD_ZVAL(funcname);
-    MAKE_STD_ZVAL(retval);
-    MAKE_STD_ZVAL(arg);
     funcname->type = IS_STRING;
     funcname->value.str.len = object->value.obj.ce->name_length + 1;
     funcname->value.str.val = emalloc(funcname->value.str.len + 1);
@@ -176,20 +174,29 @@
     memcpy(&funcname->value.str.val[1], object->value.obj.ce->name,
            funcname->value.str.len);
     funcname->value.str.val[funcname->value.str.len] = '\0';
-    res = call_user_function(&object->value.obj.ce->function_table, &object,
-                             funcname, retval, 0, &arg);
+    res = call_user_function_ex(&object->value.obj.ce->function_table, &object, 
+funcname, &retval, 0, NULL, 1, NULL);
     if (res == FAILURE) {
         php_error(E_WARNING, "calling %s::%s destructor failed!",
                   object->value.obj.ce->name, funcname->value.str.val);
     }
     zval_dtor(funcname);
-    zval_dtor(retval);
-    zval_dtor(arg);
     efree(funcname);
-    efree(retval);
-    efree(arg);
 }
 
+/* }}} */
+
+/* {{{ rinit */
+
+/* Remove if there's nothing to do at request start */
+PHP_RINIT_FUNCTION(pear)
+{
+    zend_llist_init(&PEARG(destructor_objects), sizeof(zval), 
+_destructor_objects_dtor, 0);
+       return SUCCESS;
+}
+
+/* }}} */
+/* {{{ rshutdown */
+
 /* Remove if there's nothing to do at request end */
 PHP_RSHUTDOWN_FUNCTION(pear)
 {
@@ -199,17 +206,26 @@
        return SUCCESS;
 }
 
+/* }}} */
+
+/* {{{ minfo */
+
 PHP_MINFO_FUNCTION(pear)
 {
        php_info_print_table_start();
-       php_info_print_table_header(2, "PEAR", " $Revision: 1.3 $");
+       php_info_print_table_header(2, "PEAR", " $Revision: 1.4 $");
        php_info_print_table_end();
 
        /* DISPLAY_INI_ENTRIES(); */
 }
 
+/* }}} */
+
+/* {{{ proto void PEAR::PEAR()
+
+   PEAR object constructor */
 
-PHP_FUNCTION(pear_constructor)
+PHP_FUNCTION(PEAR_constructor)
 {
     zval *this = getThis();
     size_t len;
@@ -233,14 +249,21 @@
     efree(dtorfunc);
 }
 
+/* }}} */
+/* {{{ proto void PEAR::_PEAR()
 
-PHP_FUNCTION(pear_destructor)
+   PEAR default destructor */
+
+PHP_FUNCTION(PEAR_destructor)
 {
     /*php_printf("PEAR destructor called\n");*/
 }
 
+/* }}} */
+/* {{{ proto bool PEAR::isError(object)
+   Test whether a value is a PEAR error */
 
-PHP_FUNCTION(pear_isError)
+PHP_FUNCTION(PEAR_isError)
 {
     zval **obj;
     zend_class_entry *ce = NULL;
@@ -261,8 +284,12 @@
     RETURN_FALSE;
 }
 
+/* }}} */
+/* {{{ proto void PEAR::setErrorHandling(mode, [options])
+
+   Set the default error handling for this object or globally */
 
-PHP_FUNCTION(pear_setErrorHandling)
+PHP_FUNCTION(PEAR_setErrorHandling)
 {
     zval **mode = NULL, **options = NULL, *this = getThis(), *tmp;
     HashTable *symtab;
@@ -331,6 +358,428 @@
 
 }
 
+/* }}} */
+/* {{{ proto object PEAR::raiseError([message [,code [,mode [,options 
+[,userinfo]]]]]) 
+   Returns an error object with defaults applied */
+
+PHP_FUNCTION(PEAR_raiseError)
+{
+    zval **message = NULL, **code = NULL, **mode = NULL,
+        **options = NULL, **userinfo = NULL,
+        *this = getThis(), **args[5], *ctor, *retval;
+    int argc = ZEND_NUM_ARGS(), res, nargs;
+
+    if (argc < 1 || argc > 5 ||
+        zend_get_parameters_ex(argc, &message, &code, &mode, &options, &userinfo) == 
+FAILURE) {
+        ZEND_WRONG_PARAM_COUNT();
+    }
+
+    if (this == NULL) {
+        RETURN_FALSE;
+    }
+
+    if (message) {
+        convert_to_string_ex(message);
+    } else {
+        message = emalloc(sizeof(zval *));
+        MAKE_STD_ZVAL(*message);
+        ZVAL_NULL(*message);
+    }
+    if (code) {
+        convert_to_long_ex(code);
+    } else {
+        code = emalloc(sizeof(zval *));
+        MAKE_STD_ZVAL(*code);
+        ZVAL_NULL(*code);
+    }
+    if (mode) {
+        convert_to_long_ex(mode);
+    } else {
+        mode = emalloc(sizeof(zval *));
+        MAKE_STD_ZVAL(*mode);
+        ZVAL_NULL(*mode);
+    }
+    if (options) {
+        convert_to_long_ex(options);
+    } else {
+        options = emalloc(sizeof(zval *));
+        MAKE_STD_ZVAL(*options);
+        ZVAL_NULL(*options);
+    }
+    if (userinfo == NULL) {
+        userinfo = emalloc(sizeof(zval *));
+        MAKE_STD_ZVAL(*userinfo);
+        ZVAL_NULL(*userinfo);
+    }
+
+    if (Z_TYPE_PP(mode) == IS_NULL &&
+        (zend_hash_find(this->value.obj.properties, "_default_error_mode", 
+sizeof("_default_error_mode"), (void **) &mode) == FAILURE || Z_TYPE_PP(mode) == 
+IS_NULL) &&
+        (zend_hash_find(&EG(symbol_table), "_PEAR_default_error_mode", 
+sizeof("_PEAR_default_error_mode"), (void **) &mode) == FAILURE || Z_TYPE_PP(mode) == 
+IS_NULL))
+    {
+        ZVAL_LONG(*mode, PEAR_ERROR_RETURN);
+    }
+
+#define FIND_DEFAULT(h,p,v) (zend_hash_find((h), (p), sizeof(p), (void **) &(v)) == 
+SUCCESS && Z_TYPE_PP(v) != IS_NULL)
+    switch (Z_LVAL_PP(mode)) {
+        case PEAR_ERROR_CALLBACK:
+            if ((Z_TYPE_PP(options) == IS_NULL || !zend_is_callable(*options)) &&
+                !FIND_DEFAULT(this->value.obj.properties, "_default_error_callback", 
+options) &&
+                !FIND_DEFAULT(&EG(symbol_table), "_PEAR_default_error_callback", 
+options))
+            {
+                /* no callback function provided */
+            }
+            break;
+        case PEAR_ERROR_TRIGGER:
+            if (Z_TYPE_PP(options) == IS_NULL &&
+                !FIND_DEFAULT(this->value.obj.properties, "_default_error_options", 
+options) &&
+                !FIND_DEFAULT(&EG(symbol_table), "_PEAR_default_error_options", 
+options))
+            {
+                ZVAL_LONG(*options, E_USER_NOTICE);
+            }
+            break;
+        default:
+            if (Z_TYPE_PP(options) == IS_NULL &&
+                !FIND_DEFAULT(this->value.obj.properties, "_default_error_options", 
+options) &&
+                !FIND_DEFAULT(&EG(symbol_table), "_PEAR_default_error_options", 
+options))
+            {
+                /* no options set */
+            }
+            break;
+    }
+
+#if 0
+    php_printf("PEAR::raiseError:");
+    php_printf("\nmessage="); zend_print_zval(*message, 0);
+    php_printf("\ncode="); zend_print_zval(*code, 0);
+    php_printf("\nmode="); zend_print_zval(*mode, 0);
+    php_printf("\noptions="); zend_print_zval(*options, 0);
+    php_printf("\nuserinfo="); zend_print_zval(*userinfo, 0);
+    php_printf("\n");
+#endif
+
+    /* make a PEAR_Error object */
+    if (object_init_ex(return_value, pear_error_ptr) == FAILURE) {
+        RETURN_FALSE;
+    }
+
+    /* call the constructor */
+    args[0] = message;
+    args[1] = code;
+    args[2] = mode;
+    args[3] = options;
+    args[4] = userinfo;
+    for (nargs = 5; nargs > 0; nargs--) {
+        if (Z_TYPE_PP(args[nargs - 1]) != IS_NULL) {
+            break;
+        }
+    }
+    MAKE_STD_ZVAL(ctor);
+    ZVAL_STRING(ctor, "pear_error", 1);
+    res = call_user_function_ex(&return_value->value.obj.ce->function_table, 
+&return_value, ctor, &retval, 5, args, 1, NULL);
+    if (res == FAILURE) {
+        php_error(E_WARNING, "PEAR::raiseError: calling PEAR_Error constructor 
+failed!");
+        zval_dtor(ctor);
+        zval_dtor(retval);
+        zval_dtor(return_value); /* free the pear_error object */
+        efree(ctor);
+        efree(retval);
+        RETURN_FALSE;
+    }
+}
+
+/* }}} */
+
+/* {{{ php_pear_error_get() */
+
+static void
+php_pear_error_get(INTERNAL_FUNCTION_PARAMETERS, char *property, int proplen)
+{
+    zval *this = getThis(), **prop;
+
+    if (this == NULL || zend_hash_find(this->value.obj.properties, property, proplen, 
+(void **)&prop) == FAILURE) {
+        RETURN_FALSE;
+    }
+    COPY_PZVAL_TO_ZVAL(*return_value, *prop);
+}
+
+
+#define PEAR_ERROR_GETXXX(x) php_pear_error_get(INTERNAL_FUNCTION_PARAM_PASSTHRU, 
+(x), sizeof(x))
+
+/* }}} */
+/* {{{ _pear_get_user_error_name() */
+
+static const char *
+_pear_get_user_error_name(int error)
+{
+    switch (error) {
+        case E_USER_NOTICE:
+            return "notice";
+        case E_USER_WARNING:
+            return "warning";
+        case E_USER_ERROR:
+            return "error";
+        default:
+            return "unknown";
+    }
+}
+
+/* }}} */
+/* {{{ _pear_get_error_mode_name() */
+
+static const char *
+_pear_get_error_mode_name(int error)
+{
+    switch (error) {
+        case PEAR_ERROR_RETURN:
+            return "return";
+        case PEAR_ERROR_PRINT:
+            return "print";
+        case PEAR_ERROR_DIE:
+            return "die";
+        case PEAR_ERROR_TRIGGER:
+            return "trigger";
+        case PEAR_ERROR_CALLBACK:
+            return "callback";
+        default:
+            return "unknown";
+    }
+}
+
+/* }}} */
+
+/* {{{ PEAR_Error::PEAR_Error([message [, code [, mode [, options [, userinfo]]]]])
+   PEAR_Error constructor */
+
+PHP_FUNCTION(PEAR_Error_constructor)
+{
+    zval **message = NULL, **code = NULL, **mode = NULL, **options = NULL, **userinfo 
+= NULL;
+    zval *nullval, *this = getThis();
+    int argc = ZEND_NUM_ARGS();
+    
+    if (argc > 5) {
+        ZEND_WRONG_PARAM_COUNT();
+    }
+    
+    if (this == NULL) {
+        RETURN_FALSE;
+    }
+    
+    if (message) {
+        convert_to_string_ex(message);
+    } else {
+        message = emalloc(sizeof(zval *));
+        MAKE_STD_ZVAL(*message);
+        ZVAL_NULL(*message);
+    }
+    if (code) {
+        convert_to_long_ex(code);
+    } else {
+        code = emalloc(sizeof(zval *));
+        MAKE_STD_ZVAL(*code);
+        ZVAL_NULL(*code);
+    }
+    if (mode) {
+        convert_to_long_ex(mode);
+    } else {
+        mode = emalloc(sizeof(zval *));
+        MAKE_STD_ZVAL(*mode);
+        ZVAL_NULL(*mode);
+    }
+    if (options) {
+        convert_to_long_ex(options);
+    } else {
+        options = emalloc(sizeof(zval *));
+        MAKE_STD_ZVAL(*options);
+        ZVAL_NULL(*options);
+    }
+    if (userinfo == NULL) {
+        userinfo = emalloc(sizeof(zval *));
+        MAKE_STD_ZVAL(*userinfo);
+        ZVAL_NULL(*userinfo);
+    }
+    MAKE_STD_ZVAL(nullval);
+    ZVAL_NULL(nullval);
+    
+    if (Z_TYPE_PP(mode) == IS_NULL) {
+        ZVAL_LONG(*mode, PEAR_ERROR_RETURN);
+    }
+    
+    if (Z_TYPE_PP(message) != IS_NULL) {
+        add_property_zval_ex(this, "message", sizeof("message"), *message);
+    }
+    if (Z_TYPE_PP(code) != IS_NULL) {
+        add_property_zval_ex(this, "code", sizeof("code"), *code);
+    }
+    if (Z_TYPE_PP(mode) != IS_NULL) {
+        add_property_zval_ex(this, "mode", sizeof("mode"), *mode);
+    }
+    if (Z_TYPE_PP(userinfo) != IS_NULL) {
+        add_property_zval_ex(this, "userinfo", sizeof("userinfo"), *userinfo);
+    }
+    if (Z_TYPE_PP(mode) == IS_LONG && Z_LVAL_PP(mode) & PEAR_ERROR_CALLBACK) {
+        add_property_long_ex(this, "level", sizeof("level"), E_USER_NOTICE);
+        add_property_zval_ex(this, "callback", sizeof("callback"), *options);
+    } else {
+        if (Z_TYPE_PP(options) == IS_NULL) {
+            ZVAL_LONG(*options, E_USER_NOTICE);
+        }
+        add_property_zval_ex(this, "level", sizeof("level"), *options);
+        add_property_zval_ex(this, "callback", sizeof("callback"), nullval);
+    }
+    if (Z_LVAL_PP(mode) & PEAR_ERROR_PRINT) {
+        PUTS(Z_STRVAL_PP(message));
+    }
+    if (Z_LVAL_PP(mode) & PEAR_ERROR_TRIGGER) {
+        int x = 0, len = Z_STRLEN_PP(message);
+        char *tmpstr = emalloc(len * 2) + 1;
+        char *p = Z_STRVAL_PP(message);
+        char *q = tmpstr, *end = p + len;
+        p = Z_STRVAL_PP(message);
+        while (p < end) {
+            if (*p == '%') {
+                *q++ = '%';
+                x++;
+            }
+            *q++ = *p++;
+        }
+        *q = '\0';
+        php_error(Z_LVAL_PP(options), tmpstr);
+        efree(tmpstr);
+    }
+    if (Z_LVAL_PP(mode) & PEAR_ERROR_CALLBACK) {
+        if (zend_is_callable(*options)) {
+            zval *retval, **args[1];
+            args[0] = &this;
+            if (call_user_function_ex(EG(function_table), NULL, *options, &retval, 1, 
+args, 1, NULL) == FAILURE) {
+                php_error(E_WARNING, "PEAR_Error failed to invoke callback");
+            }
+        }
+    }
+    if (Z_LVAL_PP(mode) & PEAR_ERROR_DIE) {
+        zend_print_zval(*message, 0);
+        zend_bailout();
+    }
+}
+
+/* }}} */
+/* {{{ proto void PEAR_Error::getMode() */
+
+PHP_FUNCTION(PEAR_Error_getMode)
+{
+    PEAR_ERROR_GETXXX("mode");
+}
+
+/* }}} */
+/* {{{ proto void PEAR_Error::getCallback() */
+
+PHP_FUNCTION(PEAR_Error_getCallback)
+{
+    PEAR_ERROR_GETXXX("callback");
+}
+
+/* }}} */
+/* {{{ proto void PEAR_Error::getMessage() */
+
+PHP_FUNCTION(PEAR_Error_getMessage)
+{
+    PEAR_ERROR_GETXXX("message");
+}
+
+/* }}} */
+/* {{{ proto void PEAR_Error::getCode() */
+
+PHP_FUNCTION(PEAR_Error_getCode)
+{
+    PEAR_ERROR_GETXXX("code");
+}
+
+/* }}} */
+/* {{{ proto void PEAR_Error::getType() */
+
+PHP_FUNCTION(PEAR_Error_getType)
+{
+    PEAR_ERROR_GETXXX("type");
+}
+
+/* }}} */
+/* {{{ proto void PEAR_Error::getUserInfo() */
+
+PHP_FUNCTION(PEAR_Error_getUserInfo)
+{
+    PEAR_ERROR_GETXXX("userinfo");
+}
+
+/* }}} */
+/* {{{ proto string PEAR_Error::toString() */
+
+#define PEAR_ERROR_TOSTRING_LOOKUP(name,prop) 
+zend_hash_find(this->value.obj.properties, (name), sizeof(name), (void **)&(prop))
+#define MY_STRVAL_PP(x) (Z_TYPE_PP(x) == IS_STRING ? Z_STRVAL_PP(x) : "")
+
+PHP_FUNCTION(PEAR_Error_toString)
+{
+    zval **message = NULL, **code = NULL, **mode = NULL, **options = NULL,
+        **prefix = NULL, **prepend = NULL, **append = NULL, **info = NULL;
+    zval *this = getThis();
+    int errormodes[] = {
+        PEAR_ERROR_RETURN,
+        PEAR_ERROR_PRINT,
+        PEAR_ERROR_TRIGGER,
+        PEAR_ERROR_DIE,
+        PEAR_ERROR_CALLBACK
+    };
+    int nmodes = sizeof(errormodes)/sizeof(int), m, usedmodes = 0, i, j, codeval;
+    char strbuf[8192], optiondesc[512], modes[512], *classname;
+
+    PEAR_ERROR_TOSTRING_LOOKUP("message", message);
+    PEAR_ERROR_TOSTRING_LOOKUP("code", code);
+    PEAR_ERROR_TOSTRING_LOOKUP("mode", mode);
+    PEAR_ERROR_TOSTRING_LOOKUP("level", options);
+    PEAR_ERROR_TOSTRING_LOOKUP("error_message_prefix", prefix);
+    PEAR_ERROR_TOSTRING_LOOKUP("error_prepend", prepend);
+    PEAR_ERROR_TOSTRING_LOOKUP("error_append", append);
+    PEAR_ERROR_TOSTRING_LOOKUP("userinfo", info);
+
+    m = Z_LVAL_PP(mode);
+    for (i = 0; i < nmodes; i++) {
+        if (m & errormodes[i]) {
+            usedmodes++;
+        }
+    }
+    modes[0] = '\0';
+    for (i = j = 0; i < nmodes; i++) {
+        if (m & errormodes[i]) {
+            strlcat(modes, _pear_get_error_mode_name(m & errormodes[i]), 
+sizeof(modes));
+        }
+        if (++j < usedmodes) {
+            strlcat(modes, "|", sizeof(modes));
+        }
+    }
+    classname = this->value.obj.ce->name;
+    if (m & PEAR_ERROR_CALLBACK) {
+        if (Z_TYPE_PP(options) == IS_ARRAY) {
+            zval **tmpobj = NULL, **tmpfunc = NULL;
+            zend_hash_index_find(Z_ARRVAL_PP(options), 0, (void **)&tmpobj);
+            zend_hash_index_find(Z_ARRVAL_PP(options), 1, (void **)&tmpfunc);
+            if (tmpobj && tmpfunc && Z_TYPE_PP(tmpobj) == IS_OBJECT && 
+Z_TYPE_PP(tmpfunc) == IS_STRING) {
+                snprintf(optiondesc, sizeof(optiondesc), "%.*s::%.*s",
+                         (int)(*tmpobj)->value.obj.ce->name_length, 
+(*tmpobj)->value.obj.ce->name,
+                         (int)(*tmpfunc)->value.str.len, (*tmpfunc)->value.str.val);
+            } else {
+                strlcpy(optiondesc, MY_STRVAL_PP(options), sizeof(optiondesc));
+            }
+        }
+    } else {
+        strlcpy(optiondesc, _pear_get_user_error_name(Z_LVAL_PP(options)), 
+sizeof(optiondesc));
+    }
+    codeval = (Z_TYPE_PP(code) == IS_LONG) ? Z_LVAL_PP(code) : 0;
+    snprintf(strbuf, sizeof(strbuf),
+             "[%s: message=\"%s\" code=%d mode=%s options=%s prefix=\"%s\" 
+prepend=\"%s\" append=\"%s\" info=\"%s\"]",
+             classname, MY_STRVAL_PP(message), (int)Z_LVAL_PP(code), modes, 
+optiondesc, MY_STRVAL_PP(prefix),
+             MY_STRVAL_PP(prepend), MY_STRVAL_PP(append), MY_STRVAL_PP(info));
+    RETURN_STRING(strbuf, 1);
+}
+
+/* }}} */
 
 /*
  * Local variables:
Index: pear/PEAR/php_pear.h
diff -u pear/PEAR/php_pear.h:1.2 pear/PEAR/php_pear.h:1.3
--- pear/PEAR/php_pear.h:1.2    Tue Mar 13 17:04:45 2001
+++ pear/PEAR/php_pear.h        Thu Mar 15 20:57:02 2001
@@ -88,9 +88,21 @@
 PHP_RSHUTDOWN_FUNCTION(pear);
 PHP_MINFO_FUNCTION(pear);
 
-PHP_FUNCTION(pear_constructor);
-PHP_FUNCTION(pear_destructor);
-PHP_FUNCTION(pear_isError);
+PHP_FUNCTION(PEAR_constructor);
+PHP_FUNCTION(PEAR_destructor);
+PHP_FUNCTION(PEAR_isError);
+PHP_FUNCTION(PEAR_setErrorHandling);
+PHP_FUNCTION(PEAR_raiseError);
+
+PHP_FUNCTION(PEAR_Error_constructor);
+PHP_FUNCTION(PEAR_Error_getMode);
+PHP_FUNCTION(PEAR_Error_getCallback);
+PHP_FUNCTION(PEAR_Error_getMessage);
+PHP_FUNCTION(PEAR_Error_getCode);
+PHP_FUNCTION(PEAR_Error_getType);
+PHP_FUNCTION(PEAR_Error_getUserInfo);
+PHP_FUNCTION(PEAR_Error_getUserInfo);
+PHP_FUNCTION(PEAR_Error_toString);
 
 ZEND_BEGIN_MODULE_GLOBALS(pear)
     zend_llist destructor_objects;

-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to