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