]> git.ozlabs.org Git - ccan/blob - ccan/generator/_info
e40d7bbb28c602c5e8b984a41ab203e5e82943de
[ccan] / ccan / generator / _info
1 #include "config.h"
2 #include <stdio.h>
3 #include <string.h>
4
5 #include <ccan/coroutine/coroutine.h>
6
7 /**
8  * generator - generators for C
9  *
10  * Generators are a limited form of coroutines, which provide a useful
11  * way of expressing certain problems, while being much simpler to
12  * understand than general coroutines.
13  *
14  * Instead of returning a single value, a generator can "yield" a
15  * value at various points during its execution.  Whenever it yields,
16  * the "calling" function resumes and obtains the newly yielded value
17  * to work with.  When the caller asks for the next value from the
18  * generator, the generator resumes execution from the last yield and
19  * continues onto the next.
20  *
21  * Example:
22  *      #include <stdio.h>
23  *      #include <ccan/generator/generator.h>
24  *
25  *      generator_def_static(simple_gen, int)
26  *      {
27  *              generator_yield(1);
28  *              generator_yield(3);
29  *              generator_yield(17);
30  *      }
31  *
32  *      int main(int argc, char *argv[])
33  *      {
34  *              generator_t(int) gen = simple_gen();
35  *              int *ret;
36  *
37  *              while ((ret = generator_next(gen)) != NULL) {
38  *                      printf("Generator returned %d\n", *ret);
39  *              }
40  *
41  *              return 0;
42  *      }
43  *
44  * Author: David Gibson <david@gibson.dropbear.id.au>
45  * License: LGPL (v2.1 or any later version)
46  *
47  * Ccanlint:
48  *      // We need several gcc extensions
49  *      objects_build_without_features FAIL
50  *      tests_compile_without_features FAIL
51  *      tests_helpers_compile_without_features FAIL
52  */
53 int main(int argc, char *argv[])
54 {
55         /* Expect exactly one argument */
56         if (argc != 2)
57                 return 1;
58
59         if (strcmp(argv[1], "depends") == 0) {
60                 printf("ccan/alignof\n");
61                 printf("ccan/coroutine\n");
62                 printf("ccan/cppmagic\n");
63                 printf("ccan/compiler\n");
64                 return 0;
65         }
66
67         if (strcmp(argv[1], "ported") == 0) {
68 #if COROUTINE_AVAILABLE
69                 printf("\n");
70                 return 1;
71 #else
72                 printf("Needs coroutine support\n");
73 #endif
74         }
75
76         if (strcmp(argv[1], "testdepends") == 0) {
77                 printf("ccan/str\n");
78                 return 0;
79         }
80
81         return 1;
82 }