1772
|
1 /* chksched.c This routine check to see if it is okay to call the remote.
|
|
2 Copyright (C) 1990, 1993 Rick Adams and Bob Billson
|
|
3
|
|
4 This file is part of the OS-9 UUCP package, UUCPbb.
|
|
5
|
|
6 This program is free software; you can redistribute it and/or modify
|
|
7 it under the terms of the GNU General Public License as published by
|
|
8 the Free Software Foundation; either version 2 of the License, or
|
|
9 (at your option) any later version.
|
|
10
|
|
11 This program is distributed in the hope that it will be useful,
|
|
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
14 GNU General Public License for more details.
|
|
15
|
|
16 You should have received a copy of the GNU General Public License
|
|
17 along with this program; if not, write to the Free Software
|
|
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
19
|
|
20 The author of UUCPbb, Bob Billson, can be contacted at:
|
|
21 bob@kc2wz.bubble.org or uunet!kc2wz!bob or by snail mail:
|
|
22 21 Bates Way, Westfield, NJ 07090
|
|
23 */
|
|
24
|
|
25 /* Check to see if it is okay to call remote.by looking at the schedule
|
|
26 (second) field of the Systems file entry. The schedule field has two
|
|
27 subfields, DAY and TIME. The DAY and TIME subfields have no spaces between
|
|
28 them. The DAY subfield is specified using the following keywords (case is
|
|
29 ingored):
|
|
30
|
|
31 Any -we can call at any time
|
|
32 Never -we never should never call but wait to be called
|
|
33 Wk -call any weekday (Monday-Friday)
|
|
34 Su,Mo,Tu,We, -call on individual days
|
|
35 Th,Fr,Sa
|
|
36
|
|
37 The TIME subfield is specified by two 24-hour clock times separated by
|
|
38 a dash (-), e.g. 0930-1100, call only between 9:30 and 11:00 in the
|
|
39 morning. More than one schedule field can be included by separating
|
|
40 them with commas. For example:
|
|
41
|
|
42 Wk1230-1545,Su,Sa -call Monday-Friday from 12:30 to 3:45 in the
|
|
43 afternoon and any time on Saturday and Sunday.
|
|
44 Any1800-2000 -call any day from 6:00 to 8:00 at night
|
|
45 Any -call any day, any time
|
|
46 Th -call any time on Thursday
|
|
47 */
|
|
48
|
|
49 #include "uucp.h"
|
|
50 #include "uucico.h"
|
|
51
|
|
52
|
|
53 int chksched (sched)
|
|
54 char *sched;
|
|
55 {
|
|
56 static char *days[]={"Su","Mo","Tu","We","Th","Fr","Sa"};
|
|
57 struct tm *local_time;
|
|
58 register char *p;
|
|
59 char *com, *dash;
|
|
60 int day, miltime, after, before;
|
|
61 #ifdef _OSK
|
|
62 time_t t;
|
|
63 #else
|
|
64 long t;
|
|
65 #endif
|
|
66
|
|
67 time(&t);
|
|
68 local_time = localtime(&t);
|
|
69 day = local_time->tm_wday;
|
|
70 miltime = local_time->tm_hour * 100 + local_time->tm_min;
|
|
71 strcpy (temp, sched);
|
|
72
|
|
73 for (p = com = temp; com != NULL; p = com + 1)
|
|
74 {
|
|
75 if ((com = strchr (p, ',')) != NULL)
|
|
76 *com = '\0';
|
|
77
|
|
78 if ((dash = strchr (p, '-')) != NULL)
|
|
79 *dash = '\0';
|
|
80
|
|
81 /* Is today OK? */
|
|
82 if (strnucmp (p, "Never", 5) == 0)
|
|
83 return (FALSE);
|
|
84
|
|
85 /* 'Any' matches any day */
|
|
86 if (strnucmp (p, "Any", 3) == 0)
|
|
87 p += 3;
|
|
88
|
|
89 /* Correct day of week? */
|
|
90 else if (strnucmp (p, *(days + day), 2) == 0)
|
|
91 p += 2;
|
|
92
|
|
93 /* Is it a weekday? */
|
|
94 else if (day > 0 && day < 6 && strnucmp (p, "Wk", 2) == 0)
|
|
95 p += 2;
|
|
96
|
|
97 /* No match, try next one */
|
|
98 else
|
|
99 continue;
|
|
100
|
|
101 /* Is time OK? */
|
|
102
|
|
103 /* No time specified, thus, it matches */
|
|
104 if (*p == '\0')
|
|
105 return (TRUE);
|
|
106
|
|
107 /* Else, check military time, assume correct format */
|
|
108 after = atoi (p);
|
|
109 before = atoi (dash+1);
|
|
110
|
|
111 /* 1800-2000 (not wrapping around 0000) */
|
|
112 if (after <= before)
|
|
113 {
|
|
114 if (miltime >= after && miltime <= before)
|
|
115 return (TRUE);
|
|
116 }
|
|
117 /* 2310-0750 (wrapping around 0000) */
|
|
118 else
|
|
119 {
|
|
120 if (miltime >= after || miltime <= before)
|
|
121 return (TRUE);
|
|
122 }
|
|
123 }
|
|
124
|
|
125 /* No times matched, return FALSE */
|
|
126 return (FALSE);
|
|
127 }
|