Update ooo320-m1
[ooovba.git] / solenv / bin / leconvert.pl
blob519c5b125e9ad2e9b3478fdabf1662e2df262298
2 eval 'exec perl -wS $0 ${1+"$@"}'
3 if 0;
4 #*************************************************************************
6 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
7 #
8 # Copyright 2008 by Sun Microsystems, Inc.
10 # OpenOffice.org - a multi-platform office productivity suite
12 # $RCSfile: leconvert.pl,v $
14 # $Revision: 1.4 $
16 # This file is part of OpenOffice.org.
18 # OpenOffice.org is free software: you can redistribute it and/or modify
19 # it under the terms of the GNU Lesser General Public License version 3
20 # only, as published by the Free Software Foundation.
22 # OpenOffice.org is distributed in the hope that it will be useful,
23 # but WITHOUT ANY WARRANTY; without even the implied warranty of
24 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 # GNU Lesser General Public License version 3 for more details
26 # (a copy is included in the LICENSE file that accompanied this code).
28 # You should have received a copy of the GNU Lesser General Public License
29 # version 3 along with OpenOffice.org. If not, see
30 # <http://www.openoffice.org/license.html>
31 # for a copy of the LGPLv3 License.
33 #*************************************************************************
34 my $target_format = "";
35 my @filelist;
36 #my $debug=1;
37 my $debug=0;
39 parameter_parse(@ARGV);
40 print "@filelist\n" if ( $debug );
41 foreach my $onefile ( @filelist ) {
42 convert_file( $onefile );
46 sub convert_file
48 my $filename = shift;
49 if ( $target_format eq "dos" ) {
50 $lineend = "\r\n";
51 } else {
52 $lineend = "\n";
54 open INFILE, "$filename"or die "ERROR: Couldn\'t open $filename for reading.\n";
55 my @lines = <INFILE>;
56 close INFILE;
58 foreach my $oneline ( @lines ) {
59 $oneline =~ s/\r*\n*$/$lineend/;
62 open OUTFILE, ">$filename" or die "ERROR: Couldn\'t open $filename for writing.\n";
63 syswrite OUTFILE, join "", @lines;
64 close OUTFILE;
68 sub parameter_parse
70 if ( $target_format eq "" ) {
71 $target_format = shift ;
72 usage() if ( $target_format ne "unix" && $target_format ne "dos" );
73 usage() if ( $#_ == -1 );
75 foreach my $param ( @_ ) {
76 if ( $param =~ "^@" ) {
77 my $filename = $param;
78 $filename =~ s/^@//;
79 open CMDFILE, "$filename" or die "ERROR: Couldn\'t open $filename for reading.\n";
80 my @filelist = <CMDFILE>;
81 close CMDFILE;
82 parameter_parse( @filelist );
83 } else {
84 push @filelist, $param;
89 sub usage
91 print "Convert text files to the desired lineend convention:\n";
92 print "$0 <unix|dos> <FILE|\@filelist> [more files/lists]\n";
93 exit 1;