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:
Martin Lund 2017-11-05 20:52:12 +01:00
parent 078bb6213d
commit b2aafd696b
6 changed files with 77 additions and 2 deletions

View file

@ -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)