Mercurial > hg > Members > ikki > CbC_log
view wc_sigos/WcImpl.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 "../../../context.h" #include <stdio.h> #impl "Wc.h" as "WcImpl.h" #interface "WcResult.h" 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 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); }