-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshell.c
More file actions
46 lines (43 loc) · 1.08 KB
/
shell.c
File metadata and controls
46 lines (43 loc) · 1.08 KB
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
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <signal.h>
#include "simple_shell/rec_desc.h"
void sigint_ign(int s) {
// printf("^C\n");
kill(0, SIGTERM);
}
int main(void) {
char *curline = NULL;
int res;
size_t what;
int flag;
Expression expr;
// signal(SIGINT, sigint_ign);
// signal(SIGTERM, SIG_IGN);
init_expression(&expr, "");
// char *cwd;
for (;;) {
// cwd = getcwd(NULL, 0);
printf(">>> ");
if (getline(&curline, &what, stdin) == -1) {
printf("error reading\n");
break;
} else if ((strlen(curline) == 2) && (*curline == 'q')) {
break;
} else {
free(expr.string_form);
expr.string_form = strdup(curline);
expr.curpointer = expr.string_form;
if ((flag = compute_expression(&expr, &res)) != 0) {
err_print(flag);
}
// printf("result = %d\n", res);
}
res = 0;
}
// free(cwd);
free(curline);
finalize_expression(&expr);
return 0;
}