-
Notifications
You must be signed in to change notification settings - Fork 0
/
processbuilt_cmd.c
65 lines (59 loc) · 1.08 KB
/
processbuilt_cmd.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
//libraries
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/ptrace.h>
#include <sys/stat.h>
#include <sys/wait.h>
#include <signal.h>
#include <dirent.h>
#include <sys/dir.h>
#include <pwd.h>
#include <grp.h>
#include <time.h>
#include <locale.h>
#include<sys/utsname.h>
#include "declarations.h"
void processbuilt_cmd()
{
char temp[1000];
strcpy(temp,cmd);
char*token2=strtok(cmd,">,<,>>");
strcpy(cmd,token2);
//free(cmd);
char*token=strtok(temp," , ");
while(token!=NULL)
{
if(in1==1 || out1==1 || out2==1)
{
if(doubleredirect==0)
{
strcpy(redirectfile,token);
doubleredirect=1;
token=strtok(NULL," , ");
}
}
if(token!=NULL)
{
if(!strcmp(token,"<"))
{
in1=1;
}
else if(!strcmp(token,">"))
{
out1=1;
}
else if(!strcmp(token,">>"))
{
out2=1;
}
////both redirections
if((in1 && out1) || (in1 && out2))
strcpy(redirectfile2,token);
token=strtok(NULL," , ");
}
}
}