-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshell.c
55 lines (50 loc) · 1.21 KB
/
shell.c
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
45
46
47
48
49
50
51
52
53
54
55
/*
* Minimalistic shell
* (c) 2011 Jeremy Baumont
*
*
*/
#include <stdio.h>
#include <string.h>
#include "parse.h"
int
main(int argc, char *argv[], char *envp[]) {
char tmp[CMD_LINE_SIZE];
char *prompt = "jshell>";
int cargc = 0;
char *cargv[CMD_LINE_SIZE];
char *cenvp[CMD_LINE_SIZE];
char in[FILENAME_SIZE];
char out[FILENAME_SIZE];
int am = WRONLY;
int c;
memset(tmp, '\0', sizeof(tmp));
memset(in, '\0', sizeof(in));
memset(out, '\0', sizeof(out));
memset(cargv, '\0', sizeof(cargv));
memset(cenvp, '\0', sizeof(cenvp));
printf("\n%s", prompt);
while(c != EOF) {
c = getchar();
switch(c) {
case '\n': /* parse and execute. */
parse(tmp, &cargc, cargv,
cenvp, in, out, &am);
execute(&cargc, cargv, cenvp, in, out, &am);
memset(tmp, 0, sizeof(tmp));
memset(cargv, 0, sizeof(cargv));
memset(cenvp, 0, sizeof(cenvp));
memset(in, '\0', sizeof(in));
memset(out, '\0', sizeof(out));
am = WRONLY;
cargc = 0;
printf("\n%s", prompt);
break;
default:
strncat(tmp, (const char*) &c, 1);
break;
}
}
/* some processing before terminating. */
return 0;
}