]> git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/testsuite/gdc.test/runnable/wc3.d
Add D front-end, libphobos library, and D2 testsuite.
[thirdparty/gcc.git] / gcc / testsuite / gdc.test / runnable / wc3.d
1 // PERMUTE_ARGS:
2 // EXECUTE_ARGS: runnable/extra-files/alice30.txt
3 // EXTRA_FILES: extra-files/alice30.txt
4
5 import std.stdio;
6 import std.file;
7
8 int main (string[] args)
9 {
10 int w_total;
11 int l_total;
12 int c_total;
13 int[string] dictionary;
14
15 writefln(" lines words bytes file");
16 foreach (arg; args[1 .. args.length])
17 {
18 int w_cnt, l_cnt, c_cnt;
19 size_t wstart;
20 bool inword;
21
22 auto input = cast(string)std.file.read(arg);
23
24 foreach (j, c; input)
25 {
26 if (c == '\n')
27 ++l_cnt;
28 if (c >= '0' && c <= '9')
29 {
30 }
31 else if (c >= 'a' && c <= 'z' ||
32 c >= 'A' && c <= 'Z')
33 {
34 if (!inword)
35 {
36 wstart = j;
37 inword = true;
38 ++w_cnt;
39 }
40 }
41 else if (inword)
42 { auto word = input[wstart .. j];
43
44 dictionary[word]++;
45 inword = false;
46 }
47 ++c_cnt;
48 }
49 if (inword)
50 { auto w = input[wstart .. input.length];
51 dictionary[w]++;
52 }
53 writefln("%8s%8s%8s %s", l_cnt, w_cnt, c_cnt, arg);
54 l_total += l_cnt;
55 w_total += w_cnt;
56 c_total += c_cnt;
57 }
58
59 if (args.length > 2)
60 {
61 writefln("--------------------------------------\n%8s%8s%8s total",
62 l_total, w_total, c_total);
63 }
64
65 writefln("--------------------------------------");
66
67 foreach (word1; dictionary.keys)
68 {
69 writefln("%3s %s", dictionary[word1], word1);
70 }
71 return 0;
72 }