From 4723cc3f4e3e8c3ca1ff1580cf8767a837afabbb Mon Sep 17 00:00:00 2001 From: Martin Lund Date: Thu, 27 Jun 2024 20:09:18 +0200 Subject: [PATCH] Add OIGNCR mapping flag Ignores CR on output to serial device. --- man/tio.1.in | 6 ++++-- src/bash-completion/tio.in | 2 +- src/options.c | 5 +++++ src/options.h | 1 + src/tty.c | 17 ++++++++++++++--- 5 files changed, 25 insertions(+), 6 deletions(-) diff --git a/man/tio.1.in b/man/tio.1.in index c66dae2..6f0af8c 100644 --- a/man/tio.1.in +++ b/man/tio.1.in @@ -201,8 +201,8 @@ Strip control characters and escape sequences from log. .TP .BR \-m ", " "\-\-map " \fI -Map (replace, translate) characters on input or output. The following mapping -flags are supported: +Map (replace, translate) characters on input/output to/from the serial device. +The following mapping flags are supported: .RS .TP 12n @@ -226,6 +226,8 @@ Map NL to CR-NL on output Map lowercase characters to uppercase on output .IP "\fBONULBRK" Map nul (zero) to send break signal on output +.IP "\fBOIGNCR" +Ignore CR on output .IP "\fBMSB2LSB" Map MSB bit order to LSB on output .P diff --git a/src/bash-completion/tio.in b/src/bash-completion/tio.in index 3a3e7f6..6607d1f 100644 --- a/src/bash-completion/tio.in +++ b/src/bash-completion/tio.in @@ -85,7 +85,7 @@ _tio() return 0 ;; -m | --map) - COMPREPLY=( $(compgen -W "ICRNL IGNCR INLCR IFFESCC INLCRNL OCRNL ODELBS ONLCRNL MSB2LSB" -- ${cur}) ) + COMPREPLY=( $(compgen -W "ICRNL IGNCR INLCR IFFESCC INLCRNL OCRNL ODELBS ONLCRNL OLTU ONULBRK OIGNCR MSB2LSB" -- ${cur}) ) return 0 ;; --timestamp-format) diff --git a/src/options.c b/src/options.c index 94a623f..94b940a 100644 --- a/src/options.c +++ b/src/options.c @@ -119,6 +119,7 @@ struct option_t option = .map_o_ltu = false, .map_o_nulbrk = false, .map_o_msblsb = false, + .map_o_ign_cr = false, }; void option_print_help(char *argv[]) @@ -768,6 +769,10 @@ void option_parse_mappings(const char *map) { option.map_o_nulbrk = true; } + else if (strcmp(token, "OIGNCR") == 0) + { + option.map_o_ign_cr = true; + } else if (strcmp(token, "MSB2LSB") == 0) { option.map_o_msblsb = true; diff --git a/src/options.h b/src/options.h index 80e0f3a..20a840b 100644 --- a/src/options.h +++ b/src/options.h @@ -104,6 +104,7 @@ struct option_t bool map_o_ltu; bool map_o_nulbrk; bool map_o_msblsb; + bool map_o_ign_cr; }; extern struct option_t option; diff --git a/src/tty.c b/src/tty.c index 262ad1d..83d6278 100644 --- a/src/tty.c +++ b/src/tty.c @@ -623,9 +623,9 @@ static void mappings_print(void) if (option.map_i_cr_nl || option.map_ign_cr || option.map_i_ff_escc || option.map_i_nl_cr || option.map_i_nl_crnl || option.map_o_cr_nl || option.map_o_del_bs || option.map_o_nl_crnl || option.map_o_ltu || - option.map_o_nulbrk || option.map_o_msblsb) + option.map_o_nulbrk || option.map_o_msblsb || option.map_o_ign_cr) { - tio_printf(" Mappings:%s%s%s%s%s%s%s%s%s%s%s", + tio_printf(" Mappings:%s%s%s%s%s%s%s%s%s%s%s%s", option.map_i_cr_nl ? " ICRNL" : "", option.map_ign_cr ? " IGNCR" : "", option.map_i_ff_escc ? " IFFESCC" : "", @@ -636,6 +636,7 @@ static void mappings_print(void) option.map_o_nl_crnl ? " ONLCRNL" : "", option.map_o_ltu ? " OLTU" : "", option.map_o_nulbrk ? " ONULBRK" : "", + option.map_o_ign_cr ? " OIGNCR" : "", option.map_o_msblsb ? " MSB2LSB" : ""); } else @@ -791,6 +792,10 @@ void handle_command_sequence(char input_char, char *output_char, bool *forward) tio_printf("ONULBRK is %s", option.map_o_nulbrk ? "set" : "unset"); break; case KEY_A: + option.map_o_ign_cr = !option.map_o_ign_cr; + tio_printf("OIGNCR is %s", option.map_o_ign_cr ? "set" : "unset"); + break; + case KEY_B: option.map_o_msblsb = !option.map_o_msblsb; tio_printf("MSB2LSB is %s", option.map_o_msblsb ? "set" : "unset"); break; @@ -1002,7 +1007,9 @@ void handle_command_sequence(char input_char, char *output_char, bool *forward) option.map_o_ltu ? "Unset" : "Set"); tio_printf(" (9) ONULBRK: %s mapping NUL to send break signal on output", option.map_o_nulbrk ? "Unset" : "Set"); - tio_printf(" (a) MSB2LSB: %s mapping MSB bit order to LSB on output", + tio_printf(" (a) OIGNCR: %s ignoring CR on output", + option.map_o_ign_cr ? "Unset" : "Set"); + tio_printf(" (b) MSB2LSB: %s mapping MSB bit order to LSB on output", option.map_o_msblsb ? "Unset" : "Set"); // Process next input character as sub command @@ -2133,6 +2140,10 @@ void forward_to_tty(int fd, char output_char) { output_char = '\n'; } + if ((output_char == '\r') && (option.map_o_ign_cr)) + { + return; + } /* Map newline character */ if ((output_char == '\n' || output_char == '\r') && (option.map_o_nl_crnl))