aboutsummaryrefslogtreecommitdiff
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
parent0b59672d55379f824dd592b7a5c854d9a21a2c12 (diff)
downloaduxd-f381da6760b6beec1f875f1a982719c1b6be55a3.tar.gz
add -t/-T (terminal setup) options.
-rw-r--r--uxd.122
-rw-r--r--uxd.c22
-rw-r--r--uxd.rst14
3 files changed, 55 insertions, 3 deletions
diff --git a/uxd.1 b/uxd.1
index 8110efb..6258f9c 100644
--- a/uxd.1
+++ b/uxd.1
@@ -184,6 +184,28 @@ Works with negative \fIpos\fP, too.
.
.INDENT 0.0
.TP
+.B \-t
+Put terminal in UTF\-8 mode, if possible. Prints \fBESC % G\fP sequence, which
+may or may not be supported by your terminal. To avoid surprises, this
+option also takes the terminal out of UTF\-8 mode before \fBuxd\fP exits,
+on the theory that you won\(aqt need this option if the terminal is normally
+running in UTF\-8 mode. If this assumption turns out to be wrong, you can
+use the \fB\-T\fP option instead.
+.TP
+.B \-T
+Same as \fB\-T\fP, but leaves the terminal in UTF\-8 mode on exit. Can be
+used to recover from a previous misuse of \fB\-t\fP, like so:
+.INDENT 7.0
+.INDENT 3.5
+.sp
+.nf
+.ft C
+uxd \-T \-dd
+.ft P
+.fi
+.UNINDENT
+.UNINDENT
+.TP
.B \-u
Use uppercase hex digits \fIA\-F\fP\&. Default is lowercase.
.UNINDENT
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;
}
diff --git a/uxd.rst b/uxd.rst
index ddc3b9a..459de77 100644
--- a/uxd.rst
+++ b/uxd.rst
@@ -147,6 +147,20 @@ as *K*, *M*, and *G* for power-of-10 based (e.g. *1K* is 1000 bytes).
.. like -s, but also sets -o so addresses start at 0.
+-t
+ Put terminal in UTF-8 mode, if possible. Prints **ESC % G** sequence, which
+ may or may not be supported by your terminal. To avoid surprises, this
+ option also takes the terminal out of UTF-8 mode before **uxd** exits,
+ on the theory that you won't need this option if the terminal is normally
+ running in UTF-8 mode. If this assumption turns out to be wrong, you can
+ use the **-T** option instead.
+
+-T
+ Same as **-T**, but leaves the terminal in UTF-8 mode on exit. Can be
+ used to recover from a previous misuse of **-t**, like so::
+
+ uxd -T -dd
+
-u
Use uppercase hex digits *A-F*. Default is lowercase.