Fossil SCM

New command-line options for find-fossil-cgis.tcl: --print, --symlink, and -v.

drh 2025-03-29 10:44 trunk
Commit 609f885a02afc17c3573314255eccb9a94c37e94af7553ea6ae1b1bc711f0922
1 file changed +52 -8
--- tools/find-fossil-cgis.tcl
+++ tools/find-fossil-cgis.tcl
@@ -1,13 +1,13 @@
11
#!/usr/bin/tclsh
22
#
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
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.
77
#
8
-# tclsh find-fossil-cgis.tcl [OPTIONS] $DIRECTORY
8
+# tclsh find-fossil-cgis.tcl [OPTIONS] DIRECTORY
99
#
1010
# The argument is the directory from which to begin the search.
1111
#
1212
# OPTIONS can be zero or more of the following:
1313
#
@@ -16,24 +16,35 @@
1616
# all must match.
1717
#
1818
# --hasnot REGEXP Only show the CGI if it does NOT match the
1919
# REGEXP.
2020
#
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
+#
2229
2330
# Find the CGIs in directory $dir. Invoke recursively to
2431
# scan subdirectories.
2532
#
2633
proc find_in_one_dir {dir} {
27
- global HAS HASNOT
34
+ global HAS HASNOT PRINT V
35
+ if {$V>0} {
36
+ puts "# $dir"
37
+ }
2838
foreach obj [lsort [glob -nocomplain -directory $dir *]] {
2939
if {[file isdir $obj]} {
3040
find_in_one_dir $obj
3141
continue
3242
}
3343
if {![file isfile $obj]} continue
3444
if {[file size $obj]>5000} continue
45
+ if {![file exec $obj]} continue
3546
if {![file readable $obj]} continue
3647
set fd [open $obj rb]
3748
set txt [read $fd]
3849
close $fd
3950
if {![string match #!* $txt]} continue
@@ -52,17 +63,27 @@
5263
if {!$ok} continue
5364
#
5465
# At this point assume we have found a CGI file.
5566
#
5667
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
+ }
5972
}
6073
}
6174
set HAS [list]
6275
set HASNOT [list]
76
+set PRINT 0
77
+set SYMLINK 0
78
+set V 0
6379
set N [llength $argv]
80
+set DIRLIST [list]
81
+
82
+# First pass: Gather all the command-line arguments but do no
83
+# processing.
84
+#
6485
for {set i 0} {$i<$N} {incr i} {
6586
set dir [lindex $argv $i]
6687
if {($dir eq "-has" || $dir eq "--has") && $i<[expr {$N-1}]} {
6788
incr i
6889
lappend HAS [lindex $argv $i]
@@ -71,7 +92,30 @@
7192
if {($dir eq "-hasnot" || $dir eq "--hasnot") && $i<[expr {$N-1}]} {
7293
incr i
7394
lappend HASNOT [lindex $argv $i]
7495
continue
7596
}
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
+ }
77121
}
78122
--- 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

Keyboard Shortcuts

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