summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--txr.132
-rw-r--r--txr.c23
2 files changed, 54 insertions, 1 deletions
diff --git a/txr.1 b/txr.1
index 067e9b85..045d760e 100644
--- a/txr.1
+++ b/txr.1
@@ -664,6 +664,12 @@ supports that behavior, or even that exact version.
If the option is specified more than once, the behavior is not specified.
+Compatibility can also be requested via the
+.code TXR_COMPAT
+environment variable instead of the
+.code -C
+option.
+
For more information, see the COMPATIBILITY section.
.meIP >> --gc-delta= number
@@ -37894,7 +37900,31 @@ option can be used to request emulation of old behavior.
The option was introduced in \*(TX 98, and so the oldest \*(TX version which
can be emulated is \*(TX 97.
-Here are version values which have a special meaning as arguments to the
+Side effects occur in the processing of the option. If the option is specified
+multiple times, the behavior is unspecified.
+
+.coNP Environment variable @ TXR_COMPAT
+
+If the
+.code TXR_COMPAT
+environment variable exists, and its value is not en empty string,
+it must contain a decimal integer. Its value is taken by \*(TX as a request
+to emulate old behaviors, just like the value of the
+.code -C
+option.
+
+If the variable has incorrect contents or an out-of-range value,
+\*(TX will print an error diagnostic and exit.
+
+If both
+.code -C
+and the
+.code TXR_COMPAT
+environment variable are supplied, the behavior is unspecified.
+
+.coNP Compatibility Version Values
+
+The following version values which have a special meaning as arguments to the
.code -C
option, along with a description of what behaviors are affected. For each
of these version values, the described behaviors are provided if
diff --git a/txr.c b/txr.c
index f9d20fdb..991666bb 100644
--- a/txr.c
+++ b/txr.c
@@ -54,6 +54,7 @@
#include "regex.h"
#include "arith.h"
#include "lisplib.h"
+#include "sysif.h"
#include "txr.h"
const wchli_t *version = wli(TXR_VER);
@@ -413,10 +414,27 @@ int txr_main(int argc, char **argv)
val enter_repl = nil;
val args_s = intern(lit("*args*"), user_package);
val self_path_s = intern(lit("self-path"), user_package);
+ val compat_var = lit("TXR_COMPAT");
+ val compat_val = getenv_wrap(compat_var);
list_collect_decl(arg_list, arg_tail);
setvbuf(stderr, 0, _IOLBF, 0);
+ if (compat_val && length(compat_val) != zero) {
+ val value = int_str(compat_val, nil);
+ if (!value) {
+ format(std_error,
+ lit("~a: environment variable ~a=~a must be decimal integer\n"),
+ prog_string, compat_var, compat_val, nao);
+ return EXIT_FAILURE;
+ }
+ if (!compat(value)) {
+ format(std_error, lit("~a: caused by environment variable ~a=~a\n"),
+ prog_string, compat_var, compat_val, nao);
+ return EXIT_FAILURE;
+ }
+ }
+
if (argc <= 1) {
#if HAVE_TERMIOS
banner();
@@ -792,6 +810,11 @@ int txr_main(int argc, char **argv)
repl:
#if HAVE_TERMIOS
+ if (compat_val)
+ format(std_output,
+ lit("Note: operating in TXR ~a compatibility mode "
+ "due to environment variable.\n"),
+ num(opt_compat), nao);
repl(bindings, std_input, std_output);
#endif
return 0;