changeset 21:218abc95edeb

...
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Thu, 06 May 2021 15:49:36 +0900
parents 5b8d3386f939
children 4d1009ff72c5
files Paper/codes/wc/UnixChrisFileImpl.cpp Paper/codes/wc/UnixFileImpl.cpp Paper/codes/wc/WcChrsImpl.cbc Paper/paper.pdf
diffstat 4 files changed, 54 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- 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 <stdio.h>
-#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
 }
+
--- /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 <stdio.h>
+#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
+}
+
--- 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 ; i<block->size; 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
 }
 
Binary file Paper/paper.pdf has changed