xref: /csrg-svn/local/toolchest/ksh/sh/name.h (revision 35158)
1*35158Smarc /*
2*35158Smarc 
3*35158Smarc  *      Copyright (c) 1984, 1985, 1986 AT&T
4*35158Smarc  *      All Rights Reserved
5*35158Smarc 
6*35158Smarc  *      THIS IS UNPUBLISHED PROPRIETARY SOURCE
7*35158Smarc  *      CODE OF AT&T.
8*35158Smarc  *      The copyright notice above does not
9*35158Smarc  *      evidence any actual or intended
10*35158Smarc  *      publication of such source code.
11*35158Smarc 
12*35158Smarc  */
13*35158Smarc /* @(#)name.h	1.1 */
14*35158Smarc 
15*35158Smarc /* Nodes can have all kinds of values */
16*35158Smarc union Namval
17*35158Smarc {
18*35158Smarc 	char		*cp;
19*35158Smarc 	int		*ip;
20*35158Smarc 	char		c;
21*35158Smarc 	int		i;
22*35158Smarc 	unsigned	u;
23*35158Smarc 	long		*lp;
24*35158Smarc 	double		*dp;	/* for floating point arithmetic */
25*35158Smarc 	struct Namaray	*aray;	/* for array node */
26*35158Smarc 	union Namval	*up;	/* for indirect node */
27*35158Smarc 	struct Bfunction *fp;	/* builtin-function like $RANDOM */
28*35158Smarc 	struct Ufunction *rp;	/* shell user defined functions */
29*35158Smarc };
30*35158Smarc 
31*35158Smarc /* each Namnod and each array element has one of these */
32*35158Smarc struct Nodval
33*35158Smarc {
34*35158Smarc         unsigned        namflg;         /* attributes */
35*35158Smarc         union Namval    namval;         /* value field */
36*35158Smarc };
37*35158Smarc 
38*35158Smarc /* This is an array template */
39*35158Smarc struct Namaray
40*35158Smarc {
41*35158Smarc 	unsigned short		adot;		/* index of last reference */
42*35158Smarc 	unsigned short		maxi;		/* maximum index of array */
43*35158Smarc         struct Nodval	*val[1];	/* array of value holders */
44*35158Smarc };
45*35158Smarc 
46*35158Smarc /* This is a template for a storage tree */
47*35158Smarc struct Amemory
48*35158Smarc {
49*35158Smarc 	struct Amemory  *nexttree;	/* search trees can be chained */
50*35158Smarc         short           memsize;        /* number of listheads */
51*35158Smarc         struct Namnod   *memhead[1];    /* listhead pointers   */
52*35158Smarc };
53*35158Smarc 
54*35158Smarc /* This describes a named node */
55*35158Smarc struct Namnod
56*35158Smarc {
57*35158Smarc         struct Nodval   value;          /* determines value of the item */
58*35158Smarc 	struct Namnod	*namnxt;	/* pointer to next Namnod  */
59*35158Smarc 	char		*namid;		/* pointer to name of item */
60*35158Smarc 	short 		namsz;		/* size of item */
61*35158Smarc };
62*35158Smarc 
63*35158Smarc /* This describes a builtin function node */
64*35158Smarc struct Bfunction
65*35158Smarc {
66*35158Smarc 	long	(*f_vp)();		/* value function */
67*35158Smarc 	int	(*f_ap)();		/* assignment function */
68*35158Smarc };
69*35158Smarc 
70*35158Smarc /* This describes a user defined function node */
71*35158Smarc struct Ufunction
72*35158Smarc {
73*35158Smarc 	long	hoffset;		/* offset into history file */
74*35158Smarc 	int	**ptree;		/* address of parse tree */
75*35158Smarc };
76*35158Smarc 
77*35158Smarc #define MEMSIZE   32*sizeof(int)	/* default memory size for shell.
78*35158Smarc 						Must be a power of 2 */
79*35158Smarc #define PSEPS	":"
80*35158Smarc #define ARRMAX   512	/* maximum number of elements in an array */
81*35158Smarc #define ARRINCR    16	/* number of elements to grow when array bound exceeded
82*35158Smarc 				 Must be a power of 2 */
83*35158Smarc #define MAXTREES   20	/* maximum number of mounted search trees */
84*35158Smarc 
85*35158Smarc #define NO_SUBSCRIPT	ARRMAX	/* subscript not defined */
86*35158Smarc #ifndef NULL
87*35158Smarc #define NULL	0
88*35158Smarc #endif
89*35158Smarc 
90*35158Smarc /* types of namenode items */
91*35158Smarc 
92*35158Smarc #define N_DEFAULT 0
93*35158Smarc #define INT_GER		I_FLAG	/* integer type */
94*35158Smarc #define CPOIN_TER	W_FLAG
95*35158Smarc #define N_AVAIL		B_FLAG	/* node is logically non-existent, blocked */
96*35158Smarc #define C_WRITE		C_FLAG	/* make copy of node on assignment */
97*35158Smarc #define ARRAY		F_FLAG	/* node is an array */
98*35158Smarc #define IN_DIR		P_FLAG	/* value is a pointer to a value node */
99*35158Smarc #define N_ALLOC		V_FLAG	/* don't allocate space for the value */
100*35158Smarc #define N_FREE		S_FLAG	/* don't free the space when releasing value */
101*35158Smarc #define T_FORM		T_FLAG	/* program usable tflag */
102*35158Smarc #define L_TO_U		U_FLAG	/* convert to uppercase */
103*35158Smarc #define U_TO_L		L_FLAG	/* convert to lowercase */
104*35158Smarc #define Z_FILL		Z_FLAG	/* right justify and fill with leading zeros */
105*35158Smarc #define R_JUST		W_FLAG	/* right justify and blank fill */
106*35158Smarc #define L_JUST		O_FLAG	/* left justify and blank fill */
107*35158Smarc #define HOST_N		M_FLAG	/* convert to host file name in non-unix */
108*35158Smarc #define N_EXPORT	X_FLAG	/* export bit */
109*35158Smarc #define N_RDONLY	R_FLAG	/* readonly bit */
110*35158Smarc #define N_IMPORT	N_FLAG	/* imported from environment */
111*35158Smarc 
112*35158Smarc 
113*35158Smarc /* The following are used with INT_FLG */
114*35158Smarc #define	BLT_NOD	M_FLAG		/* builtin function flag */
115*35158Smarc #define OC_TAL	O_FLAG
116*35158Smarc #define UN_SIGN	U_FLAG
117*35158Smarc 
118*35158Smarc #define is_afunction(n)	(((n)->value.namflg&(~(N_EXPORT|T_FLAG)))==(INT_GER|L_FLAG))
119*35158Smarc #define	funtree(n)	((n)->value.namval.rp->ptree)
120*35158Smarc #define NO_ALIAS	(L_TO_U|U_TO_L|N_FLAG)
121*35158Smarc 
122*35158Smarc 
123*35158Smarc /* namenode states */
124*35158Smarc 
125*35158Smarc #define NO_ERR_ 0
126*35158Smarc #define SANERR  E_FLAG
127*35158Smarc 
128*35158Smarc #define ADD_NOD	1 /* add node if not found */
129*35158Smarc #define CHK_FOR	2 /* look for only if valid name */
130*35158Smarc #define	RE_USE	4 /* used for efficiency in multitree searches */
131*35158Smarc 
132*35158Smarc /* NAMNOD MACROS */
133*35158Smarc 
134*35158Smarc /* ...  for arrays */
135*35158Smarc 
136*35158Smarc #define arayp(v)        (v->value.namval.aray)
137*35158Smarc #define curdot(n)	((arayp(n))->adot)
138*35158Smarc #define abound(n)       ((int)((n)->value.namval.aray->maxi))
139*35158Smarc #ifdef KSHELL
140*35158Smarc #define setdot(n,i)     ((n)->value.namval.aray->adot = i)
141*35158Smarc #endif	/* KSHELL */
142*35158Smarc 
143*35158Smarc /* ... for attributes */
144*35158Smarc 
145*35158Smarc #define namflag(n)	(n)->value.namflg
146*35158Smarc #define attest(n,f)     (namflag(n) & (f))
147*35158Smarc #ifdef KSHELL
148*35158Smarc #define attrib(n,f)	((n)->value.namflg |= f)
149*35158Smarc #define sattrib(n,f)	((n)->value.namflg = f)
150*35158Smarc #define pattrib(n,f)	((n)->value.namflg &= f)
151*35158Smarc #else
152*35158Smarc #define attrib(n,f)     (chattrib (n, namflag(n)|(f)))
153*35158Smarc #define sattrib(n,f)    (chattrib (n, f))
154*35158Smarc #define pattrib(n,f)    (chattrib (n, namflag(n)&(f)))
155*35158Smarc #endif	/* KSHELL */
156*35158Smarc 
157*35158Smarc /* ... etc */
158*35158Smarc 
159*35158Smarc #define isnull(n)       ((n)->value.namval.cp == NULL)  /* strings only */
160*35158Smarc #define freeble(nv)     (((int)(nv)) & 01)
161*35158Smarc #define mrkfree(nv)     ((struct Nodval*)(((int)(nv)) | 01))
162*35158Smarc #define unmark(nv)      ((struct Nodval*)(((int)(nv)) & ~01))
163*35158Smarc #define errorp(np)     ((np)->namerr)
164*35158Smarc #define asscadr(np,val)	assiadr(np,((int*)(val)))
165*35158Smarc 
166*35158Smarc extern char synmsg[];
167*35158Smarc extern char subscript[];
168*35158Smarc extern char badnum[];
169*35158Smarc extern char badparam[];
170*35158Smarc extern char divzero[];
171*35158Smarc extern char hdigits[];
172*35158Smarc extern char wtfailed[];
173*35158Smarc extern char notid[];
174*35158Smarc extern struct Amemory *namep;
175*35158Smarc extern int lastbase;
176