2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
6 * These libraries and programs are free software; you can
7 * redistribute them and/or modify them under the terms of the GNU
8 * Lesser General Public License as published by the Free Software
9 * Foundation; either version 2 of the License, or (at your option)
12 * These libraries and programs are distributed in the hope that
13 * they will be useful, but WITHOUT ANY WARRANTY; without even the
14 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU Lesser General Public License for more
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with these librararies and programs; if not, write
20 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21 * Floor, Boston, MA 02110-1301 USA
23 /* $XConsortium: nval.h /main/3 1995/11/01 16:41:55 rswiston $ */
24 /***************************************************************
26 * AT&T - PROPRIETARY *
28 * THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF *
29 * AT&T BELL LABORATORIES *
30 * AND IS NOT TO BE DISCLOSED OR USED EXCEPT IN *
31 * ACCORDANCE WITH APPLICABLE AGREEMENTS *
33 * Copyright (c) 1995 AT&T Corp. *
34 * Unpublished & Not for Publication *
35 * All Rights Reserved *
37 * The copyright notice above does not evidence any *
38 * actual or intended publication of such source code *
40 * This software was created by the *
41 * Advanced Software Technology Department *
42 * AT&T Bell Laboratories *
44 * For further information contact *
45 * {research,attmail}!dgk *
47 ***************************************************************/
49 /* : : generated by proto : : */
52 #if !defined(__PROTO__)
53 #if defined(__STDC__) || defined(__cplusplus) || defined(_proto) || defined(c_plusplus)
54 #if defined(__cplusplus)
55 #define __MANGLE__ "C"
60 #define __PROTO__(x) x
62 #define __PARAM__(n,o) n
63 #if !defined(__STDC__) && !defined(__cplusplus)
64 #if !defined(c_plusplus)
75 #define __PROTO__(x) ()
76 #define __OTORP__(x) x
77 #define __PARAM__(n,o) o
85 #if defined(__cplusplus) || defined(c_plusplus)
86 #define __VARARG__ ...
90 #if defined(__STDARG__)
91 #define __VA_START__(p,a) va_start(p,a)
93 #define __VA_START__(p,a) va_start(p)
99 * AT&T Bell Laboratories
101 * Interface definitions of structures for name-value pairs
102 * These structures are used for named variables, functions and aliases
110 typedef struct Namval Namval_t;
111 typedef struct Namfun Namfun_t;
112 typedef struct Namdisc Namdisc_t;
113 typedef struct Namarray Namarr_t;
115 * This defines the template for nodes that have their own assignment
116 * and or lookup functions
121 void (*putval) __PROTO__((Namval_t*, const char*, int, Namfun_t*));
122 char *(*getval) __PROTO__((Namval_t*, Namfun_t*));
123 double (*getnum) __PROTO__((Namval_t*, Namfun_t*));
124 char *(*setdisc) __PROTO__((Namval_t*, const char*, Namval_t*, Namfun_t*));
125 Namval_t *(*create) __PROTO__((Namval_t*, const char*, Namfun_t*));
126 char *(*name) __PROTO__((Namval_t*, Namfun_t*));
127 int (*scope) __PROTO__((Namval_t*, Namval_t*, int, Namfun_t*));
132 const Namdisc_t *disc;
136 /* This is an array template header */
139 long nelem; /* number of elements */
140 __V_ *(*fun) __PROTO__((Namval_t*,const char*,int)); /* associative arrays */
143 /* attributes of name-value node attribute flags */
146 /* This defines the attributes for an attributed name-value pair node */
149 HASH_HEADER; /* space for hash library */
150 unsigned short nvflag; /* attributes */
151 short nvsize; /* size of item */
154 #else /* hopefully these will become private soon */
156 char *nvenv; /* pointer to environment name */
157 Namfun_t *nvfun; /* pointer to trap disciplines */
158 #endif /* _NV_PRIVATE */
159 char *nvdtenv; /* dtksh-specific environment name */
162 /* The following attributes are for internal use */
163 #define NV_NOALLOC 0x100 /* don't allocate space for the value */
164 #define NV_NOFREE 0x200 /* don't free the space when releasing value */
165 #define NV_ARRAY 0x400 /* node is an array */
167 #define NV_INTEGER 0x2 /* integer attribute */
168 /* The following attributes are valid only when NV_INTEGER is off */
169 #define NV_LTOU 0x4 /* convert to uppercase */
170 #define NV_UTOL 0x8 /* convert to lowercase */
171 #define NV_ZFILL 0x10 /* right justify and fill with leading zeros */
172 #define NV_RJUST 0x20 /* right justify and blank fill */
173 #define NV_LJUST 0x40 /* left justify and blank fill */
175 /* The following attributes do not effect the value */
176 #define NV_RDONLY 0x1 /* readonly bit */
177 #define NV_EXPORT 0x2000 /* export bit */
178 #define NV_REF 0x4000 /* reference bit */
179 #define NV_TAGGED 0x8000 /* user define tag bit */
181 /* The following are used with NV_INTEGER */
182 #define NV_SHORT (NV_LTOU) /* when integers are not long */
183 #define NV_UNSIGN (NV_UTOL) /* for unsigned quantities */
184 #define NV_DOUBLE (NV_ZFILL) /* for floating point */
185 #define NV_EXPNOTE (NV_LTOU) /* for scientific notation */
186 #define NV_CPOINTER (NV_RJUST) /* for pointer */
189 /* options for nv_open */
192 # define NV_ADD (HASH_CREATE|HASH_SIZE((long)sizeof(Namval_t)))
194 # define NV_ADD (HASH_CREATE|HASH_SIZE((long)sizeof(Namval_t))+2*sizeof(char*))
195 #endif /* _NV_PRIVATE */
196 /* add node if not found */
197 #define NV_NOSCOPE NV_NOALLOC /* look only in current scope */
198 #define NV_ASSIGN NV_NOFREE /* assignment is possible */
199 #define NV_NOASSIGN 0 /* backward compatibility */
200 #define NV_NOARRAY NV_ARRAY /* array name not possible */
201 #define NV_NOREF NV_REF /* don't follow reference */
202 #define NV_IDENT 0x80 /* name must be identifier */
203 #define NV_VARNAME 0x800 /* name must be ?(.)id*(.id) */
204 #define NV_NOADD 0x1000 /* do not add node */
206 #define NV_PUBLIC (~(NV_NOSCOPE|NV_ASSIGN|NV_IDENT|NV_VARNAME|NV_NOADD))
208 /* name-value pair macros */
209 #define nv_isattr(np,f) ((np)->nvflag & (f))
211 # define nv_isnull(np) (!(np)->nvalue.cp && !(np)->nvfun) /* strings only */
213 # define nv_isnull(np) (!(np)->nvalue && !(np)->nvfun) /* strings only */
214 #endif /* _NV_PRIVATE */
215 #define nv_name(np) hashname((Hashbin_t*)(np))
216 #define nv_size(np) ((np)->nvsize&0xfff)
217 #define nv_unscope() (sh.var_tree = hashfree(sh.var_tree))
218 #define nv_search(name,root,mode) ((Namval_t*)hashlook((Hashtab_t*)(root),name,(mode)^HASH_SCOPE,(char*)0))
220 # define nv_class(np) (nv_isattr(np,NV_IMPORT)?0:(Namval_t*)((np)->nvenv))
221 #endif /* SHOPT_OO */
223 /* The following are operations for associative arrays */
224 #define NV_AINIT 1 /* initialize */
225 #define NV_AFREE 2 /* free array */
226 #define NV_ANEXT 3 /* advance to next subscript */
227 #define NV_ANAME 4 /* return subscript name */
228 #define NV_ADELETE 5 /* delete current subscript */
229 #define NV_AADD 6 /* add subscript if not found */
231 /* The following are operations for nv_putsub() */
232 #define ARRAY_BITS 16
233 #define ARRAY_ADD (1L<<ARRAY_BITS) /* add subscript if not found */
234 #define ARRAY_SCAN (2L<<ARRAY_BITS) /* For ${array[@]} */
235 #define ARRAY_UNDEF (4L<<ARRAY_BITS) /* For ${array} */
237 /* prototype for array interface*/
238 extern __MANGLE__ Namarr_t *nv_setarray __PROTO__((Namval_t*,__V_*(*)(Namval_t*,const char*,int)));
239 extern __MANGLE__ __V_ *nv_associative __PROTO__((Namval_t*,const char*,int));
240 extern __MANGLE__ int nv_aindex __PROTO__((Namval_t*));
241 extern __MANGLE__ int nv_nextsub __PROTO__((Namval_t*));
242 extern __MANGLE__ char *nv_getsub __PROTO__((Namval_t*));
243 extern __MANGLE__ Namval_t *nv_putsub __PROTO__((Namval_t*, char*, long));
245 /* name-value pair function prototypes */
246 extern __MANGLE__ void nv_close __PROTO__((Namval_t*));
247 extern __MANGLE__ Namval_t *nv_create __PROTO__((Namval_t*,const char*,Namfun_t*));
248 extern __MANGLE__ double nv_getn __PROTO__((Namval_t*, Namfun_t*));
249 extern __MANGLE__ double nv_getnum __PROTO__((Namval_t*));
250 extern __MANGLE__ Hashtab_t *nv_getscope __PROTO__((int));
251 extern __MANGLE__ char *nv_getv __PROTO__((Namval_t*, Namfun_t*));
252 extern __MANGLE__ char *nv_getval __PROTO__((Namval_t*));
253 extern __MANGLE__ void nv_newattr __PROTO__((Namval_t*,unsigned,int));
254 extern __MANGLE__ Namval_t *nv_open __PROTO__((const char*,Hashtab_t*,int));
255 extern __MANGLE__ void nv_putval __PROTO__((Namval_t*,const char*,int));
256 extern __MANGLE__ void nv_putv __PROTO__((Namval_t*,const char*,int,Namfun_t*));
257 extern __MANGLE__ int nv_scan __PROTO__((Hashtab_t*,void(*)(Namval_t*),int,int));
258 extern __MANGLE__ Namval_t *nv_scoped __PROTO__((Namval_t*));
259 extern __MANGLE__ char *nv_setdisc __PROTO__((Namval_t*,const char*,Namval_t*,Namfun_t*));
260 extern __MANGLE__ void nv_setref __PROTO__((Namval_t*));
261 extern __MANGLE__ void nv_setvec __PROTO__((Namval_t*,int,char*[]));
262 extern __MANGLE__ void nv_setvtree __PROTO__((Namval_t*));
263 extern __MANGLE__ Namfun_t *nv_stack __PROTO__((Namval_t*,Namfun_t*));
264 extern __MANGLE__ void nv_unset __PROTO__((Namval_t*));
268 * The names of many functions were changed in early '95
269 * Here is a mapping to the old names
271 # define nv_istype(np) nv_isattr(np)
272 # define nv_newtype(np) nv_newattr(np)
273 # define nv_namset(np,a,b) nv_open(np,a,b)
274 # define nv_free(np) nv_unset(np)
275 # define nv_settype(np,a,b,c) nv_setdisc(np,a,b,c)
276 # define nv_search(np,a,b) nv_open(np,a,((b)?0:NV_NOADD))
277 # define settype setdisc
280 #endif /* NV_DEFAULT */