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.

778 lines
20 KiB

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