Anonymous user
Rosetta Code/Find bare lang tags: Difference between revisions
Rosetta Code/Find bare lang tags (view source)
Revision as of 08:36, 23 September 2011
, 12 years ago→Tcl: Added implementation
(Restore AutoHotkey code by Crazyfirex, but disable Rosetta Code's syntax highlighter.) |
(→Tcl: Added implementation) |
||
Line 82:
}
}</lang>
=={{header|Tcl}}==
Doing one of the extra credit options…
{{tcllib|textutil::split}}
<lang tcl>package require textutil::split
proc init {} {
global total count found
set total 0
array set count {}
array set found {}
}
proc findBareTags {pageName pageContent} {
global total count found
set t {{no language}}
lappend t {*}[textutil::split::splitx $pageContent \
{==\s*\{\{\s*header\s*\|\s*([^{}]+?)\s*\}\}\s*==}]
foreach {sectionName sectionText} $t {
set n [regexp -all {<lang>} $sectionText]
if {!$n} continue
incr count($sectionName) $n
lappend found($sectionName) $pageName
incr total $n
}
}
proc printResults {} {
global total count found
puts "$total bare language tags."
if {$total} {
puts ""
foreach sectionName [array names found] {
puts "$count($sectionName) in $sectionName\
(\[\[[join $found($sectionName) {]], [[}]\]\])"
}
}
}
# Do the first level of extra credit. Note that filenames are interleaved with
# page titles as the page content doesn't (necessarily) contain the title.
init
foreach {filename title} $argv {
set f [open $filename]
findBareTags $title [read $f]
close $f
}
printResults</lang>
{{omit from|GUISS}}
|