# file_info - Get file information.
#
# Version 1.3
#
# Pre:
#    admin_dir - directory containing administration scripts
#    file_name - file path for which information is determined
# Post:
#    file_inode - inode (default: "0")
#    file_month - modification month (default: "")
#    file_day - modification day (default: "")
#    file_time - modification time (year if >6 months ago) (default: "")
#    file_link - link target (default: "")
#
# This routine is sourced from csh.
#
# It uses the following utility scripts:
#   abort - abort and exit the top csh script
#
# 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

# Initialize.
set file_inode = 0
set file_month = ""
set file_day = ""
set file_time = ""
set file_link = ""

# We want to get information about links even if the target does not exist.
# In this case, an existence check will return false.
# Instead, get the output from ls, even if it returns an error message.
# Then check the number of fields and whether the proper field contains
# the file name.

# Get file information.
set fi_info = (`ls -lid $file_name |& cat -`)

# Get information based on the form of the ls output.
set fi_inode = $fi_info[1]
set fi_link = ""
switch ($#fi_info)

  # BSD : inode mode count owner size month day time name -> link
  case 11:
    set fi_link = $fi_info[11]
  case 9:
    set fi_month = $fi_info[6]
    set fi_day = $fi_info[7]
    set fi_time = $fi_info[8]
    set fi_name = $fi_info[9]
    breaksw

  # sys5 : inode mode count owner group size month day time name -> link
  case 12:
    set fi_link = $fi_info[12]
  case 10:
    set fi_month = $fi_info[7]
    set fi_day = $fi_info[8]
    set fi_time = $fi_info[9]
    set fi_name = $fi_info[10]
    breaksw

  # Anything else indicates that the file does not exist.
  default:
    exit

endsw

# Quit if the name field does not match the file name.
# This will occur if the file does not exist (or is in an unsearchable
# directory).
if ("$fi_name" != "$file_name") exit

# Set the return values.
set file_inode = $fi_inode
set file_month = $fi_month
set file_day = $fi_day
set file_time = $fi_time
set file_link = $fi_link

# Return.
exit

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

source $admin_dir/abort
