The command line switches override old style arguments Signed-off-by: Sami Kerola <kerolasa@xxxxxx> --- term-utils/scriptreplay.c | 36 ++++++++++++++++++++++++++++-------- 1 files changed, 28 insertions(+), 8 deletions(-) diff --git a/term-utils/scriptreplay.c b/term-utils/scriptreplay.c index c2fc0f1..57e69d9 100644 --- a/term-utils/scriptreplay.c +++ b/term-utils/scriptreplay.c @@ -40,6 +40,9 @@ usage(FILE *out) program_invocation_short_name); fprintf(out, _( "\nOptions:\n" + " -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" " -V, --version output version information and exit\n" " -h, --help display this help and exit\n\n")); @@ -123,14 +126,17 @@ int main(int argc, char *argv[]) { FILE *tfile, *sfile; - const char *sname, *tname = NULL; + const char *sname = NULL, *tname = NULL; double divi; - int c; + int c, diviopt = FALSE; unsigned long line; size_t oldblk = 0; char ch; static const struct option longopts[] = { + { "timing", required_argument, 0, 't' }, + { "typescript", required_argument, 0, 's' }, + { "divisor", required_argument, 0, 'd' }, { "version", no_argument, 0, 'V' }, { "help", no_argument, 0, 'h' }, { NULL, 0, 0, 0 } @@ -146,8 +152,18 @@ main(int argc, char *argv[]) bindtextdomain(PACKAGE, LOCALEDIR); textdomain(PACKAGE); - while ((ch = getopt_long(argc, argv, "Vh", longopts, NULL)) != -1) + while ((ch = getopt_long(argc, argv, "t:s:d:Vh", longopts, NULL)) != -1) switch(ch) { + case 't': + tname = optarg; + break; + case 's': + sname = optarg; + break; + case 'd': + diviopt = TRUE; + divi = getnum(optarg); + break; case 'V': printf(_("%s from %s\n"), program_invocation_short_name, PACKAGE_STRING); @@ -160,14 +176,18 @@ main(int argc, char *argv[]) argc -= optind; argv += optind; - if (argc < 1 || 3 < argc) { + if ((argc < 1 && tname == NULL) || 3 < argc) { warnx(_("wrong number of arguments")); usage(stderr); } - - tname = argv[0]; - sname = argc > 2 ? argv[1] : "typescript"; - divi = argc == 4 ? getnum(argv[2]) : 1; + if (argv[0] && tname == NULL) + tname = argv[0]; + else + argc++; + if (sname == NULL) + sname = argc > 2 ? argv[1] : "typescript"; + if (diviopt == FALSE) + divi = argc == 4 ? getnum(argv[2]) : 1; tfile = fopen(tname, "r"); if (!tfile) -- 1.7.4.4 -- To unsubscribe from this list: send the line "unsubscribe util-linux" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html