]> git.sur5r.net Git - tio/commitdiff
Imported Upstream version 1.14 upstream/1.14
authorJakob Haufe <sur5r@sur5r.net>
Sat, 21 May 2016 19:46:23 +0000 (21:46 +0200)
committerJakob Haufe <sur5r@sur5r.net>
Sat, 21 May 2016 19:46:23 +0000 (21:46 +0200)
ChangeLog
configure
configure.ac
man/tio.1
src/error.c
src/include/tio/error.h
src/include/tio/options.h
src/include/tio/tty.h
src/log.c
src/options.c
src/tty.c

index e105ad58dd9f78efb870378fb61da9ba619700df..ee4a8d62396069237b08e80019fae387c226b670 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,4 +1,59 @@
-=== tio v1.12 ===
+=== tio v1.14 ===
+
+
+
+Changes since tio v1.13:
+
+ * Fixed tio_printf macro
+
+ * Fixed launch hints
+
+   Fixed launch hints not being printed in no autoconnect mode.
+
+ * Added 'ctrl-t ?' to list available commands
+
+ * Fixed log mechanism
+
+   To avoid echoing only log what is received from tty device.
+
+ * Improved tio output
+
+   Added titles and indentation to commands output for clearer separation
+   when firing commands repeatedly.
+
+   Also added print of tio version and quit command hint at launch.
+
+ * Cleaned up tio print mechanism
+
+Jakub Wilk:
+
+ * Fixed grammar
+
+   "allow" is a transitive verb, which requires an object,
+   so "allow to <verb>" is ungrammatical.
+
+ * Fixed typo
+
+
+
+Changes since tio v1.12:
+
+ * Fixed some error prints
+
+ * Fixed error printing for no autoconnect mode
+
+   Always print errors but only print silent errors when in no autoconnect
+   mode.
+
+ * Added key command for showing session settings
+
+   A new key command "ctrl-t i" is added to allow the user to display the
+   various session settings information (baudrate, databits, log file, etc.).
+
+   This is useful in case you have a running session but have forgotten
+   what the settings are.
+
+
 
 Changes since tio v1.11:
 
@@ -24,7 +79,7 @@ Changes since tio v1.11:
    send the ctrl-t key code. This is inspired by screen which does similar
    to send its command key code (ctrl-a a).
 
-   This change also allows to easier add new key commands if needed.
+   This change also eases adding new key commands if needed.
 
    Updated man page accordingly.
 
index 4da23238c1218fb6d668c3028be217c607499521..96758e100cf4739caa40a9e35cabe2b473346d86 100755 (executable)
--- a/configure
+++ b/configure
@@ -1,6 +1,6 @@
 #! /bin/sh
 # Guess values for system-dependent variables and create Makefiles.
-# Generated by GNU Autoconf 2.69 for tio 1.12.
+# Generated by GNU Autoconf 2.69 for tio 1.14.
 #
 #
 # Copyright (C) 1992-1996, 1998-2012 Free Software Foundation, Inc.
@@ -576,8 +576,8 @@ MAKEFLAGS=
 # Identity of this package.
 PACKAGE_NAME='tio'
 PACKAGE_TARNAME='tio'
-PACKAGE_VERSION='1.12'
-PACKAGE_STRING='tio 1.12'
+PACKAGE_VERSION='1.14'
+PACKAGE_STRING='tio 1.14'
 PACKAGE_BUGREPORT=''
 PACKAGE_URL='https://tio.github.io'
 
@@ -1247,7 +1247,7 @@ if test "$ac_init_help" = "long"; then
   # Omit some internal or obsolete options to make the list less imposing.
   # This message is too long to be a string in the A/UX 3.1 sh.
   cat <<_ACEOF
