mirror of
https://github.com/tio/tio.git
synced 2026-05-01 14:57:59 +02:00
Replace inih with glib key file parser
After including the use of glib we might as well replace inih with the glib key file parser. All configuraiton file parsing has been reworked and also the options parsing has been cleaned up, resulting in better and stricter configuration file and option value checks. Compared to old, configuration files now requires any default configurations to be put in a group/section named [default]. Configuration file keywords such as "enable", "disable", "on", "off", "yes", "no", "0", "1" have been retired. Now only "true" and "false" apply to boolean configuration options. This is done to simplify things and avoid any confusion. The pattern option feature has been reworked so now the user can now access the full match string and any matching subexpression using the %mN syntax. For example: [usb devices] pattern = usb([0-9]*) device = /dev/ttyUSB%m1 Then when using tio: $ tio usb12 %m0 = 'usb12' // Full match string %m1 = 12 // First match subexpression Which results in device = /dev/ttyUSB12
This commit is contained in:
parent
68d3b845b2
commit
65c5a068d8
23 changed files with 969 additions and 723 deletions
113
src/tty.c
113
src/tty.c
|
|
@ -158,7 +158,7 @@ bool map_ign_cr = false;
|
|||
|
||||
char key_hit = 0xff;
|
||||
|
||||
const char* device_name;
|
||||
const char* device_name = NULL;
|
||||
GList *device_list = NULL;
|
||||
static struct termios tio, tio_old, stdout_new, stdout_old, stdin_new, stdin_old;
|
||||
static unsigned long rx_total = 0, tx_total = 0;
|
||||
|
|
@ -1154,25 +1154,26 @@ void tty_configure(void)
|
|||
}
|
||||
|
||||
/* Set flow control */
|
||||
if (strcmp("hard", option.flow) == 0)
|
||||
switch (option.flow)
|
||||
{
|
||||
tio.c_cflag |= CRTSCTS;
|
||||
tio.c_iflag &= ~(IXON | IXOFF | IXANY);
|
||||
}
|
||||
else if (strcmp("soft", option.flow) == 0)
|
||||
{
|
||||
tio.c_cflag &= ~CRTSCTS;
|
||||
tio.c_iflag |= IXON | IXOFF;
|
||||
}
|
||||
else if (strcmp("none", option.flow) == 0)
|
||||
{
|
||||
tio.c_cflag &= ~CRTSCTS;
|
||||
tio.c_iflag &= ~(IXON | IXOFF | IXANY);
|
||||
}
|
||||
else
|
||||
{
|
||||
tio_error_printf("Invalid flow control");
|
||||
exit(EXIT_FAILURE);
|
||||
case FLOW_NONE:
|
||||
tio.c_cflag &= ~CRTSCTS;
|
||||
tio.c_iflag &= ~(IXON | IXOFF | IXANY);
|
||||
break;
|
||||
|
||||
case FLOW_HARD:
|
||||
tio.c_cflag |= CRTSCTS;
|
||||
tio.c_iflag &= ~(IXON | IXOFF | IXANY);
|
||||
break;
|
||||
|
||||
case FLOW_SOFT:
|
||||
tio.c_cflag &= ~CRTSCTS;
|
||||
tio.c_iflag |= IXON | IXOFF;
|
||||
break;
|
||||
|
||||
default:
|
||||
tio_error_printf("Invalid flow control");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
/* Set stopbits */
|
||||
|
|
@ -1190,36 +1191,37 @@ void tty_configure(void)
|
|||
}
|
||||
|
||||
/* Set parity */
|
||||
if (strcmp("odd", option.parity) == 0)
|
||||
switch (option.parity)
|
||||
{
|
||||
tio.c_cflag |= PARENB;
|
||||
tio.c_cflag |= PARODD;
|
||||
}
|
||||
else if (strcmp("even", option.parity) == 0)
|
||||
{
|
||||
tio.c_cflag |= PARENB;
|
||||
tio.c_cflag &= ~PARODD;
|
||||
}
|
||||
else if (strcmp("none", option.parity) == 0)
|
||||
{
|
||||
tio.c_cflag &= ~PARENB;
|
||||
}
|
||||
else if ( strcmp("mark", option.parity) == 0)
|
||||
{
|
||||
tio.c_cflag |= PARENB;
|
||||
tio.c_cflag |= PARODD;
|
||||
tio.c_cflag |= CMSPAR;
|
||||
}
|
||||
else if ( strcmp("space", option.parity) == 0)
|
||||
{
|
||||
tio.c_cflag |= PARENB;
|
||||
tio.c_cflag &= ~PARODD;
|
||||
tio.c_cflag |= CMSPAR;
|
||||
}
|
||||
else
|
||||
{
|
||||
tio_error_printf("Invalid parity");
|
||||
exit(EXIT_FAILURE);
|
||||
case PARITY_NONE:
|
||||
tio.c_cflag &= ~PARENB;
|
||||
break;
|
||||
|
||||
case PARITY_ODD:
|
||||
tio.c_cflag |= PARENB;
|
||||
tio.c_cflag |= PARODD;
|
||||
break;
|
||||
|
||||
case PARITY_EVEN:
|
||||
tio.c_cflag |= PARENB;
|
||||
tio.c_cflag &= ~PARODD;
|
||||
break;
|
||||
|
||||
case PARITY_MARK:
|
||||
tio.c_cflag |= PARENB;
|
||||
tio.c_cflag |= PARODD;
|
||||
tio.c_cflag |= CMSPAR;
|
||||
break;
|
||||
|
||||
case PARITY_SPACE:
|
||||
tio.c_cflag |= PARENB;
|
||||
tio.c_cflag &= ~PARODD;
|
||||
tio.c_cflag |= CMSPAR;
|
||||
break;
|
||||
|
||||
default:
|
||||
tio_error_printf("Invalid parity");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
/* Control, input, output, local modes for tty device */
|
||||
|
|
@ -1809,7 +1811,14 @@ void tty_search(void)
|
|||
return;
|
||||
|
||||
case AUTO_CONNECT_DIRECT:
|
||||
if (strlen(option.target) == TOPOLOGY_ID_SIZE)
|
||||
if (config.device != NULL)
|
||||
{
|
||||
// Prioritize any found pattern first
|
||||
device_name = config.device;
|
||||
|
||||
return;
|
||||
}
|
||||
else if (strlen(option.target) == TOPOLOGY_ID_SIZE)
|
||||
{
|
||||
// Potential topology ID detected -> trigger device search
|
||||
tty_search_for_serial_devices();
|
||||
|
|
@ -1829,6 +1838,12 @@ void tty_search(void)
|
|||
}
|
||||
}
|
||||
|
||||
if (config.device != NULL)
|
||||
{
|
||||
device_name = config.device;
|
||||
break;
|
||||
}
|
||||
|
||||
// Fallback to using tty device provided via cmdline target
|
||||
device_name = option.target;
|
||||
break;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue