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