suitcase

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

check.c (1153B)


      1 #include <stdio.h>
      2 #include <time.h>
      3 #include <tai/tai.h>
      4 #include <tai/leapsecs.h>
      5 #include <tai/caltime.h>
      6 
      7 char line[100];
      8 
      9 char *dayname[7] = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" } ;
     10 
     11 char out[101];
     12 char x[TAI_PACK];
     13 
     14 int main(int argc, char **argv)
     15 {
     16   struct tai t;
     17   struct tai t2;
     18   struct caltime ct;
     19   struct caltime ct2;
     20   int weekday;
     21   int yearday;
     22   int i;
     23   double packerr;
     24 
     25   if (leapsecs_init() == -1)
     26     printf("unable to init leapsecs\n");
     27 
     28   while (fgets(line,sizeof line,stdin))
     29     if (!caltime_scan(line,&ct))
     30       printf("unable to parse\n");
     31     else {
     32       caltime_tai(&ct,&t);
     33       caltime_utc(&ct2,&t,&weekday,&yearday);
     34       tai_pack(x,&t);
     35       tai_unpack(x,&t2);
     36       tai_sub(&t2,&t2,&t);
     37       packerr = tai_approx(&t2);
     38       for (i = 0;i < TAI_PACK;++i)
     39         printf("%2.2x",(unsigned long) (unsigned char) x[i]);
     40       if (packerr)
     41         printf(" packerr=%f",packerr);
     42       printf(" %03d  %s",yearday,dayname[weekday]);
     43       if (caltime_fmt((char *) 0,&ct2) + 1 < sizeof out) {
     44         out[caltime_fmt(out,&ct2)] = 0;
     45         printf(" %s",out);
     46       }
     47       printf("\n");
     48     }
     49   exit(0);
     50 }