#!/bin/ksh -p
#
# Name: dirtree
# Programmer:
#            Hemant T. Shah
#            Life Insurance Data Processing
#            July 12 1994
#
# Description:
#  Print directory tree structure as follows:
#   |___Mail
#     |___scheduler
#     |___cics_scripts
#     |___tar_msdos
#     |___awk
#     |___attributes
#   |___tmp
#   |___News
#     |___dosscsi
#     |___FAQ_xterminal
#     |___shell_history.Z
#     |___FAQ_AIX
#     |___aix_ftp_site
#     |___hp_software
#   |___dnload
#     |___telnet.h
#     |___msdos
#     |___tnetd.tar.Z
#     |___aix
#     |___hp
#   |___xkey.c
#

ProgramName=`basename $0`
Path="."
ShowAll=1
ShowDir=0


ExpandDirectory()
{
typeset object   # Local variable

cd $1

for object in $PWD/.??* $PWD/*
do
   if [[ -d $object ]];  # It is a directory
   then
      print "${indent}|___`basename ${object}`/"
      indent="${indent}!   "   # Add to indentation
      if [[ -x $object ]];
      then
         ExpandDirectory $object
      fi
      indent=${indent%????}    # Remove from indentation
   elif [[ -a $object ]];
   then
      if (( ShowAll == 1 ));
      then
         print "${indent}|___`basename ${object}`"
      fi
   fi
done

}


if [[ $# > 0 ]];
then
  while [ $# -gt 0 ]; do

    case $1 in
      -f) ShowAll=1
          shift
          ;;
      -d) ShowDir=1
          ShowAll=0
          shift
          ;;
      -*)
          print "Usage: $ProgramName [-h] [-f] [-d] [path] "
          print -- "\t-h       ... display this help message."
          print -- "\t-f path  ... shows all files and directories below \
path (default)."
          print -- "\t-d path  ... shows all directories only below path."
          exit
          ;;
       *)
          Path=$1
          shift
          ;;
    esac

  done
fi

if [[ ! -d $Path ]];
then
   print "Error: Specified path is not a directory."
   exit
fi


print "!$Path/"
ExpandDirectory $Path

