date and time created 88/07/21 17:35:55 by marc
authorMarc Teitelbaum <marc@ucbvax.Berkeley.EDU>
Fri, 22 Jul 1988 08:35:55 +0000 (00:35 -0800)
committerMarc Teitelbaum <marc@ucbvax.Berkeley.EDU>
Fri, 22 Jul 1988 08:35:55 +0000 (00:35 -0800)
SCCS-vsn: local/toolchest/ksh/shlib/unassign.c 1.1

usr/src/local/toolchest/ksh/shlib/unassign.c [new file with mode: 0644]

diff --git a/usr/src/local/toolchest/ksh/shlib/unassign.c b/usr/src/local/toolchest/ksh/shlib/unassign.c
new file mode 100644 (file)
index 0000000..c44f913
--- /dev/null
@@ -0,0 +1,103 @@
+/*
+
+ *      Copyright (c) 1984, 1985, 1986 AT&T
+ *      All Rights Reserved
+
+ *      THIS IS UNPUBLISHED PROPRIETARY SOURCE 
+ *      CODE OF AT&T.
+ *      The copyright notice above does not 
+ *      evidence any actual or intended
+ *      publication of such source code.
+
+ */
+/* @(#)unassign.c      1.1 */
+
+/*
+ *   UNASSIGN.C
+ *
+ *   Programmer:  D. G. Korn
+ *
+ *        Owner:  D. A. Lambeth
+ *
+ *         Date:  April 17, 1980
+ *
+ *
+ *
+ *   UNASSIGN (NODE)
+ *        
+ *        Nullify the value and the attributes of the Namnod
+ *        given by NODE.
+ *
+ *
+ *
+ *   See Also:  assign(III), assnum(III), assiadr(III), asscadr(III),
+ *              valup(III)
+ */
+
+#include       "name.h"
+#include        "flags.h"
+
+
+/*
+ *   UNASSIGN (NODE)
+ *
+ *       struct Namnod *NODE;
+ * 
+ *   Set the value of NODE to NULL, and nullify any attributes
+ *   that NODE may have had.  Free any freeable space occupied
+ *   by the value of NODE.  If NODE denotes an array member, it
+ *   will retain its attributes.  Any node that has the
+ *   indirect (IN_DIR) attribute will retain that attribute.
+ */
+
+extern void    free();
+
+void   unassign(node)
+struct Namnod *node;
+{
+       register struct Namnod *np=node;
+       register union Namval *up = &np->value.namval;
+#ifdef NAME_SCOPE
+       if (attest (np, C_WRITE))
+       {
+               np->value.namflg |= N_AVAIL;
+               return;
+       }
+#endif
+       if (attest (np, ARRAY))
+       {
+               register struct Namaray *ap = up->aray;
+               if(ap->adot != NO_SUBSCRIPT)
+               {
+                       struct Nodval *nv = unmark(ap->val[ap->adot]);
+                       if(ap->adot == ap->maxi)
+                               ap->maxi--;
+                       if(nv==NULL || (up = &nv->namval)==NULL)
+                               return;
+               }
+               else
+               {
+                       for(ap->adot=0;ap->adot <= ap->maxi;ap->adot++)
+                               unassign(np);
+                       free((char*)ap);
+                       up->cp = NULL;
+                       np->value.namflg = 0;
+                       return;
+               }
+       }
+       if (attest (np, IN_DIR))
+               up = up->up;
+       if (attest (np, INT_GER))
+       {
+               if ((attest (np, L_FLAG)) && (up->lp != NULL))
+                       free((char *)up->lp);
+       }
+       else if ((!attest (np, N_FREE)) && (!isnull (np)))
+               free(up->cp);
+       up->cp = NULL;
+       if (!attest (np, ARRAY))
+       {
+               np->value.namflg &= IN_DIR;
+               np->namsz = 0;
+       }
+}