xref: /titanic_50/usr/src/lib/libshell/amd64/include/ast/nval.h (revision 677fd05c3b05c78948501f6ffdced37dab9368fe)
1 
2 /* : : generated by proto : : */
3 /***********************************************************************
4 *                                                                      *
5 *               This software is part of the ast package               *
6 *          Copyright (c) 1982-2009 AT&T Intellectual Property          *
7 *                      and is licensed under the                       *
8 *                  Common Public License, Version 1.0                  *
9 *                    by AT&T Intellectual Property                     *
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 #include	<option.h>
44 
45 /* for compatibility with old hash library */
46 #define Hashtab_t	Dt_t
47 #define HASH_BUCKET	1
48 #define HASH_NOSCOPE	2
49 #define HASH_SCOPE	4
50 #define hashscope(x)	dtvnext(x)
51 
52 typedef struct Namval Namval_t;
53 typedef struct Namfun Namfun_t;
54 typedef struct Namdisc Namdisc_t;
55 typedef struct Nambfun Nambfun_t;
56 typedef struct Namarray Namarr_t;
57 typedef struct Namdecl Namdecl_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 	int	(*writef) __PROTO__((Namval_t*, Sfio_t*, int, Namfun_t*));
77 };
78 
79 struct Namfun
80 {
81 	const Namdisc_t	*disc;
82 	char		nofree;
83 	unsigned char	subshell;
84 	unsigned short	dsize;
85 	Namfun_t	*next;
86 	char		*last;
87 	Namval_t	*type;
88 };
89 
90 struct Nambfun
91 {
92 	Namfun_t        fun;
93 	int		num;
94 	const char	**bnames;
95 	Namval_t	*bltins[1];
96 };
97 
98 /* This is an array template header */
99 struct Namarray
100 {
101 	Namfun_t	hdr;
102 	long		nelem;				/* number of elements */
103 	__V_	*(*fun) __PROTO__((Namval_t*,const char*,int));	/* associative arrays */
104 	Namval_t	*parent;		/* for multi-dimensional */
105 	Dt_t		*table;			/* for subscripts */
106 	__V_		*scope;			/* non-zerp when scoped */
107 };
108 
109 /* The context pointer for declaration command */
110 struct Namdecl
111 {
112 	Namval_t	*tp;			/* point to type */
113 	const char	*optstring;
114 	__V_		*optinfof;
115 };
116 
117 /* attributes of name-value node attribute flags */
118 
119 #define NV_DEFAULT 0
120 /* This defines the attributes for an attributed name-value pair node */
121 struct Namval
122 {
123 	Dtlink_t	nvlink;		/* space for cdt links */
124 	char		*nvname;	/* pointer to name of the node */
125 	unsigned short	nvflag; 	/* attributes */
126 	unsigned short 	nvsize;		/* size or base */
127 #ifdef _NV_PRIVATE
128 	_NV_PRIVATE
129 #else
130 	Namfun_t	*nvfun;
131 	char		*nvalue;
132 	char		*nvprivate;
133 #endif /* _NV_PRIVATE */
134 };
135 
136 #define NV_CLASS	".sh.type"
137 #define NV_DATA		"_"	/* special class or instance variable */
138 #define NV_MINSZ	(sizeof(struct Namval)-sizeof(Dtlink_t)-sizeof(char*))
139 #define nv_namptr(p,n)	((Namval_t*)((char*)(p)+(n)*NV_MINSZ-sizeof(Dtlink_t)))
140 
141 /* The following attributes are for internal use */
142 #define NV_NOFREE	0x200	/* don't free the space when releasing value */
143 #define NV_ARRAY	0x400	/* node is an array */
144 #define NV_REF		0x4000	/* reference bit */
145 #define NV_TABLE	0x800	/* node is a dictionary table */
146 #define NV_IMPORT	0x1000	/* value imported from environment */
147 #define NV_MINIMAL	NV_IMPORT	/* node does not contain all fields */
148 
149 #define NV_INTEGER	0x2	/* integer attribute */
150 /* The following attributes are valid only when NV_INTEGER is off */
151 #define NV_LTOU		0x4	/* convert to uppercase */
152 #define NV_UTOL		0x8	/* convert to lowercase */
153 #define NV_ZFILL	0x10	/* right justify and fill with leading zeros */
154 #define NV_RJUST	0x20	/* right justify and blank fill */
155 #define NV_LJUST	0x40	/* left justify and blank fill */
156 #define NV_BINARY	0x100	/* fixed size data buffer */
157 #define NV_RAW		NV_LJUST	/* used only with NV_BINARY */
158 #define NV_HOST		(NV_RJUST|NV_LJUST)	/* map to host filename */
159 
160 /* The following attributes do not effect the value */
161 #define NV_RDONLY	0x1	/* readonly bit */
162 #define NV_EXPORT	0x2000	/* export bit */
163 #define NV_TAGGED	0x8000	/* user define tag bit */
164 
165 /* The following are used with NV_INTEGER */
166 #define NV_SHORT	(NV_RJUST)	/* when integers are not long */
167 #define NV_LONG		(NV_UTOL)	/* for long long and long double */
168 #define NV_UNSIGN	(NV_LTOU)	/* for unsigned quantities */
169 #define NV_DOUBLE	(NV_INTEGER|NV_ZFILL)	/* for floating point */
170 #define NV_EXPNOTE	(NV_LJUST)	/* for scientific notation */
171 #define NV_HEXFLOAT	(NV_LTOU)	/* for C99 base16 float notation */
172 
173 /*  options for nv_open */
174 
175 #define NV_APPEND	0x10000		/* append value */
176 #define NV_MOVE		0x8000000	/* for use with nv_clone */
177 #define NV_ADD		8
178 					/* add node if not found */
179 #define NV_ASSIGN	NV_NOFREE	/* assignment is possible */
180 #define NV_NOASSIGN	0		/* backward compatibility */
181 #define NV_NOARRAY	0x200000	/* array name not possible */
182 #define NV_IARRAY	0x400000	/* for indexed array */
183 #define NV_NOREF	NV_REF		/* don't follow reference */
184 #define NV_IDENT	0x80		/* name must be identifier */
185 #define NV_VARNAME	0x20000		/* name must be ?(.)id*(.id) */
186 #define NV_NOADD	0x40000		/* do not add node */
187 #define NV_NOSCOPE	0x80000		/* look only in current scope */
188 #define NV_NOFAIL	0x100000	/* return 0 on failure, no msg */
189 #define NV_NODISC	NV_IDENT	/* ignore disciplines */
190 
191 #define NV_FUNCT	NV_IDENT	/* option for nv_create */
192 #define NV_BLTINOPT	NV_ZFILL	/* mark builtins in libcmd */
193 
194 #define NV_PUBLIC	(~(NV_NOSCOPE|NV_ASSIGN|NV_IDENT|NV_VARNAME|NV_NOADD))
195 
196 /* numeric types */
197 #define NV_INT16P	(NV_LJUST|NV_SHORT|NV_INTEGER)
198 #define NV_INT16	(NV_SHORT|NV_INTEGER)
199 #define NV_UINT16	(NV_UNSIGN|NV_SHORT|NV_INTEGER)
200 #define NV_UINT16P	(NV_LJUSTNV_UNSIGN|NV_SHORT|NV_INTEGER)
201 #define NV_INT32	(NV_INTEGER)
202 #define NV_UNT32	(NV_UNSIGN|NV_INTEGER)
203 #define NV_INT64	(NV_LONG|NV_INTEGER)
204 #define NV_UINT64	(NV_UNSIGN|NV_LONG|NV_INTEGER)
205 #define NV_FLOAT	(NV_SHORT|NV_DOUBLE)
206 #define NV_LDOUBLE	(NV_LONG|NV_DOUBLE)
207 
208 /* name-value pair macros */
209 #define nv_isattr(np,f)		((np)->nvflag & (f))
210 #define nv_onattr(n,f)		((n)->nvflag |= (f))
211 #define nv_offattr(n,f)		((n)->nvflag &= ~(f))
212 #define nv_isarray(np)		(nv_isattr((np),NV_ARRAY))
213 
214 /* The following are operations for associative arrays */
215 #define NV_AINIT	1	/* initialize */
216 #define NV_AFREE	2	/* free array */
217 #define NV_ANEXT	3	/* advance to next subscript */
218 #define NV_ANAME	4	/* return subscript name */
219 #define NV_ADELETE	5	/* delete current subscript */
220 #define NV_AADD		6	/* add subscript if not found */
221 #define NV_ACURRENT	7	/* return current subscript Namval_t* */
222 #define NV_ASETSUB	8	/* set current subscript */
223 
224 /* The following are for nv_disc */
225 #define NV_FIRST	1
226 #define NV_LAST		2
227 #define NV_POP		3
228 #define NV_CLONE	4
229 
230 /* The following are operations for nv_putsub() */
231 #define ARRAY_BITS	22
232 #define ARRAY_ADD	(1L<<ARRAY_BITS)	/* add subscript if not found */
233 #define	ARRAY_SCAN	(2L<<ARRAY_BITS)	/* For ${array[@]} */
234 #define ARRAY_UNDEF	(4L<<ARRAY_BITS)	/* For ${array} */
235 
236 
237 /* These  are disciplines provided by the library for use with nv_discfun */
238 #define NV_DCADD	0	/* used to add named disciplines */
239 #define NV_DCRESTRICT	1	/* variable that are restricted in rsh */
240 
241 #if defined(__EXPORT__) && defined(_DLL)
242 #   ifdef _BLD_shell
243 #undef __MANGLE__
244 #define __MANGLE__ __LINKAGE__ __EXPORT__
245 #   else
246 #undef __MANGLE__
247 #define __MANGLE__ __LINKAGE__ __IMPORT__
248 #   endif /* _BLD_shell */
249 #endif /* _DLL */
250 /* prototype for array interface*/
251 extern __MANGLE__ Namarr_t	*nv_arrayptr __PROTO__((Namval_t*));
252 extern __MANGLE__ Namarr_t	*nv_setarray __PROTO__((Namval_t*,__V_*(*)(Namval_t*,const char*,int)));
253 extern __MANGLE__ int	nv_arraynsub __PROTO__((Namarr_t*));
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__ void		nv_delete __PROTO__((Namval_t*, Dt_t*, int));
268 extern __MANGLE__ Dt_t		*nv_dict __PROTO__((Namval_t*));
269 extern __MANGLE__ Sfdouble_t	nv_getn __PROTO__((Namval_t*, Namfun_t*));
270 extern __MANGLE__ Sfdouble_t	nv_getnum __PROTO__((Namval_t*));
271 extern __MANGLE__ char 		*nv_getv __PROTO__((Namval_t*, Namfun_t*));
272 extern __MANGLE__ char 		*nv_getval __PROTO__((Namval_t*));
273 extern __MANGLE__ Namfun_t		*nv_hasdisc __PROTO__((Namval_t*, const Namdisc_t*));
274 extern __MANGLE__ int		nv_isnull __PROTO__((Namval_t*));
275 extern __MANGLE__ Namfun_t		*nv_isvtree __PROTO__((Namval_t*));
276 extern __MANGLE__ Namval_t		*nv_lastdict __PROTO__((void));
277 extern __MANGLE__ Namval_t		*nv_mkinttype __PROTO__((char*, size_t, int, const char*, Namdisc_t*));
278 extern __MANGLE__ void 		nv_newattr __PROTO__((Namval_t*,unsigned,int));
279 extern __MANGLE__ void 		nv_newtype __PROTO__((Namval_t*));
280 extern __MANGLE__ Namval_t		*nv_open __PROTO__((const char*,Dt_t*,int));
281 extern __MANGLE__ void 		nv_putval __PROTO__((Namval_t*,const char*,int));
282 extern __MANGLE__ void 		nv_putv __PROTO__((Namval_t*,const char*,int,Namfun_t*));
283 extern __MANGLE__ int		nv_rename __PROTO__((Namval_t*,int));
284 extern __MANGLE__ int		nv_scan __PROTO__((Dt_t*,void(*)(Namval_t*,__V_*),__V_*,int,int));
285 extern __MANGLE__ char 		*nv_setdisc __PROTO__((Namval_t*,const char*,Namval_t*,Namfun_t*));
286 extern __MANGLE__ void		nv_setref __PROTO__((Namval_t*, Dt_t*,int));
287 extern __MANGLE__ int		nv_settype __PROTO__((Namval_t*, Namval_t*, int));
288 extern __MANGLE__ void 		nv_setvec __PROTO__((Namval_t*,int,int,char*[]));
289 extern __MANGLE__ void		nv_setvtree __PROTO__((Namval_t*));
290 extern __MANGLE__ int 		nv_setsize __PROTO__((Namval_t*,int));
291 extern __MANGLE__ Namfun_t		*nv_disc __PROTO__((Namval_t*,Namfun_t*,int));
292 extern __MANGLE__ void 		nv_unset __PROTO__((Namval_t*));	 /*obsolete */
293 extern __MANGLE__ void 		_nv_unset __PROTO__((Namval_t*,int));
294 extern __MANGLE__ Namval_t		*nv_search __PROTO__((const char *, Dt_t*, int));
295 extern __MANGLE__ char		*nv_name __PROTO__((Namval_t*));
296 extern __MANGLE__ Namval_t		*nv_type __PROTO__((Namval_t*));
297 extern __MANGLE__ void		nv_addtype __PROTO__((Namval_t*,const char*, Optdisc_t*, size_t));
298 extern __MANGLE__ const Namdisc_t	*nv_discfun __PROTO__((int));
299 
300 #ifdef _DLL
301 #undef __MANGLE__
302 #define __MANGLE__ __LINKAGE__
303 #endif /* _DLL */
304 
305 #define nv_unset(np)		_nv_unset(np,0)
306 #define nv_size(np)		nv_setsize((np),-1)
307 #define nv_stack(np,nf)		nv_disc(np,nf,0)
308 
309 #if 0
310 /*
311  * The names of many functions were changed in early '95
312  * Here is a mapping to the old names
313  */
314 #   define nv_istype(np)	nv_isattr(np)
315 #   define nv_newtype(np)	nv_newattr(np)
316 #   define nv_namset(np,a,b)	nv_open(np,a,b)
317 #   define nv_free(np)		nv_unset(np,0)
318 #   define nv_settype(np,a,b,c)	nv_setdisc(np,a,b,c)
319 #   define nv_search(np,a,b)	nv_open(np,a,((b)?0:NV_NOADD))
320 #   define settype	setdisc
321 #endif
322 
323 #endif /* NV_DEFAULT */
324