]> git.sur5r.net Git - tio/commitdiff
New upstream version 2.5
authorJakob Haufe <sur5r@debian.org>
Tue, 27 Dec 2022 23:15:42 +0000 (00:15 +0100)
committerJakob Haufe <sur5r@debian.org>
Tue, 27 Dec 2022 23:15:42 +0000 (00:15 +0100)
AUTHORS
NEWS
README.md
example/config [new file with mode: 0644]
example/tiorc [deleted file]
man/tio.1.in
man/tio.1.txt
meson.build
src/configfile.c
src/tty.c

diff --git a/AUTHORS b/AUTHORS
index 8f5cada3d161800fe84dac11ffa77a64e1150609..2941ec96ab3a79d6b23ed6b1947a18b3fd24f8ac 100644 (file)
--- a/AUTHORS
+++ b/AUTHORS
@@ -41,5 +41,6 @@ Rui Chen <rui@chenrui.dev>
 Ralph Siemsen <ralphs@netwinder.org>
 Victor Oliveira <rhapsodyv@gmail.com>
 Attila Veghelyi <aveghelyi@dension.com>
+Vyacheslav Patkov <slava@patkov.ru>
 
 Thanks to everyone who has contributed to this project.
diff --git a/NEWS b/NEWS
index 1de122c085fc6618ccb27084326ca719910b288c..cb608e073784664ce15f6846bfa2db86e58add26 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -1,5 +1,32 @@
 
-=== tio v2.4 ===
+=== tio v2.5 ===
+
+
+
+Changes since tio v2.4:
+
+ * Update configuration file documentation
+
+   Rename .tiorc to .tioconfig, tiorc to config, etc.
+
+ * Add support for $HOME/.tioconfig
+
+    Replaces what used to be $HOME/.tiorc
+
+ * Fix double prefix key regression
+
+Vyacheslav Patkov:
+
+ * Better error checking in config file, rename the file
+
+   Accept "true", "enable", "on", "yes", "1" as true values, their
+   counterparts as false ones. Check integer values for errors and range.
+   Warn about ignored (e.g. misspelled) options.
+
+   Check getenv() return value for NULL.
+
+   Rename "tiorc" to "config", as it's a static INI file, not an executable
+   "run commands".
 
 
 
index c58d4b47adde6d8c9c35ac6de6b0196a5a89978d..7625e85c693371a00ca92f286448fa01f9238574 100644 (file)
--- a/README.md
+++ b/README.md
@@ -198,9 +198,9 @@ If needed, the prefix key (ctrl-t) can be remapped via configuration file.
 
 Options can be set via the configuration file first found in any of the
 following locations in the order listed:
- - $XDG_CONFIG_HOME/tio/tiorc
- - $HOME/.config/tio/tiorc
- - $HOME/.tiorc
+ - $XDG_CONFIG_HOME/tio/config
+ - $HOME/.config/tio/config
+ - $HOME/.tioconfig
 
 The configuration file supports sub-configurations using named sections which can
 be activated via the command-line by name or pattern. A sub-configuration
