]> git.ozlabs.org Git - ccan/blob - ccan/strmap/_info
b8768698bf87a40de3a9bbc7163488206a02b281
[ccan] / ccan / strmap / _info
1 #include "config.h"
2 #include <stdio.h>
3 #include <string.h>
4
5 /**
6  * strmap - an ordered map of strings to values
7  *
8  * This code implements an ordered map of strings as a critbit tree. See:
9  *
10  *  http://cr.yp.to/critbit.html
11  *  http://github.com/agl/critbit (which this code is based on)
12  *
13  * License: CC0 (but some dependencies are LGPL!)
14  * Author: Rusty Russell <rusty@rustcorp.com.au>
15  * Ccanlint:
16  *      license_depends_compat FAIL
17  *
18  * Example:
19  * #include <ccan/compiler/compiler.h>
20  * #include <ccan/strmap/strmap.h>
21  * #include <stdio.h>
22  *
23  * static bool dump(const char *member, size_t value, void *unused UNNEEDED)
24  * {
25  *      printf("%s at %zu. ", member, value);
26  *      // true means keep going with iteration.
27  *      return true;
28  * }
29  *
30  * int main(int argc, char *argv[])
31  * {
32  *      size_t i;
33  *      STRMAP(size_t) map;
34  *
35  *      strmap_init(&map);
36  *      for (i = 1; i < argc; i++)
37  *              // This only adds the first time for this arg.
38  *              strmap_add(&map, argv[i], i);
39  *
40  *      strmap_iterate(&map, dump, NULL);
41  *      printf("\n");
42  *      return 0;
43  * }
44  * // Given "foo" outputs "foo at 1. \n"
45  * // Given "foo bar" outputs "bar at 2. foo at 1. \n"
46  * // Given "foo foo bar zebra" outputs "bar at 3. foo at 1. zebra at 4. \n"
47  */
48 int main(int argc, char *argv[])
49 {
50         /* Expect exactly one argument */
51         if (argc != 2)
52                 return 1;
53
54         if (strcmp(argv[1], "depends") == 0) {
55                 printf("ccan/ilog\n"
56                        "ccan/short_types\n"
57                        "ccan/str\n"
58                        "ccan/tcon\n"
59                        "ccan/typesafe_cb\n");
60                 return 0;
61         }
62
63         return 1;
64 }