[PATCH] - Adding timestamps to terminal output

Mark Einon mark.einon at gmail.com
Thu Feb 17 14:07:19 UTC 2011


Hello,

     I've been using minicom for some time, it's a really useful tool
- but have always lamented the fact that the terminal output cannot be
timestamped locally (useful if you're logging overnight etc.). So I've
modified the code to do this. Here is a patch against the current hg
tree with this addition, hopefully someone else will find it useful
too...

    Any feedback is most welcome.

Regards,
Mark Einon

------------------------------------------------------
src/dial.c    |    2 +-
src/help.c    |    5 ++---
src/ipc.c     |    6 +++---
src/minicom.c |   35 +++++++++++++++++++++++++++--------
src/minicom.h |    2 ++
src/vt100.c   |   26 +++++++++++++++++++++++++-
src/vt100.h   |    2 +-
7 files changed, 61 insertions(+), 17 deletions(-)
------------------------------------------------------

# HG changeset patch
# User mark.einon at gmail.com
# Date 1297949897 0
# Node ID 5619c4178e8e090c00154d06f69aa4683c2add12
# Parent  b4d7cc7b85058cc8739eddfda12823a825f28ab1
New option to timestamp terminal output
diff -r b4d7cc7b8505 -r 5619c4178e8e src/dial.c
--- a/src/dial.c Mon Feb 14 11:21:35 2011 +0100
+++ b/src/dial.c Thu Feb 17 13:38:17 2011 +0000
@@ -1416,7 +1416,7 @@
     mode_status();
   }
   newtype = d->term;
-  vt_set(-1, d->flags & FL_WRAP, -1, -1, d->flags & FL_ECHO, -1, -1);
+  vt_set(-1, d->flags & FL_WRAP, -1, -1, d->flags & FL_ECHO, -1, -1, -1);
   local_echo = d->flags & FL_ECHO;
   if (newtype != terminal)
     init_emul(newtype, 1);
diff -r b4d7cc7b8505 -r 5619c4178e8e src/help.c
--- a/src/help.c Mon Feb 14 11:21:35 2011 +0100
+++ b/src/help.c Thu Feb 17 13:38:17 2011 +0000
@@ -15,6 +15,7 @@
  *
  *
  *  26.02.1998 - acme at conectiva.com.br - i18n
+ *  mark.einon at gmail.com 16/02/11 - Added option to timestamp terminal output
  */
 #ifdef HAVE_CONFIG_H
 #include <config.h>
