summaryrefslogtreecommitdiffstats
path: root/generic/tclUtil.c
diff options
context:
space:
mode:
authorstanton <stanton>1999-05-04 01:33:10 (GMT)
committerstanton <stanton>1999-05-04 01:33:10 (GMT)
commitcbfd4003a1395d9f6ec97acf62eb239f7c3fafca (patch)
treeeaaa5805340e4ca7c3da51d93e2076081ec153e5 /generic/tclUtil.c
parent1b188bce8407ab0d9d83e72177b9fada135782d2 (diff)
downloadtcl-cbfd4003a1395d9f6ec97acf62eb239f7c3fafca.zip
tcl-cbfd4003a1395d9f6ec97acf62eb239f7c3fafca.tar.gz
tcl-cbfd4003a1395d9f6ec97acf62eb239f7c3fafca.tar.bz2
* tests/cmdIL.test:
* tests/cmdMZ.test: * tests/error.test: * tests/lindex.test: * tests/linsert.test: * tests/lrange.test: * tests/lreplace.test: * tests/string.test: * generic/tclCmdMZ.c (Tcl_StringObjCmd): * generic/tclUtil.c (TclGetIntForIndex): Applied Jeff Hobbs's string patch which includes the following changes [Bug: 1845]:
Diffstat (limited to 'generic/tclUtil.c')
-rw-r--r--generic/tclUtil.c48
1 files changed, 31 insertions, 17 deletions
diff --git a/generic/tclUtil.c b/generic/tclUtil.c
index 095100f..2031ccd 100644
--- a/generic/tclUtil.c
+++ b/generic/tclUtil.c
@@ -10,7 +10,7 @@
* See the file "license.terms" for information on usage and redistribution
* of this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tclUtil.c,v 1.8 1999/04/21 21:50:29 rjohnson Exp $
+ * RCS: @(#) $Id: tclUtil.c,v 1.9 1999/05/04 01:33:11 stanton Exp $
*/
#include "tclInt.h"
@@ -2051,31 +2051,45 @@ TclGetIntForIndex(interp, objPtr, endValue, indexPtr)
int *indexPtr; /* Location filled in with an integer
* representing an index. */
{
- Interp *iPtr = (Interp *) interp;
char *bytes;
- int index, length, result;
+ long longResult;
+ int length;
if (objPtr->typePtr == &tclIntType) {
*indexPtr = (int)objPtr->internalRep.longValue;
return TCL_OK;
}
-
+
bytes = Tcl_GetStringFromObj(objPtr, &length);
- if ((*bytes == 'e')
- && (strncmp(bytes, "end", (unsigned) length) == 0)) {
- index = endValue;
+
+ if ((*bytes != 'e') ||
+ (strncmp(bytes, "end", (length > 3) ? 3 : length) != 0)) {
+ if (Tcl_ExprLongObj(interp, objPtr, &longResult) != TCL_OK) {
+ return TCL_ERROR;
+ }
+ *indexPtr = longResult;
+ return TCL_OK;
+ }
+
+ if (length <= 3) {
+ *indexPtr = endValue;
+ } else if ((bytes[3] == '+') || (bytes[3] == '-')) {
+ /*
+ * This is our limited string expression evaluator
+ */
+ if (Tcl_ExprLong(interp, bytes+3, &longResult) != TCL_OK) {
+ return TCL_ERROR;
+ }
+ *indexPtr = endValue + longResult;
} else {
- result = Tcl_GetIntFromObj((Tcl_Interp *) NULL, objPtr, &index);
- if (result != TCL_OK) {
- if (iPtr != NULL) {
- Tcl_AppendStringsToObj(Tcl_GetObjResult(interp),
- "bad index \"", bytes,
- "\": must be integer or \"end\"", (char *) NULL);
- }
- return result;
- }
+ if (interp != NULL) {
+ Tcl_AppendStringsToObj(Tcl_GetObjResult(interp),
+ "invalid index \"", bytes,
+ "\": must be integer or ?end[+-]?expression",
+ (char *) NULL);
+ }
+ return TCL_ERROR;
}
- *indexPtr = index;
return TCL_OK;
}