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