From e2abf2a277305531c449143383ccba2748376498 Mon Sep 17 00:00:00 2001 From: Jakob Haufe Date: Sat, 21 May 2016 21:46:23 +0200 Subject: [PATCH] Imported Upstream version 1.14 --- ChangeLog | 59 +++++++++++++++++++++++++++++++++++-- configure | 20 ++++++------- configure.ac | 2 +- man/tio.1 | 10 +++++-- src/error.c | 10 +++++-- src/include/tio/error.h | 7 +++-- src/include/tio/options.h | 5 ++++ src/include/tio/tty.h | 2 ++ src/log.c | 9 +++--- src/options.c | 22 +++++++++----- src/tty.c | 61 +++++++++++++++++++++++++++------------ 11 files changed, 157 insertions(+), 50 deletions(-) diff --git a/ChangeLog b/ChangeLog index e105ad5..ee4a8d6 100644 --- 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 " 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. diff --git a/configure b/configure index 4da2323..96758e1 100755 --- 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\\" diff --git a/configure.ac b/configure.ac index 4d40350..d76809b 100644 --- a/configure.ac +++ b/configure.ac @@ -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]) diff --git a/man/tio.1 b/man/tio.1 index 953ecf5..4fd81ab 100644 --- 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 diff --git a/src/error.c b/src/error.c index ca5aa18..3bcadde 100644 --- a/src/error.c +++ b/src/error.c @@ -27,10 +27,14 @@ #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]); } diff --git a/src/include/tio/error.h b/src/include/tio/error.h index b770854..d41dcaa 100644 --- a/src/include/tio/error.h +++ b/src/include/tio/error.h @@ -25,10 +25,13 @@ #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); diff --git a/src/include/tio/options.h b/src/include/tio/options.h index 09e65b3..925a93f 100644 --- a/src/include/tio/options.h +++ b/src/include/tio/options.h @@ -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; diff --git a/src/include/tio/tty.h b/src/include/tio/tty.h index cab663e..0e4d651 100644 --- a/src/include/tio/tty.h +++ b/src/include/tio/tty.h @@ -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 diff --git a/src/log.c b/src/log.c index f242606..1f04b34 100644 --- a/src/log.c +++ b/src/log.c @@ -25,9 +25,10 @@ #include #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)); } diff --git a/src/options.c b/src/options.c index 15b6f2a..7eb964b 100644 --- a/src/options.c +++ b/src/options.c @@ -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; diff --git a/src/tty.c b/src/tty.c index 6d318ac..51c609c 100644 --- a/src/tty.c +++ b/src/tty.c @@ -32,6 +32,7 @@ #include #include #include +#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++; -- 2.39.2