128
/* die silently on EPIPE to stdout */
129
if (fp == stdout && errno == EPIPE)
130
gawk_exit(EXIT_FATAL);
132
/* otherwise die verbosely */
128
133
fatal(_("%s to \"%s\" failed (%s)"), from,
129
134
rp ? rp->value : _("standard output"),
130
135
errno ? strerror(errno) : _("reason unknown"));
1109
1115
memset(& state, 0, sizeof(state));
1110
1116
count = mbrlen(cp, arg->stlen, & state);
1112
|| count == (size_t)-1
1113
|| count == (size_t)-2)
1119
/* may need to increase fw so that padding happens, see pr_tail code */
1124
1127
need_format = false;
1421
1424
copy_count = prec;
1422
1425
if (fw == 0 && ! have_prec)
1424
else if (gawk_mb_cur_max > 1 && (cs1 == 's' || cs1 == 'c')) {
1425
assert(cp == arg->stptr || cp == cpbuf);
1426
copy_count = mbc_byte_count(arg->stptr, prec);
1427
else if (gawk_mb_cur_max > 1) {
1429
assert(cp == arg->stptr || cp == cpbuf);
1430
copy_count = mbc_byte_count(arg->stptr, prec);
1432
/* prec was set by code for %c */
1434
copy_count = prec; */
1428
1436
bchunk(cp, copy_count);
1429
1437
while (fw > prec) {
2157
2165
f0 = fields_arr[0];
2159
if (do_lint && f0 == Nnull_string)
2167
if (do_lint && (f0->flags & NULL_FIELD) != 0)
2160
2168
lintwarn(_("reference to uninitialized field `$%d'"), 0);
2162
2170
efwrite(f0->stptr, sizeof(char), f0->stlen, fp, "print", rp, false);
2370
2378
do_rand(int nargs ATTRIBUTE_UNUSED)
2381
#define RAND_DIVISOR ((double)GAWK_RANDOM_MAX+1.0)
2372
2382
if (firstrand) {
2373
2383
(void) initstate((unsigned) 1, state, SIZEOF_STATE);
2374
2384
/* don't need to srandom(1), initstate() does it for us. */
2383
return make_number((AWKNUM) (random() % GAWK_RANDOM_MAX) / GAWK_RANDOM_MAX);
2394
* Date: Wed, 28 Aug 2013 17:52:46 -0700
2395
* From: Bob Jewett <jewett@bill.scs.agilent.com>
2397
* Call random() twice to fill in more bits in the value
2398
* of the double. Also, there is a bug in random() such
2399
* that when the values of successive values are combined
2400
* like (rand1*rand2)^2, (rand3*rand4)^2, ... the
2401
* resulting time series is not white noise. The
2402
* following also seems to fix that bug.
2404
* The add/subtract 0.5 keeps small bits from filling
2405
* below 2^-53 in the double, not that anyone should be
2406
* looking down there.
2408
* Date: Wed, 25 Sep 2013 10:45:38 -0600 (MDT)
2409
* From: "Nelson H. F. Beebe" <beebe@math.utah.edu>
2410
* (4) The code is typical of many published fragments for converting
2411
* from integer to floating-point, and I discuss the serious pitfalls
2412
* in my book, because it leads to platform-dependent behavior at the
2413
* end points of the interval [0,1]
2415
* (5) the documentation in the gawk info node says
2418
* Return a random number. The values of `rand()' are uniformly
2419
* distributed between zero and one. The value could be zero but is
2422
* The division by RAND_DIVISOR may not guarantee that 1.0 is never
2423
* returned: the programmer forgot the platform-dependent issue of
2426
* For points 4 and 5, the safe way is a loop:
2429
* rand(void) // return value in [0.0, 1.0)
2431
* value = internal_rand();
2433
* while (value == 1.0)
2434
* value = internal_rand();
2441
tmprand = 0.5 + ( (random()/RAND_DIVISOR + random())
2444
} while (tmprand == 1.0);
2446
return make_number((AWKNUM) tmprand);
2386
2449
/* do_srand --- seed the random number generator */
2955
if ((matches == 0 || (flags & LITERAL) != 0) && buf != NULL)
3018
if ((matches == 0 || (flags & LITERAL) != 0) && buf != NULL) {
2958
3023
if (flags & GENSUB) {
2959
3024
if (matches > 0) {
2960
3025
/* return the result string */
3027
assert(buf != NULL);
2962
3028
return make_str_node(buf, textlen, ALREADY_MALLOCED);