Fossil SCM
Add the --has and --hasnot options to the find-fossil-cgis.tcl script.
Commit
ccb7cc4ecd6ed7797b7c7125134192deba24e50e1a767b509b9f71ee8a5970f3
Parent
71e1ef338414b88…
1 file changed
+35
-2
+35
-2
| --- tools/find-fossil-cgis.tcl | ||
| +++ tools/find-fossil-cgis.tcl | ||
| @@ -3,20 +3,30 @@ | ||
| 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 | 5 | # such file found, in prints the name of the file and then prints the |
| 6 | 6 | # file content, indented. |
| 7 | 7 | # |
| 8 | -# tclsh find-fossil-cgis.tcl $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 | +# | |
| 12 | +# OPTIONS can be zero or more of the following: | |
| 13 | +# | |
| 14 | +# --has REGEXP Only show the CGI if the body matches REGEXP. | |
| 15 | +# May be repeated multiple times, in which case | |
| 16 | +# all must match. | |
| 17 | +# | |
| 18 | +# --hasnot REGEXP Only show the CGI if it does NOT match the | |
| 19 | +# REGEXP. | |
| 11 | 20 | # |
| 12 | 21 | |
| 13 | 22 | |
| 14 | 23 | # Find the CGIs in directory $dir. Invoke recursively to |
| 15 | 24 | # scan subdirectories. |
| 16 | 25 | # |
| 17 | 26 | proc find_in_one_dir {dir} { |
| 27 | + global HAS HASNOT | |
| 18 | 28 | foreach obj [lsort [glob -nocomplain -directory $dir *]] { |
| 19 | 29 | if {[file isdir $obj]} { |
| 20 | 30 | find_in_one_dir $obj |
| 21 | 31 | continue |
| 22 | 32 | } |
| @@ -29,16 +39,39 @@ | ||
| 29 | 39 | if {![string match #!* $txt]} continue |
| 30 | 40 | if {![regexp {fossil} $txt]} continue |
| 31 | 41 | if {![regexp {\nrepository: } $txt] && |
| 32 | 42 | ![regexp {\ndirectory: } $txt] && |
| 33 | 43 | ![regexp {\nredirect: } $txt]} continue |
| 44 | + set ok 1 | |
| 45 | + foreach re $HAS { | |
| 46 | + if {![regexp $re $txt]} {set ok 0; break;} | |
| 47 | + } | |
| 48 | + if {!$ok} continue | |
| 49 | + foreach re $HASNOT { | |
| 50 | + if {[regexp $re $txt]} {set ok 0; break;} | |
| 51 | + } | |
| 52 | + if {!$ok} continue | |
| 34 | 53 | # |
| 35 | 54 | # At this point assume we have found a CGI file. |
| 36 | 55 | # |
| 37 | 56 | puts $obj |
| 38 | 57 | regsub -all {\n} [string trim $txt] "\n " out |
| 39 | 58 | puts " $out" |
| 40 | 59 | } |
| 41 | 60 | } |
| 42 | -foreach dir $argv { | |
| 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] | |
| 69 | + continue | |
| 70 | + } | |
| 71 | + if {($dir eq "-hasnot" || $dir eq "--hasnot") && $i<[expr {$N-1}]} { | |
| 72 | + incr i | |
| 73 | + lappend HASNOT [lindex $argv $i] | |
| 74 | + continue | |
| 75 | + } | |
| 43 | 76 | find_in_one_dir $dir |
| 44 | 77 | } |
| 45 | 78 |
| --- tools/find-fossil-cgis.tcl | |
| +++ tools/find-fossil-cgis.tcl | |
| @@ -3,20 +3,30 @@ | |
| 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 $DIRECTORY |
| 9 | # |
| 10 | # The argument is the directory from which to begin the search. |
| 11 | # |
| 12 | |
| 13 | |
| 14 | # Find the CGIs in directory $dir. Invoke recursively to |
| 15 | # scan subdirectories. |
| 16 | # |
| 17 | proc find_in_one_dir {dir} { |
| 18 | foreach obj [lsort [glob -nocomplain -directory $dir *]] { |
| 19 | if {[file isdir $obj]} { |
| 20 | find_in_one_dir $obj |
| 21 | continue |
| 22 | } |
| @@ -29,16 +39,39 @@ | |
| 29 | if {![string match #!* $txt]} continue |
| 30 | if {![regexp {fossil} $txt]} continue |
| 31 | if {![regexp {\nrepository: } $txt] && |
| 32 | ![regexp {\ndirectory: } $txt] && |
| 33 | ![regexp {\nredirect: } $txt]} continue |
| 34 | # |
| 35 | # At this point assume we have found a CGI file. |
| 36 | # |
| 37 | puts $obj |
| 38 | regsub -all {\n} [string trim $txt] "\n " out |
| 39 | puts " $out" |
| 40 | } |
| 41 | } |
| 42 | foreach dir $argv { |
| 43 | find_in_one_dir $dir |
| 44 | } |
| 45 |
| --- tools/find-fossil-cgis.tcl | |
| +++ tools/find-fossil-cgis.tcl | |
| @@ -3,20 +3,30 @@ | |
| 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 | # |
| 14 | # --has REGEXP Only show the CGI if the body matches REGEXP. |
| 15 | # May be repeated multiple times, in which case |
| 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 | } |
| @@ -29,16 +39,39 @@ | |
| 39 | if {![string match #!* $txt]} continue |
| 40 | if {![regexp {fossil} $txt]} continue |
| 41 | if {![regexp {\nrepository: } $txt] && |
| 42 | ![regexp {\ndirectory: } $txt] && |
| 43 | ![regexp {\nredirect: } $txt]} continue |
| 44 | set ok 1 |
| 45 | foreach re $HAS { |
| 46 | if {![regexp $re $txt]} {set ok 0; break;} |
| 47 | } |
| 48 | if {!$ok} continue |
| 49 | foreach re $HASNOT { |
| 50 | if {[regexp $re $txt]} {set ok 0; break;} |
| 51 | } |
| 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] |
| 69 | continue |
| 70 | } |
| 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 |