Release 950122
[wine] / debugger / readline / testit.c
1 /*  $Revision: 1.2 $
2 **
3 **  A "micro-shell" to test editline library.
4 **  If given any arguments, commands aren't executed.
5 */
6 #include <stdio.h>
7 #if     defined(HAVE_STDLIB)
8 #include <stdlib.h>
9 #endif  /* defined(HAVE_STDLIB) */
10
11 const char version_string[] = "4.321"; 
12
13
14 extern char     *readline();
15 extern void     add_history();
16
17 #if     !defined(HAVE_STDLIB)
18 extern int      chdir();
19 extern int      free();
20 extern int      strncmp();
21 extern int      system();
22 extern void     exit();
23 #endif  /* !defined(HAVE_STDLIB) */
24
25
26 #if     defined(NEED_PERROR)
27 void
28 perror(s)
29     char        *s;
30 {
31     extern int  errno;
32
33     (voidf)printf(stderr, "%s: error %d\n", s, errno);
34 }
35 #endif  /* defined(NEED_PERROR) */
36
37
38 /* ARGSUSED1 */
39 int
40 main(ac, av)
41     int         ac;
42     char        *av[];
43 {
44     char        *p;
45     int         doit;
46
47     doit = ac == 1;
48     while ((p = readline("testit> ")) != NULL) {
49         (void)printf("\t\t\t|%s|\n", p);
50         if (doit)
51             if (strncmp(p, "cd ", 3) == 0) {
52                 if (chdir(&p[3]) < 0)
53                     perror(&p[3]);
54             }
55             else if (system(p) != 0)
56                 perror(p);
57         add_history(p);
58         free(p);
59     }
60     exit(0);
61     /* NOTREACHED */
62 }