# cmd_init - Determine system directories and check for command existence.
#
# Version 1.3
#
# Pre:
#    top_dir - top product installation directory (e.g., ".../vt-1.2")
#    cmd_exec - command to execute (e.g., "vthoughtx")
# Post:
#    cmd_oshead - system head of directory paths (e.g., "sunos-4.1")
#    bin_dir - system executable directory (e.g., "$top_dir/$cmd_oshead/bin")
#    lib_dir - system library directory (e.g., "$top_dir/$cmd_oshead/lib")
#    cmd_status - return status:
#      0 = success (system recognized and command available)
#      10 = system not recognized
#      11 = command not available
#
# This routine is sourced from csh.
#
# Copyright (c) 1995 by
#
#    Confluent, Inc.
#    400 Spear St., Suite 207
#    San Francisco, CA 94105
#
# Voice: 415-764-1000
# Fax: 415-764-1008
# Internet: info@confluent.com
#
# Created: 950116 - jag
# Modified: 950421 - jag : add the hpux-9 system
# Modified: 961220 - jag : add "B.10.*" for HP-UX, "aush*"/"tp_s2" for SunOS

# Get the system information.
set ci_uname_s = "`uname -s`"
set ci_uname_m = "`uname -m`"
set ci_uname_r = "`uname -r`"

# Set some default return values.
set cmd_oshead = "unknown-0.0"
set cmd_status = 0

# Switch on the system name.
switch ("$ci_uname_s")

  case "HP-UX":

    # Switch on the machine.
    switch ("$ci_uname_m")

      case "9000/*":

        # Switch on the system release.
        switch ("$ci_uname_r")

          case "A.09.*":
          case "A.10.*":
          case "B.10.*":
            set cmd_oshead = "hpux-9"
            breaksw

          default:

        # "$ci_uname_r"
        endsw

        # "9000/*"
        breaksw

      default:

    # "$ci_uname_m"
    endsw

    # "HP-UX"
    breaksw

  case "SunOS":

    # Switch on the machine.
    switch ("$ci_uname_m")

      case "sun4*":
      case "aush*":
      case "tp_s2":

        # Switch on the system release.
        switch ("$ci_uname_r")

          case "4.*":
            set cmd_oshead = "sunos-4.1"
            breaksw

          case "5.*":
            set cmd_oshead = "solaris-2"
            breaksw

          default:

        # "$ci_uname_r"
        endsw

        # "sun4*"
        breaksw

      default:

    # "$ci_uname_m"
    endsw

    # "SunOS"
    breaksw

  default:

# "$ci_uname_s"
endsw

# Set up the directories.
set bin_dir = $top_dir/$cmd_oshead/bin
set lib_dir = $top_dir/$cmd_oshead/lib

# Quit if the system was not recognized.
if ("$cmd_oshead" =~ unknown*) then
  echo ""
  echo "The following operating system and machine are not recognized:"
  echo ""
  echo "   system:  $ci_uname_s $ci_uname_r"
  echo "   machine: $ci_uname_m"
  echo ""
  set cmd_status = 10
  exit
endif

# The command must be available.
set ci_cmd = $bin_dir/$cmd_exec
if (! -x $ci_cmd) then
  echo ""
  echo "The following command is not available for this system:"
  echo ""
  echo "   $ci_cmd"
  echo ""
  set cmd_status = 11
  exit
endif
