]> git.ipfire.org Git - thirdparty/util-linux.git/blobdiff - term-utils/scriptreplay.c
setterm: update comments about -ulcolor/-hbcolor syntax
[thirdparty/util-linux.git] / term-utils / scriptreplay.c
index b4549ef16edd6633ef565716240cdd5f78547974..7b59b6e244b425d787c57b71f655bf9a53a2cb9f 100644 (file)
 
 #include "closestream.h"
 #include "nls.h"
+#include "strutils.h"
 #include "c.h"
 
 #define SCRIPT_MIN_DELAY 0.0001                /* from original sripreplay.pl */
 
 static void __attribute__((__noreturn__))
-usage(FILE *out)
+usage(void)
 {
+       FILE *out = stdout;
        fputs(USAGE_HEADER, out);
        fprintf(out,
              _(" %s [-t] timingfile [typescript] [divisor]\n"),
@@ -50,31 +52,21 @@ usage(FILE *out)
                " -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);
+               ), out);
+       printf(USAGE_HELP_OPTIONS(25));
 
-       fprintf(out, USAGE_MAN_TAIL("scriptreplay(1)"));
-       exit(out == stderr ? EXIT_FAILURE : EXIT_SUCCESS);
+       printf(USAGE_MAN_TAIL("scriptreplay(1)"));
+       exit(EXIT_SUCCESS);
 }
 
 static double
 getnum(const char *s)
 {
-       double d;
-       char *end;
-
-       errno = 0;
-       d = strtod(s, &end);
-
-       if (end && *end != '\0')
-               errx(EXIT_FAILURE, _("expected a number, but got '%s'"), s);
-
-       if ((d == HUGE_VAL || d == -HUGE_VAL) && ERANGE == errno)
-               err(EXIT_FAILURE, _("divisor '%s'"), s);
+       const double d = strtod_or_err(s, _("failed to parse number"));
 
-       if (!(d==d)) { /* did they specify "nan"? */
+       if (isnan(d)) {
                errno = EINVAL;
-               err(EXIT_FAILURE, _("divisor '%s'"), s);
+               err(EXIT_FAILURE, "%s: %s", _("failed to parse number"), s);
        }
        return d;
 }
@@ -181,9 +173,9 @@ main(int argc, char *argv[])
                        printf(UTIL_LINUX_VERSION);
                        exit(EXIT_SUCCESS);
                case 'h':
-                       usage(stdout);
+                       usage();
                default:
-                       usage(stderr);
+                       errtryhelp(EXIT_FAILURE);
                        }
        argc -= optind;
        argv += optind;
@@ -191,7 +183,7 @@ main(int argc, char *argv[])
 
        if ((argc < 1 && !tname) || argc > 3) {
                warnx(_("wrong number of arguments"));
-               usage(stderr);
+               errtryhelp(EXIT_FAILURE);
        }
        if (!tname)
                tname = argv[idx++];
@@ -211,7 +203,7 @@ main(int argc, char *argv[])
        /* ignore the first typescript line */
        while((c = fgetc(sfile)) != EOF && c != '\n');
 
-       for(line = 0; ; line++) {
+       for(line = 1; ; line++) {
                double delay;
                size_t blk;
                char nl;
@@ -223,7 +215,7 @@ main(int argc, char *argv[])
                                err(EXIT_FAILURE,
                                        _("failed to read timing file %s"), tname);
                        errx(EXIT_FAILURE,
-                               _("timings file %s: %lu: unexpected format"),
+                               _("timing file %s: line %lu: unexpected format"),
                                tname, line);
                }
                delay /= divi;