#!/bin/bash
# .bashrc
# written for sh, ksh, bash compatibility

# core file limits
[ `ulimit -c` != unlimited ] && ulimit -c unlimited

# is this bash?
case "x$0" in
  x-bash | xbash | x*/bash)
    BASHRC_SHELL=bash
    ;;
  x-ksh | xksh | x*/ksh)
    BASHRC_SHELL=ksh
    ;;
  x-sh | xsh | x*/sh)
    BASHRC_SHELL=sh
    # the following tests whether the [[ shell built-in is available
    # if so, we should be ksh compatible
    type '[[' > /dev/null 2>&1 && BASHRC_SHELL=ksh
    ;;
  *)
    BASHRC_SHELL=""
    ;;
esac
export BASHRC_SHELL

# ------------------------------------------------------------------------------
# User specific aliases and functions
# ------------------------------------------------------------------------------

# buildpath: This is designed to be sh, ksh, bash compatible
buildpath ()
{
  (
    dbg=false
    if [ $# -gt 0 ]; then
      if [ x"$1" = x-d ]; then
        dbg=true
        shift
      fi
    fi
    export dbg

    if [ $# -eq 0 ]; then
      cat 1>&2 <<-EnD
buildpath [-d] directory-or-search-path [directory-or-search-path] ...
    -d    Produces debug output on the standard error stream
  Search paths are split at colons into directory path elements; these and
  any plain directory path arguments are read in order, checked to make sure
  the directory exists, and added, at most once, with colon separators, to
  the output. The result is a new colon-separated search-path, written to
  the standard output stream.
EnD

    else
      ( for dp in "$@"; do
          case "$dp" in
            *:*)
              # split args containing colons into lines on stdout
              echo "$dp" | tr : '\n'
              ;;
            *)
              # just output non-colon-containing args one per line
              echo "$dp"
              ;;
          esac
        done
      ) |
      (
        IFS=""                      # do not allow space separators inside lines
        i=0
        while read d; do            # read a line into $d
          case ":${p}:" in
            *:${d}:*)
              # $d has already been seen: ignore duplicate
              $dbg && echo "dupl $d" 1>&2
              ;;
            *)
              if [ -d "$d" ]; then
                # $d is a directory: add it to path $p
                i=`expr $i + 1`
                # or --> i=$(($i + 1))
                $dbg && echo `printf "%4d %s" $i $d` 1>&2
                p="$p$sep$d"
                sep=":"
              else
                # $d is not a directory
                $dbg && echo "! dir $d" 1>&2
              fi
              ;;
          esac
        done
        # all done: echo the new path $p
        echo $p
      )
    fi
  )
}

# ------------------------------------------------------------------------------

### findinpath: look for a file in a set of directories
##findinpath ()
##{
##  if [ $# -eq 0 ]; then
##    cat 1>&2 <<-EnD
##findinpath [-rwxfdhLcbpugks1] search-path file ...
##    -rwxfdhLcbpugks1  Flags acceptable to test(1) or 1; default is -x
##    search-path      A colon-separated list of directories
##  Looks for each file in the search path by taking each directory in the path
##  and concatenating "/" and the file name to it then testing the result using
##  the test flags. Each successfully found file path is written to stdout.
##  If flags are present, all tests must succeed for a file to be considered
##  "found". The flag 1 causes the search for a file to quit when one successful
##  occurrence is found.
##EnD
##    return 1
##  fi
##
##  (
##    flags=
##    while true; do
##      case "x$1" in
##        x--)    shift
##                break
##                ;;
##        x-*)    flags="$flags `echo -- $1 | sed -e 's/-//g' -e 's/./& /g'` "
##                shift
##                ;;
##        *)      break
##                ;;
##      esac
##    done
##    flags="`echo $flags`"
##    [ -z "$flags" -o "$flags" = 1 ] && flags="x $flags"
##
##    if [ $# = 0 ]; then
##      findinpath
##      exit 1
##    fi
##
##    flags=`echo $flags|tr ' ' :`
##    dpath="$1"
##    shift
##
##    #: echo flags="$flags" 1>&2
##    #: echo dpath="$dpath" 1>&2
##
##    IFS=:
##    res=1
##    for f in "$@"; do
##      br=n
##      for d in $dpath; do
##        ok=y
##        for q in $flags; do
##          if [ $q = 1 ]; then
##            br=y
##          elif [ ! -$q $d/$f ]; then
##            ok=n
##            break
##          fi
##        done
##        if [ $ok = y ] && echo "$d/$f" && [ $br = y ]; then
##          res=0
##          break
##        fi
##      done
##    done
##
##    exit $res
##  )
##}

