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.

770 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. 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. " -s Display colour syntax highlighted source.\n"
  219. " -w Display source with stripped comments and whitespace.\n"
  220. " -f <file> Parse <file>.\n"
  221. " -v Version number\n"
  222. " -c <path>|<file> Look for php.ini file in this directory\n"
  223. " -a Run interactively\n"
  224. " -d foo[=bar] Define INI entry foo with value 'bar'\n"
  225. " -e Generate extended information for debugger/profiler\n"
  226. " -z <file> Load Zend extension <file>.\n"
  227. " -l Syntax check only (lint)\n"
  228. " -m Show compiled in modules\n"
  229. " -i PHP information\n"
  230. " -r <code> Run PHP <code> without using script tags <?..?>\n"
  231. " -h This help\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. char *exec_direct=NULL;
  321. char *param_error=NULL;
  322. /* end of temporary locals */
  323. #ifdef ZTS
  324. zend_compiler_globals *compiler_globals;
  325. zend_executor_globals *executor_globals;
  326. php_core_globals *core_globals;
  327. sapi_globals_struct *sapi_globals;
  328. void ***tsrm_ls;
  329. #endif
  330. #ifdef HAVE_SIGNAL_H
  331. #if defined(SIGPIPE) && defined(SIG_IGN)
  332. signal(SIGPIPE, SIG_IGN); /* ignore SIGPIPE in standalone mode so
  333. that sockets created via fsockopen()
  334. don't kill PHP if the remote site
  335. closes it. in apache|apxs mode apache
  336. does that for us! thies@thieso.net
  337. 20000419 */
  338. #endif
  339. #endif
  340. #ifdef ZTS
  341. tsrm_startup(1, 1, 0, NULL);
  342. #endif
  343. sapi_startup(&cli_sapi_module);
  344. #ifdef PHP_WIN32
  345. _fmode = _O_BINARY; /*sets default for file streams to binary */
  346. setmode(_fileno(stdin), O_BINARY); /* make the stdio mode be binary */
  347. setmode(_fileno(stdout), O_BINARY); /* make the stdio mode be binary */
  348. setmode(_fileno(stderr), O_BINARY); /* make the stdio mode be binary */
  349. #endif
  350. while ((c=ap_php_getopt(argc, argv, OPTSTRING))!=-1) {
  351. switch (c) {
  352. case 'c':
  353. cli_sapi_module.php_ini_path_override = strdup(ap_php_optarg);
  354. break;
  355. }
  356. }
  357. ap_php_optind = orig_optind;
  358. ap_php_optarg = orig_optarg;
  359. cli_sapi_module.executable_location = argv[0];
  360. /* startup after we get the above ini override se we get things right */
  361. if (php_module_startup(&cli_sapi_module, NULL, 0)==FAILURE) {
  362. return FAILURE;
  363. }
  364. #ifdef ZTS
  365. compiler_globals = ts_resource(compiler_globals_id);
  366. executor_globals = ts_resource(executor_globals_id);
  367. core_globals = ts_resource(core_globals_id);
  368. sapi_globals = ts_resource(sapi_globals_id);
  369. tsrm_ls = ts_resource(0);
  370. #endif
  371. zend_first_try {
  372. while ((c=ap_php_getopt(argc, argv, OPTSTRING))!=-1) {
  373. switch (c) {
  374. case '?':
  375. no_headers = 1;
  376. php_output_startup();
  377. php_output_activate(TSRMLS_C);
  378. SG(headers_sent) = 1;
  379. php_cli_usage(argv[0]);
  380. php_end_ob_buffers(1 TSRMLS_CC);
  381. exit(1);
  382. break;
  383. }
  384. }
  385. ap_php_optind = orig_optind;
  386. ap_php_optarg = orig_optarg;
  387. zend_llist_init(&global_vars, sizeof(char *), NULL, 0);
  388. /* Set some CLI defaults */
  389. SG(options) |= SAPI_OPTION_NO_CHDIR;
  390. zend_alter_ini_entry("register_argc_argv", 19, "1", 1, PHP_INI_SYSTEM, PHP_INI_STAGE_ACTIVATE);
  391. zend_alter_ini_entry("html_errors", 12, "0", 1, PHP_INI_SYSTEM, PHP_INI_STAGE_ACTIVATE);
  392. zend_alter_ini_entry("implicit_flush", 15, "1", 1, PHP_INI_SYSTEM, PHP_INI_STAGE_ACTIVATE);
  393. zend_alter_ini_entry("max_execution_time", 19, "0", 1, PHP_INI_SYSTEM, PHP_INI_STAGE_ACTIVATE);
  394. zend_uv.html_errors = 0; /* tell the engine we're in non-html mode */
  395. while ((c = ap_php_getopt(argc, argv, OPTSTRING)) != -1) {
  396. switch (c) {
  397. case 'a': /* interactive mode */
  398. printf("Interactive mode enabled\n\n");
  399. interactive=1;
  400. break;
  401. case 'C': /* don't chdir to the script directory */
  402. /* This is default so NOP */
  403. break;
  404. case 'd': /* define ini entries on command line */
  405. define_command_line_ini_entry(ap_php_optarg);
  406. break;
  407. case 'e': /* enable extended info output */
  408. CG(extended_info) = 1;
  409. break;
  410. case 'f': /* parse file */
  411. if (behavior == PHP_MODE_CLI_DIRECT) {
  412. param_error = "Either execute direct code or use a file.\n";
  413. break;
  414. }
  415. script_file = ap_php_optarg;
  416. no_headers = 1;
  417. break;
  418. case 'g': /* define global variables on command line */
  419. {
  420. char *arg = estrdup(ap_php_optarg);
  421. zend_llist_add_element(&global_vars, &arg);
  422. }
  423. break;
  424. case 'h': /* help & quit */
  425. case '?':
  426. no_headers = 1;
  427. php_output_startup();
  428. php_output_activate(TSRMLS_C);
  429. SG(headers_sent) = 1;
  430. php_cli_usage(argv[0]);
  431. php_end_ob_buffers(1 TSRMLS_CC);
  432. exit(1);
  433. break;
  434. case 'i': /* php info & quit */
  435. if (php_request_startup(TSRMLS_C)==FAILURE) {
  436. php_module_shutdown(TSRMLS_C);
  437. return FAILURE;
  438. }
  439. if (no_headers) {
  440. SG(headers_sent) = 1;
  441. SG(request_info).no_headers = 1;
  442. }
  443. php_print_info(0xFFFFFFFF TSRMLS_CC);
  444. php_end_ob_buffers(1 TSRMLS_CC);
  445. exit(1);
  446. break;
  447. case 'l': /* syntax check mode */
  448. if (behavior != PHP_MODE_STANDARD)
  449. break;
  450. no_headers = 1;
  451. behavior=PHP_MODE_LINT;
  452. break;
  453. case 'm': /* list compiled in modules */
  454. php_output_startup();
  455. php_output_activate(TSRMLS_C);
  456. SG(headers_sent) = 1;
  457. php_printf("[PHP Modules]\n");
  458. zend_hash_apply_with_argument(&module_registry, (apply_func_arg_t) _print_module_info, NULL TSRMLS_CC);
  459. php_printf("\n[Zend Modules]\n");
  460. zend_llist_apply_with_argument(&zend_extensions, (llist_apply_with_arg_func_t) _print_extension_info, NULL TSRMLS_CC);
  461. php_printf("\n");
  462. php_end_ob_buffers(1 TSRMLS_CC);
  463. exit(1);
  464. break;
  465. #if 0 /* not yet operational, see also below ... */
  466. case 'n': /* generate indented source mode*/
  467. if (behavior == PHP_MODE_CLI_DIRECT) {
  468. param_error = "Source indenting only works for files.\n";
  469. break;
  470. }
  471. behavior=PHP_MODE_INDENT;
  472. break;
  473. #endif
  474. case 'q': /* do not generate HTTP headers */
  475. /* This is default so NOP */
  476. break;
  477. case 'r': /* run code from command line */
  478. if (behavior != PHP_MODE_STANDARD) {
  479. param_error = "Either execute direct code or use a file.\n";
  480. break;
  481. }
  482. behavior=PHP_MODE_CLI_DIRECT;
  483. exec_direct=ap_php_optarg;
  484. break;
  485. case 's': /* generate highlighted HTML from source */
  486. if (behavior == PHP_MODE_CLI_DIRECT) {
  487. param_error = "Source highlighting only works for files.\n";
  488. break;
  489. }
  490. behavior=PHP_MODE_HIGHLIGHT;
  491. break;
  492. case 'v': /* show php version & quit */
  493. no_headers = 1;
  494. if (php_request_startup(TSRMLS_C)==FAILURE) {
  495. php_module_shutdown(TSRMLS_C);
  496. return FAILURE;
  497. }
  498. if (no_headers) {
  499. SG(headers_sent) = 1;
  500. SG(request_info).no_headers = 1;
  501. }
  502. php_printf("PHP %s (%s), Copyright (c) 1997-2002 The PHP Group\n%s", PHP_VERSION, sapi_module.name, get_zend_version());
  503. php_end_ob_buffers(1 TSRMLS_CC);
  504. exit(1);
  505. break;
  506. case 'w':
  507. if (behavior == PHP_MODE_CLI_DIRECT) {
  508. param_error = "Source stripping only works for files.\n";
  509. break;
  510. }
  511. behavior=PHP_MODE_STRIP;
  512. break;
  513. case 'z': /* load extension file */
  514. zend_load_extension(ap_php_optarg);
  515. break;
  516. default:
  517. break;
  518. }
  519. }
  520. if (param_error) {
  521. SG(headers_sent) = 1;
  522. SG(request_info).no_headers = 1;
  523. PUTS(param_error);
  524. exit(1);
  525. }
  526. CG(interactive) = interactive;
  527. /* only set script_file if not set already and not in direct mode and not at end of parameter list */
  528. if (argc > ap_php_optind && !script_file && behavior!=PHP_MODE_CLI_DIRECT && strcmp(argv[ap_php_optind-1],"--")) {
  529. no_headers = 1;
  530. script_file=argv[ap_php_optind];
  531. ap_php_optind++;
  532. }
  533. if (script_file) {
  534. if (!(file_handle.handle.fp = VCWD_FOPEN(script_file, "rb"))) {
  535. SG(headers_sent) = 1;
  536. SG(request_info).no_headers = 1;
  537. PUTS("Could not open input file.\n");
  538. return FAILURE;
  539. }
  540. file_handle.filename = script_file;
  541. script_filename = script_file;
  542. /* #!php support */
  543. c = fgetc(file_handle.handle.fp);
  544. if (c == '#') {
  545. while (c != 10 && c != 13) {
  546. c = fgetc(file_handle.handle.fp); /* skip to end of line */
  547. }
  548. CG(zend_lineno)++;
  549. } else {
  550. rewind(file_handle.handle.fp);
  551. }
  552. } else {
  553. file_handle.filename = "-";
  554. file_handle.handle.fp = stdin;
  555. }
  556. file_handle.type = ZEND_HANDLE_FP;
  557. file_handle.opened_path = NULL;
  558. file_handle.free_filename = 0;
  559. php_self = file_handle.filename;
  560. /* before registering argv to modulule exchange the *new* argv[0] */
  561. /* we can achieve this without allocating more memory */
  562. SG(request_info).argc=argc-ap_php_optind+1;
  563. arg_excp = argv+ap_php_optind-1;
  564. arg_free = argv[ap_php_optind-1];
  565. SG(request_info).path_translated = file_handle.filename;
  566. argv[ap_php_optind-1] = file_handle.filename;
  567. SG(request_info).argv=argv+ap_php_optind-1;
  568. if (php_request_startup(TSRMLS_C)==FAILURE) {
  569. *arg_excp = arg_free;
  570. fclose(file_handle.handle.fp);
  571. SG(headers_sent) = 1;
  572. SG(request_info).no_headers = 1;
  573. php_request_shutdown((void *) 0);
  574. php_module_shutdown(TSRMLS_C);
  575. PUTS("Could not startup.\n");
  576. return FAILURE;
  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. return SUCCESS;
  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. return SUCCESS;
  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. return SUCCESS;
  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. php_request_shutdown((void *) 0);
  638. if (cli_sapi_module.php_ini_path_override) {
  639. free(cli_sapi_module.php_ini_path_override);
  640. }
  641. } zend_catch {
  642. exit_status = EG(exit_status);
  643. } zend_end_try();
  644. php_module_shutdown(TSRMLS_C);
  645. #ifdef ZTS
  646. tsrm_shutdown();
  647. #endif
  648. return exit_status;
  649. }
  650. /* }}} */
  651. /*
  652. * Local variables:
  653. * tab-width: 4
  654. * c-basic-offset: 4
  655. * End:
  656. * vim600: sw=4 ts=4 fdm=marker
  657. * vim<600: sw=4 ts=4
  658. */