diff options
Diffstat (limited to 'sapi/cli/php_cli.c')
-rw-r--r-- | sapi/cli/php_cli.c | 39 |
1 files changed, 31 insertions, 8 deletions
diff --git a/sapi/cli/php_cli.c b/sapi/cli/php_cli.c index 617539c155..b217b2731d 100644 --- a/sapi/cli/php_cli.c +++ b/sapi/cli/php_cli.c @@ -38,6 +38,7 @@ #ifdef PHP_WIN32 #include "win32/time.h" #include "win32/signal.h" +#include "win32/console.h" #include <process.h> #include <shellapi.h> #endif @@ -243,8 +244,11 @@ static void print_extensions(void) /* {{{ */ #ifndef STDOUT_FILENO #define STDOUT_FILENO 1 #endif +#ifndef STDERR_FILENO +#define STDERR_FILENO 2 +#endif -static inline int sapi_cli_select(int fd) +static inline int sapi_cli_select(php_socket_t fd) { fd_set wfd, dfd; struct timeval tv; @@ -910,6 +914,20 @@ static int do_cli(int argc, char **argv) /* {{{ */ goto err; } +#if defined(PHP_WIN32) && !defined(PHP_CLI_WIN32_NO_CONSOLE) && (HAVE_LIBREADLINE || HAVE_LIBEDIT) && !defined(COMPILE_DL_READLINE) + if (!interactive) { + /* The -a option was not passed. If there is no file, it could + still make sense to run interactively. The presense of a file + is essential to mitigate buggy console info. */ + interactive = php_win32_console_is_own() && + !(script_file || + argc > php_optind && behavior!=PHP_MODE_CLI_DIRECT && + behavior!=PHP_MODE_PROCESS_STDIN && + strcmp(argv[php_optind-1],"--") + ); + } +#endif + if (interactive) { #if (HAVE_LIBREADLINE || HAVE_LIBEDIT) && !defined(COMPILE_DL_READLINE) printf("Interactive shell\n\n"); @@ -944,7 +962,7 @@ static int do_cli(int argc, char **argv) /* {{{ */ /* here but this would make things only more complicated. And it */ /* is consitent with the way -R works where the stdin file handle*/ /* is also accessible. */ - file_handle.filename = "-"; + file_handle.filename = "Standard input code"; file_handle.handle.fp = stdin; } file_handle.type = ZEND_HANDLE_FP; @@ -983,7 +1001,7 @@ static int do_cli(int argc, char **argv) /* {{{ */ PG(during_request_startup) = 0; switch (behavior) { case PHP_MODE_STANDARD: - if (strcmp(file_handle.filename, "-")) { + if (strcmp(file_handle.filename, "Standard input code")) { cli_register_file_handles(); } @@ -1125,7 +1143,7 @@ static int do_cli(int argc, char **argv) /* {{{ */ } case PHP_MODE_REFLECTION_EXT_INFO: { - int len = (int)strlen(reflection_what); + size_t len = strlen(reflection_what); char *lcname = zend_str_tolower_dup(reflection_what, len); zend_module_entry *module; @@ -1201,7 +1219,7 @@ int main(int argc, char *argv[]) int php_optind = 1, use_extended_info = 0; char *ini_path_override = NULL; char *ini_entries = NULL; - int ini_entries_len = 0; + size_t ini_entries_len = 0; int ini_ignore = 0; sapi_module_struct *sapi_module = &cli_sapi_module; @@ -1211,6 +1229,11 @@ int main(int argc, char *argv[]) */ argv = save_ps_args(argc, argv); +#if defined(PHP_WIN32) && !defined(PHP_CLI_WIN32_NO_CONSOLE) + php_win32_console_fileno_set_vt100(STDOUT_FILENO, TRUE); + php_win32_console_fileno_set_vt100(STDERR_FILENO, TRUE); +#endif + cli_sapi_module.additional_functions = additional_functions; #if defined(PHP_WIN32) && defined(_DEBUG) && defined(PHP_WIN32_DEBUG_HEAP) @@ -1270,7 +1293,7 @@ int main(int argc, char *argv[]) break; case 'd': { /* define ini entries on command line */ - int len = (int)strlen(php_optarg); + size_t len = strlen(php_optarg); char *val; if ((val = strchr(php_optarg, '='))) { @@ -1278,11 +1301,11 @@ int main(int argc, char *argv[]) if (!isalnum(*val) && *val != '"' && *val != '\'' && *val != '\0') { ini_entries = realloc(ini_entries, ini_entries_len + len + sizeof("\"\"\n\0")); memcpy(ini_entries + ini_entries_len, php_optarg, (val - php_optarg)); - ini_entries_len += (int)(val - php_optarg); + ini_entries_len += (val - php_optarg); memcpy(ini_entries + ini_entries_len, "\"", 1); ini_entries_len++; memcpy(ini_entries + ini_entries_len, val, len - (val - php_optarg)); - ini_entries_len += len - (int)(val - php_optarg); + ini_entries_len += len - (val - php_optarg); memcpy(ini_entries + ini_entries_len, "\"\n\0", sizeof("\"\n\0")); ini_entries_len += sizeof("\n\0\"") - 2; } else { |