git @ Cat's Eye Technologies Befunge-93 / 8646d03
Import of bef-2.22-2011.0318 sources. catseye 9 years ago
2 changed file(s) with 100 addition(s) and 53 deletion(s). Raw diff Collapse all Expand all
00
11
2 Welcome to the Befunge-93 v2.21 Source Archive
2 Welcome to the Befunge-93 v2.22 Source Archive
33 ==============================================
4 Sep 20 2004 Chris Pressey, Cat's-Eye Technologies.
5 http://catseye.webhop.net/projects/bef/
4 Mar 18 2011 Chris Pressey, Cat's Eye Technologies.
5 http://catseye.tc/projects/bef/
66
77
88
99 Contents:
1010
1111 readme.txt : these post-modernist existential rants
12 bef.c : Befunge-93 interpreter/debugger v2.21 source code
12 bef.c : Befunge-93 interpreter/debugger v2.22 source code
1313 bef2c.c : Befunge-93 to ANSI C compiler v0.94 source code
1414 befprof.c : Befunge-93 profiler v0.94 source code
1515
1717
1818 For More Information on Befunge-93:
1919
20 See the Cat's-Eye Technologies' "official" Befunge-93 Web Site:
20 See Cat's Eye Technologies' official Befunge-93 Project Page:
2121
22 http://catseye.webhop.net/projects/befunge93/
22 http://catseye.tc/projects/befunge93/
2323
2424
2525
2626 Happy Befunging!
2727
28 -- Chris Pressey, Sep 20 2004
28 -- Chris Pressey, Mar 18 2011
00 /* ******************************************************************
11
22 bef.c - The Original Befunge-93 Interpreter/Debugger in ANSI C
3 v2.21 Sep 20 2004 Chris Pressey, Cat's-Eye Technologies
4
5 Copyright (c)1993-2004, Cat's Eye Technologies.
3 v2.22 Mar 18 2011 Chris Pressey, Cat's Eye Technologies
4
5 Copyright (c)1993-2011, Cat's Eye Technologies.
66 All rights reserved.
77
88 Redistribution and use in source and binary forms, with or without
1010 are met:
1111
1212 Redistributions of source code must retain the above copyright
13 notice, this list of conditions and the following disclaimer.
13 notices, this list of conditions and the following disclaimer.
1414
1515 Redistributions in binary form must reproduce the above copyright
16 notice, this list of conditions and the following disclaimer in
16 notices, this list of conditions, and the following disclaimer in
1717 the documentation and/or other materials provided with the
1818 distribution.
1919
20 Neither the name of Cat's Eye Technologies nor the names of its
20 Neither the names of the copyright holders nor the names of their
2121 contributors may be used to endorse or promote products derived
2222 from this software without specific prior written permission.
2323
24 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
25 CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
26 INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
27 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
28 DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE
29 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
30 OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
32 OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
33 ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
34 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35 OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 POSSIBILITY OF SUCH DAMAGE.
24 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES INCLUDING, BUT NOT
26 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
27 FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
28 COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
29 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
30 BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
31 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
32 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
34 ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35 POSSIBILITY OF SUCH DAMAGE.
3736
3837 ******************************************************************
3938
4039 Usage :
4140
42 bef [-d] [-o] [-q] [-i] [-=]
41 bef [-d] [-o] [-q] [-i] [-=] [-l] [-t]
4342 [-r input-file] [-w output-file]
4443 [-s stack-file] [-y delay] <befunge-source>
4544
4847 -q: produce no output except Befunge program output ('quiet')
4948 -i: ignore unsupported instructions
5049 -=: use b97-ish = directives
50 -l: wrap instead of truncating long program lines (compat w/2.21)
51 -t: make # at edge of playfield wrap inconsistently (compat w/2.21)
5152 -r: redirect input from a specified file instead of stdin
5253 -w: redirect output to a specified file instead of stdout
5354 -s: write contents of stack to log file
6061 Mingw v2.
6162
6263 ******************************************************************
64
65 v2.22: Mar 2011, Chris Pressey
66 don't insert bogus EOF/directive characters into
67 playfield when loading otherwise blank source file
68 (thanks to whoever sent me this patch 6 years ago)
69 truncate long lines instead of wrapping them, so that
70 programs that use the full 80 characters on adjacent
71 lines (like mycology) can load correctly; -l disables
72 make # at edge of playfield wrap and consistently skip
73 a space, regardless of which edge it's on; -t disables
74 unknown command-line options are reported as such
75 use corrected verbiage in license (I am not a Regent)
6376
6477 v2.21: Sep 2004, Chris Pressey
6578 display correct version number
174187 int deldur = 25; /* debugging delay in milliseconds */
175188 int ignore_unsupported = 0; /* flag : ignore unsupported instructions? */
176189 int use_b97directives = 0; /* flag : use b97-esque directives? */
190 int wrap_long_program_lines = 0; /* flag : long program lines wrap? */
191 int inconsistent_trampoline = 0; /* flag : should # wrap inconsistently? */
177192
178193 /********************************************************* PROTOTYPES */
179194
180195 void push (signed long val);
181196 signed long pop (void);
197 void usage (void);
182198
183199 /******************************************************* MAIN PROGRAM */
184200
201217
202218 if (argc < 2)
203219 {
204 printf ("USAGE: bef [-d] [-o] [-q] [-i] [-=]\n");
205 printf (" [-r input] [-w output] [-s stack] [-y delay] foo.bf\n");
206 exit (0);
220 usage();
207221 }
208222 for (i = 1; i < argc; i++)
209223 {
210 if (!strcmp(argv[i], "-o")) { v10err_compat = 1; }
211 if (!strcmp(argv[i], "-d")) { debug = 1; }
212 if (!strcmp(argv[i], "-r")) { infile = 1; ia = i + 1; }
213 if (!strcmp(argv[i], "-w")) { outfile = 1; oa = i + 1; }
214 if (!strcmp(argv[i], "-s")) { stackfile = 1; sa = i + 1; }
215 if (!strcmp(argv[i], "-y")) { deldur = atoi(argv[i + 1]); }
216 if (!strcmp(argv[i], "-q")) { quiet = 1; }
217 if (!strcmp(argv[i], "-i")) { ignore_unsupported = 1; }
218 if (!strcmp(argv[i], "-=")) { use_b97directives = 1; }
224 if (argv[i][0] == '-') {
225 if (!strcmp(argv[i], "-o")) { v10err_compat = 1; }
226 else if (!strcmp(argv[i], "-d")) { debug = 1; }
227 else if (!strcmp(argv[i], "-r")) { infile = 1; ia = i + 1; }
228 else if (!strcmp(argv[i], "-w")) { outfile = 1; oa = i + 1; }
229 else if (!strcmp(argv[i], "-s")) { stackfile = 1; sa = i + 1; }
230 else if (!strcmp(argv[i], "-y")) { deldur = atoi(argv[i + 1]); }
231 else if (!strcmp(argv[i], "-q")) { quiet = 1; }
232 else if (!strcmp(argv[i], "-i")) { ignore_unsupported = 1; }
233 else if (!strcmp(argv[i], "-=")) { use_b97directives = 1; }
234 else if (!strcmp(argv[i], "-l")) { wrap_long_program_lines = 1; }
235 else if (!strcmp(argv[i], "-t")) { inconsistent_trampoline = 1; }
236 else
237 {
238 printf("Unknown option: %s\n", argv[i]);
239 usage();
240 }
241 }
219242 }
220243 if (!quiet)
221244 {
222 printf ("Befunge-93 Interpreter/Debugger v2.21\n");
245 printf ("Befunge-93 Interpreter/Debugger v2.22\n");
223246 }
224247
225248 memset(pg, ' ', LINEWIDTH * PAGEHEIGHT);
239262
240263 while (!feof (f))
241264 {
242 cur = fgetc (f);
243 if (use_b97directives && (x == 0) && ((cur == dc) || ((accept_pound) && (cur == '#'))))
265 tc = fgetc (f);
266 if (feof (f))
267 break;
268 if (use_b97directives && (x == 0) &&
269 ((tc == dc) || (accept_pound && (tc == '#'))))
244270 {
245 if (cur != '#') accept_pound = 0;
271 if (tc != '#') accept_pound = 0;
246272 tc = fgetc (f);
247273 if (tc == 'l')
248274 {
257283 }
258284 if (strcmp(s, "b93"))
259285 {
260 fprintf(stderr, "Error: only Befunge-93 (not %s) sources are supported by BEF.\n", s);
286 fprintf(stderr, "Error: only Befunge-93 (not %s) sources are supported by bef.\n", s);
261287 exit(10);
262288 }
263289 }
268294 } else
269295 {
270296 accept_pound = 0;
271 if (cur == '\n')
272 {
273 cur = ' ';
297 if (tc == '\n')
298 {
274299 x = 0;
275300 y++;
276301 if (y >= PAGEHEIGHT) break;
277302 } else
278303 {
304 cur = tc;
279305 x++;
280306 if (x >= LINEWIDTH)
281307 {
308 if (!wrap_long_program_lines)
309 {
310 while (tc != '\n')
311 {
312 tc = fgetc (f);
313 if (feof(f)) { y = PAGEHEIGHT; break; }
314 }
315 }
282316 x = 0;
283317 y++;
284318 if (y >= PAGEHEIGHT) break;
750784 if (v10err_compat)
751785 {
752786 x = LINEWIDTH;
787 } else if (inconsistent_trampoline)
788 {
789 x = LINEWIDTH - 1;
753790 } else
754 {
755 x = LINEWIDTH - 1;
756 }
791 {
792 x += LINEWIDTH;
793 }
757794 else
758795 x = x % LINEWIDTH;
759796 if (y < 0)
760797 if (v10err_compat)
761798 {
762799 y = PAGEHEIGHT;
800 } else if (inconsistent_trampoline)
801 {
802 y = PAGEHEIGHT - 1;
763803 } else
764 {
765 y = PAGEHEIGHT - 1;
766 }
804 {
805 y += PAGEHEIGHT;
806 }
767807 else
768808 y = y % PAGEHEIGHT;
769809 if (stackfile)
832872 return 0;
833873 }
834874 }
875
876 void usage ()
877 {
878 printf ("USAGE: bef [-d] [-o] [-q] [-i] [-=] [-l] [-t]\n");
879 printf (" [-r input] [-w output] [-s stack] [-y delay] foo.bf\n");
880 exit (1);
881 }