]> git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/testsuite/gdc.test/runnable/wc.d
Add D front-end, libphobos library, and D2 testsuite.
[thirdparty/gcc.git] / gcc / testsuite / gdc.test / runnable / wc.d
1 // PERMUTE_ARGS:
2 // EXECUTE_ARGS: runnable/wc.d
3
4 import std.file;
5
6 extern(C) int printf(const char*, ...);
7
8 int main (string[] args)
9 {
10 int w_total;
11 int l_total;
12 int c_total;
13
14 printf (" lines words bytes file\n");
15 foreach (arg; args[1 .. args.length])
16 {
17 string input;
18 int w_cnt, l_cnt, c_cnt;
19 int inword;
20
21 input = cast(string)std.file.read(arg);
22
23 foreach (char c; input)
24 {
25 if (c == '\n')
26 ++l_cnt;
27 if (c != ' ')
28 {
29 if (!inword)
30 {
31 inword = 1;
32 ++w_cnt;
33 }
34 }
35 else
36 inword = 0;
37 ++c_cnt;
38 }
39 printf ("%8lu%8lu%8lu %.*s\n", l_cnt, w_cnt, c_cnt, arg.length, arg.ptr);
40 l_total += l_cnt;
41 w_total += w_cnt;
42 c_total += c_cnt;
43 }
44 if (args.length > 2)
45 {
46 printf ("--------------------------------------\n%8lu%8lu%8lu total",
47 l_total, w_total, c_total);
48 }
49 return 0;
50 }