@@ -60,9 +61,7 @@
   mc_wputs(w, _(" Terminal settings..T  run Kermit.........K | Cursor
key mode....I\n"));
   mc_wputs(w, _(" lineWrap on/off....W"));
   mc_wputs(w, _("  local Echo on/off..E | Help screen........Z\n"));
-  mc_wputs(w, _(" Paste file.........Y"));
-  mc_wlocate(w, 44, 13);
-  mc_wputs(w, _("| scroll Back........B"));
+  mc_wputs(w, _(" Paste file.........Y  Timestamp on/off...N | scroll
Back........B"));

   mc_wlocate(w, 13, 16 + i);
   mc_wputs(w, _("Written by Miquel van Smoorenburg 1991-1995"));
diff -r b4d7cc7b8505 -r 5619c4178e8e src/ipc.c
--- a/src/ipc.c Mon Feb 14 11:21:35 2011 +0100
+++ b/src/ipc.c Thu Feb 17 13:38:17 2011 +0000
@@ -86,13 +86,13 @@
       escape = arg;
       break;
     case KSETBS:
-      vt_set(-1, -1, -1, arg, -1, -1, -1);
+      vt_set(-1, -1, -1, arg, -1, -1, -1, -1);
       break;
     case KCURST:
-      vt_set(-1, -1, -1, -1, -1, NORMAL, -1);
+      vt_set(-1, -1, -1, -1, -1, NORMAL, -1, -1);
       break;
     case KCURAPP:
-      vt_set(-1, -1, -1, -1, -1, APPL, -1);
+      vt_set(-1, -1, -1, -1, -1, APPL, -1, -1);
       break;
     default:
       /* The rest is only meaningful if a keyserv runs. */
diff -r b4d7cc7b8505 -r 5619c4178e8e src/minicom.c
--- a/src/minicom.c Mon Feb 14 11:21:35 2011 +0100
+++ b/src/minicom.c Thu Feb 17 13:38:17 2011 +0000
@@ -22,6 +22,7 @@
  * kubota at debian.or.jp 07/98  - Added option -C to start capturing from the
  * command line
  * jl  09.07.98 added option -S to start a script at startup
+ * mark.einon at gmail.com 16/02/11 - Added option to timestamp terminal output
  */
 #ifdef HAVE_CONFIG_H
 #include <config.h>
@@ -844,26 +845,37 @@
 void toggle_addlf(void)
 {
   addlf = !addlf;
-  vt_set(addlf, -1, -1, -1, -1, -1, -1);
+  vt_set(addlf, -1, -1, -1, -1, -1, -1, -1);
 }

 static void set_addlf(int val)
 {
-  vt_set(val, -1, -1, -1, -1, -1, -1);
+  vt_set(val, -1, -1, -1, -1, -1, -1, -1);
 }

 /* Toggle local echo.  Can be called through the menu, or by a macro. */
 void toggle_local_echo(void)
 {
   local_echo = !local_echo;
-  vt_set(-1, -1, -1, -1, local_echo, -1 ,-1);
+  vt_set(-1, -1, -1, -1, local_echo, -1, -1 ,-1);
 }

 static void set_local_echo(int val)
 {
-  vt_set(-1, -1, -1, -1, val, -1 ,-1);
+  vt_set(-1, -1, -1, -1, val, -1 ,-1, -1);
 }

+/* Toggle host timestamping on/off */
+void toggle_timestamp(void)
+{
+  timestamp = !timestamp;
+  vt_set(-1, -1, -1, -1, -1, -1, -1, timestamp);
+}
+
+static void set_timestamp(int val)
+{
+  vt_set(-1, -1, -1, -1 ,-1, -1, -1, val);
+}
 /* -------------------------------------------- */

 static iconv_t iconv_rem2local;
@@ -999,6 +1011,7 @@
   stdattr = XA_NORMAL;
   us = NULL;
   addlf = 0;
+  timestamp = 0;
   wrapln = 0;
   disable_online_time = 0;
   local_echo = 0;
@@ -1180,7 +1193,7 @@
             exit(1);
           }
           docap = 1;
-          vt_set(addlf, -1, docap, -1, -1, -1, -1);
+          vt_set(addlf, -1, docap, -1, -1, -1, -1, -1);
           break;
         case 'S': /* start Script */
           strncpy(scr_name, optarg, 33);
@@ -1222,7 +1235,7 @@

   if (screen_iso && screen_ibmpc)
     /* init VT */
-    vt_set(-1, -1, -1, -1, -1, -1, 1);
+    vt_set(-1, -1, -1, -1, -1, -1, 1, -1);

   /* Avoid fraude ! */
   for (s = use_port; *s; s++)
@@ -1387,6 +1400,7 @@

   set_local_echo(local_echo);
   set_addlf(addlf);
+  set_timestamp(timestamp);

   /* The main loop calls do_terminal and gets a function key back. */
   while (!quit) {
@@ -1486,7 +1500,7 @@
           if (c == 1)
             docap = 0;
         }
-        vt_set(addlf, -1, docap, -1, -1, -1, -1);
+        vt_set(addlf, -1, docap, -1, -1, -1, -1, -1);
         break;
       case 'p': /* Set parameters */
         get_bbp(P_BAUDRATE, P_BITS, P_PARITY, P_STOPB, 0);
@@ -1511,10 +1525,15 @@
         break;
       case 'w': /* Line wrap on-off */
         c = !us->wrap;
-        vt_set(addlf, c, docap, -1, -1, -1, -1);
+        vt_set(addlf, c, docap, -1, -1, -1, -1, -1);
         s = c ? _("Linewrap ON") : _("Linewrap OFF");
  status_set_display(s, 0);
         break;
+      case 'n': /*  Timestamp on-off*/
+ toggle_timestamp();
+        s = timestamp ? _("Timestamp ON") : _("Timestamp OFF");
+        status_set_display(s, 0);
+        break;
       case 'o': /* Configure Minicom */
         (void) config(0);
         break;
diff -r b4d7cc7b8505 -r 5619c4178e8e src/minicom.h
--- a/src/minicom.h Mon Feb 14 11:21:35 2011 +0100
+++ b/src/minicom.h Thu Feb 17 13:38:17 2011 +0000
@@ -23,6 +23,7 @@
  * jl  05.10.97 changed return value of dial() to long
  * jseymour at jimsun.LinxNet.com (Jim Seymour) 03/26/98 - Added prototype
  *    for new "get_port()" function in util.c.
+ * mark.einon at gmail.com 16/02/11 - Added option to timestamp terminal output
  */

 /* First include all other application-dependant include files. */
@@ -77,6 +78,7 @@
 EXTERN int docap; /* Capture data to capture file */
 EXTERN FILE *capfp; /* File to capture to */
 EXTERN int addlf; /* Add LF after CR */
+EXTERN int timestamp; /* timestamp each line */
 EXTERN int wrapln; /* Linewrap default */
 EXTERN int tempst; /* Status line is temporary */
 EXTERN int escape; /* Escape code. */
diff -r b4d7cc7b8505 -r 5619c4178e8e src/vt100.c
--- a/src/vt100.c Mon Feb 14 11:21:35 2011 +0100
+++ b/src/vt100.c Thu Feb 17 13:38:17 2011 +0000
@@ -21,11 +21,13 @@
  *
  * // jl 04.09.97 character map conversions in and out
  *    jl 06.07.98 use conversion tables with the capture file
+ *    mark.einon at gmail.com 16/02/11 - Added option to timestamp terminal output
  */
 #ifdef HAVE_CONFIG_H
 #include <config.h>
 #endif

+#include <time.h>
 #include "port.h"
 #include "minicom.h"
 #include "vt100.h"
@@ -142,6 +144,7 @@
 static int vt_keypad; /* Keypad mode. */
 static int vt_cursor; /* cursor key mode. */
 static int vt_asis = 0; /* 8bit clean mode. */
+static int vt_timestamp = 0; /* Timestamp each line. */
 static int vt_bs = 8; /* Code that backspace key sends. */
 static int vt_insert = 0; /* Insert mode */
 static int vt_crlf = 0; /* Return sends CR/LF */
@@ -170,6 +173,12 @@
 static char *savetrans[2];
 #endif

+/* timestamp string and time */
+static struct tm tmstmp_tm;
+static time_t    tmstmp_prev;
+static time_t    tmstmp_now;
+static char      tmstmp_str[36];
+
 /*
  * Initialize the emulator once.
  */
@@ -246,7 +255,7 @@

 /* Change some things on the fly. */
 void vt_set(int addlf, int wrap, int docap, int bscode,
-            int echo, int cursor, int asis)
+            int echo, int cursor, int asis, int timestamp)
 {
   if (addlf >= 0)
     vt_addlf = addlf;
@@ -262,6 +271,8 @@
     vt_cursor = cursor;
   if (asis >=0)
     vt_asis = asis;
+  if (timestamp >= 0)
+    vt_timestamp = timestamp;
 }

 /* Output a string to the modem. */
@@ -948,6 +959,19 @@
         if (vt_docap == 1)
           fputc('\n', capfp);
       }
+      if (vt_timestamp) {
+        time(&tmstmp_now);
+ if(tmstmp_now != tmstmp_prev) {
+  tmstmp_prev = tmstmp_now;
+          tmstmp_tm = *localtime(&tmstmp_now);
+          strftime(tmstmp_str, sizeof(tmstmp_str), "\n<Timestamp [%F
%T]>", &tmstmp_tm);
+          mc_wputs(vt_win, tmstmp_str);
+          mc_wputc(vt_win, '\r');
+          if (vt_docap == 1) {
+            fputs(tmstmp_str, capfp);
+  }
+        }
+      }
       break;
     case '\t': /* Non - destructive TAB */
       /* Find next tab stop. */
diff -r b4d7cc7b8505 -r 5619c4178e8e src/vt100.h
--- a/src/vt100.h Mon Feb 14 11:21:35 2011 +0100
+++ b/src/vt100.h Thu Feb 17 13:38:17 2011 +0000
@@ -33,7 +33,7 @@
 void vt_install(void(*)(const char *, int), void (*)(int, int), WIN *);
 void vt_init(int, int, int, int, int);
 void vt_pinit(WIN *, int, int);
-void vt_set(int, int, int, int, int, int, int);
+void vt_set(int, int, int, int, int, int, int, int);
 void vt_out(int);
 void vt_send(int ch);



More information about the minicom-devel mailing list