diff options
author | Kaz Kyheku <kaz@kylheku.com> | 2020-03-06 21:07:46 -0800 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2020-03-06 21:07:46 -0800 |
commit | 8bb9388feeaa9f981862cab608166105ed31a03c (patch) | |
tree | 53a372d7687d2eae16e866c55c7bc803ece3dbe3 /lisplib.c | |
parent | a7f62122d54d2d70e2ae1afda9b27df969f75e5e (diff) | |
download | txr-8bb9388feeaa9f981862cab608166105ed31a03c.tar.gz txr-8bb9388feeaa9f981862cab608166105ed31a03c.tar.bz2 txr-8bb9388feeaa9f981862cab608166105ed31a03c.zip |
getopts: new feature: cumulative options.
An option declared as (cumul <type>) indicates that it is of
type <type>, and that multiple occurrences of the option
produce values that are accumulated into a list.
The accumulation is in reverse order: the rightmost
occurrence ends up the first in the list.
* lisplib.c (getopts_set_entries): Add cumul to list of
interned symbols, so that the getopts.tl code isn't mistakenly
working with sys:cumul.
* share/txr/stdlib/getopts.tl (opt-parsed): New slot, cumul.
(opt-desc basic-type p, opt-desc list-type-p, opt-desc
cumul-type-p): New methods.
(opt-desc check): Rework type validity check using the new
methods.
(opt-parsed convert-type): Support 'cumul type by
instantiating an opt-parsed object for the wrapped type,
and stealing its converted argument into the current object,
and setting the cumul flag.
(opts add-opt, option-base add-opt): Support options that have
the cumul flag set by accumulating list values. The code is
different due to different amounts of encapsulation. The opts
structure stores the raw opt-parsed objects, whereas
option-base just takes the decoded values.
(opthelp): Parse through the (cumul ...) type syntax, so
cumulative options are printed in the help text the same way
as if they were non-cumulative.
* txr.1: Documented.
Diffstat (limited to 'lisplib.c')
-rw-r--r-- | lisplib.c | 2 |
1 files changed, 1 insertions, 1 deletions
@@ -479,7 +479,7 @@ static val getopts_set_entries(val dlt, val fun) }; val name_noload[] = { lit("short"), lit("long"), lit("helptext"), lit("type"), - lit("in-args"), lit("out-args"), nil + lit("in-args"), lit("out-args"), lit("cumul"), nil }; set_dlt_entries(dlt, name, fun); intern_only(name_noload); |