summaryrefslogtreecommitdiff
path: root/field.c
diff options
context:
space:
mode:
Diffstat (limited to 'field.c')
-rw-r--r--field.c432
1 files changed, 207 insertions, 225 deletions
diff --git a/field.c b/field.c
index 46c9c93d..a0074d8a 100644
--- a/field.c
+++ b/field.c
@@ -36,28 +36,28 @@ is_blank(int c)
return c == ' ' || c == '\t';
}
-typedef void (* Setfunc) P((long, char *, long, NODE *));
-
-static long (*parse_field) P((long, char **, int, NODE *,
- Regexp *, Setfunc, NODE *, NODE *, int));
-static void rebuild_record P((void));
-static long re_parse_field P((long, char **, int, NODE *,
- Regexp *, Setfunc, NODE *, NODE *, int));
-static long def_parse_field P((long, char **, int, NODE *,
- Regexp *, Setfunc, NODE *, NODE *, int));
-static long posix_def_parse_field P((long, char **, int, NODE *,
- Regexp *, Setfunc, NODE *, NODE *, int));
-static long null_parse_field P((long, char **, int, NODE *,
- Regexp *, Setfunc, NODE *, NODE *, int));
-static long sc_parse_field P((long, char **, int, NODE *,
- Regexp *, Setfunc, NODE *, NODE *, int));
-static long fw_parse_field P((long, char **, int, NODE *,
- Regexp *, Setfunc, NODE *, NODE *, int));
-static long fpat_parse_field P((long, char **, int, NODE *,
- Regexp *, Setfunc, NODE *, NODE *, int));
-static void set_element P((long num, char * str, long len, NODE *arr));
-static void grow_fields_arr P((long num));
-static void set_field P((long num, char *str, long len, NODE *dummy));
+typedef void (* Setfunc)(long, char *, long, NODE *);
+
+static long (*parse_field)(long, char **, int, NODE *,
+ Regexp *, Setfunc, NODE *, NODE *, int);
+static void rebuild_record(void);
+static long re_parse_field(long, char **, int, NODE *,
+ Regexp *, Setfunc, NODE *, NODE *, int);
+static long def_parse_field(long, char **, int, NODE *,
+ Regexp *, Setfunc, NODE *, NODE *, int);
+static long posix_def_parse_field(long, char **, int, NODE *,
+ Regexp *, Setfunc, NODE *, NODE *, int);
+static long null_parse_field(long, char **, int, NODE *,
+ Regexp *, Setfunc, NODE *, NODE *, int);
+static long sc_parse_field(long, char **, int, NODE *,
+ Regexp *, Setfunc, NODE *, NODE *, int);
+static long fw_parse_field(long, char **, int, NODE *,
+ Regexp *, Setfunc, NODE *, NODE *, int);
+static long fpat_parse_field(long, char **, int, NODE *,
+ Regexp *, Setfunc, NODE *, NODE *, int);
+static void set_element(long num, char * str, long len, NODE *arr);
+static void grow_fields_arr(long num);
+static void set_field(long num, char *str, long len, NODE *dummy);
static char *parse_extent; /* marks where to restart parse of record */
static long parse_high_water = 0; /* field number that we have parsed so far */
@@ -91,7 +91,7 @@ init_fields()
getnode(Null_field);
*Null_field = *Nnull_string;
Null_field->flags |= FIELD;
- Null_field->flags &= ~(NUMCUR|NUMBER|MAYBE_NUM|PERM);
+ Null_field->flags &= ~(NUMCUR|NUMBER|MAYBE_NUM|PERM|MALLOC);
field0_valid = TRUE;
}
@@ -100,8 +100,8 @@ init_fields()
static void
grow_fields_arr(long num)
{
- register int t;
- register NODE *n;
+ int t;
+ NODE *n;
erealloc(fields_arr, NODE **, (num + 1) * sizeof(NODE *), "grow_fields_arr");
for (t = nf_high_water + 1; t <= num; t++) {
@@ -121,7 +121,7 @@ set_field(long num,
long len,
NODE *dummy ATTRIBUTE_UNUSED) /* just to make interface same as set_element */
{
- register NODE *n;
+ NODE *n;
if (num > nf_high_water)
grow_fields_arr(num);
@@ -141,12 +141,12 @@ rebuild_record()
* use explicit unsigned longs for lengths, in case
* a size_t isn't big enough.
*/
- register unsigned long tlen;
- register unsigned long ofslen;
- register NODE *tmp;
+ unsigned long tlen;
+ unsigned long ofslen;
+ NODE *tmp;
NODE *ofs;
char *ops;
- register char *cops;
+ char *cops;
long i;
assert(NF != -1);
@@ -207,7 +207,7 @@ rebuild_record()
}
} else {
*n = *(fields_arr[i]);
- n->flags &= ~(MALLOC|TEMP|PERM|STRING);
+ n->flags &= ~(MALLOC|PERM|STRING);
}
n->stptr = cops;
@@ -271,7 +271,7 @@ set_record(const char *buf, int cnt)
getnode(n);
n->stptr = databuf;
n->stlen = cnt;
- n->stref = 1;
+ n->valref = 1;
n->type = Node_val;
n->stfmt = -1;
n->flags = (STRING|STRCUR|MAYBE_NUM|FIELD);
@@ -286,7 +286,7 @@ set_record(const char *buf, int cnt)
void
reset_record()
{
- register int i;
+ int i;
NODE *n;
(void) force_string(fields_arr[0]);
@@ -317,15 +317,16 @@ reset_record()
void
set_NF()
{
- register int i;
+ int i;
+ long nf;
NODE *n;
assert(NF != -1);
- NF = (long) force_number(NF_node->var_value);
-
- if (NF < 0)
+ nf = (long) force_number(NF_node->var_value);
+ if (nf < 0)
fatal(_("NF set to negative value"));
+ NF = nf;
if (NF > nf_high_water)
grow_fields_arr(NF);
@@ -366,10 +367,10 @@ re_parse_field(long up_to, /* parse only up to this field number */
NODE *sep_arr, /* array of field separators (maybe NULL) */
int in_middle)
{
- register char *scan = *buf;
- register long nf = parse_high_water;
- register char *field;
- register char *end = scan + len;
+ char *scan = *buf;
+ long nf = parse_high_water;
+ char *field;
+ char *end = scan + len;
int regex_flags = RE_NEED_START;
char *sep;
#ifdef MBS_SUPPORT
@@ -405,7 +406,7 @@ re_parse_field(long up_to, /* parse only up to this field number */
regex_flags |= RE_NO_BOL;
if (REEND(rp, scan) == RESTART(rp, scan)) { /* null match */
#ifdef MBS_SUPPORT
- if (gawk_mb_cur_max > 1) {
+ if (gawk_mb_cur_max > 1) {
mbclen = mbrlen(scan, end-scan, &mbs);
if ((mbclen == 1) || (mbclen == (size_t) -1)
|| (mbclen == (size_t) -2) || (mbclen == 0)) {
@@ -460,10 +461,10 @@ def_parse_field(long up_to, /* parse only up to this field number */
NODE *sep_arr, /* array of field separators (maybe NULL) */
int in_middle ATTRIBUTE_UNUSED)
{
- register char *scan = *buf;
- register long nf = parse_high_water;
- register char *field;
- register char *end = scan + len;
+ char *scan = *buf;
+ long nf = parse_high_water;
+ char *field;
+ char *end = scan + len;
char sav;
char *sep;
@@ -488,30 +489,29 @@ def_parse_field(long up_to, /* parse only up to this field number */
*end = ' '; /* sentinel character */
sep = scan;
-
for (; nf < up_to; scan++) {
/*
* special case: fs is single space, strip leading whitespace
*/
while (scan < end && (*scan == ' ' || *scan == '\t' || *scan == '\n'))
scan++;
-
+
if (sep_arr != NULL && scan > sep)
set_element(nf, sep, (long) (scan - sep), sep_arr);
-
+
if (scan >= end)
break;
-
+
field = scan;
-
+
while (*scan != ' ' && *scan != '\t' && *scan != '\n')
scan++;
-
+
(*set)(++nf, field, (long)(scan - field), n);
-
+
if (scan == end)
break;
-
+
sep = scan;
}
@@ -542,10 +542,10 @@ posix_def_parse_field(long up_to, /* parse only up to this field number */
NODE *dummy ATTRIBUTE_UNUSED, /* sep_arr not needed here: hence dummy */
int in_middle ATTRIBUTE_UNUSED)
{
- register char *scan = *buf;
- register long nf = parse_high_water;
- register char *field;
- register char *end = scan + len;
+ char *scan = *buf;
+ long nf = parse_high_water;
+ char *field;
+ char *end = scan + len;
char sav;
if (up_to == UNLIMITED)
@@ -608,9 +608,9 @@ null_parse_field(long up_to, /* parse only up to this field number */
NODE *sep_arr, /* array of field separators (maybe NULL) */
int in_middle ATTRIBUTE_UNUSED)
{
- register char *scan = *buf;
- register long nf = parse_high_water;
- register char *end = scan + len;
+ char *scan = *buf;
+ long nf = parse_high_water;
+ char *end = scan + len;
if (up_to == UNLIMITED)
nf = 0;
@@ -629,7 +629,7 @@ null_parse_field(long up_to, /* parse only up to this field number */
mbclen = 1;
}
if (sep_arr != NULL && nf > 0)
- set_element(nf, scan, 0L, sep_arr);
+ set_element(nf, scan, 0L, sep_arr);
(*set)(++nf, scan, mbclen, n);
scan += mbclen;
}
@@ -663,11 +663,11 @@ sc_parse_field(long up_to, /* parse only up to this field number */
NODE *sep_arr, /* array of field separators (maybe NULL) */
int in_middle ATTRIBUTE_UNUSED)
{
- register char *scan = *buf;
- register char fschar;
- register long nf = parse_high_water;
- register char *field;
- register char *end = scan + len;
+ char *scan = *buf;
+ char fschar;
+ long nf = parse_high_water;
+ char *field;
+ char *end = scan + len;
char sav;
#ifdef MBS_SUPPORT
size_t mbclen = 0;
@@ -744,9 +744,9 @@ fw_parse_field(long up_to, /* parse only up to this field number */
NODE *dummy ATTRIBUTE_UNUSED, /* sep_arr not needed here: hence dummy */
int in_middle ATTRIBUTE_UNUSED)
{
- register char *scan = *buf;
- register long nf = parse_high_water;
- register char *end = scan + len;
+ char *scan = *buf;
+ long nf = parse_high_water;
+ char *end = scan + len;
#ifdef MBS_SUPPORT
int nmbc;
size_t mbclen;
@@ -803,12 +803,20 @@ fw_parse_field(long up_to, /* parse only up to this field number */
return nf;
}
+/* invalidate_field0 --- $0 needs reconstruction */
+
+void
+invalidate_field0()
+{
+ field0_valid = FALSE;
+}
+
/* get_field --- return a particular $n */
/* assign is not NULL if this field is on the LHS of an assign */
NODE **
-get_field(register long requested, Func_ptr *assign)
+get_field(long requested, Func_ptr *assign)
{
int in_middle = FALSE;
/*
@@ -819,7 +827,7 @@ get_field(register long requested, Func_ptr *assign)
if (! field0_valid) {
/* first, parse remainder of input record */
if (NF == -1) {
- NF = (*parse_field)(UNLIMITED-1, &parse_extent,
+ NF = (*parse_field)(UNLIMITED - 1, &parse_extent,
fields_arr[0]->stlen -
(parse_extent - fields_arr[0]->stptr),
save_FS, FS_regexp, set_field,
@@ -837,8 +845,20 @@ get_field(register long requested, Func_ptr *assign)
/* assert(requested > 0); */
+#if 0
if (assign != NULL)
field0_valid = FALSE; /* $0 needs reconstruction */
+#else
+ /* keep things uniform. Also, mere intention of assigning something
+ * to $n should not make $0 invalid. Makes sense to invalidate $0
+ * after the actual assignment is performed. Not a real issue in
+ * the interpreter otherwise, but causes problem in the
+ * debugger when watching or printing fields.
+ */
+
+ if (assign != NULL)
+ *assign = invalidate_field0; /* $0 needs reconstruction */
+#endif
if (requested <= parse_high_water) /* already parsed this field */
return &fields_arr[requested];
@@ -866,7 +886,7 @@ get_field(register long requested, Func_ptr *assign)
*/
if (parse_extent == fields_arr[0]->stptr + fields_arr[0]->stlen)
NF = parse_high_water;
- if (requested == UNLIMITED-1) /* UNLIMITED-1 means set NF */
+ if (requested == UNLIMITED - 1) /* UNLIMITED-1 means set NF */
requested = parse_high_water;
}
if (parse_high_water < requested) { /* requested beyond end of record */
@@ -888,83 +908,75 @@ get_field(register long requested, Func_ptr *assign)
static void
set_element(long num, char *s, long len, NODE *n)
{
- register NODE *it;
+ NODE *it;
+ NODE **lhs;
+ NODE *sub;
it = make_string(s, len);
it->flags |= MAYBE_NUM;
- *assoc_lookup(n, tmp_number((AWKNUM) (num)), FALSE) = it;
+ sub = make_number((AWKNUM) (num));
+ lhs = assoc_lookup(n, sub, FALSE);
+ unref(sub);
+ unref(*lhs);
+ *lhs = it;
}
/* do_split --- implement split(), semantics are same as for field splitting */
NODE *
-do_split(NODE *tree)
+do_split(int nargs)
{
- NODE *src, *arr, *sep, *fs, *sep_arr, *src2, *fs2, *tmp;
+ NODE *src, *arr, *sep, *fs, *tmp, *sep_arr = NULL;
char *s;
- long (*parseit) P((long, char **, int, NODE *,
- Regexp *, Setfunc, NODE *, NODE *, int));
+ long (*parseit)(long, char **, int, NODE *,
+ Regexp *, Setfunc, NODE *, NODE *, int);
Regexp *rp = NULL;
- src = force_string(tree_eval(tree->lnode));
-
- arr = get_param(tree->rnode->lnode);
- if (arr->type != Node_var_array)
- fatal(_("split: second argument is not an array"));
-
- sep = tree->rnode->rnode->lnode;
-
- sep_arr = tree->rnode->rnode->rnode;
- if (sep_arr != NULL) {
+ if (nargs == 4) {
static short warned1 = FALSE, warned2 = FALSE;
if (do_traditional || do_posix) {
fatal(_("split: fourth argument is a gawk extension"));
}
-
- sep_arr = get_param(tree->rnode->rnode->rnode->lnode);
-
+ sep_arr = POP_PARAM();
if (sep_arr->type != Node_var_array)
fatal(_("split: fourth argument is not an array"));
-
if (do_lint && ! warned1) {
warned1 = TRUE;
lintwarn(_("split: fourth argument is a gawk extension"));
}
-
if (do_lint_old && ! warned2) {
- warned2 = TRUE;
+ warned2 = TRUE;
warning(_("split: fourth argument is a gawk extension"));
- }
+ }
}
+ sep = POP();
+ arr = POP_PARAM();
+ if (arr->type != Node_var_array)
+ fatal(_("split: second argument is not an array"));
+
+ assoc_clear(arr);
+ if (sep_arr != NULL)
+ assoc_clear(sep_arr);
+
+ src = TOP_STRING();
if (src->stlen == 0) {
/*
* Skip the work if first arg is the null string.
*/
- free_temp(src);
- /*
- * Evaluate sep if it may have side effects.
- */
- if ((sep->re_flags & (FS_DFLT|CONSTANT)) == 0)
- free_temp(tree_eval(sep->re_exp));
- /*
- * And now we can safely turn off the arrays.
- */
- assoc_clear(arr);
-
- if (sep_arr != NULL)
- assoc_clear(sep_arr);
-
- return tmp_number((AWKNUM) 0);
+ decr_sp();
+ DEREF(src);
+ return make_number((AWKNUM) 0);
}
if ((sep->re_flags & FS_DFLT) != 0 && current_field_sep() != Using_FIELDWIDTHS && ! RS_is_null) {
parseit = parse_field;
- fs = force_string(FS_node->var_value);
+ fs = dupnode(force_string(FS_node->var_value));
rp = FS_regexp;
} else {
- fs = force_string(tree_eval(sep->re_exp));
+ fs = dupnode(sep->re_exp);
+
if (fs->stlen == 0) {
static short warned = FALSE;
@@ -972,7 +984,7 @@ do_split(NODE *tree)
if (do_lint && ! warned) {
warned = TRUE;
- lintwarn(_("split: null string for third argument is a gawk extension"));
+ lintwarn(_("split: null string for third arg is a gawk extension"));
}
} else if (fs->stlen == 1 && (sep->re_flags & CONSTANT) == 0) {
if (fs->stptr[0] == ' ') {
@@ -988,28 +1000,13 @@ do_split(NODE *tree)
}
}
- /*
- * do dupnode(), to avoid problems like
- * x = split(a["LINE"], a, a["FS"])
- * since we assoc_clear the array. gack.
- * this also gives us complete call by value semantics.
- */
- src2 = dupnode(src);
- free_temp(src);
-
- fs2 = dupnode(fs);
- free_temp(fs);
-
- assoc_clear(arr);
-
- if (sep_arr != NULL)
- assoc_clear(sep_arr);
+ s = src->stptr;
+ tmp = make_number((AWKNUM) (*parseit)(UNLIMITED, &s, (int) src->stlen,
+ fs, rp, set_element, arr, sep_arr, FALSE));
- s = src2->stptr;
- tmp = tmp_number((AWKNUM) (*parseit)(UNLIMITED, &s, (int) src2->stlen,
- fs2, rp, set_element, arr, sep_arr, FALSE));
- unref(src2);
- unref(fs2);
+ decr_sp();
+ DEREF(src);
+ unref(fs);
return tmp;
}
@@ -1019,78 +1016,53 @@ do_split(NODE *tree)
*/
NODE *
-do_patsplit(NODE *tree)
+do_patsplit(int nargs)
{
- NODE *src, *arr, *sep, *fpat, *sep_arr, *src2, *fpat2, *tmp;
+ NODE *src, *arr, *sep, *fpat, *tmp, *sep_arr = NULL;
char *s;
Regexp *rp = NULL;
- src = force_string(tree_eval(tree->lnode));
-
- arr = get_param(tree->rnode->lnode);
- if (arr->type != Node_var_array)
- fatal(_("patsplit: second argument is not an array"));
-
- sep = tree->rnode->rnode->lnode;
-
- sep_arr = tree->rnode->rnode->rnode;
- if (sep_arr != NULL) {
- sep_arr = get_param(tree->rnode->rnode->rnode->lnode);
-
+ if (nargs == 4) {
+ sep_arr = POP_PARAM();
if (sep_arr->type != Node_var_array)
fatal(_("patsplit: fourth argument is not an array"));
}
+ sep = POP();
+ arr = POP_PARAM();
+ if (arr->type != Node_var_array)
+ fatal(_("patsplit: second argument is not an array"));
+ src = TOP_STRING();
if (src->stlen == 0) {
/*
* Skip the work if first arg is the null string.
*/
- free_temp(src);
- /*
- * Evaluate sep if it may have side effects.
- */
- if ((sep->re_flags & CONSTANT) == 0)
- free_temp(tree_eval(sep->re_exp));
- /*
- * And now we can safely turn off the arrays.
- */
assoc_clear(arr);
-
if (sep_arr != NULL)
assoc_clear(sep_arr);
-
- return tmp_number((AWKNUM) 0);
+ decr_sp();
+ DEREF(src);
+ return make_number((AWKNUM) 0);
}
- fpat = force_string(tree_eval(sep->re_exp));
+ fpat = dupnode(sep->re_exp);
if (fpat->stlen == 0) {
+ unref(fpat);
fatal(_("patsplit: third argument must be non-null"));
}
- rp = re_update(sep);
-
- /*
- * do dupnode(), to avoid problems like
- * x = split(a["LINE"], a, a["FS"])
- * since we assoc_clear the array. gack.
- * this also gives us complete call by value semantics.
- */
- src2 = dupnode(src);
- free_temp(src);
-
- fpat2 = dupnode(fpat);
- free_temp(fpat);
-
assoc_clear(arr);
-
if (sep_arr != NULL)
assoc_clear(sep_arr);
- s = src2->stptr;
- tmp = tmp_number((AWKNUM) fpat_parse_field(UNLIMITED, &s,
- (int) src2->stlen, fpat2, rp,
+ rp = re_update(sep);
+
+ s = src->stptr;
+ tmp = make_number((AWKNUM) fpat_parse_field(UNLIMITED, &s,
+ (int) src->stlen, fpat, rp,
set_element, arr, sep_arr, FALSE));
- unref(src2);
- unref(fpat2);
+ decr_sp();
+ DEREF(src);
+ unref(fpat);
return tmp;
}
@@ -1099,12 +1071,13 @@ do_patsplit(NODE *tree)
void
set_FIELDWIDTHS()
{
- register char *scan;
+ char *scan;
char *end;
- register int i;
+ int i;
static int fw_alloc = 4;
static short warned = FALSE;
- extern unsigned long strtoul P((const char *, char **endptr, int base));
+ extern unsigned long strtoul(const char *, char **endptr, int base);
+ int fatal_error = FALSE;
if (do_lint && ! warned) {
warned = TRUE;
@@ -1137,10 +1110,10 @@ set_FIELDWIDTHS()
while (is_blank(*scan)) {
++scan;
}
- if (*scan == '-')
- fatal(_("invalid FIELDWIDTHS value, near `%s'"),
- scan);
-
+ if (*scan == '-') {
+ fatal_error = TRUE;
+ break;
+ }
if (*scan == '\0')
break;
@@ -1150,10 +1123,12 @@ set_FIELDWIDTHS()
errno = 0;
tmp = strtoul(scan, &end, 10);
if (errno != 0
- || (*end != '\0' && ! is_blank(*end))
- || !(0 < tmp && tmp <= INT_MAX))
- fatal(_("invalid FIELDWIDTHS value, near `%s'"),
- scan);
+ || (*end != '\0' && ! is_blank(*end))
+ || !(0 < tmp && tmp <= INT_MAX)
+ ) {
+ fatal_error = TRUE;
+ break;
+ }
FIELDWIDTHS[i] = tmp;
scan = end;
/* Skip past any trailing blanks. */
@@ -1168,6 +1143,9 @@ set_FIELDWIDTHS()
FIELDWIDTHS[i+1] = -1;
update_PROCINFO_str("FS", "FIELDWIDTHS");
+ if (fatal_error)
+ fatal(_("invalid FIELDWIDTHS value, near `%s'"),
+ scan);
}
/* set_FS --- handle things when FS is assigned to */
@@ -1182,7 +1160,7 @@ set_FS()
int remake_re = TRUE;
/*
- * If changing the way fields are split, obey least-suprise
+ * If changing the way fields are split, obey least-surprise
* semantics, and force $0 to be split totally.
*/
if (fields_arr != NULL)
@@ -1216,11 +1194,15 @@ set_FS()
unref(save_rs);
save_rs = dupnode(RS_node->var_value);
resave_fs = TRUE;
- if (FS_regexp != NULL) {
- refree(FS_re_yes_case);
- refree(FS_re_no_case);
- FS_re_yes_case = FS_re_no_case = FS_regexp = NULL;
- }
+
+ /* If FS_re_no_case assignment is fatal (make_regexp in remake_re)
+ * FS_regexp will be NULL with a non-null FS_re_yes_case.
+ * refree() handles null argument; no need for `if (FS_regexp != NULL)' below.
+ * Please do not remerge.
+ */
+ refree(FS_re_yes_case);
+ refree(FS_re_no_case);
+ FS_re_yes_case = FS_re_no_case = FS_regexp = NULL;
choose_fs_function:
@@ -1271,20 +1253,18 @@ choose_fs_function:
}
}
if (remake_re) {
- if (FS_regexp != NULL) {
- refree(FS_re_yes_case);
- refree(FS_re_no_case);
- FS_re_yes_case = FS_re_no_case = FS_regexp = NULL;
- }
+ refree(FS_re_yes_case);
+ refree(FS_re_no_case);
+ FS_re_yes_case = FS_re_no_case = FS_regexp = NULL;
if (buf[0] != '\0') {
- FS_re_yes_case = make_regexp(buf, strlen(buf), FALSE, TRUE);
- FS_re_no_case = make_regexp(buf, strlen(buf), TRUE, TRUE);
+ FS_re_yes_case = make_regexp(buf, strlen(buf), FALSE, TRUE, TRUE);
+ FS_re_no_case = make_regexp(buf, strlen(buf), TRUE, TRUE, TRUE);
FS_regexp = (IGNORECASE ? FS_re_no_case : FS_re_yes_case);
parse_field = re_parse_field;
} else if (parse_field == re_parse_field) {
- FS_re_yes_case = make_regexp(fs->stptr, fs->stlen, FALSE, TRUE);
- FS_re_no_case = make_regexp(fs->stptr, fs->stlen, TRUE, TRUE);
+ FS_re_yes_case = make_regexp(fs->stptr, fs->stlen, FALSE, TRUE, TRUE);
+ FS_re_no_case = make_regexp(fs->stptr, fs->stlen, TRUE, TRUE, TRUE);
FS_regexp = (IGNORECASE ? FS_re_no_case : FS_re_yes_case);
} else
FS_re_yes_case = FS_re_no_case = FS_regexp = NULL;
@@ -1320,12 +1300,15 @@ void
update_PROCINFO_str(char *subscript, char *str)
{
NODE **aptr;
+ NODE *tmp;
if (PROCINFO_node == NULL)
return;
-
- aptr = assoc_lookup(PROCINFO_node, tmp_string(subscript, strlen(subscript)), FALSE);
- assign_val(aptr, tmp_string(str, strlen(str)));
+ tmp = make_string(subscript, strlen(subscript));
+ aptr = assoc_lookup(PROCINFO_node, tmp, FALSE);
+ unref(tmp);
+ unref(*aptr);
+ *aptr = make_string(str, strlen(str));
}
/* update_PROCINFO_num --- update PROCINFO[sub] with numeric value */
@@ -1334,11 +1317,14 @@ void
update_PROCINFO_num(char *subscript, AWKNUM val)
{
NODE **aptr;
+ NODE *tmp;
if (PROCINFO_node == NULL)
return;
-
- aptr = assoc_lookup(PROCINFO_node, tmp_string(subscript, strlen(subscript)), FALSE);
+ tmp = make_string(subscript, strlen(subscript));
+ aptr = assoc_lookup(PROCINFO_node, tmp, FALSE);
+ unref(tmp);
+ unref(*aptr);
*aptr = make_number(val);
}
@@ -1388,25 +1374,21 @@ set_FPAT()
unref(save_fpat);
save_fpat = dupnode(FPAT_node->var_value);
- if (FPAT_regexp != NULL) {
- refree(FPAT_re_yes_case);
- refree(FPAT_re_no_case);
- FPAT_re_yes_case = FPAT_re_no_case = FPAT_regexp = NULL;
- }
+ refree(FPAT_re_yes_case);
+ refree(FPAT_re_no_case);
+ FPAT_re_yes_case = FPAT_re_no_case = FPAT_regexp = NULL;
set_fpat_function:
fpat = force_string(FPAT_node->var_value);
parse_field = fpat_parse_field;
if (remake_re) {
- if (FPAT_regexp != NULL) {
- refree(FPAT_re_yes_case);
- refree(FPAT_re_no_case);
- FPAT_re_yes_case = FPAT_re_no_case = FPAT_regexp = NULL;
- }
+ refree(FPAT_re_yes_case);
+ refree(FPAT_re_no_case);
+ FPAT_re_yes_case = FPAT_re_no_case = FPAT_regexp = NULL;
- FPAT_re_yes_case = make_regexp(fpat->stptr, fpat->stlen, FALSE, TRUE);
- FPAT_re_no_case = make_regexp(fpat->stptr, fpat->stlen, TRUE, TRUE);
+ FPAT_re_yes_case = make_regexp(fpat->stptr, fpat->stlen, FALSE, TRUE, TRUE);
+ FPAT_re_no_case = make_regexp(fpat->stptr, fpat->stlen, TRUE, TRUE, TRUE);
FPAT_regexp = (IGNORECASE ? FPAT_re_no_case : FPAT_re_yes_case);
}