-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
62 lines (54 loc) · 1.02 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
58
59
60
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <signal.h>
#include <string.h>
#include "smsh.h"
#define DFL_PROMPT "> "
int main()
{
char *cmdline, *prompt, **arglist, **cmdlist;
char rfileName[32];
int result, fd_out, i, fno, cmdNum, rioFlag;
int sfd = dup(STDOUT_FILENO);
void setup();
prompt = DFL_PROMPT;
setup();
cmdlist = emalloc(BUFSIZ);
while ((cmdline = next_cmd(prompt, stdin)) != NULL)
{
/* io redirection */
rioFlag = getRFileName(cmdline, rfileName);
if (rioFlag > 0)
fd_out = r_open(rfileName);
/* pipe test*/
cmdNum = pipeTest(cmdline, cmdlist);
if (cmdNum == 1)
{
if ((arglist = splitline(cmdline)) != NULL)
{
if (buildIn(arglist))
{
;
} else {
result = execute(arglist);
freelist(arglist);
}
}
}
else if (cmdNum == 2)
{
pipeCommand(cmdlist);
}
//freelist(cmdlist);
free(cmdline);
if (rioFlag > 0)
r_close(sfd);
}
return 0;
}
void setup()
{
signal(SIGINT, SIG_IGN);
signal(SIGQUIT, SIG_IGN);
}