summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2014-09-09 21:42:09 -0700
committerKaz Kylheku <kaz@kylheku.com>2014-09-09 21:42:09 -0700
commit063b5a8c138e68237e11bcdac2f5763243b9bfc7 (patch)
treeed6378da3b19f580a3e71631f7a76cd0fbbcf1b6
parentaa25ebafa20941133e9b2ed8111d4195c099e637 (diff)
downloadtxr-063b5a8c138e68237e11bcdac2f5763243b9bfc7.tar.gz
txr-063b5a8c138e68237e11bcdac2f5763243b9bfc7.tar.bz2
txr-063b5a8c138e68237e11bcdac2f5763243b9bfc7.zip
* txr.c (help): List new --compat option.
(requires_arg, do_fixnum_opt, compat, array_dim, gc_delta): New static functions. (txr_main): Use do_fixnum_opt for handling options with integer argument. Add --compat alias for -C. * txr.1: Documented --compat. Added missing description of --debugger.
-rw-r--r--ChangeLog10
-rw-r--r--txr.14
-rw-r--r--txr.c115
3 files changed, 85 insertions, 44 deletions
diff --git a/ChangeLog b/ChangeLog
index 13336135..2604b623 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,15 @@
2014-09-09 Kaz Kylheku <kaz@kylheku.com>
+ * txr.c (help): List new --compat option.
+ (requires_arg, do_fixnum_opt, compat, array_dim, gc_delta): New static
+ functions.
+ (txr_main): Use do_fixnum_opt for handling options with integer
+ argument. Add --compat alias for -C.
+
+ * txr.1: Documented --compat. Added missing description of --debugger.
+
+2014-09-09 Kaz Kylheku <kaz@kylheku.com>
+
* txr.c (txr_main): Cleaning up option handling code.
Better checking for misused long options.
diff --git a/txr.1 b/txr.1
index e99a6809..d2c04fd3 100644
--- a/txr.1
+++ b/txr.1
@@ -100,6 +100,8 @@ query). This option does not suppress error generation during the parsing
of the query, only during its execution.
.IP -d
+.IP --debugger
+
Invoke the interactive txr debugger. See the DEBUGGER section.
.IP -v
@@ -192,6 +194,8 @@ than once. The query-file argument becomes optional if -p is used at least
once.
.IP "-C number"
+.IP "--compat=number"
+
Requests TXR to behave in a manner that is compatible with the specified
version of TXR. This makes a difference in situations when a release of
TXR breaks backward compatibility. If some version N+1 deliberately introduces
diff --git a/txr.c b/txr.c
index 39439dac..65880002 100644
--- a/txr.c
+++ b/txr.c
@@ -130,6 +130,7 @@ static void help(void)
" section at the bottom of the license.\n"
"--lisp-bindings Synonym for -l\n"
"--debugger Synonym for -d\n"
+"--compat=N Synonym for -C N\n"
"--gc-delta=N Invoke garbage collection when malloc activity\n"
" increments by N megabytes since last collection.\n"
"\n"
@@ -300,6 +301,56 @@ int main(int argc, char **argv)
return txr_main(argc, argv);
}
+static void requires_arg(val opt)
+{
+ format(std_error, lit("~a: option --~a requires an argument\n"),
+ prog_string, opt, nao);
+}
+
+static int do_fixnum_opt(int (*opt_func)(val), val opt, val arg)
+{
+ if (arg) {
+ val optval = int_str(arg, nil);
+
+ if (!optval || !fixnump(optval)) {
+ format(std_error, lit("~a: option -~a needs a small integer "
+ "argument, not ~a\n"), prog_string, opt,
+ arg, nao);
+ return 0;
+ }
+
+ return opt_func(optval);
+ }
+
+ requires_arg(opt);
+ return 0;
+}
+
+static int compat(val optval)
+{
+ if ((opt_compat = c_num(optval)) < 97) {
+ format(std_error, lit("~a: compatibility with versions "
+ "lower than 97 not supported by version ~a\n"),
+ prog_string, auto_str(version), nao);
+ return 0;
+ }
+ compat_fixup(opt_compat);
+ return 1;
+}
+
+static int array_dim(val optval)
+{
+ opt_arraydims = c_num(optval);
+ opt_print_bindings = 1;
+ return 1;
+}
+
+static int gc_delta(val optval)
+{
+ opt_gc_delta = c_num(mul(optval, num_fast(1048576)));
+ return 1;
+}
+
int txr_main(int argc, char **argv)
{
val specstring = nil;
@@ -371,16 +422,24 @@ int txr_main(int argc, char **argv)
/* Long opts with arguments */
if (equal(opt, lit("gc-delta"))) {
- if (!org)
- goto requires_arg;
- opt_gc_delta = c_num(mul(int_str(org, num_fast(10)),
- num_fast(1048576)));
+ if (!do_fixnum_opt(gc_delta, opt, arg))
+ return EXIT_FAILURE;
+ continue;
+ }
+
+ if (equal(opt, lit("compat"))) {
+ if (!do_fixnum_opt(compat, opt, org))
+ return EXIT_FAILURE;
continue;
}
/* Long opts with no arguments */
- if (org)
- goto takes_no_arg;
+ if (org) {
+ format(std_error,
+ lit("~a: option --~a takes no argument, ~a given\n"),
+ prog_string, opt, org, nao);
+ return EXIT_FAILURE;
+ }
if (equal(opt, lit("version"))) {
format(std_output, lit("~a: version ~a\n"),
@@ -427,18 +486,6 @@ int txr_main(int argc, char **argv)
return EXIT_FAILURE;
#endif
}
-
- requires_arg:
- format(std_error,
- lit("~a: option --~a requires an argument\n"),
- prog_string, opt, nao);
- return EXIT_FAILURE;
-
- takes_no_arg:
- format(std_error,
- lit("~a: option --~a takes no argument, ~a given\n"),
- prog_string, opt, org, nao);
- return EXIT_FAILURE;
}
@@ -448,9 +495,7 @@ int txr_main(int argc, char **argv)
val opt = chr_str(arg, one);
if (!arg_list) {
- format(std_error, lit("~a: option -~a needs argument\n"),
- prog_string, opt, nao);
-
+ requires_arg(opt);
return EXIT_FAILURE;
}
@@ -458,30 +503,12 @@ int txr_main(int argc, char **argv)
switch (c_chr(opt)) {
case 'a':
+ if (!do_fixnum_opt(array_dim, opt, arg))
+ return EXIT_FAILURE;
+ break;
case 'C':
- {
- val optval = int_str(arg, nil);
-
- if (!optval || !fixnump(optval)) {
- format(std_error, lit("~a: option -~a needs a small integer "
- "argument, not ~a\n"), prog_string, opt,
- arg, nao);
- return EXIT_FAILURE;
- }
-
- if (opt == chr('a')) {
- opt_arraydims = c_num(optval);
- opt_print_bindings = 1;
- } else {
- if ((opt_compat = c_num(optval)) < 97) {
- format(std_error, lit("~a: compatibility with versions "
- "lower than 97 not supported by version ~a\n"),
- prog_string, auto_str(version), nao);
- return EXIT_FAILURE;
- }
- compat_fixup(opt_compat);
- }
- }
+ if (!do_fixnum_opt(compat, opt, arg))
+ return EXIT_FAILURE;
break;
case 'c':
specstring = arg;