Add mapping flags INLCRNL and ODELBS

The following new mapping flags are added:

INLCRNL: Map NL to CR-NL on input.
ODELBS: Map DEL to BS on output.

Flags requested and tested by Jan Ciger (janoc).
This commit is contained in:
Martin Lund 2017-12-29 11:24:28 +01:00
parent 60cbc5b368
commit 77c19ff152
3 changed files with 29 additions and 6 deletions

View file

@ -62,17 +62,21 @@ Log to file.
Map (replace, translate) special characters on input or output. The following mapping flags are supported: Map (replace, translate) special characters on input or output. The following mapping flags are supported:
.RS .RS
.TP 8n .TP 12n
.IP "\fBINLCR" .IP "\fBINLCR"
Map NL to CR on input. Map NL to CR on input.
.IP "\fBINLCRNL"
Map NL to CR-NL on input.
.IP "\fBIGNCR" .IP "\fBIGNCR"
Ignore CR on input. Ignore CR on input.
.IP "\fBICRNL" .IP "\fBICRNL"
Map CR to NL on input (unless IGNCR is set). Map CR to NL on input (unless IGNCR is set).
.IP "\fBONLCR" .IP "\fBONLCRNL"
Map NL to CR-NL on output. Map NL to CR-NL on output.
.IP "\fBOCRNL" .IP "\fBOCRNL"
Map CR to NL on output. Map CR to NL on output.
.IP "\fBODELBS"
Map DEL to BS on output.
.P .P
If defining more than one flag, the flags must be comma separated. If defining more than one flag, the flags must be comma separated.
.RE .RE

View file

@ -66,6 +66,8 @@ void print_help(char *argv[])
printf(" -v, --version Display version\n"); printf(" -v, --version Display version\n");
printf(" -h, --help Display help\n"); printf(" -h, --help Display help\n");
printf("\n"); printf("\n");
printf("See the man page for list of supported mapping flags.\n");
printf("\n");
printf("In session, press ctrl-t q to quit.\n"); printf("In session, press ctrl-t q to quit.\n");
printf("\n"); printf("\n");
} }

View file

@ -54,6 +54,8 @@ static bool print_mode = NORMAL;
static bool standard_baudrate = true; static bool standard_baudrate = true;
static void (*print)(char c); static void (*print)(char c);
static int fd; static int fd;
static bool map_inlcrnl = false;
static bool map_odelbs = false;
#define tio_printf(format, args...) \ #define tio_printf(format, args...) \
{ \ { \
@ -395,7 +397,6 @@ void tty_configure(void)
tio.c_cc[VMIN] = 1; // Blocking read until 1 character received tio.c_cc[VMIN] = 1; // Blocking read until 1 character received
/* Configure any specified input or output mappings */ /* Configure any specified input or output mappings */
buffer = strdup(option.map); buffer = strdup(option.map);
while (token_found == true) while (token_found == true)
{ {
@ -412,10 +413,14 @@ void tty_configure(void)
tio.c_iflag |= IGNCR; tio.c_iflag |= IGNCR;
else if (strcmp(token,"ICRNL") == 0) else if (strcmp(token,"ICRNL") == 0)
tio.c_iflag |= ICRNL; tio.c_iflag |= ICRNL;
else if (strcmp(token,"ONLCR") == 0) else if (strcmp(token,"ONLCRNL") == 0)
tio.c_oflag |= ONLCR; tio.c_oflag |= ONLCR;
else if (strcmp(token,"OCRNL") == 0) else if (strcmp(token,"OCRNL") == 0)
tio.c_oflag |= OCRNL; tio.c_oflag |= OCRNL;
else if (strcmp(token,"ODELBS") == 0)
map_odelbs = true;
else if (strcmp(token,"INLCRNL") == 0)
map_inlcrnl = true;
else else
{ {
printf("Error: Unknown mapping flag %s\n", token); printf("Error: Unknown mapping flag %s\n", token);
@ -596,8 +601,16 @@ int tty_connect(void)
/* Update receive statistics */ /* Update receive statistics */
rx_total++; rx_total++;
/* Map input character */
if ((input_char == '\n') && (map_inlcrnl))
{
print('\r');
print('\n');
} else
{
/* Print received tty character to stdout */ /* Print received tty character to stdout */
print(input_char); print(input_char);
}
fflush(stdout); fflush(stdout);
/* Write to log */ /* Write to log */
@ -635,6 +648,10 @@ int tty_connect(void)
if (forward) if (forward)
{ {
/* Map output character */
if ((output_char == 127) && (map_odelbs))
output_char = '\b';
/* Send output to tty device */ /* Send output to tty device */
status = write(fd, &output_char, 1); status = write(fd, &output_char, 1);
if (status < 0) if (status < 0)