summaryrefslogtreecommitdiffstats
path: root/generic
diff options
context:
space:
mode:
authordkf <donal.k.fellows@manchester.ac.uk>2004-08-27 13:59:27 (GMT)
committerdkf <donal.k.fellows@manchester.ac.uk>2004-08-27 13:59:27 (GMT)
commited3d330d86447c20841d39a0f0e0e57a2bad3ecd (patch)
treea535782e7affb360e13dd53ec1766ebaaf99ec1c /generic
parentfe1bd67c3db19045cffd0e2f58d3cdc02ebaaf90 (diff)
downloadtcl-ed3d330d86447c20841d39a0f0e0e57a2bad3ecd.zip
tcl-ed3d330d86447c20841d39a0f0e0e57a2bad3ecd.tar.gz
tcl-ed3d330d86447c20841d39a0f0e0e57a2bad3ecd.tar.bz2
Make [namespace which] use newer option parsing code for more flexibility.
Diffstat (limited to 'generic')
-rw-r--r--generic/tclNamesp.c48
1 files changed, 21 insertions, 27 deletions
diff --git a/generic/tclNamesp.c b/generic/tclNamesp.c
index 3db8543..9d88b82 100644
--- a/generic/tclNamesp.c
+++ b/generic/tclNamesp.c
@@ -21,7 +21,7 @@
* See the file "license.terms" for information on usage and redistribution
* of this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tclNamesp.c,v 1.47 2004/08/27 11:04:26 dkf Exp $
+ * RCS: @(#) $Id: tclNamesp.c,v 1.48 2004/08/27 13:59:28 dkf Exp $
*/
#include "tclInt.h"
@@ -3851,39 +3851,33 @@ NamespaceWhichCmd(dummy, interp, objc, objv)
int objc; /* Number of arguments. */
Tcl_Obj *CONST objv[]; /* Argument objects. */
{
- int argIndex, lookup;
+ static CONST char *opts[] = {
+ "-command", "-variable", NULL
+ };
+ int lookupType = 0;
- if (objc < 3) {
- badArgs:
- Tcl_WrongNumArgs(interp, 2, objv,
- "?-command? ?-variable? name");
+ if (objc < 3 || objc > 4) {
+ badArgs:
+ Tcl_WrongNumArgs(interp, 2, objv, "?-command? ?-variable? name");
return TCL_ERROR;
- }
-
- /*
- * Look for a flag controlling the lookup.
- */
+ } else if (objc == 4) {
+ /*
+ * Look for a flag controlling the lookup.
+ */
- argIndex = 2;
- lookup = 0; /* assume command lookup by default */
- arg = TclGetString(objv[2]);
- if (*arg == '-') {
- if (strncmp(arg, "-command", 8) == 0) {
- lookup = 0;
- } else if (strncmp(arg, "-variable", 9) == 0) {
- lookup = 1;
- } else {
+ if (Tcl_GetIndexFromObj(interp, objv[2], opts, "option", 0,
+ &lookupType) != TCL_OK) {
+ /*
+ * Preserve old style of error message!
+ */
+ Tcl_ResetResult(interp);
goto badArgs;
}
- argIndex = 3;
- }
- if (objc != (argIndex + 1)) {
- goto badArgs;
}
- switch (lookup) {
+ switch (lookupType) {
case 0: { /* -command */
- Tcl_Command cmd = Tcl_GetCommandFromObj(interp, objv[argIndex]);
+ Tcl_Command cmd = Tcl_GetCommandFromObj(interp, objv[objc-1]);
if (cmd == (Tcl_Command) NULL) {
return TCL_OK; /* cmd not found, just return (no error) */
}
@@ -3892,7 +3886,7 @@ NamespaceWhichCmd(dummy, interp, objc, objv)
}
case 1: { /* -variable */
Tcl_Var var = Tcl_FindNamespaceVar(interp,
- TclGetString(objv[argIndex]), NULL, /*flags*/ 0);
+ TclGetString(objv[objc-1]), NULL, /*flags*/ 0);
if (var != (Tcl_Var) NULL) {
Tcl_GetVariableFullName(interp, var, Tcl_GetObjResult(interp));
}