# HG changeset patch # User ichikitakahiro # Date 1624055083 -32400 # Node ID 7599728af8ba5a0ed9e9ee080fbe9c7fa889b798 # Parent d6911fe001277835253911f598eb135bd37e2b3a add wc diff -r d6911fe00127 -r 7599728af8ba wc_sigos/Ack.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/wc_sigos/Ack.h Sat Jun 19 07:24:43 2021 +0900 @@ -0,0 +1,3 @@ +typedef struct Ack <> { + int ok; +} Ack; diff -r d6911fe00127 -r 7599728af8ba wc_sigos/Block.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/wc_sigos/Block.h Sat Jun 19 07:24:43 2021 +0900 @@ -0,0 +1,5 @@ +typedef struct Block <> { + int eof; /* EOF etc */ + size_t size; + unsigned char *buf; +} Block; diff -r d6911fe00127 -r 7599728af8ba wc_sigos/DMGImpl.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/wc_sigos/DMGImpl.h Sat Jun 19 07:24:43 2021 +0900 @@ -0,0 +1,7 @@ +typedef struct DataGearMangerImpl ipml File { + struct Queue* lists; + int mode; + Data *fileImpl ; + __code dmgOpen(DataGearMangerImpl* file,Key *key, __code next(Record *record,...)); + __code dmgAck(DataGearMangerImpl* file,Ack *ack, __code next(Record *record,...)); +} File; diff -r d6911fe00127 -r 7599728af8ba wc_sigos/File.cbc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/wc_sigos/File.cbc Sat Jun 19 07:24:43 2021 +0900 @@ -0,0 +1,7 @@ +typedef struct File <> { + Path *path; + int mode; /* rw .. */ + Data *fileImpl ; + __code open(FileImpl* file,Key *key, __code next(Block *block,...)); + __code ack(FileImpl* file,Ack *ack, __code next(Block *block,...)); +} File; diff -r d6911fe00127 -r 7599728af8ba wc_sigos/File.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/wc_sigos/File.h Sat Jun 19 07:24:43 2021 +0900 @@ -0,0 +1,10 @@ +typedef struct File { + int mode; /* rw .. */ + Key *key; + Ack *ack; + Record *record; + Data *fileImpl ; + + __code open(FileImpl* file,Key *key, int mode, __code next(Record *record,...)); + __code ack(FileImpl* file,Ack *ack, __code next(Record *record,...)); +} File; diff -r d6911fe00127 -r 7599728af8ba wc_sigos/FileChrs.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/wc_sigos/FileChrs.h Sat Jun 19 07:24:43 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 d6911fe00127 -r 7599728af8ba wc_sigos/RemoteDMGImpl.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/wc_sigos/RemoteDMGImpl.h Sat Jun 19 07:24:43 2021 +0900 @@ -0,0 +1,7 @@ +typedef struct RemoteDataGearMangerImpl ipml File { + struct Queue* lists; + int mode; + Data *fileImpl ; + __code rdmgOpen(DataGearMangerImpl* file,Connection *conn, Key *key, __code next(Record *record,...)); + __code rdmgAck(DataGearMangerImpl* file,Ack *ack, __code next(Record *record,...)); +} File; diff -r d6911fe00127 -r 7599728af8ba wc_sigos/StdData.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/wc_sigos/StdData.h Sat Jun 19 07:24:43 2021 +0900 @@ -0,0 +1,4 @@ +typedef struct StdData <> { + size_t size; + Buffer *buffer; +} StdData; diff -r d6911fe00127 -r 7599728af8ba wc_sigos/TopologyManager.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/wc_sigos/TopologyManager.h Sat Jun 19 07:24:43 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 d6911fe00127 -r 7599728af8ba wc_sigos/UnixChrisFileImpl.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/wc_sigos/UnixChrisFileImpl.cpp Sat Jun 19 07:24:43 2021 +0900 @@ -0,0 +1,61 @@ +#include +#impl "UnixCharImpl.h" as "UnixCharImpl.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 +// +// Topology manageres determins input / output connection +// +__code gearsConnect(Wc* wc, Input *input, Output *output,__code next(...)) { + file->reader = output ; + input->add(&file->ack,"ack"); + 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; + close(file->fd); + 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(...); +} + +__code uniAck(UnixFileImpl* file,Ack *ack, Output reader, __code next(...)) { + if (!ack->isOk) { + close(file->fd); + goto next(...); + } + putBlock(file,reader); + goto next(...); // file is automaticaly put into local dataGearManger/input +} + diff -r d6911fe00127 -r 7599728af8ba wc_sigos/UnixFileImpl.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/wc_sigos/UnixFileImpl.cpp Sat Jun 19 07:24:43 2021 +0900 @@ -0,0 +1,37 @@ +#include +#impl UnixFileImp as "UnixFileImpl.h" + + +File* createUnixFileImpl(struct Context* context) { + File *file = new File(); + file->FileImpl = (union Data*)new FileImpl(); + return file; +} + +readBlock(UnixFileImpl* file) { + Block *block = new Block(); + int len = read(fd, BUFSIZE, block->data); + block->eof &= ~BLOCK_FLAG_EOF; + if (len <=0 ) { + block->eof |= BLOCK_FLAG_EOF; + close(file->fd); + } + return block ; +} + +__code unixOpen(UnixFileImpl* file,Key *key, __code next(Block *block,...)); + file->fd = open(key->path,unix_mode(key->modde)); + if (fd < 0) { + goto error("can't open"); + } + goto next(readBlock(file), ...); +} + +__code uniAck(UnixFileImpl* file,Ack *ack, __code next(Block *block,...)); + if (!ack->isOk) { + close(file->fd); + goto next(...); + } + goto next(readBlock(file), ...); // file is automaticaly put into local dataGearManger/input +} + diff -r d6911fe00127 -r 7599728af8ba wc_sigos/UnixFileImpl.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/wc_sigos/UnixFileImpl.h Sat Jun 19 07:24:43 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 d6911fe00127 -r 7599728af8ba wc_sigos/Wc.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/wc_sigos/Wc.h Sat Jun 19 07:24:43 2021 +0900 @@ -0,0 +1,9 @@ +typedef struct Wc <> { + // all arguments names in this interfaces here + union Data* wc; // an implementation + Block * block; + StdData * reuslt; + Ack * ack; + // codeGear entries of this interface + __code take(Impl* wc, Block *block,__code next(Ack *ack, ...),__code finish(StdData *result,...); +} Wc; diff -r d6911fe00127 -r 7599728af8ba wc_sigos/WcChrsImpl.cbc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/wc_sigos/WcChrsImpl.cbc Sat Jun 19 07:24:43 2021 +0900 @@ -0,0 +1,46 @@ +#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 gearsConnect(Wc* wc, Input *input,Output *output, Output *stdout,__code next(...)) { + input->add(&wc->block,"block"); + output->add(&wc->ack,"ack"); + stdout->add(&wc->result,"result"); + goto next(...); +} + +__code take(Impl* wc, Block *block /* input */, __code next(Ack *ack, ...), __code finish(StdData result, ...)) { + 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); + got finish(resut,...); + } + 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,...); + i++; + wc->bytes++; + } + } + wc->bytes++; + } + goto next(ack,...); // output ack, activate take +} + diff -r d6911fe00127 -r 7599728af8ba wc_sigos/WcImpl.cbc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/wc_sigos/WcImpl.cbc Sat Jun 19 07:24:43 2021 +0900 @@ -0,0 +1,39 @@ +#include "../../../context.h" +#include +#impl "Wc.h" as "WcImpl.h" +#interface "WcResult.h" + +Wc* createWcImpl(struct Context* context) { + Wc *wc = new Wc(); + wc->wc = (union Data*)new WcImpl(); + wc->bytes = 0; + wc->words = 0; + wc->lines = 0; + return wc; +} + +__code take(Impl* wc, Block *block,__code next(Ack *ack, ...),__code finish(StdData *result,...) { + 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); + goto finish(resut); + } + 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++; + } + goto next(ack,take); +} + diff -r d6911fe00127 -r 7599728af8ba wc_sigos/WcImpl.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/wc_sigos/WcImpl.h Sat Jun 19 07:24:43 2021 +0900 @@ -0,0 +1,5 @@ +typedef struct WcImpl <> impl Wc { + size_t bytes + size_t words + size_t lines +} WcImpl; diff -r d6911fe00127 -r 7599728af8ba wc_sigos/main.cbc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/wc_sigos/main.cbc Sat Jun 19 07:24:43 2021 +0900 @@ -0,0 +1,15 @@ +#data "wcTarget.h" +#interface "Wc.h" + +// +// start file and wc +// connect continuation each other +// + +__code startCode(struct GearsData* gearsData) { + File* file = createUnixFileImpl(context, /* file name */ gearsData->args[1] ); + Wc* wc = createWcImpl(context); + goto file->openFile(asReader(wc)); // readerInterface +} + +