-
Notifications
You must be signed in to change notification settings - Fork 4
/
main.c
69 lines (60 loc) · 1.3 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
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "forked.h"
char buf[1000][1000];
int bufsize;
FILE *in;
/* flags */
int display_code;
int display_buffer;
int main(int argc, char **argv)
{
int i;
char *fname = 0;
for (i = 1; i < argc; i++) {
if (argv[i][0] == '-')
option(argv[i]);
else
fname = argv[i];
}
in = fname ? fopen(fname,"r") : stdin;
int x = 0, y = 0, c;
while ((c = getc(in)) != EOF)
{
if (c == '\n') {
y++;
x = 0;
bufsize++;
} else {
buf[y][x] = c;
x++;
}
}
if (display_buffer)
{
for (y = 0; y < bufsize; y++) {
for (x = 0; buf[y][x]; x++)
putchar(buf[y][x]);
puts("");
}
}
int retval = interp();
fflush(stdout);
if (retval == 2) {
fprintf(stderr,"Error 2: went off the edge of the playing field\n");
return 2;
}
else if (retval == 1) {
fprintf(stderr,"Error 1: invalid direction\n");
return 1;
}
return 0;
}
void option(char *s)
{
if (!strcmp(s,"--display-code") || !strcmp(s,"-d"))
display_code = 1;
else if (!strcmp(s,"--display-buffer") || !strcmp(s,"-b"))
display_buffer = 1;
}