# ------------------------------------------------------------------------------

# findinpath: look for a file in a set of directories
findinpath ()
{
  if [ $# -eq 0 ]; then
    cat 1>&2 <<-EnD
findinpath [-rwxfdhLcbpugks1] search-path file ...
    -rwxfdhLcbpugks1  Flags acceptable to test(1) or 1; default is -x
    search-path      A colon-separated list of directories
  Looks for each file in the search path by taking each directory in the path
  and concatenating "/" and the file name to it then testing the result using
  the test flags. Each successfully found file path is written to stdout.
  If flags are present, all tests must succeed for a file to be considered
  "found". The flag 1 causes the search for a file to quit when one successful
  occurrence is found.
EnD
    return 1
  fi

  (
    flags=
    while true; do
      case "x$1" in
        x--)    shift
                break
                ;;
        x-*)    flags="$flags `echo -- $1 | sed -e 's/-//g' -e 's/./& /g'` "
                shift
                ;;
        *)      break
                ;;
      esac
    done
    flags="`echo $flags`"
    [ -z "$flags" -o "$flags" = 1 ] && flags="x $flags"

    if [ $# = 0 ]; then
      findinpath
      exit 1
    fi

    # flags=`echo $flags|tr ' ' :`
    dpath="$1"
    shift

    #: echo flags="$flags" 1>&2
    #: echo dpath="$dpath" 1>&2

    res=1
    for fa in "$@"; do
      br=n
      IFS=:
      for d in $dpath; do
        ff=`echo $d/$fa`     # attempt to glob-out any wildcards
        IFS=' '
        for f in $ff; do
          ok=y
          # IFS=:
          for q in $flags; do
            if [ -z "$q" ]; then
              :
            elif [ $q = 1 ]; then
              br=y
              # return 0
            elif [ ! -$q $f ]; then
              ok=n
              break
            fi
          done
          if [ $ok = y ] && echo "$f" && [ $br = y ]; then
            res=0
          fi
        done
      done
    done

    return $res
  )
}

# ------------------------------------------------------------------------------

