diff options
Diffstat (limited to 'generic/tclCmdMZ.c')
-rw-r--r-- | generic/tclCmdMZ.c | 30 |
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: |