diff options
author | Felipe Pena <felipensp@gmail.com> | 2015-10-18 12:08:04 -0200 |
---|---|---|
committer | Felipe Pena <felipensp@gmail.com> | 2015-10-18 12:08:04 -0200 |
commit | f231ddddafa005576e90f9325d31eebc9ea690bf (patch) | |
tree | 38452a7e230501a6e01fcd3206355005e9745343 /sapi/phpdbg/phpdbg_io.c | |
parent | daddb7a832309bb26858d3c069ecf29c0994dbd7 (diff) | |
download | php-git-f231ddddafa005576e90f9325d31eebc9ea690bf.tar.gz |
- Implemented output paging
Diffstat (limited to 'sapi/phpdbg/phpdbg_io.c')
-rw-r--r-- | sapi/phpdbg/phpdbg_io.c | 36 |
1 files changed, 35 insertions, 1 deletions
diff --git a/sapi/phpdbg/phpdbg_io.c b/sapi/phpdbg/phpdbg_io.c index baec0ac0f8..cf4fdb88b4 100644 --- a/sapi/phpdbg/phpdbg_io.c +++ b/sapi/phpdbg/phpdbg_io.c @@ -190,16 +190,50 @@ PHPDBG_API int phpdbg_mixed_read(int sock, char *ptr, int len, int tmo) { return ret; } +static int phpdbg_output_pager(int sock, const char *ptr, int len) { + int count = 0, bytes = 0; + const char *p = ptr, *endp = ptr + len; + + while ((p = memchr(p, '\n', endp - p))) { + count++; + p++; + + if (count % PHPDBG_G(lines) == 0) { + bytes += write(sock, ptr + bytes, (p - ptr) - bytes); + + if (memchr(p, '\n', endp - p)) { + int chr; + printf("\r---Type <return> to continue or q <return> to quit---"); + chr = getchar(); + if (chr == 'q') { + break; + } + printf("\r"); + } else break; + } + } + if (bytes && count % PHPDBG_G(lines) != 0) { + bytes += write(sock, ptr + bytes, len - bytes); + } else if (!bytes) { + bytes += write(sock, ptr, len); + } + return bytes; +} PHPDBG_API int phpdbg_mixed_write(int sock, const char *ptr, int len) { if (PHPDBG_G(flags) & PHPDBG_IS_REMOTE) { return phpdbg_send_bytes(sock, ptr, len); } + + if (PHPDBG_G(flags) & PHPDBG_HAS_PAGINATION + && PHPDBG_G(io)[PHPDBG_STDOUT].fd == sock + && PHPDBG_G(lines) > 0) { + return phpdbg_output_pager(sock, ptr, len); + } return write(sock, ptr, len); } - PHPDBG_API int phpdbg_open_socket(const char *interface, unsigned short port) { struct addrinfo res; int fd = phpdbg_create_listenable_socket(interface, port, &res); |