From: Giovanni Giacobbi Date: Mon, 8 Apr 2002 18:41:38 +0000 (+0000) Subject: added this small script to clean the source files X-Git-Tag: silc.client.0.8.6~4^2~19 X-Git-Url: http://git.silcnet.org/gitweb/?p=silc.git;a=commitdiff_plain;h=486df9cbf554ad550bdaeb0429fbad278604aa0e added this small script to clean the source files --- diff --git a/scripts/stripspaces.tcl b/scripts/stripspaces.tcl new file mode 100755 index 00000000..4bdcdee0 --- /dev/null +++ b/scripts/stripspaces.tcl @@ -0,0 +1,70 @@ +#! /usr/bin/tcl +# +# stripspaces.tcl - strip trailing spaces from source files +# +# Author: Johnny Mnemonic +# +# Copyright (C) 2002 Johnny Mnemonic +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; version 2 of the License. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# + +# Procedures +# --- +proc do_strip_main {in_file out_file} { + set lines 0 + if {[catch {set fd [open "$in_file" r]} errtmp]} {return -1} + if {[catch {set fw [open "$out_file" w]} errtmp]} {return -1} + + while {![eof $fd]} { + set str [string trimright [gets $fd]] + if {![eof $fd]} { + incr lines + puts $fw $str; + } + } + + close $fd + close $fw + return $lines +} + +# Main +# --- +if {$argc < 1} { + puts stderr "Usage: `./stripspaces.tcl \[output\]'" + puts stderr "" + exit 1 +} + +set in_file [lindex $argv 0] + +if {![file readable $in_file]} { + puts stderr "Error: Cannot open file \"$in_file\"." + puts stderr "" + exit 1 +} + +if {$argc > 1} { + set out_file [lindex $argv 1] +} else { + set out_file "$in_file.strip" +} + +puts stderr "Stripping trailing spaces from \"$in_file\" (output: \"$out_file\")" + +set ret [do_strip_main $in_file $out_file] + +if {$ret < 0} { + puts stderr "Failed. Couldn't open the input/output filename." + puts stderr "" +} else { + puts stderr "Done. Parsed $ret lines." +}