diff options
Diffstat (limited to 'sapi/cli/php_cli.c')
-rw-r--r-- | sapi/cli/php_cli.c | 48 |
1 files changed, 35 insertions, 13 deletions
diff --git a/sapi/cli/php_cli.c b/sapi/cli/php_cli.c index 617539c155..86d2c6d224 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; @@ -647,7 +651,7 @@ static int cli_seek_file_begin(zend_file_handle *file_handle, char *script_file, /* }}} */ /*{{{ php_cli_win32_ctrl_handler */ -#if defined(PHP_WIN32) && !defined(PHP_CLI_WIN32_NO_CONSOLE) +#if defined(PHP_WIN32) BOOL WINAPI php_cli_win32_ctrl_handler(DWORD sig) { (void)php_win32_cp_cli_do_restore(orig_cp); @@ -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; @@ -1186,12 +1204,11 @@ int main(int argc, char *argv[]) # ifdef PHP_CLI_WIN32_NO_CONSOLE int argc = __argc; char **argv = __argv; -# else +# endif int num_args; wchar_t **argv_wide; char **argv_save = argv; BOOL using_wide_argv = 0; -# endif #endif int c; @@ -1201,7 +1218,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 +1228,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 +1292,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 +1300,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 { @@ -1356,7 +1378,7 @@ exit_loop: } module_started = 1; -#if defined(PHP_WIN32) && !defined(PHP_CLI_WIN32_NO_CONSOLE) +#if defined(PHP_WIN32) php_win32_cp_cli_setup(); orig_cp = (php_win32_cp_get_orig())->id; /* Ignore the delivered argv and argc, read from W API. This place @@ -1402,7 +1424,7 @@ out: tsrm_shutdown(); #endif -#if defined(PHP_WIN32) && !defined(PHP_CLI_WIN32_NO_CONSOLE) +#if defined(PHP_WIN32) (void)php_win32_cp_cli_restore(); if (using_wide_argv) { |