summaryrefslogtreecommitdiffstats
path: root/generic/tclUtil.c
diff options
context:
space:
mode:
authorstanton <stanton>1999-05-06 18:46:42 (GMT)
committerstanton <stanton>1999-05-06 18:46:42 (GMT)
commitf832cd22b120385368e264c684cf8d874014bf3b (patch)
tree9c149c65795f698ce02226359670d8bc28d9895a /generic/tclUtil.c
parenta23a8f73b3f2aba2722a1363e2d822018fbf504c (diff)
downloadtcl-f832cd22b120385368e264c684cf8d874014bf3b.zip
tcl-f832cd22b120385368e264c684cf8d874014bf3b.tar.gz
tcl-f832cd22b120385368e264c684cf8d874014bf3b.tar.bz2
* doc/string.n:
* tests/cmdIL.test: * tests/cmdMZ.test: * tests/error.test: * tests/ioCmd.test: * tests/lindex.test: * tests/linsert.test: * tests/lrange.test: * tests/lreplace.test: * tests/string.test: * tests/cmdIL.test: * generic/tclUtil.c: * generic/tclCmdMZ.c: Replaced "string icompare/iequal" with -nocase and -length switches to "string compare/equal". Added a -nocase option to "string map". Changed index syntax to allow integer or end?-integer? instead of a full expression. This is much simpler with safeTcl scripts since it avoids double substitution issues.
Diffstat (limited to 'generic/tclUtil.c')
-rw-r--r--generic/tclUtil.c29
1 files changed, 15 insertions, 14 deletions
diff --git a/generic/tclUtil.c b/generic/tclUtil.c
index 2031ccd..16ec609 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.9 1999/05/04 01:33:11 stanton Exp $
+ * RCS: @(#) $Id: tclUtil.c,v 1.10 1999/05/06 18:46:42 stanton Exp $
*/
#include "tclInt.h"
@@ -2021,13 +2021,14 @@ TclLooksLikeInt(bytes, length)
*
* This procedure returns an integer corresponding to the list index
* held in a Tcl object. The Tcl object's value is expected to be
- * either an integer or the string "end".
+ * either an integer or a string of the form "end([+-]integer)?".
*
* Results:
* The return value is normally TCL_OK, which means that the index was
* successfully stored into the location referenced by "indexPtr". If
* the Tcl object referenced by "objPtr" has the value "end", the
- * value stored is "endValue". If "objPtr"s values is not "end" and
+ * value stored is "endValue". If "objPtr"s values is not of the form
+ * "end([+-]integer)?" and
* can not be converted to an integer, TCL_ERROR is returned and, if
* "interp" is non-NULL, an error message is left in the interpreter's
* result object.
@@ -2052,8 +2053,7 @@ TclGetIntForIndex(interp, objPtr, endValue, indexPtr)
* representing an index. */
{
char *bytes;
- long longResult;
- int length;
+ int length, offset;
if (objPtr->typePtr == &tclIntType) {
*indexPtr = (int)objPtr->internalRep.longValue;
@@ -2064,28 +2064,29 @@ TclGetIntForIndex(interp, objPtr, endValue, indexPtr)
if ((*bytes != 'e') ||
(strncmp(bytes, "end", (length > 3) ? 3 : length) != 0)) {
- if (Tcl_ExprLongObj(interp, objPtr, &longResult) != TCL_OK) {
- return TCL_ERROR;
+ if (Tcl_GetIntFromObj(NULL, objPtr, &offset) != TCL_OK) {
+ goto intforindex_error;
}
- *indexPtr = longResult;
+ *indexPtr = offset;
return TCL_OK;
}
if (length <= 3) {
*indexPtr = endValue;
- } else if ((bytes[3] == '+') || (bytes[3] == '-')) {
+ } else if (bytes[3] == '-') {
/*
* This is our limited string expression evaluator
*/
- if (Tcl_ExprLong(interp, bytes+3, &longResult) != TCL_OK) {
+ if (Tcl_GetInt(interp, bytes+3, &offset) != TCL_OK) {
return TCL_ERROR;
}
- *indexPtr = endValue + longResult;
+ *indexPtr = endValue + offset;
} else {
- if (interp != NULL) {
+ intforindex_error:
+ if ((Interp *)interp != NULL) {
Tcl_AppendStringsToObj(Tcl_GetObjResult(interp),
- "invalid index \"", bytes,
- "\": must be integer or ?end[+-]?expression",
+ "bad index \"", bytes,
+ "\": must be integer or end?-integer?",
(char *) NULL);
}
return TCL_ERROR;