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