blob: c51a88ffadd97945e0e312742266b5b01677e90a (
plain)
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
|
#include "types.h"
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
#include <errno.h>
/// < Move pointer left
/// > Move pointer right
/// + Increment cell by one
/// - Decrement cell by one
/// [ Jump past the matching ] if the cell at the pointer is 0
/// ] Jump back to the matching [ if the cell at the pointer is nonzero
/// . Output ascii at current cell
/// , Input ascii into current cell
/// * Allocate new tape size of current cell and replace with pointer
/// ! Free allocated pointer in current cell
/// ( Go to tape at pointer in current cell
/// ) Leave tape last entered
/// ` Output null terminated string at current cell
/// ~ Input string into current cells with max length in current cell
/// % Clear screen
int main(int argc, char** argv) {
FILE* file;
if (argc == 1) {
file = stdin;
} else if (argc == 2) {
file = fopen (argv[1], "r");
if (file == NULL) {
printf("error: failed to open %s (%s)\n", argv[1], strerror(errno));
exit(EXIT_FAILURE);
}
} else {
printf("usage: brainfucked infile\n");
return EXIT_FAILURE;
}
Program program;
program_init(&program, file);
interpret(&program);
program_free(&program);
return EXIT_SUCCESS;
}
|