diff options
Diffstat (limited to 'builtin.c')
-rw-r--r-- | builtin.c | 38 |
1 files changed, 38 insertions, 0 deletions
@@ -3818,6 +3818,44 @@ do_div(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 */ |