Add back "mech/utils.h", its needed for oid/buffer functions.
[heimdal.git] / lib / editline / testit.c
blobf4a84fc126aea687d1a66dd21475fd08d1aa28ad
1 /* $Revision$
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>
16 #include "edit_locl.h"
18 static int n_flag = 0;
19 static int version_flag = 0;
20 static int help_flag = 0;
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 }
31 static void
32 usage (int ret)
34 arg_printusage (args,
35 sizeof(args)/sizeof(*args),
36 NULL,
37 "");
38 exit (ret);
41 int
42 main(int argc, char **argv)
44 char *p;
45 int optidx = 0;
47 setprogname (argv[0]);
49 if(getarg(args, sizeof(args) / sizeof(args[0]), argc, argv, &optidx))
50 usage(1);
52 if (help_flag)
53 usage (0);
55 if(version_flag){
56 print_version(NULL);
57 exit(0);
60 argc -= optidx;
61 argv += optidx;
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);
73 add_history(p);
74 free(p);
76 exit(0);
77 /* NOTREACHED */