/* macros */
#define BUFSIZE 256
-#define MEMSIZE 10
+#define MEMSIZE 8
/* type definition */
int usage (int ret)
{
FILE *fd = ret ? stderr : stdout;
- fprintf (fd, "usage: %s [-i file] [-h] [-m k&r|ansi|c99] [-o file] [-v]\n", progname);
+ fprintf (fd, "usage: %s [-i file] [-h] [-m memory] [-o file] [-v]\n", progname);
fprintf (fd, " -i : input file\n");
fprintf (fd, " -h : help message\n");
- fprintf (fd, " -m : indent mode\n");
+ fprintf (fd, " -m : memory [0..0]\n");
fprintf (fd, " -o : output file\n");
fprintf (fd, " -v : verbose level (%d)\n", verbose);
char *input = NULL;
char *output = NULL;
char *buffer = NULL;
+ int i;
int n = 0;
int size = 0;
FILE *fid = NULL;
}
int c;
- while ((c = getopt(argc, argv, "i:o:hv:")) != EOF) {
+ while ((c = getopt(argc, argv, "i:m:o:hv:")) != EOF) {
switch (c) {
case 'i':
input = optarg;
break;
+ case 'm':
+ for (i = 0; i < MEMSIZE; i++) {
+ if (optarg) {
+ mem[i] = strtol (optarg, &optarg, 10);
+ VERBOSE (DEBUG, fprintf (stderr, "%s: mem[%d] = %d\n", progname, i, mem[i]));
+ }
+ }
+ if (*optarg != 0) {
+ VERBOSE (WARNING, fprintf (stderr, "%s: too many memory values\n", progname));
+ return 1;
+ }
+ break;
case 'o':
output = optarg;
break;
/* main process */
int rc = process (buffer, size, fid);
+ VERBOSE (INFO, fprintf (stdout, "\nmemory:"); int _i; for (_i = 0; _i < MEMSIZE; _i++) fprintf (stdout," %d", mem[_i]); fprintf (stdout,"\n"));
/* close output file */
fclose (fid);
// test: bf.exe -h | awk '/usage:/ { rc=1 } END { exit (1-rc) }'
// test: bf.exe -_ 2> /dev/null | awk 'END { if (NR == 0) { exit(0) } else exit (1) }'
// test: bf.exe -_ 2>&1 | awk '/usage:/ { rc=1 } END { exit (1-rc) }'
-// test: echo '++++++++++[>+++++++>++++++++++>+++>+<<<<-]>++.>+.+++++++..+++.>++.<<+++++++++++++++.>.+++.------.--------.>+.>.' | bf.exe
-// test: echo '++++++++++[>+>+++>+++++++>++++++++++<<<<-]>>>++++++++++++++.>+++++++++++++++++.<<++.>+++++++++++++.>--.<<.>+++.+.--.>----.++++++.+.<++.>----.++.<<.>>+.-------.<<.>>++.<.>+++++.<<.>-.+.<.>---.>---.<-.++++++++.>----.<---.>+++++++.<---.++++++++.' | bf.exe
-// test: echo ',3>,2>>++++++++++++++++[-<+++<---<--->>>]<<[<[>>+>+<<<-]>>>[<<<+>>>-]<<-]>.' | bf.exe
+// test: echo '++++++++++[>+++++++>++++++++++>+++>+<<<<-]>++.>+.+++++++..+++.>++.<<+++++++++++++++.>.+++.------.--------.>+.>.' | bf.exe -v1 | grep -q "Hello World!"
+// test: echo '++++++++++[>+>+++>+++++++>++++++++++<<<<-]>>>++++++++++++++.>+++++++++++++++++.<<++.>+++++++++++++.>--.<<.>+++.+.--.>----.++++++.+.<++.>----.++.<<.>>+.-------.<<.>>++.<.>+++++.<<.>-.+.<.>---.>---.<-.++++++++.>----.<---.>+++++++.<---.++++++++.' | bf.exe -v1 | grep -q "Tu as decouvert un peu de brainfuck"
+// test: echo ',4>++++++[<-------->-],3[<+>-]<.' | bf.exe -v1 | grep -q 7
+
+// test: echo ',3>,2>>++++++++++++++++[-<+++<---<--->>>]<<[<[>>+>+<<<-]>>>[<<<+>>>-]<<-]>.' | bf.exe -v1 | grep -q 6
+// test: echo ',3>,2[->>+<<]+<[->>>[>>>>>+<<<<<->+<<]<[>]>>>>>[-<<->>>>>>>]<[>]<<<<<<]>[>>>>->]<<<<<<[-]>[-]>>[-]>.' | bf.exe -v1 | grep -q 3
/* vim: set ts=4 sw=4 et: */