3 # Licensed to the Apache Software Foundation (ASF) under one or more
4 # contributor license agreements. See the NOTICE file distributed with
5 # this work for additional information regarding copyright ownership.
6 # The ASF licenses this file to You under the Apache License, Version 2.0
7 # (the "License"); you may not use this file except in compliance with
8 # the License. You may obtain a copy of the License at
10 # http://www.apache.org/licenses/LICENSE-2.0
12 # Unless required by applicable law or agreed to in writing, software
13 # distributed under the License is distributed on an "AS IS" BASIS,
14 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 # See the License for the specific language governing permissions and
16 # limitations under the License.
19 # Heuristically converts line endings to the current OS's preferred format
21 # All existing line endings must be identical (e.g. lf's only, or even
22 # the accedental cr.cr.lf sequence.) If some lines end lf, and others as
23 # cr.lf, the file is presumed binary. If the cr character appears anywhere
24 # except prefixed to an lf, the file is presumed binary. If there is no
25 # change in the resulting file size, or the file is binary, the conversion
28 # Todo: Handle NULL stdin characters gracefully.
34 # The ignore list is '-' seperated, with this leading hyphen and
35 # trailing hyphens in ever concatinated list below.
39 $ignore .= "gif-jpg-jpeg-png-ico-bmp-";
42 $ignore .= "tar-gz-z-zip-jar-war-bz2-tgz-";
44 # Many document formats
45 $ignore .= "eps-psd-pdf-ai-";
48 $ignore .= "ucs2-ucs4-";
51 $ignore .= "class-so-dll-exe-obj-a-o-lo-slo-sl-dylib-";
53 # Some build env files
54 $ignore .= "mcp-xdc-ncb-opt-pdb-ilk-sbr-";
64 while (defined @ARGV[0]) {
65 if (@ARGV[0] eq '--touch') {
68 elsif (@ARGV[0] eq '--nocr') {
71 elsif (@ARGV[0] eq '--cr') {
74 elsif (@ARGV[0] eq '--force') {
77 elsif (@ARGV[0] eq '--FORCE') {
80 elsif (@ARGV[0] =~ m/^-/) {
81 die "What is " . @ARGV[0] . " supposed to mean?\n\n"
82 . "Syntax:\t$0 [option()s] [path(s)]\n\n" . <<'OUTCH'
83 Where: paths specifies the top level directory to convert (default of '.')
88 --touch the datestamp (default: keeps date/attribs)
89 --force mismatched corrections (unbalanced ^M's)
90 --FORCE all files regardless of file name!
95 find(\&totxt, @ARGV[0]);
96 print "scanned " . @ARGV[0] . "\n";
114 if ($forceending < 2) {
115 while ($#exts && ($ext = pop(@exts))) {
116 if ($ignore =~ m|-$ext-|i) {
121 @ostat = stat($oname);
122 $srcfl = new IO::File $oname, "r" or die;
123 $dstfl = new IO::File $tname, "w" or die;
130 if (s/(\r*)\n$/\n/) {
135 if (!$forceending && (($n != $t) || m/\r/)) {
136 print "mismatch in " .$oname. ":" .$n. " expected " .$t. "\n";
140 elsif ($notnative > 0) {
146 if (defined $t && (tell $srcfl == tell $dstfl)) {
152 unlink $oname or die;
153 rename $tname, $oname or die;
156 utime $ostat[9], $ostat[9], @anames;
158 chmod $ostat[2] & 07777, @anames;
159 chown $ostat[5], $ostat[6], @anames;
160 print "Converted file " . $oname . " to text in " . $File::Find::dir . "\n";
163 unlink $tname or die;