#include <afs/param.h>
#include <roken.h>
+#include <afs/opr.h>
#include <ctype.h>
+#include <afs/opr.h>
#include "afsutil.h"
#include "ktime.h"
};
/* free token list returned by parseLine */
-#ifdef undef
-static
-LocalFreeTokens(alist)
- struct token *alist;
+static void
+LocalFreeTokens(struct token *alist)
{
struct token *nlist;
for (; alist; alist = nlist) {
free(alist->key);
free(alist);
}
- return 0;
+ return;
}
-#endif
static int
space(int x)
if (inToken) {
inToken = 0; /* end of this token */
*tptr++ = 0;
- ttok = (struct token *)malloc(sizeof(struct token));
+ ttok = malloc(sizeof(struct token));
ttok->next = NULL;
- ttok->key = (char *)malloc(strlen(tbuffer) + 1);
- strcpy(ttok->key, tbuffer);
+ ttok->key = strdup(tbuffer);
if (last) {
last->next = ttok;
last = ttok;
/* look at each token */
if (strcmp(tt->key, "now") == 0) {
ak->mask |= KTIME_NOW;
- return 0;
+ goto out;
}
if (strcmp(tt->key, "never") == 0) {
ak->mask |= KTIME_NEVER;
- return 0;
+ goto out;
}
if (strcmp(tt->key, "at") == 0)
continue;
if (isdigit(tt->key[0])) {
/* parse a time */
code = ParseTime(ak, tt->key);
- if (code)
- return -1;
+ if (code) {
+ code = -1;
+ goto out;
+ }
continue;
}
/* otherwise use keyword table */
for (tp = ptkeys;; tp++) {
if (tp->key == NULL) {
- return -1;
+ code = -1;
+ goto out;
}
if (strcmp(tp->key, tt->key) == 0)
break;
/* am or pm token */
if ((tp->value & 0xff) == 1) {
/* pm */
- if (!(ak->mask & KTIME_HOUR))
- return -1;
- if (ak->hour < 12)
+ if (!(ak->mask & KTIME_HOUR)) {
+ code = -1;
+ goto out;
+ }
+ if (ak->hour < 12) {
ak->hour += 12;
/* 12 is 12 PM */
- else if (ak->hour != 12)
- return -1;
+ } else if (ak->hour != 12) {
+ code = -1;
+ goto out;
+ }
} else {
/* am is almost a noop, except that we map 12:01 am to 0:01 */
- if (ak->hour > 12)
- return -1;
+ if (ak->hour > 12) {
+ code = -1;
+ goto out;
+ }
if (ak->hour == 12)
ak->hour = 0;
}
}
}
- return 0;
+out:
+ LocalFreeTokens(tt);
+ return code;
}
/* ktime_DisplayString
/* handle some special cases */
if (tmask & KTIME_NEVER)
- return 0x7fffffff;
+ return KTIME_NEVERTIME;
if (tmask & KTIME_NOW)
- return 0;
+ return KTIME_NOWTIME;
/* Use probe to fill in members of *tsp. Add 23 hours each iteration until
* time_next is correct. Only add 23 hrs to avoid skipping spring
* daylight savings time day */
for (probe = start;; probe += (23 * 3600)) {
tsp = localtime(&probe); /* find out what UTC time "probe" is */
+ if (!tsp)
+ return KTIME_NEVERTIME;
tdate.year = tsp->tm_year;
tdate.month = tsp->tm_mon + 1;
continue; /* "probe" time is already past */
if ((tmask & KTIME_DAY) == 0) /* don't care about day, we're done */
break;
+
tsp = localtime(&time_next);
+ if (!tsp)
+ return KTIME_NEVERTIME;
if (tsp->tm_wday == aktime->day)
break; /* day matches, we're done */
}
/* compare date in both formats, and return as in strcmp */
-#ifdef undef
-static int
-KTimeCmp(struct ktime *aktime, struct tm *atm)
-{
- afs_int32 tmask;
-
- /* don't compare day of the week, since we can't tell the
- * order in a cyclical set. Caller must check for equality, if
- * she cares */
- tmask = aktime->mask;
- if (tmask & KTIME_HOUR) {
- if (aktime->hour > atm->tm_hour)
- return 1;
- if (aktime->hour < atm->tm_hour)
- return -1;
- }
- if (tmask & KTIME_MIN) {
- if (aktime->min > atm->tm_min)
- return 1;
- if (aktime->min < atm->tm_min)
- return -1;
- }
- if (tmask & KTIME_SEC) {
- if (aktime->sec > atm->tm_sec)
- return 1;
- if (aktime->sec < atm->tm_sec)
- return -1;
- }
- return 0;
-}
-#endif
-
-/* compare date in both formats, and return as in strcmp */
static int
KDateCmp(struct ktime_date *akdate, struct tm *atm)
{
while (tbit > 0) {
temp = tresult + tbit; /* see if adding this bit keeps us < akdate */
tsp = localtime(&temp);
+ if (!tsp)
+ return KTIMEDATE_NEVERDATE;
tsp->tm_mon++;
-#ifdef notdef
- if (tsp->tm_mon == 0) {
- tsp->tm_mon = 12;
- tsp->tm_year--;
- }
-#endif
if (KDateCmp(akdate, tsp) >= 0) {
/* if temp still represents earlier than date than we're searching
* for, add in bit as increment, otherwise use old value and look