From f381da6760b6beec1f875f1a982719c1b6be55a3 Mon Sep 17 00:00:00 2001 From: "B. Watson" Date: Wed, 18 Dec 2024 06:11:54 -0500 Subject: add -t/-T (terminal setup) options. --- uxd.c | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) (limited to 'uxd.c') diff --git a/uxd.c b/uxd.c index f9ca29a..e839330 100644 --- a/uxd.c +++ b/uxd.c @@ -77,6 +77,10 @@ extern int optind; #define MONO_BOLD 1 #define MONO_REVERSE 7 +/* terminal codes to enable/disable UTF-8 mode */ +#define ESC_UTF8_ON "\x1b%G" +#define ESC_UTF8_OFF "\x1b%@" + /* replacement character � is U+FFFD */ #define PRINT_BAD "�" #define PRINT_BOM "B" @@ -144,6 +148,8 @@ const char *hex_byte_fmt = LC_BYTE_FMT; /* -u */ const char *hex_addr_fmt = LC_ADDR_FMT; /* " */ char *dump_data_arg = NULL; /* -d */ long dump_data_idx = 0; /* -d */ +int term_utf8 = 0; /* -t, -T */ +int restore_term = 0; /* -T only */ /* stats for -i option */ long byte_count = 0; @@ -259,8 +265,12 @@ void parse_args(int argc, char **argv) { version(); } - while((opt = my_getopt(argc, argv, "d:1ic:nbl:rmo:S:s:uhv")) != -1) { + while((opt = my_getopt(argc, argv, "tTd:1ic:nbl:rmo:S:s:uhv")) != -1) { switch(opt) { + case 't': + term_utf8 = restore_term = 1; break; + case 'T': + term_utf8 = 1; restore_term = 0; break; case 'd': if(dump_data_arg) { fprintf(stderr, "%s: multiple -d options not supported.\n", self); @@ -824,13 +834,19 @@ int main(int argc, char **argv) { parse_options(argc, argv); + if(term_utf8) /* -t, -T */ + puts(ESC_UTF8_ON); + if(dump_data_arg) - dump_data(); + dump_data(); /* -d */ else dump_file(); - if(print_info_opt) + if(print_info_opt) /* -i */ print_info(); + if(restore_term) /* -T */ + puts(ESC_UTF8_OFF); + return 0; } -- cgit v1.2.3