Mercurial > hg > Gears > Gears
changeset 977:ed258cf51f40
add stub to WordCount
author | ichikitakahiro <e165713@ie.u-ryukyu.ac.jp> |
---|---|
date | Wed, 13 Oct 2021 00:23:59 +0900 |
parents | 76a86972c2eb |
children | 86e66f985a34 |
files | src/parallel_execution/examples/wc/Wc.h src/parallel_execution/examples/wc/WcImpl.cbc src/parallel_execution/examples/wc/WcImpl.h |
diffstat | 3 files changed, 61 insertions(+), 36 deletions(-) [+] |
line wrap: on
line diff
--- a/src/parallel_execution/examples/wc/Wc.h Mon Oct 11 20:52:24 2021 +0900 +++ b/src/parallel_execution/examples/wc/Wc.h Wed Oct 13 00:23:59 2021 +0900 @@ -1,9 +1,10 @@ typedef struct Wc <> { union Data* wc; WcResult* result; - union Data* string; + int line; + wcString* string; __code openFile(Impl* wc, __code next(...)); - __code putString(Impl* wc, __code next(...)); - __code countUp(Impl* wc, Type* string, __code next(...)); + __code putString(Impl* wc, line, __code next(...)); + __code countUp(Impl* wc, union Data* string, __code next(...)); __code next(...); } Wc;
--- a/src/parallel_execution/examples/wc/WcImpl.cbc Mon Oct 11 20:52:24 2021 +0900 +++ b/src/parallel_execution/examples/wc/WcImpl.cbc Wed Oct 13 00:23:59 2021 +0900 @@ -8,6 +8,19 @@ #interface "wcString.h" #define BUFFERING_MODE _IOLBF + /* + Read data from file + if eof + setup result + GOTO next(WcResult* result, ...); + + befor if eof + Count new line + Count word + Count char + TODO + */ + Wc* createWcImpl(struct Context* context, char* filename) { struct Wc* wc = new Wc(); struct WcImpl* wc_impl = new WcImpl(); @@ -16,13 +29,15 @@ wc_impl->buffer = NULL; wc->result = NULL; wc_impl->Keyword = NULL; - wc_impl->wordNum = 0; + wc_impl->lineNum = 0; wc_impl->putLine = 0; + wc_impl->strTable[100] = NULL; wc->openFile = C_openFileWcImpl; wc->putString = C_putStringWcImpl; wc->countUp = C_countUpWcImpl; return wc; } + __code openFile(struct WcImpl* wc, __code next(...)) { int fd = open(wc->filename, O_RDONLY); if (fd == -1){ @@ -41,47 +56,55 @@ } else { } - goto putString(next); -} -__code putString(struct WcImpl* wc, __code next(...)){ char* buff[1000]; strcpy(buff ,wc->buffer); - char* token = strtok(buff, "\n"); int count = 0; - while (token != NULL){ - if (count == wc->putLine){ - wcString* string = NEW(wcString); - string->str = token; - printf("putString:%s\n", string->str); - goto countUp((union Data*)string, next); - }else{ - } - token = strtok(NULL, "\n"); + wc->strTable[0] = strtok(buff, "\n"); + + while (wc->strTable[count] != NULL){ count++; - } - goto showResult(next); + wc->strTable[count] = strtok(NULL, "\n"); + } + int num = 0; + Gearef(context, Wc)->line = num; //応急のマクロ + goto putString(num, next); +} + +__code putString(struct WcImpl* wc, int line, __code next(...)){ + if (wc->strTable[line] != NULL){ + wcString* string = NEW(wcString); + string->str = wc->strTable[line]; + Gearef(context, Wc)->string = string; //応急のマクロ + goto countUp(string, next); + } else { + goto showResult(next); + } +} + +__code putStringWcImpl_stub(struct Context* context){ + //応急のstub + WcImpl* wc = (WcImpl*)GearImpl(context, Wc, wc); + int line = Gearef(context, Wc)->line; + enum Code next = Gearef(context, Wc)->next; + goto putStringWcImpl(context, wc, line, next); } __code countUp(struct WcImpl* wc, wcString* string, __code next(...)) { - /* - Read data from file - if eof - setup result - GOTO next(WcResult* result, ...); - - befor if eof - Count new line - Count word - Count char - TODO - */ - printf("%s\n", string->str); - wc->putLine = wc->putLine + 1; - goto putString(next); - + printf("countUp「%s」\n", string->str); + wc->lineNum = wc->lineNum + 1; + int num = wc->lineNum; + Gearef(context, Wc)->line = num; + goto putString(num, next); } +__code countUpWcImpl_stub(struct Context* context){ + //応急のstub + WcImpl* wc = (WcImpl*)GearImpl(context, Wc, wc); + wcString* string = Gearef(context, Wc)->string; + enum Code next = Gearef(context, Wc)->next; + goto countUpWcImpl(context, wc, string, next); +} __code showResult(struct WcImpl* wc, __code next(...)) { printf("EOF and finish codes\n");
--- a/src/parallel_execution/examples/wc/WcImpl.h Mon Oct 11 20:52:24 2021 +0900 +++ b/src/parallel_execution/examples/wc/WcImpl.h Wed Oct 13 00:23:59 2021 +0900 @@ -1,8 +1,9 @@ typedef struct WcImpl <> impl Wc { char* Keyword; - int wordNum; + int lineNum; int putLine; char* filename; char* buffer; + char* strTable[100]; union Data* file; } WcImpl;