#!/bin/sh
# -*- perl -*-
# This code allows us to start perl from our path or an environment variable
# rather than hardcoding a path into the #! line.  It works from sh or csh.
(exit $?0) && eval 'exec ${QPERLQ-perl} -x $0 ${1+"$@"}'
if (! $?QPERLQ) setenv QPERLQ perl
exec $QPERLQ -x $0 $argv:q

#!/usr/local/bin/perl -w
#
# $Id: date_of,v 1.3 1998/05/10 14:29:51 ejb Exp $
# $Source: /home/ejb/scripts/RCS/date_of,v $
# $Author: ejb $
#
# Author: E. Jay Berkenbilt
# The authoritative source of this script is ~ejb/scripts/date_of.
#
# Print timestamp of a file in a form readable by co's -d flag.
#


$whoami = ($0 =~ m,([^/]*)$,) ? $1 : $0;

&usage if (scalar(@ARGV) != 1);
$file = $ARGV[0];

if (-r $file)
{
    print &date_string($ARGV[0]), "\n";
}
else
{
    print STDERR "$whoami: $file does not exist\n";
    exit 1;
}	

sub date_string {
    local($file) = @_;
    local(@stat, $mtime);
    @stat = stat $file;
    $mtime = $stat[9];
    &ctime($mtime);
}

sub ctime {
    local($sec, $min, $hour, $mday, $mon, $year, @rest) = gmtime($_[0]);
    @rest = ();			# suppress perl warning
    sprintf("%04d/%02d/%02d-%02d:%02d:%02d",
	    $year + 1900, $mon + 1, $mday, $hour, $min, $sec);
}

sub usage {
    print STDERR "Usage: $whoami filename\n";
    print STDERR "  Print timestamp for file in a form suitable for use " .
	"by co's -d option.\n";
    exit 1;
}
