1*b1cdbd2cSJim Jagielski: 2*b1cdbd2cSJim Jagielskieval 'exec perl -wS $0 ${1+"$@"}' 3*b1cdbd2cSJim Jagielski if 0; 4*b1cdbd2cSJim Jagielski#************************************************************** 5*b1cdbd2cSJim Jagielski# 6*b1cdbd2cSJim Jagielski# Licensed to the Apache Software Foundation (ASF) under one 7*b1cdbd2cSJim Jagielski# or more contributor license agreements. See the NOTICE file 8*b1cdbd2cSJim Jagielski# distributed with this work for additional information 9*b1cdbd2cSJim Jagielski# regarding copyright ownership. The ASF licenses this file 10*b1cdbd2cSJim Jagielski# to you under the Apache License, Version 2.0 (the 11*b1cdbd2cSJim Jagielski# "License"); you may not use this file except in compliance 12*b1cdbd2cSJim Jagielski# with the License. You may obtain a copy of the License at 13*b1cdbd2cSJim Jagielski# 14*b1cdbd2cSJim Jagielski# http://www.apache.org/licenses/LICENSE-2.0 15*b1cdbd2cSJim Jagielski# 16*b1cdbd2cSJim Jagielski# Unless required by applicable law or agreed to in writing, 17*b1cdbd2cSJim Jagielski# software distributed under the License is distributed on an 18*b1cdbd2cSJim Jagielski# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 19*b1cdbd2cSJim Jagielski# KIND, either express or implied. See the License for the 20*b1cdbd2cSJim Jagielski# specific language governing permissions and limitations 21*b1cdbd2cSJim Jagielski# under the License. 22*b1cdbd2cSJim Jagielski# 23*b1cdbd2cSJim Jagielski#************************************************************** 24*b1cdbd2cSJim Jagielski 25*b1cdbd2cSJim Jagielski 26*b1cdbd2cSJim Jagielskimy $target_format = ""; 27*b1cdbd2cSJim Jagielskimy @filelist; 28*b1cdbd2cSJim Jagielski#my $debug=1; 29*b1cdbd2cSJim Jagielskimy $debug=0; 30*b1cdbd2cSJim Jagielski 31*b1cdbd2cSJim Jagielskiparameter_parse(@ARGV); 32*b1cdbd2cSJim Jagielskiprint "@filelist\n" if ( $debug ); 33*b1cdbd2cSJim Jagielskiforeach my $onefile ( @filelist ) { 34*b1cdbd2cSJim Jagielski convert_file( $onefile ); 35*b1cdbd2cSJim Jagielski} 36*b1cdbd2cSJim Jagielski 37*b1cdbd2cSJim Jagielski 38*b1cdbd2cSJim Jagielskisub convert_file 39*b1cdbd2cSJim Jagielski{ 40*b1cdbd2cSJim Jagielski my $filename = shift; 41*b1cdbd2cSJim Jagielski if ( $target_format eq "dos" ) { 42*b1cdbd2cSJim Jagielski $lineend = "\r\n"; 43*b1cdbd2cSJim Jagielski } else { 44*b1cdbd2cSJim Jagielski $lineend = "\n"; 45*b1cdbd2cSJim Jagielski } 46*b1cdbd2cSJim Jagielski open INFILE, "$filename"or die "ERROR: Couldn\'t open $filename for reading.\n"; 47*b1cdbd2cSJim Jagielski my @lines = <INFILE>; 48*b1cdbd2cSJim Jagielski close INFILE; 49*b1cdbd2cSJim Jagielski 50*b1cdbd2cSJim Jagielski foreach my $oneline ( @lines ) { 51*b1cdbd2cSJim Jagielski $oneline =~ s/\r*\n*$/$lineend/; 52*b1cdbd2cSJim Jagielski } 53*b1cdbd2cSJim Jagielski 54*b1cdbd2cSJim Jagielski open OUTFILE, ">$filename" or die "ERROR: Couldn\'t open $filename for writing.\n"; 55*b1cdbd2cSJim Jagielski syswrite OUTFILE, join "", @lines; 56*b1cdbd2cSJim Jagielski close OUTFILE; 57*b1cdbd2cSJim Jagielski 58*b1cdbd2cSJim Jagielski} 59*b1cdbd2cSJim Jagielski 60*b1cdbd2cSJim Jagielskisub parameter_parse 61*b1cdbd2cSJim Jagielski{ 62*b1cdbd2cSJim Jagielski if ( $target_format eq "" ) { 63*b1cdbd2cSJim Jagielski $target_format = shift ; 64*b1cdbd2cSJim Jagielski usage() if ( $target_format ne "unix" && $target_format ne "dos" ); 65*b1cdbd2cSJim Jagielski usage() if ( $#_ == -1 ); 66*b1cdbd2cSJim Jagielski } 67*b1cdbd2cSJim Jagielski foreach my $param ( @_ ) { 68*b1cdbd2cSJim Jagielski if ( $param =~ "^@" ) { 69*b1cdbd2cSJim Jagielski my $filename = $param; 70*b1cdbd2cSJim Jagielski $filename =~ s/^@//; 71*b1cdbd2cSJim Jagielski open CMDFILE, "$filename" or die "ERROR: Couldn\'t open $filename for reading.\n"; 72*b1cdbd2cSJim Jagielski my @filelist = <CMDFILE>; 73*b1cdbd2cSJim Jagielski close CMDFILE; 74*b1cdbd2cSJim Jagielski parameter_parse( @filelist ); 75*b1cdbd2cSJim Jagielski } else { 76*b1cdbd2cSJim Jagielski push @filelist, $param; 77*b1cdbd2cSJim Jagielski } 78*b1cdbd2cSJim Jagielski } 79*b1cdbd2cSJim Jagielski} 80*b1cdbd2cSJim Jagielski 81*b1cdbd2cSJim Jagielskisub usage 82*b1cdbd2cSJim Jagielski{ 83*b1cdbd2cSJim Jagielski print "Convert text files to the desired lineend convention:\n"; 84*b1cdbd2cSJim Jagielski print "$0 <unix|dos> <FILE|\@filelist> [more files/lists]\n"; 85*b1cdbd2cSJim Jagielski exit 1; 86*b1cdbd2cSJim Jagielski} 87*b1cdbd2cSJim Jagielski 88