/* ******************************************************************************* * Copyright (c) 1996 Martin Poole * ******************************************************************************* ** ** WARNING !! WARNING !! WARNING !! WARNING !! WARNING !! WARNING !! ** ** Any changes to be made to this file should first be checked with ** mplib1 source control for library integrity. ** ** mplib1 source control can be reached at mplib1@quatermass.co.uk ** * * * $Source$ * $Author$ * $Date$ * $Revision$ * * ******************************************************************************* * * * $Log$ * ******************************************************************************* */ #ident "$Header$" /* ------------------------------------------------------------------ Include files ------------------------------------------------------------------ */ #include #include #include #include #include #include #include #include #include #include /* ------------------------------------------------------------------ defines ------------------------------------------------------------------ */ /* ------------------------------------------------------------------ Code starts here ------------------------------------------------------------------ */ void diff_timevals( struct timeval *end_p, struct timeval *start_p ) { /* Generate the difference, subtract the start from the end */ end_p->tv_sec -= start_p->tv_sec; if (end_p->tv_usec < start_p->tv_usec) { end_p->tv_usec = (end_p->tv_usec + 1000000 - start_p->tv_usec); end_p->tv_sec--; }else { end_p->tv_usec -= start_p->tv_usec; } return; } void add_timevals( struct timeval *cump, struct timeval *tvp ) { if (cump && tvp) { /* Now add it in */ cump->tv_usec += tvp->tv_usec; if (cump->tv_usec >= 1000000) { cump->tv_usec -= 1000000; cump->tv_sec++; } cump->tv_sec += tvp->tv_sec; } return; } void accum_stop_timevals( struct stopwatch *stp, struct timeval *etp ) { /* get the difference between the start and end time */ diff_timevals( etp, &stp->start_time ); /* Now add it in */ add_timevals( &stp->cumulative_time, etp ); return; } char * display_stopwatch( struct stopwatch *stp, int mode ) { switch( mode ) { case 0 : if (stp->cumulative_time.tv_sec < 1000) { sprintf( stp->elps_str, "%03d.%02d seconds", (int)stp->cumulative_time.tv_sec, (int)stp->cumulative_time.tv_usec/10000 ); }else { sprintf( stp->elps_str, "%06d.%02d seconds", (int)stp->cumulative_time.tv_sec, (int)stp->cumulative_time.tv_usec/10000 ); } break; default : strcpy( stp->elps_str, "Unknown display mode" ); break; } return(stp->elps_str); } /* -- End of File -- */