24 RCSID(
"$Id: a1fffc6674ef528a639418b6b61c3681724b25b8 $")
26 #include <freeradius-devel/radiusd.h>
32 static char const *
days[] =
33 {
"su",
"mo",
"tu",
"we",
"th",
"fr",
"sa",
"wk",
"any",
"al" };
35 #define DAYMIN (24*60)
36 #define WEEKMIN (24*60*7)
37 #define val(x) (( (x) < 48 || (x) > 57) ? 0 : ((x) - 48))
40 # define timestr_debug DEBUG2
41 # define do_timestr_debug 1
43 # define timestr_debug if (0) printf
56 for (i = 0; i < 10; i++) {
60 if (strncmp(*str, days[i], l) == 0) {
67 return (i >= 10) ? -1 : i;
86 if ((p = strchr(tm,
'-')) != NULL) {
88 if (p - tm != 5 || strlen(p) < 4 || !isdigit((
int) *p))
90 end = 600 *
val(p[0]) + 60 *
val(p[1]) + atoi(p + 2);
96 if (strlen(tm) < 4 || !isdigit((
int) *tm))
98 start = 600 *
val(tm[0]) + 60 *
val(tm[1]) + atoi(tm + 2);
99 if (end < 0) end = start;
102 if (end < 0) end = 0;
103 if (start < 0) start = 0;
107 timestr_debug(
"hour_fill: range from %d to %d\n", start, end);
117 bitmap[byte] |= (1 << bit);
134 for (hr = tm; *hr; hr++)
135 if (isdigit((
int) *hr))
142 while ((start =
strcode(&tm)) >= 0) {
162 timestr_debug(
"day_fill: range from %d to %d\n", start, end);
183 for (s = tmp; *s; s++)
184 if (isupper(*s)) *s = tolower(*s);
186 s = strtok(tmp,
",|");
189 s = strtok(NULL,
",|");
205 #ifdef do_timestr_debug
212 now = tm->tm_wday *
DAYMIN + tm->tm_hour * 60 + tm->tm_min;
214 memset(bitmap, 0,
sizeof(bitmap));
217 #ifdef do_timestr_debug
219 for (i = 0; i < 7; i++) {
221 s = bitmap + 180 * i;
222 for (y = 0; y < 23; y++) {
223 s = bitmap + 180 * i + (75 * y) / 10;
238 if (!(bitmap[byte] & (1 << bit)))
250 return (i == now) ? 0 : tot;
255 int main(
int argc,
char **argv)
260 fprintf(stderr,
"Usage: test timestring\n");
264 printf (
"%s: %d seconds left\n", argv[1], l);
static int week_fill(char *bitmap, char const *tm)
static char const * days[]
static int hour_fill(char *bitmap, char const *tm)
static int day_fill(char *bitmap, char const *tm)
static int strcode(char const **str)
int main(int argc, char *argv[])
size_t strlcpy(char *dst, char const *src, size_t siz)
struct tm * localtime_r(time_t const *l_clock, struct tm *result)
int timestr_match(char const *, time_t)