summaryrefslogtreecommitdiff
path: root/do/defined
blob: 2721f050320cd31efc19ded47b3a7c888a4a1e3f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
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;
}