From 62fe07b69e522c909aad303b31443cc3c9bdf6c0 Mon Sep 17 00:00:00 2001 From: "Andrew J. Schorr" Date: Sun, 5 Mar 2017 17:05:36 -0500 Subject: Enable an API input parser to supply an array of field widths to override the default gawk field parsing mechanism. --- io.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'io.c') diff --git a/io.c b/io.c index cced126e..040b485c 100644 --- a/io.c +++ b/io.c @@ -604,7 +604,7 @@ inrec(IOBUF *iop, int *errcode) } else { INCREMENT_REC(NR); INCREMENT_REC(FNR); - set_record(begin, cnt); + set_record(begin, cnt, iop->public.field_width); if (*errcode > 0) retval = false; } @@ -2668,7 +2668,7 @@ do_getline_redir(int into_variable, enum redirval redirtype) } if (lhs == NULL) /* no optional var. */ - set_record(s, cnt); + set_record(s, cnt, iop->public.field_width); else { /* assignment to variable */ unref(*lhs); *lhs = make_string(s, cnt); @@ -2709,7 +2709,7 @@ do_getline(int into_variable, IOBUF *iop) INCREMENT_REC(FNR); if (! into_variable) /* no optional var. */ - set_record(s, cnt); + set_record(s, cnt, iop->public.field_width); else { /* assignment to variable */ NODE **lhs; lhs = POP_ADDRESS(); -- cgit v1.2.3 From d6406b66add5652130385942a7e05ebc9ea799ce Mon Sep 17 00:00:00 2001 From: "Andrew J. Schorr" Date: Mon, 6 Mar 2017 09:20:33 -0500 Subject: Add a 6th argument to the API get_record function instead of having a separate field_width array pointer in the input buf. --- io.c | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) (limited to 'io.c') diff --git a/io.c b/io.c index 040b485c..8aa9da82 100644 --- a/io.c +++ b/io.c @@ -287,7 +287,7 @@ static RECVALUE rsrescan(IOBUF *iop, struct recmatch *recm, SCANSTATE *state); static RECVALUE (*matchrec)(IOBUF *iop, struct recmatch *recm, SCANSTATE *state) = rs1scan; -static int get_a_record(char **out, IOBUF *iop, int *errcode); +static int get_a_record(char **out, IOBUF *iop, int *errcode, const int **field_width); static void free_rp(struct redirect *rp); @@ -590,13 +590,14 @@ inrec(IOBUF *iop, int *errcode) char *begin; int cnt; bool retval = true; + const int *field_width = NULL; if (at_eof(iop) && no_data_left(iop)) cnt = EOF; else if ((iop->flag & IOP_CLOSED) != 0) cnt = EOF; else - cnt = get_a_record(& begin, iop, errcode); + cnt = get_a_record(& begin, iop, errcode, & field_width); /* Note that get_a_record may return -2 when I/O would block */ if (cnt < 0) { @@ -604,7 +605,7 @@ inrec(IOBUF *iop, int *errcode) } else { INCREMENT_REC(NR); INCREMENT_REC(FNR); - set_record(begin, cnt, iop->public.field_width); + set_record(begin, cnt, field_width); if (*errcode > 0) retval = false; } @@ -2618,6 +2619,7 @@ do_getline_redir(int into_variable, enum redirval redirtype) NODE *redir_exp = NULL; NODE **lhs = NULL; int redir_error = 0; + const int *field_width = NULL; if (into_variable) lhs = POP_ADDRESS(); @@ -2646,7 +2648,7 @@ do_getline_redir(int into_variable, enum redirval redirtype) return make_number((AWKNUM) 0.0); errcode = 0; - cnt = get_a_record(& s, iop, & errcode); + cnt = get_a_record(& s, iop, & errcode, (lhs ? NULL : & field_width)); if (errcode != 0) { if (! do_traditional && (errcode != -1)) update_ERRNO_int(errcode); @@ -2668,7 +2670,7 @@ do_getline_redir(int into_variable, enum redirval redirtype) } if (lhs == NULL) /* no optional var. */ - set_record(s, cnt, iop->public.field_width); + set_record(s, cnt, field_width); else { /* assignment to variable */ unref(*lhs); *lhs = make_string(s, cnt); @@ -2686,6 +2688,7 @@ do_getline(int into_variable, IOBUF *iop) int cnt = EOF; char *s = NULL; int errcode; + const int *field_width = NULL; if (iop == NULL) { /* end of input */ if (into_variable) @@ -2694,7 +2697,7 @@ do_getline(int into_variable, IOBUF *iop) } errcode = 0; - cnt = get_a_record(& s, iop, & errcode); + cnt = get_a_record(& s, iop, & errcode, (into_variable ? NULL : & field_width)); if (errcode != 0) { if (! do_traditional && (errcode != -1)) update_ERRNO_int(errcode); @@ -2709,7 +2712,7 @@ do_getline(int into_variable, IOBUF *iop) INCREMENT_REC(FNR); if (! into_variable) /* no optional var. */ - set_record(s, cnt, iop->public.field_width); + set_record(s, cnt, field_width); else { /* assignment to variable */ NODE **lhs; lhs = POP_ADDRESS(); @@ -3653,7 +3656,8 @@ errno_io_retry(void) static int get_a_record(char **out, /* pointer to pointer to data */ IOBUF *iop, /* input IOP */ - int *errcode) /* pointer to error variable */ + int *errcode, /* pointer to error variable */ + const int **field_width)/* pointer to pointer to field_width array */ { struct recmatch recm; SCANSTATE state; @@ -3672,7 +3676,8 @@ get_a_record(char **out, /* pointer to pointer to data */ char *rt_start; size_t rt_len; int rc = iop->public.get_record(out, &iop->public, errcode, - &rt_start, &rt_len); + &rt_start, &rt_len, + field_width); if (rc == EOF) iop->flag |= IOP_AT_EOF; else { -- cgit v1.2.3 From 39c46265139aa8faf87160b30710876bde4c6ba9 Mon Sep 17 00:00:00 2001 From: "Andrew J. Schorr" Date: Thu, 9 Mar 2017 20:44:09 -0500 Subject: For API input field parsing, use an array of structs instead of an array of integers. --- io.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'io.c') diff --git a/io.c b/io.c index 8aa9da82..b049851f 100644 --- a/io.c +++ b/io.c @@ -287,7 +287,7 @@ static RECVALUE rsrescan(IOBUF *iop, struct recmatch *recm, SCANSTATE *state); static RECVALUE (*matchrec)(IOBUF *iop, struct recmatch *recm, SCANSTATE *state) = rs1scan; -static int get_a_record(char **out, IOBUF *iop, int *errcode, const int **field_width); +static int get_a_record(char **out, IOBUF *iop, int *errcode, const awk_input_field_info_t **field_width); static void free_rp(struct redirect *rp); @@ -590,7 +590,7 @@ inrec(IOBUF *iop, int *errcode) char *begin; int cnt; bool retval = true; - const int *field_width = NULL; + const awk_input_field_info_t *field_width = NULL; if (at_eof(iop) && no_data_left(iop)) cnt = EOF; @@ -2619,7 +2619,7 @@ do_getline_redir(int into_variable, enum redirval redirtype) NODE *redir_exp = NULL; NODE **lhs = NULL; int redir_error = 0; - const int *field_width = NULL; + const awk_input_field_info_t *field_width = NULL; if (into_variable) lhs = POP_ADDRESS(); @@ -2688,7 +2688,7 @@ do_getline(int into_variable, IOBUF *iop) int cnt = EOF; char *s = NULL; int errcode; - const int *field_width = NULL; + const awk_input_field_info_t *field_width = NULL; if (iop == NULL) { /* end of input */ if (into_variable) @@ -3657,7 +3657,8 @@ static int get_a_record(char **out, /* pointer to pointer to data */ IOBUF *iop, /* input IOP */ int *errcode, /* pointer to error variable */ - const int **field_width)/* pointer to pointer to field_width array */ + const awk_input_field_info_t **field_width) + /* pointer to pointer to field_width array */ { struct recmatch recm; SCANSTATE state; -- cgit v1.2.3 From d1bebd3cbf60fa25883271512cf63e0c3275e3ef Mon Sep 17 00:00:00 2001 From: "Andrew J. Schorr" Date: Tue, 21 Mar 2017 13:22:18 -0400 Subject: Enhance FIELDWIDTHS syntax to support a skip prefix, and unify logic with API field parsing. --- io.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'io.c') diff --git a/io.c b/io.c index d1033fcd..25b6bc93 100644 --- a/io.c +++ b/io.c @@ -287,7 +287,7 @@ static RECVALUE rsrescan(IOBUF *iop, struct recmatch *recm, SCANSTATE *state); static RECVALUE (*matchrec)(IOBUF *iop, struct recmatch *recm, SCANSTATE *state) = rs1scan; -static int get_a_record(char **out, IOBUF *iop, int *errcode, const awk_input_field_info_t **field_width); +static int get_a_record(char **out, IOBUF *iop, int *errcode, const awk_fieldwidth_info_t **field_width); static void free_rp(struct redirect *rp); @@ -590,7 +590,7 @@ inrec(IOBUF *iop, int *errcode) char *begin; int cnt; bool retval = true; - const awk_input_field_info_t *field_width = NULL; + const awk_fieldwidth_info_t *field_width = NULL; if (at_eof(iop) && no_data_left(iop)) cnt = EOF; @@ -2638,7 +2638,7 @@ do_getline_redir(int into_variable, enum redirval redirtype) NODE *redir_exp = NULL; NODE **lhs = NULL; int redir_error = 0; - const awk_input_field_info_t *field_width = NULL; + const awk_fieldwidth_info_t *field_width = NULL; if (into_variable) lhs = POP_ADDRESS(); @@ -2707,7 +2707,7 @@ do_getline(int into_variable, IOBUF *iop) int cnt = EOF; char *s = NULL; int errcode; - const awk_input_field_info_t *field_width = NULL; + const awk_fieldwidth_info_t *field_width = NULL; if (iop == NULL) { /* end of input */ if (into_variable) @@ -3676,8 +3676,8 @@ static int get_a_record(char **out, /* pointer to pointer to data */ IOBUF *iop, /* input IOP */ int *errcode, /* pointer to error variable */ - const awk_input_field_info_t **field_width) - /* pointer to pointer to field_width array */ + const awk_fieldwidth_info_t **field_width) + /* pointer to pointer to field_width info */ { struct recmatch recm; SCANSTATE state; -- cgit v1.2.3