Mercurial > hg > Members > ikki > CbC_log
view wc_sigos/WcChrsImpl.cbc @ 5:7599728af8ba default tip
add wc
author | ichikitakahiro <e165713@ie.u-ryukyu.ac.jp> |
---|---|
date | Sat, 19 Jun 2021 07:24:43 +0900 |
parents | |
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 }