-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshell.c
More file actions
43 lines (40 loc) · 1.12 KB
/
shell.c
File metadata and controls
43 lines (40 loc) · 1.12 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
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<unistd.h>
#include"interpreter.h"
#include"shellmemory.h"
int check(int i){printf("checkpoint %d\n", i);}
int shellUI(){
printf("Welcome to the Jiaxuan Chen shell!\n"
"Version 1.0 Created January 2020\n");
shell_memory_initialize();
int status=0;
while (!feof(stdin)){
if(isatty(STDIN_FILENO)) printf("$ ");
fflush(stdout);
char *line = NULL;
size_t linecap = 0;
if (getline(&line, &linecap, stdin) == -1) {
if(!isatty(STDIN_FILENO)){
FILE *tty;
tty = freopen("/dev/tty", "r", stdin);
continue;
}
break;
}
if(!isatty(STDIN_FILENO)) {
if(line[0]=='\n') printf("$ \n");
else {
if(line[strlen(line)-1]!='\n') printf("$ %s\n", line);
else printf("$ %s", line);
}
}
if(line[0]=='\n') continue;
status=interpreter(line);
free(line);
if(status==999) break;
}
shell_memory_destory();
return 0;
}