-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshellsplit.c
More file actions
45 lines (42 loc) · 1.08 KB
/
shellsplit.c
File metadata and controls
45 lines (42 loc) · 1.08 KB
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
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <stdbool.h>
#include <ctype.h>
#include <string.h>
#include "buffer.h"
#include "fsa.h"
#include "parser.h"
#include "executor.h"
#include "logger.h"
#include "random.h"
void explain_simplecmd(simplecmd s) {
printf("Run program \"%s\"", s.argv[0]);
if(s.argc > 1) {
printf(" with %s ", (s.argc == 2) ? "argument" : "arguments");
int i;
for(i=1;i<s.argc-1;++i)
printf("\"%s\" and ", s.argv[i]);
printf("\"%s\"", s.argv[i]);
}
printf(".");
if(isfile(s.input_fname))
printf(" Read the input from file \"%s\".", s.input_fname);
if(isfile(s.output_fname))
printf(" Write the output to file \"%s\".", s.output_fname);
else if(s.output_fname == stderr)
printf(" Write the output to <stderr>.");
printf("\n");
}
main(int argc, char *argv[]) {
int len;
start_log("log/shellsplit.log");
filestream in = make_filestream(stdin);
while(!in.seen_eof) {
simplecmd s = parse_simplecmd(&in, &len);
explain_simplecmd(s);
free_simplecmd(s);
}
unmake_filestream(in);
close_log();
}