aboutsummaryrefslogtreecommitdiffstats
path: root/io.c
diff options
context:
space:
mode:
Diffstat (limited to 'io.c')
-rw-r--r--io.c56
1 files changed, 46 insertions, 10 deletions
diff --git a/io.c b/io.c
index 920d21f7..721b1ab7 100644
--- a/io.c
+++ b/io.c
@@ -132,6 +132,14 @@
#define PIPES_SIMULATED
#endif
+#ifdef HAVE_MPFR
+/* increment NR or FNR */
+#define INCREMENT_REC(X) (do_mpfr && X == (LONG_MAX - 1)) ? \
+ (mpz_add_ui(M##X, M##X, 1), X = 0) : X++
+#else
+#define INCREMENT_REC(X) X++
+#endif
+
typedef enum { CLOSE_ALL, CLOSE_TO, CLOSE_FROM } two_way_close_type;
/* Several macros make the code a bit clearer: */
@@ -233,6 +241,7 @@ extern NODE *ARGIND_node;
extern NODE *ERRNO_node;
extern NODE **fields_arr;
+/* init_io --- set up timeout related variables */
void
init_io()
@@ -340,6 +349,7 @@ nextfile(IOBUF **curfile, int skipping)
int fd = INVALID_HANDLE;
int errcode;
IOBUF *iop = *curfile;
+ long argc;
if (skipping) { /* for 'nextfile' call */
errcode = 0;
@@ -361,7 +371,9 @@ nextfile(IOBUF **curfile, int skipping)
return 0;
}
- for (; i < (long) (ARGC_node->lnode->numbr); i++) {
+ argc = get_number_si(ARGC_node->var_value);
+
+ for (; i < argc; i++) {
tmp = make_number((AWKNUM) i);
(void) force_string(tmp);
arg = in_array(ARGV_node, tmp);
@@ -387,6 +399,10 @@ nextfile(IOBUF **curfile, int skipping)
/* This is a kludge. */
unref(FILENAME_node->var_value);
FILENAME_node->var_value = dupnode(arg);
+#ifdef HAVE_MPFR
+ if (is_mpg_number(FNR_node->var_value))
+ mpz_set_ui(MFNR, 0);
+#endif
FNR = 0;
iop = *curfile = iop_alloc(fd, fname, &mybuf, FALSE);
if (fd == INVALID_HANDLE)
@@ -432,7 +448,14 @@ nextfile(IOBUF **curfile, int skipping)
void
set_FNR()
{
- FNR = (long) FNR_node->var_value->numbr;
+ NODE *n = FNR_node->var_value;
+ (void) force_number(n);
+#ifdef HAVE_MPFR
+ if (is_mpg_number(n))
+ FNR = mpg_set_var(FNR_node);
+ else
+#endif
+ FNR = get_number_si(n);
}
/* set_NR --- update internal NR from awk variable */
@@ -440,7 +463,14 @@ set_FNR()
void
set_NR()
{
- NR = (long) NR_node->var_value->numbr;
+ NODE *n = NR_node->var_value;
+ (void) force_number(n);
+#ifdef HAVE_MPFR
+ if (is_mpg_number(n))
+ NR = mpg_set_var(NR_node);
+ else
+#endif
+ NR = get_number_si(n);
}
/* inrec --- This reads in a record from the input file */
@@ -464,8 +494,8 @@ inrec(IOBUF *iop, int *errcode)
if (*errcode > 0)
update_ERRNO_saved(*errcode);
} else {
- NR += 1;
- FNR += 1;
+ INCREMENT_REC(NR);
+ INCREMENT_REC(FNR);
set_record(begin, cnt);
}
@@ -2296,8 +2326,8 @@ do_getline(int intovar, IOBUF *iop)
if (cnt == EOF)
return NULL; /* try next file */
- NR++;
- FNR++;
+ INCREMENT_REC(NR);
+ INCREMENT_REC(FNR);
if (! intovar) /* no optional var. */
set_record(s, cnt);
@@ -3250,7 +3280,7 @@ pty_vs_pipe(const char *command)
if (val->flags & MAYBE_NUM)
(void) force_number(val);
if (val->flags & NUMBER)
- return (val->numbr != 0.0);
+ return ! iszero(val);
else
return (val->stlen != 0);
}
@@ -3383,8 +3413,10 @@ get_read_timeout(IOBUF *iop)
} else /* use cached full index */
val = in_array(PROCINFO_node, full_idx);
- if (val != NULL)
- tmout = (long) force_number(val);
+ if (val != NULL) {
+ (void) force_number(val);
+ tmout = get_number_si(val);
+ }
} else
tmout = read_default_timeout; /* initialized from env. variable in init_io() */
@@ -3400,6 +3432,7 @@ get_read_timeout(IOBUF *iop)
static ssize_t
read_with_timeout(int fd, char *buf, size_t size)
{
+#ifndef __MINGW32__
fd_set readfds;
struct timeval tv;
@@ -3425,6 +3458,9 @@ read_with_timeout(int fd, char *buf, size_t size)
errno = EAGAIN;
#endif
return -1;
+#else /* __MINGW32__ */
+ return read(fd, buf, size);
+#endif /* __MINGW32__ */
}