Signed-off-by: Sami Kerola <kerolasa@xxxxxx> --- misc-utils/script.c | 53 +++++++++++++++++++++++++++++++++++++++----------- 1 files changed, 41 insertions(+), 12 deletions(-) diff --git a/misc-utils/script.c b/misc-utils/script.c index f349982..2a12094 100644 --- a/misc-utils/script.c +++ b/misc-utils/script.c @@ -119,6 +119,26 @@ die_if_link(char *fn) { fn, program_invocation_short_name, fn); } +static void __attribute__((__noreturn__)) +usage(FILE *out) +{ + fprintf(out, _("Usage: %s [options] [file]\n\n"), + program_invocation_short_name); + + fprintf(out, _( + " -a, --append append output\n" + " -c, --command COMMAND run command rather than interactive shell\n" + " -r, --return return exit code of the child process\n" + " -f, --flush run flush after each write\n" + " -q, --quiet be quiet\n" + " -t, --timing output timing data to stderr\n" + " -v, --version output version information and exit\n" + " -h, --help display this help and exit\n" + )); + + exit(out == stderr ? EXIT_FAILURE : EXIT_SUCCESS); +} + /* * script -t prints time delays as floating point numbers * The example program (scriptreplay) that we provide to handle this @@ -135,20 +155,24 @@ main(int argc, char **argv) { extern int optind; int ch; + struct option longopts[] = { + { "append", no_argument, 0, 'a' }, + { "command", required_argument, 0, 'c' }, + { "return", no_argument, 0, 'e' }, + { "flush", no_argument, 0, 'f' }, + { "quiet", no_argument, 0, 'q' }, + { "timing", no_argument, 0, 't' }, + { "version", no_argument, 0, 'v' }, + { "help", no_argument, 0, 'h' }, + { NULL, 0, 0, 0 } + }; + setlocale(LC_ALL, ""); setlocale(LC_NUMERIC, "C"); /* see comment above */ bindtextdomain(PACKAGE, LOCALEDIR); textdomain(PACKAGE); - if (argc == 2) { - if (!strcmp(argv[1], "-V") || !strcmp(argv[1], "--version")) { - printf(_("%s (%s)\n"), - program_invocation_short_name, PACKAGE_STRING); - return 0; - } - } - - while ((ch = getopt(argc, argv, "ac:efqt")) != -1) + while ((ch = getopt_long(argc, argv, "ac:efqtvh", longopts, NULL)) != -1) switch((char)ch) { case 'a': aflg++; @@ -168,11 +192,16 @@ main(int argc, char **argv) { case 't': tflg++; break; + case 'v': + printf(_("%s (%s)\n"), "script", PACKAGE_STRING); + exit(EXIT_SUCCESS); + break; + case 'h': + usage(stdout); + break; case '?': default: - fprintf(stderr, - _("usage: script [-a] [-e] [-f] [-q] [-t] [file]\n")); - exit(1); + usage(stderr); } argc -= optind; argv += optind; -- 1.7.4.1 -- 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