#!/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: stat,v 1.10 1998/05/10 14:29:51 ejb Exp $
# $Source: /home/ejb/scripts/RCS/stat,v $
# $Author: ejb $
#
# This script simply does a stat of its arguments and prints the output.
#


for (@ARGV) {
    $minorbits = &get_minor_bits;
    ($dev, $ino, $mode, $nlink, $uid, $gid, $rdev, $size, $atime, $mtime,
     $ctime, $blksize, $blocks) = stat($_);
    ($user = (getpwuid($uid))[0]) || ($user = sprintf("%d", $uid));
    ($group = (getgrgid($gid))[0]) || ($group = sprintf("%d", $gid));
    $atimestr = &ctime($atime);
    $mtimestr = &ctime($mtime);
    $ctimestr = &ctime($ctime);
    print "File: $_\n";
    print +("Device: $dev, inode: $ino, mode: ",
	    sprintf("%06o", $mode), ", nlink: $nlink\n");
    printf("rdev: %d, major: %d, minor: %d\n", $rdev,
	   $rdev >> $minorbits, ($rdev & (1 << $minorbits) - 1));
    print "Owner: $user, group: $group\n";
    print "Size: $size, blocksize: $blksize, blocks: $blocks\n";
    print "atime: $atimestr, mtime: $mtimestr, ctime: $ctimestr\n";
    print "mtime timestamp: $mtime\n";
    print "\n";
}

sub ctime {
    ($sec, $min, $hour, $mday, $mon, $year, @trash) = localtime($_[0]);
    @trash = ();
    sprintf("%d/%d/%02d, %02d:%02d:%02d",
	    $mon + 1, $mday, $year, $hour, $min, $sec);
}

sub get_minor_bits {
    local(@stat) = stat("/dev/tty");
    local($minorbits) = 8;
    if ((@stat) && ($stat[6] > (1 << 18)))
    {
	$minorbits = 18;
    }
    $minorbits;
}
