Rev 335 | Blame | Compare with Previous | Last modification | View Log | RSS feed
/************************************************************************** Copyright (C) 1995 Embedded Solutions* All rights reserved** file: src\check.c** purpose: This module provides routines that are used to test the team's* times.*** functions* test_times - Recalculate team time information* set_times - Calc start times for each leg** programmer: David Purdie** revision date by reason* ??/05/90 MV Modified May 1990 by Margherita Veroni* 00.0 27/01/95 DDP Tidies up the program and formatted the file***************************************************************************/#include <stdlib.h>#include "consts.h"#include "structs.h"#include "proto.h"/* Internal declarations and definitions */int parallel_legs = FALSE; /* Legs run in Parallel */ty_check_error check_error;/*========================================================================** Recalculate team time information** Purpose:* This routine will examine the team entry and :-* Calculate the elapsed times for each leg* Calculate the elapsed time for the team* Flag any inconsistencies in the data* In consistencies are :-* No start time* No end time* End before start* Times without team data* NE team with a named NE competitor*** Parameters:* data address of the data buffer* upto_leg; Examine upto and including this leg** Returns:* The function returns the bad_times flag**========================================================================*/bool test_times( team_type * data, int upto_leg ){int i; /* One of those loopy things */time_t t; /* Used for time calcs */leg_type *use; /* pointer to leg entry */if( upto_leg == 0 )upto_leg = config.num_legs; /* Test all legs */data->flags.bad_times = FALSE; /* Set times ok */check_error.leg = check_error.type = 0;if( !data->flags.valid ){/*** Test for invalid team with time information present*/for( i = 0; i < upto_leg; i++ )if( data->leg[i + 1].end >= 0 ){check_error.type = 4; /* Flag error */check_error.leg = i;data->flags.bad_times = TRUE;t = ( time_t ) - 1;}}else{for( i = 0, t = 0; i < upto_leg; i++ ){use = &data->leg[i + 1]; /* Pointer to leg data */// Is this the NE leg ?// If NE then// If we have a competitor name - warn// Don't add in timeif ( i + 1 == config.equestrian_leg && data->flags.non_equestrian ){// This error is now detected by the caller//if ( data->members[i].name[0] && use->end >= 0)//{// if( !check_error.leg )// {// check_error.leg = i + 1;// check_error.type = 5;// }//}use->elapsed = -1;continue;}// Have a start and end time// Calculate the elapsed timeif( ( use->start >= 0 ) && ( use->end >= 0 ) && ( use->end > use->start ) ){t += use->elapsed = use->end - use->start;}else{// Determine erroruse->elapsed = ( time_t ) - 1;data->flags.bad_times = TRUE;if( !check_error.leg ){check_error.leg = i + 1;check_error.type = 1;if( use->start < 0 )continue;check_error.type = 2;if( use->end < 0 )continue;check_error.type = 3;}}}}data->leg[0].elapsed = t; /* total elapsed so far */data->leg[0].start = data->leg[1].start; /* Team start */data->leg[0].end = data->leg[upto_leg].end; /* Team end */return ( data->flags.bad_times ); /* Flag errors, not warnings */}/*========================================================================** Calc start times for each leg** Purpose:* This routine will calculate the start times for each leg of the event* where the start time has not been manually entered.** The routine will allow for two types of start-time calculations* 1) End of previous leg = Start of leg.* 2) Legs run in parallel ( No calcs to do )* These are controlled on a global scale** Note : Break in time caused by the specials for the start of a leg** Parameters:* data Address of the team data** Returns:* Nothing**========================================================================*/void set_times( team_type * data ){int i;if( !parallel_legs ){for( i = 2; i <= config.num_legs; i++ ){if( data->leg[i].manual )continue; /* Skip manually entered leg start */if( data->leg[i - 1].end >= 0 )data->leg[i].start = data->leg[i - 1].end;elsedata->leg[i].start = ( time_t ) - 1;}}}/********************************* EOF ***********************************/