]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
script: add option --log-timing
authorKarel Zak <kzak@redhat.com>
Fri, 12 Apr 2019 10:47:03 +0000 (12:47 +0200)
committerKarel Zak <kzak@redhat.com>
Tue, 8 Oct 2019 11:11:53 +0000 (13:11 +0200)
The current -t[=<file>] is pretty messy due to optional <file>
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 <kzak@redhat.com>
term-utils/script.1
term-utils/script.c

index 3ae8909a66818df4d1f28b571dfac6027b47c305..439e47c8e2b5ab333448475f7cf0d0c3788c2acd 100644 (file)
@@ -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.
index bef5557424bcab635ff82b8ff383a55803716e9a..a2a35944122cd78c1cd6e4f62ba35c1176225d88 100644 (file)
@@ -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 <file>          log stdout to file (default)\n"), out);
+       fputs(_(" -T, --log-timing <file>       log timing information to file\n"), out);
        fputs(_(" -a, --append                  append the output\n"), out);
        fputs(_(" -c, --command <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 <size>     terminate if output files exceed size\n"), out);
        fputs(_(" -q, --quiet                   be quiet\n"), out);
-       fputs(_(" -t[<file>], --timing[=<file>] output timing data to stderr or to FILE\n"), out);
+       fputs(_(" -t[<file>], --timing[=<file>] 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;