-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtestit.c
More file actions
44 lines (38 loc) · 747 Bytes
/
Copy pathtestit.c
File metadata and controls
44 lines (38 loc) · 747 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
/* $Revision: 1.4 $
**
** A "micro-shell" to test editline library.
** If given any arguments, commands aren't executed.
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
extern char *readline();
extern void add_history();
int
main(ac, av)
int ac;
char *av[];
{
char *prompt;
char *p;
int doit;
doit = ac == 1;
if ((prompt = getenv("TESTPROMPT")) == NULL)
prompt = "testit> ";
while ((p = readline(prompt)) != NULL) {
(void)printf("\t\t\t|%s|\n", p);
if (doit) {
if (strncmp(p, "cd ", 3) == 0) {
if (chdir(&p[3]) < 0)
perror(&p[3]);
}
else if (system(p) != 0)
perror(p);
}
add_history(p);
free(p);
}
exit(0);
/* NOTREACHED */
}