diff options
Diffstat (limited to 'builtin.c')
-rw-r--r-- | builtin.c | 50 |
1 files changed, 46 insertions, 4 deletions
@@ -3109,7 +3109,8 @@ call_sub(const char *name, int nargs) * push replace * push $0 */ - regex = make_regnode(Node_regex, regex); + if (regex->type != Node_hardregex) + regex = make_regnode(Node_regex, regex); PUSH(regex); PUSH(replace); lhs = r_get_field(zero, (Func_ptr *) 0, true); @@ -3133,7 +3134,8 @@ call_sub(const char *name, int nargs) * nargs++ * } */ - regex = make_regnode(Node_regex, regex); + if (regex->type != Node_hardregex) + regex = make_regnode(Node_regex, regex); PUSH(regex); PUSH(replace); PUSH(glob_flag); @@ -3170,7 +3172,8 @@ call_match(int nargs) /* Don't need to pop the string just to push it back ... */ - regex = make_regnode(Node_regex, regex); + if (regex->type != Node_hardregex) + regex = make_regnode(Node_regex, regex); PUSH(regex); if (array) @@ -3198,7 +3201,8 @@ call_split_func(const char *name, int nargs) if (nargs >= 3) { regex = POP_STRING(); - regex = make_regnode(Node_regex, regex); + if (regex->type != Node_hardregex) + regex = make_regnode(Node_regex, regex); } else { if (name[0] == 's') { regex = make_regnode(Node_regex, FS_node->var_value); @@ -3825,6 +3829,44 @@ do_intdiv(int nargs) return make_number((AWKNUM) 0.0); } +/* do_typeof --- return a string with the type of the arg */ + +NODE * +do_typeof(int nargs) +{ + NODE *arg; + char *res = "unknown"; + int null_str_flags = (STRCUR|STRING|NUMCUR|NUMBER); + + arg = POP(); + switch (arg->type) { + case Node_var_array: + res = "array"; + break; + case Node_hardregex: + res = "regexp"; + break; + case Node_val: + case Node_var: + if ((arg->flags & null_str_flags) == null_str_flags) + res = "untyped"; + else if ((arg->flags & STRING) != 0) + res = "scalar_s"; + else if ((arg->flags & NUMBER) != 0) + res = "scalar_n"; + break; + case Node_var_new: + res = "untyped"; + break; + default: + fatal(_("typeof: unknown argument type `%s'"), + nodetype2str(arg->type)); + break; + } + + DEREF(arg); + return make_string(res, strlen(res)); +} /* mbc_byte_count --- return number of bytes for corresponding numchars multibyte characters */ |