iliaa Sun Nov 23 20:17:28 2003 EDT
Modified files:
/php-src NEWS
/php-src/ext/standard basic_functions.c basic_functions.h
Log:
Added php_strip_whitespace() and php_check_syntax() functions.
Index: php-src/NEWS
diff -u php-src/NEWS:1.1500 php-src/NEWS:1.1501
--- php-src/NEWS:1.1500 Wed Nov 19 16:10:33 2003
+++ php-src/NEWS Sun Nov 23 20:17:26 2003
@@ -5,6 +5,8 @@
. dba_key_split() to split inifile keys in an array. (Marcus)
. time_nanosleep() signal safe sleep (Magnus, Ilia)
. headers_list(). (Sara)
+ . php_strip_whitespace(). strip whitespace & comments from a script. (Ilia)
+ . php_check_syntax(). check php script for parse errors. (Ilia)
- Fixed bug #26072 (--disable-libxml does not work). (Jani)
- Fixed bug #26083 (Non-working write support in ext/dom). (Ilia)
- Fixed bug #24394 (Serializing cross-referenced objects causes segfault).
Index: php-src/ext/standard/basic_functions.c
diff -u php-src/ext/standard/basic_functions.c:1.642
php-src/ext/standard/basic_functions.c:1.643
--- php-src/ext/standard/basic_functions.c:1.642 Wed Nov 19 16:10:29 2003
+++ php-src/ext/standard/basic_functions.c Sun Nov 23 20:17:27 2003
@@ -17,7 +17,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: basic_functions.c,v 1.642 2003/11/19 21:10:29 pollita Exp $ */
+/* $Id: basic_functions.c,v 1.643 2003/11/24 01:17:27 iliaa Exp $ */
#include "php.h"
#include "php_streams.h"
@@ -35,6 +35,12 @@
#include "ext/standard/dns.h"
#include "ext/standard/php_uuencode.h"
+typedef struct yy_buffer_state *YY_BUFFER_STATE;
+
+#include "zend.h"
+#include "zend_language_scanner.h"
+#include "zend_language_parser.h"
+
#include <stdarg.h>
#include <stdlib.h>
#include <math.h>
@@ -606,6 +612,8 @@
PHP_FE(highlight_file,
NULL)
PHP_FALIAS(show_source, highlight_file,
NULL)
PHP_FE(highlight_string,
NULL)
+ PHP_FE(php_strip_whitespace,
NULL)
+ PHP_FE(php_check_syntax,
NULL)
PHP_FE(ini_get,
NULL)
PHP_FE(ini_get_all,
NULL)
@@ -2306,6 +2314,85 @@
}
/* }}} */
+/* {{{ proto string php_strip_whitespace(string file_name)
+ Return source with stripped comments and whitespace */
+PHP_FUNCTION(php_strip_whitespace)
+{
+ char *filename;
+ int filename_len;
+ zend_lex_state original_lex_state;
+ zend_file_handle file_handle = {0};
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &filename,
&filename_len) == FAILURE) {
+ RETURN_FALSE;
+ }
+
+ php_start_ob_buffer(NULL, 0, 1 TSRMLS_CC);
+
+ file_handle.type = ZEND_HANDLE_FILENAME;
+ file_handle.filename = filename;
+ file_handle.free_filename = 0;
+ file_handle.opened_path = NULL;
+ zend_save_lexical_state(&original_lex_state TSRMLS_CC);
+ if (open_file_for_scanning(&file_handle TSRMLS_CC)==FAILURE) {
+ RETURN_EMPTY_STRING();
+ }
+
+ zend_strip(TSRMLS_C);
+
+ zend_destroy_file_handle(&file_handle TSRMLS_CC);
+ zend_restore_lexical_state(&original_lex_state TSRMLS_CC);
+
+ php_ob_get_buffer(return_value TSRMLS_CC);
+ php_end_ob_buffer(0, 0 TSRMLS_CC);
+
+ return;
+}
+/* }}} */
+
+/* {{{ proto bool php_check_syntax(string file_name [, &$error_message])
+ Check the syntax of the specified file. */
+PHP_FUNCTION(php_check_syntax)
+{
+ char *filename;
+ int filename_len;
+ zval *errm=NULL;
+ zend_file_handle file_handle = {0};
+
+ int old_errors = PG(display_errors);
+ int log_errors = PG(log_errors);
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|z", &filename,
&filename_len, &errm) == FAILURE) {
+ RETURN_FALSE;
+ }
+
+ file_handle.type = ZEND_HANDLE_FILENAME;
+ file_handle.filename = filename;
+ file_handle.free_filename = 0;
+ file_handle.opened_path = NULL;
+
+ PG(log_errors) = PG(display_errors) = 0;
+
+ if (php_lint_script(&file_handle TSRMLS_CC) != SUCCESS) {
+ if (errm && PZVAL_IS_REF(errm)) {
+ char *error_str;
+
+ convert_to_string_ex(&errm);
+ spprintf(&error_str, 0, "%s in %s on line %d",
PG(last_error_message), PG(last_error_file), PG(last_error_lineno));
+ ZVAL_STRING(errm, error_str, 0);
+ }
+ RETVAL_FALSE;
+ } else {
+ RETVAL_TRUE;
+ }
+
+ PG(display_errors) = old_errors;
+ PG(log_errors) = log_errors;
+
+ return;
+}
+/* }}} */
+
/* {{{ proto bool highlight_string(string string [, bool return] )
Syntax highlight a string or optionally return it */
PHP_FUNCTION(highlight_string)
@@ -2314,6 +2401,7 @@
zend_syntax_highlighter_ini syntax_highlighter_ini;
char *hicompiled_string_description;
zend_bool i = 0;
+ int old_error_reporting = EG(error_reporting);
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z|b", &expr, &i) ==
FAILURE) {
RETURN_FALSE;
@@ -2324,6 +2412,8 @@
php_start_ob_buffer (NULL, 0, 1 TSRMLS_CC);
}
+ EG(error_reporting) = E_ERROR;
+
php_get_highlight_struct(&syntax_highlighter_ini);
hicompiled_string_description =
zend_make_compiled_string_description("highlighted code" TSRMLS_CC);
@@ -2334,6 +2424,8 @@
}
efree(hicompiled_string_description);
+ EG(error_reporting) = old_error_reporting;
+
if (i) {
php_ob_get_buffer (return_value TSRMLS_CC);
php_end_ob_buffer (0, 0 TSRMLS_CC);
Index: php-src/ext/standard/basic_functions.h
diff -u php-src/ext/standard/basic_functions.h:1.128
php-src/ext/standard/basic_functions.h:1.129
--- php-src/ext/standard/basic_functions.h:1.128 Fri Nov 14 17:55:54 2003
+++ php-src/ext/standard/basic_functions.h Sun Nov 23 20:17:27 2003
@@ -17,7 +17,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: basic_functions.h,v 1.128 2003/11/14 22:55:54 iliaa Exp $ */
+/* $Id: basic_functions.h,v 1.129 2003/11/24 01:17:27 iliaa Exp $ */
#ifndef BASIC_FUNCTIONS_H
#define BASIC_FUNCTIONS_H
@@ -81,6 +81,8 @@
PHP_FUNCTION(register_shutdown_function);
PHP_FUNCTION(highlight_file);
PHP_FUNCTION(highlight_string);
+PHP_FUNCTION(php_strip_whitespace);
+PHP_FUNCTION(php_check_syntax);
ZEND_API void php_get_highlight_struct(zend_syntax_highlighter_ini
*syntax_highlighter_ini);
PHP_FUNCTION(ini_get);
--
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php