summaryrefslogtreecommitdiffstats
path: root/generic
diff options
context:
space:
mode:
authordkf <donal.k.fellows@manchester.ac.uk>2002-02-22 14:52:45 (GMT)
committerdkf <donal.k.fellows@manchester.ac.uk>2002-02-22 14:52:45 (GMT)
commit13460529f07c3b6cefa73a73c4b20677a974859e (patch)
tree62dd725cfd18cac73df0af016563dc4793cd8299 /generic
parentae707bf53694039c55ae485a246b5f037caaf2df (diff)
downloadtcl-13460529f07c3b6cefa73a73c4b20677a974859e.zip
tcl-13460529f07c3b6cefa73a73c4b20677a974859e.tar.gz
tcl-13460529f07c3b6cefa73a73c4b20677a974859e.tar.bz2
Added TIP#76 implementation, docs + tests.
Diffstat (limited to 'generic')
-rw-r--r--generic/tclCmdMZ.c30
1 files changed, 19 insertions, 11 deletions
diff --git a/generic/tclCmdMZ.c b/generic/tclCmdMZ.c
index af2e214..04c6a6c 100644
--- a/generic/tclCmdMZ.c
+++ b/generic/tclCmdMZ.c
@@ -14,7 +14,7 @@
* See the file "license.terms" for information on usage and redistribution
* of this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tclCmdMZ.c,v 1.60 2002/02/15 14:28:48 dkf Exp $
+ * RCS: @(#) $Id: tclCmdMZ.c,v 1.61 2002/02/22 14:52:45 dkf Exp $
*/
#include "tclInt.h"
@@ -548,12 +548,13 @@ Tcl_RegsubObjCmd(dummy, interp, objc, objv)
}
}
endOfForLoop:
- if (objc - idx != 4) {
+ if (objc-idx < 3 || objc-idx > 4) {
Tcl_WrongNumArgs(interp, 1, objv,
- "?switches? exp string subSpec varName");
+ "?switches? exp string subSpec ?varName?");
return TCL_ERROR;
}
+ objc -= idx;
objv += idx;
if (all && (offset == 0)
@@ -781,17 +782,24 @@ Tcl_RegsubObjCmd(dummy, interp, objc, objv)
} else if (offset < wlen) {
Tcl_AppendUnicodeToObj(resultPtr, wstring + offset, wlen - offset);
}
- if (Tcl_ObjSetVar2(interp, objv[3], NULL, resultPtr, 0) == NULL) {
- Tcl_AppendResult(interp, "couldn't set variable \"",
- Tcl_GetString(objv[3]), "\"", (char *) NULL);
- result = TCL_ERROR;
+ if (objc == 4) {
+ if (Tcl_ObjSetVar2(interp, objv[3], NULL, resultPtr, 0) == NULL) {
+ Tcl_AppendResult(interp, "couldn't set variable \"",
+ Tcl_GetString(objv[3]), "\"", (char *) NULL);
+ result = TCL_ERROR;
+ } else {
+ /*
+ * Set the interpreter's object result to an integer object
+ * holding the number of matches.
+ */
+
+ Tcl_SetIntObj(Tcl_GetObjResult(interp), numMatches);
+ }
} else {
/*
- * Set the interpreter's object result to an integer object
- * holding the number of matches.
+ * No varname supplied, so just return the modified string.
*/
-
- Tcl_SetIntObj(Tcl_GetObjResult(interp), numMatches);
+ Tcl_SetObjResult(interp, resultPtr);
}
done: