summaryrefslogtreecommitdiffstats
path: root/generic/tclCmdMZ.c
diff options
context:
space:
mode:
authordkf <donal.k.fellows@manchester.ac.uk>2005-06-01 11:00:24 (GMT)
committerdkf <donal.k.fellows@manchester.ac.uk>2005-06-01 11:00:24 (GMT)
commit854f85bb1700aa6f106cc6a443cb0eb2e917f2de (patch)
treed3bbe95a2b84f8455477e5d9e709e78633b6d7bd /generic/tclCmdMZ.c
parent8f397c357860e5098e4eeea5140ed0d3c724075d (diff)
downloadtcl-854f85bb1700aa6f106cc6a443cb0eb2e917f2de.zip
tcl-854f85bb1700aa6f106cc6a443cb0eb2e917f2de.tar.gz
tcl-854f85bb1700aa6f106cc6a443cb0eb2e917f2de.tar.bz2
Implementation of TIP#241 from Joe Mistachkin
Also compilation of [switch -glob -nocase] from Donal Fellows
Diffstat (limited to 'generic/tclCmdMZ.c')
-rw-r--r--generic/tclCmdMZ.c24
1 files changed, 16 insertions, 8 deletions
diff --git a/generic/tclCmdMZ.c b/generic/tclCmdMZ.c
index b507fe5..99182f3 100644
--- a/generic/tclCmdMZ.c
+++ b/generic/tclCmdMZ.c
@@ -15,7 +15,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.122 2005/05/25 19:27:10 hobbs Exp $
+ * RCS: @(#) $Id: tclCmdMZ.c,v 1.123 2005/06/01 11:00:34 dkf Exp $
*/
#include "tclInt.h"
@@ -2520,7 +2520,7 @@ Tcl_SwitchObjCmd(dummy, interp, objc, objv)
int objc; /* Number of arguments. */
Tcl_Obj *CONST objv[]; /* Argument objects. */
{
- int i, j, index, mode, result, splitObjs, numMatchesSaved;
+ int i, j, index, mode, result, splitObjs, numMatchesSaved, noCase;
char *pattern;
Tcl_Obj *stringObj, *indexVarObj, *matchVarObj;
Tcl_Obj *CONST *savedObjv = objv;
@@ -2531,17 +2531,21 @@ Tcl_SwitchObjCmd(dummy, interp, objc, objv)
* parser as well.
*/
static CONST char *options[] = {
- "-exact", "-glob", "-indexvar", "-matchvar", "-regexp", "--",
- NULL
+ "-exact", "-glob", "-indexvar", "-matchvar", "-nocase", "-regexp",
+ "--", NULL
};
enum options {
- OPT_EXACT, OPT_GLOB, OPT_INDEXV, OPT_MATCHV, OPT_REGEXP, OPT_LAST
+ OPT_EXACT, OPT_GLOB, OPT_INDEXV, OPT_MATCHV, OPT_NOCASE, OPT_REGEXP,
+ OPT_LAST
};
+ typedef int (*strCmpFn_t) _ANSI_ARGS_((const char *, const char *));
+ strCmpFn_t strCmpFn = strcmp;
mode = OPT_EXACT;
indexVarObj = NULL;
matchVarObj = NULL;
numMatchesSaved = 0;
+ noCase = 0;
for (i = 1; i < objc; i++) {
if (TclGetString(objv[i])[0] != '-') {
break;
@@ -2580,6 +2584,9 @@ Tcl_SwitchObjCmd(dummy, interp, objc, objv)
}
matchVarObj = objv[i];
numMatchesSaved = -1;
+ } else if (index == OPT_NOCASE) {
+ strCmpFn = strcasecmp;
+ noCase = 1;
} else {
mode = index;
}
@@ -2718,18 +2725,19 @@ Tcl_SwitchObjCmd(dummy, interp, objc, objv)
} else {
switch (mode) {
case OPT_EXACT:
- if (strcmp(TclGetString(stringObj), pattern) == 0) {
+ if (strCmpFn(TclGetString(stringObj), pattern) == 0) {
goto matchFound;
}
break;
case OPT_GLOB:
- if (Tcl_StringMatch(TclGetString(stringObj), pattern)) {
+ if (Tcl_StringCaseMatch(TclGetString(stringObj), pattern,
+ noCase)) {
goto matchFound;
}
break;
case OPT_REGEXP:
regExpr = Tcl_GetRegExpFromObj(interp, objv[i],
- TCL_REG_ADVANCED);
+ TCL_REG_ADVANCED | (noCase ? TCL_REG_NOCASE : 0));
if (regExpr == NULL) {
return TCL_ERROR;
} else {