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