diff options
Diffstat (limited to 'editors/awk.c')
| -rw-r--r-- | editors/awk.c | 41 |
1 files changed, 40 insertions, 1 deletions
diff --git a/editors/awk.c b/editors/awk.c index 64e752f4b..1feb49da1 100644 --- a/editors/awk.c +++ b/editors/awk.c | |||
| @@ -970,7 +970,7 @@ static double my_strtod_or_hexoct(char **pp) | |||
| 970 | static const char *fmt_num(const char *format, double n) | 970 | static const char *fmt_num(const char *format, double n) |
| 971 | { | 971 | { |
| 972 | if (n == (long long)n) { | 972 | if (n == (long long)n) { |
| 973 | snprintf(g_buf, MAXVARFMT, "%lld", (long long)n); | 973 | snprintf(g_buf, MAXVARFMT, "%"LL_FMT"d", (long long)n); |
| 974 | } else { | 974 | } else { |
| 975 | const char *s = format; | 975 | const char *s = format; |
| 976 | char c; | 976 | char c; |
| @@ -2929,6 +2929,15 @@ static int try_to_assign(const char *expr) | |||
| 2929 | return TRUE; | 2929 | return TRUE; |
| 2930 | } | 2930 | } |
| 2931 | 2931 | ||
| 2932 | |||
| 2933 | #if ENABLE_PLATFORM_MINGW32 | ||
| 2934 | static void set_text_mode(FILE *f) | ||
| 2935 | { | ||
| 2936 | if (f) | ||
| 2937 | _setmode(fileno(f), _O_TEXT); | ||
| 2938 | } | ||
| 2939 | #endif | ||
| 2940 | |||
| 2932 | /* switch to next input file */ | 2941 | /* switch to next input file */ |
| 2933 | static int next_input_file(void) | 2942 | static int next_input_file(void) |
| 2934 | { | 2943 | { |
| @@ -2972,6 +2981,9 @@ static int next_input_file(void) | |||
| 2972 | break; | 2981 | break; |
| 2973 | } | 2982 | } |
| 2974 | } | 2983 | } |
| 2984 | #if ENABLE_PLATFORM_MINGW32 | ||
| 2985 | set_text_mode(iF.F); | ||
| 2986 | #endif | ||
| 2975 | 2987 | ||
| 2976 | setvar_s(intvar[FILENAME], fname); | 2988 | setvar_s(intvar[FILENAME], fname); |
| 2977 | input_file_seen = TRUE; | 2989 | input_file_seen = TRUE; |
| @@ -2980,6 +2992,17 @@ static int next_input_file(void) | |||
| 2980 | #undef input_file_seen | 2992 | #undef input_file_seen |
| 2981 | } | 2993 | } |
| 2982 | 2994 | ||
| 2995 | #if ENABLE_PLATFORM_MINGW32 | ||
| 2996 | static unsigned triple32(unsigned x) | ||
| 2997 | { | ||
| 2998 | x ^= x >> 17; x *= 0xed5ad4bb; | ||
| 2999 | x ^= x >> 11; x *= 0xac4c1b51; | ||
| 3000 | x ^= x >> 15; x *= 0x31848bab; | ||
| 3001 | x ^= x >> 14; | ||
| 3002 | return x; | ||
| 3003 | } | ||
| 3004 | #endif | ||
| 3005 | |||
| 2983 | /* | 3006 | /* |
| 2984 | * Evaluate node - the heart of the program. Supplied with subtree | 3007 | * Evaluate node - the heart of the program. Supplied with subtree |
| 2985 | * and "res" variable to assign the result to if we evaluate an expression. | 3008 | * and "res" variable to assign the result to if we evaluate an expression. |
| @@ -3361,6 +3384,9 @@ static var *evaluate(node *op, var *res) | |||
| 3361 | } else { | 3384 | } else { |
| 3362 | rsm->F = fopen_for_read(L.s); /* not xfopen! */ | 3385 | rsm->F = fopen_for_read(L.s); /* not xfopen! */ |
| 3363 | } | 3386 | } |
| 3387 | #if ENABLE_PLATFORM_MINGW32 | ||
| 3388 | set_text_mode(rsm->F); | ||
| 3389 | #endif | ||
| 3364 | } | 3390 | } |
| 3365 | } else { | 3391 | } else { |
| 3366 | if (!iF.F) | 3392 | if (!iF.F) |
| @@ -3412,6 +3438,12 @@ static var *evaluate(node *op, var *res) | |||
| 3412 | v &= 0x7fffffffffffffffULL; | 3438 | v &= 0x7fffffffffffffffULL; |
| 3413 | # endif | 3439 | # endif |
| 3414 | R_d = (double)v / 0x8000000000000000ULL; | 3440 | R_d = (double)v / 0x8000000000000000ULL; |
| 3441 | #elif ENABLE_PLATFORM_MINGW32 && RAND_MAX == 0x7fff | ||
| 3442 | /* 45 bits of randomness ought to be enough for anyone */ | ||
| 3443 | uint64_t v = ((uint64_t)rand() << 18) | | ||
| 3444 | ((uint64_t)rand() << 33) | | ||
| 3445 | ((uint64_t)rand() << 48); | ||
| 3446 | R_d = (double)v / 0x8000000000000000ULL; | ||
| 3415 | #else | 3447 | #else |
| 3416 | # error Not implemented for this value of RAND_MAX | 3448 | # error Not implemented for this value of RAND_MAX |
| 3417 | #endif | 3449 | #endif |
| @@ -3453,7 +3485,11 @@ static var *evaluate(node *op, var *res) | |||
| 3453 | case F_sr: | 3485 | case F_sr: |
| 3454 | R_d = (double)seed; | 3486 | R_d = (double)seed; |
| 3455 | seed = op1 ? (unsigned)L_d : (unsigned)time(NULL); | 3487 | seed = op1 ? (unsigned)L_d : (unsigned)time(NULL); |
| 3488 | #if ENABLE_PLATFORM_MINGW32 | ||
| 3489 | srand(seed == 1 ? 1 : triple32(seed)); | ||
| 3490 | #else | ||
| 3456 | srand(seed); | 3491 | srand(seed); |
| 3492 | #endif | ||
| 3457 | break; | 3493 | break; |
| 3458 | 3494 | ||
| 3459 | case F_ti: /*systime*/ | 3495 | case F_ti: /*systime*/ |
| @@ -3797,6 +3833,9 @@ int awk_main(int argc UNUSED_PARAM, char **argv) | |||
| 3797 | char *s; | 3833 | char *s; |
| 3798 | g_progname = optarg; | 3834 | g_progname = optarg; |
| 3799 | fd = xopen_stdin(g_progname); | 3835 | fd = xopen_stdin(g_progname); |
| 3836 | #if ENABLE_PLATFORM_MINGW32 | ||
| 3837 | _setmode(fd, _O_TEXT); | ||
| 3838 | #endif | ||
| 3800 | s = xmalloc_read(fd, NULL); /* it's NUL-terminated */ | 3839 | s = xmalloc_read(fd, NULL); /* it's NUL-terminated */ |
| 3801 | if (!s) | 3840 | if (!s) |
| 3802 | bb_perror_msg_and_die("read error from '%s'", g_progname); | 3841 | bb_perror_msg_and_die("read error from '%s'", g_progname); |
