
		33) Multiple Times To Call in L.sys

Date: Friday, 12 March 1982 at 1405-PST
To: tekmdp!teklabs!sterling
Cc: tekmdp!teklabs!system
Cc: sysprog
Fcc: uucp
Subject: Date routine in uucp


This routine allows you to specify a range of dates, in particular
the range that we want for uucp:

	Any0-0600,Any2300-2359,Sa0-2359,Su0-1800

this optimizes calling when the rates are low. This routine should
be installed replacing 'ifdate', which is the last routine in
'conn.c' (conn.c.hayes for the teklabs system).


~~~~~~~~~~~~~


/*********
 *
 *	ifdate(s)
 *
 *		this routine breaks up a comma-seperated list
 *		of date strings and calls _ifdate (the old
 *		ifdate) with them. This is a bit of a kludge,
 *		but in practice it works well.
 *
 *	S. McGeady, Tektronix, 3/12/82
 */

ifdate(s)
char *s;
{
	register char *p, *p1;
	register int rval;

	rval = 0;
	p = s;

	for (;;) {

		p1 = p;
		while (*p != '\0' && *p != ',') p++;

		if (*p == ',') {
			*p = '\0';
			rval += _ifdate(p1);
			*p++ = ',';
		} else {
			rval += _ifdate(p1);
			break;
		}
	}
	return(rval >= 1 ? 1 : 0);
}

/*******
 *	_ifdate(s)
 *	char *s;
 *
 *	_ifdate  -  this routine will check a string (s)
 *	like "MoTu0800-1730" to see if the present
 *	time is within the given limits.
 *
 *	String alternatives:
 *		Wk - Mo thru Fr
 *		zero or one time means all day
 *		Any - any day
 *
 *	return codes:
 *		0  -  not within limits
 *		1  -  within limits
 */

_ifdate(s)
char *s;
{
	static char *days[]={
		"Su", "Mo", "Tu", "We", "Th", "Fr", "Sa", 0
	};
	long clock;
	int i, tl, th, tn, dayok=0;
	struct tm *localtime();
	struct tm *tp;

	time(&clock);
	tp = localtime(&clock);
	while (isalpha(*s)) {
		for (i = 0; days[i]; i++) {
			if (prefix(days[i], s))
				if (tp->tm_wday == i)
					dayok = 1;
		}

		if (prefix("Wk", s))
			if (tp->tm_wday >= 1 && tp->tm_wday <= 5)
				dayok = 1;
		if (prefix("Any", s))
			dayok = 1;
		s++;
	}

	if (dayok == 0)
		return(0);
	i = sscanf(s, "%d-%d", &tl, &th);
	tn = tp->tm_hour * 100 + tp->tm_min;
	if (i < 2)
		return(1);
	if (tn >= tl && tn <= th)
		return(1);
	return(0);
}


~~~~~~~~~~~~~

