condition.c
/**
  check conditions for all states to find a set which are currently valid. At present, all 
  conditions are checked, however this is not guaranteed. In the future, this process will
  be optimised.
 */
check conditions for all states to find a set which are currently valid. At present, all
conditions are checked, however this is not guaranteed. In the future, this process will
be optimised.
check conditions for all states to find a set which are currently valid . At present all conditions are checked however this is not guaranteed . In the future this process will be optimised .
int check_all_conditions(symbol_table variables)
{
	int *failed = malloc((condition_set_number+1) * sizeof(int));
	int *conditions_run = malloc((condition_set_number+1) * sizeof(int)); 
	int i;
	int result = -1;
	condition *curr = condition_table;
    int unknownStateConditionSet = get_integer_value(states, "UNKNOWN");
	for (i=0; i<= condition_set_number; i++)
	{
		failed[i] = 0;
		conditions_run[i] = 0;
	}
    failed[get_integer_value(states, "START")] = 1; 
	while (curr != NULL) 
	{
		int res = check_one_condition(variables, curr);
		conditions_run[curr->set]++;
		if (res != 0)
			failed[curr->set] = 1;
		curr = curr->next;
	}
    {
        int max = 0;
        for (i=0; i< condition_set_number; i++)
        {
            if (i != unknownStateConditionSet && !failed[i])
            {
                if (result<0 || max < conditions_run[i])
                {
                    max = conditions_run[i];
                    result =  i;
                }
            }
        }
    }
	if (result == -1) 
		result = unknownStateConditionSet;
	free(failed);
	free(conditions_run);
	return result;
}
int check_all_conditions ( symbol_table variables ) { int * failed = malloc ( ( condition_set_number + 1 ) * sizeof ( int ) ) ; int * conditions_run = malloc ( ( condition_set_number + 1 ) * sizeof ( int ) ) ; int i ; int result = -1 ; condition * curr = condition_table ; int unknownStateConditionSet = get_integer_value ( states , " " ) ; for ( i = 0 ; i <= condition_set_number ; i ++ ) { failed [ i ] = 0 ; conditions_run [ i ] = 0 ; } failed [ get_integer_value ( states , " " ) ] = 1 ; while ( curr != NULL ) { int res = check_one_condition ( variables , curr ) ; conditions_run [ curr -> set ] ++ ; if ( res != 0 ) failed [ curr -> set ] = 1 ; curr = curr -> next ; } { int max = 0 ; for ( i = 0 ; i < condition_set_number ; i ++ ) { if ( i != unknownStateConditionSet && ! failed [ i ] ) { if ( result < 0 || max < conditions_run [ i ] ) { max = conditions_run [ i ] ; result = i ; } } } } if ( result == -1 ) result = unknownStateConditionSet ; free ( failed ) ; free ( conditions_run ) ; return result ; }
check conditions for all states to find a set which are currently valid.
check conditions for all states to find a set which are currently valid .
/* note: the last condition set is held in condition_set_number.  There is 
		never any condition numbered zero but we ignore that and prepare a 
		slot anyway.
	 */ /* counts how many conditions were run for each state */ /* there is no way back to the start state */ /* return the first set that has not failed */ /*else
            {
                printf("condition set %d failed after %d conditions\n", i, conditions_run[i]);
            }*/ /* no states match, switch to the unknown state */