-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathParser.c
64 lines (56 loc) · 1.46 KB
/
Parser.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
//
// Created by wave_ceo on 11/05/2022.
//
#include <stdio.h>
#include "tshell_func.c"
#include <stdlib.h>
#include <unistd.h>
#include <stdbool.h>
#include <sys/wait.h>
#include <string.h>
void pipeline_tokenizer(char *tbParsed,int c){
int pCount=1;
//printf("%s\n",tbParsed);
char *piped[100];
piped[0] = strtok(tbParsed, "|");
for(int token =1; (piped[token]=strtok(NULL,"|"))!=NULL;token++){
//for (int i = 0; i < c+1; i++) {
// if(piped[i]==NULL){
// i--;
//}
pCount++;
}
// printf("%d\n",pCount);
//for (int i=0;i<pCount;i++){
// printf("%s\n",piped[i]);
//}
int *FIn=NULL;
int *Fout=NULL;
bool block=false;
fork_exec_pipe(piped,pCount,FIn,Fout,block);
wait(NULL);
free(tbParsed);
//return *piped;
//if (piped[1] == NULL) {
// return NULL; // returns zero if no pipe is found.
//}else{
// return *piped;
// }
}
void CheckParsed(char *s,char** parsed,int Tcount){
for (int i=0;i<Tcount;i++){
printf("%s\n",parsed[i]);
}
if (strcmp(parsed[0],">")==0 || strcmp(parsed[0],"<")==0 || strcmp(parsed[0],"|")==0 || strcmp(parsed[0],">>")==0){
printf("error:command not of an executable type");
}else{
if(Tcount==1 ||Tcount==2){
if(BuiltInCMD(parsed)==0){
fork_exec(parsed);
wait(NULL);
}
}else{
pipeline_tokenizer(s,Tcount);
}
}
}