#!/usr/bin/perl

############################################################################
# This file is part of FreeFEM.                                            #
#                                                                          #
# FreeFEM is free software: you can redistribute it and/or modify          #
# it under the terms of the GNU Lesser General Public License as           #
# published by the Free Software Foundation, either version 3 of           #
# the License, or (at your option) any later version.                      #
#                                                                          #
# FreeFEM is distributed in the hope that it will be useful,               #
# but WITHOUT ANY WARRANTY; without even the implied warranty of           #
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            #
# GNU Lesser General Public License for more details.                      #
#                                                                          #
# You should have received a copy of the GNU Lesser General Public License #
# along with FreeFEM. If not, see <http://www.gnu.org/licenses/>.          #
############################################################################
# SUMMARY : ...
# LICENSE : LGPLv3
# ORG     : LJLL Universite Pierre et Marie Curie, Paris, FRANCE
# AUTHORS : Antoine Le Hyaric
# E-MAIL  : ...

# clean-up all CR/LF line endings (usually before patching to avoid failures after editing the same source files on
# different systems)

use strict;

# change files that have been recorded in FF using DOS line endings
my @files=`find $ARGV[0] -type f`;
chomp @files;
foreach my $file(@files){
  next if $file=~/\.(jpg|eps|mcp|pdf|pgm|o|a|so|png|jpg|gz|tgz)$/;
  next if $file=~/\.hg\//;
  my $contents=`cat $file`;
  my $oldcontents=$contents;

  # changing line-ending conventions. all ffcs patches work from unix-style (ie no CR) files

  $contents=~s/\r$//gm;
  next if $contents eq $oldcontents;
  print "cleancrlf: Unix line-ending for $file...\n";
  open FILE,">$file" or die;
  print FILE $contents;
  close FILE;
}

# Local Variables:
# mode:cperl
# ispell-local-dictionary:"british"
# coding:utf-8
# End:
