diff options
Diffstat (limited to 'sapi/cli/php_cli.c')
-rw-r--r-- | sapi/cli/php_cli.c | 83 |
1 files changed, 63 insertions, 20 deletions
diff --git a/sapi/cli/php_cli.c b/sapi/cli/php_cli.c index 978c8b332e..dc92045ae7 100644 --- a/sapi/cli/php_cli.c +++ b/sapi/cli/php_cli.c @@ -39,6 +39,7 @@ #include "win32/time.h" #include "win32/signal.h" #include <process.h> +#include <shellapi.h> #endif #if HAVE_SYS_TIME_H #include <sys/time.h> @@ -102,9 +103,12 @@ PHPAPI extern char *php_ini_opened_path; PHPAPI extern char *php_ini_scanned_path; PHPAPI extern char *php_ini_scanned_files; -#if defined(PHP_WIN32) && defined(ZTS) +#if defined(PHP_WIN32) +#if defined(ZTS) ZEND_TSRMLS_CACHE_DEFINE() #endif +static DWORD orig_cp = 0; +#endif #ifndef O_BINARY #define O_BINARY 0 @@ -218,8 +222,9 @@ static int print_extension_info(zend_extension *ext, void *arg) /* {{{ */ static int extension_name_cmp(const zend_llist_element **f, const zend_llist_element **s) /* {{{ */ { - return strcmp(((zend_extension *)(*f)->data)->name, - ((zend_extension *)(*s)->data)->name); + zend_extension *fe = (zend_extension*)(*f)->data; + zend_extension *se = (zend_extension*)(*s)->data; + return strcmp(fe->name, se->name); } /* }}} */ @@ -267,11 +272,7 @@ PHP_CLI_API size_t sapi_cli_single_write(const char *str, size_t str_length) /* #endif if (cli_shell_callbacks.cli_shell_write) { - size_t shell_wrote; - shell_wrote = cli_shell_callbacks.cli_shell_write(str, str_length); - if (shell_wrote > -1) { - return shell_wrote; - } + cli_shell_callbacks.cli_shell_write(str, str_length); } #ifdef PHP_WRITE_STDOUT @@ -376,7 +377,7 @@ static void sapi_cli_register_variables(zval *track_vars_array) /* {{{ */ } /* }}} */ -static void sapi_cli_log_message(char *message) /* {{{ */ +static void sapi_cli_log_message(char *message, int syslog_type_int) /* {{{ */ { fprintf(stderr, "%s\n", message); } @@ -487,7 +488,7 @@ static const zend_function_entry additional_functions[] = { ZEND_FE(dl, arginfo_dl) PHP_FE(cli_set_process_title, arginfo_cli_set_process_title) PHP_FE(cli_get_process_title, arginfo_cli_get_process_title) - {NULL, NULL, NULL} + PHP_FE_END }; /* {{{ php_cli_usage @@ -557,7 +558,6 @@ static php_stream *s_in_process = NULL; static void cli_register_file_handles(void) /* {{{ */ { - zval zin, zout, zerr; php_stream *s_in, *s_out, *s_err; php_stream_context *sc_in=NULL, *sc_out=NULL, *sc_err=NULL; zend_constant ic, oc, ec; @@ -581,23 +581,20 @@ static void cli_register_file_handles(void) /* {{{ */ s_in_process = s_in; - php_stream_to_zval(s_in, &zin); - php_stream_to_zval(s_out, &zout); - php_stream_to_zval(s_err, &zerr); + php_stream_to_zval(s_in, &ic.value); + php_stream_to_zval(s_out, &oc.value); + php_stream_to_zval(s_err, &ec.value); - ZVAL_COPY_VALUE(&ic.value, &zin); ic.flags = CONST_CS; ic.name = zend_string_init("STDIN", sizeof("STDIN")-1, 1); ic.module_number = 0; zend_register_constant(&ic); - ZVAL_COPY_VALUE(&oc.value, &zout); oc.flags = CONST_CS; oc.name = zend_string_init("STDOUT", sizeof("STDOUT")-1, 1); oc.module_number = 0; zend_register_constant(&oc); - ZVAL_COPY_VALUE(&ec.value, &zerr); ec.flags = CONST_CS; ec.name = zend_string_init("STDERR", sizeof("STDERR")-1, 1); ec.module_number = 0; @@ -646,6 +643,17 @@ 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) +BOOL WINAPI php_cli_win32_ctrl_handler(DWORD sig) +{ + (void)php_win32_cp_cli_do_restore(orig_cp); + + return FALSE; +} +#endif +/*}}}*/ + static int do_cli(int argc, char **argv) /* {{{ */ { int c; @@ -689,6 +697,14 @@ static int do_cli(int argc, char **argv) /* {{{ */ #else "NTS " #endif +#ifdef COMPILER + COMPILER + " " +#endif +#ifdef ARCHITECTURE + ARCHITECTURE + " " +#endif #if ZEND_DEBUG "DEBUG " #endif @@ -1163,9 +1179,16 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine int main(int argc, char *argv[]) #endif { -#ifdef PHP_CLI_WIN32_NO_CONSOLE +#if defined(PHP_WIN32) +# ifdef PHP_CLI_WIN32_NO_CONSOLE int argc = __argc; char **argv = __argv; +# else + int num_args; + wchar_t **argv_wide; + char **argv_save = argv; + BOOL using_wide_argv = 0; +# endif #endif int c; @@ -1222,9 +1245,7 @@ int main(int argc, char *argv[]) ZEND_TSRMLS_CACHE_UPDATE(); #endif -#ifdef ZEND_SIGNALS zend_signal_startup(); -#endif #ifdef PHP_WIN32 _fmode = _O_BINARY; /*sets default for file streams to binary */ @@ -1332,6 +1353,19 @@ exit_loop: } module_started = 1; +#if defined(PHP_WIN32) && !defined(PHP_CLI_WIN32_NO_CONSOLE) + 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 + might be too late though, but this is the earliest place ATW + we can access the internal charset information from PHP. */ + argv_wide = CommandLineToArgvW(GetCommandLineW(), &num_args); + PHP_WIN32_CP_W_TO_ANY_ARRAY(argv_wide, num_args, argv, argc) + using_wide_argv = 1; + + SetConsoleCtrlHandler(php_cli_win32_ctrl_handler, TRUE); +#endif + /* -e option */ if (use_extended_info) { CG(compiler_options) |= ZEND_COMPILE_EXTENDED_INFO; @@ -1365,6 +1399,15 @@ out: tsrm_shutdown(); #endif +#if defined(PHP_WIN32) && !defined(PHP_CLI_WIN32_NO_CONSOLE) + (void)php_win32_cp_cli_restore(); + + if (using_wide_argv) { + PHP_WIN32_CP_FREE_ARRAY(argv, argc); + LocalFree(argv_wide); + } + argv = argv_save; +#endif /* * Do not move this de-initialization. It needs to happen right before * exiting. |