@@ -240,7 +240,7 @@ Or by pattern match:
 $ tio usb12
 ```
 
-Another more elaborate configuration file example is available [here](example/tiorc).
+Another more elaborate configuration file example is available [here](example/config).
 
 ## 4. Installation
 
diff --git a/example/config b/example/config
new file mode 100644 (file)
index 0000000..05f96c9
--- /dev/null
@@ -0,0 +1,64 @@
+###############################
+# tio - https://tio.github.io #
+###############################
+
+# Example tio configuration file
+#
+# Place file in any of the following locations:
+#  $XDG_CONFIG_HOME/tio/config
+#  $HOME/.config/tio/config
+#  $HOME/.tioconfig
+
+# Defaults
+baudrate = 115200
+databits = 8
+flow = none
+stopbits = 1
+parity = none
+prefix-ctrl-key = t
+output-delay = 0
+output-line-delay = 0
+no-autoconnect = disable
+hexadecimal = disable
+timestamp = disable
+log = disable
+log-strip = disable
+local-echo = disable
+color = bold
+rs-485 = disable
+response-wait = disable
+alert = none
+
+# Sub-configuraions
+
+[rpi3]
+baudrate = 115200
+device = /dev/serial/by-id/usb-FTDI_FT232R_USB_UART_A6009HU3-if00-port0
+socket = unix:/tmp/tio-socket-0
+color = 9
+
+[am64-evm]
+baudrate = 115200
+device = /dev/serial/by-id/usb-Silicon_Labs_CP2105_Dual_USB_to_UART_Bridge_Controller_01093176-if01-port0
+line-pulse-duration = DTR=200,RTS=300,RI=50
+alert = bell
+color = 10
+
+[tincan]
+baudrate = 9600
+device = /dev/serial/by-id/usb-TinCanTools_Flyswatter2_FS20000-if00-port0
+log = enable
+log-file = tincan.log
+log-strip = enable
+color = 11
+
+[usb]
+pattern = usb([0-9]*)
+device = /dev/ttyUSB%s
+color = 12
+
+[rs-485-device]
+device = /dev/ttyUSB0
+rs-485 = enable
+rs-485-config = RTS_ON_SEND=1,RTS_AFTER_SEND=1,RTS_DELAY_BEFORE_SEND=60,RTS_DELAY_AFTER_SEND=80,RX_DURING_TX
+color = 13
diff --git a/example/tiorc b/example/tiorc
deleted file mode 100644 (file)
index 78a197b..0000000
+++ /dev/null
@@ -1,59 +0,0 @@
-###############################
-# tio - https://tio.github.io #
-###############################
-
-# Example configuration file
-
-# Defaults
-baudrate = 115200
-databits = 8
-flow = none
-stopbits = 1
-parity = none
-prefix-ctrl-key = t
-output-delay = 0
-output-line-delay = 0
-no-autoconnect = disable
-hexadecimal = disable
-timestamp = disable
-log = disable
-log-strip = disable
-local-echo = disable
-color = bold
-rs-485 = disable
-response-wait = disable
-alert = none
-
-# Sub-configuraions
-
-[rpi3]
-baudrate = 115200
-device = /dev/serial/by-id/usb-FTDI_FT232R_USB_UART_A6009HU3-if00-port0
-socket = unix:/tmp/tio-socket-0
-color = 9
-
-[am64-evm]
-baudrate = 115200
-device = /dev/serial/by-id/usb-Silicon_Labs_CP2105_Dual_USB_to_UART_Bridge_Controller_01093176-if01-port0
-line-pulse-duration = DTR=200,RTS=300,RI=50
-alert = bell
-color = 10
-
-[tincan]
-baudrate = 9600
-device = /dev/serial/by-id/usb-TinCanTools_Flyswatter2_FS20000-if00-port0
-log = enable
-log-file = tincan.log
-log-strip = enable
-color = 11
-
-[usb]
-pattern = usb([0-9]*)
-device = /dev/ttyUSB%s
-color = 12
-
-[rs-485-device]
-device = /dev/ttyUSB0
-rs-485 = enable
-rs-485-config = RTS_ON_SEND=1,RTS_AFTER_SEND=1,RTS_DELAY_BEFORE_SEND=60,RTS_DELAY_AFTER_SEND=80,RX_DURING_TX
-color = 13
index 1ec1355189b5a6a802369b060f91fe2d6a48cbbb..52523ee6074ccc94f0d3a267ca5550a7fbf5bb96 100644 (file)
@@ -332,11 +332,11 @@ the configuration file first found in the following locations in the order
 listed:
 
 .PP
-.I $XDG_CONFIG_HOME/tio/tiorc
+.I $XDG_CONFIG_HOME/tio/config
 .PP
-.I $HOME/.config/tio/tiorc
+.I $HOME/.config/tio/config
 .PP
-.I $HOME/.tiorc
+.I $HOME/.tioconfig
 
 .PP
 Labels can be used to group settings into named sub-configurations which can be
index aa26dcc28bd4871e9885af0546b4b714fcbf1ec6..c66269fd929108535b12bcda071498dafef97db3 100644 (file)
@@ -1,4 +1,4 @@
-tio(1)                                                                                                                              User Commands                                                                                                                             tio(1)
+tio(1)                                                                                                                User Commands                                                                                                               tio(1)
 
 NAME
        tio - a simple serial device I/O tool
@@ -66,7 +66,8 @@ OPTIONS
 
               Disable automatic connect.
 
-              By default tio automatically connects to the provided device if present. If the device is not present, it will wait for it to appear and then connect. If the connection is lost (eg. device disconnects), it will wait for the device to reappear and then reconnect.
+              By  default tio automatically connects to the provided device if present. If the device is not present, it will wait for it to appear and then connect. If the connection is lost (eg. device disconnects), it will wait for the device to
+              reappear and then reconnect.
 
               However, if the --no-autoconnect option is provided, tio will exit if the device is not present or an established connection is lost.
 
@@ -150,8 +151,8 @@ OPTIONS
 
               Redirect I/O to socket.
 
-              Any  input  from  clients connected to the socket is sent on the serial port as if entered at the terminal where tio is running (except that ctrl-t sequences are not recognized), and any input from the serial port is multiplexed to the terminal and all connected
-              clients.
+              Any input from clients connected to the socket is sent on the serial port as if entered at the terminal where tio is running (except that ctrl-t sequences are not recognized), and any input from the serial port is multiplexed  to  the
+              terminal and all connected clients.
 
               Sockets remain open while the serial port is disconnected, and writes will block.
 
@@ -258,11 +259,11 @@ HEXADECIMAL MODE
 CONFIGURATION FILE
        Options can be set via configuration file using the INI format. tio uses the configuration file first found in the following locations in the order listed:
 
-       $XDG_CONFIG_HOME/tio/tiorc
+       $XDG_CONFIG_HOME/tio/config
 
-       $HOME/.config/tio/tiorc
+       $HOME/.config/tio/config
 
-       $HOME/.tiorc
+       $HOME/.tioconfig
 
        Labels can be used to group settings into named sub-configurations which can be activated from the command-line when starting tio.
 
@@ -443,4 +444,4 @@ WEBSITE
 AUTHOR
        Created by Martin Lund <martin.lund@keep-it-simple.com>.
 
-tio 2.4                                                                                                                              2022-11-02                                                                                                                               tio(1)
+tio 2.5                                                                                                                2022-11-02                                                                                                                 tio(1)
index c394f8cb0f9188895034997e26bd41fd33630b7b..3fb3a22c6b92f8cc7e1015f3c32ddbbac3dfb828 100644 (file)
@@ -1,12 +1,12 @@
 project('tio', 'c',
-    version : '2.4',
+    version : '2.5',
     license : [ 'GPL-2'],
     meson_version : '>= 0.53.2',
     default_options : [ 'warning_level=2', 'buildtype=release', 'c_std=gnu99' ]
 )
 
 # The tag date of the project_version(), update when the version bumps.
-version_date = '2022-11-02'
+version_date = '2022-12-17'
 
 # Test for dynamic baudrate configuration interface
 compiler = meson.get_compiler('c')
index 8e29a26d2bfcb2b0c3b20df1be9954d7e361b4c1..d3dbd16aa159234cfe2112b9bce05647190cbd8a 100644 (file)
@@ -98,6 +98,40 @@ static int get_match(const char *input, const char *pattern, char **match)
     return len;
 }
 
+static bool read_boolean(const char *value, const char *name)
+{
+    const char *true_values[] = { "true", "enable", "on", "yes", "1", NULL };
+    const char *false_values[] = { "false", "disable", "off", "no", "0", NULL };
+
+    for (int i = 0; true_values[i] != NULL; i++)
+        if (strcmp(value, true_values[i]) == 0)
+            return true;
+
+    for (int i = 0; false_values[i] != NULL; i++)
+        if (strcmp(value, false_values[i]) == 0)
+            return false;
+
+    tio_error_printf("Invalid value '%s' for option '%s' in configuration file",
+            value, name);
+    exit(EXIT_FAILURE);
+}
+
+static long read_integer(const char *value, const char *name, long min_value, long max_value)
+{
+    errno = 0;
+    char *endptr;
+    long result = strtol(value, &endptr, 10);
+
+    if (errno || endptr == value || *endptr != '\0' || result < min_value || result > max_value)
+    {
+        tio_error_printf("Invalid value '%s' for option '%s' in configuration file",
+                value, name);
+        exit(EXIT_FAILURE);
+    }
+
+    return result;
+}
+
 /**
  * data_handler() - walk config file to load parameters matching user input
  *
@@ -119,11 +153,11 @@ static int data_handler(void *user, const char *section, const char *name,
         }
         else if (!strcmp(name, "baudrate"))
         {
-            option.baudrate = string_to_long((char *)value);
+            option.baudrate = read_integer(value, name, 0, LONG_MAX);
         }
         else if (!strcmp(name, "databits"))
         {
-            option.databits = atoi(value);
+            option.databits = read_integer(value, name, 5, 8);
         }
         else if (!strcmp(name, "flow"))
         {
@@ -132,7 +166,7 @@ static int data_handler(void *user, const char *section, const char *name,
         }
         else if (!strcmp(name, "stopbits"))
         {
-            option.stopbits = atoi(value);
+            option.stopbits = read_integer(value, name, 1, 2);
         }
         else if (!strcmp(name, "parity"))
         {
@@ -141,11 +175,11 @@ static int data_handler(void *user, const char *section, const char *name,
         }
         else if (!strcmp(name, "output-delay"))
         {
-            option.output_delay = atoi(value);
+            option.output_delay = read_integer(value, name, 0, LONG_MAX);
         }
         else if (!strcmp(name, "output-line-delay"))
         {
-            option.output_line_delay = atoi(value);
+            option.output_line_delay = read_integer(value, name, 0, LONG_MAX);
         }
         else if (!strcmp(name, "line-pulse-duration"))
         {
@@ -153,25 +187,11 @@ static int data_handler(void *user, const char *section, const char *name,
         }
         else if (!strcmp(name, "no-autoconnect"))
         {
-            if (!strcmp(value, "enable"))
-            {
-                option.no_autoconnect = true;
-            }
-            else if (!strcmp(value, "disable"))
-            {
-                option.no_autoconnect = false;
-            }
+            option.no_autoconnect = read_boolean(value, name);
         }
         else if (!strcmp(name, "log"))
         {
-            if (!strcmp(value, "enable"))
-            {
-                option.log = true;
-            }
-            else if (!strcmp(value, "disable"))
-            {
-                option.log = false;
-            }
+            option.log = read_boolean(value, name);
         }
         else if (!strcmp(name, "log-file"))
         {
@@ -180,47 +200,20 @@ static int data_handler(void *user, const char *section, const char *name,
         }
         else if (!strcmp(name, "log-strip"))
         {
-            if (!strcmp(value, "enable"))
-            {
-                option.log_strip = true;
-            }
-            else if (!strcmp(value, "disable"))
-            {
-                option.log_strip = false;
-            }
+            option.log_strip = read_boolean(value, name);
         }
         else if (!strcmp(name, "local-echo"))
         {
-            if (!strcmp(value, "enable"))
-            {
-                option.local_echo = true;
-            }
-            else if (!strcmp(value, "disable"))
-            {
-                option.local_echo = false;
-            }
+            option.local_echo = read_boolean(value, name);
         }
         else if (!strcmp(name, "hexadecimal"))
         {
-            if (!strcmp(value, "enable"))
-            {
-                option.hex_mode = true;
-            }
-            else if (!strcmp(value, "disable"))
-            {
-                option.hex_mode = false;
-            }
+            option.hex_mode = read_boolean(value, name);
         }
         else if (!strcmp(name, "timestamp"))
         {
-            if (!strcmp(value, "enable"))
-            {
-                option.timestamp = TIMESTAMP_24HOUR;
-            }
-            else if (!strcmp(value, "disable"))
-            {
-                option.timestamp = TIMESTAMP_NONE;
-            }
+            option.timestamp = read_boolean(value, name) ?
+                TIMESTAMP_24HOUR : TIMESTAMP_NONE;
         }
         else if (!strcmp(name, "timestamp-format"))
         {
@@ -270,29 +263,15 @@ static int data_handler(void *user, const char *section, const char *name,
         }
         else if (!strcmp(name, "response-wait"))
         {
-            if (!strcmp(value, "enable"))
-            {
-                option.response_wait = true;
-            }
-            else if (!strcmp(value, "disable"))
-            {
-                option.response_wait = false;
-            }
+            option.response_wait = read_boolean(value, name);
         }
         else if (!strcmp(name, "response-timeout"))
         {
-            option.response_timeout = atoi(value);
+            option.response_timeout = read_integer(value, name, 0, LONG_MAX);
         }
         else if (!strcmp(name, "rs-485"))
         {
-            if (!strcmp(value, "enable"))
-            {
-                option.rs485 = true;
-            }
-            else if (!strcmp(value, "disable"))
-            {
-                option.rs485 = false;
-            }
+            option.rs485 = read_boolean(value, name);
         }
         else if (!strcmp(name, "rs-485-config"))
         {
@@ -304,14 +283,11 @@ static int data_handler(void *user, const char *section, const char *name,
         }
         else if (!strcmp(name, "mute"))
         {
-            if (!strcmp(value, "enable"))
-            {
-                option.mute = true;
-            }
-            else if (!strcmp(value, "disable"))
-            {
-                option.mute = false;
-            }
+            option.mute = read_boolean(value, name);
+        }
+        else
+        {
+            tio_warning_printf("Unknown option '%s' in configuration file, ignored", name);
         }
     }
 
@@ -389,32 +365,36 @@ static int section_name_print_handler(void *user, const char *section, const cha
 
 static int resolve_config_file(void)
 {
-    asprintf(&c.path, "%s/tio/tiorc", getenv("XDG_CONFIG_HOME"));
-    if (!access(c.path, F_OK))
+    char *xdg = getenv("XDG_CONFIG_HOME");
+    if (xdg)
     {
-        return 0;
+        asprintf(&c.path, "%s/tio/config", xdg);
+        if (access(c.path, F_OK) == 0)
+        {
+            return 0;
+        }
+        free(c.path);
     }
 
-    free(c.path);
-
-    asprintf(&c.path, "%s/.config/tio/tiorc", getenv("HOME"));
-    if (!access(c.path, F_OK))
+    char *home = getenv("HOME");
+    if (home)
     {
-        return 0;
-    }
-
-    free(c.path);
+        asprintf(&c.path, "%s/.config/tio/config", home);
+        if (access(c.path, F_OK) == 0)
+        {
+            return 0;
+        }
+        free(c.path);
 
-    asprintf(&c.path, "%s/.tiorc", getenv("HOME"));
-    if (!access(c.path, F_OK))
-    {
-        return 0;
+        asprintf(&c.path, "%s/.tioconfig", home);
+        if (access(c.path, F_OK) == 0)
+        {
+            return 0;
+        }
+        free(c.path);
     }
 
-    free(c.path);
-
     c.path = NULL;
-
     return -EINVAL;
 }
 
index faad20c3a25324266d8acd7c3d3c073eab94ac91..f5ffc355fd330a42b88a06d64da6ce4b05d88aa9 100644 (file)
--- a/src/tty.c
+++ b/src/tty.c
@@ -306,10 +306,16 @@ void *tty_stdin_input_thread(void *arg)
 
                 if (previous_char == option.prefix_code)
                 {
+                    if (input_char == option.prefix_code)
+                    {
+                        previous_char = 0;
+                        continue;
+                    }
+
                     switch (input_char)
                     {
                         case KEY_Q:
-                            exit(EXIT_FAILURE);
+                            exit(EXIT_SUCCESS);
                             break;
                         case KEY_SHIFT_F:
                             tio_printf("Flushed data I/O channels")