*** tcl8.4.6/generic/tclCmdIL.c	Thu Jul 17 13:29:19 2003
--- tclCmdIL.c	Thu Aug 26 23:14:15 2004
***************
*** 31,36 ****
--- 31,37 ----
  typedef struct SortElement {
      Tcl_Obj *objPtr;			/* Object being sorted. */
      int count;				/* number of same elements in list */
+     int index;                          /* serial number for -indices */
      struct SortElement *nextPtr;        /* Next element in the list, or
  					 * NULL for end of list. */
  } SortElement;
***************
*** 3255,3261 ****
      int objc;			/* Number of arguments. */
      Tcl_Obj *CONST objv[];	/* Argument values. */
  {
!     int i, index, unique;
      Tcl_Obj *resultPtr;
      int length;
      Tcl_Obj *cmdPtr, **listObjPtrs;
--- 3256,3262 ----
      int objc;			/* Number of arguments. */
      Tcl_Obj *CONST objv[];	/* Argument values. */
  {
!     int i, index, unique, ordering;
      Tcl_Obj *resultPtr;
      int length;
      Tcl_Obj *cmdPtr, **listObjPtrs;
***************
*** 3266,3272 ****
                                           * comparison function */
      static CONST char *switches[] = {
  	"-ascii", "-command", "-decreasing", "-dictionary", "-increasing",
! 	"-index", "-integer", "-real", "-unique", (char *) NULL
      };
  
      resultPtr = Tcl_GetObjResult(interp);
--- 3267,3273 ----
                                           * comparison function */
      static CONST char *switches[] = {
  	"-ascii", "-command", "-decreasing", "-dictionary", "-increasing",
! 	"-index", "-integer", "-real", "-unique", "-indices", (char *) NULL
      };
  
      resultPtr = Tcl_GetObjResult(interp);
***************
*** 3286,3291 ****
--- 3287,3293 ----
      sortInfo.resultCode = TCL_OK;
      cmdPtr = NULL;
      unique = 0;
+     ordering = 0;
      for (i = 1; i < objc-1; i++) {
  	if (Tcl_GetIndexFromObj(interp, objv[i], switches, "option", 0, &index)
  		!= TCL_OK) {
***************
*** 3337,3342 ****
--- 3339,3347 ----
  	    case 8:			/* -unique */
  		unique = 1;
  		break;
+             case 9:                     /* -indices */
+                 ordering = 1;
+                 break;
  	}
      }
      if (sortInfo.sortMode == SORTMODE_COMMAND) {
***************
*** 3370,3375 ****
--- 3375,3381 ----
      for (i=0; i < length; i++){
  	elementArray[i].objPtr = listObjPtrs[i];
  	elementArray[i].count = 0;
+         elementArray[i].index = i;
  	elementArray[i].nextPtr = &elementArray[i+1];
      }
      elementArray[length-1].nextPtr = NULL;
***************
*** 3385,3398 ****
  	if (unique) {
  	    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);
  	    }
  	}
      }
--- 3391,3414 ----
  	if (unique) {
  	    for (; elementPtr != NULL; elementPtr = elementPtr->nextPtr){
  		if (elementPtr->count == 0) {
! 		    if (ordering) {
! 			Tcl_ListObjAppendElement(interp, resultPtr,
! 			    Tcl_NewIntObj(elementPtr->index));
! 		    } else {
! 	 		Tcl_ListObjAppendElement(interp, resultPtr,
  			    elementPtr->objPtr);
+ 		    }
  		}
  	    }
  	} else {
  	    for (; elementPtr != NULL; elementPtr = elementPtr->nextPtr){
! 		if (ordering) {
! 		    Tcl_ListObjAppendElement(interp, resultPtr,
! 			Tcl_NewIntObj(elementPtr->index));
! 		} else {
! 		    Tcl_ListObjAppendElement(interp, resultPtr,
  			elementPtr->objPtr);
+ 		}
  	    }
  	}
      }
