remove gcc34
[dragonfly.git] / crypto / heimdal-0.6.3 / lib / editline / testit.c
1 /*  $Revision: 1.3 $
2 **
3 **  A "micro-shell" to test editline library.
4 **  If given any arguments, commands aren't executed.
5 */
6 #if defined(HAVE_CONFIG_H)
7 #include <config.h>
8 #endif
9 #include <stdio.h>
10 #include <stdlib.h>
11 #ifdef HAVE_ERRNO_H
12 #include <errno.h>
13 #endif
14 #include <getarg.h>
15
16 #include "editline.h"
17
18 static int n_flag       = 0;
19 static int version_flag = 0;
20 static int help_flag    = 0;
21
22 static struct getargs args[] = {
23     {"dry-run", 'n',    arg_flag,       &n_flag,
24      "do not run commands", NULL },
25     {"version", 0,      arg_flag,       &version_flag,
26      "print version", NULL },
27     {"help",    0,      arg_flag,       &help_flag,
28      NULL, NULL }
29 };
30
31 static void
32 usage (int ret)
33 {
34     arg_printusage (args,
35                     sizeof(args)/sizeof(*args),
36                     NULL,
37                     "");
38     exit (ret);
39 }
40
41 int
42 main(int argc, char **argv)
43 {
44     char        *p;
45     int optind = 0;
46
47     setprogname (argv[0]);
48
49     if(getarg(args, sizeof(args) / sizeof(args[0]), argc, argv, &optind))
50         usage(1);
51     
52     if (help_flag)
53         usage (0);
54
55     if(version_flag){
56         print_version(NULL);
57         exit(0);
58     }
59
60     argc -= optind;
61     argv += optind;
62
63     while ((p = readline("testit> ")) != NULL) {
64         (void)printf("\t\t\t|%s|\n", p);
65         if (!n_flag) {
66             if (strncmp(p, "cd ", 3) == 0) {
67                 if (chdir(&p[3]) < 0)
68                     perror(&p[3]);
69             } else if (system(p) != 0) {
70                 perror(p);
71             }
72         }
73         add_history(p);
74         free(p);
75     }
76     exit(0);
77     /* NOTREACHED */
78 }