-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.c
91 lines (74 loc) · 1.57 KB
/
utils.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
#include <stdio.h>
#include "config.h"
#include "siparse.h"
void
printcommand(command *pcmd, int k)
{
int flags;
printf("\tCOMMAND %d\n",k);
if (pcmd==NULL){
printf("\t\t(NULL)\n");
return;
}
printf("\t\targv=:");
argseq * argseq = pcmd->args;
do{
printf("%s:", argseq->arg);
argseq= argseq->next;
}while(argseq!=pcmd->args);
printf("\n\t\tredirections=:");
redirseq * redirs = pcmd->redirs;
if (redirs){
do{
flags = redirs->r->flags;
printf("(%s,%s):",redirs->r->filename,IS_RIN(flags)?"<": IS_ROUT(flags) ?">": IS_RAPPEND(flags)?">>":"??");
redirs= redirs->next;
} while (redirs!=pcmd->redirs);
}
printf("\n");
}
void
printpipeline(pipeline * p, int k)
{
int c;
command ** pcmd;
commandseq * commands= p->commands;
printf("PIPELINE %d\n",k);
if (commands==NULL){
printf("\t(NULL)\n");
return;
}
c=0;
do{
printcommand(commands->com,++c);
commands= commands->next;
}while (commands!=p->commands);
printf("Totally %d commands in pipeline %d.\n",c,k);
printf("Pipeline %sin backgraound.\n", (p->flags & INBACKGROUND) ? "" : "NOT ");
}
void
printparsedline(pipelineseq * ln)
{
int c;
pipelineseq * ps = ln;
if (!ln){
printf("%s\n",SYNTAX_ERROR_STR);
return;
}
c=0;
do{
printpipeline(ps->pipeline,++c);
ps= ps->next;
} while(ps!=ln);
printf("Totally %d pipelines.",c);
printf("\n");
}
command *
pickfirstcommand(pipelineseq * ppls)
{
if ((ppls==NULL)
|| (ppls->pipeline==NULL)
|| (ppls->pipeline->commands==NULL)
|| (ppls->pipeline->commands->com==NULL)) return NULL;
return ppls->pipeline->commands->com;
}