mirror of
https://github.com/tio/tio.git
synced 2026-05-01 14:57:59 +02:00
Add special character map feature
Add a --map option which allows to map special characters, in particular CR and NL characters which are used in various combinations on varios platforms.
This commit is contained in:
parent
078bb6213d
commit
b2aafd696b
6 changed files with 77 additions and 2 deletions
38
src/tty.c
38
src/tty.c
|
|
@ -112,6 +112,8 @@ void handle_command_sequence(char input_char, char previous_char, char *output_c
|
|||
tio_printf(" Stopbits: %d", option.stopbits);
|
||||
tio_printf(" Parity: %s", option.parity);
|
||||
tio_printf(" Output delay: %d", option.output_delay);
|
||||
if (option.map[0] != 0)
|
||||
tio_printf(" Map flags: %s", option.map);
|
||||
if (option.log)
|
||||
tio_printf(" Log file: %s", option.log_filename);
|
||||
break;
|
||||
|
|
@ -209,6 +211,9 @@ void stdout_restore(void)
|
|||
|
||||
void tty_configure(void)
|
||||
{
|
||||
bool token_found = true;
|
||||
char *token = NULL;
|
||||
char *buffer;
|
||||
int status;
|
||||
speed_t baudrate;
|
||||
|
||||
|
|
@ -335,6 +340,39 @@ void tty_configure(void)
|
|||
/* Control characters */
|
||||
tio.c_cc[VTIME] = 0; // Inter-character timer unused
|
||||
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)
|
||||
{
|
||||
if (token == NULL)
|
||||
token = strtok(buffer,",");
|
||||
else
|
||||
token = strtok(NULL, ",");
|
||||
|
||||
if (token != NULL)
|
||||
{
|
||||
if (strcmp(token,"INLCR") == 0)
|
||||
tio.c_iflag |= INLCR;
|
||||
else if (strcmp(token,"IGNCR") == 0)
|
||||
tio.c_iflag |= IGNCR;
|
||||
else if (strcmp(token,"ICRNL") == 0)
|
||||
tio.c_iflag |= ICRNL;
|
||||
else if (strcmp(token,"ONLCR") == 0)
|
||||
tio.c_oflag |= ONLCR;
|
||||
else if (strcmp(token,"OCRNL") == 0)
|
||||
tio.c_oflag |= OCRNL;
|
||||
else
|
||||
{
|
||||
printf("Error: Unknown mapping flag %s\n", token);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
else
|
||||
token_found = false;
|
||||
}
|
||||
free(buffer);
|
||||
}
|
||||
|
||||
void tty_wait_for_device(void)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue