6 * jmap - map from indices to values (based on libJudy)
8 * This provides a convenient wrapper for using JudyL arrays; using
9 * integers or pointers as an index, Judy arrays provide an efficient
10 * map to integers or pointers.
12 * jmap.h simply contains wrappers for a size_t-indexed size_t values, and
13 * jmap_type.h contain a wrapper macro for size_t->pointer maps and pointer
17 * // Silly example of associating data with arguments by pointer and int.
20 * #include <ccan/jmap/jmap_type.h>
24 * unsigned int length; // == 1 if !is_long.
27 * // Define jmap_arg_<op> and jmap_arg, for int -> argv.
28 * JMAP_DEFINE_UINTIDX_TYPE(char, arg);
29 * // Define jmap_opt_<op> and jmap_opt, for argv -> struct opt_detail *.
30 * JMAP_DEFINE_PTRIDX_TYPE(char, struct opt_detail, opt);
32 * int main(int argc, char *argv[])
35 * // This map is equivalent to the argv[] array. Silly example.
36 * struct jmap_arg *arg = jmap_arg_new();
37 * struct jmap_opt *opt = jmap_opt_new();
38 * struct opt_detail *d;
40 * // Note: this is not correct for real parsing!
41 * for (i = 0; i < argc; i++) {
42 * jmap_arg_add(arg, i, argv[i]);
43 * if (i < 1 || argv[i][0] != '-')
45 * d = malloc(sizeof(*d));
46 * if (argv[i][1] == '-') {
49 * d->length = strlen(argv[i]+2);
55 * jmap_opt_add(opt, argv[i], d);
58 * printf("Found %lu options:\n", jmap_opt_count(opt));
59 * for (i = jmap_arg_first(arg,-1); i!=-1; i = jmap_arg_next(arg,i,-1)) {
60 * char *a = jmap_arg_get(arg, i);
61 * d = jmap_opt_get(opt, a);
62 * printf(" Arg %i ('%s') is a %s of %u chars\n",
64 * d == NULL ? "normal argument"
65 * : d->is_long ? "long option"
67 * d == NULL ? strlen(a) : d->length);
68 * // We no longer need it, so free it here.
76 * License: LGPL (2 or any later version)
77 * Author: Rusty Russell <rusty@rustcorp.com.au>
79 int main(int argc, char *argv[])
84 if (strcmp(argv[1], "depends") == 0) {
85 printf("ccan/build_assert\n");
86 printf("ccan/compiler\n");
91 if (strcmp(argv[1], "libs") == 0) {