[hackers] [st] Add write I/O to file || "Roberto E. Vargas Caballero"

From: <hg_AT_suckless.org>
Date: Mon, 3 Sep 2012 21:55:47 +0200 (CEST)

changeset: 263:c3514854da2a
user: "Roberto E. Vargas Caballero" <k0ga_AT_shike2.com>
date: Mon Sep 03 21:52:21 2012 +0200
files: st.1 st.c
description:
Add write I/O to file
This is a theorical feature listed in http://st.suckless.org/goals. All the
input/output of the terminal will be written to a file, which can be very
useful for debugging, and also allow interconnect st to other process
through named pipes.
---
 st.1 |    6 ++++++
 st.c |   14 +++++++++++++-
 2 files changed, 19 insertions(+), 1 deletion(-)
diff -r cd73991ab465 -r c3514854da2a st.1
--- a/st.1	Mon Sep 03 21:50:22 2012 +0200
+++ b/st.1	Mon Sep 03 21:52:21 2012 +0200
_AT_@ -10,6 +10,8 @@
 .RB [ \-w 
 .IR windowid ]
 .RB [ \-v ]
+.RB [ \-f
+.IR file ]
 .RB [ \-e
 .IR command ...]
 .SH DESCRIPTION
_AT_@ -30,6 +32,10 @@
 .B \-v
 prints version information to stderr, then exits.
 .TP
+.BI \-f " file"
+writes all the I/O to
+.I file
+.TP
 .BI \-e " program " [ " arguments " "... ]"
 st executes
 .I program
diff -r cd73991ab465 -r c3514854da2a st.c
--- a/st.c	Mon Sep 03 21:50:22 2012 +0200
+++ b/st.c	Mon Sep 03 21:52:21 2012 +0200
_AT_@ -36,7 +36,7 @@
 
 #define USAGE \
 	"st " VERSION " (c) 2010-2012 st engineers\n" \
-	"usage: st [-t title] [-c class] [-w windowid] [-v] [-e command...]\n"
+	"usage: st [-t title] [-c class] [-w windowid] [-v] [-f file] [-e command...]\n"
 
 /* XEMBED messages */
 #define XEMBED_FOCUS_IN  4
_AT_@ -342,7 +342,9 @@
 static int cmdfd;
 static pid_t pid;
 static Selection sel;
+static FILE *fileio;
 static char **opt_cmd  = NULL;
+static char *opt_io    = NULL;
 static char *opt_title = NULL;
 static char *opt_embed = NULL;
 static char *opt_class = NULL;
_AT_@ -776,6 +778,10 @@
 		close(s);
 		cmdfd = m;
 		signal(SIGCHLD, sigchld);
+		if (opt_io && !(fileio = fopen(opt_io, "w"))) {
+			fprintf(stderr, "Error opening %s:%s",
+				opt_io, strerror(errno));
+		}
 	}
 }
 
_AT_@ -1534,6 +1540,9 @@
 void
 tputc(char *c) {
 	char ascii = *c;
+
+	if (fileio)
+		putc(ascii, fileio);
 	if(term.esc & ESC_START) {
 		if(term.esc & ESC_CSI) {
 			csiescseq.buf[csiescseq.len++] = ascii;
_AT_@ -2269,6 +2278,9 @@
 		case 'w':
 			if(++i < argc) opt_embed = argv[i];
 			break;
+		case 'f':
+			if (++i < argc) opt_io = argv[i];
+			break;
 		case 'e':
 			/* eat every remaining arguments */
 			if(++i < argc) opt_cmd = &argv[i];
Received on Mon Sep 03 2012 - 21:55:47 CEST

This archive was generated by hypermail 2.3.0 : Mon Sep 03 2012 - 22:00:11 CEST