diff options
Diffstat (limited to 'misc/examples/coread.c')
| -rw-r--r-- | misc/examples/coread.c | 18 |
1 files changed, 9 insertions, 9 deletions
diff --git a/misc/examples/coread.c b/misc/examples/coread.c index a3eac7f9..6b0bfb37 100644 --- a/misc/examples/coread.c +++ b/misc/examples/coread.c @@ -1,30 +1,30 @@ #include <stc/cstr.h> -#include <stc/algo/ccoro.h> +#include <stc/algo/coroutine.h> #include <errno.h> // Read file line by line using coroutines: struct file_nextline { const char* filename; - int ccoro_state; + int cco_state; FILE* fp; cstr line; }; cstr file_nextline(struct file_nextline* U) { - ccoro_execute(U, + cco_begin(U) U->fp = fopen(U->filename, "r"); U->line = cstr_NULL; while (cstr_getline(&U->line, U->fp)) - ccoro_yield (cstr_clone(U->line)); + cco_yield(cstr_clone(U->line)); - ccoro_final: // ccoro_final is needed to support ccoro_stop. + cco_final: // cco_final is needed to support cco_stop. printf("finish\n"); cstr_drop(&U->line); fclose(U->fp); - ); + cco_end(); return cstr_NULL; } @@ -33,11 +33,11 @@ int main(void) { struct file_nextline z = {__FILE__}; int n = 0; do { - c_with (cstr line = file_nextline(&z), ccoro_alive(&z), cstr_drop(&line)) { + c_with (cstr line = file_nextline(&z), cco_alive(&z), cstr_drop(&line)) { printf("%3d %s\n", ++n, cstr_str(&line)); // stop after 15 lines: - if (n == 15) file_nextline(ccoro_stop(&z)); + if (n == 15) file_nextline(cco_stop(&z)); } - } while (ccoro_alive(&z)); + } while (cco_alive(&z)); } |
