From 9bd02dc1cc61e195374d3bf83febb724fb08d739 Mon Sep 17 00:00:00 2001 From: "Arnold D. Robbins" Date: Fri, 27 Feb 2015 11:32:58 +0200 Subject: First set of changes toward @/.../. --- builtin.c | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'builtin.c') diff --git a/builtin.c b/builtin.c index 38a974fc..ebd7dde5 100644 --- a/builtin.c +++ b/builtin.c @@ -3661,6 +3661,41 @@ 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"; + + 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 & 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 */ -- cgit v1.2.3