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