|
|
DataMuseum.dkPresents historical artifacts from the history of: DKUUG/EUUG Conference tapes |
This is an automatic "excavation" of a thematic subset of
See our Wiki for more about DKUUG/EUUG Conference tapes Excavated with: AutoArchaeologist - Free & Open Source Software. |
top - metrics - downloadIndex: T p
Length: 2527 (0x9df)
Types: TextFile
Names: »pstats.c«
└─⟦b20c6495f⟧ Bits:30007238 EUUGD18: Wien-båndet, efterår 1987
└─⟦this⟧ »EUUGD18/X/Xtrek/pstats.c«
static char sccsid[] = "@(#)pstats.c 1.1";
/*
Copyright (c) 1986 Chris Guthrie
Permission to use, copy, modify, and distribute this
software and its documentation for any purpose and without
fee is hereby granted, provided that the above copyright
notice appear in all copies and that both that copyright
notice and this permission notice appear in supporting
documentation. No representations are made about the
suitability of this software for any purpose. It is
provided "as is" without express or implied warranty.
*/
#include <X11/Xlib.h>
#include <stdio.h>
#include <sys/types.h>
#ifdef hpux
#include <time.h>
#else hpux
#include <sys/time.h>
#endif hpux
#include <sys/resource.h>
#include <sys/file.h>
#include <ndbm.h>
#include "defs.h"
#include "data.h"
savestats(p)
register struct player *p;
{
register DBM *db;
char buf[80];
datum key, sinfo;
long now;
struct rusage rbuf;
struct stats old;
db = dbm_open(SCOREFILE, O_RDWR, 0700);
if (db == (DBM *) NULL)
return;
if (p->p_flags & PFROBOT)
sprintf(buf, "%s", p->p_name);
else
sprintf(buf, "%s:%s", p->p_login, p->p_monitor);
key.dptr = buf;
key.dsize = strlen(buf) + 1;
sinfo = dbm_fetch(db, key);
if (sinfo.dptr) {
bcopy(sinfo.dptr, &old, sizeof (struct stats));
key.dptr = buf;
key.dsize = strlen(buf) + 1;
dbm_delete(db, key);
} else
bzero(&old, sizeof (struct stats));
p->p_stats.st_kills += old.st_kills;
p->p_stats.st_losses += old.st_losses;
p->p_stats.st_entries += old.st_entries;
p->p_stats.st_conqs += old.st_conqs;
p->p_stats.st_coups += old.st_coups;
p->p_stats.st_torps += old.st_torps;
p->p_stats.st_phasers += old.st_phasers;
p->p_stats.st_armsbomb += old.st_armsbomb;
p->p_stats.st_armsship += old.st_armsship;
p->p_stats.st_planets += old.st_planets;
p->p_stats.st_genocides += old.st_genocides;
time(&now);
p->p_stats.st_time = old.st_time + (now - p->start_time);
getrusage(0, &rbuf);
p->p_stats.st_cpu = old.st_cpu + rbuf.ru_utime.tv_sec + rbuf.ru_stime.tv_sec;
if (p->p_stats.st_maxkills < old.st_maxkills)
p->p_stats.st_maxkills = old.st_maxkills;
if (sinfo.dptr) {
sinfo.dptr = (char *) &old;
bcopy(&p->p_stats, sinfo.dptr, sizeof (struct stats));
} else {
sinfo.dptr = (char *) &p->p_stats;
}
sinfo.dsize = sizeof (struct stats);
key.dptr = buf;
key.dsize = strlen(buf) + 1;
dbm_store(db, key, sinfo, DBM_INSERT);
(void) dbm_close(db);
}