#!/bin/sh
##################################################################
# $Id: d2u, v-0.3 : GPL-v2 : 2003/05/10 17:25:45 bish Exp $
# (C) 2003 USM Bish <bish@nde.vsnl.net.in>
# Released under GNU GPL v2 - http://www.gnu.org/copyleft/gpl.html
##################################################################

##################################################################
# Purpose: To convert DOS text files to Unix. (viz. strips the
# ASCII 13 chars from the end of each DOS line). Uses tr to do
# the job.  Nothing great from my side !  Placed  on this site
# on the insistance of a few friends just too lazy to remember 
# or type a tr one liner :-)
##################################################################

##################################################################
# Usage: $PROGNAME [dosfile] [unixfile]
##################################################################

##################################################################
#  Constants
##################################################################

PROGNAME=$(basename $0)
VERSION="0.3"
DOSFILE=$1
UNIXFILE=$2

#################################################################
# Begin
#################################################################

echo $PROGNAME" ...   Version 0.3"

# Command tail has 2 params : otherwise abort
if [ $# -ne 2 ]; then
     echo 1>&2 Usage: $PROGNAME [dosfile] [unixfile]
     exit 1
     
else     
    # Check for presence of input file
    if ! [ -e $DOSFILE ] ; then 
         echo "Read Error: ["$DOSFILE"] Not found !"
         exit 1
    fi

    # And check for existance of Output file
    if [ -e $UNIXFILE ] ; then 
         echo "Trouble : Unix File ["$UNIXFILE"] exists !"
         exit 1
    fi
fi

################################################################
# If both filenames entered, file found and the  output filename 
# is unique, then do the only line in the script which is needed
################################################################

    cat $DOSFILE | tr -d '\015' > $UNIXFILE     
    echo "Done ... $UNIXFILE created "
    exit 0
    
###############################################################    
# End of an unique demo of a one liner being made into a 65
# line script :-)
###############################################################

