4 # This script is used to remove all unwanted files from a
5 # directory not in the .clean file list. This should only
6 # be used by maintainers when producing a release.
8 # Copyright (C) 2000, 2001, 2002 Free Software Foundation, Inc.
10 # This program is free software; you can redistribute it and/or modify
11 # it under the terms of the GNU General Public License as published by
12 # the Free Software Foundation; either version 2 of the License, or
13 # (at your option) any later version.
15 # This program is distributed in the hope that it will be useful,
16 # but WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 # GNU General Public License for more details.
20 # You should have received a copy of the GNU General Public License
21 # along with this program; if not, write to the Free Software
22 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 # Please email any bugs, comments, and/or additions to this file to:
27 # This file was written by Rob Savoye. (rob@welcomehome.org)
29 # default to no verbosity
30 if ![info exists verbose
] {
35 puts "USAGE: Clean.tcl \[options...\]"
36 puts "\t--verbose (-v)\t\tPrint all test output to screen"
39 # print a message if it's verbosity is greater than the default
40 proc verbose
{ args
} {
45 if { [string index
[lindex $args 0] 0] == "-" } {
46 for { set i
0 } { $i < [llength $args] } { incr i
} {
47 if { [lindex $args $i] == "--" } {
50 } elseif
{ [lindex $args $i] == "-n" } {
52 } elseif
{ [string index
[lindex $args $i] 0] == "-" } {
53 puts "ERROR: verbose: illegal argument: [lindex $args $i]"
59 if { [llength $args] == $i } {
60 puts "ERROR: verbose: nothing to print"
66 if { [llength $args] > $i + 1 } {
67 set level
[lindex $args [expr $i+1]]
69 set message [lindex $args $i]
71 if { $verbose >= $level } {
72 # There is no need for the "--" argument here, but play it safe.
73 # We assume send_user also sends the text to the log file (which
74 # appears to be the case though the docs aren't clear on this).
76 puts -nonewline "$message\n"
78 puts -nonewline "$message"
83 # process the command line arguments
84 for { set i
0 } { $i < $argc } { incr i
} {
85 set option [lindex $argv $i]
87 # make all options have two hyphens
88 switch -glob -- $option {
97 switch -glob -- $option {
98 "--he*" { # (--help) help text
104 "--verb*" { # (--verbose) verbose output
110 verbose
"Verbose level is $verbose" 2
112 proc cleanfiles
{ directory
} {
115 # get a list of all the files in this directory
116 set allfiles
[glob -nocomplain "$directory/*"]
117 regsub -all "$directory/" $allfiles "" allfiles
119 # open the .clean file, which has the list of stuff we
121 catch "set cleanfile [open "$directory/.clean
" r]"
122 if ![info exists cleanfile
] {
123 verbose
"WARNING: no .clean file in $directory, removing the default set of \"*! core CVS RCS\"" 3
124 set allfiles
[glob -nocomplain "$directory/*~"]
125 append allfiles
" [glob -nocomplain "$directory/core
*"]"
126 append allfiles
" [glob -nocomplain "$directory/CVS
"]"
127 append allfiles
" [glob -nocomplain "$directory/Cvs.
*"]"
128 append allfiles
" [glob -nocomplain "$directory/*.out
"]"
129 append allfiles
" [glob -nocomplain "$directory/*.dvi
"]"
130 append allfiles
" [glob -nocomplain "$directory/*.rej
"]"
131 append allfiles
" [glob -nocomplain "$directory/*.orig
"]"
132 append allfiles
" [glob -nocomplain "$directory/*.log
"]"
133 append allfiles
" [glob -nocomplain "$directory/*.cvsignore
"]"
134 append allfiles
" [glob -nocomplain "$directory/*.tgz
"]"
135 append allfiles
" [glob -nocomplain "$directory/*.tar.gz
"]"
136 append allfiles
" [glob -nocomplain "$directory/autom4te.cache
"]"
137 append allfiles
" [glob -nocomplain "$directory/RCS
"]"
138 append allfiles
" [glob -nocomplain "$directory/.
\#*"]"
140 # read in the .clean file, line by line
141 while { [gets $cleanfile cur_line
]>=0 } {
143 if { [string index
$cur_line 0] == "\#" } {
144 verbose
"Ignoring comment" 2
148 if { [string length
$cur_line]<=0 } {
149 verbose
"Ignoring blank line" 2
152 regsub -all "\[\+\]" $cur_line "\\+" cur_line
153 # remove the filename from the list
154 regsub -all " $cur_line " $allfiles " " allfiles
155 # also match the name if it's the last one in the file
156 regsub -all " $cur_line$" $allfiles " " allfiles
157 # also match if it's the only name in the list
158 regsub -all "^$cur_line" $allfiles " " allfiles
162 # remove the leading and trailing blank spaces for cleanliness sake
163 set allfiles
[string trimleft
$allfiles]
164 set allfiles
[string trimright
$allfiles]
166 if { [string length
$allfiles] > 0 } {
167 verbose
"Removing \"$allfiles\" from $directory"
168 catch "exec rm -fr $allfiles"
170 verbose
"Nothing to remove from $directory" 2
173 # close the .clean file
174 catch "close $cleanfile"
178 # now that we've removed everything we don't want from this
179 # directory, recur into the directories that are left to clean
182 proc getdirs
{ directory
} {
184 set files
[glob -nocomplain "$directory/*"]
185 if { [llength $files] != 0 } {
187 if [file isdirectory
$j] {
189 append dirs
" [getdirs $j]"
197 # now we actually do it all
198 foreach i
[getdirs .
] {