]> git.sur5r.net Git - tio/commitdiff
New upstream version 1.26 upstream/1.26
authorJakob Haufe <sur5r@sur5r.net>
Tue, 7 Nov 2017 22:02:41 +0000 (23:02 +0100)
committerJakob Haufe <sur5r@sur5r.net>
Tue, 7 Nov 2017 22:02:41 +0000 (23:02 +0100)
12 files changed:
AUTHORS
ChangeLog
README
configure
configure.ac
man/tio.1
src/bash-completion/tio.in
src/include/tio/options.h
src/include/tio/tty.h
src/main.c
src/options.c
src/tty.c

diff --git a/AUTHORS b/AUTHORS
index 5d44e15d8d937f35d24a058a37101b0786f2c725..68f60bbdb35554e1793ef6fb2242942f1468916a 100644 (file)
--- a/AUTHORS
+++ b/AUTHORS
@@ -9,5 +9,7 @@ Jakub Wilk <jwilk@jwilk.net>
 Martin Hundeboll <martin@hundeboll.net>
 Nick Ã˜stergaard <oe.nick@gmail.com>
 Adam Borowski <kilobyte@angband.pl>
+Robert Scheck <robert@fedoraproject.org>
+Dmitri Goutnik <dg@syrec.org>
 
 Thanks to everyone who has contributed to this project.
index 21022e908f61bd264d06cc498f38d8aa0254a855..bd42d2d160e371f5a5615d6d0465ee9710dd5999 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,29 @@
 
-=== tio v1.25 ===
+=== tio v1.26 ===
+
+
+Changes since tio v1.25:
+
+ * Reconfigure stdin
+
+   Make stdin behave more raw'ish. In particular, don't
+   translate CR -> NL on input.
+
+ * 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.
+
+ * Cleanup
+
+ * Update AUTHORS
+
+ * Update README
+
+ * Mention website
+
+ * Update man page
+
 
 
 Changes since tio v1.24:
diff --git a/README b/README
index 20c161f0bd3c3d5c8b09708b50f002e17385b5d3..0491598c9e26e1deffd85e18e6b8e1f5b9078dbc 100644 (file)
--- a/README
+++ b/README
@@ -30,6 +30,7 @@
           -o, --output-delay <ms>     Output delay (default: 0)
           -n, --no-autoconnect        Disable automatic connect
           -l, --log <filename>        Log to file
+          -m, --map <flags>           Map special characters
           -v, --version               Display version
           -h, --help                  Display help
 
@@ -62,7 +63,7 @@
 
 4. Installation
 
-    Installation steps (from source):
+4.1 Installation from source:
 
     $ ./configure
     $ make
     See INSTALL file for more installation details.
 
 
-    Installation steps (binary package):
+4.2 Installation using package:
 
     Tio comes prepackaged for various GNU/Linux distributions. Visit
-    https://tio.github.io to see package installation details.
+    https://tio.github.io for package installation details.
 
 
 5. Contributing
     Submit bug reports via GitHub: https://github.com/tio/tio/issues
 
 
-7. License
+7. Website
+
+    Visit https://tio.github.io
+
+
+8. License
 
     Tio is GPLv2+. See COPYING file for license details.
 
 
-8. Authors
+9. Authors
 
     Created by Martin Lund <martin.lund@keep-it-simple.com>
 
index 47681e36e52f499bf89e9ede2686c9581a1000c1..e682972a156b7a140b56a3edd6423fe93d553048 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.25.
+# Generated by GNU Autoconf 2.69 for tio 1.26.
 #
 #
 # 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.25'
-PACKAGE_STRING='tio 1.25'
+PACKAGE_VERSION='1.26'
+PACKAGE_STRING='tio 1.26'
 PACKAGE_BUGREPORT=''
 PACKAGE_URL='https://tio.github.io'
 
