Mercurial > hg > Papers > 2021 > ikki-sigos
view Paper/codes/wc/WcChrsImpl.cbc @ 21:218abc95edeb
...
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Thu, 06 May 2021 15:49:36 +0900 |
parents | 2d91b4d2569c |
children |
line wrap: on
line source
#include <stdio.h> #impl "Wc.h" as "WcChrsImpl.h" Wc* createChrsWcImpl(struct Context* context) { Wc *wc = new Wc(); wc->wc = (union Data*)new WcImpl(); wc->bytes = 0; wc->words = 0; wc->lines = 0; return wc; } // Topology manageres determins input / output connection // __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, 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); got 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,...); i++; wc->bytes++; } } wc->bytes++; } goto next(ack,...); // output ack, activate take }