summaryrefslogtreecommitdiffhomepage
path: root/misc/examples/coread.c
diff options
context:
space:
mode:
author_Tradam <[email protected]>2023-09-08 01:29:47 +0000
committerGitHub <[email protected]>2023-09-08 01:29:47 +0000
commit3c76c7f3d5db3f9586a90d03f8fbb02d79de9acd (patch)
treeafbe4b540967223911f7c5de36559b82154f02f3 /misc/examples/coread.c
parent0841165881871ee01b782129be681209aeed2423 (diff)
parent1a72205fe05c2375cfd380dd8381a8460d9ed8d1 (diff)
downloadSTC-modified-modified.tar.gz
STC-modified-modified.zip
Merge branch 'stclib:master' into modifiedHEADmodified
Diffstat (limited to 'misc/examples/coread.c')
-rw-r--r--misc/examples/coread.c39
1 files changed, 0 insertions, 39 deletions
diff --git a/misc/examples/coread.c b/misc/examples/coread.c
deleted file mode 100644
index 0a7f4816..00000000
--- a/misc/examples/coread.c
+++ /dev/null
@@ -1,39 +0,0 @@
-#include <stc/cstr.h>
-#include <stc/algo/coroutine.h>
-#include <errno.h>
-
-// Read file line by line using coroutines:
-
-struct file_nextline {
- const char* filename;
- int cco_state;
- FILE* fp;
- cstr line;
-};
-
-bool file_nextline(struct file_nextline* U)
-{
- cco_begin(U)
- U->fp = fopen(U->filename, "r");
- U->line = cstr_init();
-
- while (cstr_getline(&U->line, U->fp))
- cco_yield(true);
-
- cco_final: // this label is required.
- printf("finish\n");
- cstr_drop(&U->line);
- fclose(U->fp);
- cco_end(false);
-}
-
-int main(void)
-{
- struct file_nextline it = {__FILE__};
- int n = 0;
- while (file_nextline(&it))
- {
- printf("%3d %s\n", ++n, cstr_str(&it.line));
- //if (n == 10) cco_stop(&it);
- }
-}