# where is like which but has no csh dependencies. It uses findinpath to do the
# real work.
where ()
{
  (
  doMan=n doLib=n doType=n doHash=n doBasicType=n doCst=n doUsage=n
  opts='th'
  [ $BASHRC_SHELL != bash ] && opts='t'

  OPTIND=1
  while getopts a${opts}mlxqp: opt "$@"
  do
    case "$opt" in
      m)
        doMan=y
        [ -z "$doExe" ] && doExe=n
        [ -z "$show" ] && show=echo
        ;;
      l)
        doLib=y
        [ -z "$doExe" ] && doExe=n
        [ -z "$show" ] && show=echo
        ;;
      x)
        doExe=y
        [ -z "$show" ] && show=echo
        ;;
      t)
        doType=y
        [ -z "$doExe" ] && doExe=n
        [ -z "$show" ] && show=echo
        ;;
      h)
        doHash=y
        [ -z "$doExe" ] && doExe=n
        [ -z "$show" ] && show=echo
        ;;
      p)
        cpath="$OPTARG"
        doCst=y
        [ -z "$doExe" ] && doExe=n
        [ -z "$show" ] && show=echo
        ;;
      a)
        doExe=y doMan=y doLib=y doType=y doHash=y
        [ -z "$show" ] && show='echo'
        ;;
      q)
        show=:
        ;;
      *)
        doUsage=y
        ;;
    esac
  done
  shift `expr $OPTIND - 1`

  [ -z "$doExe" ] && doExe=y
  [ -z "$show" ] && show=:

  # need arguments!
  [ $# = 0 ] && doUsage=y

  # type -atp supported only in bash
  if [ $BASHRC_SHELL != bash ]; then
    if [ "$doType" = y ] || [ "$doHash" = y ]; then
      doType=n
      doHash=n
      doBasicType=y
    fi
  fi

  if [ "$doUsage" != y ]; then
    mans="${MANPATH:-/usr/man:/usr/contrib/man:/usr/local/man}"
    libs="${LD_LIBRARY_PATH:-/usr/lib:/usr/local/lib}"
    showsep=:
    for f in "$@"; do
      if [ "$doBasicType" = y ]; then
        res=`type "$f" 2>&1`
        [ -n "$res" ] && $showsep "" \
                      && $show "type ${f}" && echo "$res"
        showsep=$show
      fi
      if [ "$doType" = y ]; then
        res=`type -at "$f" 2>&1`
        [ -n "$res" ] && $showsep "" \
                      && $show "type -at ${f}" && echo "$res"
        showsep=$show
      fi
      if [ "$doHash" = y ]; then
        res=`type -p "$f" 2>&1`
        [ -n "$res" ] && $showsep "" \
                      && $show "type -p ${f}" && echo "$res"
        showsep=$show
      fi
      if [ "$doExe" = y ]; then
        res=`findinpath -x "$PATH" "$f"`
        [ -n "$res" ] && $showsep "" \
                      && $show "\$PATH: ${f}" && echo "$res"
        showsep=$show
      fi
      if [ "$doMan" = y ]; then
        res=`findinpath -f "$mans" "*/$f.*"`
        [ -n "$res" ] && $showsep "" \
                      && $show "\$MANPATH: ${f}" && echo "$res"
        showsep=$show
      fi
      if [ "$doLib" = y ]; then
        res=`findinpath -f "$libs" "$f" "$f.*"`
        [ -n "$res" ] && $showsep "" \
                      && $show "\$LD_LIBRARY_PATH: ${f}" && echo "$res"
        showsep=$show
      fi
      if [ "$doCst" = y ]; then
        res=`findinpath -f "$cpath" "$f"`
        [ -n "$res" ] && $showsep "" \
                      && $show "${cpath}: ${f}" && echo "$res"
        showsep=$show
      fi
    done
  fi

  if [ "$doUsage" = y ]; then
    aopts="${opts}xml"
    opts="[-a${aopts}xmlq]"
    echo "Usage: where ${opts} [-p search-path] file-name-or-prefix" 1>&2
    echo "  -a      \"all\": apply options -$aopts" 1>&2
    if [ $BASHRC_SHELL == bash ]; then
      echo "  -t      use type -at to show command interpretation" 1>&2
      echo "  -h      use type -p to show hashed path to executable file" 1>&2
    else
      echo "  -t      use the type built-in to show command interpretation" 1>&2
    fi
    echo "  -x      search for executable files in \$PATH" 1>&2
    echo "  -m      search for matching manual page files in \$MANPATH" 1>&2
    echo "  -l      search for matching files in \$LD_LIBRARY_PATH" 1>&2
    echo "  -p path search for files in path" 1>&2
    echo "  -q      quiet: do not mention which search is executing" 1>&2
    echo "File names must match exactly for -x, -p; -x is the default." 1>&2
  fi
  )
}

# ------------------------------------------------------------------------------

# Source global definitions
if [ "$BASHRC_SHELL" = bash ] && [ -f /etc/bashrc ]; then
  . /etc/bashrc
fi
if [ -f "$HOME/tmpBashSettings" ]; then
  . "$HOME/tmpBashSettings"
