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 /* @(#)adjust.c	1.1 */
14 
15 /*
16  *   ADJUST.C
17  *
18  *   Programmer:  D. A. Lambeth
19  *
20  *        Owner:  D. A. Lambeth
21  *
22  *         Date:  April 17, 1980
23  *
24  *
25  *
26  *   CHATTRIB (NODE, NEWATTS)
27  *
28  *        Give NODE the attribute(s) NEWATTS, and change its
29  *        value to conform to the new attributes.
30  *
31  *
32  *
33  *   See Also:  TYPESET(I)
34  */
35 
36 
37 #include     "name.h"
38 #include     "flags.h"
39 
40 extern char *valup();
41 extern char *malloc();
42 extern char *strcpy();
43 extern void fassign();
44 extern void unassign();
45 extern void free();
46 #ifdef BSD
47 #define strchr	index
48 #endif	/* BSD */
49 extern char *strchr();
50 #ifdef NAME_SCOPE
51 extern struct Namnod *copy_nod();
52 #endif
53 #ifdef apollo
54 extern void	ev_$delete_var();
55 extern void	ev_$set_var();
56 #endif /* apollo */
57 
58 
59 /*
60  *   CHATTRIB (NODE, NEWATTS)
61  *
62  *        struct Namnod *NODE;
63  *
64  *        int NEWATTS;
65  *
66  *	  int size;
67  *
68  *   Give NODE the attributes NEWATTS, and change its current
69  *   value to conform to NEWATTS.  The SIZE of left and right
70  *   justified fields may be given.
71  */
72 
73 chattrib (node, newatts, size)
74 struct Namnod *node;
75 unsigned int newatts;
76 {
77 	register char *sp;
78 	register char *cp = NULL;
79 	register struct Namnod *np = node;
80 	register unsigned int n;
81 
82 #ifdef NAME_SCOPE
83 	if(np->value.namflg&C_WRITE)
84 		np = copy_nod(np,1);
85 #endif
86 	/* handle attributes that do not change data separately */
87 	n = np->value.namflg;
88 #ifdef apollo
89 	if(((n^newatts)&N_EXPORT))
90 	/* record changes to the environment */
91 	{
92 		short namlen = strlen(np->namid);
93 		if(cp = strchr(np->namid,'='))
94 		{
95 			namlen = cp - np->namid;
96 			cp = NULL;
97 		}
98 		if(n&N_EXPORT)
99 			ev_$delete_var(np->namid,&namlen);
100 		else
101 		{
102 			char *vp = valup(np);
103 			short vallen = strlen(vp);
104 			ev_$set_var(np->namid,&namlen,vp,&vallen);
105 		}
106 	}
107 #endif /* apollo */
108 	if(size==0 && ((n^newatts)&~(E_FLAG|N_IMPORT|N_EXPORT|N_RDONLY|T_FORM))==0)
109 	{
110 		if(((n^newatts)&N_EXPORT) && (cp=strchr(np->namid,'=')))
111 		{
112 			/* get rid of import attribute */
113 			*cp = 0;
114 			newatts &= ~N_IMPORT;
115 		}
116 		np->value.namflg = newatts;
117 		return;
118 	}
119 	if (sp = valup (np))
120  	{
121 		cp = malloc ((n=strlen (sp)) + 1);
122 		strcpy (cp, sp);
123 		unassign(np);
124 		if(size==0 && (newatts&(L_JUST|R_JUST|Z_FILL)))
125 			np->namsz =  n;
126 	 else
127 			np->namsz = size;
128 	}
129 	else
130 		np->namsz = size;
131 	np->value.namflg = newatts;
132 	if (cp != NULL)
133 	{
134 		fassign (np, cp);
135 		free(cp);
136 	}
137 	return;
138 }
139