~ubuntu-branches/ubuntu/feisty/apache2/feisty

« back to all changes in this revision

Viewing changes to srclib/apr/build/lineends.pl

  • Committer: Bazaar Package Importer
  • Author(s): Andreas Barth
  • Date: 2006-12-09 21:05:45 UTC
  • mfrom: (0.6.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20061209210545-h70s0xaqc2v8vqr2
Tags: 2.2.3-3.2
* Non-maintainer upload.
* 043_ajp_connection_reuse: Patch from upstream Bugzilla, fixing a critical
  issue with regard to connection reuse in mod_proxy_ajp.
  Closes: #396265

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/local/bin/perl
 
2
#
 
3
#  Heuristically converts line endings to the current OS's preferred format
 
4
#  
 
5
#  All existing line endings must be identical (e.g. lf's only, or even
 
6
#  the accedental cr.cr.lf sequence.)  If some lines end lf, and others as
 
7
#  cr.lf, the file is presumed binary.  If the cr character appears anywhere
 
8
#  except prefixed to an lf, the file is presumed binary.  If there is no 
 
9
#  change in the resulting file size, or the file is binary, the conversion 
 
10
#  is discarded.
 
11
#  
 
12
#  Todo: Handle NULL stdin characters gracefully.
 
13
#
 
14
 
 
15
use IO::File;
 
16
use File::Find;
 
17
 
 
18
# The ignore list is '-' seperated, with this leading hyphen and
 
19
# trailing hyphens in ever concatinated list below.
 
20
$ignore = "-";
 
21
 
 
22
# Image formats
 
23
$ignore .= "gif-jpg-jpeg-png-ico-bmp-";
 
24
 
 
25
# Archive formats
 
26
$ignore .= "tar-gz-z-zip-jar-war-bz2-tgz-";
 
27
 
 
28
# Many document formats
 
29
$ignore .= "eps-psd-pdf-ai-";
 
30
 
 
31
# Some encodings
 
32
$ignore .= "ucs2-ucs4-";
 
33
 
 
34
# Some binary objects
 
35
$ignore .= "class-so-dll-exe-obj-a-o-lo-slo-sl-dylib-";
 
36
 
 
37
# Some build env files 
 
38
$ignore .= "mcp-xdc-ncb-opt-pdb-ilk-sbr-";
 
39
 
 
40
$preservedate = 1;
 
41
 
 
42
$forceending = 0;
 
43
 
 
44
$givenpaths = 0;
 
45
 
 
46
$notnative = 0;
 
47
 
 
48
while (defined @ARGV[0]) {
 
49
    if (@ARGV[0] eq '--touch') {
 
50
        $preservedate = 0;
 
51
    }
 
52
    elsif (@ARGV[0] eq '--nocr') {
 
53
        $notnative = -1;
 
54
    }
 
55
    elsif (@ARGV[0] eq '--cr') {
 
56
        $notnative = 1;
 
57
    }
 
58
    elsif (@ARGV[0] eq '--force') {
 
59
        $forceending = 1;
 
60
    }
 
61
    elsif (@ARGV[0] eq '--FORCE') {
 
62
        $forceending = 2;
 
63
    }
 
64
    elsif (@ARGV[0] =~ m/^-/) {
 
65
        die "What is " . @ARGV[0] . " supposed to mean?\n\n" 
 
66
          . "Syntax:\t$0 [option()s] [path(s)]\n\n" . <<'OUTCH'
 
67
Where:  paths specifies the top level directory to convert (default of '.')
 
68
        options are;
 
69
 
 
70
          --cr     keep/add one ^M
 
71
          --nocr   remove ^M's
 
72
          --touch  the datestamp (default: keeps date/attribs)
 
73
          --force  mismatched corrections (unbalanced ^M's)
 
74
          --FORCE  all files regardless of file name!
 
75
 
 
76
OUTCH
 
77
    }
 
78
    else {
 
79
        find(\&totxt, @ARGV[0]);
 
80
        print "scanned " . @ARGV[0] . "\n";
 
81
        $givenpaths = 1;
 
82
    }
 
83
    shift @ARGV;
 
84
}
 
85
 
 
86
if (!$givenpaths) {
 
87
    find(\&totxt, '.');
 
88
    print "did .\n";
 
89
}
 
90
 
 
91
sub totxt {
 
92
        $oname = $_;
 
93
        $tname = '.#' . $_;
 
94
        if (!-f) {
 
95
            return;
 
96
        }
 
97
        @exts = split /\./;
 
98
        if ($forceending < 2) {
 
99
            while ($#exts && ($ext = pop(@exts))) {
 
100
                if ($ignore =~ m|-$ext-|i) {
 
101
                    return;
 
102
                }
 
103
            }
 
104
        }
 
105
        @ostat = stat($oname);
 
106
        $srcfl = new IO::File $oname, "r" or die;
 
107
        $dstfl = new IO::File $tname, "w" or die;
 
108
        binmode $srcfl; 
 
109
        if ($notnative) {
 
110
            binmode $dstfl;
 
111
        } 
 
112
        undef $t;
 
113
        while (<$srcfl>) { 
 
114
            if (s/(\r*)\n$/\n/) {
 
115
                $n = length $1;
 
116
                if (!defined $t) { 
 
117
                    $t = $n; 
 
118
                }
 
119
                if (!$forceending && (($n != $t) || m/\r/)) {
 
120
                    print "mismatch in " .$oname. ":" .$n. " expected " .$t. "\n";
 
121
                    undef $t;
 
122
                    last;
 
123
                }
 
124
                elsif ($notnative > 0) {
 
125
                    s/\n$/\r\n/; 
 
126
                }
 
127
            }
 
128
            print $dstfl $_; 
 
129
        }
 
130
        if (defined $t && (tell $srcfl == tell $dstfl)) {
 
131
            undef $t;
 
132
        }
 
133
        undef $srcfl;
 
134
        undef $dstfl;
 
135
        if (defined $t) {
 
136
            unlink $oname or die;
 
137
            rename $tname, $oname or die;
 
138
            @anames = ($oname);
 
139
            if ($preservedate) {
 
140
                utime $ostat[9], $ostat[9], @anames;
 
141
            }
 
142
            chmod $ostat[2] & 07777, @anames;
 
143
            chown $ostat[5], $ostat[6], @anames;
 
144
            print "Converted file " . $oname . " to text in " . $File::Find::dir . "\n"; 
 
145
        }
 
146
        else {
 
147
            unlink $tname or die;
 
148
        }
 
149
}