Fossil SCM
New command-line options for find-fossil-cgis.tcl: --print, --symlink, and -v.
Commit
609f885a02afc17c3573314255eccb9a94c37e94af7553ea6ae1b1bc711f0922
Parent
ccb7cc4ecd6ed77…
1 file changed
+52
-8
+52
-8
| --- tools/find-fossil-cgis.tcl | ||
| +++ tools/find-fossil-cgis.tcl | ||
| @@ -1,13 +1,13 @@ | ||
| 1 | 1 | #!/usr/bin/tclsh |
| 2 | 2 | # |
| 3 | 3 | # This script scans a directory hierarchy looking for Fossil CGI files - |
| 4 | 4 | # the files that are used to launch Fossil as a CGI program. For each |
| 5 | -# such file found, in prints the name of the file and then prints the | |
| 6 | -# file content, indented. | |
| 5 | +# such file found, in prints the name of the file and also the file | |
| 6 | +# content, indented, if the --print option is used. | |
| 7 | 7 | # |
| 8 | -# tclsh find-fossil-cgis.tcl [OPTIONS] $DIRECTORY | |
| 8 | +# tclsh find-fossil-cgis.tcl [OPTIONS] DIRECTORY | |
| 9 | 9 | # |
| 10 | 10 | # The argument is the directory from which to begin the search. |
| 11 | 11 | # |
| 12 | 12 | # OPTIONS can be zero or more of the following: |
| 13 | 13 | # |
| @@ -16,24 +16,35 @@ | ||
| 16 | 16 | # all must match. |
| 17 | 17 | # |
| 18 | 18 | # --hasnot REGEXP Only show the CGI if it does NOT match the |
| 19 | 19 | # REGEXP. |
| 20 | 20 | # |
| 21 | - | |
| 21 | +# --print Show the content of the CGI, indented by | |
| 22 | +# three spaces | |
| 23 | +# | |
| 24 | +# --symlink Process DIRECTORY arguments that are symlinks. | |
| 25 | +# Normally symlinks are silently ignored. | |
| 26 | +# | |
| 27 | +# -v Show progress information for debugging | |
| 28 | +# | |
| 22 | 29 | |
| 23 | 30 | # Find the CGIs in directory $dir. Invoke recursively to |
| 24 | 31 | # scan subdirectories. |
| 25 | 32 | # |
| 26 | 33 | proc find_in_one_dir {dir} { |
| 27 | - global HAS HASNOT | |
| 34 | + global HAS HASNOT PRINT V | |
| 35 | + if {$V>0} { | |
| 36 | + puts "# $dir" | |
| 37 | + } | |
| 28 | 38 | foreach obj [lsort [glob -nocomplain -directory $dir *]] { |
| 29 | 39 | if {[file isdir $obj]} { |
| 30 | 40 | find_in_one_dir $obj |
| 31 | 41 | continue |
| 32 | 42 | } |
| 33 | 43 | if {![file isfile $obj]} continue |
| 34 | 44 | if {[file size $obj]>5000} continue |
| 45 | + if {![file exec $obj]} continue | |
| 35 | 46 | if {![file readable $obj]} continue |
| 36 | 47 | set fd [open $obj rb] |
| 37 | 48 | set txt [read $fd] |
| 38 | 49 | close $fd |
| 39 | 50 | if {![string match #!* $txt]} continue |
| @@ -52,17 +63,27 @@ | ||
| 52 | 63 | if {!$ok} continue |
| 53 | 64 | # |
| 54 | 65 | # At this point assume we have found a CGI file. |
| 55 | 66 | # |
| 56 | 67 | puts $obj |
| 57 | - regsub -all {\n} [string trim $txt] "\n " out | |
| 58 | - puts " $out" | |
| 68 | + if {$PRINT} { | |
| 69 | + regsub -all {\n} [string trim $txt] "\n " out | |
| 70 | + puts " $out" | |
| 71 | + } | |
| 59 | 72 | } |
| 60 | 73 | } |
| 61 | 74 | set HAS [list] |
| 62 | 75 | set HASNOT [list] |
| 76 | +set PRINT 0 | |
| 77 | +set SYMLINK 0 | |
| 78 | +set V 0 | |
| 63 | 79 | set N [llength $argv] |
| 80 | +set DIRLIST [list] | |
| 81 | + | |
| 82 | +# First pass: Gather all the command-line arguments but do no | |
| 83 | +# processing. | |
| 84 | +# | |
| 64 | 85 | for {set i 0} {$i<$N} {incr i} { |
| 65 | 86 | set dir [lindex $argv $i] |
| 66 | 87 | if {($dir eq "-has" || $dir eq "--has") && $i<[expr {$N-1}]} { |
| 67 | 88 | incr i |
| 68 | 89 | lappend HAS [lindex $argv $i] |
| @@ -71,7 +92,30 @@ | ||
| 71 | 92 | if {($dir eq "-hasnot" || $dir eq "--hasnot") && $i<[expr {$N-1}]} { |
| 72 | 93 | incr i |
| 73 | 94 | lappend HASNOT [lindex $argv $i] |
| 74 | 95 | continue |
| 75 | 96 | } |
| 76 | - find_in_one_dir $dir | |
| 97 | + if {$dir eq "-print" || $dir eq "--print"} { | |
| 98 | + set PRINT 1 | |
| 99 | + continue | |
| 100 | + } | |
| 101 | + if {$dir eq "-symlink" || $dir eq "--symlink"} { | |
| 102 | + set SYMLINK 1 | |
| 103 | + continue | |
| 104 | + } | |
| 105 | + if {$dir eq "-v"} { | |
| 106 | + set V 1 | |
| 107 | + continue | |
| 108 | + } | |
| 109 | + if {[file type $dir]=="directory"} { | |
| 110 | + lappend DIRLIST $dir | |
| 111 | + } | |
| 112 | +} | |
| 113 | + | |
| 114 | +# Second pass: Process the non-option arguments. | |
| 115 | +# | |
| 116 | +foreach dir $DIRLIST { | |
| 117 | + set type [file type $dir] | |
| 118 | + if {$type eq "directory" || ($SYMLINK && $type eq "link")} { | |
| 119 | + find_in_one_dir $dir | |
| 120 | + } | |
| 77 | 121 | } |
| 78 | 122 |
| --- tools/find-fossil-cgis.tcl | |
| +++ tools/find-fossil-cgis.tcl | |
| @@ -1,13 +1,13 @@ | |
| 1 | #!/usr/bin/tclsh |
| 2 | # |
| 3 | # This script scans a directory hierarchy looking for Fossil CGI files - |
| 4 | # the files that are used to launch Fossil as a CGI program. For each |
| 5 | # such file found, in prints the name of the file and then prints the |
| 6 | # file content, indented. |
| 7 | # |
| 8 | # tclsh find-fossil-cgis.tcl [OPTIONS] $DIRECTORY |
| 9 | # |
| 10 | # The argument is the directory from which to begin the search. |
| 11 | # |
| 12 | # OPTIONS can be zero or more of the following: |
| 13 | # |
| @@ -16,24 +16,35 @@ | |
| 16 | # all must match. |
| 17 | # |
| 18 | # --hasnot REGEXP Only show the CGI if it does NOT match the |
| 19 | # REGEXP. |
| 20 | # |
| 21 | |
| 22 | |
| 23 | # Find the CGIs in directory $dir. Invoke recursively to |
| 24 | # scan subdirectories. |
| 25 | # |
| 26 | proc find_in_one_dir {dir} { |
| 27 | global HAS HASNOT |
| 28 | foreach obj [lsort [glob -nocomplain -directory $dir *]] { |
| 29 | if {[file isdir $obj]} { |
| 30 | find_in_one_dir $obj |
| 31 | continue |
| 32 | } |
| 33 | if {![file isfile $obj]} continue |
| 34 | if {[file size $obj]>5000} continue |
| 35 | if {![file readable $obj]} continue |
| 36 | set fd [open $obj rb] |
| 37 | set txt [read $fd] |
| 38 | close $fd |
| 39 | if {![string match #!* $txt]} continue |
| @@ -52,17 +63,27 @@ | |
| 52 | if {!$ok} continue |
| 53 | # |
| 54 | # At this point assume we have found a CGI file. |
| 55 | # |
| 56 | puts $obj |
| 57 | regsub -all {\n} [string trim $txt] "\n " out |
| 58 | puts " $out" |
| 59 | } |
| 60 | } |
| 61 | set HAS [list] |
| 62 | set HASNOT [list] |
| 63 | set N [llength $argv] |
| 64 | for {set i 0} {$i<$N} {incr i} { |
| 65 | set dir [lindex $argv $i] |
| 66 | if {($dir eq "-has" || $dir eq "--has") && $i<[expr {$N-1}]} { |
| 67 | incr i |
| 68 | lappend HAS [lindex $argv $i] |
| @@ -71,7 +92,30 @@ | |
| 71 | if {($dir eq "-hasnot" || $dir eq "--hasnot") && $i<[expr {$N-1}]} { |
| 72 | incr i |
| 73 | lappend HASNOT [lindex $argv $i] |
| 74 | continue |
| 75 | } |
| 76 | find_in_one_dir $dir |
| 77 | } |
| 78 |
| --- tools/find-fossil-cgis.tcl | |
| +++ tools/find-fossil-cgis.tcl | |
| @@ -1,13 +1,13 @@ | |
| 1 | #!/usr/bin/tclsh |
| 2 | # |
| 3 | # This script scans a directory hierarchy looking for Fossil CGI files - |
| 4 | # the files that are used to launch Fossil as a CGI program. For each |
| 5 | # such file found, in prints the name of the file and also the file |
| 6 | # content, indented, if the --print option is used. |
| 7 | # |
| 8 | # tclsh find-fossil-cgis.tcl [OPTIONS] DIRECTORY |
| 9 | # |
| 10 | # The argument is the directory from which to begin the search. |
| 11 | # |
| 12 | # OPTIONS can be zero or more of the following: |
| 13 | # |
| @@ -16,24 +16,35 @@ | |
| 16 | # all must match. |
| 17 | # |
| 18 | # --hasnot REGEXP Only show the CGI if it does NOT match the |
| 19 | # REGEXP. |
| 20 | # |
| 21 | # --print Show the content of the CGI, indented by |
| 22 | # three spaces |
| 23 | # |
| 24 | # --symlink Process DIRECTORY arguments that are symlinks. |
| 25 | # Normally symlinks are silently ignored. |
| 26 | # |
| 27 | # -v Show progress information for debugging |
| 28 | # |
| 29 | |
| 30 | # Find the CGIs in directory $dir. Invoke recursively to |
| 31 | # scan subdirectories. |
| 32 | # |
| 33 | proc find_in_one_dir {dir} { |
| 34 | global HAS HASNOT PRINT V |
| 35 | if {$V>0} { |
| 36 | puts "# $dir" |
| 37 | } |
| 38 | foreach obj [lsort [glob -nocomplain -directory $dir *]] { |
| 39 | if {[file isdir $obj]} { |
| 40 | find_in_one_dir $obj |
| 41 | continue |
| 42 | } |
| 43 | if {![file isfile $obj]} continue |
| 44 | if {[file size $obj]>5000} continue |
| 45 | if {![file exec $obj]} continue |
| 46 | if {![file readable $obj]} continue |
| 47 | set fd [open $obj rb] |
| 48 | set txt [read $fd] |
| 49 | close $fd |
| 50 | if {![string match #!* $txt]} continue |
| @@ -52,17 +63,27 @@ | |
| 63 | if {!$ok} continue |
| 64 | # |
| 65 | # At this point assume we have found a CGI file. |
| 66 | # |
| 67 | puts $obj |
| 68 | if {$PRINT} { |
| 69 | regsub -all {\n} [string trim $txt] "\n " out |
| 70 | puts " $out" |
| 71 | } |
| 72 | } |
| 73 | } |
| 74 | set HAS [list] |
| 75 | set HASNOT [list] |
| 76 | set PRINT 0 |
| 77 | set SYMLINK 0 |
| 78 | set V 0 |
| 79 | set N [llength $argv] |
| 80 | set DIRLIST [list] |
| 81 | |
| 82 | # First pass: Gather all the command-line arguments but do no |
| 83 | # processing. |
| 84 | # |
| 85 | for {set i 0} {$i<$N} {incr i} { |
| 86 | set dir [lindex $argv $i] |
| 87 | if {($dir eq "-has" || $dir eq "--has") && $i<[expr {$N-1}]} { |
| 88 | incr i |
| 89 | lappend HAS [lindex $argv $i] |
| @@ -71,7 +92,30 @@ | |
| 92 | if {($dir eq "-hasnot" || $dir eq "--hasnot") && $i<[expr {$N-1}]} { |
| 93 | incr i |
| 94 | lappend HASNOT [lindex $argv $i] |
| 95 | continue |
| 96 | } |
| 97 | if {$dir eq "-print" || $dir eq "--print"} { |
| 98 | set PRINT 1 |
| 99 | continue |
| 100 | } |
| 101 | if {$dir eq "-symlink" || $dir eq "--symlink"} { |
| 102 | set SYMLINK 1 |
| 103 | continue |
| 104 | } |
| 105 | if {$dir eq "-v"} { |
| 106 | set V 1 |
| 107 | continue |
| 108 | } |
| 109 | if {[file type $dir]=="directory"} { |
| 110 | lappend DIRLIST $dir |
| 111 | } |
| 112 | } |
| 113 | |
| 114 | # Second pass: Process the non-option arguments. |
| 115 | # |
| 116 | foreach dir $DIRLIST { |
| 117 | set type [file type $dir] |
| 118 | if {$type eq "directory" || ($SYMLINK && $type eq "link")} { |
| 119 | find_in_one_dir $dir |
| 120 | } |
| 121 | } |
| 122 |