fi

# file creation mask
umask 022

# logname
LOGNAME=${LOGNAME:-${USER}}

# system specifics
UNAME=`uname`
export UNAME
MAIL=/usr/mail/${LOGNAME:?}

if [ -z "$BASH_PATHS_SET" ]; then
    # Set local environment for FIDEV users (for CVS, etc.)

    CVSROOT=:pserver:${USER}@nysuntradedev01:/export/home/fidev/CVS
    export CVSROOT

    # disable coreadm when invoking FITOP's environment
    if [ -d /fidev ] && \
       [ "$BASHRC_SHELL" = bash -o "$BASHRC_SHELL" = ksh ]; then
      alias coreadm=":"
      FITOP=/fidev
      . $FITOP/set_env
      unalias coreadm
      # coreadm fmt: %f=exefile %p=PID %u=UID %g=GID %n=node %m=machine %t=time
      coreadm -p core.%f $$

#     # corrections for development?
#     myIRISHOME=/fidev/apps/iris     # myIRISHOME=/fidev/apps/iris-em
#     if [ "$IRISHOME" != "$myIRISHOME" ]; then
#       export IRISHOME="$myIRISHOME"
#       export TFBASE=$IRISHOME/tf
#       export AFBASE=$IRISHOME/af3
#       export UIBASE=$IRISHOME/ui
#       export ABBASE=$IRISHOME/ab
#       export IRBASE=$IRISHOME/ir
#       export ITPBASE=$IRISHOME/itp
#       export VENBASE=$IRISHOME/vendor
#       export SHLBASE=$IRISHOME/shlib
#     fi
#     unset myIRISHOME
#
#     myAPPBASE=/fidev/apps/forest    # myAPPBASE=/fidev/src/forest-em
#     if [ "$APPBASE" != "$myAPPBASE" ]; then
#       export APPBASE="$myAPPBASE"
#       export TB_SBASE=$APPBASE/db
#       export TB_LBASE=$APPBASE
#       export TB_FBASE=$APPBASE/db
#       export TB_DBASE=$APPBASE/db
#       export TB_LOGBASE=$APPBASE/log/iris
#       export DSQUERY=FIDEV
#     fi
#     unset myAPPBASE

      # sqsh - the SQL shell
      export PATH=$PATH:/usr/local/sqsh
    fi

    case `uname` in
        SunOS)
            # Sun development tools
            [ -d /opt/SUNWspro/bin ] && SunOSPATH=/opt/SUNWspro/bin
            [ -d /opt/SUNWspro/man ] && SunOSMANPATH=/opt/SUNWspro/man
            [ -d /opt/SUNWspro/lib ] && SunOSLIBPATH=/opt/SUNWspro/lib
            ;;
    esac

    # PATH -------------------------------------------------
    PATH=`buildpath "$HOME"/.util \
                    "$HOME"/.util/"$UNAME" \
                    "$HOME"/usr/bin/"$UNAME" \
                    "$HOME"/usr/sbin \
                    "$HOME"/usr/bin \
                    "$HOME"/sqsh \
                    $SunOSPATH \
                    /usr/java4/bin \
                    /usr/xpg4/bin \
                    /usr/bin \
                    /bin \
                    /usr/sbin \
                    /sbin \
                    /usr/local/bin \
                    /usr/local/sbin \
                    . \
                    /usr/ccs/bin \
                    /usr/ucb \
                    /usr/dt/bin \
                    /usr/X/bin \
                    /usr/X/demo \
                    /opt/SUNWspro/bin \
                    /etc \
                    "$PATH"`
    # for EMC Power
    PATH=`buildpath "$PATH" \
                    /opt/EMCpower/bin \
                    /etc`
    export PATH
    BASH_PATHS_SET="$BASH_PATHS_SET PATH "
    export BASH_PATHS_SET

    # LD_LIBRARY_PATH --------------------------------------
    LD_LIBRARY_PATH=`buildpath \
                    $LD_LIBRARY_PATH \
                    $SunOSLIBPATH \
                    /usr/local/lib \
                    /usr/lib \
                    /lib`
    export LD_LIBRARY_PATH
    BASH_PATHS_SET="$BASH_PATHS_SET LD_LIBRARY_PATH "
    export BASH_PATHS_SET

    # MANPATH ----------------------------------------------
    MANPATH=`buildpath \
                    ~/usr/man \
                    $SunOSMANPATH \
                    /usr/share/man \
                    /usr/openwin/man \
                    /usr/local/man \
                    /usr/X/man \
                    /usr/dt/man \
                    /usr/openwin/man \
                    $MANPATH`
    export MANPATH
    BASH_PATHS_SET="$BASH_PATHS_SET MANPATH "
    export BASH_PATHS_SET

    # ------------------------------------------------------
