diff options
author | dgp <dgp@users.sourceforge.net> | 2016-04-19 20:35:49 (GMT) |
---|---|---|
committer | dgp <dgp@users.sourceforge.net> | 2016-04-19 20:35:49 (GMT) |
commit | 66032e8a327e0498b0d8970307452f66c69be25c (patch) | |
tree | 345b92b9d0c1be0f8ff45032a38884929744545e /tests/langbench/wc.l | |
parent | 0a228666ae8b3189ae92ff7624263de1455c24ff (diff) | |
download | tcl-66032e8a327e0498b0d8970307452f66c69be25c.zip tcl-66032e8a327e0498b0d8970307452f66c69be25c.tar.gz tcl-66032e8a327e0498b0d8970307452f66c69be25c.tar.bz2 |
Fork of Tcl used in the "Little" project.
http://www.mcvoy.com/lm/little/index.html
Diffstat (limited to 'tests/langbench/wc.l')
-rw-r--r-- | tests/langbench/wc.l | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/tests/langbench/wc.l b/tests/langbench/wc.l new file mode 100644 index 0000000..f24ec07 --- /dev/null +++ b/tests/langbench/wc.l @@ -0,0 +1,52 @@ +string [] +wordsplit(string str) +{ + string chars[]; + string list[]; + string c, word; + int i; + + word = ""; + chars = split(str, ""); + foreach (c in chars) { + if (string("is", "space", c)) { + if (length(word) > 0) { + push(&list, word); + } + word = ""; + } else { + append(&word, c); + } + } + if (length(word) > 0) { + push(&list, word); + } + return (list); +} + +int +doit(string file) +{ + FILE f = open(file, "rb"); + string buf; + string words[]; + int n; + + while (gets(f, &buf) >= 0) { + words = wordsplit(buf); + n += llength(words); + } + close(f); + return (n); +} + +void +main(int ac, string av[]) +{ + int total, i; + + for (i = 1; i < ac; ++i) { + total += doit(av[i]); + } + printf("%d\n", total); +} |