diff options
Diffstat (limited to 'do/defined')
-rw-r--r-- | do/defined | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/do/defined b/do/defined new file mode 100644 index 0000000000..2721f05032 --- /dev/null +++ b/do/defined @@ -0,0 +1,42 @@ +int /*SUPPRESS 590*/ +do_defined(TARG,arg,gimme,arglast) +STR *TARG; +register ARG *arg; +int gimme; +int *arglast; +{ + register int type; + register int retarg = arglast[0] + 1; + int retval; + ARRAY *ary; + HASH *hash; + + if ((arg[1].arg_type & A_MASK) != A_LEXPR) + fatal("Illegal argument to defined()"); + arg = arg[1].arg_ptr.arg_arg; + type = arg->arg_type; + + if (type == O_SUBR || type == O_DBSUBR) { + if ((arg[1].arg_type & A_MASK) == A_WORD) + retval = stab_sub(arg[1].arg_ptr.arg_stab) != 0; + else { + STR *tmpstr = STAB_STR(arg[1].arg_ptr.arg_stab); + + retval = tmpstr && stab_sub(stabent(str_get(tmpstr),TRUE)) != 0; + } + } + else if (type == O_ARRAY || type == O_LARRAY || + type == O_ASLICE || type == O_LASLICE ) + retval = ((ary = stab_xarray(arg[1].arg_ptr.arg_stab)) != 0 + && ary->ary_max >= 0 ); + else if (type == O_HASH || type == O_LHASH || + type == O_HSLICE || type == O_LHSLICE ) + retval = ((hash = stab_xhash(arg[1].arg_ptr.arg_stab)) != 0 + && hash->tbl_array); + else + retval = FALSE; + str_numset(TARG,(double)retval); + stack->ary_array[retarg] = TARG; + return retarg; +} + |