From 1778731bc75274cfc4ae5d9a979f05e92a261365 Mon Sep 17 00:00:00 2001 From: Assar Westerlund Date: Fri, 23 Aug 2002 03:19:21 +0000 Subject: [PATCH] make it use getarg so that it can handle --help and --version (and thus make check can pass) git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@11214 ec53bebd-3082-4978-b11e-865c3cabbd6b --- lib/editline/testit.c | 48 +++++++++++++++++++++++++++++++++++++++---- 1 file changed, 44 insertions(+), 4 deletions(-) diff --git a/lib/editline/testit.c b/lib/editline/testit.c index c7216b9ff..187094284 100644 --- a/lib/editline/testit.c +++ b/lib/editline/testit.c @@ -11,25 +11,65 @@ #ifdef HAVE_ERRNO_H #include #endif +#include #include "editline.h" +static int n_flag = 0; +static int version_flag = 0; +static int help_flag = 0; + +static struct getargs args[] = { + {"dry-run", 'n', arg_flag, &n_flag, + "do not run commands", NULL }, + {"version", 0, arg_flag, &version_flag, + "print version", NULL }, + {"help", 0, arg_flag, &help_flag, + NULL, NULL } +}; + +static void +usage (int ret) +{ + arg_printusage (args, + sizeof(args)/sizeof(*args), + NULL, + ""); + exit (ret); +} + int -main(int ac, char **av) +main(int argc, char **argv) { char *p; - int doit; + int optind = 0; + + setprogname (argv[0]); + + if(getarg(args, sizeof(args) / sizeof(args[0]), argc, argv, &optind)) + usage(1); + + if (help_flag) + usage (0); + + if(version_flag){ + print_version(NULL); + exit(0); + } + + argc -= optind; + argv += optind; - doit = ac == 1; while ((p = readline("testit> ")) != NULL) { (void)printf("\t\t\t|%s|\n", p); - if (doit) + if (!n_flag) { if (strncmp(p, "cd ", 3) == 0) { if (chdir(&p[3]) < 0) perror(&p[3]); } else if (system(p) != 0) { perror(p); } + } add_history(p); free(p); }