# file_date - Get the modification date/time for a file.
#
# Version 1.3
#
# Pre:
#    admin_dir - directory containing administration scripts
#    file_name - file path for which date/time is determined
# Post:
#    file_date - file modification date/time (default: "00/00/00 00:00")
#
# This routine is sourced from csh.
#
# It uses the following utility scripts:
#   abort - abort and exit the top csh script
#   file_info - get file information
#   match_arrays - match strings with arrays of strings
#
# 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: 950314 - jag : Set onintr to abort only if enable_intr set

# If enable_intr is set, set onintr to abort; otherwise, ignore interrupts.
if ($enable_intr) then
  onintr cleanup_mark
else
  onintr -
endif

# Set up a default value.
set file_date = "00/00/00 00:00"

# Quit if the file does not exist (or is in an unsearchable directory).
if (! -e $file_name) exit

# Get file information.
source $admin_dir/file_info

# Set up arrays of month names and two-character digits.
set fd_months = ("Jan" "Feb" "Mar" "Apr" "May" "Jun" \
                 "Jul" "Aug" "Sep" "Oct" "Nov" "Dec")
set fd_digits = ("00" "01" "02" "03" "04" "05" "06" "07" "08" "09")

# Get the month.
set array_names = ("fd_months")
set string_data = ("$file_month")
source $admin_dir/match_arrays
set fd_month = $array_index
@ fd_i = $fd_month + 1
if ($fd_i < 11) then
  set fd_month = $fd_digits[$fd_i]
endif

# Get the day.
set fd_day = $file_day
@ fd_i = $fd_day + 1
if ($fd_i < 11) then
  set fd_day = $fd_digits[$fd_i]
endif

# Get the time and year.
set fd_temp = `echo $file_time | grep ':'`
if ("$fd_temp" == "") then
  set fd_time = "00:00"
  set fd_year = `echo $file_time | sed -e 's/^..//'`
else
  set fd_time = $file_time
  set fd_year = `date '+%y'`
endif

# Format the date/time.
set file_date = "$fd_month/$fd_day/$fd_year $fd_time"

# Return.
exit

#----------------------------------------------------------------------
# Cleanup
#----------------------------------------------------------------------
cleanup_mark:

source $admin_dir/abort
