
/*
 *  Examine a path and return the date
 */

typedef struct FileInfoBlock FIB;

extern void *malloc();
extern char *datetos();

main(ac,av)
char *av[];
{
    char buf[64];
    long lock;
    FIB *fib = malloc(sizeof(FIB));

    strcpy(buf, "error");
    if (lock = Lock(av[1], ACCESS_READ)) {
	if (Examine(lock, fib))
	    strcpy(buf, datetos(&fib->fib_Date));
	UnLock(lock);
    }
    puts(buf);
}

char *
datetos(d)
register struct DateStamp *d;
{
    static char stamp[64];
    static char dim[12] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
    static char *Month[12] = { "Jan","Feb","Mar","Apr","May","Jun","Jul",
			       "Aug","Sep","Oct","Nov","Dec" };
    register long day, month, year, scr;

    day = d->ds_Days;	    /* iteration (could be done w/equations) */
    year = 1978;

    while (day >= (scr = ((year&3)|!(year%100)) ? 365 : 366)) {
	++year;
	day -= scr;
    }
    dim[1] = ((year&3)|!(year%100)) ? 28 : 29;
    for (month = 0; day >= dim[month]; (day -= dim[month]), ++month);
    sprintf(stamp, "%2ld %s %2ld:%02ld:%02ld.%02ld %4ld",
	day + 1, Month[month], d->ds_Minute/60, d->ds_Minute%60,
	d->ds_Tick/50, (d->ds_Tick%50)<<2,
	year);
    return (stamp);
}


