#! /bin/csh -f
#Status: R

# ------------------------------------------------------------------------------
# procedure  : dos2unix
# purpose    : remove ^M at the end of line , UNIX doesn't use CR
# purpose    : and remove ^Z at the end of the file
# procedure  : unix2dos
# purpose    : add ^M at the end of line    , DOS needs a CR
# purpose    : and remove ^Z at the end of the file
# programmer : A. Pellizzon
# date       : Oct1097
# ------------------------------------------------------------------------------
#
# ------------------------------------------------------------------------------
# procedure  : dos2unix
# purpose    : remove ^M at the end of line , UNIX doesn't use CR
# procedure  : unix2dos
# purpose    : add ^M at the end of line    , DOS needs a CR
# programmer : C. Wenigwieser
# date       : mar2094
# ------------------------------------------------------------------------------
#

set prg=`basename $0`

if ( $prg == dos2unix ) then
    set sed_opt='1,$ s/$//'    # remove CR   instead of @ type in vi ^V^M
else
    set sed_opt='1,$s/$//'     # add CR
endif

set sed_opt2='$ s/^$//'      # Always remove  final CTRL-Z

 # do it ..
foreach item ( $argv )
  if ( ! -d $item && -w $item ) then
     mv $item $item.old
     if ( -e $item.old ) then
        sed -e "$sed_opt" <$item.old | sed -e "$sed_opt2" >$item
        rm $item.old
        echo " $prg :   $item"
     else
        # something must have gone wrong  (permissions ?)
        echo "Error while converting  : " $*
     endif
  endif
end
exit 0
