changeset 976:76a86972c2eb

progress wordcount
author ichikitakahiro <e165713@ie.u-ryukyu.ac.jp>
date Mon, 11 Oct 2021 20:52:24 +0900
parents 18650c9ff2b2
children ed258cf51f40
files src/parallel_execution/examples/new_wc/WordPutImpl.cbc src/parallel_execution/examples/wc/CountImpl.cbc src/parallel_execution/examples/wc/CountImpl.h src/parallel_execution/examples/wc/ShowResult.h src/parallel_execution/examples/wc/Wc.h src/parallel_execution/examples/wc/WcImpl.cbc src/parallel_execution/examples/wc/WcImpl.h src/parallel_execution/examples/wc/main.h src/parallel_execution/examples/wc/wcString.h
diffstat 9 files changed, 109 insertions(+), 23 deletions(-) [+]
line wrap: on
line diff
--- a/src/parallel_execution/examples/new_wc/WordPutImpl.cbc	Thu Sep 30 00:25:36 2021 +0900
+++ b/src/parallel_execution/examples/new_wc/WordPutImpl.cbc	Mon Oct 11 20:52:24 2021 +0900
@@ -25,7 +25,7 @@
 }
 __code openFile(struct WordPutImpl* wordPut, __code next(...)) {
     printf("%s\n", wordPut->filename);
-    WordCount* wordCount = createWordCountImpl(context);
+    WordCount* wordCount = new WordCount();
     FILE* file = fopen(wordPut->filename, "r");
     if (file == NULL){
         printf("ファイルが開ませんでした\n");
@@ -46,10 +46,10 @@
     printf("%d\n", wordPut->lineNum);
     while (fgets(str, wordPut->wordLen, wordPut->file) != NULL && count < wordPut->lineNum) {
 		if(count == wordPut->lineNum -1){
-            wcString* string = NEW(wcString);
+            wcString* string = new wcString());
             string->str = str;
             printf("%s", string->str);
-            goto wordCount->getWord(wordPut, string, Put);
+            goto wordCount->getWord(wordPut, openFile);
         }
         count ++;
 	}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/parallel_execution/examples/wc/CountImpl.cbc	Mon Oct 11 20:52:24 2021 +0900
@@ -0,0 +1,37 @@
+#include "../../../context.h"
+#include <stdio.h>
+#impl "Wc.h" as "CountImpl.h"
+#interface "Wc.h"
+
+// ----
+// typedef struct CountImpl <> impl Wc {
+//   char* Keyword;
+//   int wordNum;
+//   char* filename;
+//   union Data* file;
+// } CountImpl;
+// ----
+
+Wc* createCountImpl(struct Context* context) {
+    struct Wc* wc  = new Wc();
+    struct CountImpl* count_impl = new CountImpl();
+    wc->wc = (union Data*)count_impl;
+    wc->result = NULL;
+    count_impl->Keyword = NULL;
+    count_impl->wordNum = 0;
+    count_impl->filename = NULL;
+    count_impl->file = NULL;
+    wc->openFile = C_openFileCountImpl;
+    wc->countUp = C_countUpCountImpl;
+    return wc;
+}
+__code openFile(struct CountImpl* wc, __code next(...)) {
+
+    goto next(...);
+}
+
+__code countUp(struct CountImpl* wc, __code next(WcResult* result, ...)) {
+
+    goto next(WcResult* result, ...);
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/parallel_execution/examples/wc/CountImpl.h	Mon Oct 11 20:52:24 2021 +0900
@@ -0,0 +1,6 @@
+typedef struct CountImpl <> impl Wc {
+  char* Keyword;
+  int wordNum;
+  char* filename;
+  union Data* file;
+} CountImpl;
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/parallel_execution/examples/wc/ShowResult.h	Mon Oct 11 20:52:24 2021 +0900
@@ -0,0 +1,3 @@
+typedef struct ShowResult <> {
+  __code next(...);
+} ShowResult;
--- a/src/parallel_execution/examples/wc/Wc.h	Thu Sep 30 00:25:36 2021 +0900
+++ b/src/parallel_execution/examples/wc/Wc.h	Mon Oct 11 20:52:24 2021 +0900
@@ -1,7 +1,9 @@
 typedef struct Wc <> {
   union Data* wc;
   WcResult* result;    
+  union Data* string;
   __code openFile(Impl* wc, __code next(...));
-  __code countUp(Impl* wc, __code next(WcResult* result, ...));
+  __code putString(Impl* wc, __code next(...));
+  __code countUp(Impl* wc, Type* string, __code next(...));
   __code next(...);
 } Wc;
--- a/src/parallel_execution/examples/wc/WcImpl.cbc	Thu Sep 30 00:25:36 2021 +0900
+++ b/src/parallel_execution/examples/wc/WcImpl.cbc	Mon Oct 11 20:52:24 2021 +0900
@@ -3,6 +3,9 @@
 #impl "Wc.h" as "WcImpl.h"
 #interface "WcResult.h"
 #include <stdlib.h>
+#include <fcntl.h>
+#include <string.h>
+#interface "wcString.h"
 #define BUFFERING_MODE _IOLBF
 
 Wc* createWcImpl(struct Context* context, char* filename) {
@@ -10,26 +13,57 @@
     struct WcImpl* wc_impl = new WcImpl();
     wc->wc = (union Data*)wc_impl;
     wc_impl->filename = filename;
+    wc_impl->buffer = NULL;
     wc->result = NULL;
     wc_impl->Keyword = NULL;
     wc_impl->wordNum = 0;
+    wc_impl->putLine = 0;
     wc->openFile = C_openFileWcImpl;
+    wc->putString = C_putStringWcImpl;
     wc->countUp = C_countUpWcImpl;
     return wc;
 }
 __code openFile(struct WcImpl* wc, __code next(...)) {
-  FILE* file = fopen(wc->filename, "r");
-  if (file == NULL){
+  int fd = open(wc->filename, O_RDONLY);
+  if (fd == -1){
     printf("ファイルが開ませんでした\n");
     exit(1);
   } else {
     printf("file open\n");
   }
-  wc->file = (union Data*)file; 
-  goto countUp(wc, next);
+
+  int buf_size = 10000;
+  char* buffer[buf_size];
+  int rc = read(fd, buffer, buf_size);  
+  wc->buffer = buffer;
+  if (rc == -1){
+    printf("ファイルが読み込めませんでした");
+  } else {
+
+  }
+  goto putString(next);
 }
 
-__code countUp(struct WcImpl* wc,__code next(WcResult* result, ...)) {
+__code putString(struct WcImpl* wc, __code next(...)){
+  char* buff[1000];
+  strcpy(buff ,wc->buffer);
+  char* token = strtok(buff, "\n");
+  int count = 0;
+  while (token != NULL){
+    if (count == wc->putLine){
+      wcString* string = NEW(wcString);
+      string->str = token;
+      printf("putString:%s\n", string->str);
+      goto countUp((union Data*)string, next);
+    }else{
+    }
+    token = strtok(NULL, "\n");
+    count++;
+  } 
+  goto showResult(next);
+}
+
+__code countUp(struct WcImpl* wc, wcString* string, __code next(...)) {
     /*
     Read data from file
     if eof
@@ -42,19 +76,14 @@
     Count char
     TODO
     */
-  int buf_size = 10000;
-  /*
-  if( setvbuf( wc->file, buffer, BUFFERING_MODE, sizeof(buffer)) != 0 ){
-    fputs("stdinのバッファリングを変更できませんでした。", stderr);
-    exit(EXIT_FAILURE);
-  } else {
-  printf("setvbuffer\n");  
-  }
-  */
-  char buffer[buf_size];
-  int m = fread(buffer, sizeof( char ), buf_size ,wc->file);  
-  printf("文字数=%d\n", m);
-  printf("%s\n" ,buffer);
+  printf("%s\n", string->str);
+  wc->putLine = wc->putLine + 1;
+   goto putString(next);
+
+}
 
-  //goto countUp(wc, next);
+
+__code showResult(struct WcImpl* wc, __code next(...)) {
+  printf("EOF and finish codes\n");
+  goto next(...);
 }
--- a/src/parallel_execution/examples/wc/WcImpl.h	Thu Sep 30 00:25:36 2021 +0900
+++ b/src/parallel_execution/examples/wc/WcImpl.h	Mon Oct 11 20:52:24 2021 +0900
@@ -1,6 +1,8 @@
 typedef struct WcImpl <> impl Wc {
   char* Keyword; 
   int wordNum;
+  int putLine;
   char* filename;
+  char* buffer;
   union Data* file;
 } WcImpl;
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/parallel_execution/examples/wc/main.h	Mon Oct 11 20:52:24 2021 +0900
@@ -0,0 +1,4 @@
+typedef struct WcMain <> { 
+struct LoopCounter* loopCounter;
+struct TaskManager* taskManager;
+} WcMain;
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/parallel_execution/examples/wc/wcString.h	Mon Oct 11 20:52:24 2021 +0900
@@ -0,0 +1,3 @@
+typedef struct wcString <> {
+    char* str;
+} wcString;
\ No newline at end of file