X-Git-Url: http://mj.ucw.cz/gitweb/?a=blobdiff_plain;ds=inline;f=ucw%2Fopt-test.c;h=07fd6835f8c1ca7b1d5a69ed18c49744910feecf;hb=959566090f98dd31eaa67d3d5959b641e5fe902b;hp=b9bedde5160a8621c314b7a1524e39392f907a71;hpb=0db6e10eac28f38bfc3b325b13ad95107c58ce1e;p=libucw.git diff --git a/ucw/opt-test.c b/ucw/opt-test.c index b9bedde5..07fd6835 100644 --- a/ucw/opt-test.c +++ b/ucw/opt-test.c @@ -2,6 +2,7 @@ * UCW Library -- Parsing of command line options * * (c) 2013 Jan Moskyto Matejka + * (c) 2014 Martin Mares * * This software may be freely distributed and used according to the terms * of the GNU Lesser General Public License. @@ -11,6 +12,7 @@ #include #include #include +#include static void show_version(struct opt_item * opt UNUSED, const char * value UNUSED, void * data UNUSED) { printf("This is a simple tea boiling console v0.1.\n"); @@ -45,9 +47,10 @@ static int english = 0; static int sugar = 0; static int verbose = 1; static int with_gas = 0; -static clist black_magic; +static int *black_magic; static int pray = 0; static int water_amount = 0; +static int clean_pot = 1; static char * first_tea = NULL; #define MAX_TEA_COUNT 30 @@ -97,7 +100,7 @@ static struct cf_user_type teapot_temperature_t = { .dumper = (cf_dumper1*) teapot_temperature_dumper }; -static void opt_test_hook(struct opt_item * opt, uns event UNUSED, const char * value, void * data) { +static void opt_test_hook(struct opt_item * opt, uint event UNUSED, const char * value, void * data) { if (!show_hooks) return; if (opt) @@ -140,8 +143,9 @@ static struct opt_section options = { "\t\tOnly integer values allowed."), OPT_INC('v', "verbose", verbose, 0, "\tVerbose (the more -v, the more verbose)"), OPT_INC('q', "quiet", verbose, OPT_NEGATIVE, "\tQuiet (the more -q, the more quiet)"), - OPT_INT('b', NULL, black_magic, OPT_MULTIPLE, "\tUse black magic to make the tea extraordinarily delicious.\n\t\tMay be specified more than once to describe the amounts of black magic to be invoked in each step of tea boiling."), + OPT_INT_MULTIPLE('b', NULL, black_magic, 0, "\tUse black magic to make the tea extraordinarily delicious.\n\t\tMay be specified more than once to describe the amounts of black magic to be invoked in each step of tea boiling."), OPT_BOOL('p', "pray", pray, OPT_SINGLE, "\tPray before boiling"), + OPT_BOOL(0, "no-clean", clean_pot, OPT_NEGATIVE, "\tDo not clean the teapot before boiling"), OPT_STRING(OPT_POSITIONAL(1), NULL, first_tea, OPT_REQUIRED, ""), OPT_CALL(OPT_POSITIONAL_TAIL, NULL, add_tea, &tea_list, 0, ""), OPT_HELP(""), @@ -166,7 +170,7 @@ struct intnode { int main(int argc UNUSED, char ** argv) { cf_def_file = "etc/libucw"; - clist_init(&black_magic); + GARY_INIT(black_magic, 0); opt_parse(&options, argv+1); printf("English style: %s|", english ? "yes" : "no"); @@ -176,9 +180,11 @@ int main(int argc UNUSED, char ** argv) printf("Chosen teapot: %s|", teapot_type_str[set]); printf("Temperature: %d%s|", temperature.value, temp_scale_str[temperature.scale]); printf("Verbosity: %d|", verbose); - CLIST_FOR_EACH(struct intnode *, n, black_magic) - printf("Black magic: %d|", n->x); + uint magick = GARY_SIZE(black_magic); + for (uint i=0; i