⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 php_cli.c

📁 php-4.4.7学习linux时下载的源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
	ec.name_len = sizeof("STDERR");	ec.module_number = 0;	zend_register_constant(&ec TSRMLS_CC);	FREE_ZVAL(zin);	FREE_ZVAL(zout);	FREE_ZVAL(zerr);}/* {{{ cli_seek_file_begin */static int cli_seek_file_begin(zend_file_handle *file_handle, char *script_file, int *lineno TSRMLS_DC){	int c;	*lineno = 1;	if (!(file_handle->handle.fp = VCWD_FOPEN(script_file, "rb"))) {		php_printf("Could not open input file: %s\n", script_file);		return FAILURE;	}	file_handle->filename = script_file;	/* #!php support */	c = fgetc(file_handle->handle.fp);	if (c == '#') {		while (c != 10 && c != 13) {			c = fgetc(file_handle->handle.fp);	/* skip to end of line */		}		/* handle situations where line is terminated by \r\n */		if (c == 13) {			if (fgetc(file_handle->handle.fp) != 10) {				long pos = ftell(file_handle->handle.fp);				fseek(file_handle->handle.fp, pos - 1, SEEK_SET);			}		}		*lineno = -2;	} else {		rewind(file_handle->handle.fp);	}	return SUCCESS;}/* }}} *//* {{{ main */int main(int argc, char *argv[]){	int exit_status = SUCCESS;	int c;	zend_file_handle file_handle;/* temporary locals */	int behavior=PHP_MODE_STANDARD;	int orig_optind=php_optind;	char *orig_optarg=php_optarg;	char *arg_free=NULL, **arg_excp=&arg_free;	char *script_file=NULL;	zend_llist global_vars;	int interactive=0;	int module_started = 0;	int lineno = 0;	char *exec_direct=NULL;	char *param_error=NULL;	int hide_argv = 0;/* end of temporary locals */#ifdef ZTS	zend_compiler_globals *compiler_globals;	zend_executor_globals *executor_globals;	php_core_globals *core_globals;	sapi_globals_struct *sapi_globals;	void ***tsrm_ls;#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);#endif	cli_sapi_module.ini_defaults = sapi_cli_ini_defaults;	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	while ((c = php_getopt(argc, argv, OPTIONS, &php_optarg, &php_optind, 0))!=-1) {		switch (c) {		case 'c':			cli_sapi_module.php_ini_path_override = strdup(php_optarg);			break;		case 'n':			cli_sapi_module.php_ini_ignore = 1;			break;		}	}	php_optind = orig_optind;	php_optarg = orig_optarg;	cli_sapi_module.executable_location = argv[0];#ifdef ZTS	compiler_globals = ts_resource(compiler_globals_id);	executor_globals = ts_resource(executor_globals_id);	core_globals = ts_resource(core_globals_id);	sapi_globals = ts_resource(sapi_globals_id);	tsrm_ls = ts_resource(0);#endif	/* startup after we get the above ini override se we get things right */	if (php_module_startup(&cli_sapi_module, NULL, 0)==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_llist_init(&global_vars, sizeof(char *), NULL, 0);		zend_uv.html_errors = 0; /* tell the engine we're in non-html mode */		CG(in_compilation) = 0; /* not initialized but needed for several options */		EG(uninitialized_zval_ptr) = NULL;		if (cli_sapi_module.php_ini_path_override && cli_sapi_module.php_ini_ignore) {			PUTS("You cannot use both -n and -c switch. Use -h for help.\n");			exit_status=1;			goto out_err;		}		/* here is the place for hard coded defaults which cannot be overwritten in the ini file */		INI_HARDCODED("register_argc_argv", "1");		INI_HARDCODED("html_errors", "0");		INI_HARDCODED("implicit_flush", "1");		INI_HARDCODED("output_buffering", "0");		INI_HARDCODED("max_execution_time", "0");		while ((c = php_getopt(argc, argv, OPTIONS, &php_optarg, &php_optind, 0)) != -1) {			switch (c) {			case 'd': /* define ini entries on command line */				define_command_line_ini_entry(php_optarg);				break;			case 'h': /* help & quit */			case '?':				if (php_request_startup(TSRMLS_C)==FAILURE) {					goto err;				}				php_output_startup();				php_cli_usage(argv[0]);				php_end_ob_buffers(1 TSRMLS_CC);				exit_status=0;				goto out;			case 'i': /* php info & quit */				if (php_request_startup(TSRMLS_C)==FAILURE) {					goto err;				}				php_print_info(0xFFFFFFFF TSRMLS_CC);				php_end_ob_buffers(1 TSRMLS_CC);				exit_status=0;				goto out;			case 'm': /* list compiled in modules */				if (php_request_startup(TSRMLS_C)==FAILURE) {					goto err;				}				php_output_startup();				php_printf("[PHP Modules]\n");				print_modules(TSRMLS_C);				php_printf("\n[Zend Modules]\n");				print_extensions(TSRMLS_C);				php_printf("\n");				php_end_ob_buffers(1 TSRMLS_CC);				exit_status=0;				goto out;			case 'v': /* show php version & quit */				if (php_request_startup(TSRMLS_C)==FAILURE) {					goto err;				}#if ZEND_DEBUG				php_printf("PHP %s (%s) (built: %s %s) (DEBUG)\nCopyright (c) 1997-2007 The PHP Group\n%s", PHP_VERSION, sapi_module.name, __DATE__, __TIME__, get_zend_version());#else				php_printf("PHP %s (%s) (built: %s %s)\nCopyright (c) 1997-2007 The PHP Group\n%s", PHP_VERSION, sapi_module.name, __DATE__, __TIME__, get_zend_version());#endif				php_end_ob_buffers(1 TSRMLS_CC);				exit_status=0;				goto out;			default:				break;			}		}        /* Set some CLI defaults */		SG(options) |= SAPI_OPTION_NO_CHDIR;		php_optind = orig_optind;		php_optarg = orig_optarg;		while ((c = php_getopt(argc, argv, OPTIONS, &php_optarg, &php_optind, 0)) != -1) {			switch (c) {			case 'a':	/* interactive mode */				printf("Interactive mode enabled\n\n");				interactive=1;				break;			case 'C': /* don't chdir to the script directory */				/* This is default so NOP */				break;			case 'e': /* enable extended info output */				CG(extended_info) = 1;				break;			case 'f': /* parse file */				if (behavior == PHP_MODE_CLI_DIRECT) {					param_error = "Either execute direct code or use a file.\n";					break;				}				script_file = php_optarg;				break;			case 'g': /* define global variables on command line */				{					char *arg = estrdup(php_optarg);					zend_llist_add_element(&global_vars, &arg);				}				break;			case 'l': /* syntax check mode */				if (behavior != PHP_MODE_STANDARD) {					break;				}				behavior=PHP_MODE_LINT;				break;#if 0 /* not yet operational, see also below ... */			case '': /* generate indented source mode*/				if (behavior == PHP_MODE_CLI_DIRECT) {					param_error = "Source indenting only works for files.\n";					break;				}				behavior=PHP_MODE_INDENT;				break;#endif			case 'q': /* do not generate HTTP headers */				/* This is default so NOP */				break;			case 'r': /* run code from command line */				if (behavior != PHP_MODE_STANDARD) {					param_error = "Either execute direct code or use a file.\n";					break;				}				behavior=PHP_MODE_CLI_DIRECT;				exec_direct=php_optarg;				break;			case 's': /* generate highlighted HTML from source */				if (behavior == PHP_MODE_CLI_DIRECT) {					param_error = "Source highlighting only works for files.\n";					break;				}				behavior=PHP_MODE_HIGHLIGHT;				break;			case 'w':				if (behavior == PHP_MODE_CLI_DIRECT) {					param_error = "Source stripping only works for files.\n";					break;				}				behavior=PHP_MODE_STRIP;				break;			case 'z': /* load extension file */				zend_load_extension(php_optarg);				break;			case 'H':				hide_argv = 1;				break;			default:				break;			}		}		if (param_error) {			PUTS(param_error);			exit_status=1;			goto out_err;		}		CG(interactive) = interactive;		/* only set script_file if not set already and not in direct mode and not at end of parameter list */		if (argc > php_optind && !script_file && behavior!=PHP_MODE_CLI_DIRECT && strcmp(argv[php_optind-1],"--")) {			script_file=argv[php_optind];			php_optind++;		}		if (script_file) {			if (cli_seek_file_begin(&file_handle, script_file, &lineno TSRMLS_CC) != SUCCESS) {				goto err;			}			file_handle.filename = script_file;			script_filename = script_file;		} else {			file_handle.filename = "-";			file_handle.handle.fp = stdin;		}		file_handle.type = ZEND_HANDLE_FP;		file_handle.opened_path = NULL;		file_handle.free_filename = 0;		php_self = file_handle.filename;		/* before registering argv to module exchange the *new* argv[0] */		/* we can achieve this without allocating more memory */		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 = file_handle.filename;		argv[php_optind-1] = file_handle.filename;		SG(request_info).argv=argv+php_optind-1;		if (php_request_startup(TSRMLS_C)==FAILURE) {			*arg_excp = arg_free;			fclose(file_handle.handle.fp);			php_request_shutdown((void *) 0);			PUTS("Could not startup.\n");			goto err;		}		CG(zend_lineno) = lineno;		*arg_excp = arg_free; /* reconstuct argv */		if (hide_argv) {			int i;			for (i = 1; i < argc; i++) {				memset(argv[i], 0, strlen(argv[i]));			}		}		/* This actually destructs the elements of the list - ugly hack */		zend_llist_apply(&global_vars, (llist_apply_func_t) php_register_command_line_global_vars TSRMLS_CC);		zend_llist_destroy(&global_vars);		PG(during_request_startup) = 0;		switch (behavior) {		case PHP_MODE_STANDARD:			if (strcmp(file_handle.filename, "-")) {				cli_register_file_handles(TSRMLS_C);			}			php_execute_script(&file_handle TSRMLS_CC);			exit_status = EG(exit_status);			break;		case PHP_MODE_LINT:			exit_status = php_lint_script(&file_handle TSRMLS_CC);			if (exit_status==SUCCESS) {				zend_printf("No syntax errors detected in %s\n", file_handle.filename);			} else {				zend_printf("Errors parsing %s\n", file_handle.filename);			}			break;		case PHP_MODE_STRIP:			if (open_file_for_scanning(&file_handle TSRMLS_CC)==SUCCESS) {				zend_strip(TSRMLS_C);			}			goto out;			break;		case PHP_MODE_HIGHLIGHT:			{				zend_syntax_highlighter_ini syntax_highlighter_ini;				if (open_file_for_scanning(&file_handle TSRMLS_CC)==SUCCESS) {					php_get_highlight_struct(&syntax_highlighter_ini);					zend_highlight(&syntax_highlighter_ini TSRMLS_CC);				}				goto out;			}			break;#if 0			/* Zeev might want to do something with this one day */		case PHP_MODE_INDENT:			open_file_for_scanning(&file_handle TSRMLS_CC);			zend_indent();			fclose(file_handle.handle.fp);			goto out;			break;#endif		case PHP_MODE_CLI_DIRECT:			cli_register_file_handles(TSRMLS_C);			if (zend_eval_string(exec_direct, NULL, "Command line code" TSRMLS_CC) == FAILURE) {				exit_status=254;			}			break;		}		if (cli_sapi_module.php_ini_path_override) {			free(cli_sapi_module.php_ini_path_override);		}	} zend_end_try();out:	php_request_shutdown((void *) 0);	if (exit_status == 0) {		exit_status = EG(exit_status);	}out_err:		if (module_started) {		php_module_shutdown(TSRMLS_C);	}	sapi_shutdown();#ifdef ZTS	tsrm_shutdown();#endif	exit(exit_status);err:	zend_ini_deactivate(TSRMLS_C);	exit_status = 1;	goto out_err;}/* }}} *//* * Local variables: * tab-width: 4 * c-basic-offset: 4 * End: * vim600: sw=4 ts=4 fdm=marker * vim<600: sw=4 ts=4 */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -