From: Stephen D. <sd...@gm...> - 2005-03-18 11:36:21
|
> Oh yes, Stephen, I love the arg parsing code This is really > a relief. After years any years of parsing... heh.. Well, it would be great if it actually worked... :-/ I don't think the return value of the parse-proc can be overloaded to mean both the number of args left and 'break' (by saying zero args left). The way it is now, a command like [ns_foo -blah whatsit] will return 0 args left from the proc which handles the -foo switch because there really are no args left. But this is used as a signal to end option parsing so objc does't get updated to reflect that fact that 'whatsit' was consumed. The result is that 'whatsit' gets treated as an arg even though it was already handled. I think the signature of the parse procs will have to be changed to return TCL_OK, TCL_ERROR, TCL_BREAK, and pass a pointer to objc which they will be expected to update. What do you think? On Mon, 28 Feb 2005 10:05:38 +0100, Zoran Vasiljevic <zv...@ar...> wrote: > On Monday 28 February 2005 08:25, Stephen Deasey wrote: > > I was thinking about making the Ns_ObjvBool proc look at it's arg, and > > if present, place that in the destination pointer and not consume an > > object from the objv array. The presence of the option (without > > argument) alone would signify true, it's absence false. > > > > Then I realised I left out the short-circuit logic... When a -- > > (break) arg is found the options are assumed to have ended and we jump > > to arg processing. The signal for this is that the Ns_ObjvBreak proc > > returns exactly objc. But that's really what the Bool proc should > > return in the case described above when it doesn't consume an arg. > > > > Unfortunately it's not as simple as that. The "wrong num args" > > description needs to know that the option takes no argument too. > > > > > > Any thoughts? > > And if Ns_ObjvBreak returns zero as a signal that none > of the options are expected any more: > > remain = specPtr->proc(specPtr->dest, interp, objc, objv + objvIndex, > specPtr->arg); > if (remain == 0 || remain == objc) { > remain = objc; > break; > } > > Hm? > Zoran |