1// quick hack to re-compute the delta times in an irdalog 2 3#include <stdio.h> 4 5#define Reset 0 6#define Delta 1 7 8int state = Reset; 9long last_fract, last_secs; 10char buf[1000]; 11 12int main(int argc, char *argv[]) 13{ 14 long secs; /* the seconds */ 15 long fract; /* the fraction */ 16 int rc1, rc2; 17 long dt1, dt2; 18 char *ts, *tf; /* start of seconds string and fraction string */ 19 char *index(), *rindex(); 20 21 while (fgets(buf, sizeof(buf), stdin) != NULL) { /* loop over input */ 22 tf = index(buf, '.'); /* find the decimal */ 23 if (tf == NULL) { /* if none, blow off this line */ 24 state = Reset; 25 printf("%s", buf); 26 continue; 27 } 28 *tf = 0; /* zap the period */ 29 ts = rindex(buf, ' '); /* look for start of seconds */ 30 if (ts == NULL) ts = buf; 31 else ts++; 32 *tf = '.'; /* put back the period */ 33 tf++; 34 rc1 = sscanf(ts, "%ld", &secs); 35 rc2 = sscanf(tf, "%ld", &fract); 36 37 if (rc1 == 1 && rc2 == 1) { /* parsed it ok */ 38 if (state == Reset) { 39 printf("%s", buf); 40 state = Delta; 41 } 42 else { 43 dt2 = fract - last_fract; 44 dt1 = secs - last_secs; 45 if (dt2 < 0) { 46 dt2 += 1000000; 47 dt1--; 48 } 49 if (dt1 > 99) dt1 = 99; // seconds overflow 50 if (1) { // splice in the new delta time (bigger) 51 char *b1, *b2; 52 b1 = index(buf, '['); 53 b2 = index(buf, ']'); 54 if (b1 && b2) { 55 b1++; // end after the [ 56 *b1 = 0; 57 if (dt1 > 0) 58 printf("%s%2ld.%06ld%s", buf, dt1, dt2, b2); 59 else 60 printf("%s %6ld%s", buf, dt2, b2); 61 } 62 else 63 printf("%2ld.%06ld %s", dt1, dt2, buf); 64 } 65 } 66 last_secs = secs; 67 last_fract = fract; 68 continue; 69 } 70 // if verbose ... 71 //fprintf(stderr, "%s: %s", "Parse Error", buf); 72 } 73 return 0; 74} 75