summaryrefslogtreecommitdiffstats
path: root/tests/langbench/wc.tcl
diff options
context:
space:
mode:
authordgp <dgp@users.sourceforge.net>2016-04-19 20:35:49 (GMT)
committerdgp <dgp@users.sourceforge.net>2016-04-19 20:35:49 (GMT)
commit66032e8a327e0498b0d8970307452f66c69be25c (patch)
tree345b92b9d0c1be0f8ff45032a38884929744545e /tests/langbench/wc.tcl
parent0a228666ae8b3189ae92ff7624263de1455c24ff (diff)
downloadtcl-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.tcl')
-rw-r--r--tests/langbench/wc.tcl36
1 files changed, 36 insertions, 0 deletions
diff --git a/tests/langbench/wc.tcl b/tests/langbench/wc.tcl
new file mode 100644
index 0000000..5dc17aa
--- /dev/null
+++ b/tests/langbench/wc.tcl
@@ -0,0 +1,36 @@
+proc wordsplit {str} {
+ set list {}
+ set word {}
+ foreach char [split $str {}] {
+ if {[string is space $char]} {
+ if {[string length $word] > 0} {
+ lappend list $word
+ }
+ set word {}
+ } else {
+ append word $char
+ }
+ }
+ if {[string length $word] > 0} {
+ lappend list $word
+ }
+ return $list
+}
+
+proc doit {file} {
+ set f [open $file r]
+ fconfigure $f -translation binary
+ set buf ""
+ set n 0
+ while {[gets $f buf] >= 0} {
+ set words [wordsplit $buf]
+ incr n [llength $words]
+ }
+ close $f
+ return $n
+}
+set total 0
+foreach file $argv {
+ incr total [doit $file]
+}
+puts $total