cvs: php4 /ext/standard levenshtein.c /main main.c
| From: | Hartmut Holzgraefe | Date: | Tue, 01 Aug 2000 07:57:20 +0000 |
| Subject: | cvs: php4 /ext/standard levenshtein.c /main main.c | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-1002@lists.php.net to get a copy of this message | ||
hholzgra Tue Aug 1 00:57:20 2000 EDT
Modified files:
/php4/main main.c
/php4/ext/standard levenshtein.c
Log:
"undefined function" error message will now suggest similar named
functions as jikes compiler for java does (typo protection)
Index: php4/main/main.c
diff -u php4/main/main.c:1.286 php4/main/main.c:1.287
--- php4/main/main.c:1.286 Sat Jul 29 07:46:08 2000
+++ php4/main/main.c Tue Aug 1 00:57:19 2000
@@ -19,7 +19,7 @@
*/
-/* $Id: main.c,v 1.286 2000/07/29 14:46:08 zeev Exp $ */
+/* $Id: main.c,v 1.287 2000/08/01 07:57:19 hholzgra Exp $ */
#include <stdio.h>
@@ -328,7 +328,7 @@
/* extended error handling function */
static void php_error_cb(int type, const char *error_filename, const uint error_lineno, const char
*format, va_list orig_args)
{
- char buffer[1024];
+ char buffer[1024],buf2[1024],*alt_func = NULL;
int size = 0;
va_list args;
ELS_FETCH();
@@ -371,6 +371,44 @@
va_end(args);
buffer[sizeof(buffer) - 1] = 0;
+ if(strstr(format,"Call to undefined function:")) {
+ int dist,min,stat;
+ char *name,*str,*p;
+ char *string_key;
+ ulong num_key;
+
+ size = vsnprintf(buf2, sizeof(buf2) - 1, "%s", args);
+ buf2[sizeof(buf2) - 1] = 0;
+
+ str=estrdup(buf2);
+ for(p=str;*p;p++)
+ *p=tolower(*p);
+
+ min=5;
+ if(strlen(str)<10) min=3;
+ if(strlen(str)<6) min=2;
+
+ zend_hash_internal_pointer_reset(EG(function_table));
+ while(1) {
+ stat=zend_hash_get_current_key(EG(function_table),&string_key,&num_key);
+ if(stat==HASH_KEY_IS_STRING)
+ {
+ dist = fastest_levdist(str,string_key);
+ if(dist<=min) {
+ if(alt_func!=NULL) efree(alt_func);
+ alt_func=estrdup(string_key);
+ min=dist;
+ }
+ }
+ else if(stat==HASH_KEY_IS_LONG)
+ { /* empty */ }
+ else
+ break;
+ zend_hash_move_forward(EG(function_table));
+ }
+ efree(str);
+ }
+
if (!module_initialized || PG(log_errors)) {
char log_buffer[1024];
@@ -381,6 +419,10 @@
#endif
snprintf(log_buffer, 1024, "PHP %s: %s in %s on line %d", error_type_str, buffer,
error_filename, error_lineno);
php_log_err(log_buffer);
+ if(alt_func) {
+ snprintf(log_buffer, 1024, " ( maybe you were looking for %s() instead of %s() ?
)",alt_func,buf2);
+ php_log_err(log_buffer);
+ }
}
if (module_initialized && PG(display_errors)) {
char *prepend_string = INI_STR("error_prepend_string");
@@ -396,6 +438,9 @@
}
php_printf(error_format, error_type_str, buffer,
error_filename, error_lineno);
+ if(alt_func) {
+ php_printf(" ( maybe you were looking for
<b>%s()</b> instead of <b>%s()</b> ? )<br>\n",alt_func,buf2);
+ }
if (append_string) {
PUTS(append_string);
}
Index: php4/ext/standard/levenshtein.c
diff -u php4/ext/standard/levenshtein.c:1.10 php4/ext/standard/levenshtein.c:1.11
--- php4/ext/standard/levenshtein.c:1.10 Fri Jun 16 11:46:57 2000
+++ php4/ext/standard/levenshtein.c Tue Aug 1 00:57:19 2000
@@ -15,7 +15,7 @@
| Author: Hartmut Holzgraefe <hartmut@six.de> |
+----------------------------------------------------------------------+
*/
-/* $Id: levenshtein.c,v 1.10 2000/06/16 18:46:57 hholzgra Exp $ */
+/* $Id: levenshtein.c,v 1.11 2000/08/01 07:57:19 hholzgra Exp $ */
#include "php.h"
#include <stdlib.h>
@@ -24,7 +24,7 @@
#include "php_string.h"
/* faster, but obfuscated, all operations have a cost of 1 */
-static int fastest_levdist(const char *s1, const char *s2)
+int fastest_levdist(const char *s1, const char *s2)
{
register char *p1,*p2;
register int i,j,n;