120 lines
3.7 KiB
Diff
120 lines
3.7 KiB
Diff
|
|
From 562ce2612356ef2aff4c99dc7219df60da421362 Mon Sep 17 00:00:00 2001
|
||
|
|
From: Mark Nudelman <markn@greenwoodsoftware.com>
|
||
|
|
Date: Thu, 20 Oct 2022 10:26:20 -0700
|
||
|
|
Subject: [PATCH 28/48] Store 2-char hex values in log file rather than binary
|
||
|
|
bytes. Don't want to accidentally store a newline in the middle of a line.
|
||
|
|
|
||
|
|
---
|
||
|
|
lesstest/display.c | 22 ++++++++++++++++++----
|
||
|
|
lesstest/lt_screen.c | 12 +++++++++---
|
||
|
|
lesstest/lt_types.h | 2 +-
|
||
|
|
3 files changed, 28 insertions(+), 8 deletions(-)
|
||
|
|
|
||
|
|
diff --git a/lesstest/display.c b/lesstest/display.c
|
||
|
|
index 2a8f030..648d42a 100644
|
||
|
|
--- a/lesstest/display.c
|
||
|
|
+++ b/lesstest/display.c
|
||
|
|
@@ -19,6 +19,20 @@ static void display_attr_color(Attr attr, Color fg_color, Color bg_color) {
|
||
|
|
printf("%s", terminfo.enter_standout);
|
||
|
|
}
|
||
|
|
|
||
|
|
+static int hexval(unsigned char ch) {
|
||
|
|
+ if (ch >= '0' && ch <= '9') return ch - '0';
|
||
|
|
+ if (ch >= 'A' && ch <= 'F') return ch - 'A' + 10;
|
||
|
|
+ if (ch >= 'a' && ch <= 'f') return ch - 'a' + 10;
|
||
|
|
+ fprintf(stderr, "invalid hex char 0x%x\n", ch);
|
||
|
|
+ abort();
|
||
|
|
+}
|
||
|
|
+
|
||
|
|
+static int get_hex(unsigned char const** pp) {
|
||
|
|
+ int v1 = hexval(*(*pp)++);
|
||
|
|
+ int v2 = hexval(*(*pp)++);
|
||
|
|
+ return (v1 << 4) | v2;
|
||
|
|
+}
|
||
|
|
+
|
||
|
|
void display_screen(const byte* img, int imglen, int screen_width, int screen_height) {
|
||
|
|
int x = 0;
|
||
|
|
int y = 0;
|
||
|
|
@@ -36,15 +50,15 @@ void display_screen(const byte* img, int imglen, int screen_width, int screen_he
|
||
|
|
literal = 1;
|
||
|
|
continue;
|
||
|
|
case LTS_CHAR_ATTR:
|
||
|
|
- curr_attr = *img++;
|
||
|
|
+ curr_attr = get_hex(&img);
|
||
|
|
display_attr_color(curr_attr, curr_fg_color, curr_bg_color);
|
||
|
|
continue;
|
||
|
|
case LTS_CHAR_FG_COLOR:
|
||
|
|
- curr_fg_color = *img++;
|
||
|
|
+ curr_fg_color = get_hex(&img);
|
||
|
|
display_attr_color(curr_attr, curr_fg_color, curr_bg_color);
|
||
|
|
continue;
|
||
|
|
case LTS_CHAR_BG_COLOR:
|
||
|
|
- curr_bg_color = *img++;
|
||
|
|
+ curr_bg_color = get_hex(&img);
|
||
|
|
display_attr_color(curr_attr, curr_fg_color, curr_bg_color);
|
||
|
|
continue;
|
||
|
|
case LTS_CHAR_CURSOR:
|
||
|
|
@@ -85,7 +99,7 @@ void display_screen_debug(const byte* img, int imglen, int screen_width, int scr
|
||
|
|
case LTS_CHAR_ATTR:
|
||
|
|
case LTS_CHAR_FG_COLOR:
|
||
|
|
case LTS_CHAR_BG_COLOR:
|
||
|
|
- x -= 2; // don't count LTS_CHAR or following byte
|
||
|
|
+ x -= 3; // don't count LTS_CHAR or following 2 bytes
|
||
|
|
literal = 1;
|
||
|
|
break;
|
||
|
|
case LTS_CHAR_CURSOR:
|
||
|
|
diff --git a/lesstest/lt_screen.c b/lesstest/lt_screen.c
|
||
|
|
index 8b3daac..674251c 100644
|
||
|
|
--- a/lesstest/lt_screen.c
|
||
|
|
+++ b/lesstest/lt_screen.c
|
||
|
|
@@ -132,6 +132,12 @@ static int screen_clear(int x, int y, int count) {
|
||
|
|
return 1;
|
||
|
|
}
|
||
|
|
|
||
|
|
+static void store_hex(byte** pp, int val) {
|
||
|
|
+ char hexchar[] = "0123456789ABCDEF";
|
||
|
|
+ *(*pp)++ = hexchar[(val >> 4) & 0xf];
|
||
|
|
+ *(*pp)++ = hexchar[val & 0xf];
|
||
|
|
+}
|
||
|
|
+
|
||
|
|
static int screen_read(int x, int y, int count) {
|
||
|
|
//write(ttyout, "$|", 2);
|
||
|
|
Attr attr = 0;
|
||
|
|
@@ -144,17 +150,17 @@ static int screen_read(int x, int y, int count) {
|
||
|
|
if (sc->attr != attr) {
|
||
|
|
attr = sc->attr;
|
||
|
|
*bufp++ = LTS_CHAR_ATTR;
|
||
|
|
- *bufp++ = attr;
|
||
|
|
+ store_hex(&bufp, attr);
|
||
|
|
}
|
||
|
|
if (sc->fg_color != fg_color) {
|
||
|
|
fg_color = sc->fg_color;
|
||
|
|
*bufp++ = LTS_CHAR_FG_COLOR;
|
||
|
|
- *bufp++ = fg_color;
|
||
|
|
+ store_hex(&bufp, fg_color);
|
||
|
|
}
|
||
|
|
if (sc->bg_color != bg_color) {
|
||
|
|
bg_color = sc->bg_color;
|
||
|
|
*bufp++ = LTS_CHAR_BG_COLOR;
|
||
|
|
- *bufp++ = bg_color;
|
||
|
|
+ store_hex(&bufp, bg_color);
|
||
|
|
}
|
||
|
|
if (x == screen.cx && y == screen.cy)
|
||
|
|
*bufp++ = LTS_CHAR_CURSOR;
|
||
|
|
diff --git a/lesstest/lt_types.h b/lesstest/lt_types.h
|
||
|
|
index a2cae31..01932f7 100644
|
||
|
|
--- a/lesstest/lt_types.h
|
||
|
|
+++ b/lesstest/lt_types.h
|
||
|
|
@@ -15,7 +15,7 @@ typedef unsigned char Color;
|
||
|
|
#define ESC '\33'
|
||
|
|
#define LESS_DUMP_CHAR '\35'
|
||
|
|
#define UNICODE_MAX_BYTES 4
|
||
|
|
-#define MAX_SCREENBUF_SIZE 8192
|
||
|
|
+#define MAX_SCREENBUF_SIZE (16*1024)
|
||
|
|
|
||
|
|
#define RUN_OK 0
|
||
|
|
#define RUN_ERR 1
|
||
|
|
--
|
||
|
|
2.27.0
|
||
|
|
|