worldstone: add -s for statistical profiling
[minix.git] / lib / libedit / testit.c
blob525436c5d727e38cbf613ce305bb96793f8d5f63
1 /*
2 ** A "micro-shell" to test editline library.
3 ** If given any arguments, commands aren't executed.
4 */
5 #include <stdio.h>
6 #if defined(HAVE_STDLIB)
7 #include <stdlib.h>
8 #endif /* defined(HAVE_STDLIB) */
10 extern char *readline();
11 extern void add_history();
13 #if !defined(HAVE_STDLIB)
14 extern int chdir();
15 extern int free();
16 extern int strncmp();
17 extern int system();
18 extern void exit();
19 extern char *getenv();
20 #endif /* !defined(HAVE_STDLIB) */
23 #if defined(NEED_PERROR)
24 void
25 perror(s)
26 char *s;
28 extern int errno;
30 (voidf)printf(stderr, "%s: error %d\n", s, errno);
32 #endif /* defined(NEED_PERROR) */
35 /* ARGSUSED1 */
36 int
37 main(ac, av)
38 int ac;
39 char *av[];
41 char *prompt;
42 char *p;
43 int doit;
45 doit = ac == 1;
46 if ((prompt = getenv("TESTPROMPT")) == NULL)
47 prompt = "testit> ";
49 while ((p = readline(prompt)) != NULL) {
50 (void)printf("\t\t\t|%s|\n", p);
51 if (doit)
52 if (strncmp(p, "cd ", 3) == 0) {
53 if (chdir(&p[3]) < 0)
54 perror(&p[3]);
56 else if (system(p) != 0)
57 perror(p);
58 add_history(p);
59 free(p);
61 exit(0);
62 /* NOTREACHED */
66 * $PchId: testit.c,v 1.3 1996/02/22 21:18:51 philip Exp $