You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

758 lines
20 KiB

24 years ago
24 years ago
24 years ago
  1. /*
  2. +----------------------------------------------------------------------+
  3. | PHP Version 4 |
  4. +----------------------------------------------------------------------+
  5. | Copyright (c) 1997-2002 The PHP Group |
  6. +----------------------------------------------------------------------+
  7. | This source file is subject to version 2.02 of the PHP license, |
  8. | that is bundled with this package in the file LICENSE, and is |
  9. | available at through the world-wide-web at |
  10. | http://www.php.net/license/2_02.txt. |
  11. | If you did not receive a copy of the PHP license and are unable to |
  12. | obtain it through the world-wide-web, please send a note to |
  13. | license@php.net so we can mail you a copy immediately. |
  14. +----------------------------------------------------------------------+
  15. | Author: Edin Kadribasic <edink@php.net> |
  16. | Marcus Boerger <helly@php.net> |
  17. | Parts based on CGI SAPI Module by |
  18. | Rasmus Lerdorf, Stig Bakken and Zeev Suraski |
  19. +----------------------------------------------------------------------+
  20. */
  21. #include "php.h"
  22. #include "php_globals.h"
  23. #include "php_variables.h"
  24. #include "zend_modules.h"
  25. #include "SAPI.h"
  26. #include <stdio.h>
  27. #include "php.h"
  28. #ifdef PHP_WIN32
  29. #include "win32/time.h"
  30. #include "win32/signal.h"
  31. #include <process.h>
  32. #else
  33. #include "build-defs.h"
  34. #endif
  35. #if HAVE_SYS_TIME_H
  36. #include <sys/time.h>
  37. #endif
  38. #if HAVE_UNISTD_H
  39. #include <unistd.h>
  40. #endif
  41. #if HAVE_SIGNAL_H
  42. #include <signal.h>
  43. #endif
  44. #if HAVE_SETLOCALE
  45. #include <locale.h>
  46. #endif
  47. #include "zend.h"
  48. #include "zend_extensions.h"
  49. #include "php_ini.h"
  50. #include "php_globals.h"
  51. #include "php_main.h"
  52. #include "fopen_wrappers.h"
  53. #include "ext/standard/php_standard.h"
  54. #ifdef PHP_WIN32
  55. #include <io.h>
  56. #include <fcntl.h>
  57. #include "win32/php_registry.h"
  58. #endif
  59. #if HAVE_SIGNAL_H
  60. #include <signal.h>
  61. #endif
  62. #ifdef __riscos__
  63. #include <unixlib/local.h>
  64. #endif
  65. #include "zend_compile.h"
  66. #include "zend_execute.h"
  67. #include "zend_highlight.h"
  68. #include "zend_indent.h"
  69. #include "php_getopt.h"
  70. #define PHP_MODE_STANDARD 1
  71. #define PHP_MODE_HIGHLIGHT 2
  72. #define PHP_MODE_INDENT 3
  73. #define PHP_MODE_LINT 4
  74. #define PHP_MODE_STRIP 5
  75. #define PHP_MODE_CLI_DIRECT 6
  76. extern char *ap_php_optarg;
  77. extern int ap_php_optind;
  78. #define OPTSTRING "aCc:d:ef:g:hilmnqr:sw?vz:"
  79. static int _print_module_info(zend_module_entry *module, void *arg TSRMLS_DC)
  80. {
  81. php_printf("%s\n", module->name);
  82. return 0;
  83. }
  84. static int _print_extension_info(zend_extension *module, void *arg TSRMLS_DC)
  85. {
  86. php_printf("%s\n", module->name);
  87. return 0;
  88. }
  89. #ifndef STDOUT_FILENO
  90. #define STDOUT_FILENO 1
  91. #endif
  92. static inline size_t sapi_cli_single_write(const char *str, uint str_length)
  93. {
  94. #ifdef PHP_WRITE_STDOUT
  95. long ret;
  96. ret = write(STDOUT_FILENO, str, str_length);
  97. if (ret <= 0) return 0;
  98. return ret;
  99. #else
  100. size_t ret;
  101. ret = fwrite(str, 1, MIN(str_length, 16384), stdout);
  102. return ret;
  103. #endif
  104. }
  105. static int sapi_cli_ub_write(const char *str, uint str_length TSRMLS_DC)
  106. {
  107. const char *ptr = str;
  108. uint remaining = str_length;
  109. size_t ret;
  110. while (remaining > 0)
  111. {
  112. ret = sapi_cli_single_write(ptr, remaining);
  113. if (!ret) {
  114. php_handle_aborted_connection();
  115. }
  116. ptr += ret;
  117. remaining -= ret;
  118. }
  119. return str_length;
  120. }
  121. static void sapi_cli_flush(void *server_context)
  122. {
  123. if (fflush(stdout)==EOF) {
  124. php_handle_aborted_connection();
  125. }
  126. }
  127. static char *php_self = "";
  128. static char *script_filename = "";
  129. static void sapi_cli_register_variables(zval *track_vars_array TSRMLS_DC)
  130. {
  131. /* In CGI mode, we consider the environment to be a part of the server
  132. * variables
  133. */
  134. php_import_environment_variables(track_vars_array TSRMLS_CC);
  135. /* Build the special-case PHP_SELF variable for the CLI version */
  136. php_register_variable("PHP_SELF", php_self, track_vars_array TSRMLS_CC);
  137. php_register_variable("SCRIPT_NAME", php_self, track_vars_array TSRMLS_CC);
  138. /* filenames are empty for stdin */
  139. php_register_variable("SCRIPT_FILENAME", script_filename, track_vars_array TSRMLS_CC);
  140. php_register_variable("PATH_TRANSLATED", script_filename, track_vars_array TSRMLS_CC);
  141. /* just make it available */
  142. php_register_variable("DOCUMENT_ROOT", "", track_vars_array TSRMLS_CC);
  143. }
  144. static void sapi_cli_log_message(char *message)
  145. {
  146. if (php_header()) {
  147. fprintf(stderr, "%s", message);
  148. fprintf(stderr, "\n");
  149. }
  150. }
  151. static int sapi_cli_deactivate(TSRMLS_D)
  152. {
  153. fflush(stdout);
  154. if(SG(request_info).argv0) {
  155. free(SG(request_info).argv0);
  156. SG(request_info).argv0 = NULL;
  157. }
  158. return SUCCESS;
  159. }
  160. static char* sapi_cli_read_cookies(TSRMLS_D)
  161. {
  162. return NULL;
  163. }
  164. static void sapi_cli_send_header(sapi_header_struct *sapi_header, void *server_context TSRMLS_DC)
  165. {
  166. if (sapi_header) {
  167. PHPWRITE_H(sapi_header->header, sapi_header->header_len);
  168. }
  169. PHPWRITE_H("\r\n", 2);
  170. }
  171. /* {{{ sapi_module_struct cli_sapi_module
  172. */
  173. static sapi_module_struct cli_sapi_module = {
  174. "cli", /* name */
  175. "Command Line Interface", /* pretty name */
  176. php_module_startup, /* startup */
  177. php_module_shutdown_wrapper, /* shutdown */
  178. NULL, /* activate */
  179. sapi_cli_deactivate, /* deactivate */
  180. sapi_cli_ub_write, /* unbuffered write */
  181. sapi_cli_flush, /* flush */
  182. NULL, /* get uid */
  183. NULL, /* getenv */
  184. php_error, /* error handler */
  185. NULL, /* header handler */
  186. NULL, /* send headers handler */
  187. sapi_cli_send_header, /* send header handler */
  188. NULL, /* read POST data */
  189. sapi_cli_read_cookies, /* read Cookies */
  190. sapi_cli_register_variables, /* register server variables */
  191. sapi_cli_log_message, /* Log message */
  192. NULL, /* Block interruptions */
  193. NULL, /* Unblock interruptions */
  194. STANDARD_SAPI_MODULE_PROPERTIES
  195. };
  196. /* }}} */
  197. /* {{{ php_cli_usage
  198. */
  199. static void php_cli_usage(char *argv0)
  200. {
  201. char *prog;
  202. prog = strrchr(argv0, '/');
  203. if (prog) {
  204. prog++;
  205. } else {
  206. prog = "php";
  207. }
  208. php_printf( "Usage: %s [options] [-f] <file> [args...]\n"
  209. " %s [options] -r <code> [args...]\n"
  210. " %s [options] [-- args...]\n"
  211. " -s Display colour syntax highlighted source.\n"
  212. " -w Display source with stripped comments and whitespace.\n"
  213. " -f <file> Parse <file>.\n"
  214. " -v Version number\n"
  215. " -c <path>|<file> Look for php.ini file in this directory\n"
  216. " -a Run interactively\n"
  217. " -d foo[=bar] Define INI entry foo with value 'bar'\n"
  218. " -e Generate extended information for debugger/profiler\n"
  219. " -z <file> Load Zend extension <file>.\n"
  220. " -l Syntax check only (lint)\n"
  221. " -m Show compiled in modules\n"
  222. " -i PHP information\n"
  223. " -r <code> Run PHP <code> without using script tags <?..?>\n"
  224. " -h This help\n"
  225. "\n"
  226. " args... Arguments passed to script. Use -- args when first argument \n"
  227. " starts with - or script is read from stdin\n"
  228. , prog, prog, prog);
  229. }
  230. /* }}} */
  231. static void define_command_line_ini_entry(char *arg)
  232. {
  233. char *name, *value;
  234. name = arg;
  235. value = strchr(arg, '=');
  236. if (value) {
  237. *value = 0;
  238. value++;
  239. } else {
  240. value = "1";
  241. }
  242. zend_alter_ini_entry(name, strlen(name)+1, value, strlen(value), PHP_INI_SYSTEM, PHP_INI_STAGE_ACTIVATE);
  243. }
  244. static void php_register_command_line_global_vars(char **arg TSRMLS_DC)
  245. {
  246. char *var, *val;
  247. var = *arg;
  248. val = strchr(var, '=');
  249. if (!val) {
  250. printf("No value specified for variable '%s'\n", var);
  251. } else {
  252. *val++ = '\0';
  253. php_register_variable(var, val, NULL TSRMLS_CC);
  254. }
  255. efree(*arg);
  256. }
  257. static void cli_register_file_handles(TSRMLS_D)
  258. {
  259. zval *zin, *zout, *zerr;
  260. php_stream *s_in, *s_out, *s_err;
  261. php_stream_context *sc_in=NULL, *sc_out=NULL, *sc_err=NULL;
  262. zend_constant ic, oc, ec;
  263. MAKE_STD_ZVAL(zin);
  264. MAKE_STD_ZVAL(zout);
  265. MAKE_STD_ZVAL(zerr);
  266. s_in = php_stream_open_wrapper_ex("php://stdin", "rb", 0, NULL, sc_in);
  267. s_out = php_stream_open_wrapper_ex("php://stdout", "wb", 0, NULL, sc_out);
  268. s_err = php_stream_open_wrapper_ex("php://stderr", "wb", 0, NULL, sc_err);
  269. if (s_in==NULL || s_out==NULL || s_err==NULL) {
  270. return;
  271. }
  272. php_stream_to_zval(s_in, zin);
  273. php_stream_to_zval(s_out, zout);
  274. php_stream_to_zval(s_err, zerr);
  275. ic.value = *zin;
  276. zval_copy_ctor(&ic.value);
  277. ic.flags = CONST_CS | CONST_PERSISTENT;
  278. ic.name = zend_strndup("STDIN", 6);
  279. ic.name_len = 6;
  280. zend_register_constant(&ic TSRMLS_CC);
  281. oc.value = *zout;
  282. zval_copy_ctor(&oc.value);
  283. oc.flags = CONST_CS | CONST_PERSISTENT;
  284. oc.name = zend_strndup("STDOUT", 7);
  285. oc.name_len = 7;
  286. zend_register_constant(&oc TSRMLS_CC);
  287. ec.value = *zerr;
  288. zval_copy_ctor(&ec.value);
  289. ec.flags = CONST_CS | CONST_PERSISTENT;
  290. ec.name = zend_strndup("STDERR", 7);
  291. ec.name_len = 7;
  292. zend_register_constant(&ec TSRMLS_CC);
  293. FREE_ZVAL(zin);
  294. FREE_ZVAL(zout);
  295. FREE_ZVAL(zerr);
  296. }
  297. /* {{{ main
  298. */
  299. int main(int argc, char *argv[])
  300. {
  301. int exit_status = SUCCESS;
  302. int c;
  303. zend_file_handle file_handle;
  304. /* temporary locals */
  305. int behavior=PHP_MODE_STANDARD;
  306. int no_headers=1;
  307. int orig_optind=ap_php_optind;
  308. char *orig_optarg=ap_php_optarg;
  309. char *arg_free=NULL, **arg_excp=&arg_free;
  310. char *script_file=NULL;
  311. zend_llist global_vars;
  312. int interactive=0;
  313. char *exec_direct=NULL;
  314. char *param_error=NULL;
  315. /* end of temporary locals */
  316. #ifdef ZTS
  317. zend_compiler_globals *compiler_globals;
  318. zend_executor_globals *executor_globals;
  319. php_core_globals *core_globals;
  320. sapi_globals_struct *sapi_globals;
  321. void ***tsrm_ls;
  322. #endif
  323. #ifdef HAVE_SIGNAL_H
  324. #if defined(SIGPIPE) && defined(SIG_IGN)
  325. signal(SIGPIPE, SIG_IGN); /* ignore SIGPIPE in standalone mode so
  326. that sockets created via fsockopen()
  327. don't kill PHP if the remote site
  328. closes it. in apache|apxs mode apache
  329. does that for us! thies@thieso.net
  330. 20000419 */
  331. #endif
  332. #endif
  333. #ifdef ZTS
  334. tsrm_startup(1, 1, 0, NULL);
  335. #endif
  336. sapi_startup(&cli_sapi_module);
  337. #ifdef PHP_WIN32
  338. _fmode = _O_BINARY; /*sets default for file streams to binary */
  339. setmode(_fileno(stdin), O_BINARY); /* make the stdio mode be binary */
  340. setmode(_fileno(stdout), O_BINARY); /* make the stdio mode be binary */
  341. setmode(_fileno(stderr), O_BINARY); /* make the stdio mode be binary */
  342. #endif
  343. while ((c=ap_php_getopt(argc, argv, OPTSTRING))!=-1) {
  344. switch (c) {
  345. case 'c':
  346. cli_sapi_module.php_ini_path_override = strdup(ap_php_optarg);
  347. break;
  348. }
  349. }
  350. ap_php_optind = orig_optind;
  351. ap_php_optarg = orig_optarg;
  352. cli_sapi_module.executable_location = argv[0];
  353. /* startup after we get the above ini override se we get things right */
  354. if (php_module_startup(&cli_sapi_module)==FAILURE) {
  355. return FAILURE;
  356. }
  357. #ifdef ZTS
  358. compiler_globals = ts_resource(compiler_globals_id);
  359. executor_globals = ts_resource(executor_globals_id);
  360. core_globals = ts_resource(core_globals_id);
  361. sapi_globals = ts_resource(sapi_globals_id);
  362. tsrm_ls = ts_resource(0);
  363. #endif
  364. zend_first_try {
  365. while ((c=ap_php_getopt(argc, argv, OPTSTRING))!=-1) {
  366. switch (c) {
  367. case '?':
  368. no_headers = 1;
  369. php_output_startup();
  370. php_output_activate(TSRMLS_C);
  371. SG(headers_sent) = 1;
  372. php_cli_usage(argv[0]);
  373. php_end_ob_buffers(1 TSRMLS_CC);
  374. exit(1);
  375. break;
  376. }
  377. }
  378. ap_php_optind = orig_optind;
  379. ap_php_optarg = orig_optarg;
  380. zend_llist_init(&global_vars, sizeof(char *), NULL, 0);
  381. /* Set some CLI defaults */
  382. SG(options) |= SAPI_OPTION_NO_CHDIR;
  383. zend_alter_ini_entry("register_argc_argv", 19, "1", 1, PHP_INI_SYSTEM, PHP_INI_STAGE_ACTIVATE);
  384. zend_alter_ini_entry("html_errors", 12, "0", 1, PHP_INI_SYSTEM, PHP_INI_STAGE_ACTIVATE);
  385. zend_alter_ini_entry("implicit_flush", 15, "1", 1, PHP_INI_SYSTEM, PHP_INI_STAGE_ACTIVATE);
  386. zend_alter_ini_entry("max_execution_time", 19, "0", 1, PHP_INI_SYSTEM, PHP_INI_STAGE_ACTIVATE);
  387. while ((c = ap_php_getopt(argc, argv, OPTSTRING)) != -1) {
  388. switch (c) {
  389. case 'a': /* interactive mode */
  390. printf("Interactive mode enabled\n\n");
  391. interactive=1;
  392. break;
  393. case 'C': /* don't chdir to the script directory */
  394. /* This is default so NOP */
  395. break;
  396. case 'd': /* define ini entries on command line */
  397. define_command_line_ini_entry(ap_php_optarg);
  398. break;
  399. case 'e': /* enable extended info output */
  400. CG(extended_info) = 1;
  401. break;
  402. case 'f': /* parse file */
  403. if (behavior == PHP_MODE_CLI_DIRECT) {
  404. param_error = "Either execute direct code or use a file.\n";
  405. break;
  406. }
  407. script_file = ap_php_optarg;
  408. no_headers = 1;
  409. break;
  410. case 'g': /* define global variables on command line */
  411. {
  412. char *arg = estrdup(ap_php_optarg);
  413. zend_llist_add_element(&global_vars, &arg);
  414. }
  415. break;
  416. case 'h': /* help & quit */
  417. case '?':
  418. no_headers = 1;
  419. php_output_startup();
  420. php_output_activate(TSRMLS_C);
  421. SG(headers_sent) = 1;
  422. php_cli_usage(argv[0]);
  423. php_end_ob_buffers(1 TSRMLS_CC);
  424. exit(1);
  425. break;
  426. case 'i': /* php info & quit */
  427. if (php_request_startup(TSRMLS_C)==FAILURE) {
  428. php_module_shutdown(TSRMLS_C);
  429. return FAILURE;
  430. }
  431. if (no_headers) {
  432. SG(headers_sent) = 1;
  433. SG(request_info).no_headers = 1;
  434. }
  435. php_print_info(0xFFFFFFFF TSRMLS_CC);
  436. php_end_ob_buffers(1 TSRMLS_CC);
  437. exit(1);
  438. break;
  439. case 'l': /* syntax check mode */
  440. if (behavior != PHP_MODE_STANDARD)
  441. break;
  442. no_headers = 1;
  443. behavior=PHP_MODE_LINT;
  444. break;
  445. case 'm': /* list compiled in modules */
  446. php_output_startup();
  447. php_output_activate(TSRMLS_C);
  448. SG(headers_sent) = 1;
  449. php_printf("[PHP Modules]\n");
  450. zend_hash_apply_with_argument(&module_registry, (apply_func_arg_t) _print_module_info, NULL TSRMLS_CC);
  451. php_printf("\n[Zend Modules]\n");
  452. zend_llist_apply_with_argument(&zend_extensions, (llist_apply_with_arg_func_t) _print_extension_info, NULL TSRMLS_CC);
  453. php_printf("\n");
  454. php_end_ob_buffers(1 TSRMLS_CC);
  455. exit(1);
  456. break;
  457. #if 0 /* not yet operational, see also below ... */
  458. case 'n': /* generate indented source mode*/
  459. if (behavior == PHP_MODE_CLI_DIRECT) {
  460. param_error = "Source indenting only works for files.\n";
  461. break;
  462. }
  463. behavior=PHP_MODE_INDENT;
  464. break;
  465. #endif
  466. case 'q': /* do not generate HTTP headers */
  467. /* This is default so NOP */
  468. break;
  469. case 'r': /* run code from command line */
  470. if (behavior != PHP_MODE_STANDARD) {
  471. param_error = "Either execute direct code or use a file.\n";
  472. break;
  473. }
  474. behavior=PHP_MODE_CLI_DIRECT;
  475. exec_direct=ap_php_optarg;
  476. break;
  477. case 's': /* generate highlighted HTML from source */
  478. if (behavior == PHP_MODE_CLI_DIRECT) {
  479. param_error = "Source highlighting only works for files.\n";
  480. break;
  481. }
  482. behavior=PHP_MODE_HIGHLIGHT;
  483. break;
  484. case 'v': /* show php version & quit */
  485. no_headers = 1;
  486. if (php_request_startup(TSRMLS_C)==FAILURE) {
  487. php_module_shutdown(TSRMLS_C);
  488. return FAILURE;
  489. }
  490. if (no_headers) {
  491. SG(headers_sent) = 1;
  492. SG(request_info).no_headers = 1;
  493. }
  494. php_printf("PHP %s (%s), Copyright (c) 1997-2002 The PHP Group\n%s", PHP_VERSION, sapi_module.name, get_zend_version());
  495. php_end_ob_buffers(1 TSRMLS_CC);
  496. exit(1);
  497. break;
  498. case 'w':
  499. if (behavior == PHP_MODE_CLI_DIRECT) {
  500. param_error = "Source stripping only works for files.\n";
  501. break;
  502. }
  503. behavior=PHP_MODE_STRIP;
  504. break;
  505. case 'z': /* load extension file */
  506. zend_load_extension(ap_php_optarg);
  507. break;
  508. default:
  509. break;
  510. }
  511. }
  512. if (param_error) {
  513. SG(headers_sent) = 1;
  514. SG(request_info).no_headers = 1;
  515. PUTS(param_error);
  516. exit(1);
  517. }
  518. CG(interactive) = interactive;
  519. /* only set script_file if not set already and not in direct mode and not at end of parameter list */
  520. if (argc > ap_php_optind && !script_file && behavior!=PHP_MODE_CLI_DIRECT && strcmp(argv[ap_php_optind-1],"--")) {
  521. no_headers = 1;
  522. script_file=argv[ap_php_optind];
  523. ap_php_optind++;
  524. }
  525. if (script_file) {
  526. if (!(file_handle.handle.fp = VCWD_FOPEN(script_file, "rb"))) {
  527. SG(headers_sent) = 1;
  528. SG(request_info).no_headers = 1;
  529. PUTS("Could not open input file.\n");
  530. return FAILURE;
  531. }
  532. file_handle.filename = script_file;
  533. script_filename = script_file;
  534. /* #!php support */
  535. c = fgetc(file_handle.handle.fp);
  536. if (c == '#') {
  537. while (c != 10 && c != 13) {
  538. c = fgetc(file_handle.handle.fp); /* skip to end of line */
  539. }
  540. CG(zend_lineno)++;
  541. } else {
  542. rewind(file_handle.handle.fp);
  543. }
  544. } else {
  545. file_handle.filename = "-";
  546. file_handle.handle.fp = stdin;
  547. }
  548. file_handle.type = ZEND_HANDLE_FP;
  549. file_handle.opened_path = NULL;
  550. file_handle.free_filename = 0;
  551. php_self = file_handle.filename;
  552. /* before registering argv to modulule exchange the *new* argv[0] */
  553. /* we can achieve this without allocating more memory */
  554. SG(request_info).argc=argc-ap_php_optind+1;
  555. arg_excp = argv+ap_php_optind-1;
  556. arg_free = argv[ap_php_optind-1];
  557. SG(request_info).path_translated = file_handle.filename;
  558. argv[ap_php_optind-1] = file_handle.filename;
  559. SG(request_info).argv=argv+ap_php_optind-1;
  560. if (php_request_startup(TSRMLS_C)==FAILURE) {
  561. *arg_excp = arg_free;
  562. fclose(file_handle.handle.fp);
  563. SG(headers_sent) = 1;
  564. SG(request_info).no_headers = 1;
  565. php_request_shutdown((void *) 0);
  566. php_module_shutdown(TSRMLS_C);
  567. PUTS("Could not startup.\n");
  568. return FAILURE;
  569. }
  570. *arg_excp = arg_free; /* reconstuct argv */
  571. if (no_headers) {
  572. SG(headers_sent) = 1;
  573. SG(request_info).no_headers = 1;
  574. }
  575. /* This actually destructs the elements of the list - ugly hack */
  576. zend_llist_apply(&global_vars, (llist_apply_func_t) php_register_command_line_global_vars TSRMLS_CC);
  577. zend_llist_destroy(&global_vars);
  578. switch (behavior) {
  579. case PHP_MODE_STANDARD:
  580. if (strcmp(file_handle.filename, "-")) {
  581. cli_register_file_handles(TSRMLS_C);
  582. }
  583. php_execute_script(&file_handle TSRMLS_CC);
  584. exit_status = EG(exit_status);
  585. break;
  586. case PHP_MODE_LINT:
  587. PG(during_request_startup) = 0;
  588. exit_status = php_lint_script(&file_handle TSRMLS_CC);
  589. if (exit_status==SUCCESS) {
  590. zend_printf("No syntax errors detected in %s\n", file_handle.filename);
  591. } else {
  592. zend_printf("Errors parsing %s\n", file_handle.filename);
  593. }
  594. break;
  595. case PHP_MODE_STRIP:
  596. if (open_file_for_scanning(&file_handle TSRMLS_CC)==SUCCESS) {
  597. zend_strip(TSRMLS_C);
  598. fclose(file_handle.handle.fp);
  599. }
  600. return SUCCESS;
  601. break;
  602. case PHP_MODE_HIGHLIGHT:
  603. {
  604. zend_syntax_highlighter_ini syntax_highlighter_ini;
  605. if (open_file_for_scanning(&file_handle TSRMLS_CC)==SUCCESS) {
  606. php_get_highlight_struct(&syntax_highlighter_ini);
  607. zend_highlight(&syntax_highlighter_ini TSRMLS_CC);
  608. fclose(file_handle.handle.fp);
  609. }
  610. return SUCCESS;
  611. }
  612. break;
  613. #if 0
  614. /* Zeev might want to do something with this one day */
  615. case PHP_MODE_INDENT:
  616. open_file_for_scanning(&file_handle TSRMLS_CC);
  617. zend_indent();
  618. fclose(file_handle.handle.fp);
  619. return SUCCESS;
  620. break;
  621. #endif
  622. case PHP_MODE_CLI_DIRECT:
  623. cli_register_file_handles(TSRMLS_C);
  624. if (zend_eval_string(exec_direct, NULL, "Command line code" TSRMLS_CC) == FAILURE) {
  625. exit_status=254;
  626. }
  627. break;
  628. }
  629. php_request_shutdown((void *) 0);
  630. if (cli_sapi_module.php_ini_path_override) {
  631. free(cli_sapi_module.php_ini_path_override);
  632. }
  633. } zend_catch {
  634. exit_status = EG(exit_status);
  635. } zend_end_try();
  636. php_module_shutdown(TSRMLS_C);
  637. #ifdef ZTS
  638. tsrm_shutdown();
  639. #endif
  640. return exit_status;
  641. }
  642. /* }}} */
  643. /*
  644. * Local variables:
  645. * tab-width: 4
  646. * c-basic-offset: 4
  647. * End:
  648. * vim600: sw=4 ts=4 fdm=marker
  649. * vim<600: sw=4 ts=4
  650. */