diff options
Diffstat (limited to 'sapi/cli')
| -rw-r--r-- | sapi/cli/config.m4 | 2 | ||||
| -rw-r--r-- | sapi/cli/config.w32 | 6 | ||||
| -rw-r--r-- | sapi/cli/getopt.c | 175 | ||||
| -rw-r--r-- | sapi/cli/php.1.in | 11 | ||||
| -rw-r--r-- | sapi/cli/php_cli.c | 115 | ||||
| -rw-r--r-- | sapi/cli/php_cli_readline.c | 8 | ||||
| -rw-r--r-- | sapi/cli/php_cli_readline.h | 2 | ||||
| -rw-r--r-- | sapi/cli/php_getopt.h | 39 | ||||
| -rw-r--r-- | sapi/cli/tests/002-win32.phpt | 2 | ||||
| -rw-r--r-- | sapi/cli/tests/005.phpt | 39 | ||||
| -rw-r--r-- | sapi/cli/tests/006.phpt | 326 | ||||
| -rw-r--r-- | sapi/cli/tests/010.phpt | 23 | ||||
| -rw-r--r-- | sapi/cli/tests/016.phpt | 108 | ||||
| -rw-r--r-- | sapi/cli/tests/017.phpt | 106 | ||||
| -rw-r--r-- | sapi/cli/tests/018.phpt | 27 | ||||
| -rw-r--r-- | sapi/cli/tests/019.phpt | 36 | ||||
| -rw-r--r-- | sapi/cli/tests/020.phpt | 32 | ||||
| -rw-r--r-- | sapi/cli/tests/021.phpt | 4 |
18 files changed, 497 insertions, 564 deletions
diff --git a/sapi/cli/config.m4 b/sapi/cli/config.m4 index 3ac11ce12..882cab4ba 100644 --- a/sapi/cli/config.m4 +++ b/sapi/cli/config.m4 @@ -1,5 +1,5 @@ dnl -dnl $Id: config.m4 265789 2008-09-01 13:15:15Z dmitry $ +dnl $Id: config.m4 265790 2008-09-01 13:15:31Z dmitry $ dnl PHP_ARG_ENABLE(cli,, diff --git a/sapi/cli/config.w32 b/sapi/cli/config.w32 index 47fc7afb9..cd106f197 100644 --- a/sapi/cli/config.w32 +++ b/sapi/cli/config.w32 @@ -1,12 +1,12 @@ // vim:ft=javascript -// $Id: config.w32 213267 2006-05-18 21:46:12Z edink $ +// $Id: config.w32 243567 2007-10-05 16:00:30Z rrichards $ ARG_ENABLE('cli', 'Build CLI version of PHP', 'yes'); ARG_ENABLE('crt-debug', 'Extra CRT debugging', 'no'); ARG_ENABLE('cli-win32', 'Build console-less CLI version of PHP', 'no'); if (PHP_CLI == "yes") { - SAPI('cli', 'getopt.c php_cli.c php_cli_readline.c', 'php.exe'); + SAPI('cli', 'php_cli.c php_cli_readline.c', 'php.exe'); if (PHP_CRT_DEBUG == "yes") { ADD_FLAG("CFLAGS_CLI", "/D PHP_WIN32_DEBUG_HEAP"); } @@ -14,7 +14,7 @@ if (PHP_CLI == "yes") { } if (PHP_CLI_WIN32 == "yes") { - SAPI('cli_win32', 'getopt.c cli_win32.c php_cli_readline.c', 'php-win.exe'); + SAPI('cli_win32', 'cli_win32.c php_cli_readline.c', 'php-win.exe'); ADD_FLAG("LDFLAGS_CLI_WIN32", "/stack:8388608"); } diff --git a/sapi/cli/getopt.c b/sapi/cli/getopt.c deleted file mode 100644 index bd0d2ddb3..000000000 --- a/sapi/cli/getopt.c +++ /dev/null @@ -1,175 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 5 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2009 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 3.01 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available through the world-wide-web at the following url: | - | http://www.php.net/license/3_01.txt | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Author: Marcus Boerger <helly@php.net> | - +----------------------------------------------------------------------+ -*/ - -/* $Id: getopt.c 272374 2008-12-31 11:17:49Z sebastian $ */ - -#include <stdio.h> -#include <string.h> -#include <assert.h> -#include <stdlib.h> -#include "php_getopt.h" -#define OPTERRCOLON (1) -#define OPTERRNF (2) -#define OPTERRARG (3) - - -static int php_opt_error(int argc, char * const *argv, int oint, int optchr, int err, int show_err) /* {{{ */ -{ - if (show_err) - { - fprintf(stderr, "Error in argument %d, char %d: ", oint, optchr+1); - switch(err) - { - case OPTERRCOLON: - fprintf(stderr, ": in flags\n"); - break; - case OPTERRNF: - fprintf(stderr, "option not found %c\n", argv[oint][optchr]); - break; - case OPTERRARG: - fprintf(stderr, "no argument for option %c\n", argv[oint][optchr]); - break; - default: - fprintf(stderr, "unknown\n"); - break; - } - } - return('?'); -} -/* }}} */ - -int php_getopt(int argc, char* const *argv, const opt_struct opts[], char **optarg, int *optind, int show_err) /* {{{ */ -{ - static int optchr = 0; - static int dash = 0; /* have already seen the - */ - int arg_start = 2; - - int opts_idx = -1; - - if (*optind >= argc) { - return(EOF); - } - if (!dash) { - if ((argv[*optind][0] != '-')) { - return(EOF); - } else { - if (!argv[*optind][1]) - { - /* - * use to specify stdin. Need to let pgm process this and - * the following args - */ - return(EOF); - } - } - } - if ((argv[*optind][0] == '-') && (argv[*optind][1] == '-')) { - /* '--' indicates end of args if not followed by a known long option name */ - if (argv[*optind][2] == '\0') { - (*optind)++; - return(EOF); - } - - while (1) { - opts_idx++; - if (opts[opts_idx].opt_char == '-') { - (*optind)++; - return(php_opt_error(argc, argv, *optind-1, optchr, OPTERRARG, show_err)); - } else if (opts[opts_idx].opt_name && !strcmp(&argv[*optind][2], opts[opts_idx].opt_name)) { - break; - } - } - optchr = 0; - dash = 0; - arg_start = 2 + strlen(opts[opts_idx].opt_name); - } else { - if (!dash) { - dash = 1; - optchr = 1; - } - /* Check if the guy tries to do a -: kind of flag */ - if (argv[*optind][optchr] == ':') { - dash = 0; - (*optind)++; - return (php_opt_error(argc, argv, *optind-1, optchr, OPTERRCOLON, show_err)); - } - arg_start = 1 + optchr; - } - if (opts_idx < 0) { - while (1) { - opts_idx++; - if (opts[opts_idx].opt_char == '-') { - int errind = *optind; - int errchr = optchr; - - if (!argv[*optind][optchr+1]) { - dash = 0; - (*optind)++; - } else { - optchr++; - arg_start++; - } - return(php_opt_error(argc, argv, errind, errchr, OPTERRNF, show_err)); - } else if (argv[*optind][optchr] == opts[opts_idx].opt_char) { - break; - } - } - } - if (opts[opts_idx].need_param) { - /* Check for cases where the value of the argument - is in the form -<arg> <val> or in the form -<arg><val> */ - dash = 0; - if(!argv[*optind][arg_start]) { - (*optind)++; - if (*optind == argc) { - return(php_opt_error(argc, argv, *optind-1, optchr, OPTERRARG, show_err)); - } - *optarg = argv[(*optind)++]; - } else { - *optarg = &argv[*optind][arg_start]; - (*optind)++; - } - return opts[opts_idx].opt_char; - } else { - /* multiple options specified as one (exclude long opts) */ - if (arg_start >= 2 && !((argv[*optind][0] == '-') && (argv[*optind][1] == '-'))) { - if (!argv[*optind][optchr+1]) - { - dash = 0; - (*optind)++; - } else { - optchr++; - } - } else { - (*optind)++; - } - return opts[opts_idx].opt_char; - } - assert(0); - return(0); /* never reached */ -} -/* }}} */ - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - * vim600: sw=4 ts=4 fdm=marker - * vim<600: sw=4 ts=4 - */ diff --git a/sapi/cli/php.1.in b/sapi/cli/php.1.in index 1033bb5d9..52161973d 100644 --- a/sapi/cli/php.1.in +++ b/sapi/cli/php.1.in @@ -69,7 +69,7 @@ specified by \-F to be executed. You can access the input line by \fB$argn\fP. While processing the input lines .B $argi contains the number of the actual line being processed. Further more -the parameters \-B and \-E can be used to execute +the paramters \-B and \-E can be used to execute .IR code (see \-r) before and after all input lines have been processed respectively. Notice that the @@ -304,9 +304,6 @@ Shows information about extension .IR name Shows configuration for extension .B name -.TP -.B \-\-ini -Show configuration file names .SH FILES .TP 15 .B php\-cli.ini @@ -318,7 +315,7 @@ The standard configuration file will only be used when cannot be found. .SH EXAMPLES .TP 5 -\fIphp \-r 'echo "Hello World\\n";'\fP +\fIphp -r 'echo "Hello World\\n";'\fP This command simply writes the text "Hello World" to standard out. .TP \fIphp \-r 'print_r(gd_info());'\fP @@ -342,7 +339,7 @@ configuration information. If you then combine those two Using this PHP command you can count the lines being input. .TP \fIphp \-R '@$l+=count(file($argn));' \-E 'echo "Lines:$l\\n";'\fP -In this example PHP expects each input line being a file. It counts all lines +In this example PHP expects each input line beeing a file. It counts all lines of the files specified by each input line and shows the summarized result. You may combine this with tools like find and change the php scriptlet. .TP @@ -369,7 +366,7 @@ such a first line as shown below: .PD 1 .P .SH SEE ALSO -For a more or less complete description of PHP look here: +For a description of PHP see: .PD 0 .P .B http://www.php.net/manual/ diff --git a/sapi/cli/php_cli.c b/sapi/cli/php_cli.c index 891c551db..aeade0940 100644 --- a/sapi/cli/php_cli.c +++ b/sapi/cli/php_cli.c @@ -20,7 +20,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: php_cli.c 292081 2009-12-13 17:06:47Z felipe $ */ +/* $Id: php_cli.c 287973 2009-09-02 20:02:17Z pajoye $ */ #include "php.h" #include "php_globals.h" @@ -76,11 +76,8 @@ #endif #if (HAVE_LIBREADLINE || HAVE_LIBEDIT) && !defined(COMPILE_DL_READLINE) - -#if HAVE_LIBEDIT -#include <editline/readline.h> -#else #include <readline/readline.h> +#if !HAVE_LIBEDIT #include <readline/history.h> #endif #include "php_cli_readline.h" @@ -120,13 +117,13 @@ PHPAPI extern char *php_ini_scanned_files; #define PHP_MODE_REFLECTION_EXT_INFO 11 #define PHP_MODE_SHOW_INI_CONFIG 12 -#define HARDCODED_INI \ - "html_errors=0\n" \ - "register_argc_argv=1\n" \ - "implicit_flush=1\n" \ - "output_buffering=0\n" \ - "max_execution_time=0\n" \ - "max_input_time=-1\n" +const char HARDCODED_INI[] = + "html_errors=0\n" + "register_argc_argv=1\n" + "implicit_flush=1\n" + "output_buffering=0\n" + "max_execution_time=0\n" + "max_input_time=-1\n\0"; static char *php_optarg = NULL; static int php_optind = 1; @@ -323,19 +320,35 @@ static char *script_filename = ""; static void sapi_cli_register_variables(zval *track_vars_array TSRMLS_DC) /* {{{ */ { + unsigned int len; + char *docroot = ""; + /* In CGI mode, we consider the environment to be a part of the server * variables */ php_import_environment_variables(track_vars_array TSRMLS_CC); /* Build the special-case PHP_SELF variable for the CLI version */ - php_register_variable("PHP_SELF", php_self, track_vars_array TSRMLS_CC); - php_register_variable("SCRIPT_NAME", php_self, track_vars_array TSRMLS_CC); + len = strlen(php_self); + if (sapi_module.input_filter(PARSE_SERVER, "PHP_SELF", &php_self, len, &len TSRMLS_CC)) { + php_register_variable("PHP_SELF", php_self, track_vars_array TSRMLS_CC); + } + if (sapi_module.input_filter(PARSE_SERVER, "SCRIPT_NAME", &php_self, len, &len TSRMLS_CC)) { + php_register_variable("SCRIPT_NAME", php_self, track_vars_array TSRMLS_CC); + } /* filenames are empty for stdin */ - php_register_variable("SCRIPT_FILENAME", script_filename, track_vars_array TSRMLS_CC); - php_register_variable("PATH_TRANSLATED", script_filename, track_vars_array TSRMLS_CC); + len = strlen(script_filename); + if (sapi_module.input_filter(PARSE_SERVER, "SCRIPT_FILENAME", &script_filename, len, &len TSRMLS_CC)) { + php_register_variable("SCRIPT_FILENAME", script_filename, track_vars_array TSRMLS_CC); + } + if (sapi_module.input_filter(PARSE_SERVER, "PATH_TRANSLATED", &script_filename, len, &len TSRMLS_CC)) { + php_register_variable("PATH_TRANSLATED", script_filename, track_vars_array TSRMLS_CC); + } /* just make it available */ - php_register_variable("DOCUMENT_ROOT", "", track_vars_array TSRMLS_CC); + len = 0U; + if (sapi_module.input_filter(PARSE_SERVER, "DOCUMENT_ROOT", &docroot, len, &len TSRMLS_CC)) { + php_register_variable("DOCUMENT_ROOT", docroot, track_vars_array TSRMLS_CC); + } } /* }}} */ @@ -362,11 +375,8 @@ static char* sapi_cli_read_cookies(TSRMLS_D) /* {{{ */ } /* }}} */ -static int sapi_cli_header_handler(sapi_header_struct *h, sapi_headers_struct *s TSRMLS_DC) /* {{{ */ +static int sapi_cli_header_handler(sapi_header_struct *h, sapi_header_op_enum op, sapi_headers_struct *s TSRMLS_DC) /* {{{ */ { - /* free allocated header line */ - efree(h->header); - /* avoid pushing headers into SAPI headers list */ return 0; } /* }}} */ @@ -397,20 +407,16 @@ static int php_cli_startup(sapi_module_struct *sapi_module) /* {{{ */ /* overwriteable ini defaults must be set in sapi_cli_ini_defaults() */ #define INI_DEFAULT(name,value)\ - ZVAL_STRING(tmp, value, 0);\ - zend_hash_update(configuration_hash, name, sizeof(name), tmp, sizeof(zval), (void**)&entry);\ - Z_STRVAL_P(entry) = zend_strndup(Z_STRVAL_P(entry), Z_STRLEN_P(entry)) + Z_SET_REFCOUNT(tmp, 0);\ + Z_UNSET_ISREF(tmp); \ + ZVAL_STRINGL(&tmp, zend_strndup(value, sizeof(value)-1), sizeof(value)-1, 0);\ + zend_hash_update(configuration_hash, name, sizeof(name), &tmp, sizeof(zval), NULL);\ static void sapi_cli_ini_defaults(HashTable *configuration_hash) { - zval *tmp, *entry; - - MAKE_STD_ZVAL(tmp); - + zval tmp; INI_DEFAULT("report_zend_debug", "0"); INI_DEFAULT("display_errors", "1"); - - FREE_ZVAL(tmp); } /* }}} */ @@ -443,11 +449,23 @@ static sapi_module_struct cli_sapi_module = { sapi_cli_register_variables, /* register server variables */ sapi_cli_log_message, /* Log message */ NULL, /* Get request time */ + NULL, /* Child terminate */ STANDARD_SAPI_MODULE_PROPERTIES }; /* }}} */ +/* {{{ arginfo ext/standard/dl.c */ +ZEND_BEGIN_ARG_INFO(arginfo_dl, 0) + ZEND_ARG_INFO(0, extension_filename) +ZEND_END_ARG_INFO() +/* }}} */ + +static const zend_function_entry additional_functions[] = { + ZEND_FE(dl, arginfo_dl) + {NULL, NULL, NULL} +}; + /* {{{ php_cli_usage */ static void php_cli_usage(char *argv0) @@ -581,18 +599,22 @@ static const char *param_mode_conflict = "Either execute direct code, process st */ static int cli_seek_file_begin(zend_file_handle *file_handle, char *script_file, int *lineno TSRMLS_DC) { - int c; + char c; *lineno = 1; + file_handle->type = ZEND_HANDLE_FP; + file_handle->opened_path = NULL; + file_handle->free_filename = 0; if (!(file_handle->handle.fp = VCWD_FOPEN(script_file, "rb"))) { php_printf("Could not open input file: %s\n", script_file); return FAILURE; } file_handle->filename = script_file; + /* #!php support */ c = fgetc(file_handle->handle.fp); - if (c == '#') { + if (c == '#' && (c = fgetc(file_handle->handle.fp)) == '!') { while (c != '\n' && c != '\r' && c != EOF) { c = fgetc(file_handle->handle.fp); /* skip to end of line */ } @@ -607,6 +629,7 @@ static int cli_seek_file_begin(zend_file_handle *file_handle, char *script_file, } else { rewind(file_handle->handle.fp); } + return SUCCESS; } /* }}} */ @@ -649,10 +672,12 @@ int main(int argc, char *argv[]) #if defined(PHP_WIN32) && defined(_DEBUG) && defined(PHP_WIN32_DEBUG_HEAP) { int tmp_flag; - + _CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_FILE); + _CrtSetReportFile(_CRT_WARN, _CRTDBG_FILE_STDERR); _CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_FILE); _CrtSetReportFile(_CRT_ERROR, _CRTDBG_FILE_STDERR); - + _CrtSetReportMode(_CRT_ASSERT, _CRTDBG_MODE_FILE); + _CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDERR); tmp_flag = _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG); tmp_flag |= _CRTDBG_DELAY_FREE_MEM_DF; tmp_flag |= _CRTDBG_LEAK_CHECK_DF; @@ -690,12 +715,11 @@ int main(int argc, char *argv[]) setmode(_fileno(stderr), O_BINARY); /* make the stdio mode be binary */ #endif - ini_entries_len = strlen(HARDCODED_INI); - cli_sapi_module.ini_entries = malloc(ini_entries_len+2); - memcpy(cli_sapi_module.ini_entries, HARDCODED_INI, ini_entries_len+1); - cli_sapi_module.ini_entries[ini_entries_len+1] = 0; + ini_entries_len = sizeof(HARDCODED_INI)-2; + cli_sapi_module.ini_entries = malloc(sizeof(HARDCODED_INI)); + memcpy(cli_sapi_module.ini_entries, HARDCODED_INI, sizeof(HARDCODED_INI)); - while ((c = php_getopt(argc, argv, OPTIONS, &php_optarg, &php_optind, 0))!=-1) { + while ((c = php_getopt(argc, argv, OPTIONS, &php_optarg, &php_optind, 0, 2))!=-1) { switch (c) { case 'c': if (cli_sapi_module.php_ini_path_override) { @@ -743,6 +767,7 @@ int main(int argc, char *argv[]) php_optarg = orig_optarg; cli_sapi_module.executable_location = argv[0]; + cli_sapi_module.additional_functions = additional_functions; /* startup after we get the above ini override se we get things right */ if (cli_sapi_module.startup(&cli_sapi_module)==FAILURE) { @@ -760,7 +785,7 @@ int main(int argc, char *argv[]) CG(in_compilation) = 0; /* not initialized but needed for several options */ EG(uninitialized_zval_ptr) = NULL; - while ((c = php_getopt(argc, argv, OPTIONS, &php_optarg, &php_optind, 0)) != -1) { + while ((c = php_getopt(argc, argv, OPTIONS, &php_optarg, &php_optind, 0, 2)) != -1) { switch (c) { case 'h': /* help & quit */ @@ -831,7 +856,7 @@ int main(int argc, char *argv[]) php_optind = orig_optind; php_optarg = orig_optarg; - while ((c = php_getopt(argc, argv, OPTIONS, &php_optarg, &php_optind, 0)) != -1) { + while ((c = php_getopt(argc, argv, OPTIONS, &php_optarg, &php_optind, 0, 2)) != -1) { switch (c) { case 'a': /* interactive mode */ @@ -850,7 +875,7 @@ int main(int argc, char *argv[]) break; case 'e': /* enable extended info output */ - CG(extended_info) = 1; + CG(compiler_options) |= ZEND_COMPILE_EXTENDED_INFO; break; case 'F': @@ -1142,7 +1167,7 @@ int main(int argc, char *argv[]) continue; } - zend_eval_string(code, NULL, "php shell code" TSRMLS_CC); + zend_eval_stringl(code, pos, NULL, "php shell code" TSRMLS_CC); pos = 0; if (php_last_char != '\0' && php_last_char != '\n') { @@ -1150,7 +1175,7 @@ int main(int argc, char *argv[]) } if (EG(exception)) { - zend_exception_error(EG(exception) TSRMLS_CC); + zend_exception_error(EG(exception), E_WARNING TSRMLS_CC); } php_last_char = '\0'; @@ -1195,7 +1220,7 @@ int main(int argc, char *argv[]) case PHP_MODE_INDENT: open_file_for_scanning(&file_handle TSRMLS_CC); zend_indent(); - fclose(file_handle.handle.fp); + zend_file_handle_dtor(file_handle.handle TSRMLS_CC); goto out; break; #endif diff --git a/sapi/cli/php_cli_readline.c b/sapi/cli/php_cli_readline.c index ca4535ae4..66010d7b0 100644 --- a/sapi/cli/php_cli_readline.c +++ b/sapi/cli/php_cli_readline.c @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: php_cli_readline.c 292081 2009-12-13 17:06:47Z felipe $ */ +/* $Id: php_cli_readline.c 272370 2008-12-31 11:15:49Z sebastian $ */ #include "php.h" @@ -49,10 +49,8 @@ #include <unixlib/local.h> #endif -#if HAVE_LIBEDIT -#include <editline/readline.h> -#else #include <readline/readline.h> +#if !HAVE_LIBEDIT #include <readline/history.h> #endif @@ -364,7 +362,7 @@ TODO: - future: respect scope ("php > function foo() { $[tab]" should only expand to local variables...) */ - char *retval; + char *retval = NULL; int textlen = strlen(text); TSRMLS_FETCH(); diff --git a/sapi/cli/php_cli_readline.h b/sapi/cli/php_cli_readline.h index c2599aaa2..d2fd65935 100644 --- a/sapi/cli/php_cli_readline.h +++ b/sapi/cli/php_cli_readline.h @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: php_cli_readline.h 272374 2008-12-31 11:17:49Z sebastian $ */ +/* $Id: php_cli_readline.h 272370 2008-12-31 11:15:49Z sebastian $ */ #include "php.h" diff --git a/sapi/cli/php_getopt.h b/sapi/cli/php_getopt.h deleted file mode 100644 index eb4743d42..000000000 --- a/sapi/cli/php_getopt.h +++ /dev/null @@ -1,39 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 5 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2009 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 3.01 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available through the world-wide-web at the following url: | - | http://www.php.net/license/3_01.txt | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Author: Marcus Boerger <helly@php.net> | - +----------------------------------------------------------------------+ -*/ - -/* $Id: php_getopt.h 272374 2008-12-31 11:17:49Z sebastian $ */ - -#include "php.h" - -#ifdef NETWARE -/* -As NetWare LibC has optind and optarg macros defined in unistd.h our local variables were getting mistakenly preprocessed so undeffing optind and optarg -*/ -#undef optarg -#undef optind -#endif -/* Define structure for one recognized option (both single char and long name). - * If short_open is '-' this is the last option. - */ -typedef struct _opt_struct { - const char opt_char; - const int need_param; - const char * opt_name; -} opt_struct; - -int php_getopt(int argc, char* const *argv, const opt_struct opts[], char **optarg, int *optind, int show_err); diff --git a/sapi/cli/tests/002-win32.phpt b/sapi/cli/tests/002-win32.phpt index ca0e66ddc..5a00c67f7 100644 --- a/sapi/cli/tests/002-win32.phpt +++ b/sapi/cli/tests/002-win32.phpt @@ -10,7 +10,7 @@ if (substr(PHP_OS, 0, 3) != 'WIN') { --FILE-- <?php -$php = $_ENV['TEST_PHP_EXECUTABLE']; +$php = getenv('TEST_PHP_EXECUTABLE'); var_dump(`$php -n -r "var_dump('hello');"`); diff --git a/sapi/cli/tests/005.phpt b/sapi/cli/tests/005.phpt index 0b38bba76..914e33c7f 100644 --- a/sapi/cli/tests/005.phpt +++ b/sapi/cli/tests/005.phpt @@ -12,16 +12,16 @@ if (!extension_loaded("reflection")) { $php = getenv('TEST_PHP_EXECUTABLE'); -var_dump(`$php -n --rc unknown`); -var_dump(`$php -n --rc stdclass`); -var_dump(`$php -n --rc exception`); +var_dump(`"$php" -n --rc unknown`); +var_dump(`"$php" -n --rc stdclass`); +var_dump(`"$php" -n --rc exception`); echo "Done\n"; ?> --EXPECTF-- string(40) "Exception: Class unknown does not exist " -string(178) "Class [ <internal> class stdClass ] { +string(183) "Class [ <internal:Core> class stdClass ] { - Constants [0] { } @@ -40,7 +40,7 @@ string(178) "Class [ <internal> class stdClass ] { } " -string(1141) "Class [ <internal> class Exception ] { +string(1355) "Class [ <internal:Core> class Exception ] { - Constants [0] { } @@ -51,46 +51,51 @@ string(1141) "Class [ <internal> class Exception ] { - Static methods [0] { } - - Properties [6] { + - Properties [7] { Property [ <default> protected $message ] Property [ <default> private $string ] Property [ <default> protected $code ] Property [ <default> protected $file ] Property [ <default> protected $line ] Property [ <default> private $trace ] + Property [ <default> private $previous ] } - - Methods [9] { - Method [ <internal> final private method __clone ] { + - Methods [10] { + Method [ <internal:Core> final private method __clone ] { } - Method [ <internal, ctor> public method __construct ] { + Method [ <internal:Core, ctor> public method __construct ] { - - Parameters [2] { + - Parameters [3] { Parameter #0 [ <optional> $message ] Parameter #1 [ <optional> $code ] + Parameter #2 [ <optional> $previous ] } } - Method [ <internal> final public method getMessage ] { + Method [ <internal:Core> final public method getMessage ] { } - Method [ <internal> final public method getCode ] { + Method [ <internal:Core> final public method getCode ] { } - Method [ <internal> final public method getFile ] { + Method [ <internal:Core> final public method getFile ] { } - Method [ <internal> final public method getLine ] { + Method [ <internal:Core> final public method getLine ] { } - Method [ <internal> final public method getTrace ] { + Method [ <internal:Core> final public method getTrace ] { } - Method [ <internal> final public method getTraceAsString ] { + Method [ <internal:Core> final public method getPrevious ] { } - Method [ <internal> public method __toString ] { + Method [ <internal:Core> final public method getTraceAsString ] { + } + + Method [ <internal:Core> public method __toString ] { } } } diff --git a/sapi/cli/tests/006.phpt b/sapi/cli/tests/006.phpt index 8b1fec8d6..e322d7ef7 100644 --- a/sapi/cli/tests/006.phpt +++ b/sapi/cli/tests/006.phpt @@ -16,7 +16,7 @@ $php = getenv('TEST_PHP_EXECUTABLE'); var_dump(`$php -n --re unknown`); var_dump(`$php -n --re ""`); -var_dump(`$php -n --re date`); +var_dump(`$php -n --re pcre`); echo "Done\n"; ?> @@ -25,298 +25,112 @@ string(44) "Exception: Extension unknown does not exist " string(37) "Exception: Extension does not exist " -string(%d) "Extension [ <persistent> extension #%d date version %s ] { +string(%d) "Extension [ <persistent> extension #%d pcre version <no_version> ] { - INI { - Entry [ date.timezone <ALL> ] - Current = '' + Entry [ pcre.backtrack_limit <ALL> ] + Current = '%d' } - Entry [ date.default_latitude <ALL> ] - Current = '%s' - } - Entry [ date.default_longitude <ALL> ] - Current = '%s' - } - Entry [ date.sunset_zenith <ALL> ] - Current = '%s' - } - Entry [ date.sunrise_zenith <ALL> ] - Current = '%s' + Entry [ pcre.recursion_limit <ALL> ] + Current = '%d' } } - Constants [14] { - Constant [ string DATE_ATOM ] { Y-m-d\TH:i:sP } - Constant [ string DATE_COOKIE ] { l, d-M-y H:i:s T } - Constant [ string DATE_ISO8601 ] { Y-m-d\TH:i:sO } - Constant [ string DATE_RFC822 ] { D, d M y H:i:s O } - Constant [ string DATE_RFC850 ] { l, d-M-y H:i:s T } - Constant [ string DATE_RFC1036 ] { D, d M y H:i:s O } - Constant [ string DATE_RFC1123 ] { D, d M Y H:i:s O } - Constant [ string DATE_RFC2822 ] { D, d M Y H:i:s O } - Constant [ string DATE_RFC3339 ] { Y-m-d\TH:i:sP } - Constant [ string DATE_RSS ] { D, d M Y H:i:s O } - Constant [ string DATE_W3C ] { Y-m-d\TH:i:sP } - Constant [ integer SUNFUNCS_RET_TIMESTAMP ] { 0 } - Constant [ integer SUNFUNCS_RET_STRING ] { 1 } - Constant [ integer SUNFUNCS_RET_DOUBLE ] { 2 } + Constant [ integer PREG_PATTERN_ORDER ] { 1 } + Constant [ integer PREG_SET_ORDER ] { 2 } + Constant [ integer PREG_OFFSET_CAPTURE ] { 256 } + Constant [ integer PREG_SPLIT_NO_EMPTY ] { 1 } + Constant [ integer PREG_SPLIT_DELIM_CAPTURE ] { 2 } + Constant [ integer PREG_SPLIT_OFFSET_CAPTURE ] { 4 } + Constant [ integer PREG_GREP_INVERT ] { 1 } + Constant [ integer PREG_NO_ERROR ] { 0 } + Constant [ integer PREG_INTERNAL_ERROR ] { 1 } + Constant [ integer PREG_BACKTRACK_LIMIT_ERROR ] { 2 } + Constant [ integer PREG_RECURSION_LIMIT_ERROR ] { 3 } + Constant [ integer PREG_BAD_UTF8_ERROR ] { 4 } + Constant [ integer PREG_BAD_UTF8_OFFSET_ERROR ] { 5 } + Constant [ string PCRE_VERSION ] { %s } } - Functions { - Function [ <internal:date> function strtotime ] { - - - Parameters [2] { - Parameter #0 [ <required> $time ] - Parameter #1 [ <optional> $now ] - } - } - Function [ <internal:date> function date ] { + Function [ <internal:pcre> function preg_match ] { - - Parameters [2] { - Parameter #0 [ <required> $format ] - Parameter #1 [ <optional> $timestamp ] + - Parameters [5] { + Parameter #0 [ <required> $pattern ] + Parameter #1 [ <required> $subject ] + Parameter #2 [ <optional> &$subpatterns ] + Parameter #3 [ <optional> $flags ] + Parameter #4 [ <optional> $offset ] } } - Function [ <internal:date> function idate ] { + Function [ <internal:pcre> function preg_match_all ] { - - Parameters [2] { - Parameter #0 [ <required> $format ] - Parameter #1 [ <optional> $timestamp ] + - Parameters [5] { + Parameter #0 [ <required> $pattern ] + Parameter #1 [ <required> $subject ] + Parameter #2 [ <required> &$subpatterns ] + Parameter #3 [ <optional> $flags ] + Parameter #4 [ <optional> $offset ] } } - Function [ <internal:date> function gmdate ] { + Function [ <internal:pcre> function preg_replace ] { - - Parameters [2] { - Parameter #0 [ <required> $format ] - Parameter #1 [ <optional> $timestamp ] + - Parameters [5] { + Parameter #0 [ <required> $regex ] + Parameter #1 [ <required> $replace ] + Parameter #2 [ <optional> $subject ] + Parameter #3 [ <optional> $limit ] + Parameter #4 [ <optional> &$count ] } } - Function [ <internal:date> function mktime ] { + Function [ <internal:pcre> function preg_replace_callback ] { - - Parameters [6] { - Parameter #0 [ <optional> $hour ] - Parameter #1 [ <optional> $min ] - Parameter #2 [ <optional> $sec ] - Parameter #3 [ <optional> $mon ] - Parameter #4 [ <optional> $day ] - Parameter #5 [ <optional> $year ] + - Parameters [5] { + Parameter #0 [ <required> $regex ] + Parameter #1 [ <required> $callback ] + Parameter #2 [ <required> $subject ] + Parameter #3 [ <optional> $limit ] + Parameter #4 [ <optional> &$count ] } } - Function [ <internal:date> function gmmktime ] { + Function [ <internal:pcre> function preg_filter ] { - - Parameters [6] { - Parameter #0 [ <optional> $hour ] - Parameter #1 [ <optional> $min ] - Parameter #2 [ <optional> $sec ] - Parameter #3 [ <optional> $mon ] - Parameter #4 [ <optional> $day ] - Parameter #5 [ <optional> $year ] + - Parameters [5] { + Parameter #0 [ <required> $regex ] + Parameter #1 [ <required> $replace ] + Parameter #2 [ <optional> $subject ] + Parameter #3 [ <optional> $limit ] + Parameter #4 [ <optional> &$count ] } } - Function [ <internal:date> function checkdate ] { + Function [ <internal:pcre> function preg_split ] { - - Parameters [3] { - Parameter #0 [ <required> $month ] - Parameter #1 [ <required> $day ] - Parameter #2 [ <required> $year ] - } - } - Function [ <internal:date> function strftime ] { - - - Parameters [2] { - Parameter #0 [ <required> $format ] - Parameter #1 [ <optional> $timestamp ] - } - } - Function [ <internal:date> function gmstrftime ] { - - - Parameters [2] { - Parameter #0 [ <required> $format ] - Parameter #1 [ <optional> $timestamp ] - } - } - Function [ <internal:date> function time ] { - - - Parameters [0] { + - Parameters [4] { + Parameter #0 [ <required> $pattern ] + Parameter #1 [ <required> $subject ] + Parameter #2 [ <optional> $limit ] + Parameter #3 [ <optional> $flags ] } } - Function [ <internal:date> function localtime ] { + Function [ <internal:pcre> function preg_quote ] { - Parameters [2] { - Parameter #0 [ <optional> $timestamp ] - Parameter #1 [ <optional> $associative_array ] - } - } - Function [ <internal:date> function getdate ] { - - - Parameters [1] { - Parameter #0 [ <optional> $timestamp ] - } - } - Function [ <internal:date> function date_create ] { - } - Function [ <internal:date> function date_parse ] { - } - Function [ <internal:date> function date_format ] { - } - Function [ <internal:date> function date_modify ] { - } - Function [ <internal:date> function date_timezone_get ] { - } - Function [ <internal:date> function date_timezone_set ] { - } - Function [ <internal:date> function date_offset_get ] { - } - Function [ <internal:date> function date_time_set ] { - } - Function [ <internal:date> function date_date_set ] { - } - Function [ <internal:date> function date_isodate_set ] { - } - Function [ <internal:date> function timezone_open ] { - } - Function [ <internal:date> function timezone_name_get ] { - } - Function [ <internal:date> function timezone_name_from_abbr ] { - } - Function [ <internal:date> function timezone_offset_get ] { - } - Function [ <internal:date> function timezone_transitions_get ] { - } - Function [ <internal:date> function timezone_identifiers_list ] { - } - Function [ <internal:date> function timezone_abbreviations_list ] { - } - Function [ <internal:date> function date_default_timezone_set ] { - - - Parameters [1] { - Parameter #0 [ <required> $timezone_identifier ] + Parameter #0 [ <required> $str ] + Parameter #1 [ <optional> $delim_char ] } } - Function [ <internal:date> function date_default_timezone_get ] { - - - Parameters [0] { - } - } - Function [ <internal:date> function date_sunrise ] { - - - Parameters [6] { - Parameter #0 [ <required> $time ] - Parameter #1 [ <optional> $format ] - Parameter #2 [ <optional> $latitude ] - Parameter #3 [ <optional> $longitude ] - Parameter #4 [ <optional> $zenith ] - Parameter #5 [ <optional> $gmt_offset ] - } - } - Function [ <internal:date> function date_sunset ] { - - - Parameters [6] { - Parameter #0 [ <required> $time ] - Parameter #1 [ <optional> $format ] - Parameter #2 [ <optional> $latitude ] - Parameter #3 [ <optional> $longitude ] - Parameter #4 [ <optional> $zenith ] - Parameter #5 [ <optional> $gmt_offset ] - } - } - Function [ <internal:date> function date_sun_info ] { + Function [ <internal:pcre> function preg_grep ] { - Parameters [3] { - Parameter #0 [ <required> $time ] - Parameter #1 [ <required> $latitude ] - Parameter #2 [ <required> $longitude ] + Parameter #0 [ <required> $regex ] + Parameter #1 [ <required> $input ] + Parameter #2 [ <optional> $flags ] } } - } - - - Classes [2] { - Class [ <internal:date> class DateTime ] { - - - Constants [11] { - Constant [ string ATOM ] { Y-m-d\TH:i:sP } - Constant [ string COOKIE ] { l, d-M-y H:i:s T } - Constant [ string ISO8601 ] { Y-m-d\TH:i:sO } - Constant [ string RFC822 ] { D, d M y H:i:s O } - Constant [ string RFC850 ] { l, d-M-y H:i:s T } - Constant [ string RFC1036 ] { D, d M y H:i:s O } - Constant [ string RFC1123 ] { D, d M Y H:i:s O } - Constant [ string RFC2822 ] { D, d M Y H:i:s O } - Constant [ string RFC3339 ] { Y-m-d\TH:i:sP } - Constant [ string RSS ] { D, d M Y H:i:s O } - Constant [ string W3C ] { Y-m-d\TH:i:sP } - } - - - Static properties [0] { - } - - - Static methods [0] { - } - - - Properties [0] { - } - - - Methods [9] { - Method [ <internal:date, ctor> public method __construct ] { - } - - Method [ <internal:date> public method format ] { - } - - Method [ <internal:date> public method modify ] { - } + Function [ <internal:pcre> function preg_last_error ] { - Method [ <internal:date> public method getTimezone ] { - } - - Method [ <internal:date> public method setTimezone ] { - } - - Method [ <internal:date> public method getOffset ] { - } - - Method [ <internal:date> public method setTime ] { - } - - Method [ <internal:date> public method setDate ] { - } - - Method [ <internal:date> public method setISODate ] { - } - } - } - - Class [ <internal:date> class DateTimeZone ] { - - - Constants [0] { - } - - - Static properties [0] { - } - - - Static methods [2] { - Method [ <internal:date> static public method listAbbreviations ] { - } - - Method [ <internal:date> static public method listIdentifiers ] { - } - } - - - Properties [0] { - } - - - Methods [4] { - Method [ <internal:date, ctor> public method __construct ] { - } - - Method [ <internal:date> public method getName ] { - } - - Method [ <internal:date> public method getOffset ] { - } - - Method [ <internal:date> public method getTransitions ] { - } + - Parameters [0] { } } } diff --git a/sapi/cli/tests/010.phpt b/sapi/cli/tests/010.phpt index e465e3797..77c76c194 100644 --- a/sapi/cli/tests/010.phpt +++ b/sapi/cli/tests/010.phpt @@ -12,8 +12,8 @@ if (substr(PHP_OS, 0, 3) == 'WIN') { $php = getenv('TEST_PHP_EXECUTABLE'); -$filename = dirname(__FILE__)."/010.test.php"; -$filename_txt = dirname(__FILE__)."/010.test.txt"; +$filename = __DIR__."/010.test.php"; +$filename_txt = __DIR__."/010.test.txt"; $code = ' <?php @@ -25,23 +25,22 @@ file_put_contents($filename, $code); $txt = ' test -hello -'; +hello'; file_put_contents($filename_txt, $txt); var_dump(`cat "$filename_txt" | "$php" -n -F "$filename"`); -@unlink($filename); -@unlink($filename_txt); - -echo "Done\n"; +?> +===DONE=== +--CLEAN-- +<?php +@unlink(__DIR__."/010.test.php"); +@unlink(__DIR__."/010.test.txt"); ?> --EXPECTF-- -string(39) " +string(25) " string(10) "test hello" - -string(0) "" " -Done +===DONE=== diff --git a/sapi/cli/tests/016.phpt b/sapi/cli/tests/016.phpt new file mode 100644 index 000000000..adde106df --- /dev/null +++ b/sapi/cli/tests/016.phpt @@ -0,0 +1,108 @@ +--TEST-- +CLI -a and readline +--SKIPIF-- +<?php +include "skipif.inc"; +if (!extension_loaded('readline') || readline_info('done') === NULL) { + die ("skip need readline support"); +} +?> +--FILE-- +<?php +$php = getenv('TEST_PHP_EXECUTABLE'); + +// disallow console escape sequences that may break the output +putenv('TERM=VT100'); + +$codes = array(); + +$codes[1] = <<<EOT +echo 'Hello world'; +exit +EOT; + +$codes[] = <<<EOT +echo 'multine +single +quote'; +exit +EOT; + +$codes[] = <<<EOT +echo <<<HEREDOC +Here +comes +the +doc +HEREDOC; +EOT; + +$codes[] = <<<EOT +if (0) { + echo "I'm not there"; +} +echo "Done"; +EOT; + +$codes[] = <<<EOT +function a_function_with_some_name() { + echo "I was called!"; +} +a_function_w ); +EOT; + +foreach ($codes as $key => $code) { + echo "\n--------------\nSnippet no. $key:\n--------------\n"; + $code = escapeshellarg($code); + echo `echo $code | "$php" -a`, "\n"; +} + +echo "\nDone\n"; +?> +--EXPECTF-- +-------------- +Snippet no. 1: +-------------- +Interactive shell + +php > Hello world +php > + +-------------- +Snippet no. 2: +-------------- +Interactive shell + +php > php ' php ' multine +single +quote +php > + +-------------- +Snippet no. 3: +-------------- +Interactive shell + +php > <<< > <<< > <<< > <<< > <<< > Here +comes +the +doc +php > + +-------------- +Snippet no. 4: +-------------- +Interactive shell + +php > php { php { php > Done +php > + +-------------- +Snippet no. 5: +-------------- +Interactive shell + +php > php { php { php > I was called! +php > + +Done diff --git a/sapi/cli/tests/017.phpt b/sapi/cli/tests/017.phpt new file mode 100644 index 000000000..efaf977db --- /dev/null +++ b/sapi/cli/tests/017.phpt @@ -0,0 +1,106 @@ +--TEST-- +CLI -a and libedit +--SKIPIF-- +<?php +include "skipif.inc"; +if (!extension_loaded('readline') || readline_info('done') !== NULL) { + die ("skip need readline support using libedit"); +} +?> +--FILE-- +<?php +$php = getenv('TEST_PHP_EXECUTABLE'); + +$codes = array(); + +$codes[1] = <<<EOT +echo 'Hello world'; +exit +EOT; + +$codes[] = <<<EOT +echo 'multine +single +quote'; +exit +EOT; + +$codes[] = <<<EOT +echo <<<HEREDOC +Here +comes +the +doc +HEREDOC; +EOT; + +$codes[] = <<<EOT +if (0) { + echo "I'm not there"; +} +echo "Done"; +EOT; + +$codes[] = <<<EOT +function a_function_with_some_name() { + echo "I was called!"; +} +a_function_w ); +EOT; + +foreach ($codes as $key => $code) { + echo "\n--------------\nSnippet no. $key:\n--------------\n"; + $code = escapeshellarg($code); + echo `echo $code | "$php" -a`, "\n"; +} + +echo "\nDone\n"; +?> +--EXPECTF-- +-------------- +Snippet no. 1: +-------------- +Interactive shell + +Hello world + + +-------------- +Snippet no. 2: +-------------- +Interactive shell + +multine +single +quote + + +-------------- +Snippet no. 3: +-------------- +Interactive shell + +Here +comes +the +doc + + +-------------- +Snippet no. 4: +-------------- +Interactive shell + +Done + + +-------------- +Snippet no. 5: +-------------- +Interactive shell + + +Parse error: syntax error, unexpected ')' in php shell code on line 1 + + +Done diff --git a/sapi/cli/tests/018.phpt b/sapi/cli/tests/018.phpt new file mode 100644 index 000000000..56921bd66 --- /dev/null +++ b/sapi/cli/tests/018.phpt @@ -0,0 +1,27 @@ +--TEST-- +CLI php -m +--SKIPIF-- +<?php +include "skipif.inc"; +if (substr(PHP_OS, 0, 3) == 'WIN') { + die ("skip not for Windows"); +} +?> +--FILE-- +<?php + +$php = getenv('TEST_PHP_EXECUTABLE'); + + +echo `"$php" -n -m`; + +echo "Done\n"; +?> +--EXPECTF-- +[PHP Modules] +%a +pcre +%a + +[Zend Modules] +%aDone diff --git a/sapi/cli/tests/019.phpt b/sapi/cli/tests/019.phpt new file mode 100644 index 000000000..c98155d8d --- /dev/null +++ b/sapi/cli/tests/019.phpt @@ -0,0 +1,36 @@ +--TEST-- +CLI php -i +--SKIPIF-- +<?php +include "skipif.inc"; +if (substr(PHP_OS, 0, 3) == 'WIN') { + die ("skip not for Windows"); +} +?> +--FILE-- +<?php + +$php = getenv('TEST_PHP_EXECUTABLE'); + + +echo `"$php" -n -i`; + +echo "\nDone\n"; +?> +--EXPECTF-- +phpinfo() +PHP Version => %s +%a +PHP License +This program is free software; you can redistribute it and/or modify +it under the terms of the PHP License as published by the PHP Group +and included in the distribution in the file: LICENSE + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + +If you did not receive a copy of the PHP license, or have any +questions about PHP licensing, please contact license@php.net. + +Done diff --git a/sapi/cli/tests/020.phpt b/sapi/cli/tests/020.phpt new file mode 100644 index 000000000..62be4ba31 --- /dev/null +++ b/sapi/cli/tests/020.phpt @@ -0,0 +1,32 @@ +--TEST-- +CLI php --ri +--SKIPIF-- +<?php +include "skipif.inc"; +if (substr(PHP_OS, 0, 3) == 'WIN') { + die ("skip not for Windows"); +} +?> +--FILE-- +<?php + +$php = getenv('TEST_PHP_EXECUTABLE'); + + +echo `"$php" -n --ri this_extension_does_not_exist_568537753423`; +echo `"$php" -n --ri standard`; + +echo "\nDone\n"; +?> +--EXPECTF-- +Extension 'this_extension_does_not_exist_568537753423' not present. + +standard + +%a + +Directive => Local Value => Master Value +%a + +Done + diff --git a/sapi/cli/tests/021.phpt b/sapi/cli/tests/021.phpt index b127b8969..a4442b0e0 100644 --- a/sapi/cli/tests/021.phpt +++ b/sapi/cli/tests/021.phpt @@ -12,7 +12,7 @@ if (substr(PHP_OS, 0, 3) == 'WIN') { $php = getenv('TEST_PHP_EXECUTABLE'); -$filename = dirname(__FILE__).'/021.tmp.php'; +$filename = __DIR__.'/021.tmp.php'; $script = "#!$php -n\n". "ola\n". @@ -29,7 +29,7 @@ echo "\nDone\n"; ?> --CLEAN-- <?php -unlink(dirname(__FILE__).'/021.tmp.php'); +unlink(__DIR__.'/021.tmp.php'); ?> --EXPECTF-- ola |
