opt: add an int decrementing helper function
authorDouglas Bagnall <douglas@halo.gen.nz>
Fri, 20 Jun 2014 02:34:02 +0000 (14:34 +1200)
committerRusty Russell <rusty@rustcorp.com.au>
Mon, 23 Jun 2014 00:57:23 +0000 (10:27 +0930)
commit63b0055673d2c55ff90f8b7bd8a7c5fe30f83269
tree08b507124a939f0cf2c8b50ca207610c5acb5698
parentb377324e5c1ad356b535f4c3724251c626abdf40
opt: add an int decrementing helper function

opt_dec_intval decrements an int value, just as opt_inc_intval
increments.

There is not much more to say, other than it allows this
kind of thing, with balanced opposing options:

    static int opt_verbosity = 0;
    static struct opt_table options[] = {
            OPT_WITHOUT_ARG("-q|--quiet", opt_dec_intval,
                            &opt_verbosity, "print less"),
            OPT_WITHOUT_ARG("-v|--verbose", opt_inc_intval,
                            &opt_verbosity, "print more"),
            OPT_ENDTABLE
    };

which is an occasionally seen idiom.  It allows, e.g., people who like
quiet to use `alias foo='foo -q'`, while letting them get back to
normal and verbose modes with various amounts of '-v's.

Signed-off-by: Douglas Bagnall <douglas@halo.gen.nz>
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
ccan/opt/helpers.c
ccan/opt/opt.h