From f231ddddafa005576e90f9325d31eebc9ea690bf Mon Sep 17 00:00:00 2001 From: Felipe Pena Date: Sun, 18 Oct 2015 12:08:04 -0200 Subject: - Implemented output paging --- sapi/phpdbg/phpdbg_io.c | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) (limited to 'sapi/phpdbg/phpdbg_io.c') 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 to continue or q 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); -- cgit v1.2.1