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

  while getopts ":vV" OPTION
  do
    case "${OPTION}" in
        'v') VERBOSE="${TRUE}";;
        'V') VERYVERB="${TRUE}";;
        '?') print "Syntax: cat_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
      while IFS="" read -r -- LINE
      do
        print -r -n -- "${LINE}"
      done
  else
      for FNAME in "${@}"
      do
        if [[ -e "${FNAME}" ]]
        then
            exec 0<"${FNAME}"
            while IFS="" read -r -- LINE
            do
              print -r -- "${LINE}"
            done
            exec 0<&-
        else
            print -u 2 "${0##*/}: ${FNAME}: No such file or directory"
            return 1
        fi
      done
  fi

  return 0
}
################################################################

cat_k93 "${@}"