]> git.ozlabs.org Git - ccan/blob - ccan/tlist2/_info
Fix typos detected by github.com/client9/misspell
[ccan] / ccan / tlist2 / _info
1 #include "config.h"
2 #include <stdio.h>
3 #include <string.h>
4
5 /**
6  * tlist2 - typesafe double linked list routines, alternative form
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 accommodate
10  * a specific entry type.
11  *
12  * Compared to 'tlist', this:
13  *
14  *  - does not allow (or require) declaring an extra struct (uses anonymous
15  *    structs)
16  *  - encodes the member offset into the type (and as a result doesn't need the
17  *    member name, but requires the source list)
18  *
19  * Based on tlist by: Rusty Russell <rusty@rustcorp.com.au>
20  *
21  * Example:
22  *      #include <err.h>
23  *      #include <stdio.h>
24  *      #include <stdlib.h>
25  *      #include <ccan/tlist2/tlist2.h>
26  *
27  *      struct child {
28  *              const char *name;
29  *              struct list_node list;
30  *      };
31  *
32  *      struct parent {
33  *              const char *name;
34  *              TLIST2(struct child, list) children;
35  *              unsigned int num_children;
36  *      };
37  *
38  *      int main(int argc, char *argv[])
39  *      {
40  *              struct parent p;
41  *              struct child *c;
42  *              unsigned int i;
43  *
44  *              if (argc < 2)
45  *                      errx(1, "Usage: %s parent children...", argv[0]);
46  *
47  *              p.name = argv[1];
48  *              tlist2_init(&p.children);
49  *              for (i = 2; i < argc; i++) {
50  *                      c = malloc(sizeof(*c));
51  *                      c->name = argv[i];
52  *                      tlist2_add(&p.children, c);
53  *                      p.num_children++;
54  *              }
55  *
56  *              printf("%s has %u children:", p.name, p.num_children);
57  *              tlist2_for_each(&p.children, c)
58  *                      printf("%s ", c->name);
59  *              printf("\n");
60  *              return 0;
61  *      }
62  *
63  * License: LGPL
64  * Author: Cody P Schafer <dev@codyps.com>
65  */
66 int main(int argc, char *argv[])
67 {
68         if (argc != 2)
69                 return 1;
70
71         if (strcmp(argv[1], "depends") == 0) {
72                 printf("ccan/list\n");
73                 printf("ccan/tcon\n");
74                 return 0;
75         }
76
77         return 1;
78 }