home *** CD-ROM | disk | FTP | other *** search
/ back2roots/padua / padua.7z / padua / uucp / auucp+-1.02 / fuucp_plus_src.lzh / uucico / time.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-11-21  |  2.0 KB  |  113 lines

  1.  
  2. /*
  3.  *  TIME.C
  4.  *
  5.  *  By Christopher A. Wichura
  6.  *
  7.  *  Note: cannot use strtok() due to parent level's use of it.
  8.  */
  9.  
  10. #include "includes.h"           /* System include files, system dependent */
  11. #include "uucp.h"               /* Uucp definitions and parameters */
  12. #include <log.h>
  13. #include "version.h"
  14.  
  15. Prototype int CheckTimeRestrictions(char *);
  16.  
  17. typedef struct tm   Time;
  18.  
  19. char Days[7][3] = {"Su", "Mo", "Tu", "We", "Th", "Fr", "Sa"};
  20.  
  21. int
  22. CheckTimeRestrictions(timeStr)
  23. char *timeStr;
  24. {
  25.     Time *tm;
  26.     char *ptr;
  27.     int work1;
  28.     int work2;
  29.     int starth, startm;
  30.     int endh,    endm;
  31.     char Hours[24];
  32.     int result;
  33.     int day;
  34.  
  35.     if (strnicmp("Any", timeStr, 3) == 0)
  36.     return (SUCCESS);
  37.  
  38.     if (strnicmp("Never", timeStr, 5) == 0)
  39.     return (FAIL);
  40.  
  41.     {
  42.     time_t t;
  43.     time (&t);
  44.     tm = localtime(&t);
  45.     }
  46.  
  47.     result = FAIL;
  48.  
  49.     for (ptr = timeStr; ptr; ptr = strpbrk(ptr, ",")) {
  50.     if (*ptr == ',')
  51.         ++ptr;
  52.  
  53.     day = 0;
  54.  
  55.     while (isalpha(*ptr)) {
  56.         for (work1 = 0; work1 < 7; ++work1) {
  57.         if (strnicmp(ptr, Days[work1], 2) == 0) {
  58.             day |= 1L << work1;
  59.             ptr += 2;
  60.             break;
  61.         }
  62.         }
  63.         if (work1 == 7) {
  64.         ulog(-1, "Illegal DOW Field (L.Sys): %s", timeStr);
  65.         return(FAIL);
  66.         }
  67.     }
  68.  
  69.     if (day == 0)
  70.         day = -1;
  71.  
  72.     if (sscanf(ptr, "%d:%d-%d:%d", &starth, &startm, &endh, &endm) != 4) {
  73.         ulog(-1, "Illegal Time Range Field (L.Sys): %s", timeStr);
  74.         return(FAIL);
  75.     }
  76.  
  77.     /*
  78.      * at this point we have start and end times.  check them against
  79.      * current system time
  80.      */
  81.  
  82.     setmem(Hours, sizeof(Hours), 0);
  83.  
  84.     work1 = endh - starth;
  85.     if (work1 < 0)
  86.         work1 += 24;
  87.  
  88.     work1 = starth + work1;
  89.     work2 = starth;
  90.  
  91.     while (work2 <= work1) {
  92.         Hours[work2++] = 1;
  93.  
  94.         if (work2 == 24)
  95.         work1 -= 24, work2 -=24;
  96.     }
  97.  
  98.     for (;;) {
  99.         if (!(day & 1L << tm->tm_wday))
  100.         break;
  101.         if (!Hours[tm->tm_hour])
  102.         break;
  103.         if (tm->tm_hour == starth && tm->tm_min < startm)
  104.         break;
  105.         if (tm->tm_hour == endh && tm->tm_min > endm)
  106.         break;
  107.         return(SUCCESS);
  108.     }
  109.     }
  110.     return (FAIL);
  111. }
  112.  
  113.