[PATCH 6/6] script: optional timing output file argument added

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



And update to manual page accordingly.

Signed-off-by: Sami Kerola <kerolasa@xxxxxx>
---
 term-utils/script.1 |    8 ++++++--
 term-utils/script.c |   19 ++++++++++++-------
 2 files changed, 18 insertions(+), 9 deletions(-)

diff --git a/term-utils/script.1 b/term-utils/script.1
index f411dc6..725bdb2 100644
--- a/term-utils/script.1
+++ b/term-utils/script.1
@@ -44,7 +44,7 @@
 .Op Fl e
 .Op Fl f
 .Op Fl q
-.Op Fl t
+.Op Fl t[=FILE]
 .Op Fl V
 .Op Fl h
 .Op Ar file
@@ -86,12 +86,16 @@ One person does `mkfifo foo; script -f foo' and another can
 supervise real-time what is being done using `cat foo'.
 .It Fl q, Fl Fl quiet
 Be quiet.
-.It Fl t, Fl Fl timing
+.It Fl t, Fl Fl timing[=FILE]
 Output timing data to standard error. This data contains two fields,
 separated by a space. The first field indicates how much time elapsed since
 the previous output. The second field indicates how many characters were
 output this time. This information can be used to replay typescripts with
 realistic typing and output delays.
+
+The timing option is able to take file path as an argument. The
+file is used as output detination instead of standard error when
+it is supplied.
 .It Fl V, Fl Fl version
 Output version information and exit.
 .It Fl h, Fl Fl help
diff --git a/term-utils/script.c b/term-utils/script.c
index f7b6d2e..1f3cc1f 100644
--- a/term-utils/script.c
+++ b/term-utils/script.c
@@ -76,7 +76,7 @@ void fixtty(void);
 void getmaster(void);
 void getslave(void);
 void doinput(void);
-void dooutput(void);
+void dooutput(FILE *timingfd);
 void doshell(void);
 
 char	*shell;
@@ -133,7 +133,7 @@ usage(FILE *out)
 		" -r, --return            return exit code of the child process\n"
 		" -f, --flush             run flush after each write\n"
 		" -q, --quiet             be quiet\n"
-		" -t, --timing            output timing data to stderr\n"
+		" -t, --timing=FILE       output timing data to stderr, or to file\n"
 		" -V, --version           output version information and exit\n"
 		" -h, --help              display this help and exit\n\n"));
 
@@ -155,6 +155,7 @@ main(int argc, char **argv) {
 	struct sigaction sa;
 	extern int optind;
 	int ch;
+	FILE *timingfd = stderr;
 
 	static const struct option longopts[] = {
 		{ "append",	no_argument,	   0, 'a' },
@@ -162,7 +163,7 @@ main(int argc, char **argv) {
 		{ "return",	no_argument,	   0, 'e' },
 		{ "flush",	no_argument,	   0, 'f' },
 		{ "quiet",	no_argument,	   0, 'q' },
-		{ "timing",	no_argument,	   0, 't' },
+		{ "timing",	optional_argument, 0, 't' },
 		{ "version",	no_argument,	   0, 'V' },
 		{ "help",	no_argument,	   0, 'h' },
 		{ NULL,		0, 0, 0 }
@@ -173,7 +174,7 @@ main(int argc, char **argv) {
 	bindtextdomain(PACKAGE, LOCALEDIR);
 	textdomain(PACKAGE);
 
-	while ((ch = getopt_long(argc, argv, "ac:efqtVh", longopts, NULL)) != -1)
+	while ((ch = getopt_long(argc, argv, "ac:efqt::Vh", longopts, NULL)) != -1)
 		switch((char)ch) {
 		case 'a':
 			aflg++;
@@ -191,6 +192,9 @@ main(int argc, char **argv) {
 			qflg++;
 			break;
 		case 't':
+			if (optarg)
+				if ((timingfd = fopen(optarg, "w")) == NULL)
+					err(EXIT_FAILURE, _("cannot open timing file %s"), optarg);
 			tflg++;
 			break;
 		case 'V':
@@ -260,7 +264,7 @@ main(int argc, char **argv) {
 			fail();
 		}
 		if (child)
-			dooutput();
+			dooutput(timingfd);
 		else
 			doshell();
 	} else {
@@ -269,6 +273,7 @@ main(int argc, char **argv) {
 	}
 	doinput();
 
+	fclose(timingfd);
 	return EXIT_SUCCESS;
 }
 
@@ -328,7 +333,7 @@ my_strftime(char *buf, size_t len, const char *fmt, const struct tm *tm) {
 }
 
 void
-dooutput() {
+dooutput(FILE *timingfd) {
 	register ssize_t cc;
 	time_t tvec;
 	char obuf[BUFSIZ];
@@ -370,7 +375,7 @@ dooutput() {
 			break;
 		if (tflg) {
 			newtime = tv.tv_sec + (double) tv.tv_usec / 1000000;
-			fprintf(stderr, "%f %zd\n", newtime - oldtime, cc);
+			fprintf(timingfd, "%f %zd\n", newtime - oldtime, cc);
 			oldtime = newtime;
 		}
 		wrt = write(1, obuf, cc);
-- 
1.7.4.4

--
To unsubscribe from this list: send the line "unsubscribe util-linux" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Netdev]     [Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]

  Powered by Linux