Corrected fix for bug #46844 to only trigger on the 1st line of CLI opened

files.
This commit is contained in:
Ilia Alshanetsky 2009-01-09 17:20:57 +00:00
parent ae6b1d2216
commit af28e3443f
5 changed files with 26 additions and 26 deletions

View file

@ -6474,7 +6474,7 @@ yy553:
++YYCURSOR; ++YYCURSOR;
YYDEBUG(556, *YYCURSOR); YYDEBUG(556, *YYCURSOR);
yyleng = YYCURSOR - SCNG(yy_text); yyleng = YYCURSOR - SCNG(yy_text);
#line 1641 "Zend/zend_language_scanner.l" #line 1620 "Zend/zend_language_scanner.l"
{ {
return T_UNICODE_CAST; return T_UNICODE_CAST;
} }
@ -8614,7 +8614,7 @@ yy887:
yy888: yy888:
YYDEBUG(888, *YYCURSOR); YYDEBUG(888, *YYCURSOR);
yyleng = YYCURSOR - SCNG(yy_text); yyleng = YYCURSOR - SCNG(yy_text);
#line 1580 "Zend/zend_language_scanner.l" #line 1559 "Zend/zend_language_scanner.l"
{ {
Z_STRVAL_P(zendlval) = yytext; /* no copying - intentional */ Z_STRVAL_P(zendlval) = yytext; /* no copying - intentional */
Z_STRLEN_P(zendlval) = yyleng; Z_STRLEN_P(zendlval) = yyleng;

View file

@ -1336,27 +1336,6 @@ yymore_restart:
return 0; return 0;
} }
/* ignore first line when it's started with a #! */
if (YYCURSOR == SCNG(yy_start) && *YYCURSOR == '#' && *(YYCURSOR + 1) == '!') {
while (++YYCURSOR < YYLIMIT) {
if (*YYCURSOR == '\n') {
++YYCURSOR;
CG(zend_lineno)++;
goto restart;
}
if (*YYCURSOR == '\r') {
if (++YYCURSOR < YYLIMIT && *YYCURSOR == '\n') { /* match \r\n as single newline */
++YYCURSOR;
}
CG(zend_lineno)++;
goto restart;
}
}
return 0; /* EOF */
}
/*!re2c /*!re2c
re2c:yyfill:check = 0; re2c:yyfill:check = 0;
LNUM [0-9]+ LNUM [0-9]+

View file

@ -1,5 +1,5 @@
/* Generated by re2c 0.13.5 on Tue Dec 2 17:02:52 2008 */ /* Generated by re2c 0.13.5 on Fri Jan 9 12:18:37 2009 */
#line 3 "Zend/zend_language_scanner_defs.h" #line 3 "./zend_language_scanner_defs.h"
enum YYCONDTYPE { enum YYCONDTYPE {
yycST_IN_SCRIPTING, yycST_IN_SCRIPTING,

View file

@ -219,7 +219,7 @@ ZEND_API int zend_stream_fixup(zend_file_handle *file_handle, char **buf, size_t
#if HAVE_MMAP #if HAVE_MMAP
if (file_handle->handle.fp) { if (file_handle->handle.fp) {
/* *buf[size] is zeroed automatically by the kernel */ /* *buf[size] is zeroed automatically by the kernel */
*buf = mmap(0, size + ZEND_MMAP_AHEAD, PROT_READ, MAP_PRIVATE, fileno(file_handle->handle.fp), 0); *buf = mmap(0, size + ZEND_MMAP_AHEAD, PROT_READ, MAP_PRIVATE, fileno(file_handle->handle.fp), ftell(file_handle->handle.fp));
if (*buf != MAP_FAILED) { if (*buf != MAP_FAILED) {
file_handle->handle.stream.mmap.len = size; file_handle->handle.stream.mmap.len = size;
file_handle->handle.stream.mmap.map = *buf; file_handle->handle.stream.mmap.map = *buf;

View file

@ -574,6 +574,8 @@ static const char *param_mode_conflict = "Either execute direct code, process st
*/ */
static int cli_seek_file_begin(zend_file_handle *file_handle, char *script_file, int *lineno TSRMLS_DC) static int cli_seek_file_begin(zend_file_handle *file_handle, char *script_file, int *lineno TSRMLS_DC)
{ {
char c;
*lineno = 1; *lineno = 1;
file_handle->type = ZEND_HANDLE_FP; file_handle->type = ZEND_HANDLE_FP;
@ -584,6 +586,25 @@ static int cli_seek_file_begin(zend_file_handle *file_handle, char *script_file,
return FAILURE; return FAILURE;
} }
file_handle->filename = 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') {
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; return SUCCESS;
} }
/* }}} */ /* }}} */