}
/* }}} */
-/* {{{ main
- */
-#ifdef PHP_CLI_WIN32_NO_CONSOLE
-int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
-#else
-int main(int argc, char *argv[])
-#endif
+static int do_cli(int argc, char **argv TSRMLS_DC) /* {{{ */
{
- volatile int exit_status = SUCCESS;
int c;
zend_file_handle file_handle;
-/* temporary locals */
- int behavior=PHP_MODE_STANDARD;
+ int behavior = PHP_MODE_STANDARD;
char *reflection_what = NULL;
- int orig_optind=php_optind;
- char *orig_optarg=php_optarg;
+ volatile int request_started = 0;
+ volatile int exit_status = 0;
+ char *php_optarg = NULL, *orig_optarg = NULL;
+ int php_optind = 1, orig_optind = 1;
+ char *exec_direct=NULL, *exec_run=NULL, *exec_begin=NULL, *exec_end=NULL;
char *arg_free=NULL, **arg_excp=&arg_free;
- char *script_file=NULL;
+ char *script_file=NULL, *translated_path = NULL;
int interactive=0;
- volatile int module_started = 0;
- volatile int request_started = 0;
int lineno = 0;
- char *exec_direct=NULL, *exec_run=NULL, *exec_begin=NULL, *exec_end=NULL;
const char *param_error=NULL;
int hide_argv = 0;
-/* end of temporary locals */
-#ifdef ZTS
- void ***tsrm_ls;
-#endif
-#ifdef PHP_CLI_WIN32_NO_CONSOLE
- int argc = __argc;
- char **argv = __argv;
-#endif
- int ini_entries_len = 0;
-
-#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;
-
- _CrtSetDbgFlag(tmp_flag);
- }
-#endif
-
-#ifdef HAVE_SIGNAL_H
-#if defined(SIGPIPE) && defined(SIG_IGN)
- signal(SIGPIPE, SIG_IGN); /* ignore SIGPIPE in standalone mode so
- that sockets created via fsockopen()
- don't kill PHP if the remote site
- closes it. in apache|apxs mode apache
- does that for us! thies@thieso.net
- 20000419 */
-#endif
-#endif
-
-
-#ifdef ZTS
- tsrm_startup(1, 1, 0, NULL);
- tsrm_ls = ts_resource(0);
-#endif
-
- cli_sapi_module.ini_defaults = sapi_cli_ini_defaults;
- cli_sapi_module.php_ini_path_override = NULL;
- cli_sapi_module.phpinfo_as_text = 1;
- sapi_startup(&cli_sapi_module);
-
-#ifdef PHP_WIN32
- _fmode = _O_BINARY; /*sets default for file streams to binary */
- setmode(_fileno(stdin), O_BINARY); /* make the stdio mode be binary */
- setmode(_fileno(stdout), O_BINARY); /* make the stdio mode be binary */
- setmode(_fileno(stderr), O_BINARY); /* make the stdio mode be binary */
-#endif
- 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, 2))!=-1) {
- switch (c) {
- case 'c':
- if (cli_sapi_module.php_ini_path_override) {
- free(cli_sapi_module.php_ini_path_override);
- }
- cli_sapi_module.php_ini_path_override = strdup(php_optarg);
- break;
- case 'n':
- cli_sapi_module.php_ini_ignore = 1;
- break;
- case 'd': {
- /* define ini entries on command line */
- int len = strlen(php_optarg);
- char *val;
-
- if ((val = strchr(php_optarg, '='))) {
- val++;
- if (!isalnum(*val) && *val != '"' && *val != '\'' && *val != '\0') {
- cli_sapi_module.ini_entries = realloc(cli_sapi_module.ini_entries, ini_entries_len + len + sizeof("\"\"\n\0"));
- memcpy(cli_sapi_module.ini_entries + ini_entries_len, php_optarg, (val - php_optarg));
- ini_entries_len += (val - php_optarg);
- memcpy(cli_sapi_module.ini_entries + ini_entries_len, "\"", 1);
- ini_entries_len++;
- memcpy(cli_sapi_module.ini_entries + ini_entries_len, val, len - (val - php_optarg));
- ini_entries_len += len - (val - php_optarg);
- memcpy(cli_sapi_module.ini_entries + ini_entries_len, "\"\n\0", sizeof("\"\n\0"));
- ini_entries_len += sizeof("\n\0\"") - 2;
- } else {
- cli_sapi_module.ini_entries = realloc(cli_sapi_module.ini_entries, ini_entries_len + len + sizeof("\n\0"));
- memcpy(cli_sapi_module.ini_entries + ini_entries_len, php_optarg, len);
- memcpy(cli_sapi_module.ini_entries + ini_entries_len + len, "\n\0", sizeof("\n\0"));
- ini_entries_len += len + sizeof("\n\0") - 2;
- }
- } else {
- cli_sapi_module.ini_entries = realloc(cli_sapi_module.ini_entries, ini_entries_len + len + sizeof("=1\n\0"));
- memcpy(cli_sapi_module.ini_entries + ini_entries_len, php_optarg, len);
- memcpy(cli_sapi_module.ini_entries + ini_entries_len + len, "=1\n\0", sizeof("=1\n\0"));
- ini_entries_len += len + sizeof("=1\n\0") - 2;
- }
- break;
- }
- }
- }
- php_optind = orig_optind;
- 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) {
- /* there is no way to see if we must call zend_ini_deactivate()
- * since we cannot check if EG(ini_directives) has been initialised
- * because the executor's constructor does not set initialize it.
- * Apart from that there seems no need for zend_ini_deactivate() yet.
- * So we goto out_err.*/
- exit_status = 1;
- goto out_err;
- }
- module_started = 1;
-
- zend_first_try {
+ zend_try {
+
CG(in_compilation) = 0; /* not initialized but needed for several options */
EG(uninitialized_zval_ptr) = NULL;
SG(request_info).argc=argc-php_optind+1;
arg_excp = argv+php_optind-1;
arg_free = argv[php_optind-1];
- SG(request_info).path_translated = (char*)file_handle.filename;
- SG(request_info).path_translated = translated_path? translated_path : file_handle.filename;
- argv[php_optind-1] = file_handle.filename;
++ SG(request_info).path_translated = translated_path? translated_path: (char*)file_handle.filename;
+ argv[php_optind-1] = (char*)file_handle.filename;
SG(request_info).argv=argv+php_optind-1;
if (php_request_startup(TSRMLS_C)==FAILURE) {