home *** CD-ROM | disk | FTP | other *** search
/ ftp.wwiv.com / ftp.wwiv.com.zip / ftp.wwiv.com / pub / MISC / LO241SRV.ZIP / timer.c < prev    next >
C/C++ Source or Header  |  1998-08-01  |  2KB  |  86 lines

  1.  
  2. // LoraBBS Version 2.41 Free Edition
  3. // Copyright (C) 1987-98 Marco Maccaferri
  4. //
  5. // This program is free software; you can redistribute it and/or modify
  6. // it under the terms of the GNU General Public License as published by
  7. // the Free Software Foundation; either version 2 of the License, or
  8. // (at your option) any later version.
  9. //
  10. // This program is distributed in the hope that it will be useful,
  11. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13. // GNU General Public License for more details.
  14. //
  15. // You should have received a copy of the GNU General Public License
  16. // along with this program; if not, write to the Free Software
  17. // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18.  
  19. #include <stdio.h>
  20. #include <dos.h>
  21.  
  22. #define PER_WEEK    60480000L
  23. #define PER_DAY      8640000L
  24. #define PER_HOUR      360000L
  25. #define PER_MINUTE      6000L
  26. #define PER_SECOND       100L
  27.  
  28. void dostime (int *hour, int *min, int *sec, int *hdths)
  29. {
  30.    struct time timep;
  31.  
  32.    gettime (&timep);
  33.  
  34.    *hour = timep.ti_hour;
  35.    *min = timep.ti_min;
  36.    *sec = timep.ti_sec;
  37.    *hdths = timep.ti_hund;
  38. }
  39.  
  40. void dosdate (int *month, int *mday, int *year, int *wday)
  41. {
  42.    struct dosdate_t datep;
  43.  
  44.    _dos_getdate (&datep);
  45.  
  46.    *month = datep.month;
  47.    *mday = datep.day;
  48.    *year = datep.year;
  49.    *wday = datep.dayofweek;
  50. }
  51.  
  52. long timerset (int t)
  53. {
  54.    long l;
  55.    int hours, mins, secs, ths;
  56.  
  57.    /* Get the DOS time and day of week */
  58.    dostime (&hours, &mins, &secs, &ths);
  59.  
  60.    /* Figure out the hundredths of a second so far this week */
  61.    l = (mins % 60) * PER_MINUTE +
  62.        (secs % 60) * PER_SECOND +
  63.     ths;
  64.  
  65.    /* Add in the timer value */
  66.    l += t;
  67.  
  68.    /* Return the alarm off time */
  69.    return (l);
  70. }
  71.  
  72. int timeup (long t)
  73. {
  74.    long l;
  75.  
  76.    /* Get current time in hundredths */
  77.    l = timerset (0);
  78.  
  79.    /* If current is less then set by more than max int, then adjust */
  80.    if (l < (t - 65536L))
  81.       l += PER_HOUR;
  82.  
  83.    /* Return whether the current is greater than the timer variable */
  84.    return ((l - t) >= 0L);
  85. }
  86.