#!<myshell>
# dos2unix - converts files with DOS-style line endings to Unix-style
#            this implementation is just a semi-intelligent wrapper
#            for tr
# Markus Hoenicka <markus@mhoenicka.de> 010930
# $Id: refdb_dos2unix.in,v 1.1.2.1 2005/03/29 20:35:06 mhoenicka Exp $
# OPTIONS: -h (invoke help)
# relies on these external programs: tr

### start user-customizable section
### end user-customizable section

# read the command line options
while getopts ":h" opt; do
  case $opt in
    h  ) echo "converts files with DOS line ending (\\r\\n) to UNIX (\\n)"
	 echo 'usage: dos2unix [-h] file1 [file2...]'
	 echo "Options: -h print this help and exit"
	 exit 0 ;;
    \? ) echo 'usage: dos2unix [-h] file1 [file2...]'
	 exit 1;;
  esac
done

# correct the index so the filename argument is always $1
shift $(($OPTIND - 1))

for filename in $*; do
    tr -d '\r' < $filename > $filename.$$
    mv $filename.$$ $filename
done

exit 0
