]> git.ozlabs.org Git - ccan/blob - ccan/tlist/_info
endian: add constant versions.
[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  * Example:
13  *      #include <err.h>
14  *      #include <stdio.h>
15  *      #include <stdlib.h>
16  *      #include <ccan/tlist/tlist.h>
17  *
18  *      // We could use TLIST_TYPE(children, struct child) to define this.
19  *      struct tlist_children {
20  *              struct list_head raw;
21  *              TCON(struct child *canary);
22  *      };
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                 printf("ccan/tcon\n");
70                 return 0;
71         }
72
73         return 1;
74 }