aboutsummaryrefslogtreecommitdiffstats
path: root/builtin.c
diff options
context:
space:
mode:
Diffstat (limited to 'builtin.c')
-rw-r--r--builtin.c50
1 files changed, 46 insertions, 4 deletions
diff --git a/builtin.c b/builtin.c
index 500b35d9..d50e75ae 100644
--- a/builtin.c
+++ b/builtin.c
@@ -3116,7 +3116,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);
@@ -3140,7 +3141,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);
@@ -3177,7 +3179,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)
@@ -3205,7 +3208,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);
@@ -3832,6 +3836,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 */