1 /***********************************************************************
3 * This software is part of the ast package *
4 * Copyright (c) 1982-2010 AT&T Intellectual Property *
5 * and is licensed under the *
6 * Common Public License, Version 1.0 *
7 * by AT&T Intellectual Property *
9 * A copy of the License is available at *
10 * http://www.opensource.org/licenses/cpl1.0.txt *
11 * (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) *
13 * Information and Software Systems Research *
17 * David Korn <dgk@research.att.com> *
19 ***********************************************************************/
23 * This is the implementation header file for name-value pairs
27 Namfun_t *nvfun; /* pointer to trap functions */ \
28 union Value nvalue; /* value field */ \
29 char *nvenv; /* pointer to environment name */
35 /* Nodes can have all kinds of values */
44 Sflong_t
*llp
; /* for long long arithmetic */
47 double *dp
; /* for floating point arithmetic */
48 Sfdouble_t
*ldp
; /* for long floating point arithmetic */
49 struct Namarray
*array
; /* for array node */
50 struct Namval
*np
; /* for Namval_t node */
51 union Value
*up
; /* for indirect node */
52 struct Ufunction
*rp
; /* shell user defined functions */
53 struct Namfun
*funp
; /* discipline pointer */
54 struct Namref
*nrp
; /* name reference */
55 int (*bfp
)(int,char*[],void*);/* builtin entry point function pointer */
62 #define ARRAY_MAX (1L<<ARRAY_BITS) /* maximum number of elements in an array */
63 #define ARRAY_MASK (ARRAY_MAX-1) /* For index values */
65 #define ARRAY_INCR 32 /* number of elements to grow when array
66 bound exceeded. Must be a power of 2 */
67 #define ARRAY_FILL (8L<<ARRAY_BITS) /* used with nv_putsub() */
68 #define ARRAY_NOCLONE (16L<<ARRAY_BITS) /* do not clone array disc */
69 #define ARRAY_NOCHILD (32L<<ARRAY_BITS) /* skip compound arrays */
70 #define ARRAY_SETSUB (64L<<ARRAY_BITS) /* set subscript */
71 #define ARRAY_NOSCOPE (128L<<ARRAY_BITS) /* top level scope only */
72 #define ARRAY_TREE (256L<<ARRAY_BITS) /* arrays of compound vars */
73 #define NV_ASETSUB 8 /* set subscript */
75 /* These flags are used as options to array_get() */
76 #define ARRAY_ASSIGN 0
77 #define ARRAY_LOOKUP 1
78 #define ARRAY_DELETE 2
89 /* This describes a user shell function node */
92 int *ptree
; /* address of parse tree */
93 int lineno
; /* line number of function start */
94 off_t hoffset
; /* offset into source or history file */
95 Namval_t
*nspace
; /* pointer to name space */
96 char *fname
; /* file name where function defined */
97 char *help
; /* help string */
98 Dt_t
*sdict
; /* dictionary for statics */
99 Dt_t
*fdict
; /* dictionary node belongs to */
100 Namval_t
*np
; /* function node pointer */
105 #endif /* !ARG_RAW */
107 /* attributes of Namval_t items */
109 /* The following attributes are for internal use */
110 #define NV_NOCHANGE (NV_EXPORT|NV_IMPORT|NV_RDONLY|NV_TAGGED|NV_NOFREE|NV_ARRAY)
111 #define NV_ATTRIBUTES (~(NV_NOSCOPE|NV_ARRAY|NV_NOARRAY|NV_IDENT|NV_ASSIGN|NV_REF|NV_VARNAME|NV_STATIC))
112 #define NV_PARAM NV_NODISC /* expansion use positional params */
114 /* This following are for use with nodes which are not name-values */
115 #define NV_TYPE 0x1000000
116 #define NV_STATIC 0x2000000
117 #define NV_COMVAR 0x4000000
118 #define NV_UNJUST 0x8000000 /* clear justify attributes */
119 #define NV_FUNCTION (NV_RJUST|NV_FUNCT) /* value is shell function */
120 #define NV_FPOSIX NV_LJUST /* posix function semantics */
121 #define NV_FTMP NV_ZFILL /* function source in tmpfile */
123 #define NV_NOPRINT (NV_LTOU|NV_UTOL) /* do not print */
124 #define NV_NOALIAS (NV_NOPRINT|NV_IMPORT)
125 #define NV_NOEXPAND NV_RJUST /* do not expand alias */
126 #define NV_BLTIN (NV_NOPRINT|NV_EXPORT)
127 #define BLT_ENV (NV_RDONLY) /* non-stoppable,
128 * can modify enviornment */
129 #define BLT_SPC (NV_LJUST) /* special built-ins */
130 #define BLT_EXIT (NV_RJUST) /* exit value can be > 255 */
131 #define BLT_DCL (NV_TAGGED) /* declaration command */
132 #define BLT_NOSFIO (NV_IMPORT) /* doesn't use sfio */
133 #define NV_OPTGET (NV_BINARY) /* function calls getopts */
134 #define nv_isref(n) (nv_isattr((n),NV_REF|NV_TAGGED|NV_FUNCT)==NV_REF)
135 #define nv_istable(n) (nv_isattr((n),NV_TABLE|NV_LJUST|NV_RJUST|NV_INTEGER)==NV_TABLE)
136 #define is_abuiltin(n) (nv_isattr(n,NV_BLTIN|NV_INTEGER)==NV_BLTIN)
137 #define is_afunction(n) (nv_isattr(n,NV_FUNCTION|NV_REF)==NV_FUNCTION)
138 #define nv_funtree(n) ((n)->nvalue.rp->ptree)
139 #define funptr(n) ((n)->nvalue.bfp)
141 #define NV_SUBQUOTE (NV_ADD<<1) /* used with nv_endsubscript */
144 /* ... for attributes */
146 #define nv_setattr(n,f) ((n)->nvflag = (f))
147 #define nv_context(n) ((void*)(n)->nvfun) /* for builtins */
148 /* The following are for name references */
149 #define nv_refnode(n) ((n)->nvalue.nrp->np)
150 #define nv_reftree(n) ((n)->nvalue.nrp->root)
151 #define nv_reftable(n) ((n)->nvalue.nrp->table)
152 #define nv_refsub(n) ((n)->nvalue.nrp->sub)
156 #define nv_setsize(n,s) ((n)->nvsize = (s))
158 #define nv_size(np) ((np)->nvsize)
159 #define _nv_hasget(np) ((np)->nvfun && (np)->nvfun->disc && nv_hasget(np))
160 #define nv_isnull(np) (!(np)->nvalue.cp && (nv_isattr(np,NV_SHORT|NV_INTEGER)!=(NV_SHORT|NV_INTEGER)) && !_nv_hasget(np))
164 #define array_elem(ap) ((ap)->nelem&ARRAY_MASK)
165 #define array_assoc(ap) ((ap)->fun)
167 extern int array_maxindex(Namval_t
*);
168 extern char *nv_endsubscript(Namval_t
*, char*, int);
169 extern Namfun_t
*nv_cover(Namval_t
*);
170 extern Namarr_t
*nv_arrayptr(Namval_t
*);
171 extern int nv_arrayisset(Namval_t
*, Namarr_t
*);
172 extern int nv_arraysettype(Namval_t
*, Namval_t
*,const char*,int);
173 extern int nv_aimax(Namval_t
*);
174 extern int nv_atypeindex(Namval_t
*, const char*);
175 extern int nv_setnotify(Namval_t
*,char **);
176 extern int nv_unsetnotify(Namval_t
*,char **);
177 extern void nv_setlist(struct argnod
*, int, Namval_t
*);
178 extern struct argnod
* nv_onlist(struct argnod
*, const char*);
179 extern void nv_optimize(Namval_t
*);
180 extern void nv_outname(Sfio_t
*,char*, int);
181 extern void nv_unref(Namval_t
*);
182 extern void _nv_unset(Namval_t
*,int);
183 extern int nv_hasget(Namval_t
*);
184 extern int nv_clone(Namval_t
*, Namval_t
*, int);
185 void clone_all_disc(Namval_t
*, Namval_t
*, int);
186 extern Namfun_t
*nv_clone_disc(Namfun_t
*, int);
187 extern void *nv_diropen(Namval_t
*, const char*);
188 extern char *nv_dirnext(void*);
189 extern void nv_dirclose(void*);
190 extern char *nv_getvtree(Namval_t
*, Namfun_t
*);
191 extern void nv_attribute(Namval_t
*, Sfio_t
*, char*, int);
192 extern Namval_t
*nv_bfsearch(const char*, Dt_t
*, Namval_t
**, char**);
193 extern Namval_t
*nv_mkclone(Namval_t
*);
194 extern Namval_t
*nv_mktype(Namval_t
**, int);
195 extern Namval_t
*nv_addnode(Namval_t
*, int);
196 extern Namval_t
*nv_parent(Namval_t
*);
197 extern char *nv_getbuf(size_t);
198 extern Namval_t
*nv_mount(Namval_t
*, const char *name
, Dt_t
*);
199 extern Namval_t
*nv_arraychild(Namval_t
*, Namval_t
*, int);
200 extern int nv_compare(Dt_t
*, Void_t
*, Void_t
*, Dtdisc_t
*);
201 extern void nv_outnode(Namval_t
*,Sfio_t
*, int, int);
202 extern int nv_subsaved(Namval_t
*);
203 extern void nv_typename(Namval_t
*, Sfio_t
*);
204 extern void nv_newtype(Namval_t
*);
206 extern const Namdisc_t RESTRICTED_disc
;
207 extern const Namdisc_t ENUM_disc
;
208 extern char nv_local
;
209 extern Dtdisc_t _Nvdisc
;
210 extern const char *nv_discnames
[];
211 extern const char e_subscript
[];
212 extern const char e_nullset
[];
213 extern const char e_notset
[];
214 extern const char e_noparent
[];
215 extern const char e_notelem
[];
216 extern const char e_readonly
[];
217 extern const char e_badfield
[];
218 extern const char e_restricted
[];
219 extern const char e_ident
[];
220 extern const char e_varname
[];
221 extern const char e_noalias
[];
222 extern const char e_noarray
[];
223 extern const char e_notenum
[];
224 extern const char e_aliname
[];
225 extern const char e_badexport
[];
226 extern const char e_badref
[];
227 extern const char e_badsubscript
[];
228 extern const char e_noref
[];
229 extern const char e_selfref
[];
230 extern const char e_envmarker
[];
231 extern const char e_badlocale
[];
232 extern const char e_loop
[];
233 extern const char e_redef
[];
234 extern const char e_required
[];
235 extern const char e_badappend
[];
236 extern const char e_unknowntype
[];
237 extern const char e_globalref
[];
238 #endif /* _NV_PRIVATE */