#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"),
" -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;
}
printf(UTIL_LINUX_VERSION);
exit(EXIT_SUCCESS);
case 'h':
- usage(stdout);
+ usage();
default:
- usage(stderr);
+ errtryhelp(EXIT_FAILURE);
}
argc -= optind;
argv += optind;
if ((argc < 1 && !tname) || argc > 3) {
warnx(_("wrong number of arguments"));
- usage(stderr);
+ errtryhelp(EXIT_FAILURE);
}
if (!tname)
tname = argv[idx++];
/* 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;
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;