/*
 * time-formatting routine to provide shorter output than ctime()
 * since the extra verbosity isn't necessary
 */

static char time_buf[15] = "xx/xx/xx xx:xx";
/* ctime format is "Sun Sep 16 01:03:52 1973\0" */
/*                  0         1         2   2   */
/*                  0         0         0   4   */
/* output format is "mm/dd/yy hh:mm\0"          */
/*                   0         1                */

#include <stdio.h>
#include <time.h>

static const char rcsid[] =
    "$Header: /afs/sipb.mit.edu/project/discuss/.cvsroot/discuss/source/xdsc/time.c,v 1.4 1992/06/26 02:26:09 raeburn Exp $";

typedef struct {
    long quot;
    long rem;
} ldiv_t;

#if !defined(vax) || !defined(__GNUC__) || 1
static ldiv_t ldiv (long int numer, long int denom)
{
    ldiv_t result;
    result.quot = numer / denom;
    result.rem = numer - result.quot * denom;
    return result;
}
#else
static inline ldiv_t ldiv (long int numer, long int denom)
{
    ldiv_t result;
    ldiv_t input;
    input.quot = numer;
    input.rem = 0;
    asm ("ediv %2,%3,%0,%1"
	 : "g" (result.quot), "g" (result.rem)
	 : "g" (denom), "g" (input));
    return result;
}
#endif

char * short_time(time)
    unsigned long *time;
{
    register struct tm *now;
    ldiv_t result;

    now = localtime(time);
    time_buf[2] = '/';
    time_buf[5] = '/';
    time_buf[8] = ' ';
    time_buf[11] = ':';
    time_buf[14] = '\0';
#define put(n,o) {result=ldiv(n,10UL);time_buf[o]='0'+result.quot;time_buf[o+1]='0'+result.rem;}
    now->tm_mon++;
    put(now->tm_mon, 0);
    put(now->tm_mday, 3);
    put(now->tm_year, 6);
    put(now->tm_hour, 9);
    put(now->tm_min, 12);
    return(time_buf);
}

