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