crossroads

Git mirror of https://crossroads.e-tunity.com/
git clone git://git.finwo.net/app/crossroads
Log | Files | Refs

untab (729B)


      1 #!/usr/bin/perl
      2 
      3 use strict;
      4 
      5 die ("Usage: untab file [file...]\n") if ($#ARGV == -1);
      6 
      7 for my $in (@ARGV) {
      8     my $out = "$in.new";
      9     open (my $fin, $in)      or die ("Can't read $in: $!\n");
     10     open (my $fout, ">$out") or die ("Can't write $out: $!\n");
     11 
     12     my $changed = 0;
     13     while (defined (my $line = <$fin>)) {
     14 	while ($line =~ /^\t/) {
     15 	    $line =~ s/^\t/        /;
     16 	    $changed++;
     17 	}
     18 	print $fout ($line);
     19     }
     20 
     21     close ($fin);
     22     close ($fout);
     23 
     24     if (!$changed) {
     25 	unlink ($out)      or die ("Can't unlink $out: $!\n");
     26     } else {
     27 	print ("Untabbed $in ($changed times)\n");
     28 	unlink ($in)       or die ("Can't unlink $in: $!\n");
     29 	rename ($out, $in) or die ("Can't rename $out to $in: $!\n");
     30     }
     31 }
     32