cvs: php4 /main main.c /sapi/cgi cgi_main.c
| From: | Hartmut Holzgraefe | Date: | Fri, 28 Jul 2000 15:21:20 +0000 |
| Subject: | cvs: php4 /main main.c /sapi/cgi cgi_main.c | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-963@lists.php.net to get a copy of this message | ||
hholzgra Fri Jul 28 08:21:20 2000 EDT
Modified files:
/php4/main main.c
/php4/sapi/cgi cgi_main.c
Log:
added '-l' option to command line / CGI version for 'syntax check only'
plus a little cleanup and rearranging in command line option parsing
@ CGI aka. command line version has now an option '-l' for syntax check
@ without execution (Hartmut)
Index: php4/main/main.c
diff -u php4/main/main.c:1.283 php4/main/main.c:1.284
--- php4/main/main.c:1.283 Tue Jul 18 04:02:28 2000
+++ php4/main/main.c Fri Jul 28 08:21:19 2000
@@ -19,7 +19,7 @@
*/
-/* $Id: main.c,v 1.283 2000/07/18 11:02:28 ssb Exp $ */
+/* $Id: main.c,v 1.284 2000/07/28 15:21:19 hholzgra Exp $ */
#include <stdio.h>
@@ -1168,6 +1168,28 @@
EG(active_op_array) = EG(main_op_array);
zend_execute(EG(main_op_array) ELS_CC);
}
+}
+
+PHPAPI int php_lint_script(zend_file_handle *file CLS_DC ELS_DC PLS_DC)
+{
+ SLS_FETCH();
+
+ php_hash_environment(ELS_C SLS_CC PLS_CC);
+
+ zend_activate_modules();
+ PG(modules_activated)=1;
+
+ if (setjmp(EG(bailout))!=0) {
+ return FAILURE;
+ }
+
+#ifdef PHP_WIN32
+ UpdateIniFromRegistry(primary_file->filename);
+#endif
+
+ EG(main_op_array) = zend_compile_files(ZEND_REQUIRE CLS_CC, 1, file);
+
+ return (EG(main_op_array)) ? SUCCESS : FAILURE;
}
#ifdef PHP_WIN32
Index: php4/sapi/cgi/cgi_main.c
diff -u php4/sapi/cgi/cgi_main.c:1.62 php4/sapi/cgi/cgi_main.c:1.63
--- php4/sapi/cgi/cgi_main.c:1.62 Thu Jul 13 02:17:39 2000
+++ php4/sapi/cgi/cgi_main.c Fri Jul 28 08:21:20 2000
@@ -79,10 +79,12 @@
#define PHP_MODE_STANDARD 1
#define PHP_MODE_HIGHLIGHT 2
#define PHP_MODE_INDENT 3
+#define PHP_MODE_LINT 4
extern char *ap_php_optarg;
extern int ap_php_optind;
+#define OPTSTRING "ac:d:ef:g:hilnqs?vz:"
static int sapi_cgibin_ub_write(const char *str, uint str_length)
{
@@ -258,6 +260,7 @@
" -d foo[=bar] Define INI entry foo with value 'bar'\n"
" -e Generate extended information for debugger/profiler\n"
" -z<file> Load Zend extension <file>.\n"
+ " -l Syntax check only (lint)\n"
" -i PHP information\n"
" -h This help\n", prog);
}
@@ -359,6 +362,7 @@
int main(int argc, char *argv[])
{
+ int exit_status = SUCCESS;
int cgi = 0, c, i, len;
zend_file_handle file_handle;
char *s;
@@ -448,7 +452,7 @@
}
if (!cgi) {
- while ((c=ap_php_getopt(argc, argv, "c:d:z:g:qvisnaeh?vf:"))!=-1) {
+ while ((c=ap_php_getopt(argc, argv, OPTSTRING))!=-1) {
switch (c) {
case 'c':
php_ini_path = strdup(ap_php_optarg); /* intentional leak */
@@ -474,7 +478,7 @@
#endif
if (!cgi) {
- while ((c=ap_php_getopt(argc, argv, "c:d:z:g:qvisnaeh?vf:"))!=-1) {
+ while ((c=ap_php_getopt(argc, argv, OPTSTRING))!=-1) {
switch (c) {
case '?':
no_headers = 1;
@@ -503,9 +507,27 @@
free(SG(request_info).argv0);
SG(request_info).argv0 = NULL;
}
- while ((c = ap_php_getopt(argc, argv, "c:d:z:g:qvisnaeh?vf:")) != -1) {
+ while ((c = ap_php_getopt(argc, argv, OPTSTRING)) != -1) {
switch (c) {
- case 'f':
+
+ case 'a': /* interactive mode */
+#if SUPPORT_INTERACTIVE
+ printf("Interactive mode enabled\n\n");
+ interactive=1;
+#else
+ printf("Interactive mode not supported!\n\n");
+#endif
+ break;
+
+ case 'd': /* define ini entries on command line */
+ define_command_line_ini_entry(ap_php_optarg);
+ break;
+
+ case 'e': /* enable extended info output */
+ CG(extended_info) = 1;
+ break;
+
+ case 'f': /* parse file */
if (!cgi_started){
if (php_request_startup(CLS_C ELS_CC PLS_CC SLS_CC)==FAILURE) {
php_module_shutdown();
@@ -517,26 +539,28 @@
}
cgi_started=1;
SG(request_info).path_translated = estrdup(ap_php_optarg);
- /* break missing intentionally */
- case 'q':
no_headers = 1;
break;
- case 'v':
- no_headers = 1;
- if (!cgi_started) {
- if (php_request_startup(CLS_C ELS_CC PLS_CC SLS_CC)==FAILURE) {
- php_module_shutdown();
- return FAILURE;
- }
- }
- if (no_headers) {
- SG(headers_sent) = 1;
+
+ case 'g': /* define global variables on command line */
+ {
+ char *arg = estrdup(ap_php_optarg);
+
+ zend_llist_add_element(&global_vars, &arg);
}
- php_printf("%s\n", PHP_VERSION);
+ break;
+
+ case 'h': /* help & quit */
+ case '?':
+ no_headers = 1;
+ php_output_startup();
+ SG(headers_sent) = 1;
+ php_cgi_usage(argv[0]);
php_end_ob_buffering(1);
exit(1);
break;
- case 'i':
+
+ case 'i': /* php info & quit */
if (!cgi_started) {
if (php_request_startup(CLS_C ELS_CC PLS_CC SLS_CC)==FAILURE) {
php_module_shutdown();
@@ -550,45 +574,46 @@
php_print_info(0xFFFFFFFF);
exit(1);
break;
- case 's':
- behavior=PHP_MODE_HIGHLIGHT;
+
+ case 'l': /* syntax check mode */
+ no_headers = 1;
+ behavior=PHP_MODE_LINT;
break;
- case 'n':
+
+#if 0 /* not yet operational, see also below ... */
+ case 'n': /* generate indented source mode*/
behavior=PHP_MODE_INDENT;
break;
- case 'a':
-#if SUPPORT_INTERACTIVE
- printf("Interactive mode enabled\n\n");
- interactive=1;
-#else
- printf("Interactive mode not supported!\n\n");
#endif
+
+ case 'q': /* do not generate HTTP headers */
+ no_headers = 1;
break;
- case 'e':
- CG(extended_info) = 1;
+
+ case 's': /* generate highlighted HTML from source */
+ behavior=PHP_MODE_HIGHLIGHT;
break;
- case 'h':
- case '?':
- no_headers = 1;
- php_output_startup();
- SG(headers_sent) = 1;
- php_cgi_usage(argv[0]);
+
+ case 'v': /* show php version & quit */
+ no_headers = 1;
+ if (!cgi_started) {
+ if (php_request_startup(CLS_C ELS_CC PLS_CC SLS_CC)==FAILURE) {
+ php_module_shutdown();
+ return FAILURE;
+ }
+ }
+ if (no_headers) {
+ SG(headers_sent) = 1;
+ }
+ php_printf("%s\n", PHP_VERSION);
php_end_ob_buffering(1);
exit(1);
break;
- case 'd':
- define_command_line_ini_entry(ap_php_optarg);
- break;
- case 'g':
- {
- char *arg = estrdup(ap_php_optarg);
- zend_llist_add_element(&global_vars, &arg);
- }
- break;
- case 'z':
+ case 'z': /* load extension file */
zend_load_extension(ap_php_optarg);
break;
+
default:
break;
}
@@ -673,6 +698,9 @@
case PHP_MODE_STANDARD:
php_execute_script(&file_handle CLS_CC ELS_CC PLS_CC);
break;
+ case PHP_MODE_LINT:
+ exit_status = php_lint_script(&file_handle CLS_CC ELS_CC PLS_CC);
+ break;
case PHP_MODE_HIGHLIGHT:
{
zend_syntax_highlighter_ini syntax_highlighter_ini;
@@ -682,7 +710,7 @@
zend_highlight(&syntax_highlighter_ini);
fclose(file_handle.handle.fp);
}
- return 0;
+ return SUCCESS;
}
break;
#if 0
@@ -691,12 +719,13 @@
open_file_for_scanning(&file_handle CLS_CC);
zend_indent();
fclose(file_handle.handle.fp);
- return 0;
+ return SUCCESS;
break;
#endif
}
php_header(); /* Make sure headers have been sent */
+
if (SG(request_info).path_translated) {
@@ -711,6 +740,7 @@
#ifdef ZTS
tsrm_shutdown();
#endif
- return SUCCESS;
+
+ return exit_status;
}