Line | |
---|
1 | /* $Revision: 1.1.1.1 $
|
---|
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 | extern char *readline();
|
---|
12 | extern void add_history();
|
---|
13 |
|
---|
14 | #if !defined(HAVE_STDLIB)
|
---|
15 | extern int chdir();
|
---|
16 | extern int free();
|
---|
17 | extern int strncmp();
|
---|
18 | extern int system();
|
---|
19 | extern void exit();
|
---|
20 | extern char *getenv();
|
---|
21 | #endif /* !defined(HAVE_STDLIB) */
|
---|
22 |
|
---|
23 |
|
---|
24 | #if defined(NEED_PERROR)
|
---|
25 | void
|
---|
26 | perror(s)
|
---|
27 | char *s;
|
---|
28 | {
|
---|
29 | extern int errno;
|
---|
30 |
|
---|
31 | (voidf)printf(stderr, "%s: error %d\n", s, errno);
|
---|
32 | }
|
---|
33 | #endif /* defined(NEED_PERROR) */
|
---|
34 |
|
---|
35 |
|
---|
36 | /* ARGSUSED1 */
|
---|
37 | int
|
---|
38 | main(ac, av)
|
---|
39 | int ac;
|
---|
40 | char *av[];
|
---|
41 | {
|
---|
42 | char *prompt;
|
---|
43 | char *p;
|
---|
44 | int doit;
|
---|
45 |
|
---|
46 | doit = ac == 1;
|
---|
47 | if ((prompt = getenv("TESTPROMPT")) == NULL)
|
---|
48 | prompt = "testit> ";
|
---|
49 |
|
---|
50 | while ((p = readline(prompt)) != NULL) {
|
---|
51 | (void)printf("\t\t\t|%s|\n", p);
|
---|
52 | if (doit)
|
---|
53 | if (strncmp(p, "cd ", 3) == 0) {
|
---|
54 | if (chdir(&p[3]) < 0)
|
---|
55 | perror(&p[3]);
|
---|
56 | }
|
---|
57 | else if (system(p) != 0)
|
---|
58 | perror(p);
|
---|
59 | add_history(p);
|
---|
60 | free(p);
|
---|
61 | }
|
---|
62 | exit(0);
|
---|
63 | /* NOTREACHED */
|
---|
64 | }
|
---|
65 |
|
---|
66 | /*
|
---|
67 | * $PchId: testit.c,v 1.3 1996/02/22 21:18:51 philip Exp $
|
---|
68 | */
|
---|
Note:
See
TracBrowser
for help on using the repository browser.