Implement the -y delay in C99 and ANSI C, not just Borland C++.
catseye
9 years ago
61 | 61 | Mingw v2. |
62 | 62 | |
63 | 63 | ****************************************************************** |
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 | |
64 | 70 | |
65 | 71 | v2.22: Mar 2011, Chris Pressey |
66 | 72 | don't insert bogus EOF/directive characters into |
192 | 198 | |
193 | 199 | /********************************************************* PROTOTYPES */ |
194 | 200 | |
201 | void befsleep (int); | |
195 | 202 | void push (signed long val); |
196 | 203 | signed long pop (void); |
197 | 204 | void usage (void); |
227 | 234 | else if (!strcmp(argv[i], "-r")) { infile = 1; ia = i + 1; } |
228 | 235 | else if (!strcmp(argv[i], "-w")) { outfile = 1; oa = i + 1; } |
229 | 236 | 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]); } | |
231 | 238 | else if (!strcmp(argv[i], "-q")) { quiet = 1; } |
232 | 239 | else if (!strcmp(argv[i], "-i")) { ignore_unsupported = 1; } |
233 | 240 | else if (!strcmp(argv[i], "-=")) { use_b97directives = 1; } |
427 | 434 | fflush (stdout); |
428 | 435 | #endif /* CONSOLE */ |
429 | 436 | } |
430 | #if __BORLANDC__ | |
431 | delay (deldur); | |
432 | #endif /* __BORLANDC __ */ | |
437 | befsleep (deldur); | |
433 | 438 | } |
434 | 439 | if (stringmode && (cur != '"')) |
435 | 440 | push (cur); |
842 | 847 | } |
843 | 848 | |
844 | 849 | /* |
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 | /* | |
845 | 872 | * pushes a value onto the stack. |
846 | 873 | */ |
847 | 874 | void push (val) |