Add OIGNCR mapping flag

Ignores CR on output to serial device.
This commit is contained in:
Martin Lund 2024-06-27 20:09:18 +02:00
parent 8c471105fe
commit 4723cc3f4e
5 changed files with 25 additions and 6 deletions

View file

@ -201,8 +201,8 @@ Strip control characters and escape sequences from log.
.TP
.BR \-m ", " "\-\-map " \fI<flags>
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

View file

@ -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)

View file

@ -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;

View file

@ -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;

View file

@ -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))