From: Karel Zak Date: Fri, 12 Apr 2019 10:47:03 +0000 (+0200) Subject: script: add option --log-timing X-Git-Tag: v2.35-rc1~171 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=fc58044f795f49325213b28f27205cf149691b31;p=thirdparty%2Futil-linux.git script: add option --log-timing The current -t[=] is pretty messy due to optional argument; and default is to output to stderr. The default output to stderr is very unusual semantic. This path makes the old -t deprecated. The new option -T, --log-timing requires the file name. Signed-off-by: Karel Zak --- diff --git a/term-utils/script.1 b/term-utils/script.1 index 3ae8909a66..439e47c8e2 100644 --- a/term-utils/script.1 +++ b/term-utils/script.1 @@ -91,6 +91,14 @@ or symbolic link. The command will follow a symbolic link. Log output to the \fIfile\fR. The default is to log the file with name 'typescript' if the option is not given. .TP +\fB\-T\fR, \fB\-\-log\-timing\fR \fIfile\fR +Log timing information to the \fIfile\fR. +.sp +This log 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. +.TP \fB\-o\fR, \fB\-\-output-limit\fR \fIsize\fR Limit the size of the typescript and timing files to .I size @@ -106,10 +114,8 @@ Be quiet (do not write start and done messages to standard output). \fB\-t\fR[\fIfile\fR], \fB\-\-timing\fR[=\fIfile\fR] Output timing data to standard error, or to .I file -when given. 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. +when given. This option is deprecated in favour of \fB\-\-log\-timing\fR where +the \fIfile\fR argument is not optional. .TP \fB\-V\fR, \fB\-\-version\fR Display version information and exit. diff --git a/term-utils/script.c b/term-utils/script.c index bef5557424..a2a3594412 100644 --- a/term-utils/script.c +++ b/term-utils/script.c @@ -73,6 +73,7 @@ #include "timeutils.h" #include "strutils.h" #include "xalloc.h" +#include "optutils.h" #include "debug.h" @@ -189,6 +190,7 @@ static void __attribute__((__noreturn__)) usage(void) fputs(USAGE_OPTIONS, out); fputs(_(" -O, --log-out log stdout to file (default)\n"), out); + fputs(_(" -T, --log-timing log timing information to file\n"), out); fputs(_(" -a, --append append the output\n"), out); fputs(_(" -c, --command run command rather than interactive shell\n"), out); fputs(_(" -e, --return return exit code of the child process\n"), out); @@ -196,7 +198,7 @@ static void __attribute__((__noreturn__)) usage(void) fputs(_(" --force use output file even when it is a link\n"), out); fputs(_(" -o, --output-limit terminate if output files exceed size\n"), out); fputs(_(" -q, --quiet be quiet\n"), out); - fputs(_(" -t[], --timing[=] output timing data to stderr or to FILE\n"), out); + fputs(_(" -t[], --timing[=] deprecated alias to -T (default file is stderr)\n"), out); fputs(USAGE_SEPARATOR, out); printf(USAGE_HELP_OPTIONS(31)); @@ -897,6 +899,7 @@ int main(int argc, char **argv) {"flush", no_argument, NULL, 'f'}, {"force", no_argument, NULL, FORCE_OPTION,}, {"log-out", required_argument, NULL, 'O'}, + {"log-timing", required_argument, NULL, 'T'}, {"output-limit", required_argument, NULL, 'o'}, {"quiet", no_argument, NULL, 'q'}, {"timing", optional_argument, NULL, 't'}, @@ -904,7 +907,11 @@ int main(int argc, char **argv) {"help", no_argument, NULL, 'h'}, {NULL, 0, NULL, 0} }; - + static const ul_excl_t excl[] = { /* rows and cols in ASCII order */ + { 'T', 't' }, + { 0 } + }; + int excl_st[ARRAY_SIZE(excl)] = UL_EXCL_STATUS_INIT; setlocale(LC_ALL, ""); /* * script -t prints time delays as floating point numbers. The example @@ -920,7 +927,10 @@ int main(int argc, char **argv) script_init_debug(); - while ((ch = getopt_long(argc, argv, "ac:efO:o:qt::Vh", longopts, NULL)) != -1) + while ((ch = getopt_long(argc, argv, "ac:efO:o:qT:t::Vh", longopts, NULL)) != -1) { + + err_exclusive_options(ch, longopts, excl, excl_st); + switch (ch) { case 'a': ctl.append = 1; @@ -955,7 +965,10 @@ int main(int argc, char **argv) /* used for message only */ timingfile = optarg ? optarg : "stderr"; break; - + case 'T' : + log_associate(&ctl, &ctl.out, optarg, SCRIPT_FMT_TIMING_SIMPLE); + timingfile = optarg; + break; case 'V': print_version(EXIT_SUCCESS); case 'h': @@ -963,6 +976,7 @@ int main(int argc, char **argv) default: errtryhelp(EXIT_FAILURE); } + } argc -= optind; argv += optind;