~vanvugt/ubuntu/oneiric/mediatomb/fix-770964-784431

« back to all changes in this revision

Viewing changes to scripts/whitespace_cleanup.pl

  • Committer: Bazaar Package Importer
  • Author(s): Andres Mejia
  • Date: 2009-04-22 21:39:19 UTC
  • mto: (4.2.1 sid)
  • mto: This revision was merged to the branch mainline in revision 9.
  • Revision ID: james.westby@ubuntu.com-20090422213919-52m015y6gcpv1m1g
Tags: upstream-0.12.0~svn2018
ImportĀ upstreamĀ versionĀ 0.12.0~svn2018

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/perl
 
2
 
 
3
use strict;
 
4
 
 
5
foreach (@ARGV)
 
6
{
 
7
    my $full_path = $_;
 
8
    #my @full_fn = split('/', $full_path);
 
9
    #my $filename = pop(@full_fn);
 
10
    
 
11
    print $full_path.": ";
 
12
    open (FILE, '<', $full_path);
 
13
    my $data = join('', <FILE>);
 
14
    close FILE;
 
15
 
 
16
    if (length($data) == 0)
 
17
    {
 
18
        print "0\n";
 
19
        next;
 
20
    }
 
21
 
 
22
    my $last_chars = substr($data, -2);
 
23
    #print "x-".$last_chars."-x";
 
24
    
 
25
    my $modified = 0;
 
26
    
 
27
    if ($last_chars =~ m|^[^\n]\n|s)
 
28
    {
 
29
        print "-";
 
30
    }
 
31
    else
 
32
    {
 
33
        if ($last_chars eq "\n\n")
 
34
        {
 
35
            print "!!!!!!";
 
36
            $data =~ s|\n+$|\n|s;
 
37
            $modified = 1;
 
38
        }
 
39
        else
 
40
        {
 
41
            print "!-!-!-!-!-!";
 
42
        }
 
43
    }
 
44
    
 
45
    if ($modified)
 
46
    {
 
47
        #$last_chars = substr($data, -2);
 
48
        printf("y-%x %x-y",ord(substr($data,-2,1)), ord(substr($data,-1)));
 
49
    }
 
50
    
 
51
    if (0) #tab-cleanup
 
52
    {
 
53
        my $data_before = $data;
 
54
        
 
55
        $data =~ s|\t|    |g;
 
56
    
 
57
        if ($data_before ne $data)
 
58
        {
 
59
            print "TAB";
 
60
            $modified = 1;
 
61
        }
 
62
    }
 
63
    
 
64
    # off for safety reasons
 
65
    $modified = 0;
 
66
 
 
67
    if ($modified)
 
68
    {
 
69
        open (FILE, '>', $full_path);
 
70
        print FILE $data;
 
71
#       print $data;
 
72
        close FILE;
 
73
    }
 
74
    print "\n";
 
75
}