int main(int argc, char **argv) { VSTRING *in = vstring_alloc(10); VSTRING *out = vstring_alloc(10); double tval; int sec; int usec; int sig_dig; int max_dig; while (vstring_get_nonl(in, VSTREAM_IN) > 0) { vstream_printf(">> %s\n", vstring_str(in)); if (vstring_str(in)[0] == 0 || vstring_str(in)[0] == '#') continue; if (sscanf(vstring_str(in), "%lf %d %d", &tval, &sig_dig, &max_dig) != 3) msg_fatal("bad input: %s", vstring_str(in)); sec = (int) tval; /* raw seconds */ usec = (tval - sec) * MILLION; /* raw microseconds */ VSTRING_RESET(out); format_tv(out, sec, usec, sig_dig, max_dig); vstream_printf("%s\n", vstring_str(out)); vstream_fflush(VSTREAM_OUT); } vstring_free(in); vstring_free(out); return (0); }
char *psc_format_delta_time(VSTRING *buf, struct timeval tv, DELTA_TIME *delta) { DELTA_TIME pdelay; struct timeval now; GETTIMEOFDAY(&now); PSC_CALC_DELTA(pdelay, now, tv); VSTRING_RESET(buf); format_tv(buf, pdelay.dt_sec, pdelay.dt_usec, SIG_DIGS, var_delay_max_res); *delta = pdelay; return (STR(buf)); }