mirror of
https://github.com/tio/tio.git
synced 2026-05-01 14:57:59 +02:00
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:
parent
60cbc5b368
commit
77c19ff152
3 changed files with 29 additions and 6 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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");
|
||||
}
|
||||
|
|
|
|||
25
src/tty.c
25
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)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue