Mercurial > hg > Papers > 2021 > ikki-sigos
changeset 17:0d703e0d9781
...
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Wed, 05 May 2021 15:31:39 +0900 |
parents | b434a3dd23cd |
children | f3112bbff428 |
files | Paper/codes/wc/Ack.h Paper/codes/wc/Block.h Paper/codes/wc/DMGImpl.h Paper/codes/wc/File.cbc Paper/codes/wc/File.h Paper/codes/wc/FileImpl.h Paper/codes/wc/RemoteDMGImpl.h Paper/codes/wc/StdData.h Paper/codes/wc/Wc.h Paper/codes/wc/WcImpl.cbc Paper/codes/wc/WcImpl.h |
diffstat | 11 files changed, 87 insertions(+), 51 deletions(-) [+] |
line wrap: on
line diff
--- /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;
--- /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;
--- /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 <Record> ipml File { + struct Queue<Record>* 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;
--- /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;
--- /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 <Record> { + 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;
--- /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;
--- /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 <Record> ipml File { + struct Queue<Record>* 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;
--- /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;
--- 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;
--- 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 ; i<block->size; 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); -}