-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
155 lines (127 loc) · 2.46 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
#include "declarations.h"
int main()
{
//initialize
homeflag=1;
maxbg=0;
remindflag=0;
pipein=dup(0);
pipeout=dup(1);
//built in commands
strcpy(c1,"pwd");
strcpy(c2,"echo ");
strcpy(c3,"cd ");
strcpy(c4,"ls");
strcpy(c5,"pinfo");
strcpy(c6,"remindme");
strcpy(c7,"clock");
strcpy(c8,"setenv");
strcpy(c9,"unsetenv");
strcpy(c10,"jobs");
strcpy(c11,"kjob");
strcpy(c12,"overkill");
strcpy(c13,"quit");
strcpy(c14,"fg");
strcpy(c15,"bg");
int i,j,flag,pointer;
while(1)
{
/////////////////////take input////////////////////////////////
flag=0;//for removing front space
pointer=0;//for storing commands
remindflag=0;//for reminder
remindmsg[0]='\0';//for reminder msg
j=0;
cmdc=0;
pipecheck=0;
pipedes=0;
intermediatepipe=0;
//pid=0;/////////////////////////
builtinredirecterror=0;
in1=0;
out1=0;
out2=0;
in1i=0;
out1i=0;
out2i=0;
doubleredirect=0;
char a='z';
//ctrl+c
signal(SIGINT,sigintHandler);
//ctrl+z
signal(SIGTSTP,sigstpHandler);
//ctrl+'\'
signal(SIGQUIT,sigqHandler);
prompt();
//get input
while(a!=10)
{
a=getc(stdin);
if(a==10)
break;
tcs[pointer]=a;
pointer++;
}
tcs[pointer]='\0';
//printf("%s\n",tcs);
/////////////////////////////////////////////////////////////////
////////////////tokenising and storing///////////////////////////
tempcmd=strtok(tcs,";");
while(tempcmd!=NULL)
{
cmdstorage[cmdc]=tempcmd;
tempcmd=strtok(NULL,";");
cmdc++;
}
////////////////////////////////////////////////////////////////
///////////executing all commands given in one input////////////
cmdc--;
while(cmdstorage[cmdc]!=NULL)
{
//initial conditions
remindflag=0;
remindmsg[0]='\0';
flag=0;
pointer=0;
j=0;
pipecheck=0;
pipedes=0;
intermediatepipe=0;
//pid=0;/////////////////////////
builtinredirecterror=0;
in1=0;
out1=0;
out2=0;
in1i=0;
out1i=0;
out2i=0;
doubleredirect=0;
strcpy(cmd,cmdstorage[cmdc]);//for uniformity
//remove front space
for(i=0;i<strlen(cmd);i++)
{
if(flag==0)
{
if(cmd[i]!=32 && cmd[i]!=9)
{
cmd[j++]=cmd[i];
flag=1;
}
}
else
cmd[j++]=cmd[i];
}
cmd[j]='\0';
//remove backward space
for(i=j-1;cmd[i]==9 || cmd[i]==32;i--);
cmd[i+1]='\0';
//if(!builtin_check())
//{
pipefunc();
//}
cmdc--;
}
////////////////////////////////////////////////////////////////
}
return 0;
}