diff --git a/man/tio.1 b/man/tio.1 index 5bd8742..f666ad9 100644 --- a/man/tio.1 +++ b/man/tio.1 @@ -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 "\fBODELBS" +Map DEL to BS on output. .P If defining more than one flag, the flags must be comma separated. .RE diff --git a/src/options.c b/src/options.c index 3f9c199..3edf05c 100644 --- a/src/options.c +++ b/src/options.c @@ -66,6 +66,8 @@ void print_help(char *argv[]) printf(" -v, --version Display version\n"); printf(" -h, --help Display help\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("\n"); } diff --git a/src/tty.c b/src/tty.c index de4bcf8..9ad4980 100644 --- a/src/tty.c +++ b/src/tty.c @@ -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_odelbs = 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,"ODELBS") == 0) + map_odelbs = 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 == 127) && (map_odelbs)) + output_char = '\b'; + /* Send output to tty device */ status = write(fd, &output_char, 1); if (status < 0)