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 /* @(#)unassign.c	1.1 */
14 
15 /*
16  *   UNASSIGN.C
17  *
18  *   Programmer:  D. G. Korn
19  *
20  *        Owner:  D. A. Lambeth
21  *
22  *         Date:  April 17, 1980
23  *
24  *
25  *
26  *   UNASSIGN (NODE)
27  *
28  *        Nullify the value and the attributes of the Namnod
29  *        given by NODE.
30  *
31  *
32  *
33  *   See Also:  assign(III), assnum(III), assiadr(III), asscadr(III),
34  *              valup(III)
35  */
36 
37 #include	"name.h"
38 #include        "flags.h"
39 
40 
41 /*
42  *   UNASSIGN (NODE)
43  *
44  *       struct Namnod *NODE;
45  *
46  *   Set the value of NODE to NULL, and nullify any attributes
47  *   that NODE may have had.  Free any freeable space occupied
48  *   by the value of NODE.  If NODE denotes an array member, it
49  *   will retain its attributes.  Any node that has the
50  *   indirect (IN_DIR) attribute will retain that attribute.
51  */
52 
53 extern void	free();
54 
55 void	unassign(node)
56 struct Namnod *node;
57 {
58 	register struct Namnod *np=node;
59 	register union Namval *up = &np->value.namval;
60 #ifdef NAME_SCOPE
61 	if (attest (np, C_WRITE))
62 	{
63 		np->value.namflg |= N_AVAIL;
64 		return;
65 	}
66 #endif
67 	if (attest (np, ARRAY))
68 	{
69 		register struct Namaray *ap = up->aray;
70 		if(ap->adot != NO_SUBSCRIPT)
71 		{
72 			struct Nodval *nv = unmark(ap->val[ap->adot]);
73 			if(ap->adot == ap->maxi)
74 				ap->maxi--;
75 			if(nv==NULL || (up = &nv->namval)==NULL)
76 				return;
77 		}
78 		else
79 		{
80 			for(ap->adot=0;ap->adot <= ap->maxi;ap->adot++)
81 				unassign(np);
82 			free((char*)ap);
83 			up->cp = NULL;
84 			np->value.namflg = 0;
85 			return;
86 		}
87 	}
88 	if (attest (np, IN_DIR))
89 		up = up->up;
90 	if (attest (np, INT_GER))
91 	{
92         	if ((attest (np, L_FLAG)) && (up->lp != NULL))
93 			free((char *)up->lp);
94 	}
95 	else if ((!attest (np, N_FREE)) && (!isnull (np)))
96 		free(up->cp);
97 	up->cp = NULL;
98 	if (!attest (np, ARRAY))
99 	{
100 		np->value.namflg &= IN_DIR;
101 		np->namsz = 0;
102 	}
103 }
104