]> granicus.if.org Git - php/commitdiff
Corrected fix for bug #46844 to only trigger on the 1st line of CLI opened
authorIlia Alshanetsky <iliaa@php.net>
Fri, 9 Jan 2009 17:20:57 +0000 (17:20 +0000)
committerIlia Alshanetsky <iliaa@php.net>
Fri, 9 Jan 2009 17:20:57 +0000 (17:20 +0000)
files.

Zend/zend_language_scanner.c
Zend/zend_language_scanner.l
Zend/zend_language_scanner_defs.h
Zend/zend_stream.c
sapi/cli/php_cli.c

index a58a84eb70c609abd5f084cf4c5d34bf361f9681..71da2309a9b044f066e09c72784d680301c35e2b 100644 (file)
@@ -6474,7 +6474,7 @@ yy553:
                ++YYCURSOR;
                YYDEBUG(556, *YYCURSOR);
                yyleng = YYCURSOR - SCNG(yy_text);
-#line 1641 "Zend/zend_language_scanner.l"
+#line 1620 "Zend/zend_language_scanner.l"
                {
        return T_UNICODE_CAST;
 }
@@ -8614,7 +8614,7 @@ yy887:
 yy888:
                YYDEBUG(888, *YYCURSOR);
                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_STRLEN_P(zendlval) = yyleng;
index 747dcbe49e298fc447ae6416768abe5f73c604cb..db85c49123c50c4332f0d1ede56c0ee8eccb8081 100644 (file)
@@ -1336,27 +1336,6 @@ yymore_restart:
                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:yyfill:check = 0;
 LNUM   [0-9]+
index eb4e6489e1b24f1f37ca13742cdb3cd8cea7e439..463a2fbac6b7e0f393c71c6cb00cdd75c7d7d41c 100644 (file)
@@ -1,5 +1,5 @@
-/* Generated by re2c 0.13.5 on Tue Dec  2 17:02:52 2008 */
-#line 3 "Zend/zend_language_scanner_defs.h"
+/* Generated by re2c 0.13.5 on Fri Jan  9 12:18:37 2009 */
+#line 3 "./zend_language_scanner_defs.h"
 
 enum YYCONDTYPE {
        yycST_IN_SCRIPTING,
index f9853f599e44cabb894339ca69bfc24861d79a38..0c76ba70b4b683800a06d0424bc1edac2a25a0bb 100644 (file)
@@ -219,7 +219,7 @@ ZEND_API int zend_stream_fixup(zend_file_handle *file_handle, char **buf, size_t
 #if HAVE_MMAP
                if (file_handle->handle.fp) {
                        /*  *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) {
                                file_handle->handle.stream.mmap.len = size;
                                file_handle->handle.stream.mmap.map = *buf;
index 4938d9c932b3637ade5cb00c83c987c525476a6a..5fc0a028017c1ee4a79664f0254caefe39e59e87 100644 (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)
 {
+       char c;
+
        *lineno = 1;
 
        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;
        }
        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;
 }
 /* }}} */