/*
 * $Copyright:	$
 * Copyright (c) 1984, 1985, 1986, 1987, 1988, 1989, 1990 
 * Sequent Computer Systems, Inc.   All rights reserved.
 *  
 * This software is furnished under a license and may be used
 * only in accordance with the terms of that license and with the
 * inclusion of the above copyright notice.   This software may not
 * be provided or otherwise made available to, or used by, any
 * other person.  No title to or ownership of the software is
 * hereby transferred.
 *
 * This software is furnished under a license and may be used
 * only in accordance with the terms of that license and with the
 * inclusion of the above copyright notice.   This software may not
 * be provided or otherwise made available to, or used by, any
 * other person.  No title to or ownership of the software is
 * hereby transferred.
 *
 */

#include <sys/types.h>
#include <sys/vm.h>
#include <stdio.h>
#include <nlist.h>
#include <time.h>

struct nlist nl[] = {
        { "avenrun" },
#define NL_AVENRUN      0
        { "boottime" },
#define NL_BOOTTIME     1
        { "" },
};

timeval_t boottime;
time_t now, uptime;
struct tm *lnow;
long avenrun[3];

main(argc, argv)
char *argv[];
{
        register int i;
        int kmem;
        int days, hrs, mins;

        if ((kmem = open("/dev/kmem", 0)) == -1) {
                perror("/dev/kmem");
                exit(1);
        }
        nlist("/unix", nl);
        if (nl[0].n_value == 0) {
                fprintf(stderr, "%s: no namelist\n", argv[0]);
                exit(1);
        }
        time(&now);
        lnow = localtime(&now);
        printf("%02d:%02d,", lnow->tm_hour, lnow->tm_min);

        lseek(kmem, (long)nl[NL_BOOTTIME].n_value, 0);
        read(kmem, &boottime, sizeof(boottime));

        uptime = now - boottime.tv_sec;
        uptime += 30;
        days = uptime / (60 * 60 * 24);
        uptime %= (60 * 60 * 24);
        hrs = uptime / (60 * 60);
        uptime %= (60 * 60);
        mins = uptime / 60;

        printf(" up");
        if (days > 0)
                printf(" %d day%s,", days, days > 1 ? "s" : "");
        if (hrs > 0 && mins > 0) {
                printf(" %2d:%02d,", hrs, mins);
        } else {
                if (hrs > 0)
                        printf(" %d hr%s,", hrs, hrs > 1 ? "s" : "");
                if (mins > 0)
                        printf(" %d min%s,", mins, mins > 1 ? "s" : "");
        }

        lseek(kmem, (long)nl[NL_AVENRUN].n_value, 0);
        read(kmem, avenrun, sizeof(avenrun));
        printf(" load average:");
        for (i = 0; i < sizeof(avenrun)/sizeof(avenrun[0]); i++) {
                if (i > 0)
                        printf(",");
                printf(" %.2f", (double)avenrun[i]/FSCALE);
        }
        printf("\n");
}