@@ -1239,7 +1239,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.25 to adapt to many kinds of systems.
+\`configure' configures tio 1.26 to adapt to many kinds of systems.
 
 Usage: $0 [OPTION]... [VAR=VALUE]...
 
@@ -1306,7 +1306,7 @@ fi
 
 if test -n "$ac_init_help"; then
   case $ac_init_help in
-     short | recursive ) echo "Configuration of tio 1.25:";;
+     short | recursive ) echo "Configuration of tio 1.26:";;
    esac
   cat <<\_ACEOF
 
@@ -1405,7 +1405,7 @@ fi
 test -n "$ac_init_help" && exit $ac_status
 if $ac_init_version; then
   cat <<\_ACEOF
-tio configure 1.25
+tio configure 1.26
 generated by GNU Autoconf 2.69
 
 Copyright (C) 2012 Free Software Foundation, Inc.
@@ -1506,7 +1506,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.25, which was
+It was created by tio $as_me 1.26, which was
 generated by GNU Autoconf 2.69.  Invocation command line was
 
   $ $0 $@
@@ -2371,7 +2371,7 @@ fi
 
 # Define the identity of the package.
  PACKAGE='tio'
- VERSION='1.25'
+ VERSION='1.26'
 
 
 cat >>confdefs.h <<_ACEOF
@@ -4966,7 +4966,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.25, which was
+This file was extended by tio $as_me 1.26, which was
 generated by GNU Autoconf 2.69.  Invocation command line was
 
   CONFIG_FILES    = $CONFIG_FILES
@@ -5033,7 +5033,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.25
+tio config.status 1.26
 configured by $0, generated by GNU Autoconf 2.69,
   with options \\"\$ac_cs_config\\"
 
index fd4c1cce23c9a317fa34cad900388fb23499c370..c030d4fc8ffb94bde2d218fc412a226cce20ab9e 100644 (file)
@@ -1,5 +1,5 @@
 AC_PREREQ([2.68])
-AC_INIT([tio], [1.25], [], [tio], [https://tio.github.io])
+AC_INIT([tio], [1.26], [], [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 13385339419523e005ac7341d8cc0acc8d01c65d..4e122b96f0d4b939923c95d20acccb57b65b809d 100644 (file)
--- a/man/tio.1
+++ b/man/tio.1
@@ -1,4 +1,4 @@
-.TH "tio" "1" "September 2017"
+.TH "tio" "1" "October 2017"
 
 .SH "NAME"
 tio \- a simple TTY terminal I/O application
@@ -6,7 +6,7 @@ tio \- a simple TTY terminal I/O application
 .SH "SYNOPSIS"
 .PP
 .B tio
-.RI "[" <options> "] " "<tty device>"
+.RI "[" <options> "] " "<tty-device>"
 
 .SH "DESCRIPTION"
 .PP
@@ -55,6 +55,28 @@ option is provided, tio will exit if the device is not present or an established
 .BR \-l ", " "\-\-log " \fI<filename>
 
 Log to file.
+
+.TP
+.BR \-m ", " "\-\-map " \fI<flags>
+
+Map (replace, translate) special characters on input or output. The following mapping flags are supported:
+
+.RS
+.TP 8n
+.IP "\fBINLCR"
+Translate NL to CR on input.
+.IP "\fBIGNCR"
+Ignore carriage return on input.
+.IP "\fBICRNL"
+Translate carriage return to newline on input (unless IGNCR is set).
+.IP "\fBONLCR"
+Map NL to CR-NL on output.
+.IP "\fBOCRNL"
+Map CR to NL on output.
+.P
+If defining more than one flag, the flags must be comma separated.
+.RE
+
 .TP
 .BR \-v ", " \-\-version
 
@@ -102,6 +124,10 @@ tio /dev/serial/by\-id/usb\-FTDI_TTL232R-3V3_FTGQVXBL\-if00\-port0
 Using serial devices by id ensures that tio automatically reconnects to the
 correct serial device if the device is disconnected and then reconnected.
 
+.SH "WEBSITE"
+.PP
+Visit https://tio.github.io
+
 .SH "AUTHOR"
 .PP
 Written by Martin Lund <martin.lund@keep\-it\-simple.com>.
index 0f8dde438fda34b06c2664187d9b7028b64d2a7a..431b1cc27561635cab2cf2e5b28464ef8f6dd7ef 100644 (file)
@@ -18,6 +18,7 @@ _tio()
           -o --output-delay \
           -n --no-autoconnect \
           -l --log \
+          -m --map \
           -v --version \
           -h --help"
 
@@ -56,6 +57,10 @@ _tio()
             COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
             return 0
             ;;
+        -m | --map)
+            COMPREPLY=( $(compgen -W "INLCR IGNCR ICRNL ONLCR OCRNL" -- ${cur}) )
+            return 0
+            ;;
         -v | --version)
             COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
             return 0
index 15f3cf79ee5c46404cb3e353fe824c9841932f69..b41f34082b289f5282dd80053853223ed9bc3214 100644 (file)
@@ -40,6 +40,7 @@ struct option_t
     bool no_autoconnect;
     bool log;
     const char *log_filename;
+    const char *map;
 };
 
 extern struct option_t option;
index 9b48751444bfc478b25eb1e4c748af964220486d..cfc2610e32d2444c4d7257d59d9d55ca92b8bf14 100644 (file)
@@ -37,6 +37,8 @@
 
 void stdout_configure(void);
 void stdout_restore(void);
+void stdin_configure(void);
+void stdin_restore(void);
 void tty_configure(void);
 int tty_connect(void);
 void tty_wait_for_device(void);
index 683c62740cf12985d348f741bd6e6dfcee7448ac..83c060a478820ac933b6fe745aa72764f8145620 100644 (file)
@@ -42,6 +42,9 @@ int main(int argc, char *argv[])
     /* Configure tty device */
     tty_configure();
 
+    /* Configure input terminal */
+    stdin_configure();
+
     /* Configure output terminal */
     stdout_configure();
 
index 67275c39b2da61f2d566651d0e77cdced6ca6c44..fa47f6032a585a1d11de2b5bbc87de03d9d63756 100644 (file)
@@ -25,6 +25,7 @@
 #include <string.h>
 #include <stdlib.h>
 #include <stdio.h>
+#include <stdbool.h>
 #include <errno.h>
 #include <getopt.h>
 #include <termios.h>
@@ -44,7 +45,8 @@ struct option_t option =
     0,        // No output delay
     false,    // No autoconnect
     false,    // No log
-    ""        // Log filename
+    "",       // Log filename
+    ""        // Map string
 };
 
 void print_help(char *argv[])
@@ -60,6 +62,7 @@ void print_help(char *argv[])
     printf("  -o, --output-delay <ms>     Output delay (default: 0)\n");
     printf("  -n, --no-autoconnect        Disable automatic connect\n");
     printf("  -l, --log <filename>        Log to file\n");
+    printf("  -m, --map <flags>           Map special characters\n");
     printf("  -v, --version               Display version\n");
     printf("  -h, --help                  Display help\n");
     printf("\n");
@@ -105,6 +108,7 @@ void parse_options(int argc, char *argv[])
             {"output-delay",   required_argument, 0, 'o'},
             {"no-autoconnect", no_argument,       0, 'n'},
             {"log",            required_argument, 0, 'l'},
+            {"map",            required_argument, 0, 'm'},
             {"version",        no_argument,       0, 'v'},
             {"help",           no_argument,       0, 'h'},
             {0,                0,                 0,  0 }
@@ -114,7 +118,7 @@ void parse_options(int argc, char *argv[])
         int option_index = 0;
 
         /* Parse argument using getopt_long */
-        c = getopt_long(argc, argv, "b:d:f:s:p:o:nl:vh", long_options, &option_index);
+        c = getopt_long(argc, argv, "b:d:f:s:p:o:nl:m:vh", long_options, &option_index);
 
         /* Detect the end of the options */
         if (c == -1)
@@ -165,6 +169,10 @@ void parse_options(int argc, char *argv[])
                 option.log_filename = optarg;
                 break;
 
+            case 'm':
+                option.map = optarg;
+                break;
+
             case 'v':
                 printf("tio v%s\n", VERSION);
                 printf("Copyright (c) 2014-2017 Martin Lund\n");
index 88de59ba638672a31a6b827ba25b0037408fc66c..60d6c15ad117b145b65d5354030c2bf8ed01cd25 100644 (file)
--- a/src/tty.c
+++ b/src/tty.c
@@ -42,7 +42,7 @@
 #include "tio/log.h"
 #include "tio/error.h"
 
-static struct termios tio, new_stdout, old_stdout, old_tio;
+static struct termios tio, tio_old, stdout_new, stdout_old, stdin_new, stdin_old;
 static unsigned long rx_total = 0, tx_total = 0;
 static bool connected = false;
 static bool tainted = false;
@@ -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;
@@ -161,30 +163,70 @@ void handle_command_sequence(char input_char, char previous_char, char *output_c
     }
 }
 
+void stdin_configure(void)
+{
+    int status;
+
+    /* Save current stdin settings */
+    if (tcgetattr(STDIN_FILENO, &stdin_old) < 0)
+    {
+        error_printf("Saving current stdin settings failed");
+        exit(EXIT_FAILURE);
+    }
+
+    /* Prepare new stdin settings */
+    memcpy(&stdin_new, &stdin_old, sizeof(stdin_old));
+
+    /* Reconfigure stdin (RAW configuration) */
+    stdin_new.c_iflag &= ~(ICRNL); // Do not translate CR -> NL on input
+    stdin_new.c_oflag &= ~(OPOST);
+    stdin_new.c_lflag &= ~(ECHO|ICANON|ISIG|ECHOE|ECHOK|ECHONL);
+
+    /* Control characters */
+    stdin_new.c_cc[VTIME] = 0; /* Inter-character timer unused */
+    stdin_new.c_cc[VMIN]  = 1; /* Blocking read until 1 character received */
+
+    /* Activate new stdin settings */
+    status = tcsetattr(STDIN_FILENO, TCSANOW, &stdin_new);
+    if (status == -1)
+    {
+        error_printf("Could not apply new stdin settings (%s)", strerror(errno));
+        exit(EXIT_FAILURE);
+    }
+
+    /* Make sure we restore old stdin settings on exit */
+    atexit(&stdin_restore);
+}
+
+void stdin_restore(void)
+{
+    tcsetattr(STDIN_FILENO, TCSANOW, &stdin_old);
+}
+
 void stdout_configure(void)
 {
     int status;
 
     /* Save current stdout settings */
-    if (tcgetattr(STDOUT_FILENO, &old_stdout) < 0)
+    if (tcgetattr(STDOUT_FILENO, &stdout_old) < 0)
     {
         error_printf("Saving current stdio settings failed");
         exit(EXIT_FAILURE);
     }
 
     /* Prepare new stdout settings */
-    memcpy(&new_stdout, &old_stdout, sizeof(old_stdout));
+    memcpy(&stdout_new, &stdout_old, sizeof(stdout_old));
 
     /* Reconfigure stdout (RAW configuration) */
-    new_stdout.c_oflag &= ~(OPOST);
-    new_stdout.c_lflag &= ~(ECHO|ICANON|ISIG|ECHOE|ECHOK|ECHONL);
+    stdout_new.c_oflag &= ~(OPOST);
+    stdout_new.c_lflag &= ~(ECHO|ICANON|ISIG|ECHOE|ECHOK|ECHONL);
 
     /* Control characters */
-    new_stdout.c_cc[VTIME] = 0; /* Inter-character timer unused */
-    new_stdout.c_cc[VMIN]  = 1; /* Blocking read until 1 character received */
+    stdout_new.c_cc[VTIME] = 0; /* Inter-character timer unused */
+    stdout_new.c_cc[VMIN]  = 1; /* Blocking read until 1 character received */
 
     /* Activate new stdout settings */
-    status = tcsetattr(STDOUT_FILENO, TCSANOW, &new_stdout);
+    status = tcsetattr(STDOUT_FILENO, TCSANOW, &stdout_new);
     if (status == -1)
     {
         error_printf("Could not apply new stdout settings (%s)", strerror(errno));
@@ -204,11 +246,14 @@ void stdout_configure(void)
 
 void stdout_restore(void)
 {
-    tcsetattr(STDOUT_FILENO, TCSANOW, &old_stdout);
+    tcsetattr(STDOUT_FILENO, TCSANOW, &stdout_old);
 }
 
 void tty_configure(void)
 {
+    bool token_found = true;
+    char *token = NULL;
+    char *buffer;
     int status;
     speed_t baudrate;
 
@@ -326,6 +371,48 @@ void tty_configure(void)
         error_printf("Invalid parity");
         exit(EXIT_FAILURE);
     }
+
+    /* Control, input, output, local modes for tty device */
+    tio.c_cflag |= CLOCAL | CREAD;
+    tio.c_oflag = 0;
+    tio.c_lflag = 0;
+
+    /* 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)
@@ -399,7 +486,7 @@ void tty_disconnect(void)
 
 void tty_restore(void)
 {
-    tcsetattr(fd, TCSANOW, &old_tio);
+    tcsetattr(fd, TCSANOW, &tio_old);
 
     if (connected)
         tty_disconnect();
@@ -446,7 +533,7 @@ int tty_connect(void)
     tainted = false;
 
     /* Save current port settings */
-    if (tcgetattr(fd, &old_tio) < 0)
+    if (tcgetattr(fd, &tio_old) < 0)
         goto error_tcgetattr;
 
     /* Make sure we restore tty settings on exit */
@@ -456,15 +543,6 @@ int tty_connect(void)
         first = false;
     }
 
-    /* Control, input, output, local modes for tty device */
-    tio.c_cflag |= CLOCAL | CREAD;
-    tio.c_oflag = 0;
-    tio.c_lflag = 0;
-
-    /* Control characters */
-    tio.c_cc[VTIME] = 0; /* Inter-character timer unused */
-    tio.c_cc[VMIN]  = 1; /* Blocking read until 1 character received */
-
     /* Activate new port settings */
     status = tcsetattr(fd, TCSANOW, &tio);
     if (status == -1)