Home | History | Annotate | Download | only in common
      1 .fp 5 CW
      2 .TH NVAL 3 "12 Feb 2003"
      3 .PP
      4 .SH NAME
      5 .PP
      6 \fBnval\fR \- the \f5ksh\fP name/value library 
      7 .PP
      8 .SH SYNOPSIS
      9 .ta .8i 1.6i 2.4i 3.2i 4.0i
     10 .SS "HEADERS/LIBRARIES"
     11 .nf
     12 .ft 5
     13 #include	<nval.h>
     14 libshell.a	-lshell
     15 .ft R
     16 .fi
     17 .SS "DATA TYPES"
     18 .nf
     19 .ft 5
     20 Namval_t;
     21 Namfun_t;
     22 Namarr_t;
     23 Namdisc_t;
     24 .ft R
     25 .fi
     26 .SS "OPENING/CLOSING"
     27 .nf
     28 .ft 5
     29 Namval_t 	*nv_open(const char *\fIname\fP, Dt_t *\fIdict\fP, int \fIflags\fP);
     30 Namval_t	*nv_create(const char *\fIname\fP,  Dt_t *\fIdict\fP, int \fIflags\fP, Namfun_t *\fIfp\fP);
     31 Namval_t	*nv_namptr(void *\fIptr\fP, int \fIindx\fP); 
     32 void	nv_close(Namval_t *\fInp\fP);
     33 void	nv_delete(Namval_t *\fInp\fP, Dt_t *\fIdict\fP, int \fInofree\fP);
     34 .ft R
     35 .fi
     36 .SS "GETTING AND SETTING VALUES"
     37 .nf
     38 .ft 5
     39 char	*nv_getval(Namval_t *\fInp\fP);
     40 Sfdouble_t	nv_getnum(Namval_t *\fInp\fP);
     41 char	*nv_name(Namval_t *\fInp\fP);
     42 void	nv_putval(Namval_t *\fInp\fP, const char *\fIval\fP, int \fIflags\fP);
     43 void	nv_unset(Namval_t *\fInp\fP, int \fIflags\fP);
     44 int	nv_clone(Namval_t *\fIsrc\fP, Namval_t *\fIdest\fP, int \fIflags\fP);
     45 .ft R
     46 .fi
     47 .SS "ATTRIBUTES AND SIZE"
     48 .nf
     49 .ft 5
     50 int	nv_isnull(Namval_t *\fInp\fP);
     51 int	nv_setsize(Namval_t *\fInp\fP, int \fIsize\fP);
     52 int	nv_size(Namval_t *\fInp\fP);
     53 unsigned nv_isattr(Namval_t *\fInp\fP, unsigned \fIflags\fP);
     54 Namfun_t	*nv_isvtree(Namval_t *\fInp\fP);
     55 unsigned nv_onattr(Namval_t *\fInp\fP, unsigned \fIflags\fP);
     56 unsigned nv_offattr(Namval_t *\fInp\fP, unsigned \fIflags\fP);
     57 void	nv_newattr(Namval_t *\fInp\fP, unsigned \fIflags\fP, int \fIsize\fP);
     58 .ft R
     59 .fi
     60 
     61 .SS "ARRAY HANDLING"
     62 .nf
     63 .ft 5
     64 unsigned nv_isarray(Namval_t *\fInp\fP);
     65 Namarr_t	*nv_setarray(Namval_t *\fInp\fP,void*(*\fIfun\fP)(Namval_t*,const char*,int));
     66 Namarr_t	*nv_arrayptr(Namval_t *\fInp\fP);
     67 Namval_t	*nv_putsub(Namval_t *\fInp\fP, char *\fIname\fP, long \fImode\fP);
     68 Namval_t	*nv_opensub(Namval_t *\fInp\fP);
     69 void	nv_setvec(Namval_t *\fInp\fP, int \fIappend\fP, int \fIargc\fP, char *\fIargv\fP[]);
     70 char	*nv_getsub(Namval_t *\fInp\fP);
     71 int	nv_nextsub(Namval_t *\fInp\fP);
     72 int	nv_aindex(Namval_t *\fInp\fP);
     73 .ft R
     74 .fi
     75 .SS "DISCIPLINES"
     76 .nf
     77 .ft 5
     78 Namfun_t	*nv_disc(Namval_t *\fInp\fP, Namfun_t *\fIfp\fP, int \fIflags\fP);
     79 Namfun_t	*nv_hasdisc(Namval_t *\fInp\fP, const Namdisc_t *\fIdp\fP);
     80 char	*nv_getv(Namval_t *\fInp\fP, Namfun_t *\fIfp\fP);
     81 Sfdouble_t	nv_getn(Namval_t *\fInp\fP, Namfun_t *\fIfp\fP);
     82 void	nv_putv(Namval_t *\fInp\fP, const char *\fIval\fP, int \fIflags\fP, Namfun_t *\fIfp\fP);
     83 char	*nv_setdisc(Namval_t *\fInp\fP, const char *\fIa\fP, Namval_t *\fIf\fP, Namfun_t *\fIfp\fP);
     84 char	*nv_adddisc(Namval_t *\fInp\fP, const char **\fInames\fP);
     85 const Namdisc_t	*nv_discfun(int \fIwhich\fP);
     86 .ft R
     87 .fi
     88 .SS "TYPES"
     89 .nf
     90 .ft 5
     91 Namval_t	*nv_type(Namval_t  *\fInp\fP);
     92 int	*nv_settype(Namval_t  *\fInp\fP, Namval_t *\fItp\fP, int \fIflags\fP);
     93 Namval_t	*nv_mkinttype(char *\fIname\fP, size_t \fIsz\fP, int \fIus\fP, const char *\fIstr\fP, Namdisc_t *\fIdp\fP);
     94 void	nv_addtype(Namval_t *\fInp\fP, const char *\fIstr\fP, Optdisc_t* *\fIop\fP, size_t \fIsz\fP);
     95 .ft R
     96 .fi
     97 .SS "MISCELLANEOUS FUNCTIONS"
     98 .nf
     99 .ft 5
    100 int	nv_scan(Dt_t *\fIdict\fP, void(*\fIfn\fP)(Namval_t*,void*), void *\fIdata\fP, int \fImask\fP, int \fIflags\fP);
    101 Dt_t	*nv_dict(Namval_t *\fInp\fP);
    102 void	nv_setvtree(Namval_t *\fInp\fP);
    103 void	nv_setref(Namval_t *\fInp\fP, Dt_t *\fIdp\fP, int \fIflags\fP);
    104 Namval_t	*nv_lastdict(void);
    105 .ft R
    106 .fi
    107 .PP
    108 .SH DESCRIPTION
    109 .PP
    110 \fINval\fP is a library of functions for interacting with name-value
    111 pairs as used in \f5ksh\fP.
    112 It is built on top the container dictionary type library facility
    113 in \f5libcdt\fP. (See cdt(3)).
    114 Each name-value pair is represented by a
    115 type named \f5Namval_t\fP. 
    116 A \f5Namval_t\fP contains the name, value and
    117 attributes of a variable.
    118 Some attributes can have an associated number that
    119 represents the field width, arithmetic base, or precision.
    120 Additionally, each name-value pair can be associated with
    121 one or more processing disciplines that affect
    122 its behavior.
    123 .PP
    124 The function \f5nv_open()\fP returns a pointer to a name-value
    125 pair corresponding to the given \fIname\fP.
    126 It can also assign a value and give attributes to a name-value pair.
    127 The argument \fIdict\fP defines the dictionary to search.
    128 A \f5NULL\fP value causes the shell global variable dictionary to be searched.
    129 .PP
    130 The \fIflags\fP argument consists of the bitwise-or of zero or more
    131 of the attributes listed later and zero or more of the following:
    132 .IP
    133 \f5NV_VARNAME\fP:
    134 An invalid variable name causes an error.
    135 .IP
    136 \f5NV_IDENTIFIER\fP:
    137 A variable name that is not an identifier causes an error.
    138 .IP
    139 \f5NV_ASSIGN\fP:
    140 The \fIname\fP argument can contain an assignment.
    141 .IP
    142 \f5NV_NOARRAY\fP:
    143 The \fIname\fP argument cannot contain a subscript.
    144 .IP
    145 \f5NV_NOREF\fP:
    146 Do not follow references when finding the name-value pair.
    147 .IP
    148 \f5NV_NOADD\fP:
    149 The name-value pair will not be added if it doesn't exist.
    150 Instead, a \f5NULL\fP pointer will be returned.
    151 .IP
    152 \f5NV_NOSCOPE\fP:
    153 Only the top level scope is used.
    154 .IP
    155 \f5NV_NOFAIL\fP:
    156 Just return \f5NULL\fP when an error occurs.
    157 By default an error message is displayed and the current command
    158 is aborted.
    159 .IP
    160 .PP
    161 If a name-value pair by this name does not already exist, it is
    162 created unless \fIflags\fP contains the \f5NV_NOADD\fP flag.
    163 If \f5NV_VARNAME\fP, \f5NV_IDENTIFIER\fP and \f5NV_ASSIGN\fP are
    164 all not specified, then no validity check is performed on the \fIname\fP
    165 argument and no further processing is performed.
    166 Otherwise, if \f5NV_ASSIGN\fP is specified, then the characters up
    167 to the first \f5=\fP or \f5+=\fP are used to find the name-value pair,
    168 and the characters after the \f5=\fP are used to define
    169 the value that will be assigned to this name-value pair.
    170 If \fIname\fP does not contain an \f5=\fP, than no assignment
    171 will be made.
    172 If the first identifier in \fIname\fP is a reference and is not
    173 preceded by a \fB.\fP,
    174 it will be replaced by the value of the reference
    175 to find the name of a variable.
    176 Unless \fIflags\fP contains the \f5NV_NOREF\fP flag,
    177 if the name-value pair give by \fIname\fP has the \f5NV_REF\fP
    178 attribute, it will be replaced by the variable whose name
    179 is the value of this name-value pair.
    180 If \f5NV_ASSIGN\fP is set in the \fIflags\fP argument,
    181 the \fIname\fP variable can contain an \f5=\fP
    182 and a value that will be assigned to the name-value pair.
    183 Any attributes appearing in the \fIflags\fP argument
    184 will be applied to the name-value pair after any value is assigned.
    185 .PP
    186 It is possible for an application to create additional dictionaries
    187 with the cdt library and associate them with name-value pairs.
    188 The \f5nv_dict()\fP function returns the dictionary associated with
    189 the specified name-value pair, or if no dictionary was specified,
    190 \f5NULL\fP is returned.
    191 The \f5nv_lastdict()\fP function returns a pointer the the
    192 name-value pair that contains
    193 the last dictionary searched on the previous \f5nv_open()\fP.
    194 .PP
    195 Name-value pairs can also be allocated without belonging to
    196 a dictionary.  They will typically be looked by a a \fIcreate\fP
    197 discipline associated with a parent node.  In this case the
    198 node size will by \f5NV_MINSZ\fP and \fIn\fP nodes can be allocated
    199 vial \f5calloc(5NV_MINSZ,\fIn\fP)\fP(3).
    200 The \f5nv_namptr\fP function can be used on the pointer returned by
    201 \f5calloc\fP along with the element number to return the
    202 corresponding node.
    203 Each of these nodes must be given the \f5NV_MINIMAL\fP attributes.
    204 .PP
    205 The \f5nv_close()\fP indicates that the pointer returned by
    206 \f5nv_open()\fP or \f5nv_opensub()\fP will not be referenced again.  If the
    207 name-value pair is unset, and not referenced elsewhere,
    208 the name-value pair may be freed.
    209 .PP
    210 The \f5nv_delete()\fP function will remove the node \fInp\fP from
    211 the dictionary \fIdict\fP.  Unless \fInofree\fP is non-zero, the
    212 node \fInp\fP will also be freed.
    213 .PP
    214 The \f5nv_name()\fP function returns the name of the given name-value
    215 pair \fInp\fP.
    216 The \f5nv_setsize()\fP function returns the size of the field for
    217 justified variables, the arithmetic base for integer variables,
    218 and the precision or number of places after the decimal point
    219 for floating point variables.  If \fIsize\fP is greater than or
    220 equal to zero, the current size is changed to this value. 
    221 The \f5nv_size()\fP function is equivalent to \f5nv_setsize()\fP
    222 with the second argument negative.
    223 .PP
    224 The \f5nv_getval()\fP function returns the value of the given
    225 name-value pair as a string.  A \f5NULL\fP return value indicates
    226 that the name-value pair is unset.
    227 The \f5nv_getnum()\fP function returns the value of the given
    228 name-value pair as a double precision number using the \f5Sfio\fP
    229 library  (See Sfio(3)) type \f5Sfdouble_t\fP.
    230 For name-value pairs without the \f5NV_INTEGER\fP attribute,
    231 the string value is evaluated as an arithmetic expression to
    232 arrive at a numerical value.
    233 .PP
    234 The \f5nv_putval()\fP function is used to assign a \fIvalue\fP to
    235 the name-value pair \fInp\fP.
    236 The \fIflags\fP argument consists zero or more of the bitwise-or
    237 of \f5NV_LONG\fP, \f5NV_SHORT\fP, \f5NV_DOUBLE\fP, \f5NV_INTEGER\fP,
    238 \f5NV_RDONLY\fP, \f5NV_REF\fP, \f5NV_BINARY\fP, and \f5NV_NOFREE\fP.
    239 The presence of \f5NV_RDONLY\fP allows the assignment to occur
    240 even if the name-value pair has the \f5NV_RDONLY\fP attribute.
    241 The presence of \f5NV_INTEGER\fP indicates that the \fIvalue\fP
    242 argument is actually a pointer to a numerical type.
    243 By default this type is \f5long\fP, but can be modified with
    244 \f5NV_LONG\fP, \f5NV_SHORT\fP, and \f5NV_DOUBLE\fP
    245 to represent \f5long long\fP, \f5short\fP, \f5double\fP, \f5long double\fP,
    246 and \f5float\fP.
    247 The presence of \f5NV_REF\fP indicates that the \fIvalue\fP
    248 argument is actually a pointer to a name-value pair
    249 and \f5np\fP should become a reference to this name-value pair.
    250 If \f5NV_NOFREE\fP is specified, \fIvalue\fP itself becomes
    251 the value of the name-value pair \fInp\fP.
    252 Otherwise, a  copy of the value is stored
    253 as the value for \fInp\fP.
    254 .PP
    255 The \f5nv_unset()\fP function clears out the value and attributes
    256 of the given name-value function but does not free the name-value
    257 pair.
    258 If called from the \f5putval\fP discipline function, use the \fIflags\fP
    259 argument as the \fIflags\fP to  \f5nv_unset()\fP.  Otherwise, use 0.
    260 .PP
    261 The following attributes can be associated with a name-value pair:
    262 .IP
    263 \f5NV_EXPORT\fP:
    264 The export attribute.
    265 .IP
    266 \f5NV_RDONLY\fP:
    267 The readonly attribute.
    268 .IP
    269 \f5NV_LTOU\fP:
    270 Lower case characters are converted to upper case characters.
    271 .IP
    272 \f5NV_UTOL\fP:
    273 Upper case characters are converted to lower case characters.
    274 .IP
    275 \f5NV_RJUST\fP:
    276 Right justify and blank fill.
    277 This attribute has an associated size that defines the
    278 string length of the value.
    279 .IP
    280 \f5NV_LJUST\fP:
    281 Left justify and blank fill.
    282 This attribute has an associated size that defines the
    283 string length of the value.
    284 .IP
    285 \f5NV_ZFILL\fP:
    286 Without \f5NV_LJUST\fP, right justifies and fills with leading zeros.
    287 With \f5NV_LJUST\fP, left justify and strip leading zeros.
    288 Left justify and blank fill.
    289 This attribute has an associated size that defines the
    290 string length of the value.
    291 .IP
    292 \f5NV_TAGGED\fP:
    293 Indicates the tagged attribute.
    294 .IP
    295 \f5NV_INTEGER\fP:
    296 Causes value to be represented by a number.
    297 This attribute has an associated number that defines the
    298 arithmetic base to be used when the value is expanded as a string.
    299 .IP
    300 \f5NV_DOUBLE\fP:
    301 Used in conjunction with \f5NV_INTEGER\fP to cause value
    302 to be stored as a double precision floating point number.
    303 This attribute has an associated number that defines the
    304 number of places after the decimal point to be used when
    305 the value is expanded as a string.
    306 .IP
    307 \f5NV_EXPNOTE\fP:
    308 Used in conjunction with \f5NV_INTEGER\fP and \f5NV_DOUBLE\fP to
    309 cause the value to be represented in scientific notation when
    310 expanded as a string.
    311 This attribute has an associated number that defines the
    312 the precision of the mantissa.
    313 .IP
    314 \f5NV_HEXFLOAT\fP:
    315 Used in conjunction with \f5NV_INTEGER\fP and \f5NV_DOUBLE\fP to
    316 cause the value to be represented in C99 %a format when expanded as
    317 a string.
    318 .IP
    319 \f5NV_BINARY\fP:
    320 The name-value pair contains a buffer of binary data and \f5nv_size()\fP
    321 is the number of bytes for this data.  By default the value
    322 will be represented by the base64 encoding of the buffer.
    323 The \f5NV_LJUST\fP flag may also be specified and causes the buffer
    324 size to be fixed and data either truncated or filled with \f50\fP bytes.
    325 .IP
    326 \f5NV_REF\fP:
    327 The name-value pair is a name reference variable.
    328 .IP
    329 \f5NV_MINIMAL\fP:
    330 The name-value pair node is not embedded in a dictionary
    331 and is minimal size, \f5NV_MINSZ\fP.
    332 .IP
    333 \f5NV_NODISC\fP:
    334 All discipline functions are ignored when performing assignments
    335 and lookups.
    336 .PP
    337 The \f5nv_isattr()\fP function can test whether or not any of
    338 the attributes given by \fIflags\fP is set.
    339 The \f5nv_onattr()\fP and \f5nv_offattr()\fP functions turn attributes
    340 on or off respectively.  Only attributes that do not affect the
    341 value can be set in this way.
    342 The \f5nv_newattr()\fP function can be used to change the
    343 attributes and size of the given name-value pair which may result
    344 in the value being changed to conform to the new attributes and size.
    345 The \fIsize\fP argument is needed for attributes that require
    346 an additional argument such as justifies variables.
    347 Changing the attribute may require changing the value
    348 to agree with the new attributes.
    349 For an array variable, the values for each of the
    350 subscripts will be changed.
    351 .PP
    352 The \f5nv_isvtree()\fP function returns a pointer to the compound
    353 variable discipline if the node \fInp\fP is a compound variable
    354 or \f5NULL\fP otherwise.
    355 .PP
    356 The \f5nv_isarray()\fP function returns a non-zero value if the specified
    357 name-value pair is an array. 
    358 .PP
    359 The \f5nv_scan()\fP function is used to walk through
    360 all name-value pairs in the dictionary given by \fIdict\fP.
    361 If the \f5flags\fP variable contains the \f5NV_NOSCOPE\fP
    362 flag, then only the top scope will be examined.
    363 The remaining flags will be used in conjunction with \fImask\fP
    364 to further restrict the walk.
    365 If \fImask\fP is non-zero, only the nodes for which 
    366 \f5nv_isattr(\fP\fInode\fP\f5,\fP\fImask\fP\f5)\fP
    367 is equal to \fIflags\fP will be visited.
    368 If \fIfn\fP is non-zero, then this function will be executed
    369 for each name-value pair in the walk. 
    370 The arguments to \fIfn\fP will be a pointer to the name-value pair
    371 and the \fIdata\fP pointer passed to \f5nv_scan()\fP.
    372 The number of elements visited will be returned.
    373 .PP
    374 The \f5nv_clone()\fP function is used make a copy of the contents of
    375 name-value pair \fIsrc\fP to another name-value pair \fIdest\fP.
    376 .PP
    377 Disciplines provide a way to
    378 intercept the lookup and assignment operations,
    379 to manage the creation of sub-variables,
    380 and to extend the operations permitted on a name-value pair.
    381 A discipline consists of a set of one or more functions and related
    382 data that are used to override and extend the operations
    383 on a name-value pair. 
    384 A discipline is defined by the types
    385 \f5Namfun_t\fP and \f5Namdisc_t\fP.
    386 The \f5Namdisc_t\fP is not modified by any of these functions and
    387 can therefore be shared by several name-value pairs. 
    388 It contains following public fields in the order listed:
    389 .nf
    390       \f5size_t	dsize;\fP
    391       \f5void	(*putval)(Namval_t*,const char*,int,Namfun_t*);\fP
    392       \f5char	*(*getval)(Namval_t*,Namfun_t*);\fP
    393       \f5double	(*getnum)(Namval_t*,Namfun_t*);\fP
    394       \f5char	*(*setdisc)(Namval_t*,const char*,Namval_t*,Namfun_t*);\fP
    395       \f5Namval_t	*(*createf)(Namval_t*,const char*,Namfun_t*);\fP
    396       \f5Namfun_t	*(*clonef)(Namval_t*,Namval_t*,int,Namfun_t*);\fP
    397       \f5char	*(*namef)(Namval_t*,Namfun_t*);\fP
    398       \f5Namval_t	*(*nextf)(Namval_t*,Dt_t*,Namfun_t*);\fP
    399       \f5Namval_t	*(*typef)(Namval_t*,Namfun_t*);\fP
    400 .fi
    401 The \f5Namfun_t\fP type contains a member named
    402 \f5disc\fP which points to a \f5Namdisc_t\fP structure.
    403 To create a discipline with additional user data,
    404 define a structure with an instance of \f5Namfun_t\fP
    405 as the first element.
    406 An application must initialize the \f5Namfun_t\fP portion of
    407 the structure to zero and then set the \fIdisc\fP field to point
    408 to the \f5Namdisc_t\fP structure.
    409 The \f5dsize\fP field of the \f5Namdisc_t\fP structure must be
    410 the size of this structure.  A value of 0,
    411 indicates that there are no additional fields and is equivalent
    412 to \f5sizeof(Namfun_t)\fP.
    413 If different instances of this structure uses different sizes, then
    414 the \f5size\fP field in the \f5Namfun_t\fP can must be set to
    415 this size and overrides the value in the \f5Namdisc_t\fP structure.
    416 .PP
    417 When a variable is referenced by calling the \f5nv_getval()\fP function,
    418 and the \f5NV_NODISC\fP attribute is not set,
    419 the \f5getval()\fP discipline function is called with a pointer
    420 to the name-value pair, \fInp\fP, and a pointer to the discipline,
    421 \fIfp\fP.
    422 Inside the \f5getval()\fP function, the \f5nv_getv()\fP function
    423 can be called to get the value of the name-value pair that
    424 would have resulted if the discipline were not used.
    425 The \f5getnum()\fP discipline is called whenever a numerical
    426 value is needed for the name-value pair \fInp\fP
    427 and the \f5NV_NODISC\fP attribute is not set,
    428 The \f5nv_getn()\fP function can be called from within
    429 the \f5getnum()\fP discipline to get the value that would
    430 have resulted if there were no \f5getnum()\fP discipline.
    431 .PP
    432 The \f5putval\fP\f5()\fP discipline function is used to
    433 override the assignment of values
    434 to a name-value pair.
    435 It is called whenever a value is assigned with \f5nv_putval()\fP
    436 and the \f5NV_NODISC\fP attribute is not set,
    437 or when a name-value pair is unset with \f5nv_unset()\fP.
    438 When a name-value pair is unset, \f5putval\fP\f5()\fP
    439 is called with \fIvalue\fP set to \f5NULL\fP. 
    440 The \f5nv_putv()\fP function is used within the \f5putval()\fP
    441 to perform the assignment or unset that would have occurred
    442 if the discipline had not been installed.
    443 .PP
    444 The \f5createf()\fP discipline function is called from
    445 \f5nv_open()\fP or \f5nv_create()\fP when the name-value pair preceding a
    446 .B \s+2.\s-2
    447 is found.
    448 This function is passed the name-value pointer plus the remaining string and
    449 the current \fIflags\fP argument.
    450 The \f5createf()\fP discipline function
    451 must return the created name-value pair, otherwise the default action
    452 will be taken.
    453 If the name-value pair that is returned  is the same as the
    454 one given, then the the behavior will be the same as if
    455 an invalid name had been given to \f5nv_open()\fP.
    456 The \f5nv_create()\fP function may be called within
    457 the \f5createf()\fP discipline function
    458 to perform the action that would have occurred
    459 by an earlier \f5nv_open()\fP function.
    460 .PP
    461 The \f5setdisc()\fP discipline function is used
    462 to extend the set of available shell level discipline functions
    463 associated with a name-value pair by allowing
    464 builtins or functions whose name is of the
    465 form \fIvarname\fP\f5.\fP\fIaction\fP to be defined.
    466 By default, each name-value pair can have a \f5get\fP,
    467 \f5set\fP, and \f5unset\fP discipline associated with it.
    468 Whenever a builtin or function whose name is of the 
    469 form \fIvarname\fP\f5.\fP\fIaction\fP is defined or is unset,
    470 and \fIaction\fP is not \f5get\fP,
    471 \f5set\fP, or \f5unset\fP, the \fIsetdisc\fP\f5()\fP function is invoked
    472 with the same argument format as \f5nv_setdisc\fP\f5()\fP.
    473 The argument \fIf\fP points to the name-value pair associated
    474 with the function being defined, or \f5NULL\fP if the function is
    475 being unset.
    476 If the given action \fIa\fP is not known by this discipline,
    477 it should return the value returned by calling
    478 \f5nv_setdisc(\fP\fInp\fP\f5,\fP\fIa\fP\f5,\fP\fIf\fP\f5,\fP\fIfp\fP\f5)\fP
    479 so that it can be searched for in previously stacked disciplines.
    480 Otherwise, the \fIsetdisc\fP\f5()\fP function should save the function
    481 name-value pair pointer, and return a non-\f5NULL\fP value.
    482 The name-value pointer to the function can be used to invoke
    483 the function at an application defined point.
    484 If the action \fIa\fP is \f5NULL\fP, then \fIf\fP points to
    485 an action name instead of a name-value pair pointer.
    486 The \fIsetdisc\fP\f5()\fP must return the
    487 name of the action that follows the action name given by
    488 \fIf\fP.  If \fIf\fP is also \f5NULL\fP, the name of the first action
    489 must be returned.
    490 This allows an application to get the list of valid discipline
    491 action names allowed by a given name-value pair.
    492 .PP
    493 The \f5nv_adddisc()\fP function is a higher level function that
    494 adds a \fIsetdisc\fP discipline to the name-value pair that allows
    495 shell level disciplines to be created for each of the name specified
    496 in \f5names\fP.
    497 .PP
    498 The \f5nv_discfun()\fP function can be used to get a pointer to
    499 discipline functions that are provided by the library.
    500 Currently, the only one that is provided is the ones used to
    501 implement \f5nv_adddisc()\fP which can be returned with an
    502 argument of \f5NV_DCADD\fP.
    503 .PP
    504 The \f5clonef()\fP discipline function is called by \f5nv_clone()\fP
    505 when making a copy of the \f5Namfun_t\fP discipline to the new node.  
    506 The first argument is the original node, the second argument is
    507 the new node, and the third argument is the flags that were passed
    508 down to \f5nv_clone()\fP.
    509 It must return a new instance of the \f5Namfun_t*\fP \f5fp\fP.
    510 If omitted, then memory whose size is determinated by the \f5size\fP
    511 field of \f5fp\fP, if non-zero, or \f5fp->disc\fP, will be allocated
    512 and copied from \f5fp\fP.
    513 .PP
    514 The \f5namef()\fP discipline function returns the name for this name-value pair.
    515 .PP
    516 The \f5nextf()\fP is used for walking through the list of sub-variables
    517 associated with this name-value pair.  If the dictionary argument is
    518 \f5NULL\fP, it must return the first sub-variable.  Otherwise,
    519 it must return the next sub-variable, or \f5NULL\fP if there are
    520 no more variables.
    521 .PP
    522 A discipline is installed or removed with the
    523 \f5nv_disc()\fP function.
    524 The following flags can be specified:
    525 .IP
    526 \f5NV_FIRST\fP:
    527 If \fIfp\fP is non-\f5NULL\fP, the discipline is moved to the top
    528 of the stack or pushed onto the top of the stack of disciplines
    529 associated with the given name-value
    530 pair \fInp\fP if not already present.
    531 Otherwise, the top of the discipline stack is returned.
    532 .IP
    533 \f5NV_LAST\fP:
    534 If \fIfp\fP is non-\f5NULL\fP, the discipline is moved to the bottom
    535 of the stack or pushed onto the bottom of the stack of disciplines
    536 associated with the given name-value
    537 pair \fInp\fP if not already present.
    538 Otherwise, the bottom of the discipline stack is returned.
    539 .IP
    540 \f5NV_POP\fP:
    541 If \fIfp\fP is non-\f5NULL\fP and it is on the stack,
    542 it is removed and \fIfp\fP is returned.  If  \fIfp\fP is non-\f5NULL\fP
    543 and is not on the stack, \f5NULL\fP is returned.
    544 Otherwise, the the top discipline is popped
    545 and returned.
    546 .IP
    547 \f5NV_CLONE\fP:
    548 If \fIfp\fP is non-\f5NULL\fP and it is on the stack,
    549 it is replace by a copy created by \f5malloc\fP(3).
    550 The \f5nofree\fP field is set to \f50\fP.
    551 The new discipline is returned.
    552 Otherwise, \f5NULL\fP is returned.
    553 .IP
    554 \f50\fP:
    555 If \fIfp\fP is non-\f5NULL\fP then it is equivalent to \f5NV_FIRST\fP.
    556 Otherwise, it is equivalent to \f5NV_POP\fP.
    557 .PP
    558 The
    559 \f5nv_hasdisc()\fP function can be used to tell whether a discipline
    560 whose discipline functions are those defined in \fIdp\fP.
    561 A pointer to this discipline is returned.
    562 .PP
    563 The \f5nv_aindex()\fP function returns
    564 the current index for
    565 the indexed array given by the name-value pair pointer \fInp\fP. 
    566 The return value is negative if \fInp\fP refers to
    567 an associative array.
    568 .PP
    569 The \f5nv_setarray()\fP function is used to create an associative array
    570 from a name-value pair node.
    571 The function \fIfun\fP defines the semantics of the associative
    572 array.
    573 Using \fIfun\fP equal to \f5nv_associative()\fP implements the default
    574 associative array semantics
    575 that are used with \f5typeset\ -A\fP.
    576 The function \fIfun\fP will be called with third argument as follows:
    577 .IP
    578 \f5NV_AINIT\fP:
    579 This will be called at initialization.
    580 The function you supply must return a pointer to a structure
    581 that contains the type \f5Namarr_t\fP as the first element.
    582 All other calls receive this value as an argument.
    583 .IP
    584 \f5NV_AFREE\fP:
    585 This will be called after all elements of the name-value pair have been
    586 deleted and the array is to be freed.
    587 .IP
    588 \f5NV_ADELETE\fP:
    589 The current element should be deleted.
    590 .IP
    591 \f5NV_ANEXT\fP:
    592 This means that the array subscript should be advanced to the
    593 next subscript.  A \f5NULL\fP return indicates that there are
    594 no more subscripts.
    595 .IP
    596 \f5NV_ANAME\fP:
    597 The name of the current subscript must be returned.
    598 .IP
    599 \f5NV_ACURRENT\fP:
    600 Returns a pointer to a name-value pair corresponding to the
    601 current subscript, or \f5NULL\fP if this array type doesn't
    602 create represent each element as a name-value pair.
    603 .IP
    604 \f5NV_ASETSUB\fP:
    605 Set the current subscript to the name-value pair passed in
    606 as the second argument.
    607 .PP
    608 If \fInp\fP refers to an array,
    609 \f5nv_arrayptr()\fP returns a pointer to
    610 the array discipline structure \f5Namarr_t\fP.
    611 Otherwise \f5nv_arrayptr()\fP returns \f5NULL\fP.
    612 .PP
    613 If \fInp\fP refers to an array,
    614 the \f5nv_getsub()\fP returns a pointer to
    615 the name of the current subscript.
    616 Otherwise, \f5nv_getsub()\fP
    617 returns \f5NULL\fP.
    618 .PP
    619 The \f5nv_opensub()\fP function returns
    620 a pointer to the name-value pair corresponding
    621 to the current subscript in an associative array.
    622 Note that the \f5nv_close()\fP function should be called
    623 when the pointer is no longer needed.
    624 .PP
    625 The \f5nv_putsub()\fP function is used to
    626 set the subscript for the next reference to \f5np\fP.
    627 If the \f5name\fP argument is not \f5NULL\fP,
    628 it defines the value of the next subscript. 
    629 The \f5mode\fP argument can contain one or more of the following flags:
    630 .IP
    631 \f5ARRAY_ADD\fP:
    632 Add the subscript if not found.
    633 Otherwise, \f5nv_putsub()\fP returns \f5NULL\fP if the
    634 given subscript is not found.
    635 .IP
    636 \f5ARRAY_SCAN\fP:
    637 Begin a walk through the subscripts starting at the subscript
    638 given by \f5name\fP.  If \f5name\fP is \f5NULL\fP
    639 the walk is started from the beginning.
    640 .IP
    641 \f5ARRAY_UNDEF\fP:
    642 This causes any current scan to terminate and leaves the
    643 subscript in an undefined state.
    644 .PP
    645 If \f5ARRAY_ADD\fP is not given and the subscript
    646 does not exist, a \f5NULL\fP value is returned.
    647 .PP
    648 The \f5nv_nextsub()\fP function is used to advance to the
    649 next subscript.
    650 It returns 0 if there are no more subscripts or if called
    651 when not in a scan.
    652 .PP
    653 The \f5nv_setref()\fP function makes the name-value pair \f5np\fP
    654 into a reference to the variable whose name is given by
    655 the value of \f5np\fP.  The \f5nv_open()\fP open function is
    656 called with this name, the dictionary given by \f5dp\fP,
    657 and the \f5flags\fP argument.
    658 A \f5NULL\fP value causes the shell global variable dictionary to be searched.
    659 .PP
    660 The \f5nv_setvtree()\fP function makes the name-value pair \f5np\fP
    661 into a tree structured variable so that \f5nv_getval()\fP
    662 will return a string containing all the names and values of
    663 children nodes in a format that can be used in
    664 a shell compound assignment.
    665 .PP
    666 The \f5nv_type()\fP function returns a name_value pair pointer
    667 that contains the type definition for the specified name-value pair.
    668 The \fInvname\fP field contains the name for the type. 
    669 .PP
    670 The \f5nv_settype()\fP function converts the name-value pair
    671 given by \fInp\fP into the type given by \fItp\fP.
    672 .PP
    673 The \f5nv_addtype()\fP function adds the name of the type given by
    674 \fInp\fP to the list of declaration built-ins.  The \fIstr\fP
    675 argument contains the string used by \f5optget\fP(3) to generate
    676 the man page and process the options.  The \fIop\fP argument
    677 specifies the callback discipline used by  \f5optget\fP(3) and
    678 \fIsz\fP specifies the size of the callback information so
    679 that the  discipline \fBoptget\fP(3) can be extended with private
    680 data used by the callback function.
    681 .P
    682 The \f5nv_mkinttype()\fP function creates named integer types
    683 of the specified \fIname\fP.  The \fIsize\fP parameter is the size
    684 in bytes of the integer variable and  \fIus\fP is non-zero
    685 for unsigned integer types.  If \fIdp\fP is specified then integer
    686 variables of this type will all use this discipline.
    687 .SH SEE ALSO
    688 calloc(3)
    689 cdt(3)
    690 shell(3)
    691 optget(3)
    692 .SH AUTHOR
    693 David G. Korn (dgk (a] research.att.com).
    694