static gint get_matches(unsigned char *b, struct custom_data *d, gboolean *err) { gint i, r = 0; d->num_matches = get16; b += 2; r += 2; for (i = 0; i < d->num_matches; i++) { gint t = get8; b++; r++; if (t != CD_MATCH) ERROR("Expected CD_MATCH, got %d", t); t = get8; b++; r++; if (t != CD_MATCH_COMP_1) ERROR("Expected CD_MATCH_COMP_1, got %d", t); gint ret = get_competitor(b, &(d->matches[i].c1), err); b += ret; r += ret; t = get8; b++; r++; if (t != CD_MATCH_COMP_2) ERROR("Expected CD_MATCH_COMP_2, got %d", t); ret = get_competitor(b, &(d->matches[i].c2), err); b += ret; r += ret; } LOG("num matches = %d", d->num_matches); return r; }
/* Function to get query the location of a competitor. */ void query_location(event_ptr event) { competitor *competitor; int number; printf("\nPlease enter in the competitor number you wish to query the location of: "); scanf("%d", &number); while ((competitor = get_competitor(event, number)) == NULL) { /* Check to make sure a valid competitor is entered. */ printf("\nPlease enter in a valid competitor number: "); scanf("%d", &number); } print_location(event, competitor); }
/* Function to get a manual input for the updating of a competitor's arrival at a time checkpoint. */ void update_competitor(event_ptr event) { int hours; int minutes; competitor *competitor; int number; int checkpoint; printf("\nPlease enter in the competitor number you wish to update: "); scanf("%d", &number); while ((competitor = get_competitor(event, number)) == NULL) { /* Check to make sure a valid competitor is entered. */ printf("\nPlease enter in a valid competitor number: "); scanf("%d", &number); } printf("\nPlease enter in the new checkpoint of the competitor: "); scanf("%d", &checkpoint); while (checkpoint > event->number_of_nodes || checkpoint < 1) { /* Check to make sure a valid status is entered. */ printf("\nPlease enter in a valid checkpoint between 1 and %d: ", event->number_of_nodes); scanf("%d", &checkpoint); } printf("\nPlease enter in the hour at which the competitor arrived (between 00 and 23) for a 24-hour clock: "); scanf("%02d", &hours); while (hours > 23 || hours < 00) { /* Check to make sure a valid number of hours is entered. */ printf("\nPlease enter in a valid hour between 00 and 23 for a 24-hour clock: "); scanf("%02d", &hours); } printf("\nPlease enter in the minutes at which the competitor arrived: "); scanf("%02d", &minutes); while (minutes > 60 || minutes < 00) { /* Check to make sure a valid number of minutes is entered. */ printf("\nPlease enter in a valid number of minutes between (00 and 60): "); scanf("%02d", &minutes); } if ((chronological_check(event->current_time, hours, minutes)) == SUCCESS) { if (competitor->status == NS) { printf("\nCompetitor %d has now started\n", competitor->number); } else { checkpoint_update(event, competitor, checkpoint, hours, minutes); /* Call to function that does the updating. */ } } else { printf("\n\nSorry but the manual update you are attempting is not in chronological order, updating process aborted.\n"); } }
/* Function to read in a file of times. */ void read_times_file(event_ptr event) { FILE *times_file; /* File pointer. */ char file_name[MAX_PATH_LENGTH]; int load_status; char status; int checkpoint; int competitor_number; int hours; int minutes; competitor *competitor; do { printf("\n\nPlease enter in the file path and name of the time file to be loaded: "); scanf("%s", file_name); if ((times_file = fopen(file_name, "r")) == NULL) { /* Open file with read permissions only and check file opened. */ printf("Please enter in a valid file path and name.\n"); } } while (times_file == NULL); do { load_status = fscanf(times_file, " %c %d %d %d:%d", &status, &checkpoint, &competitor_number, &hours, &minutes); if (load_status == EOF) { printf("\nEnd of file reached."); } else if (load_status == 5) { if ((chronological_check(event->current_time, hours, minutes)) == SUCCESS) { competitor = get_competitor(event, competitor_number); checkpoint_update(event, competitor, checkpoint, hours, minutes); } else { load_status = FAILURE; } } else { printf("Error reading in time file, possible pattern mismatch.\n"); } } while (load_status != EOF && load_status == 5 && load_status != FAILURE); if (load_status == EOF) { fclose(times_file); printf("\nLoading of times files complete.\n"); } else if (load_status == FAILURE) { printf("\nFile has not arrived in chronological order, permission to read in file denied.\n"); fclose(times_file); } else if (load_status != 5) { printf("Error reading in time file, possible pattern mismatch.\n"); fclose(times_file); } }
static gint get_rr_pool(unsigned char *b, round_robin_bare_t *pool, gboolean *err) { gint r = 0, i; gint ret = get_string(b, pool->name); b += ret; r += ret; LOG("POOL NAME = %s", pool->name); gint t = get8; b++; r++; if (t != CD_RR_POOL_NUM_MATCHES) ERROR("Expected CD_RR_POOL_NUM_MATCHES, got %d", t); pool->num_rr_matches = get16; b += 2; r += 2; for (i = 0; i < pool->num_rr_matches; i++) { t = get8; b++; r++; if (t == CD_RR_POOL_MATCH) { pool->rr_matches[i] = get16; b += 2; r += 2; LOG("rr match %d: %d", i, pool->rr_matches[i]); } else ERROR("Expected CD_RR_POOL_MATCH, got %d", t); } t = get8; b++; r++; if (t != CD_RR_POOL_NUM_COMPETITORS) ERROR("Expected CD_RR_POOL_NUM_COMPETITORS, got %d", t); pool->num_competitors = get16; b += 2; r += 2; for (i = 0; i < pool->num_competitors; i++) { t = get8; b++; r++; if (t == CD_COMP) { gint ret = get_competitor(b, &pool->competitors[i], err); b += ret; r += ret; } else ERROR("Expected CD_COMP, got %d", t); } LOG("num rr matches = %d, num comps = %d", pool->num_rr_matches, pool->num_competitors); return r; }