-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.c
More file actions
64 lines (51 loc) · 1.2 KB
/
main.c
File metadata and controls
64 lines (51 loc) · 1.2 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include "headers.h"
#include "main.h"
#include "utils.h"
#include "colours.h"
#include "Commands/process.h"
#include "Commands/history.h"
#include "Features/signals.h"
#include "Features/prompt.h"
char home[10000];
char *stream;
pid_t shellPID;
char *getInput()
{
size_t lineReadSize = 1000;
char *lineRead = malloc(sizeof(char) * lineReadSize);
stream = fgets(lineRead, lineReadSize, stdin);
lineRead[strcspn(lineRead, "\n")] = 0; // remove newline
return lineRead;
}
void tokenize(char *input)
{
char *token;
while (token = strtok_r(input, ";", &input))
tokenizeCommand(token);
}
int main()
{
printf(bold lightPurple "\n Welcome to" lightPink " Magnush" reset "!\n\n" noBold);
getcwd(home, sizeof(home));
loadHistory();
currentID = -1;
shellPID = getpid();
signal(SIGTSTP, ctrlz);
signal(SIGINT, ctrlc);
signal(SIGCHLD, handler);
while (1)
{
prompt();
char *input = getInput();
if (stream == NULL)
{
printf("\n");
return 0;
}
addCommandToHistory(input);
tokenize(input);
printf("\r");
free(input);
}
return 0;
}