#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)
{
" -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);
}
int main(int argc, char *argv[])
{
+ int exit_status = SUCCESS;
int cgi = 0, c, i, len;
zend_file_handle file_handle;
char *s;
}
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 */
#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;
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();
}
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();
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;
}
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;
zend_highlight(&syntax_highlighter_ini);
fclose(file_handle.handle.fp);
}
- return 0;
+ return SUCCESS;
}
break;
#if 0
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) {
#ifdef ZTS
tsrm_shutdown();
#endif
- return SUCCESS;
+
+ return exit_status;
}