diff options
author | Arnold D. Robbins <arnold@skeeve.com> | 2015-02-27 11:32:58 +0200 |
---|---|---|
committer | Arnold D. Robbins <arnold@skeeve.com> | 2015-02-27 11:32:58 +0200 |
commit | 9bd02dc1cc61e195374d3bf83febb724fb08d739 (patch) | |
tree | 6bf791dda3e32f22b9b3d2d2c12deea9865a59e8 /builtin.c | |
parent | 06ff159e6744b18a3c15d95f9100b050cd169269 (diff) | |
download | egawk-9bd02dc1cc61e195374d3bf83febb724fb08d739.tar.gz egawk-9bd02dc1cc61e195374d3bf83febb724fb08d739.tar.bz2 egawk-9bd02dc1cc61e195374d3bf83febb724fb08d739.zip |
First set of changes toward @/.../.
Diffstat (limited to 'builtin.c')
-rw-r--r-- | builtin.c | 35 |
1 files changed, 35 insertions, 0 deletions
@@ -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 */ |