Fossil SCM

Add the --has and --hasnot options to the find-fossil-cgis.tcl script.

drh 2025-03-29 00:22 trunk
Commit ccb7cc4ecd6ed7797b7c7125134192deba24e50e1a767b509b9f71ee8a5970f3
1 file changed +35 -2
--- tools/find-fossil-cgis.tcl
+++ tools/find-fossil-cgis.tcl
@@ -3,20 +3,30 @@
33
# This script scans a directory hierarchy looking for Fossil CGI files -
44
# the files that are used to launch Fossil as a CGI program. For each
55
# such file found, in prints the name of the file and then prints the
66
# file content, indented.
77
#
8
-# tclsh find-fossil-cgis.tcl $DIRECTORY
8
+# tclsh find-fossil-cgis.tcl [OPTIONS] $DIRECTORY
99
#
1010
# 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.
1120
#
1221
1322
1423
# Find the CGIs in directory $dir. Invoke recursively to
1524
# scan subdirectories.
1625
#
1726
proc find_in_one_dir {dir} {
27
+ global HAS HASNOT
1828
foreach obj [lsort [glob -nocomplain -directory $dir *]] {
1929
if {[file isdir $obj]} {
2030
find_in_one_dir $obj
2131
continue
2232
}
@@ -29,16 +39,39 @@
2939
if {![string match #!* $txt]} continue
3040
if {![regexp {fossil} $txt]} continue
3141
if {![regexp {\nrepository: } $txt] &&
3242
![regexp {\ndirectory: } $txt] &&
3343
![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
3453
#
3554
# At this point assume we have found a CGI file.
3655
#
3756
puts $obj
3857
regsub -all {\n} [string trim $txt] "\n " out
3958
puts " $out"
4059
}
4160
}
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
+ }
4376
find_in_one_dir $dir
4477
}
4578
--- 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

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button