git @ Cat's Eye Technologies Befunge-93 / 297b06e
Implement the -y delay in C99 and ANSI C, not just Borland C++. catseye 9 years ago
1 changed file(s) with 31 addition(s) and 4 deletion(s). Raw diff Collapse all Expand all
6161 Mingw v2.
6262
6363 ******************************************************************
64
65 v2.23: Aug 2012, Chris Pressey
66 delay given with -y now actually happens when compiled
67 with compilers other than Borland C++; it's implemented
68 with nanosleep() in C99, and sleep() (with one-second
69 resolution) in ANSI C
6470
6571 v2.22: Mar 2011, Chris Pressey
6672 don't insert bogus EOF/directive characters into
192198
193199 /********************************************************* PROTOTYPES */
194200
201 void befsleep (int);
195202 void push (signed long val);
196203 signed long pop (void);
197204 void usage (void);
227234 else if (!strcmp(argv[i], "-r")) { infile = 1; ia = i + 1; }
228235 else if (!strcmp(argv[i], "-w")) { outfile = 1; oa = i + 1; }
229236 else if (!strcmp(argv[i], "-s")) { stackfile = 1; sa = i + 1; }
230 else if (!strcmp(argv[i], "-y")) { deldur = atoi(argv[i + 1]); }
237 else if (!strcmp(argv[i], "-y")) { deldur = atoi(argv[++i]); }
231238 else if (!strcmp(argv[i], "-q")) { quiet = 1; }
232239 else if (!strcmp(argv[i], "-i")) { ignore_unsupported = 1; }
233240 else if (!strcmp(argv[i], "-=")) { use_b97directives = 1; }
427434 fflush (stdout);
428435 #endif /* CONSOLE */
429436 }
430 #if __BORLANDC__
431 delay (deldur);
432 #endif /* __BORLANDC __ */
437 befsleep (deldur);
433438 }
434439 if (stringmode && (cur != '"'))
435440 push (cur);
842847 }
843848
844849 /*
850 * sleep for the given number of milliseconds, so far as we are able
851 */
852 void befsleep (dur)
853 int dur;
854 {
855 #if __BORLANDC__
856 delay (deldur);
857 #else
858 #ifdef _POSIX_C_SOURCE
859 struct timespec tv;
860
861 tv.tv_sec = dur / 1000;
862 tv.tv_nsec = (dur % 1000) * 1000000;
863
864 nanosleep(&tv, NULL);
865 #else
866 sleep (dur / 1000);
867 #endif
868 #endif
869 }
870
871 /*
845872 * pushes a value onto the stack.
846873 */
847874 void push (val)