git @ Cat's Eye Technologies Befunge-93 / c91d094
Merge pull request #9 from catseye/defined-input-integer-error-mode Defined input integer error mode Chris Pressey authored 3 years ago GitHub committed 3 years ago
1 changed file(s) with 22 addition(s) and 6 deletion(s). Raw diff Collapse all Expand all
00 /* ******************************************************************
11
22 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.
66 All rights reserved.
77
88 Redistribution and use in source and binary forms, with or without
3838
3939 Usage :
4040
41 bef [-d] [-o] [-q] [-i] [-=] [-l] [-t]
41 bef [-d] [-o] [-u] [-q] [-i] [-=] [-l] [-t]
4242 [-r input-file] [-w output-file]
4343 [-s stack-file] [-y delay] <befunge-source>
4444
4545 -d: visual ANSI debugging display
4646 -o: do not fix off-by-one error (for old sources)
47 -u: & on error or EOF is undefined, not -1 (backwards compat)
4748 -q: produce no output except Befunge program output ('quiet')
4849 -i: ignore unsupported instructions
4950 -=: use b97-ish = directives
6061 DJGPP v2.952 (32-bit Protected-Mode MS-DOS)
6162
6263 ******************************************************************
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)
6370
6471 v2.23: Aug 2012, Chris Pressey
6572 delay given with -y now actually happens when compiled
122129 v2.00: Jun 1997, Chris Pressey
123130 combines interpreter and debugger.
124131 fixes ANSI error in debugger.
132
125133 v1.02: Feb 1996, Chris Pressey
126134 @ now pushes '@' onto the stack in stringmode instead of quitting.
127135
191199 int stringmode = 0; /* flag : are we in string mode? */
192200 int quiet = 0; /* flag : are we quiet? */
193201 int v10err_compat = 0; /* flag : emulate v1.0 off-by-one err? */
202 int undef_input_int = 0; /* flag : undefined value on "&" err/EOF? */
194203 int deldur = 25; /* debugging delay in milliseconds */
195204 int ignore_unsupported = 0; /* flag : ignore unsupported instructions? */
196205 int use_b97directives = 0; /* flag : use b97-esque directives? */
232241 {
233242 if (argv[i][0] == '-') {
234243 if (!strcmp(argv[i], "-o")) { v10err_compat = 1; }
244 else if (!strcmp(argv[i], "-u")) { undef_input_int = 1; }
235245 else if (!strcmp(argv[i], "-d")) { debug = 1; }
236246 else if (!strcmp(argv[i], "-r")) { infile = 1; ia = i + 1; }
237247 else if (!strcmp(argv[i], "-w")) { outfile = 1; oa = i + 1; }
251261 }
252262 if (!quiet)
253263 {
254 printf ("Befunge-93 Interpreter/Debugger v2.23\n");
264 printf ("Befunge-93 Interpreter/Debugger v2.24\n");
255265 }
256266
257267 memset(pg, ' ', LINEWIDTH * PAGEHEIGHT);
660670 case '&': /* Input Integer */
661671 {
662672 signed long b;
673 if (!undef_input_int) {
674 b = -1;
675 }
663676 if (infile)
664677 {
665678 fscanf (fi, "%ld", &b);
676689 int x, y;
677690 long int p;
678691 char t[172];
692 if (!undef_input_int) {
693 p = -1;
694 }
679695 x = wherex();
680696 y = wherey();
681697 gettext(10, DEBUGROW, 80, DEBUGROW, t);
904920
905921 void usage ()
906922 {
907 printf ("USAGE: bef [-d] [-o] [-q] [-i] [-=] [-l] [-t]\n");
923 printf ("USAGE: bef [-d] [-o] [-u] [-q] [-i] [-=] [-l] [-t]\n");
908924 printf (" [-r input] [-w output] [-s stack] [-y delay] foo.bf\n");
909925 exit (1);
910926 }