-\`configure' configures tio 1.12 to adapt to many kinds of systems.
+\`configure' configures tio 1.14 to adapt to many kinds of systems.
 
 Usage: $0 [OPTION]... [VAR=VALUE]...
 
@@ -1314,7 +1314,7 @@ fi
 
 if test -n "$ac_init_help"; then
   case $ac_init_help in
-     short | recursive ) echo "Configuration of tio 1.12:";;
+     short | recursive ) echo "Configuration of tio 1.14:";;
    esac
   cat <<\_ACEOF
 
@@ -1422,7 +1422,7 @@ fi
 test -n "$ac_init_help" && exit $ac_status
 if $ac_init_version; then
   cat <<\_ACEOF
-tio configure 1.12
+tio configure 1.14
 generated by GNU Autoconf 2.69
 
 Copyright (C) 2012 Free Software Foundation, Inc.
@@ -1477,7 +1477,7 @@ cat >config.log <<_ACEOF
 This file contains any messages produced by compilers while
 running configure, to aid debugging if configure makes a mistake.
 
-It was created by tio $as_me 1.12, which was
+It was created by tio $as_me 1.14, which was
 generated by GNU Autoconf 2.69.  Invocation command line was
 
   $ $0 $@
@@ -2342,7 +2342,7 @@ fi
 
 # Define the identity of the package.
  PACKAGE='tio'
- VERSION='1.12'
+ VERSION='1.14'
 
 
 cat >>confdefs.h <<_ACEOF
@@ -4476,7 +4476,7 @@ cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
 # report actual input values of CONFIG_FILES etc. instead of their
 # values after options handling.
 ac_log="
-This file was extended by tio $as_me 1.12, which was
+This file was extended by tio $as_me 1.14, which was
 generated by GNU Autoconf 2.69.  Invocation command line was
 
   CONFIG_FILES    = $CONFIG_FILES
@@ -4543,7 +4543,7 @@ _ACEOF
 cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
 ac_cs_config="`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`"
 ac_cs_version="\\
-tio config.status 1.12
+tio config.status 1.14
 configured by $0, generated by GNU Autoconf 2.69,
   with options \\"\$ac_cs_config\\"
 
index 4d403508c06c220c8dc8c104c65960069af854ed..d76809b338fa75027469946b720df4948eaa9fa8 100644 (file)
@@ -1,5 +1,5 @@
 AC_PREREQ([2.68])
-AC_INIT([tio], [1.12], [], [tio], [https://tio.github.io])
+AC_INIT([tio], [1.14], [], [tio], [https://tio.github.io])
 AC_CONFIG_HEADERS([src/include/config.h])
 AM_INIT_AUTOMAKE([1.11 foreign dist-xz no-dist-gzip -Wall -Werror])
 AM_SILENT_RULES([yes])
index 953ecf5591d126e51d7aefa8bb0c92089ebb4d3f..4fd81ab3dc8425907035ca1e15c3e8891774bfc9 100644 (file)
--- a/man/tio.1
+++ b/man/tio.1
@@ -61,20 +61,24 @@ Display help.
 .PP
 .TP 16n
 In session, the following key sequences are intercepted as tio commands:
+.IP "\fBctrl-t ?"
+List available key commands
+.IP "\fBctrl-t i"
+Show settings information (baudrate, databits, etc.)
 .IP "\fBctrl-t q"
 Quit
 .IP "\fBctrl-t s"
-Show session statistics (total number of bytes transmitted/received)
+Show statistics (total number of bytes transmitted/received)
 .IP "\fBctrl-t t"
 Send ctrl-t key code
 
 .SH "EXAMPLES"
 .TP
-The most common use is without options. For example:
+A typical use is without options. For example:
 
 tio /dev/ttyUSB0
 .TP
-Which corresponds to:
+Which corresponds to the commonly used options:
 
 tio \-b 115200 \-d 8 \-f none \-s 1 \-p none /dev/ttyUSB0
 .TP
index ca5aa1873fac3d9714bcf09228f4dce02095597f..3bcadde097ad7b20254a6414504d79fba1f24f7d 100644 (file)
 #include "tio/print.h"
 #include "tio/error.h"
 
-char error[1000];
+char error[2][1000];
 
 void error_exit(void)
 {
-    if ((error[0] != 0) && (option.no_autoconnect))
-        printf("\rError: %s\r\n", error);
+    /* Always print errors but only print silent errors when in no autoconnect
+     * mode */
+    if (error[0][0] != 0)
+        printf("\rError: %s\r\n", error[0]);
+    else if ((error[1][0] != 0) && (option.no_autoconnect))
+        printf("\rError: %s\r\n", error[1]);
 }
index b770854ac82b5b3708f4f88fe15a76173e25e7e6..d41dcaa63d4276982de0aaf66d49b1f1387bb361 100644 (file)
 #define TIO_SUCCESS 0
 #define TIO_ERROR   1
 
-extern char error[1000];
+extern char error[2][1000];
 
 #define error_printf(format, args...) \
-   snprintf (error, 1000, format, ## args);
+   snprintf (error[0], 1000, format, ## args);
+
+#define error_printf_silent(format, args...) \
+   snprintf (error[1], 1000, format, ## args);
 
 void error_exit(void);
 
index 09e65b30c252a884cb631f7108830d2c0e0f7000..925a93f682d82b8ae12a3e8f1c9128fce0255041 100644 (file)
@@ -36,6 +36,11 @@ struct option_t
     bool no_autoconnect;
     int output_delay;
     struct termios tio;
+    int baudrate;
+    int databits;
+    char *flow;
+    int stopbits;
+    char *parity;
 };
 
 extern struct option_t option;
index cab663ecff26d007f5370b596f5ab822776f35af..0e4d651c9d7fa6a3de0b4a6cb16bc9f8f98d470b 100644 (file)
@@ -22,6 +22,8 @@
 #ifndef TTY_H
 #define TTY_H
 
+#define KEY_QUESTION 0x3f
+#define KEY_I 0x69
 #define KEY_Q 0x71
 #define KEY_S 0x73
 #define KEY_T 0x74
index f242606884771e6e15bf102ed24ebbbe0f80df28..1f04b34805029a271c176ebb5153bcf3cacd8ae0 100644 (file)
--- a/src/log.c
+++ b/src/log.c
 #include <errno.h>
 #include "tio/options.h"
 #include "tio/print.h"
+#include "tio/error.h"
 
 static FILE *fp;
-static bool error = false;
+static bool log_error = false;
 
 void log_open(const char *filename)
 {
@@ -35,7 +36,7 @@ void log_open(const char *filename)
 
     if (fp == NULL)
     {
-        error = true;
+        log_error = true;
         exit(EXIT_FAILURE);
     }
 }
@@ -57,6 +58,6 @@ void log_exit(void)
     if (option.log)
         log_close();
 
-    if (error)
-        printf("Error: Could not open log file %s (%s)\n", option.log_filename, strerror(errno));
+    if (log_error)
+        error_printf("Could not open log file %s (%s)", option.log_filename, strerror(errno));
 }
index 15b6f2a781272d947ab3d66f34e08f4d42fa9bff..7eb964bd7fb274da7bf505a1b3e5eda298b5dcc2 100644 (file)
@@ -39,6 +39,12 @@ struct option_t option =
     "",       // Log filename
     false,    // No autoconnect
     0,        // No output delay
+    {},
+    115200,   // Baudrate
+    8,        // Databits
+    "none",   // Flow
+    1,        // Stopbits
+    "none"    // Parity
 };
 
 void print_options_help(char *argv[])
@@ -65,8 +71,6 @@ void parse_options(int argc, char *argv[])
 {
     int c;
     int baudrate;
-    int databits;
-    int stopbits;
 
     if (argc == 1)
     {
@@ -122,7 +126,7 @@ void parse_options(int argc, char *argv[])
                 break;
 
             case 'b':
-                baudrate = atoi(optarg);
+                option.baudrate = baudrate = atoi(optarg);
                 switch (baudrate)
                 {
                     case 0:
@@ -223,9 +227,9 @@ void parse_options(int argc, char *argv[])
                 break;
 
             case 'd':
-                databits = atoi(optarg);
+                option.databits = atoi(optarg);
                 option.tio.c_cflag &= ~CSIZE;
-                switch (databits)
+                switch (option.databits)
                 {
                     case 5:
                         option.tio.c_cflag |= CS5;
@@ -246,6 +250,8 @@ void parse_options(int argc, char *argv[])
                 break;
 
             case 'f':
+                option.flow = optarg;
+
                 if (strcmp("hard", optarg) == 0)
                 {
                     option.tio.c_cflag |= CRTSCTS;
@@ -269,8 +275,8 @@ void parse_options(int argc, char *argv[])
                 break;
 
             case 's':
-                stopbits = atoi(optarg);
-                switch (stopbits)
+                option.stopbits = atoi(optarg);
+                switch (option.stopbits)
                 {
                     case 1:
                         option.tio.c_cflag &= ~CSTOPB;
@@ -285,6 +291,8 @@ void parse_options(int argc, char *argv[])
                 break;
 
             case 'p':
+                option.parity = optarg;
+
                 if (strcmp("odd", optarg) == 0)
                 {
                     option.tio.c_cflag |= PARENB;
index 6d318acefd00248ea4d787964cab4575adbb4b88..51c609ce2e68db557b1cfa68c8e565c2d1a15dc8 100644 (file)
--- a/src/tty.c
+++ b/src/tty.c
@@ -32,6 +32,7 @@
 #include <termios.h>
 #include <stdbool.h>
 #include <errno.h>
+#include "config.h"
 #include "tio/tty.h"
 #include "tio/print.h"
 #include "tio/options.h"
@@ -45,6 +46,13 @@ static bool connected = false;
 static bool tainted = false;
 static int fd;
 
+#define tio_printf(format, args...) \
+{ \
+    if (tainted) putchar('\n'); \
+    color_printf("[tio %s] " format, current_time(), ## args); \
+    tainted = false; \
+}
+
 void handle_command_sequence(char input_char, char previous_char, char *output_char, bool *forward)
 {
     char unused_char;
@@ -62,6 +70,28 @@ void handle_command_sequence(char input_char, char previous_char, char *output_c
     {
         switch (input_char)
         {
+            case KEY_QUESTION:
+                tio_printf("Key commands:");
+                tio_printf(" ctrl-t ?   List available key commands");
+                tio_printf(" ctrl-t i   Show settings information");
+                tio_printf(" ctrl-t q   Quit");
+                tio_printf(" ctrl-t s   Show statistics");
+                tio_printf(" ctrl-t t   Send ctrl-t key code");
+                *forward = false;
+                break;
+            case KEY_I:
+                tio_printf("Settings information:");
+                tio_printf(" TTY device: %s", option.tty_device);
+                tio_printf(" Baudrate: %d", option.baudrate);
+                tio_printf(" Databits: %d", option.databits);
+                tio_printf(" Flow: %s", option.flow);
+                tio_printf(" Stopbits: %d", option.stopbits);
+                tio_printf(" Parity: %s", option.parity);
+                tio_printf(" Output delay: %d", option.output_delay);
+                if (option.log)
+                    tio_printf(" Log file: %s", option.log_filename);
+                *forward = false;
+                break;
             case KEY_Q:
                 /* Exit upon ctrl-t q sequence */
                 exit(EXIT_SUCCESS);
@@ -71,10 +101,8 @@ void handle_command_sequence(char input_char, char previous_char, char *output_c
                 break;
             case KEY_S:
                 /* Show tx/rx statistics upon ctrl-t s sequence */
-                if (tainted)
-                    putchar('\n');
-                color_printf("[tio %s] Sent %ld bytes, received %ld bytes", current_time(), tx_total, rx_total);
-                tainted = false;
+                tio_printf("Statistics:");
+                tio_printf(" Sent %ld bytes, received %ld bytes", tx_total, rx_total);
                 *forward = false;
                 break;
             default:
@@ -169,6 +197,10 @@ void configure_stdout(void)
     tcsetattr(STDOUT_FILENO, TCSANOW, &new_stdout);
     tcsetattr(STDOUT_FILENO, TCSAFLUSH, &new_stdout);
 
+    /* Print launch hints */
+    tio_printf("tio v%s", VERSION);
+    tio_printf("Press ctrl-t + q to quit");
+
     /* Make sure we restore old stdout settings on exit */
     atexit(&restore_stdout);
 }
@@ -181,12 +213,9 @@ void restore_stdout(void)
 
 void disconnect_tty(void)
 {
-    if (tainted)
-        putchar('\n');
-
     if (connected)
     {
-        color_printf("[tio %s] Disconnected", current_time());
+        tio_printf("Disconnected");
         flock(fd, LOCK_UN);
         close(fd);
         connected = false;
@@ -215,14 +244,14 @@ int connect_tty(void)
     fd = open(option.tty_device, O_RDWR | O_NOCTTY );
     if (fd < 0)
     {
-        error_printf("Could not open tty device (%s)", strerror(errno));
+        error_printf_silent("Could not open tty device (%s)", strerror(errno));
         goto error_open;
     }
 
     /* Make sure device is of tty type */
     if (!isatty(fd))
     {
-        error_printf("Not a tty device");
+        error_printf_silent("Not a tty device");
         goto error_isatty;
     }
 
@@ -230,7 +259,7 @@ int connect_tty(void)
     status = flock(fd, LOCK_EX | LOCK_NB);
     if ((status == -1) && (errno == EWOULDBLOCK))
     {
-        printf("Error: Device file is locked by another process\r\n");
+        error_printf("Device file is locked by another process");
         exit(EXIT_FAILURE);
     }
 
@@ -238,7 +267,7 @@ int connect_tty(void)
     tcflush(fd, TCIOFLUSH);
 
     /* Print connect status */
-    color_printf("[tio %s] Connected", current_time());
+    tio_printf("Connected");
     connected = true;
     tainted = false;
 
@@ -300,7 +329,7 @@ int connect_tty(void)
                 } else
                 {
                     /* Error reading - device is likely unplugged */
-                    error_printf("Could not read from tty device");
+                    error_printf_silent("Could not read from tty device");
                     goto error_read;
                 }
             }
@@ -312,7 +341,7 @@ int connect_tty(void)
                 status = read(STDIN_FILENO, &input_char, 1);
                 if (status <= 0)
                 {
-                    error_printf("Could not read from stdin");
+                    error_printf_silent("Could not read from stdin");
                     goto error_read;
                 }
 
@@ -331,10 +360,6 @@ int connect_tty(void)
                     if (status < 0)
                         warning_printf("Could not write to tty device");
 
-                    /* Write to log */
-                    if (option.log)
-                        log_write(output_char);
-
                     /* Update transmit statistics */
                     tx_total++;