Mercurial > hg > Members > ikki > CbC_log
comparison 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 |
comparison
equal
deleted
inserted
replaced
4:d6911fe00127 | 5:7599728af8ba |
---|---|
1 #include <stdio.h> | |
2 #impl "Wc.h" as "WcChrsImpl.h" | |
3 | |
4 Wc* createChrsWcImpl(struct Context* context) { | |
5 Wc *wc = new Wc(); | |
6 wc->wc = (union Data*)new WcImpl(); | |
7 wc->bytes = 0; | |
8 wc->words = 0; | |
9 wc->lines = 0; | |
10 return wc; | |
11 } | |
12 | |
13 // Topology manageres determins input / output connection | |
14 // | |
15 __code gearsConnect(Wc* wc, Input *input,Output *output, Output *stdout,__code next(...)) { | |
16 input->add(&wc->block,"block"); | |
17 output->add(&wc->ack,"ack"); | |
18 stdout->add(&wc->result,"result"); | |
19 goto next(...); | |
20 } | |
21 | |
22 __code take(Impl* wc, Block *block /* input */, __code next(Ack *ack, ...), __code finish(StdData result, ...)) { | |
23 if (isEof(block->eof )) { | |
24 result.buffer = new Buffer(1); | |
25 result.buffer->data = new Byte(BUSIZE); | |
26 result.size = 1; | |
27 result.buffer->size = | |
28 snprintf(result.buffer[0]->data, "%d %d %d\n",wc->bytes,wc->words,wc->lines); | |
29 got finish(resut,...); | |
30 } | |
31 for(size_t i = 0 ; i<block->size; i++) { | |
32 if (block->data[i] == '\n') wc->lines++; | |
33 if (block->data[i] == ' ') { | |
34 wc->words++; | |
35 while(block->data[i] == ' ') { | |
36 if(i>=block->size) | |
37 goto next(ack,...); | |
38 i++; | |
39 wc->bytes++; | |
40 } | |
41 } | |
42 wc->bytes++; | |
43 } | |
44 goto next(ack,...); // output ack, activate take | |
45 } | |
46 |