aboutsummaryrefslogtreecommitdiff
path: root/uxd.c
diff options
context:
space:
mode:
authorB. Watson <urchlay@slackware.uk>2024-12-18 06:11:54 -0500
committerB. Watson <urchlay@slackware.uk>2024-12-18 06:11:54 -0500
commitf381da6760b6beec1f875f1a982719c1b6be55a3 (patch)
tree75f75a1f200902921e2b89eb6cbafdd462330e14 /uxd.c
parent0b59672d55379f824dd592b7a5c854d9a21a2c12 (diff)
downloaduxd-f381da6760b6beec1f875f1a982719c1b6be55a3.tar.gz
add -t/-T (terminal setup) options.
Diffstat (limited to 'uxd.c')
-rw-r--r--uxd.c22
1 files changed, 19 insertions, 3 deletions
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;
}