]> git.ozlabs.org Git - ccan/blob - ccan/strmap/_info
c128cc27b5c3cbe941cd5e72a4bef2ae2c043f91
[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/strmap/strmap.h>
20  * #include <stdio.h>
21  *
22  * static bool dump(const char *member, size_t value, void *unused)
23  * {
24  *      printf("%s at %zu. ", member, value);
25  *      // true means keep going with iteration.
26  *      return true;
27  * }
28  *
29  * int main(int argc, char *argv[])
30  * {
31  *      size_t i;
32  *      STRMAP(size_t) map;
33  *
34  *      strmap_init(&map);
35  *      for (i = 1; i < argc; i++)
36  *              // This only adds the first time for this arg.
37  *              strmap_add(&map, argv[i], i);
38  *
39  *      strmap_iterate(&map, dump, NULL);
40  *      printf("\n");
41  *      return 0;
42  * }
43  * // Given "foo" outputs "foo at 1. \n"
44  * // Given "foo bar" outputs "bar at 2. foo at 1. \n"
45  * // Given "foo foo bar zebra" outputs "bar at 3. foo at 1. zebra at 4. \n"
46  */
47 int main(int argc, char *argv[])
48 {
49         /* Expect exactly one argument */
50         if (argc != 2)
51                 return 1;
52
53         if (strcmp(argv[1], "depends") == 0) {
54                 printf("ccan/ilog\n"
55                        "ccan/short_types\n"
56                        "ccan/str\n"
57                        "ccan/tcon\n"
58                        "ccan/typesafe_cb\n");
59                 return 0;
60         }
61
62         return 1;
63 }