# HG changeset patch # User Shinji KONO # Date 1620207827 -32400 # Node ID 2d91b4d2569c64dcfd8a0a450993fdef2d944bcf # Parent f3112bbff42889d1607435594a0a376a96fe599b ... diff -r f3112bbff428 -r 2d91b4d2569c Paper/codes/wc/FileChrs.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Paper/codes/wc/FileChrs.h Wed May 05 18:43:47 2021 +0900 @@ -0,0 +1,11 @@ +typedef struct FileChrs { + int mode; /* rw .. */ + Key *key; + Ack *ack; + Record *record; + Output *reader; + Data *fileImpl ; + __code setOutput(Output *output,__code next(...)) ; + __code Open(Key *key, Output reader, __code next(...)) ; + __code Ack(Ack *ack, Output reader, __code next(...)) ; +} FileChrs; diff -r f3112bbff428 -r 2d91b4d2569c Paper/codes/wc/FileImpl.h --- a/Paper/codes/wc/FileImpl.h Wed May 05 15:38:07 2021 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,7 +0,0 @@ -typedef struct UnixFileImpl <> ipml File { - int fd; // unix file descriptor - int mode; - Data *fileImpl ; - __code unixOpen(UnixFileImpl* file,Key *key, __code next(Block *block,...)); - __code uniAck(UnixFileImpl* file,Ack *ack, __code next(Block *block,...)); -} File; diff -r f3112bbff428 -r 2d91b4d2569c Paper/codes/wc/TopologyManager.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Paper/codes/wc/TopologyManager.h Wed May 05 18:43:47 2021 +0900 @@ -0,0 +1,13 @@ +// Topologymanger connect file impl and wc impl +// setput remote data Gear Manager + +run() { + foreach imple in (codeGearList) { + intf = create imple + imple->intf = im + } + foreach imple in (codeGearList) { + imple->intf->setOutput(); + } + goto imple->intf->start(); +} diff -r f3112bbff428 -r 2d91b4d2569c Paper/codes/wc/UnixChrisFileImpl.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Paper/codes/wc/UnixChrisFileImpl.cpp Wed May 05 18:43:47 2021 +0900 @@ -0,0 +1,56 @@ +#include +#impl "Wc.h" as "WcChrsImpl.h" + +typedef struct UnixFileImpl <> ipml File { + int fd; // unix file descriptor + int mode; + Data *fileImpl ; + __code setOutput(UnixFileImpl* file, Output *output,__code next(...)) ; + __code unixOpen(UnixFileImpl* file,Key *key, Output reader, __code next(...)) ; + __code uniAck(UnixFileImpl* file,Ack *ack, Output reader, __code next(...)) ; +} File; + +File* createUnixChrisFileImpl(struct Context* context) { + File *file = new File(); + file->ChrisFileImpl = (union Data*)new ChrisFileImpl(); + return file; +} + +// Topology manageres determins input / output connection +// +__code setOutput(Wc* wc, Output *output,__code next(...)) { + file->reader = output ; + goto next(...); +} + +int +putBlock(UnixFileImpl* file, Output *reader) { + Block *block = new Block(); + int len = read(fd, BUFSIZE, block->data); + if (len <=0 ) { + block->eof |= BLOCK_FLAG_EOF; + return 0; + } + reader->put(block); + return 1 ; +} + +__code unixOpen(UnixFileImpl* file,Key *key, Output reader, __code next(...)) { + file->fd = open(key->path,unix_mode(key->modde)); + if (fd < 0) { + goto error("can't open"); + } + if (putBlock(file,reader)) { + putBlock(file,reader); + } + goto next(file,...); +} + +__code uniAck(UnixFileImpl* file,Ack *ack, Output reader, __code next(...)) { + if (!ack->isOk) { + close(fd); + goto next(...); + } + putBlock(file,reader); + goto next(...); // file is automaticaly put into local dataGearManger/input +} diff -r f3112bbff428 -r 2d91b4d2569c Paper/codes/wc/UnixFileImpl.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Paper/codes/wc/UnixFileImpl.h Wed May 05 18:43:47 2021 +0900 @@ -0,0 +1,7 @@ +typedef struct UnixFileImpl <> ipml File { + int fd; // unix file descriptor + int mode; + Data *fileImpl ; + __code unixOpen(UnixFileImpl* file,Key *key, __code next(Block *block,...)); + __code uniAck(UnixFileImpl* file,Ack *ack, __code next(Block *block,...)); +} File; diff -r f3112bbff428 -r 2d91b4d2569c Paper/codes/wc/WcChrsImpl.cbc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Paper/codes/wc/WcChrsImpl.cbc Wed May 05 18:43:47 2021 +0900 @@ -0,0 +1,49 @@ +#include +#impl "Wc.h" as "WcChrsImpl.h" + +Wc* createChrsWcImpl(struct Context* context) { + Wc *wc = new Wc(); + wc->wc = (union Data*)new WcImpl(); + wc->bytes = 0; + wc->words = 0; + wc->lines = 0; + return wc; +} + +// Topology manageres determins input / output connection +// +__code setOutput(Wc* wc, Output *output,__code next(...)) { + wc->output = output ; + goto next(...); +} + +__code take(Impl* wc, Output *output, + Block *block, // Input + __code next(...)) { + if (isEof(block->eof )) { + result.buffer = new Buffer(1); + result.buffer->data = new Byte(BUSIZE); + result.size = 1; + result.buffer->size = + snprintf(result.buffer[0]->data, "%d %d %d\n",wc->bytes,wc->words,wc->lines); + output->put(result); // goto finish(resut); + goto next(...); + } + for(size_t i = 0 ; isize; i++) { + if (block->data[i] == '\n') wc->lines++; + if (block->data[i] == ' ') { + wc->words++; + while(block->data[i] == ' ') { + if(i>=block->size) + goto next(ack,take); + i++; + wc->bytes++; + } + } + wc->bytes++; + } + // output1->put(ack); // goto next(ack,take); + output->put(ack); // goto next(ack,take); + goto next(...); +} + diff -r f3112bbff428 -r 2d91b4d2569c Paper/codes/wc/WcResult.h --- a/Paper/codes/wc/WcResult.h Wed May 05 15:38:07 2021 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,4 +0,0 @@ -typedef struct WcResult <> { - int wordNum; - char* str; -} WcResult; diff -r f3112bbff428 -r 2d91b4d2569c Paper/codes/wc/main.cbc --- a/Paper/codes/wc/main.cbc Wed May 05 15:38:07 2021 +0900 +++ b/Paper/codes/wc/main.cbc Wed May 05 18:43:47 2021 +0900 @@ -1,10 +1,15 @@ #data "wcTarget.h" #interface "Wc.h" +// +// start file and wc +// connect continuation each other +// __code startCode(struct GearsData* gearsData) { - Wc* wc = createWcImpl(context, /* file name */ gearsData->args[1] ); - goto wc->openFile(code2); + File* file = createUnixFileImpl(context, /* file name */ gearsData->args[1] ); + Wc* wc = createWcImpl(context); + goto file->openFile(asReader(wc)); // readerInterface } diff -r f3112bbff428 -r 2d91b4d2569c Paper/codes/wc/wcTarget.h --- a/Paper/codes/wc/wcTarget.h Wed May 05 15:38:07 2021 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,5 +0,0 @@ -typedef struct wcTarget <> { - char* filename; - char* keyword; -} wcTarget; - diff -r f3112bbff428 -r 2d91b4d2569c Paper/images/wordCountDGM.graffle Binary file Paper/images/wordCountDGM.graffle has changed