From 8dba4647e9729cdea27f6b0165e82f20ee1d7266 Mon Sep 17 00:00:00 2001 From: Derek Buitenhuis Date: Sun, 6 Jan 2019 12:44:11 -0500 Subject: [PATCH] Implement PGUP and PGDOWN support for skipping full screens Implements part of #2. Signed-off-by: Derek Buitenhuis --- LICENSE | 2 +- README.md | 5 +++-- main.c | 38 +++++++++++++++++++++++++++++++++++++- 3 files changed, 41 insertions(+), 4 deletions(-) diff --git a/LICENSE b/LICENSE index 22c6e5e..9394f6a 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ ISC License (ISC) -Copyright (c) 2016, Derek Buitenhuis +Copyright (c) 2016-2019, Derek Buitenhuis Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above diff --git a/README.md b/README.md index ab6d677..f2a37ee 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ BXD: Binary Hex Diff ==================== -Copyright (c) 2016 Derek Buitenhuis +Copyright (c) 2016-2019 Derek Buitenhuis ![BXD](http://chromashift.org/bxd.png) @@ -28,7 +28,7 @@ Usage Currently, the command like arguments are very simple: Binary Hex Diff - Copyright (c) 2016 Derek Buitenhuis. + Copyright (c) 2016-2019 Derek Buitenhuis. A tool to compare two arbitrarily sized binary files. @@ -39,6 +39,7 @@ Keys are: * `q` to quit. * `space` to seek to next diff. * `up`/`down` to scroll up and down. +* `pgup` / `pgdn` to scroll up and down by one full screen. Current Limitations ------------------- diff --git a/main.c b/main.c index b0d47ea..15ec274 100644 --- a/main.c +++ b/main.c @@ -25,7 +25,7 @@ int main(int argc, char *argv[]) if (argc < 3) { fprintf(stderr, "Binary Hex Diff\n" - "Copyright (c) 2016 Derek Buitenhuis.\n\n" + "Copyright (c) 2016-2019 Derek Buitenhuis.\n\n" "A tool to compare two arbitrarily sized binary files.\n\n" "Usage: %s file1 file2\n\n", argv[0]); return 0; @@ -124,6 +124,42 @@ int main(int argc, char *argv[]) break; } + case TB_KEY_PGUP: { + unsigned int lpu = get_line_per_side(); + + for (unsigned int i = 0; i < lpu; i++) { + if (ctx.offset == 0) { + if (ctx.nf_offset != 0 && ctx.of_offset != 0) + load_previous(&ctx, &lbuf[0], scratch); + } else { + ctx.offset -= 2; + } + } + break; + } + case TB_KEY_PGDN: { + unsigned int cpl = get_char_per_line(); + unsigned int lpu = get_line_per_side(); + + if (ctx.done) + continue; + + for (unsigned int i = 0; i < lpu && !ctx.done; i++) { + ctx.offset += 2; + + if (((size_t) ctx.offset / 2) * cpl + cpl * lpu >= ctx.blocksize) { + bool err; + + calc_next_mask(&ctx, &lbuf[0], scratch, &err); + + if (err) + goto end; + } + + draw_ui_dummy(&ctx); + } + break; + } case TB_KEY_SPACE: { unsigned int cpl = get_char_per_line(); unsigned int lpu = get_line_per_side();