3 # stripspaces.tcl - strip trailing spaces from source files
5 # Author: Johnny Mnemonic <johnny@themnemonic.org>
7 # Copyright (C) 2002 Johnny Mnemonic
9 # This program is free software; you can redistribute it and/or modify
10 # it under the terms of the GNU General Public License as published by
11 # the Free Software Foundation; version 2 of the License.
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
21 proc do_strip_main {in_file out_file} {
23 if {[catch {set fd [open "$in_file" r]} errtmp]} {return -1}
24 if {[catch {set fw [open "$out_file" w]} errtmp]} {return -1}
27 set str [string trimright [gets $fd]]
42 puts stderr "Usage: `./stripspaces.tcl <file> \[output\]'"
47 set in_file [lindex $argv 0]
49 if {![file readable $in_file]} {
50 puts stderr "Error: Cannot open file \"$in_file\"."
56 set out_file [lindex $argv 1]
58 set out_file "$in_file.strip"
61 puts stderr "Stripping trailing spaces from \"$in_file\" (output: \"$out_file\")"
63 set ret [do_strip_main $in_file $out_file]
66 puts stderr "Failed. Couldn't open the input/output filename."
69 puts stderr "Done. Parsed $ret lines."