Mercurial > hg > Papers > 2021 > ikki-sigos
changeset 15:92975c2d26b3
add GearBox and Christie form
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Tue, 04 May 2021 22:46:05 +0900 |
parents | 3be047dc2366 |
children | b434a3dd23cd |
files | Paper/codes/wc/Wc.h Paper/codes/wc/WcImpl.cbc Paper/codes/wc/WcImpl.h Paper/codes/wc/WcResult.h Paper/codes/wc/main.cbc Paper/codes/wc/wcTarget.h Paper/images/keyBasewordCountGearBox.graffle Paper/images/keyBasewordCountGearBox.pdf Paper/images/wordCountGearBox.graffle Paper/images/wordCountGearBox.pdf |
diffstat | 10 files changed, 86 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Paper/codes/wc/Wc.h Tue May 04 22:46:05 2021 +0900 @@ -0,0 +1,9 @@ +typedef struct Wc <> { + // all arguments names in this interfaces here + union Data* wc; // an implementation + WcResult* result; + // codeGear entries of this interface + __code openFile(Impl* wc, __code next(...)); + __code countUp(Impl* wc, __code next(WcResult* result, ...)); + __code next(...); +} Wc;
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Paper/codes/wc/WcImpl.cbc Tue May 04 22:46:05 2021 +0900 @@ -0,0 +1,52 @@ +#include "../../../context.h" +#include <stdio.h> +#impl "Wc.h" as "WcImpl.h" +#interface "WcResult.h" + +Wc* createWcImpl(struct Context* context, char* filename) { + struct Wc* wc = new Wc(); + struct WcImpl* wc_impl = new WcImpl(); + wc->wc = (union Data*)wc_impl; + wc_impl->filename = filename; + wc->result = NULL; + wc_impl->Keyword = NULL; + wc_impl->wordNum = 0; + wc->openFile = C_openFileWcImpl; + wc->countUp = C_countUpWcImpl; + return wc; +} +__code openFile(struct WcImpl* wc, __code next(...)) { + FILE* file = fopen(wc->filename, "r"); + if (file == NULL){ + printf("ファイルが開ませんでした\n"); + exit(1); + } else { + printf("file open"); + } + wc->file = (union Data*)file; + goto countUp(wc, next); +} + +__code countUp(struct WcImpl* wc,__code next(WcResult* result, ...)) { + /* + Read data from file + if eof + setup result + GOTO next(WcResult* result, ...); + + befor if eof + Count new line + Count word + Count char + TODO + */ + int N = 256; + char str[N]; + int line = 0; + while(fgets(str, N, wc->file)!=NULL){ + printf("%s\n",str); + line++; + } + printf("line = %d\n", line); + //goto countUp(wc, next); +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Paper/codes/wc/WcImpl.h Tue May 04 22:46:05 2021 +0900 @@ -0,0 +1,6 @@ +typedef struct WcImpl <> impl Wc { + char* Keyword; + int wordNum; + char* filename; + union Data* file; +} WcImpl;
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Paper/codes/wc/WcResult.h Tue May 04 22:46:05 2021 +0900 @@ -0,0 +1,4 @@ +typedef struct WcResult <> { + int wordNum; + char* str; +} WcResult;
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Paper/codes/wc/main.cbc Tue May 04 22:46:05 2021 +0900 @@ -0,0 +1,10 @@ +#data "wcTarget.h" +#interface "Wc.h" + + +__code startCode(struct GearsData* gearsData) { + Wc* wc = createWcImpl(context, /* file name */ gearsData->args[1] ); + goto wc->openFile(code2); +} + +