home *** CD-ROM | disk | FTP | other *** search
/ nisttime.carsoncity.k12.mi.us / nisttime.carsoncity.k12.mi.us.tar / nisttime.carsoncity.k12.mi.us / pub / acts / getlst.c < prev    next >
C/C++ Source or Header  |  1997-12-08  |  2KB  |  69 lines

  1. int getlst()
  2. {
  3. /*
  4.     this subroutine reads the last value in the difference file
  5.     and stores it in the global array tmprev.  this is a structure
  6.     of integers giving the year, month,day, hour, minute and second
  7.     of the most recent time difference followed by the value of
  8.     that time difference.
  9.  
  10.     since an IBMPC may have two clocks, there are two time differences
  11.     in the structure if IBMPC is defined.  the first is the previous
  12.     difference of the RAM clock and the second is for the CMOS clock
  13.     of AT-type machines.
  14. */
  15. #include "nistime.h"
  16. #include <stdio.h>
  17. extern struct tmprev
  18.     {
  19.     int yrprev;
  20.     int moprev;
  21.     int dyprev;
  22.     int hrprev;
  23.     int mnprev;
  24.     int scprev;
  25.     float dffprv;
  26.     char unprev;
  27. #ifdef IBMPC
  28.     float datprv;
  29.     char uatprv;
  30. #endif
  31. } tmpp;
  32. extern FILE *jop;
  33. FILE *fopen();
  34. extern int debug;
  35. int jj,num;
  36. #ifdef SUN
  37.     num= 8;
  38. #endif
  39. #ifdef IBMPC
  40.     num= 10;
  41. #endif
  42. /*
  43.     open difference file and skip to last line
  44.     if open fails signal that to caller
  45. */
  46.     if( (jop=fopen("nistime.dif","r+t")) == 0) return (0);
  47.     do
  48.     {
  49.     jj=fscanf(jop," %2d-%2d-%2d %2d:%2d:%2d%9f%c",
  50.     &tmpp.yrprev,&tmpp.moprev,&tmpp.dyprev,&tmpp.hrprev,
  51.     &tmpp.mnprev,&tmpp.scprev,&tmpp.dffprv,&tmpp.unprev);
  52. #ifdef IBMPC
  53.     jj += fscanf(jop," %9f%c",&tmpp.datprv,&tmpp.uatprv);
  54. #endif
  55.     } while (jj == num);
  56.     if(debug != 0)
  57.        {
  58.        printf("\n previous time difference\
  59.        \n%2d %2d %2d %2d %2d %2d %f  units= %c",
  60.        tmpp.yrprev,tmpp.moprev,tmpp.dyprev,tmpp.hrprev,
  61.        tmpp.mnprev,tmpp.scprev,tmpp.dffprv,tmpp.unprev);
  62. #ifdef IBMPC
  63.        printf("%f %c \n",tmpp.datprv,tmpp.uatprv);
  64. #endif
  65.        }
  66.     if(tmpp.yrprev < 80) tmpp.yrprev += 100;    /*years since 1900*/
  67.     return (1);
  68. }
  69.