3 * disabled: check to see if registration is enabled right now. Most of this
4 * code is stolen from the cron daemon.
6 * (c) Copyright 1988 by the Massachusetts Institute of Technology.
7 * For copying and distribution information, please see the file
11 #include <mit-copyright.h>
14 #include <sys/types.h>
19 #define LISTS (2 * BUFSIZ)
30 struct tm *localtime();
39 int number(char c, FILE *f);
41 /* This routine will determine if registration is enabled at this time. If
42 * NULL is returned, registration is OK. Otherwise, the string returned
43 * will indicate the time that registration will be re-enabled.
46 char *disabled(char **msg)
58 itime -= localtime(&itime)->tm_sec;
59 loct = localtime(&itime);
60 loct->tm_mon++; /* 1-12 for month */
61 if (loct->tm_wday == 0)
62 loct->tm_wday = 7; /* sunday is 7, not 0 */
64 for (cp = list; *cp != EOS;)
67 cp = cmp(cp, loct->tm_min);
68 cp = cmp(cp, loct->tm_hour);
69 cp = cmp(cp, loct->tm_mday);
70 cp = cmp(cp, loct->tm_mon);
71 cp = cmp(cp, loct->tm_wday);
85 itime += 60; /* add a minute */
86 loct = localtime(&itime);
87 loct->tm_mon++; /* 1-12 for month */
88 if (loct->tm_wday == 0)
89 loct->tm_wday = 7; /* sunday is 7, not 0 */
91 for(cp = list; *cp != EOS;)
94 cp = cmp(cp, loct->tm_min);
95 cp = cmp(cp, loct->tm_hour);
96 cp = cmp(cp, loct->tm_mday);
97 cp = cmp(cp, loct->tm_mon);
98 cp = cmp(cp, loct->tm_wday);
108 return ctime(&itime);
111 char *cmp(char *p, int v)
131 while (*cp++ != LIST)
140 if (*cp > v || cp[1] < v)
152 * Don't free in case was longer than LISTS. Trades off
153 * the rare case of crontab shrinking vs. the common case of
154 * extra realloc's needed in append() for a large crontab.
158 list = malloc(LISTS);
172 if (!(f = fopen(fn, "r")))
176 if (cp > list + listsize - MAXLIN)
178 int length = cp - list;
181 list = realloc(list, listsize);
189 while(c == ' ' || c == '\t');
190 if (c == EOF || c == '\n')
199 if ((n = number(c, f)) < 0)
206 if(c != '\t' && c != ' ')
217 if ((n = number(getc(f), f)) < 0)
223 if (c != '\t' && c != ' ')
231 if ((n = number(getc(f), f)) < 0)
234 if (c != '\t' && c != ' ')
266 int number(char c, FILE *f)
272 n = n * 10 + c - '0';