comparison 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
comparison
equal deleted inserted replaced
4:d6911fe00127 5:7599728af8ba
1 #include "../../../context.h"
2 #include <stdio.h>
3 #impl "Wc.h" as "WcImpl.h"
4 #interface "WcResult.h"
5
6 Wc* createWcImpl(struct Context* context) {
7 Wc *wc = new Wc();
8 wc->wc = (union Data*)new WcImpl();
9 wc->bytes = 0;
10 wc->words = 0;
11 wc->lines = 0;
12 return wc;
13 }
14
15 __code take(Impl* wc, Block *block,__code next(Ack *ack, ...),__code finish(StdData *result,...) {
16 if (isEof(block->eof )) {
17 result.buffer = new Buffer(1);
18 result.buffer->data = new Byte(BUSIZE);
19 result.size = 1;
20 result.buffer->size =
21 snprintf(result.buffer[0]->data, "%d %d %d\n",wc->bytes,wc->words,wc->lines);
22 goto finish(resut);
23 }
24 for(size_t i = 0 ; i<block->size; i++) {
25 if (block->data[i] == '\n') wc->lines++;
26 if (block->data[i] == ' ') {
27 wc->words++;
28 while(block->data[i] == ' ') {
29 if(i>=block->size)
30 goto next(ack,take);
31 i++;
32 wc->bytes++;
33 }
34 }
35 wc->bytes++;
36 }
37 goto next(ack,take);
38 }
39