Add mapping flags INLCRNL and OBSDEL

This commit is contained in:
Martin Lund 2017-12-29 11:24:28 +01:00
parent 60cbc5b368
commit 01ec8d6315
2 changed files with 27 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:
.RS
.TP 8n
.TP 12n
.IP "\fBINLCR"
Map NL to CR on input.
.IP "\fBINLCRNL"
Map NL to CR-NL on input.
.IP "\fBIGNCR"
Ignore CR on input.
.IP "\fBICRNL"
Map CR to NL on input (unless IGNCR is set).
.IP "\fBONLCR"
.IP "\fBONLCRNL"
Map NL to CR-NL on output.
.IP "\fBOCRNL"
Map CR to NL on output.
.IP "\fBOBSDEL"
Map BS to DEL on output.
.P
If defining more than one flag, the flags must be comma separated.
.RE

View file

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