mirror of
https://github.com/dlang/dmd.git
synced 2025-04-27 21:51:03 +03:00
Move dmd files into compiler/
This commit is contained in:
parent
20bd0cacbd
commit
6374bb87b7
4579 changed files with 4 additions and 4 deletions
49
compiler/samples/wc.d
Normal file
49
compiler/samples/wc.d
Normal file
|
@ -0,0 +1,49 @@
|
|||
import std.stdio;
|
||||
import std.file;
|
||||
|
||||
void main(string[] args)
|
||||
{
|
||||
int w_total;
|
||||
int l_total;
|
||||
int c_total;
|
||||
|
||||
writeln(" lines words bytes file");
|
||||
|
||||
foreach (arg; args[1 .. $])
|
||||
{
|
||||
int w_cnt, l_cnt, c_cnt;
|
||||
bool inword;
|
||||
|
||||
string input = readText(arg);
|
||||
|
||||
foreach (char c; input)
|
||||
{
|
||||
if (c == '\n')
|
||||
++l_cnt;
|
||||
|
||||
if (c != ' ')
|
||||
{
|
||||
if (!inword)
|
||||
{
|
||||
inword = true;
|
||||
++w_cnt;
|
||||
}
|
||||
}
|
||||
else
|
||||
inword = false;
|
||||
|
||||
++c_cnt;
|
||||
}
|
||||
|
||||
writefln("%8s%8s%8s %s\n", l_cnt, w_cnt, c_cnt, arg);
|
||||
l_total += l_cnt;
|
||||
w_total += w_cnt;
|
||||
c_total += c_cnt;
|
||||
}
|
||||
|
||||
if (args.length > 2)
|
||||
{
|
||||
writefln("--------------------------------------\n%8s%8s%8s total",
|
||||
l_total, w_total, c_total);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue