From 8bb9388feeaa9f981862cab608166105ed31a03c Mon Sep 17 00:00:00 2001 From: Kaz Kyheku Date: Fri, 6 Mar 2020 21:07:46 -0800 Subject: getopts: new feature: cumulative options. An option declared as (cumul ) indicates that it is of 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. --- lisplib.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lisplib.c') diff --git a/lisplib.c b/lisplib.c index 8fc31c9a..d1a2dd06 100644 --- a/lisplib.c +++ b/lisplib.c @@ -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); -- cgit v1.2.3