4 Usage
: spellsift.tcl
<source_filenames
>
5 The named .c and .h
source files comment blocks are spell-checked.
8 if {[llength $argv] == 0} {
13 # Want a Tcl version with 3-argument close.
14 package require
Tcl 8.6
16 set ::spellchk "aspell --extra-dicts ./custom.rws list"
18 # Run text through aspell with custom dictionary, return finds.
19 proc misspelled
{text} {
20 set spellerr
[open "|$::spellchk" r
+]
24 set huhq
[regsub {\s
*$} [read $spellerr] {}]
26 return [split $huhq "\n"]
29 # Eliminate some common patterns that need not be well spelled.
31 set nopp
[regsub -all "\n *#\[^\n\]*\n" $text "\n\n" ]
32 set noticket
[regsub -all {Ticket
\[?
[0-9a-f
]+\]?
} $nopp "" ]
36 # Sift out common variable spellings not in normal dictionaries.
37 proc varsift
{words
} {
40 set n
[string length
$w]
41 set cr
[string range
$w 1 end
]
42 if {[string tolower
$cr] ne
$cr} continue
49 set ich
[open $fname r
]
50 set dtext
[decruft
[read $ich]]
52 set cbounds
[regexp -indices -inline -all {(/\*)|
(\*/)} $dtext]
55 foreach {ap cb ce
} $cbounds {
56 set cib
[lindex $cb 1]
57 set cie
[lindex $ce 0]
60 set cce
[expr $cie - 1]
61 set destar
[string map
[list * " "] [string range
$dtext $ccb $cce]]
62 lappend cblocks
$destar
65 } elseif
{$cib != -1} {
66 set ccb
[expr $cib + 1]
69 set oddspells
[varsift
[misspelled
[join $cblocks "\n"]]]
70 if {[llength $oddspells] > 0} {
71 puts "!? Misspellings from $fname:"
72 puts [join [lsort -nocase -unique $oddspells] "\n"]