aboutsummaryrefslogtreecommitdiffstats
path: root/field.c
diff options
context:
space:
mode:
authorArnold D. Robbins <arnold@skeeve.com>2017-05-23 05:43:32 +0300
committerArnold D. Robbins <arnold@skeeve.com>2017-05-23 05:43:32 +0300
commit1d9b00da83d88f353dd517bb8a763baf34d7c80f (patch)
tree90bc2a83e45f04e37ae33519098fc498279d9d77 /field.c
parent76dd301e43e1d3bc93652704293dc71879513ce9 (diff)
parentd3d50a55367f84182d21420121b504f898cda459 (diff)
downloadegawk-1d9b00da83d88f353dd517bb8a763baf34d7c80f.tar.gz
egawk-1d9b00da83d88f353dd517bb8a763baf34d7c80f.tar.bz2
egawk-1d9b00da83d88f353dd517bb8a763baf34d7c80f.zip
Merge branch 'master' into feature/api-mpfr
Diffstat (limited to 'field.c')
-rw-r--r--field.c32
1 files changed, 26 insertions, 6 deletions
diff --git a/field.c b/field.c
index 608be7da..de1bae5f 100644
--- a/field.c
+++ b/field.c
@@ -777,7 +777,7 @@ fw_parse_field(long up_to, /* parse only up to this field number */
* in practice.
*/
memset(&mbs, 0, sizeof(mbstate_t));
- while (nf < up_to) {
+ while (nf < up_to && scan < end) {
if (nf >= fw->nf) {
*buf = end;
return nf;
@@ -788,7 +788,7 @@ fw_parse_field(long up_to, /* parse only up to this field number */
scan += flen;
}
} else {
- while (nf < up_to) {
+ while (nf < up_to && scan < end) {
if (nf >= fw->nf) {
*buf = end;
return nf;
@@ -1171,18 +1171,38 @@ set_FIELDWIDTHS()
if (*scan == '\0')
break;
- /* Detect an invalid base-10 integer, a valid value that
- is followed by something other than a blank or '\0',
- or a value that is not in the range [1..INT_MAX]. */
+ // Look for skip value. We allow N:M and N:*.
+ /*
+ * Detect an invalid base-10 integer, a valid value that
+ * is followed by something other than a blank or '\0',
+ * or a value that is not in the range [1..INT_MAX].
+ */
errno = 0;
tmp = strtoul(scan, &end, 10);
- if (errno == 0 && *end == ':' && (0 < tmp && tmp <= INT_MAX)) {
+ if (errno == 0 && *end == ':' && (0 < tmp && tmp <= UINT_MAX)) {
FIELDWIDTHS->fields[i].skip = tmp;
scan = end + 1;
+ if (*scan == '*')
+ goto got_star;
+ // try scanning for field width
tmp = strtoul(scan, &end, 10);
}
else
FIELDWIDTHS->fields[i].skip = 0;
+
+ if (*scan == '*') {
+ got_star:
+ for (scan++; is_blank(*scan); scan++)
+ continue;
+
+ if (*scan != '\0')
+ fatal(_("`*' must be the last designator in FIELDWIDTHS"));
+
+ FIELDWIDTHS->fields[i].len = UINT_MAX;
+ FIELDWIDTHS->nf = i+1;
+ break;
+ }
+
if (errno != 0
|| (*end != '\0' && ! is_blank(*end))
|| !(0 < tmp && tmp <= INT_MAX)