]> git.ozlabs.org Git - ccan/blob - ccan/objset/_info
ccanlint: enhance and streamline "output" testing lines.
[ccan] / ccan / objset / _info
1 #include "config.h"
2 #include <stdio.h>
3 #include <string.h>
4
5 /**
6  * objset - unordered set of pointers.
7  *
8  * This code implements a very simple unordered set of pointers.  It's very
9  * fast to add and check if something is in the set; it's implemented by
10  * a hash table.
11  *
12  * License: LGPL (v2.1 or any later version)
13  *
14  * Example:
15  *      // Silly example to determine if an arg starts with a -
16  *      #include <ccan/objset/objset.h>
17  *      #include <stdio.h>
18  *
19  *      struct objset_arg {
20  *              OBJSET_MEMBERS(const char *);
21  *      };
22  *
23  *      int main(int argc, char *argv[])
24  *      {
25  *              struct objset_arg args;
26  *              unsigned int i;
27  *
28  *              objset_init(&args);
29  *              // Put all args starting with - in the set.
30  *              for (i = 1; i < argc; i++)
31  *                      if (argv[i][0] == '-')
32  *                              objset_add(&args, argv[i]);
33  *
34  *              if (objset_empty(&args))
35  *                      printf("No arguments start with -.\n");
36  *              else {
37  *                      for (i = 1; i < argc; i++)
38  *                              if (objset_get(&args, argv[i]))
39  *                                      printf("%i,", i);
40  *                      printf("\n");
41  *              }
42  *              return 0;
43  *      }
44  *      // Given "a b c" outputs No arguments start with -.
45  *      // Given "a -b c" outputs 2,
46  *      // Given "a -b -c d" outputs 2,3,
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/hash\n");
56                 printf("ccan/htable\n");
57                 printf("ccan/tcon\n");
58                 return 0;
59         }
60
61         return 1;
62 }