tlist: typesafe variant of list module.
[ccan] / ccan / tlist / _info
1 #include <stdio.h>
2 #include <string.h>
3 #include "config.h"
4
5 /**
6  * tlist - typesafe double linked list routines
7  *
8  * The list header contains routines for manipulating double linked lists;
9  * this extends it so you can create list head types which only accomodate
10  * a specific entry type.
11  *
12  * You use TLIST_TYPE() to define the specific struct tlist_<name>, then use
13  * the tlist_* variants of the various list_* operations.
14  *
15  * Example:
16  *      #include <err.h>
17  *      #include <stdio.h>
18  *      #include <stdlib.h>
19  *      #include <ccan/tlist/tlist.h>
20  *
21  *      // Defines struct tlist_children
22  *      TLIST_TYPE(children, struct child);
23  *      struct parent {
24  *              const char *name;
25  *              struct tlist_children children;
26  *              unsigned int num_children;
27  *      };
28  *
29  *      struct child {
30  *              const char *name;
31  *              struct list_node list;
32  *      };
33  *
34  *      int main(int argc, char *argv[])
35  *      {
36  *              struct parent p;
37  *              struct child *c;
38  *              unsigned int i;
39  *
40  *              if (argc < 2)
41  *                      errx(1, "Usage: %s parent children...", argv[0]);
42  *
43  *              p.name = argv[1];
44  *              tlist_init(&p.children);
45  *              for (i = 2; i < argc; i++) {
46  *                      c = malloc(sizeof(*c));
47  *                      c->name = argv[i];
48  *                      tlist_add(&p.children, c, list);
49  *                      p.num_children++;
50  *              }
51  *
52  *              printf("%s has %u children:", p.name, p.num_children);
53  *              tlist_for_each(&p.children, c, list)
54  *                      printf("%s ", c->name);
55  *              printf("\n");
56  *              return 0;
57  *      }
58  *
59  * License: LGPL
60  * Author: Rusty Russell <rusty@rustcorp.com.au>
61  */
62 int main(int argc, char *argv[])
63 {
64         if (argc != 2)
65                 return 1;
66
67         if (strcmp(argv[1], "depends") == 0) {
68                 printf("ccan/list\n");
69                 return 0;
70         }
71
72         return 1;
73 }