# HG changeset patch # User Shinji KONO # Date 1620196299 -32400 # Node ID 0d703e0d9781f9a51584f258077727d5664791b2 # Parent b434a3dd23cdaa56e6cd4adc4c3f38663c05b2e2 ... diff -r b434a3dd23cd -r 0d703e0d9781 Paper/codes/wc/Ack.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Paper/codes/wc/Ack.h Wed May 05 15:31:39 2021 +0900 @@ -0,0 +1,3 @@ +typedef struct Ack <> { + int ok; +} Ack; diff -r b434a3dd23cd -r 0d703e0d9781 Paper/codes/wc/Block.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Paper/codes/wc/Block.h Wed May 05 15:31:39 2021 +0900 @@ -0,0 +1,5 @@ +typedef struct Block <> { + int eof; /* EOF etc */ + size_t size; + unsigned char *buf; +} Block; diff -r b434a3dd23cd -r 0d703e0d9781 Paper/codes/wc/DMGImpl.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Paper/codes/wc/DMGImpl.h Wed May 05 15:31:39 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 b434a3dd23cd -r 0d703e0d9781 Paper/codes/wc/File.cbc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Paper/codes/wc/File.cbc Wed May 05 15:31:39 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 b434a3dd23cd -r 0d703e0d9781 Paper/codes/wc/File.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Paper/codes/wc/File.h Wed May 05 15:31:39 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 b434a3dd23cd -r 0d703e0d9781 Paper/codes/wc/FileImpl.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Paper/codes/wc/FileImpl.h Wed May 05 15:31:39 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 b434a3dd23cd -r 0d703e0d9781 Paper/codes/wc/RemoteDMGImpl.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Paper/codes/wc/RemoteDMGImpl.h Wed May 05 15:31:39 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 b434a3dd23cd -r 0d703e0d9781 Paper/codes/wc/StdData.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Paper/codes/wc/StdData.h Wed May 05 15:31:39 2021 +0900 @@ -0,0 +1,4 @@ +typedef struct StdData <> { + size_t size; + Buffer *buffer; +} StdData; diff -r b434a3dd23cd -r 0d703e0d9781 Paper/codes/wc/Wc.h --- a/Paper/codes/wc/Wc.h Wed May 05 11:22:41 2021 +0900 +++ b/Paper/codes/wc/Wc.h Wed May 05 15:31:39 2021 +0900 @@ -1,9 +1,9 @@ typedef struct Wc <> { // all arguments names in this interfaces here union Data* wc; // an implementation - WcResult* result; + Block * block; + StdData * reuslt; + Ack * ack; // codeGear entries of this interface - __code openFile(Impl* wc, __code next(...)); - __code countUp(Impl* wc, __code next(WcResult* result, ...)); - __code next(...); + __code take(Impl* wc, Block *block,__code next(Ack *ack, ...),__code finish(StdData *result,...); } Wc; diff -r b434a3dd23cd -r 0d703e0d9781 Paper/codes/wc/WcImpl.cbc --- a/Paper/codes/wc/WcImpl.cbc Wed May 05 11:22:41 2021 +0900 +++ b/Paper/codes/wc/WcImpl.cbc Wed May 05 15:31:39 2021 +0900 @@ -3,50 +3,37 @@ #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; +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 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, ...); +__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); +} - 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); -} diff -r b434a3dd23cd -r 0d703e0d9781 Paper/codes/wc/WcImpl.h --- a/Paper/codes/wc/WcImpl.h Wed May 05 11:22:41 2021 +0900 +++ b/Paper/codes/wc/WcImpl.h Wed May 05 15:31:39 2021 +0900 @@ -1,6 +1,5 @@ typedef struct WcImpl <> impl Wc { - char* Keyword; - int wordNum; - char* filename; - union Data* file; + size_t bytes + size_t words + size_t lines } WcImpl;