#!/usr/bin/ksh93
################################################################
#### Program: unix2dos_k93
#### 
#### Description: Emulation of the Unix "unix2dos" command
#### 
#### Author: Dana French (dfrench@mtxia.com)
####         Copyright 2004
#### 
#### Date: 07/22/2004
#### 
################################################################
function unix2dos_k93 {
  typeset TRUE="0"
  typeset FALSE="1"
  typeset unix2dosCOLS="${FALSE}"
  typeset unix2dosFLDS="${FALSE}"
  typeset VERBOSE="${FALSE}"
  typeset VERYVERB="${FALSE}"
  typeset FNAME

  while getopts ":vV" OPTION
  do
    case "${OPTION}" in
        'v') VERBOSE="${TRUE}";;
        'V') VERYVERB="${TRUE}";;
        '?') print "Syntax: unix2dos_k93 file ..." && exit 1 ;;
    esac
  done
 
  shift $(( ${OPTIND} - 1 ))

  typeset STDIN="${1:+${FALSE}}"
  STDIN="${STDIN:-${TRUE}}"

#### Read in the data either from STDIN or one or more files
  if (( STDIN == TRUE ))
  then
      u2d_k93
  else
      for FNAME in "${@}"
      do
          exec 0<"${FNAME}"
            u2d_k93
          exec 0<&-
      done
  fi

  return 0
}
################################################################
function u2d_k93 {
    typeset LINE

    while read -r -- LINE
    do
        if [[ "_${LINE}" = "_" ]]
        then
            print -r -- $'\r'
        else
            print -r -- "${LINE/%[!$'\r']/$'\r'}"
        fi
    done
}
################################################################

unix2dos_k93 "${@}"