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 (10 years, 10 months ago) by misho
Branches: pcre, MAIN
CVS tags: v8_34, v8_33, v8_31, v8_30, v8_21, HEAD
8.33

    1: #!/usr/bin/perl
    2: 
    3: # This is a script for removing trailing whitespace from lines in files that
    4: # are listed on the command line.
    5: 
    6: # This subroutine does the work for one file.
    7: 
    8: sub detrail {
    9: my($file) = $_[0];
   10: my($changed) = 0;
   11: open(IN, "$file") || die "Can't open $file for input";
   12: @lines = <IN>;
   13: close(IN);
   14: foreach (@lines)
   15:   {
   16:   if (/\s+\n$/)
   17:     {
   18:     s/\s+\n$/\n/;
   19:     $changed = 1;
   20:     }
   21:   }
   22: if ($changed)
   23:   {
   24:   open(OUT, ">$file") || die "Can't open $file for output";
   25:   print OUT @lines;
   26:   close(OUT);
   27:   }
   28: }
   29: 
   30: # This is the main program
   31: 
   32: $, = "";   # Output field separator
   33: for ($i = 0; $i < @ARGV; $i++) { &detrail($ARGV[$i]); }
   34: 
   35: # End

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