Hello,
I attached two patches and a Java class (which is not new,
but contains so many differences that a patch is bigger than
the complete code).
It contains the following new features:
- Expressions with , || or ?: now accept boolean string values.
- No error for [lreplace {} end end].
- lsearch is 8.4 compliant.
Have fun, Krischan
--
Christian Krone, SQL Datenbanksysteme GmbH
Mail mailto:[EMAIL PROTECTED]
--- Expression.java.org Fri Mar 10 19:05:01 2000
+++ Expression.java Mon Aug 14 20:16:00 2000
@@ -564,15 +575,20 @@
value.intValue = (value.doubleValue != 0) ? 1 : 0;
value.type = ExprValue.INT;
} else if (value.type == ExprValue.STRING) {
- if (interp.noEval == 0) {
- IllegalType(interp, ExprValue.STRING, operator);
- }
+ try {
+ boolean b = Util.getBoolean(null, value.stringValue);
+ value = new ExprValue(b ? 1 : 0);
+ } catch (TclException e) {
+ if (interp.noEval == 0) {
+ IllegalType(interp, ExprValue.STRING, operator);
+ }
- // Must set value.intValue to avoid referencing
- // uninitialized memory in the "if" below; the actual
- // value doesn't matter, since it will be ignored.
+ // Must set value.intValue to avoid referencing
+ // uninitialized memory in the "if" below; the actual
+ // value doesn't matter, since it will be ignored.
- value.intValue = 0;
+ value.intValue = 0;
+ }
}
if (((operator == AND) (value.intValue == 0))
|| ((operator == OR) (value.intValue != 0))) {
@@ -708,7 +724,12 @@
IllegalType(interp, value.type, operator);
}
if (value2.type == ExprValue.STRING) {
- IllegalType(interp, value.type, operator);
+ try {
+ boolean b = Util.getBoolean(null, value2.stringValue);
+ value2 = new ExprValue(b ? 1 : 0);
+ } catch (TclException e) {
+ IllegalType(interp, value2.type, operator);
+ }
}
break;
--- LreplaceCmd.java.orgSat Mar 18 00:31:30 2000
+++ LreplaceCmd.javaMon Aug 14 21:08:50 2000
@@ -30,30 +30,39 @@
throw new TclNumArgsException(interp, 1, argv,
"list first last ?element element ...?");
}
- int size = TclList.getLength(interp, argv[1]);
- int first;
- int last;
-
- first = Util.getIntForIndex(interp, argv[2], size-1);
- last = Util.getIntForIndex(interp, argv[3], size-1);
+ int size = TclList.getLength(interp, argv[1]);
+ int first = Util.getIntForIndex(interp, argv[2], size-1);
+ int last = Util.getIntForIndex(interp, argv[3], size-1);
+ int numToDelete;
if (first 0) {
first = 0;
}
- if (first = size) {
+
+ // Complain if the user asked for a start element that is greater
+ // than the list length. This won't ever trigger for the "end*"
+ // case as that will be properly constrained by getIntForIndex
+ // because we use size-1 (to allow for replacing the last elem).
+
+ if ((first = size) (size 0)) {
throw new TclException(interp, "list doesn't contain element " +
argv[2]);
}
if (last = size) {
last = size - 1;
}
+ if (first = last) {
+ numToDelete = (last - first + 1);
+ } else {
+ numToDelete = 0;
+ }
TclObject list = argv[1];
list.preserve();
list = list.takeExclusive();
try {
- TclList.replace(interp, list, first, last-first+1, argv, 4,
+ TclList.replace(interp, list, first, numToDelete, argv, 4,
argv.length-1);
interp.setResult(list);
} finally {
/*
* LsearchCmd.java
*
* Copyright (c) 1997 Cornell University.
* Copyright (c) 1997 Sun Microsystems, Inc.
* Copyright (c) 1998-1999 by Scriptics Corporation.
* Copyright (c) 2000 Christian Krone.
*
* See the file "license.terms" for information on usage and
* redistribution of this file, and for a DISCLAIMER OF ALL
* WARRANTIES.
*
* RCS: @(#) $Id: LsearchCmd.java,v 1.1.1.1 1998/10/14 21:09:20 cvsadmin Exp $
*
*/
package tcl.lang;
/*
* This class implements the built-in "lsearch" command in Tcl.
*/
class LsearchCmd implements Command {
static final private String options[] = {
"-ascii",
"-decreasing",
"-dictionary",
"-exact",
"-increasing",
"-integer",