1*35203Smarc /*
2*35203Smarc 
3*35203Smarc  *      Copyright (c) 1984, 1985, 1986 AT&T
4*35203Smarc  *      All Rights Reserved
5*35203Smarc 
6*35203Smarc  *      THIS IS UNPUBLISHED PROPRIETARY SOURCE
7*35203Smarc  *      CODE OF AT&T.
8*35203Smarc  *      The copyright notice above does not
9*35203Smarc  *      evidence any actual or intended
10*35203Smarc  *      publication of such source code.
11*35203Smarc 
12*35203Smarc  */
13*35203Smarc /* @(#)valup.c	1.1 */
14*35203Smarc 
15*35203Smarc /*
16*35203Smarc  *   VALUP.C
17*35203Smarc  *
18*35203Smarc  *   Programmer:  D. G. Korn
19*35203Smarc  *
20*35203Smarc  *        Owner:  D. A. Lambeth
21*35203Smarc  *
22*35203Smarc  *         Date:  April 17, 1980
23*35203Smarc  *
24*35203Smarc  *
25*35203Smarc  *
26*35203Smarc  *   VALUP (NODP)
27*35203Smarc  *
28*35203Smarc  *        Return a pointer to the value of the node given by NODP.
29*35203Smarc  *
30*35203Smarc  *
31*35203Smarc  *
32*35203Smarc  *   See Also:  assign(III), asscadr(III), assiadr(III), assnum(III),
33*35203Smarc  *              unassign(III)
34*35203Smarc  */
35*35203Smarc 
36*35203Smarc #include	"name.h"
37*35203Smarc #include        "flags.h"
38*35203Smarc 
39*35203Smarc #ifdef NAME_SCOPE
40*35203Smarc extern struct Namnod *copy_nod();
41*35203Smarc #endif
42*35203Smarc extern char *utos();
43*35203Smarc extern char *ltos();
44*35203Smarc extern char *itos();
45*35203Smarc extern void failed();
46*35203Smarc 
47*35203Smarc 
48*35203Smarc /*
49*35203Smarc  *   VALUP (NODP)
50*35203Smarc  *
51*35203Smarc  *        struct Namnod *NODP;
52*35203Smarc  *
53*35203Smarc  *   Return a pointer to a character string that denotes the value
54*35203Smarc  *   of NODP.  If NODP refers to an array,  return a pointer to
55*35203Smarc  *   the value associated with the current index.
56*35203Smarc  *
57*35203Smarc  *   If NODP is blocked, N_AVAIL, then the value of the node
58*35203Smarc  *   with the same name in the last tree is returned.
59*35203Smarc  *   Thus a node can become blocked after the lookup but
60*35203Smarc  *   before retrieving its value and still work correctly.
61*35203Smarc  *
62*35203Smarc  *   If the value of NODP is an integer, the string returned will
63*35203Smarc  *   be overwritten by the next call to valup.
64*35203Smarc  *
65*35203Smarc  *   If NODP has no value, NULL is returned.
66*35203Smarc  */
67*35203Smarc 
valup(nodp)68*35203Smarc char *valup(nodp)
69*35203Smarc struct Namnod *nodp;
70*35203Smarc {
71*35203Smarc 	int dot;
72*35203Smarc 	register struct Namnod *np=nodp;
73*35203Smarc 	register union Namval *up= &np->value.namval;
74*35203Smarc 	register struct Nodval *nv;
75*35203Smarc #ifdef NAME_SCOPE
76*35203Smarc 	if (attest (np,N_AVAIL))	/* node blocked */
77*35203Smarc 		/* use node with same name in last tree */
78*35203Smarc 		np = copy_nod(np,0);
79*35203Smarc #endif
80*35203Smarc 	if (attest (np, ARRAY))
81*35203Smarc         {
82*35203Smarc         	dot = up->aray->adot;
83*35203Smarc         	if (dot > abound (np))
84*35203Smarc         		failed (itos(dot), subscript);
85*35203Smarc         	if ((nv = up->aray->val[dot]) == NULL)
86*35203Smarc 	        	return (NULL);
87*35203Smarc         	else
88*35203Smarc 	        	up = &(unmark (nv)->namval);
89*35203Smarc         }
90*35203Smarc 	if ((attest (np, IN_DIR)) && up->cp)
91*35203Smarc 		up = up->up;
92*35203Smarc 	if (attest (np, INT_GER))
93*35203Smarc 	{
94*35203Smarc 		long l;
95*35203Smarc         	if (attest (np, CPOIN_TER))
96*35203Smarc 			return(up->cp);
97*35203Smarc 		else if(attest (np, (BLT_NOD)))
98*35203Smarc 			l = ((*up->fp->f_vp)());
99*35203Smarc         	else
100*35203Smarc 		{
101*35203Smarc 			if(up->lp == NULL)
102*35203Smarc 				return(NULL);
103*35203Smarc 			l = *(up->lp);
104*35203Smarc 		}
105*35203Smarc 		if (attest (np, (BLT_NOD|UN_SIGN)))
106*35203Smarc #ifdef pdp11
107*35203Smarc 			return(utos(l,np->namsz));
108*35203Smarc #else
109*35203Smarc 			return(utos((unsigned long)l,np->namsz));
110*35203Smarc #endif /* pdp11 */
111*35203Smarc 		return(ltos(l,np->namsz));
112*35203Smarc 	}
113*35203Smarc 	return (up->cp);
114*35203Smarc }
115*35203Smarc 
116