# HG changeset patch # User Shinji KONO # Date 1620283776 -32400 # Node ID 218abc95edeb73f5a89b48346ecc324d47ad1d71 # Parent 5b8d3386f93979f93724c1f8137da1245b7f5425 ... diff -r 5b8d3386f939 -r 218abc95edeb Paper/codes/wc/UnixChrisFileImpl.cpp --- a/Paper/codes/wc/UnixChrisFileImpl.cpp Thu May 06 00:00:26 2021 +0900 +++ b/Paper/codes/wc/UnixChrisFileImpl.cpp Thu May 06 15:49:36 2021 +0900 @@ -1,5 +1,5 @@ #include -#impl "Wc.h" as "WcChrsImpl.h" +#impl "UnixCharImpl.h" as "UnixCharImpl.h" typedef struct UnixFileImpl <> ipml File { int fd; // unix file descriptor @@ -18,8 +18,11 @@ // Topology manageres determins input / output connection // -__code setOutput(Wc* wc, Output *output,__code next(...)) { +// 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(...); } @@ -29,6 +32,7 @@ int len = read(fd, BUFSIZE, block->data); if (len <=0 ) { block->eof |= BLOCK_FLAG_EOF; + close(file->fd); return 0; } reader->put(block); @@ -43,14 +47,15 @@ if (putBlock(file,reader)) { putBlock(file,reader); } - goto next(file,...); + goto next(...); } __code uniAck(UnixFileImpl* file,Ack *ack, Output reader, __code next(...)) { if (!ack->isOk) { - close(fd); + close(file->fd); goto next(...); } putBlock(file,reader); goto next(...); // file is automaticaly put into local dataGearManger/input } + diff -r 5b8d3386f939 -r 218abc95edeb Paper/codes/wc/UnixFileImpl.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Paper/codes/wc/UnixFileImpl.cpp Thu May 06 15:49:36 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 5b8d3386f939 -r 218abc95edeb Paper/codes/wc/WcChrsImpl.cbc --- a/Paper/codes/wc/WcChrsImpl.cbc Thu May 06 00:00:26 2021 +0900 +++ b/Paper/codes/wc/WcChrsImpl.cbc Thu May 06 15:49:36 2021 +0900 @@ -12,22 +12,21 @@ // Topology manageres determins input / output connection // -__code setOutput(Wc* wc, Output *output,__code next(...)) { - wc->output = output ; +__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, Output *output, - Block *block, // Input - __code 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); - output->put(result); // goto finish(resut); - goto next(...); + got finish(resut,...); } for(size_t i = 0 ; isize; i++) { if (block->data[i] == '\n') wc->lines++; @@ -35,15 +34,13 @@ wc->words++; while(block->data[i] == ' ') { if(i>=block->size) - goto next(ack,take); + goto next(ack,...); i++; wc->bytes++; } } wc->bytes++; } - // output1->put(ack); // goto next(ack,take); - output->put(ack); // goto next(ack,take); - goto next(...); + goto next(ack,...); // output ack, activate take } diff -r 5b8d3386f939 -r 218abc95edeb Paper/paper.pdf Binary file Paper/paper.pdf has changed