示例#1
0
/*
 * Returns true if the order is correct
 */
int
correctLocalOrder (const System sys)
{
  int flag;

  int checkRun (int r1)
  {
    int checkTerm (Term t)
    {
      if (!isTermVariable (t))
	{
	  int r2;
	  int e1, e2;

	  // t is a term from r2 that occurs in r1
	  r2 = TermRunid (t);
	  e1 = firstOccurrence (sys, r1, t, ANYEVENT);
	  if (e1 >= 0)
	    {
	      if (roledef_shift (sys->runs[r1].start, e1)->type == RECV)
		{
		  e2 = firstOccurrence (sys, r2, t, SEND);
		  if (e2 >= 0)
		    {
		      // thus, it should not be the case that e1 occurs before e2
		      if (isDependEvent (r1, e1, r2, e2))
			{
			  // That's not good!
			  if (switches.output == PROOF)
			    {
			      indentPrint ();
			      eprintf ("Pruned because ordering for term ");
			      termSubstPrint (t);
			      eprintf
				(" cannot be correct: the first send r%ii%i occurs after the receive r%ii%i.\n",
				 r2, e2, r1, e1);
			    }
			  flag = false;
			  return false;
			}
		    }
		}
	    }
	  else
	    {
	      globalError++;
	      eprintf ("error: term ");
	      termSubstPrint (t);
	      eprintf
		(" from run %i should occur in run %i, but it doesn't.\n", r2,
		 r1);
	      globalError--;
	      error ("Abort");
	    }
	}
      return true;
    }

    return iterateLocalToOther (sys, r1, checkTerm);
  }
示例#2
0
QDate WeeklyRecurrence::nextOccurrence(const QDate &date, bool include_equals) const {
	const KCalendarSystem *calSys = KGlobal::locale()->calendar();
	if(!include_equals) {
		if(date < startDate()) return firstOccurrence();
	} else {
		if(date <= startDate()) return firstOccurrence();
	}
	QDate nextdate = date;
	if(!include_equals) nextdate = calSys->addDays(nextdate, 1);
	if(!endDate().isNull() && nextdate > endDate()) return QDate();
	if(i_frequency != 1 && calSys->weekNumber(nextdate) != calSys->weekNumber(startDate())) {
		int i = weeks_between_dates(startDate(), nextdate) % i_frequency;
		if(i != 0) {
			nextdate = calSys->addDays(nextdate, (i_frequency - i) * 7 - (calSys->dayOfWeek(nextdate) - 1));
		}
	}
	int dow = calSys->dayOfWeek(nextdate);
	int i = dow;
	for(; i <= 7; i++) {
		if(b_daysofweek[i - 1]) {
			break;
		}
	}
	if(i > 7) {
		for(i = 1; i <= 7; i++) {
			if(b_daysofweek[i - 1]) {
				break;
			}
		}
		if(i > 7) return QDate();
	}
	if(i < dow) {
		nextdate = calSys->addDays(nextdate, (i_frequency * 7) + i - dow);
	} else if(i > dow) {
		nextdate = calSys->addDays(nextdate, i - dow);
	}
	if(!endDate().isNull() && nextdate > endDate()) return QDate();
	if(hasException(nextdate)) return nextOccurrence(nextdate);
	return nextdate;
}
示例#3
0
QDate DailyRecurrence::nextOccurrence(const QDate &date, bool include_equals) const {
	const KCalendarSystem *calSys = KGlobal::locale()->calendar();
	if(include_equals) {
		if(date == startDate()) return date;
	}
	QDate nextdate = date;
	if(!include_equals) nextdate = calSys->addDays(nextdate, 1);
	if(!endDate().isNull() && nextdate > endDate()) return QDate();
	if(nextdate <= startDate()) return firstOccurrence();
	if(i_frequency != 1) {
		int days = startDate().daysTo(nextdate);
		if(days % i_frequency != 0) {
			nextdate = calSys->addDays(nextdate, i_frequency - (days % i_frequency));
		}
	}
	if(!endDate().isNull() && nextdate > endDate()) return QDate();
	if(hasException(nextdate)) return nextOccurrence(nextdate);
	return nextdate;
}
示例#4
0
QDate YearlyRecurrence::nextOccurrence(const QDate &date, bool include_equals) const {
	const KCalendarSystem *calSys = KGlobal::locale()->calendar();
	if(!include_equals) {
		if(date < startDate()) return firstOccurrence();
	} else {
		if(date <= startDate()) return firstOccurrence();
	}
	QDate nextdate = date;
	if(!include_equals) nextdate = calSys->addDays(nextdate, 1);
	if(!endDate().isNull() && nextdate > endDate()) return QDate();
	if(calSys->year(nextdate) == calSys->year(startDate())) {
		nextdate = calSys->addYears(nextdate, i_frequency);
		calSys->setYMD(nextdate, calSys->year(nextdate), 1, 1);
	} else if(i_frequency != 1) {
		int i = (calSys->year(nextdate) - calSys->year(startDate())) % i_frequency;
		if(i != 0) {
			nextdate = calSys->addYears(nextdate, i_frequency - i);
			calSys->setYMD(nextdate, calSys->year(nextdate), 1, 1);
		}
	}
	if(i_dayofyear > 0) {
		if(calSys->dayOfYear(nextdate) > i_dayofyear) {
			nextdate = calSys->addYears(nextdate, i_frequency);
		}
		if(i_dayofyear > calSys->daysInYear(nextdate)) {
			int i = 10;
			do {
				if(i == 0) return QDate();
				nextdate = calSys->addYears(nextdate, i_frequency);
				i--;
			} while(i_dayofyear > calSys->daysInYear(nextdate));
		}
		nextdate = calSys->addDays(nextdate, i_dayofyear - calSys->dayOfYear(nextdate));
	} else {
		int day = i_dayofmonth;
		if(i_dayofweek > 0) day = get_day_in_month(calSys->year(nextdate), i_month, i_week, i_dayofweek);
		if(day == 0 || calSys->month(nextdate) > i_month || (calSys->month(nextdate) == i_month && calSys->day(nextdate) > day)) {
			do {
				nextdate = calSys->addYears(nextdate, i_frequency);
				day = get_day_in_month(calSys->year(nextdate), i_month, i_week, i_dayofweek);
				if(!endDate().isNull() && calSys->year(nextdate) > calSys->year(endDate())) return QDate();
			} while(day == 0);
		}
		if(i_dayofweek <= 0) {
			calSys->setYMD(nextdate, calSys->year(nextdate), i_month, 1);
			if(day > calSys->daysInMonth(nextdate)) {
				int i = 10;
				do {
					if(i == 0) return QDate();
					nextdate = calSys->addYears(nextdate, i_frequency);
					calSys->setYMD(nextdate, calSys->year(nextdate), i_month, 1);
					i--;
				} while(day > calSys->daysInMonth(nextdate));
			}
		}
		calSys->setYMD(nextdate, calSys->year(nextdate), i_month, day);
	}
	if(!endDate().isNull() && nextdate > endDate()) return QDate();
	if(hasException(nextdate)) return nextOccurrence(nextdate);
	return nextdate;
}
示例#5
0
QDate MonthlyRecurrence::nextOccurrence(const QDate &date, bool include_equals) const {
	const KCalendarSystem *calSys = KGlobal::locale()->calendar();
	if(!include_equals) {
		if(date < startDate()) return firstOccurrence();
	} else {
		if(date <= startDate()) return firstOccurrence();
	}
	QDate nextdate = date;
	if(!include_equals) nextdate = calSys->addDays(nextdate, 1);
	if(!endDate().isNull() && nextdate > endDate()) return QDate();
	int prevday = -1;
	if(calSys->month(nextdate) == calSys->month(startDate())) {
		if(i_frequency > 1) prevday = 1;
		else prevday = calSys->day(nextdate);
		nextdate = calSys->addMonths(nextdate, i_frequency);
		calSys->setYMD(nextdate, calSys->year(nextdate), calSys->month(nextdate), 1);
	} else if(i_frequency != 1) {
		int i = months_between_dates(startDate(), nextdate) % i_frequency;
		if(i != 0) {
			if(i_frequency - i > 1) prevday = 1;
			else prevday = calSys->day(nextdate);
			nextdate = calSys->addMonths(nextdate, i_frequency - i);
			calSys->setYMD(nextdate, calSys->year(nextdate), calSys->month(nextdate), 1);
		}
	}
	int day = i_day;
	if(i_dayofweek > 0) day = get_day_in_month(nextdate, i_week, i_dayofweek);
	else if(i_day < 1) day = calSys->daysInMonth(nextdate) + i_day;
	if(wh_weekendhandling == WEEKEND_HANDLING_BEFORE) {
		QDate date;
		calSys->setYMD(date, calSys->year(nextdate), calSys->month(nextdate), day);
		int wday = calSys->dayOfWeek(date);
		if(wday == 6) day -= 1;
		else if(wday == 7) day -= 2;
		if(day <= 0 && prevday > 0 && prevday <= calSys->daysInMonth(calSys->addMonths(nextdate, -1)) + day) {
			nextdate = calSys->addMonths(nextdate, -1);
			day = calSys->daysInMonth(nextdate) + day;
		}
	} else if(wh_weekendhandling == WEEKEND_HANDLING_AFTER) {
		QDate date;
		calSys->setYMD(date, calSys->year(nextdate), calSys->month(nextdate), day);
		int wday = calSys->dayOfWeek(date);
		if(wday == 6) day += 2;
		else if(wday == 7) day += 1;
		if(day > calSys->daysInMonth(nextdate)) {
			day -= calSys->daysInMonth(nextdate);
			nextdate = calSys->addMonths(nextdate, 1);
			calSys->setYMD(nextdate, calSys->year(nextdate), calSys->month(nextdate), day);
		}
	}
	if(day <= 0 || calSys->day(nextdate) > day || day > calSys->daysInMonth(nextdate)) {
		do {
			if(i_frequency > 1) prevday = 1;
			else prevday = calSys->day(nextdate);
			nextdate = calSys->addMonths(nextdate, i_frequency);
			if(!endDate().isNull() && calSys->month(nextdate) > calSys->month(endDate())) return QDate();
			day = i_day;
			if(i_dayofweek > 0) day = get_day_in_month(nextdate, i_week, i_dayofweek);
			else if(i_day < 1) day = calSys->daysInMonth(nextdate) + i_day;
			if(wh_weekendhandling == WEEKEND_HANDLING_BEFORE) {
				QDate date;
				calSys->setYMD(date, calSys->year(nextdate), calSys->month(nextdate), day);
				int wday = calSys->dayOfWeek(date);
				if(wday == 6) day -= 1;
				else if(wday == 7) day -= 2;
				if(day <= 0 && prevday > 0 && prevday <= calSys->daysInMonth(calSys->addMonths(nextdate, -1)) + day) {
					nextdate = calSys->addMonths(nextdate, -1);
					day = calSys->daysInMonth(nextdate) + day;
				} else {
					calSys->setYMD(nextdate, calSys->year(nextdate), calSys->month(nextdate), 1);
				}
			} else if(wh_weekendhandling == WEEKEND_HANDLING_AFTER) {
				QDate date;
				calSys->setYMD(date, calSys->year(nextdate), calSys->month(nextdate), day);
				int wday = calSys->dayOfWeek(date);
				if(wday == 6) day += 2;
				else if(wday == 7) day += 1;
				if(day > calSys->daysInMonth(nextdate)) {
					day -= calSys->daysInMonth(nextdate);
					nextdate = calSys->addMonths(nextdate, 1);
					calSys->setYMD(nextdate, calSys->year(nextdate), calSys->month(nextdate), day);
				}
			}
		} while(day <= 0 || day > calSys->daysInMonth(nextdate));
	}
	calSys->setYMD(nextdate, calSys->year(nextdate), calSys->month(nextdate), day);
	if(!endDate().isNull() && nextdate > endDate()) return QDate();
	if(hasException(nextdate)) return nextOccurrence(nextdate);
	return nextdate;
}