| 1 |
# checkLibraryDoc.tcl -- |
| 2 |
# |
| 3 |
# This script attempts to determine what APIs exist in the source base that |
| 4 |
# have not been documented. By grepping through all of the doc/*.3 man |
| 5 |
# pages, looking for "Pkg_*" (e.g., Tcl_ or Tk_), and comparing this list |
| 6 |
# against the list of Pkg_ APIs found in the source (e.g., tcl8.6/*/*.[ch]) |
| 7 |
# we create six lists: |
| 8 |
# 1) APIs in Source not in Docs. |
| 9 |
# 2) APIs in Docs not in Source. |
| 10 |
# 3) Internal APIs and structs. |
| 11 |
# 4) Misc APIs and structs that we are not documenting. |
| 12 |
# 5) Command APIs (e.g., Tcl_ArrayObjCmd.) |
| 13 |
# 6) Proc pointers (e.g., Tcl_CloseProc.) |
| 14 |
# |
| 15 |
# Note: Each list is "a best guess" approximation. If developers write |
| 16 |
# non-standard code, this script will produce erroneous results. Each |
| 17 |
# list should be carefully checked for accuracy. |
| 18 |
# |
| 19 |
# Copyright (c) 1998-1999 Scriptics Corporation. |
| 20 |
# All rights reserved. |
| 21 |
|
| 22 |
|
| 23 |
lappend auto_path "c:/program\ files/tclpro1.2/win32-ix86/bin" |
| 24 |
#lappend auto_path "/home/surles/cvs/tclx8.0/tcl/unix" |
| 25 |
if {[catch {package require Tclx}]} { |
| 26 |
puts "error: could not load TclX. Please set TCL_LIBRARY." |
| 27 |
exit 1 |
| 28 |
} |
| 29 |
|
| 30 |
# A list of structs that are known to be undocumented. |
| 31 |
|
| 32 |
set StructList { |
| 33 |
Tcl_AsyncHandler \ |
| 34 |
Tcl_CallFrame \ |
| 35 |
Tcl_Condition \ |
| 36 |
Tcl_Encoding \ |
| 37 |
Tcl_EncodingState \ |
| 38 |
Tcl_EncodingType \ |
| 39 |
Tcl_HashEntry \ |
| 40 |
Tcl_HashSearch \ |
| 41 |
Tcl_HashTable \ |
| 42 |
Tcl_Mutex \ |
| 43 |
Tcl_Pid \ |
| 44 |
Tcl_QueuePosition \ |
| 45 |
Tcl_ResolvedVarInfo \ |
| 46 |
Tcl_SavedResult \ |
| 47 |
Tcl_ThreadDataKey \ |
| 48 |
Tcl_ThreadId \ |
| 49 |
Tcl_Time \ |
| 50 |
Tcl_TimerToken \ |
| 51 |
Tcl_Token \ |
| 52 |
Tcl_Trace \ |
| 53 |
Tcl_Value \ |
| 54 |
Tcl_ValueType \ |
| 55 |
Tcl_Var \ |
| 56 |
Tk_3DBorder \ |
| 57 |
Tk_ArgvInfo \ |
| 58 |
Tk_BindingTable \ |
| 59 |
Tk_Canvas \ |
| 60 |
Tk_CanvasTextInfo \ |
| 61 |
Tk_ConfigSpec \ |
| 62 |
Tk_ConfigTypes \ |
| 63 |
Tk_Cursor \ |
| 64 |
Tk_CustomOption \ |
| 65 |
Tk_ErrorHandler \ |
| 66 |
Tk_FakeWin \ |
| 67 |
Tk_Font \ |
| 68 |
Tk_FontMetrics \ |
| 69 |
Tk_GeomMgr \ |
| 70 |
Tk_Image \ |
| 71 |
Tk_ImageMaster \ |
| 72 |
Tk_ImageModel \ |
| 73 |
Tk_ImageType \ |
| 74 |
Tk_Item \ |
| 75 |
Tk_ItemType \ |
| 76 |
Tk_OptionSpec\ |
| 77 |
Tk_OptionTable \ |
| 78 |
Tk_OptionType \ |
| 79 |
Tk_PhotoHandle \ |
| 80 |
Tk_PhotoImageBlock \ |
| 81 |
Tk_PhotoImageFormat \ |
| 82 |
Tk_PostscriptInfo \ |
| 83 |
Tk_SavedOption \ |
| 84 |
Tk_SavedOptions \ |
| 85 |
Tk_SegType \ |
| 86 |
Tk_TextLayout \ |
| 87 |
Tk_Window \ |
| 88 |
} |
| 89 |
|
| 90 |
# Misc junk that appears in the comments of the source. This just |
| 91 |
# allows us to filter comments that "fool" the script. |
| 92 |
|
| 93 |
set CommentList { |
| 94 |
Tcl_Create\[Obj\]Command \ |
| 95 |
Tcl_DecrRefCount\\n \ |
| 96 |
Tcl_NewObj\\n \ |
| 97 |
Tk_GetXXX \ |
| 98 |
} |
| 99 |
|
| 100 |
# Main entry point to this script. |
| 101 |
|
| 102 |
proc main {} { |
| 103 |
global argv0 |
| 104 |
global argv |
| 105 |
|
| 106 |
set len [llength $argv] |
| 107 |
if {($len != 2) && ($len != 3)} { |
| 108 |
puts "usage: $argv0 pkgName pkgDir \[outFile\]" |
| 109 |
puts " pkgName == Tcl,Tk" |
| 110 |
exit 1 |
| 111 |
} |
| 112 |
|
| 113 |
set pkg [lindex $argv 0] |
| 114 |
set dir [lindex $argv 1] |
| 115 |
if {[llength $argv] == 3} { |
| 116 |
set file [open [lindex $argv 2] w] |
| 117 |
} else { |
| 118 |
set file stdout |
| 119 |
} |
| 120 |
|
| 121 |
foreach {c d} [compare [grepCode $dir $pkg] [grepDocs $dir $pkg]] {} |
| 122 |
filter $c $d $dir $pkg $file |
| 123 |
|
| 124 |
if {$file ne "stdout"} { |
| 125 |
close $file |
| 126 |
} |
| 127 |
return |
| 128 |
} |
| 129 |
|
| 130 |
# Intersect the two list and write out the sets of APIs in one |
| 131 |
# list that is not in the other. |
| 132 |
|
| 133 |
proc compare {list1 list2} { |
| 134 |
set inter [intersect3 $list1 $list2] |
| 135 |
return [list [lindex $inter 0] [lindex $inter 2]] |
| 136 |
} |
| 137 |
|
| 138 |
# Filter the lists into the six lists we report on. Then write |
| 139 |
# the results to the file. |
| 140 |
|
| 141 |
proc filter {code docs dir pkg {outFile stdout}} { |
| 142 |
set apis {} |
| 143 |
|
| 144 |
# A list of Tcl command APIs. These are not documented. |
| 145 |
# This list should just be verified for accuracy. |
| 146 |
|
| 147 |
set cmds {} |
| 148 |
|
| 149 |
# A list of proc pointer structs. These are not documented. |
| 150 |
# This list should just be verified for accuracy. |
| 151 |
|
| 152 |
set procs {} |
| 153 |
|
| 154 |
# A list of internal declarations. These are not documented. |
| 155 |
# This list should just be verified for accuracy. |
| 156 |
|
| 157 |
set decls [grepDecl $dir $pkg] |
| 158 |
|
| 159 |
# A list of misc. procedure declarations that are not documented. |
| 160 |
# This list should just be verified for accuracy. |
| 161 |
|
| 162 |
set misc [grepMisc $dir $pkg] |
| 163 |
|
| 164 |
set pat1 ".*(${pkg}_\[A-z0-9]+).*$" |
| 165 |
|
| 166 |
# A list of APIs in the source, not in the docs. |
| 167 |
# This list should just be verified for accuracy. |
| 168 |
|
| 169 |
foreach x $code { |
| 170 |
if {[string match *Cmd $x]} { |
| 171 |
if {[string match ${pkg}* $x]} { |
| 172 |
lappend cmds $x |
| 173 |
} |
| 174 |
} elseif {[string match *Proc $x]} { |
| 175 |
if {[string match ${pkg}* $x]} { |
| 176 |
lappend procs $x |
| 177 |
} |
| 178 |
} elseif {[lsearch -exact $decls $x] >= 0} { |
| 179 |
# No Op. |
| 180 |
} elseif {[lsearch -exact $misc $x] >= 0} { |
| 181 |
# No Op. |
| 182 |
} else { |
| 183 |
lappend apis $x |
| 184 |
} |
| 185 |
} |
| 186 |
|
| 187 |
dump $apis "APIs in Source not in Docs." $outFile |
| 188 |
dump $docs "APIs in Docs not in Source." $outFile |
| 189 |
dump $decls "Internal APIs and structs." $outFile |
| 190 |
dump $misc "Misc APIs and structs that we are not documenting." $outFile |
| 191 |
dump $cmds "Command APIs." $outFile |
| 192 |
dump $procs "Proc pointers." $outFile |
| 193 |
return |
| 194 |
} |
| 195 |
|
| 196 |
# Print the list of APIs if the list is not null. |
| 197 |
|
| 198 |
proc dump {list title file} { |
| 199 |
if {$list ne ""} { |
| 200 |
puts $file "" |
| 201 |
puts $file $title |
| 202 |
puts $file "---------------------------------------------------------" |
| 203 |
foreach x $list { |
| 204 |
puts $file $x |
| 205 |
} |
| 206 |
} |
| 207 |
} |
| 208 |
|
| 209 |
# Grep into "dir/*/*.[ch]" looking for APIs that match $pkg_*. |
| 210 |
# (e.g., Tcl_Exit). Return a list of APIs. |
| 211 |
|
| 212 |
proc grepCode {dir pkg} { |
| 213 |
set apis [myGrep "${pkg}_\.\*" "${dir}/\*/\*\.\[ch\]"] |
| 214 |
set pat1 ".*(${pkg}_\[A-z0-9]+).*$" |
| 215 |
|
| 216 |
foreach a $apis { |
| 217 |
if {[regexp -- $pat1 $a main n1]} { |
| 218 |
set result([string trim $n1]) 1 |
| 219 |
} |
| 220 |
} |
| 221 |
return [lsort [array names result]] |
| 222 |
} |
| 223 |
|
| 224 |
# Grep into "dir/doc/*.3" looking for APIs that match $pkg_*. |
| 225 |
# (e.g., Tcl_Exit). Return a list of APIs. |
| 226 |
|
| 227 |
proc grepDocs {dir pkg} { |
| 228 |
set apis [myGrep "\\fB${pkg}_\.\*\\fR" "${dir}/doc/\*\.3"] |
| 229 |
set pat1 ".*(${pkg}_\[A-z0-9]+)\\\\fR.*$" |
| 230 |
|
| 231 |
foreach a $apis { |
| 232 |
if {[regexp -- $pat1 $a main n1]} { |
| 233 |
set result([string trim $n1]) 1 |
| 234 |
} |
| 235 |
} |
| 236 |
return [lsort [array names result]] |
| 237 |
} |
| 238 |
|
| 239 |
# Grep into "generic/pkgIntDecls.h" looking for APIs that match $pkg_*. |
| 240 |
# (e.g., Tcl_Export). Return a list of APIs. |
| 241 |
|
| 242 |
proc grepDecl {dir pkg} { |
| 243 |
set file [file join $dir generic "[string tolower $pkg]IntDecls.h"] |
| 244 |
set apis [myGrep "^EXTERN.*\[ \t\]${pkg}_.*" $file] |
| 245 |
set pat1 ".*(${pkg}_\[A-z0-9]+).*$" |
| 246 |
|
| 247 |
foreach a $apis { |
| 248 |
if {[regexp -- $pat1 $a main n1]} { |
| 249 |
set result([string trim $n1]) 1 |
| 250 |
} |
| 251 |
} |
| 252 |
return [lsort [array names result]] |
| 253 |
} |
| 254 |
|
| 255 |
# Grep into "*/*.[ch]" looking for APIs that match $pkg_Db*. |
| 256 |
# (e.g., Tcl_DbCkalloc). Return a list of APIs. |
| 257 |
|
| 258 |
proc grepMisc {dir pkg} { |
| 259 |
global CommentList |
| 260 |
global StructList |
| 261 |
|
| 262 |
set apis [myGrep "^EXTERN.*\[ \t\]${pkg}_Db.*" "${dir}/\*/\*\.\[ch\]"] |
| 263 |
set pat1 ".*(${pkg}_\[A-z0-9]+).*$" |
| 264 |
|
| 265 |
foreach a $apis { |
| 266 |
if {[regexp -- $pat1 $a main n1]} { |
| 267 |
set dbg([string trim $n1]) 1 |
| 268 |
} |
| 269 |
} |
| 270 |
|
| 271 |
set result {} |
| 272 |
eval {lappend result} $StructList |
| 273 |
eval {lappend result} [lsort [array names dbg]] |
| 274 |
eval {lappend result} $CommentList |
| 275 |
return $result |
| 276 |
} |
| 277 |
|
| 278 |
proc myGrep {searchPat globPat} { |
| 279 |
set result {} |
| 280 |
foreach file [glob -nocomplain $globPat] { |
| 281 |
set file [open $file r] |
| 282 |
set data [read $file] |
| 283 |
close $file |
| 284 |
foreach line [split $data "\n"] { |
| 285 |
if {[regexp "^.*${searchPat}.*\$" $line]} { |
| 286 |
lappend result $line |
| 287 |
} |
| 288 |
} |
| 289 |
} |
| 290 |
return $result |
| 291 |
} |
| 292 |
main |
| 293 |
|