Make & push -1 on error or EOF unless back-compat -u flag is given.
Chris Pressey
3 years ago
0 | 0 | /* ****************************************************************** |
1 | 1 | |
2 | 2 | bef.c - The Original Befunge-93 Interpreter/Debugger in ANSI C |
3 | v2.23-and-then-some-TODO-describe-the-changes-then-bump-this | |
4 | ||
5 | Copyright (c)1993-2015, Chris Pressey, Cat's Eye Technologies. | |
3 | v2.24 | |
4 | ||
5 | Copyright (c)1993-2018, Chris Pressey, Cat's Eye Technologies. | |
6 | 6 | All rights reserved. |
7 | 7 | |
8 | 8 | Redistribution and use in source and binary forms, with or without |
38 | 38 | |
39 | 39 | Usage : |
40 | 40 | |
41 | bef [-d] [-o] [-q] [-i] [-=] [-l] [-t] | |
41 | bef [-d] [-o] [-u] [-q] [-i] [-=] [-l] [-t] | |
42 | 42 | [-r input-file] [-w output-file] |
43 | 43 | [-s stack-file] [-y delay] <befunge-source> |
44 | 44 | |
45 | 45 | -d: visual ANSI debugging display |
46 | 46 | -o: do not fix off-by-one error (for old sources) |
47 | -u: & on error or EOF is undefined, not -1 (backwards compat) | |
47 | 48 | -q: produce no output except Befunge program output ('quiet') |
48 | 49 | -i: ignore unsupported instructions |
49 | 50 | -=: use b97-ish = directives |
60 | 61 | DJGPP v2.952 (32-bit Protected-Mode MS-DOS) |
61 | 62 | |
62 | 63 | ****************************************************************** |
64 | ||
65 | v2.24: Summer 2018, Chris Pressey | |
66 | when & encounters an error or EOF condition it pushes | |
67 | -1 onto the stack instead of an undefined value; | |
68 | added -u option to retain old behaviour in this case | |
69 | (thanks to James Holderness for noticing and suggesting) | |
63 | 70 | |
64 | 71 | v2.23: Aug 2012, Chris Pressey |
65 | 72 | delay given with -y now actually happens when compiled |
122 | 129 | v2.00: Jun 1997, Chris Pressey |
123 | 130 | combines interpreter and debugger. |
124 | 131 | fixes ANSI error in debugger. |
132 | ||
125 | 133 | v1.02: Feb 1996, Chris Pressey |
126 | 134 | @ now pushes '@' onto the stack in stringmode instead of quitting. |
127 | 135 | |
191 | 199 | int stringmode = 0; /* flag : are we in string mode? */ |
192 | 200 | int quiet = 0; /* flag : are we quiet? */ |
193 | 201 | int v10err_compat = 0; /* flag : emulate v1.0 off-by-one err? */ |
202 | int undef_input_int = 0; /* flag : undefined value on "&" err/EOF? */ | |
194 | 203 | int deldur = 25; /* debugging delay in milliseconds */ |
195 | 204 | int ignore_unsupported = 0; /* flag : ignore unsupported instructions? */ |
196 | 205 | int use_b97directives = 0; /* flag : use b97-esque directives? */ |
232 | 241 | { |
233 | 242 | if (argv[i][0] == '-') { |
234 | 243 | if (!strcmp(argv[i], "-o")) { v10err_compat = 1; } |
244 | else if (!strcmp(argv[i], "-u")) { undef_input_int = 1; } | |
235 | 245 | else if (!strcmp(argv[i], "-d")) { debug = 1; } |
236 | 246 | else if (!strcmp(argv[i], "-r")) { infile = 1; ia = i + 1; } |
237 | 247 | else if (!strcmp(argv[i], "-w")) { outfile = 1; oa = i + 1; } |
251 | 261 | } |
252 | 262 | if (!quiet) |
253 | 263 | { |
254 | printf ("Befunge-93 Interpreter/Debugger v2.23\n"); | |
264 | printf ("Befunge-93 Interpreter/Debugger v2.24\n"); | |
255 | 265 | } |
256 | 266 | |
257 | 267 | memset(pg, ' ', LINEWIDTH * PAGEHEIGHT); |
660 | 670 | case '&': /* Input Integer */ |
661 | 671 | { |
662 | 672 | signed long b; |
673 | if (!undef_input_int) { | |
674 | b = -1; | |
675 | } | |
663 | 676 | if (infile) |
664 | 677 | { |
665 | 678 | fscanf (fi, "%ld", &b); |
676 | 689 | int x, y; |
677 | 690 | long int p; |
678 | 691 | char t[172]; |
692 | if (!undef_input_int) { | |
693 | p = -1; | |
694 | } | |
679 | 695 | x = wherex(); |
680 | 696 | y = wherey(); |
681 | 697 | gettext(10, DEBUGROW, 80, DEBUGROW, t); |
904 | 920 | |
905 | 921 | void usage () |
906 | 922 | { |
907 | printf ("USAGE: bef [-d] [-o] [-q] [-i] [-=] [-l] [-t]\n"); | |
923 | printf ("USAGE: bef [-d] [-o] [-u] [-q] [-i] [-=] [-l] [-t]\n"); | |
908 | 924 | printf (" [-r input] [-w output] [-s stack] [-y delay] foo.bf\n"); |
909 | 925 | exit (1); |
910 | 926 | } |