mirror of
https://github.com/php/php-src.git
synced 2025-08-16 05:58:45 +02:00
Move shebang handling into the lexer
Instead of handling shebang lines by adjusting the file pointer in individual SAPIs, move the handling into the lexer, where this is both a lot simpler and more robust. Whether the shebang should be skipped is controlled by CG(skip_shebang) -- we might want to do that in more cases. This fixed bugs #60677 and #78066.
This commit is contained in:
parent
17d4e86dda
commit
c5f1b384b5
9 changed files with 48 additions and 170 deletions
|
@ -587,12 +587,9 @@ static const char *param_mode_conflict = "Either execute direct code, process st
|
|||
|
||||
/* {{{ cli_seek_file_begin
|
||||
*/
|
||||
static int cli_seek_file_begin(zend_file_handle *file_handle, char *script_file, int *lineno)
|
||||
static int cli_seek_file_begin(zend_file_handle *file_handle, char *script_file)
|
||||
{
|
||||
int c;
|
||||
|
||||
*lineno = 1;
|
||||
|
||||
// TODO: Is this still needed?
|
||||
file_handle->type = ZEND_HANDLE_FP;
|
||||
file_handle->opened_path = NULL;
|
||||
file_handle->free_filename = 0;
|
||||
|
@ -602,23 +599,7 @@ static int cli_seek_file_begin(zend_file_handle *file_handle, char *script_file,
|
|||
}
|
||||
file_handle->filename = script_file;
|
||||
|
||||
/* #!php support */
|
||||
c = fgetc(file_handle->handle.fp);
|
||||
if (c == '#' && (c = fgetc(file_handle->handle.fp)) == '!') {
|
||||
while (c != '\n' && c != '\r' && c != EOF) {
|
||||
c = fgetc(file_handle->handle.fp); /* skip to end of line */
|
||||
}
|
||||
/* handle situations where line is terminated by \r\n */
|
||||
if (c == '\r') {
|
||||
if (fgetc(file_handle->handle.fp) != '\n') {
|
||||
zend_long pos = zend_ftell(file_handle->handle.fp);
|
||||
zend_fseek(file_handle->handle.fp, pos - 1, SEEK_SET);
|
||||
}
|
||||
}
|
||||
*lineno = 2;
|
||||
} else {
|
||||
rewind(file_handle->handle.fp);
|
||||
}
|
||||
rewind(file_handle->handle.fp);
|
||||
|
||||
return SUCCESS;
|
||||
}
|
||||
|
@ -649,7 +630,6 @@ static int do_cli(int argc, char **argv) /* {{{ */
|
|||
char *arg_free=NULL, **arg_excp=&arg_free;
|
||||
char *script_file=NULL, *translated_path = NULL;
|
||||
int interactive=0;
|
||||
int lineno = 0;
|
||||
const char *param_error=NULL;
|
||||
int hide_argv = 0;
|
||||
|
||||
|
@ -922,7 +902,7 @@ static int do_cli(int argc, char **argv) /* {{{ */
|
|||
php_optind++;
|
||||
}
|
||||
if (script_file) {
|
||||
if (cli_seek_file_begin(&file_handle, script_file, &lineno) != SUCCESS) {
|
||||
if (cli_seek_file_begin(&file_handle, script_file) != SUCCESS) {
|
||||
goto err;
|
||||
} else {
|
||||
char real_path[MAXPATHLEN];
|
||||
|
@ -960,7 +940,7 @@ static int do_cli(int argc, char **argv) /* {{{ */
|
|||
goto err;
|
||||
}
|
||||
request_started = 1;
|
||||
CG(start_lineno) = lineno;
|
||||
CG(skip_shebang) = 1;
|
||||
|
||||
zend_register_bool_constant(
|
||||
ZEND_STRL("PHP_CLI_PROCESS_TITLE"),
|
||||
|
@ -1050,10 +1030,10 @@ static int do_cli(int argc, char **argv) /* {{{ */
|
|||
}
|
||||
} else {
|
||||
if (script_file) {
|
||||
if (cli_seek_file_begin(&file_handle, script_file, &lineno) != SUCCESS) {
|
||||
if (cli_seek_file_begin(&file_handle, script_file) != SUCCESS) {
|
||||
exit_status = 1;
|
||||
} else {
|
||||
CG(start_lineno) = lineno;
|
||||
CG(skip_shebang) = 1;
|
||||
php_execute_script(&file_handle);
|
||||
exit_status = EG(exit_status);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue