At 18:59 28.11.2002, Ilia A. wrote:
On November 28, 2002 12:56 pm, Maxim Maletsky wrote:
> Shall we still consider introducing error codes to PHP? IMO, it does not
> represent any enormous maintenance increase while has some positive
> points.

Do you have an effecient manner in which to implement the introduction of
error codes?

Ilia

That's not the problem (see patch below). The problem is changing the
whole source to use error-codes and having a scheme for the codes.

marcus

cvs -z3 -q diff main.c php.h (in directory S:\php4-HEAD\main)
Index: main.c
===================================================================
RCS file: /repository/php4/main/main.c,v
retrieving revision 1.518
diff -u -r1.518 main.c
--- main.c 21 Nov 2002 14:56:06 -0000 1.518
+++ main.c 28 Nov 2002 18:06:48 -0000
@@ -385,16 +385,25 @@
/* }}} */

/* {{{ php_verror */
+PHPAPI void php_verror(const char *docref, const char *params, int type, const char *format, va_list args TSRMLS_DC)
+{
+ php_verror_ex(NULL, docref, params, type, format, args TSRMLS_CC);
+}
+/* }}} */
+
+/* {{{ php_verror_ex */
/* php_verror is called from php_error_docref<n> functions.
* Its purpose is to unify error messages and automatically generate clickable
* html error messages if correcponding ini setting (html_errors) is activated.
* See: CODING_STANDARDS for details.
*/
-PHPAPI void php_verror(const char *docref, const char *params, int type, const char *format, va_list args TSRMLS_DC)
+PHPAPI void php_verror_ex(const char *error_code, const char *docref, const char *params, int type, const char *format, va_list args TSRMLS_DC)
{
char *buffer = NULL, *docref_buf = NULL, *ref = NULL, *target = NULL;
char *docref_target = "", *docref_root = "";
char *function, *p;
+ char *error_code_separator1 = error_code ? "< " : "";
+ char *error_code_separator2 = error_code ? "> " : "";
int buffer_len = 0;

buffer_len = vspprintf(&buffer, 0, format, args);
@@ -442,9 +451,9 @@
}
}
if (PG(html_errors)) {
- php_error(type, "%s(%s) [<a href='%s%s%s'>%s</a>]: %s", get_active_function_name(TSRMLS_C), params, docref_root, docref, docref_target, docref, buffer);
+ php_error(type, "%s(%s) [<a href='%s%s%s'>%s</a>]: %s%s%s%s", get_active_function_name(TSRMLS_C), params, docref_root, docref, docref_target, docref, error_code_separator1, error_code, error_code_separator2, buffer);
} else {
- php_error(type, "%s(%s) [%s%s%s]: %s", get_active_function_name(TSRMLS_C), params, docref_root, docref, docref_target, buffer);
+ php_error(type, "%s(%s) [%s%s%s]: %s%s%s%s", get_active_function_name(TSRMLS_C), params, docref_root, docref, docref_target, error_code_separator1, error_code, error_code_separator2, buffer);
}
if (target) {
efree(target);
@@ -453,7 +462,7 @@
docref = get_active_function_name(TSRMLS_C);
if (!docref)
docref = "Unknown";
- php_error(type, "%s(%s): %s", docref, params, buffer);
+ php_error(type, "%s(%s): %s%s%s%s", docref, params, error_code_separator1, error_code, error_code_separator2, buffer);
}

if (PG(track_errors) && EG(active_symbol_table)) {
@@ -475,6 +484,18 @@
}
/* }}} */

+/* {{{ php_error_ex */
+/* See: CODING_STANDARDS for details. */
+PHPAPI void php_error_ex(const char *error_code, const char *docref TSRMLS_DC, int type, const char *format, ...)
+{
+ va_list args;
+
+ va_start(args, format);
+ php_verror_ex(error_code, docref, "", type, format, args TSRMLS_CC);
+ va_end(args);
+}
+/* }}} */
+
/* {{{ php_error_docref */
/* See: CODING_STANDARDS for details. */
PHPAPI void php_error_docref(const char *docref TSRMLS_DC, int type, const char *format, ...)
@@ -487,6 +508,18 @@
}
/* }}} */

+/* {{{ php_error_ex1 */
+/* See: CODING_STANDARDS for details. */
+PHPAPI void php_error_ex1(const char *error_code, const char *docref TSRMLS_DC, const char *param1, int type, const char *format, ...)
+{
+ va_list args;
+
+ va_start(args, format);
+ php_verror_ex(error_code, docref, param1, type, format, args TSRMLS_CC);
+ va_end(args);
+}
+/* }}} */
+
/* {{{ php_error_docref1 */
/* See: CODING_STANDARDS for details. */
PHPAPI void php_error_docref1(const char *docref TSRMLS_DC, const char *param1, int type, const char *format, ...)
@@ -499,6 +532,21 @@
}
/* }}} */

+/* {{{ php_error_ex2 */
+/* See: CODING_STANDARDS for details. */
+PHPAPI void php_error_ex2(const char *error_code, const char *docref TSRMLS_DC, const char *param1, const char *param2, int type, const char *format, ...)
+{
+ char *params;
+ va_list args;
+
+ spprintf(&params, 0, "%s,%s", param1, param2);
+ va_start(args, format);
+ php_verror_ex(error_code, docref, params ? params : "...", type, format, args TSRMLS_CC);
+ va_end(args);
+ if (params)
+ efree(params);
+}
+/* }}} */
/* {{{ php_error_docref2 */
/* See: CODING_STANDARDS for details. */
PHPAPI void php_error_docref2(const char *docref TSRMLS_DC, const char *param1, const char *param2, int type, const char *format, ...)
Index: php.h
===================================================================
RCS file: /repository/php4/main/php.h,v
retrieving revision 1.178
diff -u -r1.178 php.h
--- php.h 7 Nov 2002 11:52:45 -0000 1.178
+++ php.h 28 Nov 2002 18:06:48 -0000
@@ -274,7 +274,8 @@

#define php_error zend_error

-PHPAPI void php_verror(const char *docref, const char *params, int type, const char *format, va_list args TSRMLS_DC) ;
+PHPAPI void php_verror(const char *docref, const char *params, int type, const char *format, va_list args TSRMLS_DC);
+PHPAPI void php_verror_ex(const char *error_code, const char *docref, const char *params, int type, const char *format, va_list args TSRMLS_DC);

/* PHPAPI void php_error(int type, const char *format, ...); */
PHPAPI void php_error_docref0(const char *docref TSRMLS_DC, int type, const char *format, ...);

Reply via email to