Posted to tcl by aku at Fri Nov 03 17:53:47 GMT 2017view raw

  1. #!/usr/bin/env tclsh
  2. # -*- tcl -*-
  3. # Check list of files and dirs for files containing the eliminated functions.
  4.  
  5. proc funcs {} {
  6. return {
  7. Tcl_AppendResultVA
  8. Tcl_AppendStringsToObjVA
  9. Tcl_SetErrorCodeVA
  10. Tcl_PanicVA
  11. }
  12. }
  13.  
  14. proc main {} {
  15. process-paths [cmdline]
  16. }
  17.  
  18. proc cmdline {} {
  19. global argv
  20. if {![llength $argv]} usage
  21. return $argv
  22. }
  23.  
  24. proc usage {} {
  25. global argv0
  26. puts stderr "Usage: $argv0 path path..."
  27. exit 1
  28. }
  29.  
  30. proc process-paths {pathlist} {
  31. foreach path $pathlist {
  32. process-one $path
  33. }
  34. }
  35.  
  36. proc process-one {path} {
  37. switch -exact -- [file type $path] {
  38. file {
  39. check-file $path
  40. }
  41. directory {
  42. process-paths [glob -directory $path *]
  43. }
  44. }
  45. }
  46.  
  47. proc check-file {path} {
  48. set linenumber 0
  49. set lines [split [get $path] \n]
  50. foreach line $lines {
  51. foreach f [funcs] {
  52. if {[string match "*${f}*" $line]} {
  53. puts "$path : $linenumber : $f"
  54. }
  55. }
  56. incr linenumber
  57. }
  58. }
  59.  
  60. proc get {path} {
  61. set chan [open $path r]
  62. set contents [read $chan]
  63. close $chan
  64. return $contents
  65. }
  66.  
  67. main
  68.  

Comments

Posted by aku at Fri Nov 03 17:59:18 GMT 2017 [text] [code]

Oops. The [glob -directory ...] needs a -nocomplain to handle empty dirs.