-removed -x

-error handling for illegal switch combinations
-corrected ws for one case block
This commit is contained in:
Marcus Boerger 2002-03-23 17:10:31 +00:00
parent f40007a1ef
commit fdf9d3502a

View File

@ -83,12 +83,11 @@
#define PHP_MODE_LINT 4
#define PHP_MODE_STRIP 5
#define PHP_MODE_CLI_DIRECT 6
#define PHP_MODE_CLI_NO_TAGS 7
extern char *ap_php_optarg;
extern int ap_php_optind;
#define OPTSTRING "aCc:d:ef:g:hilmnqr:sw?vx:z:"
#define OPTSTRING "aCc:d:ef:g:hilmnqr:sw?vz:"
static int _print_module_info(zend_module_entry *module, void *arg TSRMLS_DC)
{
@ -242,13 +241,12 @@ static void php_cli_usage(char *argv0)
prog = "php";
}
php_printf( "Usage: %s [options] [-f | -x] <file> [args...]\n"
php_printf( "Usage: %s [options] [-f] <file> [args...]\n"
" %s [options] -r <code> [args...]\n"
" %s [options] [-- args...]\n"
" -s Display colour syntax highlighted source.\n"
" -w Display source with stripped comments and whitespace.\n"
" -f <file> Parse <file>.\n"
" -x <file> Parse <file> without script tags <?..?>\n"
" -v Version number\n"
" -c <path> Look for php.ini file in this directory\n"
" -a Run interactively\n"
@ -315,6 +313,7 @@ int main(int argc, char *argv[])
zend_llist global_vars;
int interactive=0;
char *exec_direct=NULL;
char *param_error=NULL;
/* end of temporary locals */
#ifdef ZTS
zend_compiler_globals *compiler_globals;
@ -418,16 +417,11 @@ int main(int argc, char *argv[])
CG(extended_info) = 1;
break;
case 'x': /* parse file */
if (behavior != PHP_MODE_STANDARD)
break;
behavior=PHP_MODE_CLI_NO_TAGS;
script_file = ap_php_optarg;
no_headers = 1;
case 'f': /* parse file */
if (behavior != PHP_MODE_STANDARD)
if (behavior == PHP_MODE_CLI_DIRECT) {
param_error = "Either execute direct code or use a file.\n";
break;
}
script_file = ap_php_optarg;
no_headers = 1;
break;
@ -478,18 +472,20 @@ int main(int argc, char *argv[])
SG(headers_sent) = 1;
php_printf("Running PHP %s\n%s\n", PHP_VERSION , get_zend_version());
php_printf("[PHP Modules]\n");
zend_hash_apply_with_argument(&module_registry, (apply_func_arg_t) _print_module_info, NULL TSRMLS_CC);
php_printf("\n[Zend Modules]\n");
zend_llist_apply_with_argument(&zend_extensions, (llist_apply_with_arg_func_t) _print_extension_info, NULL TSRMLS_CC);
php_printf("\n");
php_end_ob_buffers(1 TSRMLS_CC);
exit(1);
zend_hash_apply_with_argument(&module_registry, (apply_func_arg_t) _print_module_info, NULL TSRMLS_CC);
php_printf("\n[Zend Modules]\n");
zend_llist_apply_with_argument(&zend_extensions, (llist_apply_with_arg_func_t) _print_extension_info, NULL TSRMLS_CC);
php_printf("\n");
php_end_ob_buffers(1 TSRMLS_CC);
exit(1);
break;
#if 0 /* not yet operational, see also below ... */
case 'n': /* generate indented source mode*/
if (behavior != PHP_MODE_STANDARD)
if (behavior == PHP_MODE_CLI_DIRECT) {
param_error = "Source indenting only works for files.\n";
break;
}
behavior=PHP_MODE_INDENT;
break;
#endif
@ -498,19 +494,23 @@ int main(int argc, char *argv[])
/* This is default so NOP */
break;
case 's': /* generate highlighted HTML from source */
if (behavior != PHP_MODE_STANDARD)
break;
behavior=PHP_MODE_HIGHLIGHT;
break;
case 'r': /* run code from command line */
if (behavior != PHP_MODE_STANDARD)
if (behavior != PHP_MODE_STANDARD) {
param_error = "Either execute direct code or use a file.\n";
break;
}
behavior=PHP_MODE_CLI_DIRECT;
exec_direct=ap_php_optarg;
break;
case 's': /* generate highlighted HTML from source */
if (behavior == PHP_MODE_CLI_DIRECT) {
param_error = "Source highlighting only works for files.\n";
break;
}
behavior=PHP_MODE_HIGHLIGHT;
break;
case 'v': /* show php version & quit */
no_headers = 1;
if (php_request_startup(TSRMLS_C)==FAILURE) {
@ -527,8 +527,10 @@ int main(int argc, char *argv[])
break;
case 'w':
if (behavior != PHP_MODE_STANDARD)
if (behavior == PHP_MODE_CLI_DIRECT) {
param_error = "Source stripping only works for files.\n";
break;
}
behavior=PHP_MODE_STRIP;
break;
@ -541,6 +543,13 @@ int main(int argc, char *argv[])
}
}
if (param_error) {
SG(headers_sent) = 1;
SG(request_info).no_headers = 1;
PUTS(param_error);
exit(1);
}
CG(interactive) = interactive;
/* only set script_file if not set already and not in direct mode and not at end of parameter list */
@ -572,29 +581,13 @@ int main(int argc, char *argv[])
}
if (script_file) {
if (!(file_handle.handle.fp = VCWD_FOPEN(script_file, "rb"))) {
SG(headers_sent) = 1;
SG(request_info).no_headers = 1;
PUTS("Could not open input file.\n");
php_request_shutdown((void *) 0);
php_module_shutdown(TSRMLS_C);
return FAILURE;
}
if (behavior == PHP_MODE_CLI_NO_TAGS) {
FILE *fp;
if (!(fp=tmpfile())) {
PUTS("Could not create temp file.\n");
php_request_shutdown((void *) 0);
php_module_shutdown(TSRMLS_C);
return FAILURE;
}
fwrite("<?\n", 3, 1, fp);
while((c=fgetc(file_handle.handle.fp))!=EOF) {
fputc(c, fp);
}
fwrite("\n?>", 3, 1, fp);
fclose(file_handle.handle.fp);
file_handle.handle.fp = fp;
behavior = PHP_MODE_STANDARD;
}
php_register_variable("PHP_SELF", script_file, NULL TSRMLS_CC);
file_handle.filename = script_file;
/* #!php support */