-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
56 lines (41 loc) · 1.23 KB
/
main.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
56
#include "header.h"
#include "shell.h"
#include "tokenize.h"
#include "global.h"
#include "signal.h"
pid_t fg_pid = -1;
int main(int argc, char *argv[]){
signal(SIGCHLD, sigchld_handler);
signal(SIGTSTP, sigtstp_handler);
signal(SIGINT, sigint_handler);
char home_path[MAX_LEN],previous[MAX_LEN];
directory(home_path);
directory(previous);
while(true){
char* username = get_username();
char* system_name = get_system_name();
char* dir = get_directory(home_path);
printf(BLU "<%s@%s:%s" RESET,username,system_name,dir);
int dur = get_global_dur();
if(dur == -1) printf(BLU "> " RESET);
else{
char* firstword = get_global_firstword();
printf(BLU " %s : %ds> " RESET,firstword,dur);
free(firstword);
set_global_flags(-1,NULL);
}
free(username);
free(system_name);
free(dir);
char command[MAX_LEN];
fgets(command,sizeof(command),stdin);
command[strcspn(command,"\n")] = '\0';
if(feof(stdin)){
kill(0,SIGKILL);
printf("\n");
exit(0);
}
tokenize(command,home_path,previous);
}
return 0;
}