Esempio n. 1
0
static int create_time_rec(const str *time_start, const str *time_end,
		const str *week_days, tmrec_p trec)
{
	int end_h, end_m;

	memset(trec, 0, sizeof(tmrec_t));

	if (strtime(time_start, &trec->ts.tm_hour, &trec->ts.tm_min) != 0
			|| strtime(time_end, &end_h, &end_m) != 0)
		return -1;

	trec->duration = (end_h * 3600 + end_m * 60) -
		(trec->ts.tm_hour * 3600 + trec->ts.tm_min * 60);
	trec->ts.tm_isdst = -1 /*daylight*/;
	trec->dtstart = trec->duration;
	trec->freq = FREQ_DAILY;

	unsigned short day_set = 0;
	int n = parse_week_days(week_days, &day_set);

	if (n == -1)
		return -1;

	if (n) {
		//TODO - byday custom init - no req needed
		trec->byday = tr_byxxx_new(SHM_ALLOC);
		if (trec->byday == NULL)
			return -1;

		if (tr_byxxx_init(trec->byday, n) < 0) {
			tr_byxxx_free(trec->byday);
			return -1;
		}

		short i, j = 0;

		for (i = 0; i < 7; ++i)
			if (day_set & 1 << i)
				trec->byday->xxx[j++] = i;
	}

	return 0;
}
Esempio n. 2
0
tr_byxxx_p ic_parse_byxxx(char *_in)
{
	tr_byxxx_p _bxp = NULL;
	int _nr, _s, _v;
	char *_p;

	if(!_in)
		return NULL;
	_bxp = tr_byxxx_new();
	if(!_bxp)
		return NULL;
	_p = _in;
	_nr = 1;
	while(*_p)
	{
		if(*_p == ',')
			_nr++;
		_p++;
	}
	if(tr_byxxx_init(_bxp, _nr) < 0)
	{
		tr_byxxx_free(_bxp);
		return NULL;
	}
	_p = _in;
	_nr = _v = 0;
	_s = 1;
	while(*_p && _nr < _bxp->nr)
	{
		switch(*_p)
		{
			case '0': case '1': case '2':
			case '3': case '4': case '5':
			case '6': case '7': case '8':
			case '9':
				_v = _v*10 + *_p - '0';
			break;
			
			case '-':
				_s = -1;
			break;
			case '+':
			case ' ':
			case '\t':
			break;
			case ',':
				_bxp->xxx[_nr] = _v;
				_bxp->req[_nr] = _s;
				_s = 1;
				_v = 0;
				_nr++;
			break;
			default:
				goto error;
		}
		_p++;
	}
	if(_nr < _bxp->nr)
	{
		_bxp->xxx[_nr] = _v;
		_bxp->req[_nr] = _s;
	}
	return _bxp;

error:
	tr_byxxx_free(_bxp);
	return NULL;
}
Esempio n. 3
0
tr_byxxx_p ic_parse_byday(char *_in)
{
	tr_byxxx_p _bxp = NULL;
	int _nr, _s, _v;
	char *_p;

	if(!_in)
		return NULL;
	_bxp = tr_byxxx_new();
	if(!_bxp)
		return NULL;
	_p = _in;
	_nr = 1;
	while(*_p)
	{
		if(*_p == ',')
			_nr++;
		_p++;
	}
	if(tr_byxxx_init(_bxp, _nr) < 0)
	{
		tr_byxxx_free(_bxp);
		return NULL;
	}
	_p = _in;
	_nr = _v = 0;
	_s = 1;
	while(*_p && _nr < _bxp->nr)
	{
		switch(*_p)
		{
			case '0': case '1': case '2':
			case '3': case '4': case '5':
			case '6': case '7': case '8':
			case '9':
				_v = _v*10 + *_p - '0';
			break;
			
			case 's':
			case 'S':
				_p++;
				switch(*_p)
				{
					case 'a':
					case 'A':
						_bxp->xxx[_nr] = WDAY_SA;
						_bxp->req[_nr] = _s*_v;
					break;
					case 'u':
					case 'U':
						_bxp->xxx[_nr] = WDAY_SU;
						_bxp->req[_nr] = _s*_v;
					break;
					default:
						goto error;
				}
				_s = 1;
				_v = 0;
			break;
			case 'm':
			case 'M':
				_p++;
				if(*_p!='o' && *_p!='O')
					goto error;
				_bxp->xxx[_nr] = WDAY_MO;
				_bxp->req[_nr] = _s*_v;
				_s = 1;
				_v = 0;
			break;
			case 't':
			case 'T':
				_p++;
				switch(*_p)
				{
					case 'h':
					case 'H':
						_bxp->xxx[_nr] = WDAY_TH;
						_bxp->req[_nr] = _s*_v;
					break;
					case 'u':
					case 'U':
						_bxp->xxx[_nr] = WDAY_TU;
						_bxp->req[_nr] = _s*_v;
					break;
					default:
						goto error;
				}
				_s = 1;
				_v = 0;
			break;
			case 'w':
			case 'W':
				_p++;
				if(*_p!='e' && *_p!='E')
					goto error;
				_bxp->xxx[_nr] = WDAY_WE;
				_bxp->req[_nr] = _s*_v;
				_s = 1;
				_v = 0;
			break;
			case 'f':
			case 'F':
				_p++;
				if(*_p!='r' && *_p!='R')
					goto error;
				_bxp->xxx[_nr] = WDAY_FR;
				_bxp->req[_nr] = _s*_v;
				_s = 1;
				_v = 0;
			break;
			case '-':
				_s = -1;
			break;
			case '+':
			case ' ':
			case '\t':
			break;
			case ',':
				_nr++;
			break;
			default:
				goto error;
		}
		_p++;
	}

	return _bxp;

error:
	tr_byxxx_free(_bxp);
	return NULL;
}