fi

# ------------------------------------------------------------------------------

today_file=`date +today=%d-%m-%Y`
(
    IFS=;
    today_files=`cd "$HOME"; ls | grep 'today=.*'`
    if [ "$today_files" != "" ]; then
        for today_file_rm in $today_files; do
            [ "$today_file" != "$today_file_rm" ] && rm -f $HOME/$today_file_rm
        done
    fi
)
[ -f "$HOME/$today_file" ] || touch "$HOME/$today_file"

if [ -d "$HOME/.app-defaults" ]; then
  XAPPLRESDIR="$HOME/.app-defaults"
  export XAPPLRESDIR
fi

if [ -f "$HOME/.bashrc.$UNAME" ]; then
  . "$HOME/.bashrc.$UNAME"
fi

# ------------------------------------------------------------------------------

# aliases and functions
if [ "$BASHRC_SHELL" = bash -o "$BASHRC_SHELL" = ksh ]; then
  [ -r ~/.util/bashaliasrc ] && . ~/.util/bashaliasrc
fi

# localised definitions
[ -r $HOME/.localrc ] && . $HOME/.localrc

# ------------------------------------------------------------------------------

# is our shell interactive?
if [ -z "$NO_INTERACTIVE_CHECK" ]; then
  case "$-" in
    *i*)
      INTERACTIVE=y
      ;;
    *)
      INTERACTIVE=
      ;;
  esac
fi

# ------------------------------------------------------------------------------

if [ "$INTERACTIVE" = "y" ]; then
  CDPATH=`buildpath . ~/cvs ~`
  if tty -s; then
    if [ -z "$BASHRC_SHOW_REMINDER" ] && [ -f ~/reminder ]; then
      echo "";
      echo ===== Reminder file ~/reminder: =====
      cat ~/reminder
      echo "";
      echo ===== Reminder file ~/reminder: ===== | sed -e s/./=/g
      echo "";
    fi
    BASHRC_SHOW_REMINDER="done"
    export BASHRC_SHOW_REMINDER
    # unless on Sun or DEC keyboards, with xterm we want Backspace to erase
    if [ "$TERM" = xterm ] || [ "$TERM" = vt100 ]; then
      stty erase ^H
    fi
    # use less with man if we have it
    if type less > /dev/null 2>&1; then
      PAGER=less
      LESS='-egmqsX'
      export PAGER LESS
    fi
    # if we don't have more, use less instead
    if type more > /dev/null 2>&1; then
      :
    else
      alias more=less
    fi
  fi

  # use custom cd (if we're using a terminal)
  if [ "$BASHRC_SHELL" = bash ] && tty -s; then
    [ -r ~/.util/bashcd ] && . ~/.util/bashcd
    setcd c
  fi

  # ignore repeats and space-leading commands in history
  HISTCONTROL=ignoreboth      # ignorespace, ignoredups, ignoreboth

  [ -z "$tty" ] && tty=`tty | sed -e s./dev/..`

  # - try to avoid a DISPLAY with "localhost" in its name
  if [ -n "$DISPLAY" ]; then
    display="$DISPLAY"
    if [ "$display" = *localhost* ]; then
      OLD_DISPLAY="$DISPLAY"
      unset display
      export OLD_DISPLAY
    fi
  fi
  if [ -z "$display" ] && type last > /dev/null 2>&1; then
    # use last to pick up current "terminal" IP address
    #   case `uname` in
    #   SunOS)
    #       nlast="-n 1 -a"
    #       ;;
    #   *)
    #       nlast="-1 -l"
    #       ;;
    #   esac
    nlast="-n 1 -a"
    # pick up the terminal
    # take the last word of the first line of last(1) as an IP address
    last=`last $nlast $USER | awk '{ print $NF; exit }'`
    # see if we can find the same thing in who(1) (in comments field)
    if who -uT | fgrep "$tty" | fgrep "$last" >& /dev/null; then
      # looks like we have the connecting terminal (if any)
      if echo "$last" | grep '[^.0-9]' >& /dev/null; then
        # we have a name: try to resolve its address
        display=`nslookup "$last" | \
                 awk '
                 /^Name:/       { nextln = 0; if ($2 == "'"$last"'") nextln++; }
                 /^Address:/    { if (nextln) print $2; }
                 ' | head -n 1`
        if [ -n "$display" ]; then
          DISPLAY="${display}:0"
        else
          DISPLAY="${last}:0"
        fi
        unset display
      else
        DISPLAY="${last}:0"
      fi
      export DISPLAY
    fi
  fi
