xref: /titanic_50/usr/src/lib/libshell/amd64/include/ast/nval.h (revision 275c9da86e89f8abf71135cf63d9fc23671b2e60)
1 
2 /* : : generated by proto : : */
3 /***********************************************************************
4 *                                                                      *
5 *               This software is part of the ast package               *
6 *           Copyright (c) 1982-2007 AT&T Knowledge Ventures            *
7 *                      and is licensed under the                       *
8 *                  Common Public License, Version 1.0                  *
9 *                      by AT&T Knowledge Ventures                      *
10 *                                                                      *
11 *                A copy of the License is available at                 *
12 *            http://www.opensource.org/licenses/cpl1.0.txt             *
13 *         (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9)         *
14 *                                                                      *
15 *              Information and Software Systems Research               *
16 *                            AT&T Research                             *
17 *                           Florham Park NJ                            *
18 *                                                                      *
19 *                  David Korn <dgk@research.att.com>                   *
20 *                                                                      *
21 ***********************************************************************/
22 
23 #ifndef NV_DEFAULT
24 #if !defined(__PROTO__)
25 #include <prototyped.h>
26 #endif
27 #if !defined(__LINKAGE__)
28 #define __LINKAGE__		/* 2004-08-11 transition */
29 #endif
30 
31 /*
32  * David Korn
33  * AT&T Labs
34  *
35  * Interface definitions of structures for name-value pairs
36  * These structures are used for named variables, functions and aliases
37  *
38  */
39 
40 
41 #include	<ast.h>
42 #include	<cdt.h>
43 
44 /* for compatibility with old hash library */
45 #define Hashtab_t	Dt_t
46 #define HASH_BUCKET	1
47 #define HASH_NOSCOPE	2
48 #define HASH_SCOPE	4
49 #define hashscope(x)	dtvnext(x)
50 
51 typedef struct Namval Namval_t;
52 typedef struct Namfun Namfun_t;
53 typedef struct Namdisc Namdisc_t;
54 typedef struct Nambfun Nambfun_t;
55 typedef struct Namarray Namarr_t;
56 typedef struct Nambltin Nambltin_t;
57 typedef struct Namtype Namtype_t;
58 
59 /*
60  * This defines the template for nodes that have their own assignment
61  * and or lookup functions
62  */
63 struct Namdisc
64 {
65 	size_t	dsize;
66 	void	(*putval) __PROTO__((Namval_t*, const char*, int, Namfun_t*));
67 	char	*(*getval) __PROTO__((Namval_t*, Namfun_t*));
68 	Sfdouble_t	(*getnum) __PROTO__((Namval_t*, Namfun_t*));
69 	char	*(*setdisc) __PROTO__((Namval_t*, const char*, Namval_t*, Namfun_t*));
70 	Namval_t *(*createf) __PROTO__((Namval_t*, const char*, int, Namfun_t*));
71 	Namfun_t *(*clonef) __PROTO__((Namval_t*, Namval_t*, int, Namfun_t*));
72 	char	*(*namef) __PROTO__((Namval_t*, Namfun_t*));
73 	Namval_t *(*nextf) __PROTO__((Namval_t*, Dt_t*, Namfun_t*));
74 	Namval_t *(*typef) __PROTO__((Namval_t*, Namfun_t*));
75 	int	(*readf) __PROTO__((Namval_t*, Sfio_t*, int, Namfun_t*));
76 };
77 
78 struct Namfun
79 {
80 	const Namdisc_t	*disc;
81 	char		nofree;
82 	char		funs;
83 	unsigned short	dsize;
84 	Namfun_t	*next;
85 	char		*last;
86 	Namval_t	*type;
87 };
88 
89 struct Nambfun
90 {
91 	Namfun_t        fun;
92 	int		num;
93 	const char	**bnames;
94 	Namval_t	*bltins[1];
95 };
96 
97 /* This is an array template header */
98 struct Namarray
99 {
100 	Namfun_t	hdr;
101 	long		nelem;				/* number of elements */
102 	__V_	*(*fun) __PROTO__((Namval_t*,const char*,int));	/* associative arrays */
103 	Namval_t	*parent;		/* for multi-dimensional */
104 };
105 
106 /* Passed as third argument to a builtin when  NV_BLTINOPT is set on node */
107 struct Nambltin
108 {
109         __V_		*shp;
110 	Namval_t	*np;
111         __V_	 	*ptr;
112         __V_		*data;
113         int		flags;
114 };
115 
116 struct Namtype
117 {
118         __V_		*shp;
119 	Namval_t	*np;
120 	const char	*optstring;
121 	__V_		*optinfof;
122 };
123 
124 /* attributes of name-value node attribute flags */
125 
126 #define NV_DEFAULT 0
127 /* This defines the attributes for an attributed name-value pair node */
128 struct Namval
129 {
130 	Dtlink_t	nvlink;		/* space for cdt links */
131 	char		*nvname;	/* pointer to name of the node */
132 	unsigned short	nvflag; 	/* attributes */
133 	unsigned short 	nvsize;		/* size or base */
134 #ifdef _NV_PRIVATE
135 	_NV_PRIVATE
136 #else
137 	Namfun_t	*nvfun;
138 	char		*nvalue;
139 	char		*nvprivate;
140 #endif /* _NV_PRIVATE */
141 };
142 
143 #define NV_CLASS	".sh.type"
144 #define NV_MINSZ	(sizeof(struct Namval)-sizeof(Dtlink_t)-sizeof(char*))
145 #define nv_namptr(p,n)	((Namval_t*)((char*)(p)+(n)*NV_MINSZ-sizeof(Dtlink_t)))
146 
147 /* The following attributes are for internal use */
148 #define NV_NOFREE	0x200	/* don't free the space when releasing value */
149 #define NV_ARRAY	0x400	/* node is an array */
150 #define NV_REF		0x4000	/* reference bit */
151 #define NV_TABLE	0x800	/* node is a dictionary table */
152 #define NV_IMPORT	0x1000	/* value imported from environment */
153 #define NV_MINIMAL	NV_IMPORT	/* node does not contain all fields */
154 
155 #define NV_INTEGER	0x2	/* integer attribute */
156 /* The following attributes are valid only when NV_INTEGER is off */
157 #define NV_LTOU		0x4	/* convert to uppercase */
158 #define NV_UTOL		0x8	/* convert to lowercase */
159 #define NV_ZFILL	0x10	/* right justify and fill with leading zeros */
160 #define NV_RJUST	0x20	/* right justify and blank fill */
161 #define NV_LJUST	0x40	/* left justify and blank fill */
162 #define NV_BINARY	0x100	/* fixed size data buffer */
163 #define NV_RAW		NV_LJUST	/* used only with NV_BINARY */
164 #define NV_HOST		(NV_RJUST|NV_LJUST)	/* map to host filename */
165 
166 /* The following attributes do not effect the value */
167 #define NV_RDONLY	0x1	/* readonly bit */
168 #define NV_EXPORT	0x2000	/* export bit */
169 #define NV_TAGGED	0x8000	/* user define tag bit */
170 
171 /* The following are used with NV_INTEGER */
172 #define NV_SHORT	(NV_RJUST)	/* when integers are not long */
173 #define NV_LONG		(NV_UTOL)	/* for long long and long double */
174 #define NV_UNSIGN	(NV_LTOU)	/* for unsigned quantities */
175 #define NV_DOUBLE	(NV_ZFILL)	/* for floating point */
176 #define NV_EXPNOTE	(NV_LJUST)	/* for scientific notation */
177 
178 /*  options for nv_open */
179 
180 #define NV_APPEND	0x10000		/* append value */
181 #define NV_MOVE		0x20000		/* for use with nv_clone */
182 #define NV_ADD		8
183 					/* add node if not found */
184 #define NV_ASSIGN	NV_NOFREE	/* assignment is possible */
185 #define NV_NOASSIGN	0		/* backward compatibility */
186 #define NV_NOARRAY	0x200000	/* array name not possible */
187 #define NV_IARRAY	0x400000	/* for indexed array */
188 #define NV_NOREF	NV_REF		/* don't follow reference */
189 #define NV_IDENT	0x80		/* name must be identifier */
190 #define NV_VARNAME	0x20000		/* name must be ?(.)id*(.id) */
191 #define NV_NOADD	0x40000		/* do not add node */
192 #define NV_NOSCOPE	0x80000		/* look only in current scope */
193 #define NV_NOFAIL	0x100000	/* return 0 on failure, no msg */
194 #define NV_NODISC	NV_IDENT	/* ignore disciplines */
195 
196 #define NV_FUNCT	NV_IDENT	/* option for nv_create */
197 #define NV_BLTINOPT	NV_ZFILL	/* save state for optimization*/
198 
199 #define NV_PUBLIC	(~(NV_NOSCOPE|NV_ASSIGN|NV_IDENT|NV_VARNAME|NV_NOADD))
200 
201 /* numeric types */
202 #define NV_INT16	(NV_SHORT|NV_INTEGER)
203 #define NV_UINT16	(NV_UNSIGN|NV_SHORT|NV_INTEGER)
204 #define NV_INT32	(NV_INTEGER)
205 #define NV_UNT32	(NV_UNSIGN|NV_INTEGER)
206 #define NV_INT64	(NV_LONG|NV_INTEGER)
207 #define NV_UINT64	(NV_UNSIGN|NV_LONG|NV_INTEGER)
208 #define NV_FLOAT	(NV_SHORT|NV_DOUBLE|NV_INTEGER)
209 #define NV_LDOUBLE	(NV_LONG|NV_DOUBLE|NV_INTEGER)
210 
211 /* name-value pair macros */
212 #define nv_isattr(np,f)		((np)->nvflag & (f))
213 #define nv_onattr(n,f)		((n)->nvflag |= (f))
214 #define nv_offattr(n,f)		((n)->nvflag &= ~(f))
215 #define nv_isarray(np)		(nv_isattr((np),NV_ARRAY))
216 
217 /* The following are operations for associative arrays */
218 #define NV_AINIT	1	/* initialize */
219 #define NV_AFREE	2	/* free array */
220 #define NV_ANEXT	3	/* advance to next subscript */
221 #define NV_ANAME	4	/* return subscript name */
222 #define NV_ADELETE	5	/* delete current subscript */
223 #define NV_AADD		6	/* add subscript if not found */
224 #define NV_ACURRENT	7	/* return current subscript Namval_t* */
225 
226 /* The following are for nv_disc */
227 #define NV_FIRST	1
228 #define NV_LAST		2
229 #define NV_POP		3
230 #define NV_CLONE	4
231 
232 /* The following are operations for nv_putsub() */
233 #define ARRAY_BITS	24
234 #define ARRAY_ADD	(1L<<ARRAY_BITS)	/* add subscript if not found */
235 #define	ARRAY_SCAN	(2L<<ARRAY_BITS)	/* For ${array[@]} */
236 #define ARRAY_UNDEF	(4L<<ARRAY_BITS)	/* For ${array} */
237 
238 
239 /* These  are disciplines provided by the library for use with nv_discfun */
240 #define NV_DCADD	0	/* used to add named disciplines */
241 #define NV_DCRESTRICT	1	/* variable that are restricted in rsh */
242 
243 #if defined(__EXPORT__) && defined(_DLL)
244 #   ifdef _BLD_shell
245 #undef __MANGLE__
246 #define __MANGLE__ __LINKAGE__ __EXPORT__
247 #   else
248 #undef __MANGLE__
249 #define __MANGLE__ __LINKAGE__ __IMPORT__
250 #   endif /* _BLD_shell */
251 #endif /* _DLL */
252 /* prototype for array interface*/
253 extern __MANGLE__ Namarr_t	*nv_setarray __PROTO__((Namval_t*,__V_*(*)(Namval_t*,const char*,int)));
254 extern __MANGLE__ __V_	*nv_associative __PROTO__((Namval_t*,const char*,int));
255 extern __MANGLE__ int	nv_aindex __PROTO__((Namval_t*));
256 extern __MANGLE__ int	nv_nextsub __PROTO__((Namval_t*));
257 extern __MANGLE__ char	*nv_getsub __PROTO__((Namval_t*));
258 extern __MANGLE__ Namval_t	*nv_putsub __PROTO__((Namval_t*, char*, long));
259 extern __MANGLE__ Namval_t	*nv_opensub __PROTO__((Namval_t*));
260 
261 /* name-value pair function prototypes */
262 extern __MANGLE__ int		nv_adddisc __PROTO__((Namval_t*, const char**, Namval_t**));
263 extern __MANGLE__ int		nv_clone __PROTO__((Namval_t*, Namval_t*, int));
264 extern __MANGLE__ void 		nv_close __PROTO__((Namval_t*));
265 extern __MANGLE__ __V_		*nv_context __PROTO__((Namval_t*));
266 extern __MANGLE__ Namval_t		*nv_create __PROTO__((const char*, Dt_t*, int,Namfun_t*));
267 extern __MANGLE__ Dt_t		*nv_dict __PROTO__((Namval_t*));
268 extern __MANGLE__ Sfdouble_t	nv_getn __PROTO__((Namval_t*, Namfun_t*));
269 extern __MANGLE__ Sfdouble_t	nv_getnum __PROTO__((Namval_t*));
270 extern __MANGLE__ char 		*nv_getv __PROTO__((Namval_t*, Namfun_t*));
271 extern __MANGLE__ char 		*nv_getval __PROTO__((Namval_t*));
272 extern __MANGLE__ Namfun_t		*nv_hasdisc __PROTO__((Namval_t*, const Namdisc_t*));
273 extern __MANGLE__ int		nv_isnull __PROTO__((Namval_t*));
274 extern __MANGLE__ Namval_t		*nv_lastdict __PROTO__((void));
275 extern __MANGLE__ void 		nv_newattr __PROTO__((Namval_t*,unsigned,int));
276 extern __MANGLE__ Namval_t		*nv_open __PROTO__((const char*,Dt_t*,int));
277 extern __MANGLE__ void 		nv_putval __PROTO__((Namval_t*,const char*,int));
278 extern __MANGLE__ void 		nv_putv __PROTO__((Namval_t*,const char*,int,Namfun_t*));
279 extern __MANGLE__ int		nv_scan __PROTO__((Dt_t*,void(*)(Namval_t*,__V_*),__V_*,int,int));
280 extern __MANGLE__ Namval_t		*nv_scoped __PROTO__((Namval_t*));
281 extern __MANGLE__ char 		*nv_setdisc __PROTO__((Namval_t*,const char*,Namval_t*,Namfun_t*));
282 extern __MANGLE__ void		nv_setref __PROTO__((Namval_t*, Dt_t*,int));
283 extern __MANGLE__ int		nv_settype __PROTO__((Namval_t*, Namval_t*, int));
284 extern __MANGLE__ void 		nv_setvec __PROTO__((Namval_t*,int,int,char*[]));
285 extern __MANGLE__ void		nv_setvtree __PROTO__((Namval_t*));
286 extern __MANGLE__ int 		nv_setsize __PROTO__((Namval_t*,int));
287 extern __MANGLE__ Namfun_t		*nv_disc __PROTO__((Namval_t*,Namfun_t*,int));
288 extern __MANGLE__ void 		nv_unset __PROTO__((Namval_t*));
289 extern __MANGLE__ Namval_t		*nv_search __PROTO__((const char *, Dt_t*, int));
290 extern __MANGLE__ void		nv_unscope __PROTO__((void));
291 extern __MANGLE__ char		*nv_name __PROTO__((Namval_t*));
292 extern __MANGLE__ Namval_t		*nv_type __PROTO__((Namval_t*));
293 extern __MANGLE__ const Namdisc_t	*nv_discfun __PROTO__((int));
294 
295 #ifdef _DLL
296 #undef __MANGLE__
297 #define __MANGLE__ __LINKAGE__
298 #endif /* _DLL */
299 
300 #define nv_size(np)		nv_setsize((np),-1)
301 #define nv_stack(np,nf)		nv_disc(np,nf,0)
302 
303 #if 0
304 /*
305  * The names of many functions were changed in early '95
306  * Here is a mapping to the old names
307  */
308 #   define nv_istype(np)	nv_isattr(np)
309 #   define nv_newtype(np)	nv_newattr(np)
310 #   define nv_namset(np,a,b)	nv_open(np,a,b)
311 #   define nv_free(np)		nv_unset(np)
312 #   define nv_settype(np,a,b,c)	nv_setdisc(np,a,b,c)
313 #   define nv_search(np,a,b)	nv_open(np,a,((b)?0:NV_NOADD))
314 #   define settype	setdisc
315 #endif
316 
317 #endif /* NV_DEFAULT */
318