diff options
author | Bob Weinand <bobwei9@hotmail.com> | 2015-08-01 21:33:23 +0200 |
---|---|---|
committer | Bob Weinand <bobwei9@hotmail.com> | 2015-08-01 23:28:55 +0200 |
commit | 06ef2aeca9705322c52230aba2fd633ae7aa2737 (patch) | |
tree | 1b956a277c2cc9a1b7a55ae2e251756e84257af0 /sapi/phpdbg/phpdbg_prompt.c | |
parent | fb37da2a4875abc2153da583faca6c7554810ce9 (diff) | |
download | php-git-06ef2aeca9705322c52230aba2fd633ae7aa2737.tar.gz |
Skip shebang line if present
Diffstat (limited to 'sapi/phpdbg/phpdbg_prompt.c')
-rw-r--r-- | sapi/phpdbg/phpdbg_prompt.c | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/sapi/phpdbg/phpdbg_prompt.c b/sapi/phpdbg/phpdbg_prompt.c index 89e8d027f6..e920f30cdf 100644 --- a/sapi/phpdbg/phpdbg_prompt.c +++ b/sapi/phpdbg/phpdbg_prompt.c @@ -443,14 +443,36 @@ PHPDBG_COMMAND(exec) /* {{{ */ int phpdbg_compile(void) /* {{{ */ { zend_file_handle fh; + char *buf; + size_t len; if (!PHPDBG_G(exec)) { phpdbg_error("inactive", "type=\"nocontext\"", "No execution context"); return FAILURE; } - if (php_stream_open_for_zend_ex(PHPDBG_G(exec), &fh, USE_PATH|STREAM_OPEN_FOR_INCLUDE) == SUCCESS) { + if (php_stream_open_for_zend_ex(PHPDBG_G(exec), &fh, USE_PATH|STREAM_OPEN_FOR_INCLUDE) == SUCCESS && zend_stream_fixup(&fh, &buf, &len) == SUCCESS) { + /* Skip #! line */ + if (len >= 3 && buf[0] == '#' && buf[1] == '!') { + char *end = buf + len; + do { + switch (fh.handle.stream.mmap.buf++[0]) { + case '\r': + if (fh.handle.stream.mmap.buf[0] == '\n') { + fh.handle.stream.mmap.buf++; + } + case '\n': + CG(start_lineno) = 2; + fh.handle.stream.mmap.len -= fh.handle.stream.mmap.buf - buf; + end = fh.handle.stream.mmap.buf; + } + } while (fh.handle.stream.mmap.buf + 1 < end); + } + PHPDBG_G(ops) = zend_compile_file(&fh, ZEND_INCLUDE); + + fh.handle.stream.mmap.buf = buf; + fh.handle.stream.mmap.len = len; zend_destroy_file_handle(&fh); if (EG(exception)) { zend_exception_error(EG(exception), E_ERROR); |