fi

# ------------------------------------------------------------------------------

# and X?
if [ -n "$DISPLAY" ]; then
  if [ "$INTERACTIVE" = "y" ] && [ -z "$XEDITOR" ]; then
    echo "Display: export DISPLAY=${DISPLAY}"
  fi
  # do we support CDE?
  if [ -d ~/.dt ] && [ -d /usr/dt/bin ]; then
    [ -z "$DTSCREENSAVERLIST" ] && \
        { DTSCREENSAVERLIST=`echo StartDtscreenSwarm \
                                  StartDtscreenQix \
                                  StartDtscreenFlame \
                                  StartDtscreenHop \
                                  StartDtscreenImage \
                                  StartDtscreenLife \
                                  StartDtscreenRotor \
                                  StartDtscreenPyro \
                                  StartDtscreenWorm \
                                  StartDtscreenBlank`
          export DTSCREENSAVERLIST; }
#   [ -z "$dtstart_sessionlogfile" ] && \
#       export dtstart_sessionlogfile=/dev/null
#   [ -z "$XMBINDDIR" ] && \
#       export XMBINDDIR=/usr/dt/lib/bindings
    [ -z "$DTUSERSESSION" ] && \
        export DTUSERSESSION="${USER}-`echo $DISPLAY | \
                                       sed -e s/:/-/ | sed -e s/\\.0\$/-0/`"
