aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSteve Bennett <steveb@workware.net.au>2021-04-03 14:00:22 +1000
committerSteve Bennett <steveb@workware.net.au>2021-04-03 14:06:53 +1000
commit3703a49423578649b67abe0e0457842e4ff911a2 (patch)
treef40294cad6b7f25cce1a68db8193e91e3ff19d4e
parentc3df59264eb27d4914c21f0901350a6d9eeb1807 (diff)
downloadjimtcl-3703a49423578649b67abe0e0457842e4ff911a2.zip
jimtcl-3703a49423578649b67abe0e0457842e4ff911a2.tar.gz
jimtcl-3703a49423578649b67abe0e0457842e4ff911a2.tar.bz2
expr: allow existing multiple argument support with --compat
Some users may not be ready to immediately move to the single-argument expr, so provide a --compat option to configure to support the previous behaviour as a transition strategy. Signed-off-by: Steve Bennett <steveb@workware.net.au>
-rw-r--r--auto.def5
-rw-r--r--jim.c26
-rw-r--r--jim_tcl.txt2
3 files changed, 29 insertions, 4 deletions
diff --git a/auto.def b/auto.def
index 8ab5022..3f2f5a0 100644
--- a/auto.def
+++ b/auto.def
@@ -21,6 +21,7 @@ options {
maintainer => {Enable the [debug] command and JimPanic}
full => "Enable some optional features: ipv6, ssl, math, utf8, and some extensions (see --extinfo)"
allextmod => "Enable all non-default extensions as modules if prerequisites are found"
+ compat => "Enable some backward compatibility behaviour"
extinfo => "Show information about available extensions"
with-jim-shared shared => "Build a shared library instead of a static library"
jim-regexp=1 => "Prefer POSIX regex if over the the built-in (Tcl-compatible) regex"
@@ -432,6 +433,10 @@ if {[opt-bool references]} {
msg-result "Enabling references"
define JIM_REFERENCES
}
+if {[opt-bool compat]} {
+ msg-result "Enabling compatibility mode"
+ define JIM_COMPAT
+}
if {[opt-bool shared with-jim-shared]} {
msg-result "Building shared library"
} else {
diff --git a/jim.c b/jim.c
index 64f47bd..cfc0f8f 100644
--- a/jim.c
+++ b/jim.c
@@ -13598,11 +13598,31 @@ static int Jim_UplevelCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *
/* [expr] */
static int Jim_ExprCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
+ int retcode;
+
if (argc == 2) {
- return Jim_EvalExpression(interp, argv[1]);
+ retcode = Jim_EvalExpression(interp, argv[1]);
}
- Jim_WrongNumArgs(interp, 1, argv, "expression");
- return JIM_ERR;
+#ifndef JIM_COMPAT
+ else {
+ Jim_WrongNumArgs(interp, 1, argv, "expression");
+ retcode = JIM_ERR;
+ }
+#else
+ else if (argc > 2) {
+ Jim_Obj *objPtr;
+
+ objPtr = Jim_ConcatObj(interp, argc - 1, argv + 1);
+ Jim_IncrRefCount(objPtr);
+ retcode = Jim_EvalExpression(interp, objPtr);
+ Jim_DecrRefCount(interp, objPtr);
+ }
+ else {
+ Jim_WrongNumArgs(interp, 1, argv, "expression ?...?");
+ return JIM_ERR;
+ }
+#endif
+ return retcode;
}
/* [break] */
diff --git a/jim_tcl.txt b/jim_tcl.txt
index aea64f4..49972b7 100644
--- a/jim_tcl.txt
+++ b/jim_tcl.txt
@@ -65,7 +65,7 @@ Changes since 0.80
8. `lsort -index` now supports multiple indices
9. Add support for `lsort -stride`
10. `open` now supports POSIX-style access arguments
-11. TIP 526, `expr` now only allows a single argument
+11. TIP 526, `expr` now only allows a single argument (unless --compat is enabled)
Changes between 0.79 and 0.80
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~