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