File:  [ELWIX - Embedded LightWeight unIX -] / embedaddon / pcre / Detrail
Revision 1.1.1.1 (vendor branch): download - view: text, annotated - select for diffs - revision graph
Mon Jul 22 08:25:56 2013 UTC (11 years, 5 months ago) by misho
Branches: pcre, MAIN
CVS tags: v8_34, v8_33, v8_31, v8_30, v8_21, HEAD
8.33

#!/usr/bin/perl

# This is a script for removing trailing whitespace from lines in files that
# are listed on the command line.

# This subroutine does the work for one file.

sub detrail {
my($file) = $_[0];
my($changed) = 0;
open(IN, "$file") || die "Can't open $file for input";
@lines = <IN>;
close(IN);
foreach (@lines)
  {
  if (/\s+\n$/)
    {
    s/\s+\n$/\n/;
    $changed = 1;
    }
  }
if ($changed)
  {
  open(OUT, ">$file") || die "Can't open $file for output";
  print OUT @lines;
  close(OUT);
  }
}

# This is the main program

$, = "";   # Output field separator
for ($i = 0; $i < @ARGV; $i++) { &detrail($ARGV[$i]); }

# End

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>