#   [ -z "$DTDATABASESEARCHPATH" ] && \
#       export DTDATABASESEARCHPATH=`echo ~/.dt/types \
#                                         /usr/dt/appconfig/types/%L \
#                                         /usr/dt/appconfig/types/C | \
#                                    tr ' ' ,`
#   # export DTXSERVERLOCATION=remote
#   [ -z "$XFILESEARCHPATH" ] && \
#       export XFILESEARCHPATH=`echo /usr/openwin/lib/locale/%L/%T/%N%S \
#                                    /usr/openwin/lib/%T/%N%S | \
#                               tr ' ' :`
#   [ -z "$XMICONSEARCHPATH" ] && \
#       export XMICONSEARCHPATH=`echo ~/.dt/icons/%B%M.pm \
#                                     ~/.dt/icons/%B%M.bm \
#                                     ~/.dt/icons/%B \
#                                     /usr/dt/appconfig/icons/%L/%B%M.pm \
#                                     /usr/dt/appconfig/icons/%L/%B%M.bm \
#                                     /usr/dt/appconfig/icons/%L/%B \
#                                     /usr/dt/appconfig/icons/C/%B%M.pm \
#                                     /usr/dt/appconfig/icons/C/%B%M.bm \
#                                     /usr/dt/appconfig/icons/C/%B | \
#                                tr ' ' :`
#   [ -z "$XMICONBMSEARCHPATH" ] && \
#       export XMICONBMSEARCHPATH=`echo ~/.dt/icons/%B%M.bm \
#                                       ~/.dt/icons/%B%M.pm \
#                                       ~/.dt/icons/%B \
#                                       /usr/dt/appconfig/icons/%L/%B%M.bm \
#                                       /usr/dt/appconfig/icons/%L/%B%M.pm \
#                                       /usr/dt/appconfig/icons/%L/%B \
#                                       /usr/dt/appconfig/icons/C/%B%M.bm \
#                                       /usr/dt/appconfig/icons/C/%B%M.pm \
#                                       /usr/dt/appconfig/icons/C/%B | \
#                                  tr ' ' :`
#   [ -z "$DTSOURCEPROFILE" ] && export DTSOURCEPROFILE=true
#   [ -z "$DTHELPSEARCHPATH" ] && \
#       export DTHELPSEARCHPATH=\
#           `echo ~/.dt/help/$DTUSERSESSION/%H \
#                 ~/.dt/help/$DTUSERSESSION/%H.sdl \
#                 ~/.dt/help/$DTUSERSESSION/%H.hv \
#                 ~/.dt/help/%H \
#                 ~/.dt/help/%H.sdl \
#                 ~/.dt/help/%H.hv \
#                 /usr/dt/appconfig/help/%L/%H \
#                 /usr/dt/appconfig/help/%L/%H.sdl \
#                 /usr/dt/appconfig/help/%L/%H.hv \
#                 /usr/dt/appconfig/help/C/%H \
#                 /usr/dt/appconfig/help/C/%H.sdl \
#                 /usr/dt/appconfig/help/C/%H.hv | \
#            tr ' ' :`
    [ -z "$DTAPPSEARCHPATH" ] && \
        { DTAPPSEARCHPATH=`echo $HOME/.dt/appmanager \
                                /usr/dt/appconfig/appmanager/%L \
                                /usr/dt/appconfig/appmanager/C | \
                           tr ' ' :`
          export DTAPPSEARCHPATH; }
    [ -z "$TERMINAL_EMULATOR" ] && \
        { TERMINAL_EMULATOR=xterm
           export TERMINAL_EMULATOR; }
  fi

  # use NEdit
  XEDITOR="nc -noask"
  export XEDITOR
  if [ -z "$NEDIT_INCLUDE_PATH" ]; then
    # put "standard" include paths here
    NEDIT_INCLUDE_PATH=`find /opt/SUNWspro/WS6U2/include/CC/ \
                                 -type d -print`
    NEDIT_INCLUDE_PATH=`buildpath \
                         . \
                         /opt/SUNWspro/WS6U2/include/CC/Cstd \
                         $NEDIT_INCLUDE_PATH \
                         /usr/include`
    export NEDIT_INCLUDE_PATH
  fi

  if [ -d "$HOME/.app-defaults" ]; then
    app_defaults=~/.app-defaults
    XAPPLRESDIR=$app_defaults
    app_defaults=$app_defaults/%N
    if [ -n "$XUSERFILESEARCHPATH" ]; then
      case "${XUSERFILESEARCHPATH}:" in
      *:${app_defaults}:*)
          # echo not Resetting XUSERFILESEARCHPATH
          ;;
      *)
          # echo Resetting XUSERFILESEARCHPATH
          XUSERFILESEARCHPATH=${XUSERFILESEARCHPATH}:$app_defaults
          ;;
      esac
    else
      XUSERFILESEARCHPATH=$app_defaults
    fi
    export XAPPLRESDIR XUSERFILESEARCHPATH
  fi
fi

