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