summaryrefslogtreecommitdiffstats
path: root/generic/tclCmdIL.c
diff options
context:
space:
mode:
authordkf <donal.k.fellows@manchester.ac.uk>2004-10-14 17:20:10 (GMT)
committerdkf <donal.k.fellows@manchester.ac.uk>2004-10-14 17:20:10 (GMT)
commit2b7d6e025eefe41b48ec7f948602faf2d3bf7055 (patch)
tree14d3d4e324059c624c3f6cf74f45cfccae9574db /generic/tclCmdIL.c
parent97449587f00016cab8acc385844a1d82f26332c6 (diff)
downloadtcl-2b7d6e025eefe41b48ec7f948602faf2d3bf7055.zip
tcl-2b7d6e025eefe41b48ec7f948602faf2d3bf7055.tar.gz
tcl-2b7d6e025eefe41b48ec7f948602faf2d3bf7055.tar.bz2
TIP#217 implementation
Diffstat (limited to 'generic/tclCmdIL.c')
-rw-r--r--generic/tclCmdIL.c44
1 files changed, 32 insertions, 12 deletions
diff --git a/generic/tclCmdIL.c b/generic/tclCmdIL.c
index 2997509..2204d1f 100644
--- a/generic/tclCmdIL.c
+++ b/generic/tclCmdIL.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: tclCmdIL.c,v 1.65 2004/10/14 15:06:01 dkf Exp $
+ * RCS: @(#) $Id: tclCmdIL.c,v 1.66 2004/10/14 17:20:11 dkf Exp $
*/
#include "tclInt.h"
@@ -3751,7 +3751,7 @@ Tcl_LsortObjCmd(clientData, interp, objc, objv)
int objc; /* Number of arguments. */
Tcl_Obj *CONST objv[]; /* Argument values. */
{
- int i, index, unique;
+ int i, index, unique, indices;
Tcl_Obj *resultPtr;
int length;
Tcl_Obj *cmdPtr, **listObjPtrs;
@@ -3762,12 +3762,12 @@ Tcl_LsortObjCmd(clientData, interp, objc, objv)
* comparison function */
static CONST char *switches[] = {
"-ascii", "-command", "-decreasing", "-dictionary", "-increasing",
- "-index", "-integer", "-real", "-unique", (char *) NULL
+ "-index", "-indices", "-integer", "-real", "-unique", (char *) NULL
};
enum Lsort_Switches {
LSORT_ASCII, LSORT_COMMAND, LSORT_DECREASING, LSORT_DICTIONARY,
- LSORT_INCREASING, LSORT_INDEX, LSORT_INTEGER, LSORT_REAL,
- LSORT_UNIQUE
+ LSORT_INCREASING, LSORT_INDEX, LSORT_INDICES, LSORT_INTEGER,
+ LSORT_REAL, LSORT_UNIQUE
};
if (objc < 2) {
@@ -3787,6 +3787,7 @@ Tcl_LsortObjCmd(clientData, interp, objc, objv)
sortInfo.resultCode = TCL_OK;
cmdPtr = NULL;
unique = 0;
+ indices = 0;
for (i = 1; i < objc-1; i++) {
if (Tcl_GetIndexFromObj(interp, objv[i], switches, "option", 0, &index)
!= TCL_OK) {
@@ -3884,6 +3885,9 @@ Tcl_LsortObjCmd(clientData, interp, objc, objv)
case LSORT_UNIQUE:
unique = 1;
break;
+ case LSORT_INDICES:
+ indices = 1;
+ break;
}
}
@@ -3928,16 +3932,32 @@ Tcl_LsortObjCmd(clientData, interp, objc, objv)
if (sortInfo.resultCode == TCL_OK) {
resultPtr = Tcl_NewObj();
if (unique) {
- for (; elementPtr != NULL; elementPtr = elementPtr->nextPtr){
- if (elementPtr->count == 0) {
- Tcl_ListObjAppendElement(interp, resultPtr,
- elementPtr->objPtr);
+ if (indices) {
+ for (; elementPtr != NULL ; elementPtr = elementPtr->nextPtr) {
+ if (elementPtr->count == 0) {
+ Tcl_ListObjAppendElement(interp, resultPtr,
+ Tcl_NewIntObj(elementPtr - &elementArray[0]));
+ }
+ }
+ } else {
+ for (; elementPtr != NULL; elementPtr = elementPtr->nextPtr) {
+ if (elementPtr->count == 0) {
+ Tcl_ListObjAppendElement(interp, resultPtr,
+ elementPtr->objPtr);
+ }
}
}
} else {
- for (; elementPtr != NULL; elementPtr = elementPtr->nextPtr){
- Tcl_ListObjAppendElement(interp, resultPtr,
- elementPtr->objPtr);
+ if (indices) {
+ for (; elementPtr != NULL ; elementPtr = elementPtr->nextPtr) {
+ Tcl_ListObjAppendElement(interp, resultPtr,
+ Tcl_NewIntObj(elementPtr - &elementArray[0]));
+ }
+ } else {
+ for (; elementPtr != NULL; elementPtr = elementPtr->nextPtr){
+ Tcl_ListObjAppendElement(interp, resultPtr,
+ elementPtr->objPtr);
+ }
}
}
Tcl_SetObjResult(interp, resultPtr);