source: trunk/minix/lib/editline/testit.c@ 11

Last change on this file since 11 was 9, checked in by Mattia Monga, 14 years ago

Minix 3.1.2a

File size: 1.2 KB
RevLine 
[9]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
11extern char *readline();
12extern void add_history();
13
14#if !defined(HAVE_STDLIB)
15extern int chdir();
16extern int free();
17extern int strncmp();
18extern int system();
19extern void exit();
20extern char *getenv();
21#endif /* !defined(HAVE_STDLIB) */
22
23
24#if defined(NEED_PERROR)
25void
26perror(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 */
37int
38main(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.