From: Stephen D. <sd...@us...> - 2005-03-04 09:24:29
|
Update of /cvsroot/naviserver/naviserver/nsd In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv1903/nsd Modified Files: tclobjv.c Log Message: Add support for boolean options which take no argument. Truth is determined by presence of the option alone. Index: tclobjv.c =================================================================== RCS file: /cvsroot/naviserver/naviserver/nsd/tclobjv.c,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** tclobjv.c 28 Feb 2005 07:15:06 -0000 1.2 --- tclobjv.c 4 Mar 2005 09:24:14 -0000 1.3 *************** *** 83,87 **** remain = specPtr->proc(specPtr->dest, interp, objc, objv + objvIndex, specPtr->arg); ! if (remain == objc) { break; } --- 83,87 ---- remain = specPtr->proc(specPtr->dest, interp, objc, objv + objvIndex, specPtr->arg); ! if (remain == 0) { break; } *************** *** 132,137 **** *---------------------------------------------------------------------- * ! * Ns_ObjvBool, Ns_ObjvInt, Ns_ObjvLong, Ns_ObjvWideInt, ! * Ns_ObjvDouble -- * * Consume exactly one argument, returning it's value into dest. --- 132,136 ---- *---------------------------------------------------------------------- * ! * Ns_ObjvInt, Ns_ObjvLong, Ns_ObjvWideInt, Ns_ObjvDouble -- * * Consume exactly one argument, returning it's value into dest. *************** *** 148,163 **** int - Ns_ObjvBool(void *dest, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[], - void *arg) - { - if (objc > 0 - && Tcl_GetBooleanFromObj(interp, objv[0], (int *) dest) == TCL_OK) { - return --objc; - } - - return -1; - } - - int Ns_ObjvInt(void *dest, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[], void *arg) --- 147,150 ---- *************** *** 212,215 **** --- 199,237 ---- *---------------------------------------------------------------------- * + * Ns_ObjvBool -- + * + * If no argument is given, consume the next objv object and attempt + * conversion to a boolean value. If an argument is given it is + * expected to be an int and is placed into dest. + * + * Results: + * -1 on error. Exactly objc if an arg was given, objc-1 otherwise. + * + * Side effects: + * Next Tcl object maybe converted to type specific internal rep. + * + *---------------------------------------------------------------------- + */ + + int + Ns_ObjvBool(void *dest, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[], + void *arg) + { + if (arg) { + *((int *) dest) = ((int) arg); + return objc; + } + if (objc > 0 + && Tcl_GetBooleanFromObj(interp, objv[0], (int *) dest) == TCL_OK) { + return --objc; + } + + return -1; + } + + + /* + *---------------------------------------------------------------------- + * * Ns_ObjvString -- * *************** *** 379,383 **** * * Results: ! * Exactly objc. * * Side effects: --- 401,405 ---- * * Results: ! * Always 0 (zero). * * Side effects: *************** *** 392,396 **** void *arg) { ! return objc; } --- 414,418 ---- void *arg) { ! return 0; } *************** *** 449,452 **** --- 471,476 ---- if (STREQ(specPtr->key, "--")) { Ns_DStringAppend(&ds, "?--? "); + } else if (specPtr->proc == &Ns_ObjvBool && specPtr->arg != NULL) { + Ns_DStringPrintf(&ds, "?%s? ", specPtr->key); } else { p = specPtr->key; |