-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
91 lines (81 loc) · 1.76 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
/******************************************************************************
*
* File Name........: main.c
*
* Description......: Simple driver program for ush's parser
*
* Author...........: Vincent W. Freeh
*
*****************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include "parse.h"
static void prCmd(Cmd c)
{
int i;
if ( c ) {
printf("%s%s ", c->exec == Tamp ? "BG " : "", c->args[0]);
if ( c->in == Tin )
printf("<(%s) ", c->infile);
if ( c->out != Tnil )
switch ( c->out ) {
case Tout:
printf(">(%s) ", c->outfile);
break;
case Tapp:
printf(">>(%s) ", c->outfile);
break;
case ToutErr:
printf(">&(%s) ", c->outfile);
break;
case TappErr:
printf(">>&(%s) ", c->outfile);
break;
case Tpipe:
printf("| ");
break;
case TpipeErr:
printf("|& ");
break;
default:
fprintf(stderr, "Shouldn't get here\n");
exit(-1);
}
if ( c->nargs > 1 ) {
printf("[");
for ( i = 1; c->args[i] != NULL; i++ )
printf("%d:%s,", i, c->args[i]);
printf("\b]");
}
putchar('\n');
// this driver understands one command
if ( !strcmp(c->args[0], "end") )
exit(0);
}
}
static void prPipe(Pipe p)
{
int i = 0;
Cmd c;
if ( p == NULL )
return;
printf("Begin pipe%s\n", p->type == Pout ? "" : " Error");
for ( c = p->head; c != NULL; c = c->next ) {
printf(" Cmd #%d: ", ++i);
prCmd(c);
}
printf("End pipe\n");
prPipe(p->next);
}
int main(int argc, char *argv[])
{
Pipe p;
char *host = "armadillo";
while ( 1 ) {
printf("%s%% ", host);
p = parse();
prPipe(p);
freePipe(p);
}
}
/*........................ end of main.c ....................................*/