public inbox for util-linux@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] scriptreplay: Add --maxdelay option.
@ 2014-02-10 10:53 Jesper Dahl Nyerup
  2014-02-10 18:25 ` Karel Zak
  0 siblings, 1 reply; 3+ messages in thread
From: Jesper Dahl Nyerup @ 2014-02-10 10:53 UTC (permalink / raw)
  To: util-linux; +Cc: nyerup

This option caps the delay between updates, to avoid long pauses in
transcript playback.

Signed-off-by: Jesper Dahl Nyerup <nyerup@one.com>
---
 term-utils/scriptreplay.1 |  6 ++++++
 term-utils/scriptreplay.c | 15 ++++++++++++---
 2 files changed, 18 insertions(+), 3 deletions(-)

diff --git a/term-utils/scriptreplay.1 b/term-utils/scriptreplay.1
index 20b6d93..329dbc9 100644
--- a/term-utils/scriptreplay.1
+++ b/term-utils/scriptreplay.1
@@ -56,6 +56,12 @@ Speed up the replay displaying this
 of times.  The argument is a floating point number.  It's called divisor
 because it divides the timings by this factor.
 .TP
+.BR \-m , " \-\-maxdelay " \fInumber\fR
+Set the maximal delay between transcript updates to
+.I number
+seconds.  The argument is a floating point number.  This can be used to
+avoid long pauses in the transcript replay.
+.TP
 .BR \-V , " \-\-version"
 Display version information and exit.
 .TP
diff --git a/term-utils/scriptreplay.c b/term-utils/scriptreplay.c
index 46468be..6a29874 100644
--- a/term-utils/scriptreplay.c
+++ b/term-utils/scriptreplay.c
@@ -46,6 +46,7 @@ usage(FILE *out)
 	fputs(_(" -t, --timing <file>     script timing output file\n"
 		" -s, --typescript <file> script terminal session output file\n"
 		" -d, --divisor <num>     speed up or slow down execution with time divisor\n"
+		" -m, --maxdelay <num>    wait at most this many seconds between updates\n"
 		" -V, --version           output version information and exit\n"
 		" -h, --help              display this help and exit\n\n"), out);
 
@@ -130,8 +131,8 @@ main(int argc, char *argv[])
 {
 	FILE *tfile, *sfile;
 	const char *sname = NULL, *tname = NULL;
-	double divi = 1;
-	int c, diviopt = FALSE, idx;
+	double divi = 1, maxdelay = 10;
+	int c, diviopt = FALSE, maxdelayopt = FALSE, idx;
 	unsigned long line;
 	size_t oldblk = 0;
 	char ch;
@@ -140,6 +141,7 @@ main(int argc, char *argv[])
 		{ "timing",	required_argument,	0, 't' },
 		{ "typescript",	required_argument,	0, 's' },
 		{ "divisor",	required_argument,	0, 'd' },
+		{ "maxdelay",	required_argument,	0, 'm' },
 		{ "version",	no_argument,		0, 'V' },
 		{ "help",	no_argument,		0, 'h' },
 		{ NULL,		0, 0, 0 }
@@ -156,7 +158,7 @@ main(int argc, char *argv[])
 	textdomain(PACKAGE);
 	atexit(close_stdout);
 
-	while ((ch = getopt_long(argc, argv, "t:s:d:Vh", longopts, NULL)) != -1)
+	while ((ch = getopt_long(argc, argv, "t:s:d:m:Vh", longopts, NULL)) != -1)
 		switch(ch) {
 		case 't':
 			tname = optarg;
@@ -168,6 +170,10 @@ main(int argc, char *argv[])
 			diviopt = TRUE;
 			divi = getnum(optarg);
 			break;
+		case 'm':
+			maxdelayopt = TRUE;
+			maxdelay = getnum(optarg);
+			break;
 		case 'V':
 			printf(_("%s from %s\n"), program_invocation_short_name,
 						  PACKAGE_STRING);
@@ -219,6 +225,9 @@ main(int argc, char *argv[])
 		}
 		delay /= divi;
 
+		if (maxdelayopt && delay > maxdelay)
+			delay = maxdelay;
+
 		if (delay > SCRIPT_MIN_DELAY)
 			delay_for(delay);
 
-- 
1.8.4


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] scriptreplay: Add --maxdelay option.
  2014-02-10 10:53 [PATCH] scriptreplay: Add --maxdelay option Jesper Dahl Nyerup
@ 2014-02-10 18:25 ` Karel Zak
  2014-02-10 19:10   ` Jesper Dahl Nyerup
  0 siblings, 1 reply; 3+ messages in thread
From: Karel Zak @ 2014-02-10 18:25 UTC (permalink / raw)
  To: Jesper Dahl Nyerup; +Cc: util-linux

On Mon, Feb 10, 2014 at 11:53:18AM +0100, Jesper Dahl Nyerup wrote:
>  term-utils/scriptreplay.1 |  6 ++++++
>  term-utils/scriptreplay.c | 15 ++++++++++++---
>  2 files changed, 18 insertions(+), 3 deletions(-)

 Applied, thanks.

> +	double divi = 1, maxdelay = 10;

 I have used maxdelay = 0; it seems more readable :-)

    Karel

-- 
 Karel Zak  <kzak@redhat.com>
 http://karelzak.blogspot.com

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] scriptreplay: Add --maxdelay option.
  2014-02-10 18:25 ` Karel Zak
@ 2014-02-10 19:10   ` Jesper Dahl Nyerup
  0 siblings, 0 replies; 3+ messages in thread
From: Jesper Dahl Nyerup @ 2014-02-10 19:10 UTC (permalink / raw)
  To: Karel Zak; +Cc: util-linux

[-- Attachment #1: Type: text/plain, Size: 781 bytes --]

On Feb 10  19:25, Karel Zak wrote:
> On Mon, Feb 10, 2014 at 11:53:18AM +0100, Jesper Dahl Nyerup wrote:
> >  term-utils/scriptreplay.1 |  6 ++++++
> >  term-utils/scriptreplay.c | 15 ++++++++++++---
> >  2 files changed, 18 insertions(+), 3 deletions(-)
> 
>  Applied, thanks.

Back atcha.

> > +	double divi = 1, maxdelay = 10;
> 
>  I have used maxdelay = 0; it seems more readable :-)

Fine by me.

I had 0 in my patch initially, but changed it to 10. The only reason was
if someone someday decided to make the option argument optional, a
default value of 0 would effectively render scriptreplay(1) to be a
poorly implemented cat(1).

But let's cross that bridge when we reach it.

J.
-- 
Jesper Dahl Nyerup
Systems Engineer
One.com, nyerup@one.com

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 198 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2014-02-10 19:10 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-02-10 10:53 [PATCH] scriptreplay: Add --maxdelay option Jesper Dahl Nyerup
2014-02-10 18:25 ` Karel Zak
2014-02-10 19:10   ` Jesper Dahl Nyerup

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox