-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.c
57 lines (53 loc) · 1.38 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
57
#include "headers.h"
#include "prompt.h"
#include "input.h"
char homedir[PATH_MAX];
char curDir[PATH_MAX], prevDir[PATH_MAX], tDir[PATH_MAX];
char historypath[PATH_MAX];
int BACKUP_STDOUT_FILENO, BACKUP_STDIN_FILENO;
int main_terminal_id;
extern Node *listptr;
void addhistory(){
int n=strlen(historypath);
historypath[n]='/';
historypath[n+1]='h';
historypath[n+2]='i';
historypath[n+3]='s';
historypath[n+4]='t';
historypath[n+5]='o';
historypath[n+6]='r';
historypath[n+7]='y';
historypath[n+8]='\0';
}
int main(){
system("clear");
// Backing up file descriptors of STDIN and STDOUT
BACKUP_STDIN_FILENO=dup(STDIN_FILENO);
BACKUP_STDOUT_FILENO=dup(STDOUT_FILENO);
main_terminal_id=getpid();
// Getting the homedir
if (getcwd(homedir, sizeof(homedir)) == NULL)
exit(0);
if (getcwd(historypath, sizeof(historypath)) == NULL)
exit(0);
addhistory();
strcpy(curDir, homedir);
// For andling bg childs
signal(SIGCHLD, killChilds);
// Ctr+C
signal(SIGINT, ctcHandler);
// Ctrl+Z
signal(SIGTSTP, ctzHandler);
signal(SIGQUIT, SIG_IGN);
while (1)
{
if (getcwd(tDir, sizeof(tDir)) == NULL)
exit(0);
if(strcmp(tDir, curDir)!=0){
strcpy(prevDir, curDir);
strcpy(curDir, tDir);
}
prompt();
input();
}
}