-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshell.c
More file actions
68 lines (67 loc) · 1.72 KB
/
shell.c
File metadata and controls
68 lines (67 loc) · 1.72 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
65
66
67
68
#include "global.h"
#include "input_manipulation.h"
#include "exit.h"
#include "initial.h"
#include "signalhandle.h"
#include "prompt.h"
#include "lookup.h"
#include "piping.h"
int main()
{
initfun(); // initializes shelldir, history
char input[1000];
char tmp[1000];
signal(SIGINT, Handle_SIGINT);
signal(SIGTSTP, Handle_SIGSTP);
while (1)
{
prompt(); // prints username, hostname and path
strcpy(input, readLine());
strcpy(tmp, input);
int iscopy = strcmp(tmp, history[(size_hist + 19) % 20]);
commandsHere = separateCommands(input);
for (int i = 0; i < numcommands; i++)
{
commands = separateInput(commandsHere[i]);
if (numargs == 0)
continue;
if (i == 0 & iscopy != 0)
{
strcpy(history[(size_hist) % 20], tmp);
size_hist++;
if (size_hist > 20)
{
first_hist = (first_hist + 1) % 20;
}
}
if (checkForInputFile() < 0)
{
continue;
}
if (checkForOutputFile() < 0)
{
continue;
}
// int check;
if (checkpipes())
{
handlepipes();
}
else
{
check = lookup();
}
free(commands);
if (changedStdIn)
{
resetFiles(copyOfStdIn, 0, &changedStdIn);
}
if (changedStdOut)
{
resetFiles(copyOfStdOut, 1, &changedStdOut);
}
}
free(commandsHere);
}
return 0;
}