Subversion Repositories svn1

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1 root 1
/*************************************************************************
2
*           Copyright (C) 1995 Embedded Solutions
3
*                       All rights reserved
4
*
5
* file:     src\report.c
6
*
7
* purpose:  PREFIX -
8
*
9
* functions
10
*       report                  - Report menu
11
*       pri_team                - Print in team order
12
*       pri_leg                 - Print in given leg finishing time
13
*       p_place                 - Print place information
14
*       p_team                  - Print team information
15
*       pri_eleg                - Print on elapsed times for given leg
16
*       pe_place                - Print place and elapsed time information
17
*       pe_team                 - Print team and elapsed time information
18
*       pri_final               - Print final results
19
*       pri_interim             - Print interim results
20
*       print_class_header      - Print a class header
21
*       print_class_stats       - Generate the class stats
22
*       print_legend            - Print the legend
23
*       pi_place                - Return place data
24
*       pr_place                - Return place data
25
*       ck_data                 - Check data for bad times
26
*       srt_place               - Update placing information
27
*       do_big_sort             - Main sort routine for final data
28
*       sort                    - Sort in memory buffer
29
*       sort_comp               - qsort comparison function
30
*       load                    - load report data into memory
31
*       gen_stats               - Generate all the stats
32
*
33
* programmer: David Purdie
34
*
35
* revision  date        by      reason
36
*    e388   11-Oct-88           Option in the final printout to only
37
*                               produce the main result sheet. The leg
38
*                               placing printout is not produced.
39
*
40
*                               Changes to the display format of unknown
41
*                               times of disqualified teams. Only affects
42
*                               the leg-printouts.
43
*                               Disqualified teams show as -- -- --
44
*                               Otherwise they show as     ** ** **
45
*                               or a valid time.
46
*
47
*   e339    31-Oct-88   DDP     Added the "Interim Report" facility
48
*   00.0    27/01/95    DDP     Tidies up the program and formatted the file
49
*   00.1    06-sep-02   DDP     Added support for HTML report generation
50
*
51
**************************************************************************/
52
 
53
#include    <stdio.h>
54
#if defined(HI_TECH_C) || defined(__TURBOC__)
55
#include    <alloc.h>
56
#endif
57
#include    "consts.h"
58
#include    "structs.h"
59
#include    "proto.h"
60
 
61
void pri_awards(void);
62
void pri_master_index(void);
63
char *placing ( int place );
18 david 64
void pri_name_index(void);
65
void pri_name_index_body( void );
29 - 66
void pri_all_reports (void );
67
void pri_leg_body(int leg);
68
void pri_eleg_body(int leg);
1 root 69
 
70
 
71
menu_table  rpt_menu[] = {
72
    { '1', "Print team order", pri_team },
73
    { '2', "Print end leg times", pri_leg },
74
    { '3', "Print elapsed leg times", pri_eleg },
75
    { '4', "Print final results", pri_final },
76
    { '5', "Print final results(All-HTML)", pri_final_html },
77
    { '6', "Print Interim results", pri_interim },
78
    { '7', "Update event and class placings", srt_place },
79
    { '8', "Display summary information", display_summary },
13 david 80
    { '9', "Print summary information", pri_summary },
1 root 81
    { 'a', "Print Awards only", pri_awards },
82
    { 'b', "Print Master Index only", pri_master_index },
18 david 83
    { 'c', "Print Name Index only", pri_name_index },
29 - 84
    { 'z', "Print all reports", pri_all_reports },
85
 
1 root 86
#if defined(HI_TECH_C) || defined(__TURBOC__)
87
    { 'S', "MS-DOS system", ms_system },
88
#endif
89
    { 'q', "Return to main menu", 0 },
90
    { '\0' }
91
};
92
 
93
#define MAX_PLACE 11
94
char * place_text[] =
95
{
96
    "Zero'th",
97
    "First",
98
    "Second",
99
    "Third",
100
    "Fourth",
101
    "Fifth",
102
    "Sixth",
103
    "Seventh",
104
    "Eighth",
105
    "Ninth",
106
    "Tenth",
107
    "Eleventh"
108
};
109
 
110
int         sort_leg;
111
int         sort_mode;
112
bool        report_html = FALSE;
29 - 113
bool        report_all = FALSE;
1 root 114
 
115
/* Parameters used by the sort routine to govern its actions */
116
 
117
#define S_L     1                                /* Elasped times */
118
#define S_LE    2                                /* Leg end time */
119
#define S_LC    3                                /* Elapsed times per class */
120
#define S_LEC   4                                /* Leg end time per class */
121
#define S_FIN   5                                /* Sort on finish time at given leg */
122
#define S_TEAM  6                                /* Sort on team order */
123
#define S_CLASS 7                                /* Sort on class/team order */
124
 
125
/*
126
**  Various checking modes
127
*/
128
#define C_ELAPSED   1                            /* Check elapsed times */
129
#define C_END       2                            /* Check end times */
130
#define C_DISQUAL   3                            /* Check disqualified teams */
131
 
132
/*
133
**  Data
134
*/
135
ty_s_data  *sort_data = 0;                       /* pointer to memory */
136
ty_s_aux   *sort_aux = 0;                        /* pointer to aux sort info */
18 david 137
ty_s_namedata *sort_name_data = 0;                /* pointer to name info */
1 root 138
unsigned    sort_num;                            /* Number in the array */
18 david 139
unsigned    sort_num_data;                       /* Number in the array */
1 root 140
 
141
/*
142
**  A structure to hold statistical information
143
*/
144
typedef struct
145
{
146
    int         team[MAX_LEGS + 1][MAX_CLASS + 1];
147
    struct
148
    {
149
        int     team[MAX_LEGS + 1][MAX_CLASS + 1];
150
        time_t  time[MAX_LEGS + 1][MAX_CLASS + 1];
151
    } fast;
152
    time_t      average[MAX_LEGS + 1][MAX_CLASS + 1];
153
} ty_stats;
154
 
155
ty_stats        stats;                           /* Holds statistics */
156
 
157
/*========================================================================
158
 *
159
 *  Report menu
160
 *
161
 *  Purpose:
162
 *      This function is called to produce the "Report Menu"
163
 *
164
 *  Parameters:
165
 *      None
166
 *
167
 *  Returns:
168
 *      Nothing
169
 *
170
 *========================================================================*/
171
 
172
void report(void)
173
{
174
    report_html = FALSE;
175
    if( load_report_data() )
176
        do_menu( "Report generation", "Select option", rpt_menu );
177
 
178
    if( sort_data )
179
        free( ( char * ) sort_data );
180
    if( sort_aux )
181
        free( ( char * ) sort_aux );
18 david 182
    if ( sort_name_data )
183
        free( ( char * ) sort_name_data );
1 root 184
    sort_data = ( ty_s_data * ) 0;
185
    sort_aux = ( ty_s_aux * ) 0;
18 david 186
    sort_name_data = ( ty_s_namedata * ) 0;
1 root 187
}
188
 
189
/*========================================================================
190
 *
191
 *  Print in team order
192
 *
193
 *  Purpose:
194
 *      This function is called to Print in team order
195
 *      This function may also be used to create an HTML suite of files
196
 *      within the result set
197
 *
198
 *  Parameters:
199
 *      None
200
 *
201
 *  Returns:
202
 *      Nothing
203
 *
204
 *========================================================================*/
205
 
206
void pri_team(void)
207
{
208
    int         i, k;
209
 
210
    cur( 0, 5 );
211
    printf( "Team information - in team order\n" );
212
    printf( "\nPrinting team names\n" );
213
    flush_out();
214
 
215
    if( !open_printer( "", "name", 132, report_html, "Team Names" ) )
216
        return;
217
 
218
    /*
219
     * Print out the data 
220
     * Print out the header
221
     */
222
 
223
    print( "\n" );
224
 
225
    print_underline( TRUE );
226
    print( "%-*s %-*s %-*s", MAX_TM_NAME + 5, "Entry number and name",
227
               LEN_CLASS_NAME, "Category",
228
               config.num_countries == 0 ? 1 : LEN_CNTRY_NAME,
229
               config.num_countries == 0 ? "" : "Country" );
230
    for( k = 0; k < MAX_MEMB; k++ )
231
    {
232
        print( " %-*s", MAX_PERSON_NAME, config.leg_name[k] ? config.leg_name[k] : "Competitor"  );
233
    }
234
    print_underline( FALSE ) ;
235
    print( "\n" );
236
 
237
    for( i = config.min_team; i <= config.max_team; i++ )
238
    {
239
        if( valid_field( i ) && g_record( i, &team_buf ) )
240
        {
241
            /*
242
            **  If printing an HTML report then we need to mark
243
            **  the entry with a reference so that we can link to it
244
            */
245
            if ( report_html )
246
            {
247
                print( "<A NAME=\"Team_%04d\">",team_buf.numb );
248
                print( "</A>" );
249
            }
250
 
251
            /*
252
            **  Basic information
253
            **      - Team number - with Xref back to full result
254
            **      - Full team name
255
            **      - Full categoray name - with Xref to category results
256
            **      - Country name
257
            */
258
            if ( report_html ) print( "<A HREF=\"%s#Team_%04d\">", p_filename(filebase, "finish" ,"html"), team_buf.numb );
259
            print( "%4d",       team_buf.numb );
260
            if ( report_html ) print( "</A>" );
261
 
262
            print( " %-*s ",     MAX_TM_NAME, team_buf.name );
263
 
264
            if ( report_html ) print( "<A HREF=\"%s#Team_%04d\">",p_filename(filebase, config.team_class[team_buf.class - 1].abr ,"html"), team_buf.numb );
265
            print( "%-*s",     LEN_CLASS_NAME, team_buf.class == 0 ? "" : config.team_class[team_buf.class - 1].full_name );
266
            if ( report_html ) print( "</A>" );
267
 
268
            print( " %-*s",     config.num_countries == 0 ? 1 : LEN_CNTRY_NAME,
269
                                config.num_countries == 0
270
                                || team_buf.country ==
271
 
272
 
273
            for( k = 0; k < MAX_MEMB; k++ )
274
                print( " %-*s", MAX_PERSON_NAME, team_buf.members[k].name );
275
 
276
            print( "\n" );
277
        }
278
    }
279
    close_printer();
280
}
281
 
18 david 282
/*========================================================================
283
 *
284
 *  Print in name order
285
 *
286
 *  Purpose:
287
 *      This function is called to print a list of all known competitors
288
 *      This function may also be used to create an HTML suite of files
289
 *      within the result set
290
 *
291
 *  Parameters:
292
 *      None
293
 *
294
 *  Returns:
295
 *      Nothing
296
 *
297
 *========================================================================*/
298
void pri_name_index( void )
299
{
300
    cur( 0, 5 );
301
    printf( "Team Member information - in name order\n" );
302
    printf( "\nPrinting competitor names\n" );
303
    flush_out();
304
    pri_name_index_body();
305
    printf( "Found %d names\n", sort_num_data );
306
    printf( "\nAny key to continue" );
307
    getinp();
308
}
1 root 309
 
310
/*========================================================================
311
 *
18 david 312
 *  Print in name order
313
 *
314
 *  Purpose:
315
 *      This function is called to print a list of all known competitors
316
 *      This function may also be used to create an HTML suite of files
317
 *      within the result set
318
 *
319
 *  Parameters:
320
 *      None
321
 *
322
 *  Returns:
323
 *      Nothing
324
 *
325
 *========================================================================*/
326
void pri_name_index_body( void )
327
{
328
    ty_s_namedata *ptr;
329
    unsigned    num;
330
    int i,k;
331
    int num_names;
332
 
333
    /*
334
    **  Determine the number of names to allow for
335
    *   Based on the total number of teams
336
    */
337
    num = config.max_team - config.min_team + 1 ;
338
    num *= MAX_MEMB;
339
 
340
    sort_name_data = ( ty_s_namedata * ) calloc ( num , sizeof( ty_s_namedata ) );
341
 
342
    if( sort_name_data == 0 )
343
    {
344
        printf( "\n\nError in allocating memory\n" );
345
        sleep( 5 );
346
        return;
347
    }
348
 
349
    /*
350
    **  Read all teams an extract name information
351
    */
352
    ptr = sort_name_data;
353
    for( i = config.min_team; i <= config.max_team; i++ )
354
    {
355
        if( valid_field( i ) && g_record( i, &team_buf ) )
356
        {
357
            num_names = 0;
358
            for( k = 0; k < MAX_MEMB; k++ )
359
            {
360
                if ( team_buf.members[k].name[0] )
361
                {
362
                    ptr->team = i;
363
                    ptr->leg = k;
364
                    ptr->class = team_buf.class;
365
                    strncpy( ptr->name,team_buf.members[k].name, sizeof(team_buf.members[k].name));
366
                    ptr++;
367
                    num_names++;
368
                }
369
            }
370
 
371
            if ( num_names == 0 )
372
            {
373
                ptr->team = i;
374
                ptr->leg = 0;
375
                ptr->class = team_buf.class;
376
                strncpy( ptr->name,team_buf.name, sizeof(team_buf.members[k].name));
377
                ptr++;
378
            }
379
 
380
        }
381
    }
382
    sort_num_data = ptr - sort_name_data;
383
 
384
    /*
385
    **  Now stort the entries by name:team:leg
386
    */
387
    qsort( ( char * ) sort_name_data, sort_num_data, sizeof( ty_s_namedata ), sort_comp_cname );
388
 
389
    /*
390
    **  Now generate the report
391
    */
392
 
393
    if( !open_printer( "", "competitor", 80, report_html, "Competitor Names" ) )
394
        return;
395
 
396
    /*
397
     * Print out the data 
398
     * Print out the header
399
     */
400
    print( "\n" );
401
 
402
    print_underline( TRUE );
403
    print( "%-*s %-*s %-*s %-*s", MAX_TM_NAME + 5, "Competitor name",
404
               6, "Leg",
405
               5, "Team",
406
               LEN_CLASS_NAME, "Category"
407
               );
408
    print_underline( FALSE ) ;
409
    print( "\n" );
410
 
411
    ptr = sort_name_data;
412
    for( k = 1; k <= sort_num_data; k++, ptr++ )
413
    {
414
        print( "%-*s", MAX_TM_NAME + 5, ptr->name );
415
        print( " " );
416
 
417
        if ( report_html ) print( "<A HREF=\"%s#Team_%04d\">", p_filename(filebase, "finish" ,"html"), ptr->team );
418
        print( "%-*d", 6, ptr->leg + 1 );
419
        if ( report_html ) print( "</A>" );
420
        print( " " );
421
 
422
        if ( report_html ) print( "<A HREF=\"%s#Team_%04d\">", p_filename(filebase, "name" ,"html"), ptr->team );
423
        print( "%-*d", 5, ptr->team );
424
        if ( report_html ) print( "</A>" );
425
        print( " " );
426
 
427
        if ( report_html ) print( "<A HREF=\"%s#Team_%04d\">",p_filename(filebase, config.team_class[ptr->class - 1].abr ,"html"), ptr->team );
428
        print( "%-*s", LEN_CLASS_NAME, ptr->class == 0 ? "" : config.team_class[ptr->class - 1].abr );
429
        if ( report_html ) print( "</A>" );
430
        print( " " );
431
 
432
        if ( ptr->multi ) print( "* ");
433
        print( "\n" );
434
    }
435
 
436
    print_legend( -1, 0 );
437
    close_printer();
438
 
439
}
440
 
441
/*========================================================================
442
 *
1 root 443
 *  Print in given leg finishing time
444
 *
445
 *  Purpose:
446
 *      This function is called to Print in given leg finishing time
447
 *
448
 *  Parameters:
449
 *      None
450
 *
451
 *  Returns:
452
 *      Nothing
453
 *
454
 *========================================================================*/
455
 
456
void pri_leg(void)
457
{
458
    int         leg = 0;
459
 
29 - 460
 
1 root 461
    /*
462
     * This function is used to provide interum print-outs
463
     * The team data is sorted by time at leg-end and the times printed are
464
     * real times at leg end.
465
     * This operation is designed to be quick - it doesn't update the disk file
466
     * and is not available in an HTML version - yet
467
     */
468
 
469
    cur( 0, 5 );
470
    printf( "Leg finishing time report\n" );
471
    while( TRUE )
472
    {
473
        d_field( 0, 7, "Enter leg to print :", D_NUMBER, 1, ( char * ) &leg,
474
                 TRUE, M_UPDATE );
475
        if( abort_flag )
476
            return;
477
        if( leg <= config.num_legs )
478
            break;
479
        beep();
480
    }
29 - 481
 
482
    pri_leg_body ( leg );
483
}
1 root 484
 
29 - 485
void pri_leg_body(int leg)    
486
{
487
    ty_s_data  *ptr;
488
    int         i, k;
1 root 489
    /*
490
     * Sort the data in finishing order 
491
     */
492
 
493
    printf( "\nSorting the data\n" );
494
    flush_out();
495
    if( ck_data( leg, C_END ) )
496
        return;                                  /* Check data for this leg */
497
    sort_team_data( leg, S_FIN );                /* Sort the data */
498
 
499
 
500
    /*
501
     * Now print the data on the printer 
502
     */
503
    if( !open_printer( "",
504
                        tprintf("lg%1.1d", leg ),
505
                        80,
506
                        report_html,
507
                        leg ? tprintf ("Finish order for Leg %d.", leg)
508
                            : "Final team finish order"
509
                     ) )
510
    {
511
        return;
512
    }
513
 
514
    /*
515
     * Print out the data 
516
     */
517
    print( "PRELIMINARY RESULTS ONLY\n\n" );
518
 
519
    print_underline( TRUE );
520
    print( "%4s %4s %-8s  ", "Plce", "Team", "Time" );
521
    print( "%4s %4s %-8s  ", "Plce", "Team", "Time" );
522
    print( "|" );
523
    print( "%4s %4s %-8s  ", "Team", "Plce", "Time" );
524
    print( "%4s %4s %-8s\n", "Team", "Plce", "Time" );
525
    print_underline( FALSE );
526
 
527
    for( ptr = sort_data, k = 0, i = config.min_team; i <= config.max_team; )
528
    {
529
        p_place( ptr++, leg, k++ );
530
        p_place( ptr++, leg, k++ );
531
        print( "|" );
532
        while( i <= config.max_team && !valid_field( i ) )
533
            i++;
534
        p_team( i++, leg );
535
        while( i <= config.max_team && !valid_field( i ) )
536
            i++;
537
        p_team( i++, leg );
538
        print( "\n" );
539
    }
540
 
32 - 541
    printf( "\n\n" );
542
    print_underline( TRUE );
543
    print( "%4s %4s %-8s  ", "Plce", "Team", "Time" );
544
//    print( "%4s %4s %-8s  ", "Plce", "Team", "Time" );
545
    print( "|" );
546
//    print( "%4s %4s %-8s  ", "Team", "Plce", "Time" );
547
    print( "%4s %4s %-8s\n", "Team", "Plce", "Time" );
548
    print_underline( FALSE );
549
 
550
    for( ptr = sort_data, k = 0, i = config.min_team; i <= config.max_team; )
551
    {
552
        p_place( ptr++, leg, k++ );
553
//        p_place( ptr++, leg, k++ );
554
        print( "|" );
555
        while( i <= config.max_team && !valid_field( i ) )
556
            i++;
557
        p_team( i++, leg );
558
//        while( i <= config.max_team && !valid_field( i ) )
559
//            i++;
560
//        p_team( i++, leg );
561
        print( "\n" );
562
    }
563
 
564
 
1 root 565
    /*
566
     * Insert the leg statistics 
567
     */
568
 
569
    gen_stats();                               /* Generate all stats */
570
    print( "\nLeg statistics\n" );
571
    print( "Fastest team: %4d time : %s.",
572
           stats.fast.team[leg][0], time_a( stats.fast.time[leg][0] ) );
573
    print( " Average time: %s\n", time_a( stats.average[leg][0] ) );
574
 
575
    close_printer();
576
}
577
 
578
/*========================================================================
579
 *
580
 *  Print place information
581
 *
582
 *  Purpose:
583
 *      This helper function is called to Print place information
584
 *      in a 20-character field
585
 *
586
 *  Parameters:
587
 *      ptr         Address of the place data
588
 *      leg         Leg to print
589
 *      k           Current index into sorted array. Simply
590
 *                  used to determine if the entry is valid
591
 *                  or if it should be space-filled
592
 *
593
 *  Returns:
594
 *      Nothing
595
 *
596
 *========================================================================*/
597
 
598
void p_place( ty_s_data * ptr, int leg, unsigned k )
599
{
600
    if( k < sort_num )
601
    {
602
        print( "%4.4s %4d %8s  ",
603
               pr_place( ptr->place, ptr->flags.bad_times ),
604
               ptr->team, time_fa( ptr->leg[leg], ptr->flags.disqualified ) );
605
    }
606
    else
607
    {
608
        print( "%20s", "" );
609
    }
610
}
611
 
612
/*========================================================================
613
 *
614
 *  Print team information
615
 *
616
 *  Purpose:
617
 *      This helper function is called to Print team information
618
 *      in a 20-character field
619
 *
620
 *  Parameters:
621
 *      i           team to print
622
 *      leg         Leg to print
623
 *
624
 *  Returns:
625
 *      Nothing
626
 *
627
 *========================================================================*/
628
 
629
void p_team( int i, int leg )
630
{
631
    ty_s_data  *ptra;                            /* Pointer to sort data */
632
    int         found = FALSE;
633
    unsigned    j;
634
 
635
    if( valid_field( i ) )
636
    {
637
        ptra = sort_data;
638
        for( j = 1; j <= sort_num; j++, ptra++ )
639
            if( i == ptra->team )
640
            {
641
                found = TRUE;
642
                break;
643
            }
644
    }
645
    if( found )
646
    {
647
        print( "%4d %4.4s %8s  ",
648
               ptra->team,
649
               pr_place( ptra->place, ptra->flags.bad_times ),
650
               time_fa( ptra->leg[leg], ptra->flags.disqualified ) );
651
    }
652
    else
653
    {
654
        print( "%20s", "" );
655
    }
656
}
657
 
658
/*========================================================================
659
 *
660
 *  Print on elapsed times for given leg
661
 *
662
 *  Purpose:
663
 *      This function is called to Print on elapsed times for given leg
664
 *
665
 *  Parameters:
666
 *      None
667
 *
668
 *  Returns:
669
 *      Nothing
670
 *
671
 *========================================================================*/
672
 
673
void pri_eleg(void)
674
{
675
    int         leg = 0;
676
 
29 - 677
 
1 root 678
    /*
679
     * This function is used to provide interum print-outs
680
     * The team data is sorted by time at leg-elapsed and the times printed are
681
     * real times at leg end.
682
     * This operation is designed to be quick - it doesn't update the disk file
683
     * and is not available in an HTML version - yet
684
     */
685
 
686
    cur( 0, 5 );
687
    printf( "Leg elapsed time report\n" );
688
    while( TRUE )
689
    {
690
        d_field( 0, 7, "Enter leg to print :", D_NUMBER, 1, ( char * ) &leg,
691
                 TRUE, M_UPDATE );
692
        if( abort_flag )
693
            return;
694
        if( leg <= config.num_legs )
695
            break;
696
        beep();
697
    }
29 - 698
    pri_eleg_body(leg);
699
}
1 root 700
 
29 - 701
 
702
void pri_eleg_body( int leg)
703
{
704
    ty_s_data  *ptr;
705
    int         i, k;
32 - 706
 
1 root 707
    /*
708
     * Sort the data in finishing order 
709
     */
710
 
711
    printf( "\nSorting the data\n" );
712
    flush_out();
713
    if( ck_data( leg, C_ELAPSED ) )
714
        return;                                  /* Check data for this leg */
715
    sort_team_data( leg, S_L );                  /* Sort the data on elapsed time */
716
 
717
 
718
    /*
719
     * Now print the data on the printer 
720
     */
721
    if( !open_printer( "", tprintf( "le%1.1d", leg ),
722
                       80,
723
                       report_html,
724
                       leg ? tprintf( "Elapsed time order for Leg %d.", leg )
725
                           : tprintf( "Final elapsed team finishing order." )
726
                     ) )
727
    {
728
        return;
729
    }
730
 
731
    /*
732
     * Print out the data 
733
     */
734
    print( "PRELIMINARY RESULTS ONLY\n\n" );
735
 
736
    print_underline( TRUE );
737
    print( "%4s %4s %-8s  ", "Plce", "Team", "Time" );
738
    print( "%4s %4s %-8s  ", "Plce", "Team", "Time" );
739
    print( "|" );
740
    print( "%4s %4s %-8s  ", "Team", "Plce", "Time" );
741
    print( "%4s %4s %-8s\n", "Team", "Plce", "Time" );
742
    print_underline( FALSE );
32 - 743
 
1 root 744
 
745
    for( ptr = sort_data, k = 0, i = config.min_team; i <= config.max_team; )
746
    {
747
        pe_place( ptr++, leg, k++ );
748
        pe_place( ptr++, leg, k++ );
749
        print( "|" );
750
        while( i <= config.max_team && !valid_field( i ) )
751
            i++;
752
        pe_team( i++, leg );
753
        while( i <= config.max_team && !valid_field( i ) )
754
            i++;
755
        pe_team( i++, leg );
756
        print( "\n" );
757
    }
758
 
32 - 759
    print( "\n\n" );
760
    print_underline( TRUE );
761
    print( "%4s %4s %-8s  ", "Plce", "Team", "Time" );
762
//    print( "%4s %4s %-8s  ", "Plce", "Team", "Time" );
763
    print( "|" );
764
//    print( "%4s %4s %-8s  ", "Team", "Plce", "Time" );
765
    print( "%4s %4s %-8s\n", "Team", "Plce", "Time" );
766
    print_underline( FALSE );
767
 
768
 
769
    for( ptr = sort_data, k = 0, i = config.min_team; i <= config.max_team; )
770
    {
771
        pe_place( ptr++, leg, k++ );
772
//        pe_place( ptr++, leg, k++ );
773
        print( "|" );
774
        while( i <= config.max_team && !valid_field( i ) )
775
            i++;
776
        pe_team( i++, leg );
777
//        while( i <= config.max_team && !valid_field( i ) )
778
//            i++;
779
//        pe_team( i++, leg );
780
        print( "\n" );
781
    }
782
 
783
 
1 root 784
    /*
785
     * Insert the leg statistics 
786
     */
787
 
788
    gen_stats();                               /* Generate all stats */
789
    print( "\nLeg statistics\n" );
790
    print( "Fastest team: %4d time : %s.",
791
           stats.fast.team[leg][0], time_a( stats.fast.time[leg][0] ) );
792
    print( " Average time: %s\n", time_a( stats.average[leg][0] ) );
793
 
794
    close_printer();
795
}
796
 
797
/*========================================================================
798
 *
799
 *  Print place information
800
 *
801
 *  Purpose:
802
 *      This helper function is called to Print place and elapsed information
803
 *      in a 20-character field
804
 *
805
 *  Parameters:
806
 *      ptr         Address of the place data
807
 *      leg         Leg to print
808
 *      k           Current index into sorted array. Simply
809
 *                  used to determine if the entry is valid
810
 *                  or if it should be space-filled
811
 *
812
 *  Returns:
813
 *      Nothing
814
 *
815
 *========================================================================*/
816
 
817
void pe_place( ty_s_data * ptr, int leg, unsigned k )
818
{
819
    if( k < sort_num )
820
    {
821
        print( "%4.4s %4d %8s  ",
822
               pr_place( ptr->place, ptr->flags.bad_times ),
823
               ptr->team,
824
               time_fa( ptr->lege[leg], ptr->flags.disqualified ) );
825
    }
826
    else
827
    {
828
        print( "%20s", "" );
829
    }
830
}
831
 
832
/*========================================================================
833
 *
834
 *  Print team information
835
 *
836
 *  Purpose:
837
 *      This helper function is called to Print team and elapsed time
838
 *      information
839
 *      in a 20-character field
840
 *
841
 *  Parameters:
842
 *      i           Team to print
843
 *      leg         Leg to print
844
 *
845
 *  Returns:
846
 *      Nothing
847
 *
848
 *========================================================================*/
849
 
850
void pe_team( int i, int leg )
851
{
852
    ty_s_data  *ptra;                            /* Pointer to sort data */
853
    int         found = FALSE;
854
    unsigned    j;
855
 
856
    if( valid_field( i ) )
857
    {
858
        ptra = sort_data;
859
        for( j = 1; j <= sort_num; j++, ptra++ )
860
            if( i == ptra->team )
861
            {
862
                found = TRUE;
863
                break;
864
            }
865
    }
866
    if( found )
867
    {
868
        print( "%4d %4.4s %8s  ",
869
               ptra->team,
870
               pr_place( ptra->place, ptra->flags.bad_times ),
871
               time_fa( ptra->lege[leg], ptra->flags.disqualified ) );
872
    }
873
    else
874
    {
875
        print( "%20s", "" );
876
    }
877
}
878
 
879
/*========================================================================
880
 *
881
 *  Print final results in HTML
882
 *
883
 *  Purpose:
884
 *      This function is called to Print final results with HTML formatting
885
 *      All result files are created
886
 *
887
 *  Parameters:
888
 *      None
889
 *
890
 *  Returns:
891
 *      Nothing
892
 *
893
 *========================================================================*/
894
 
895
void pri_final_html(void)
896
{
897
    /*
898
    **  Generate ALL results with HTML tags
899
    */
900
    report_html = TRUE;
901
    pri_final();
902
    report_html = FALSE;
903
}
904
 
905
 
906
/*========================================================================
907
 *
908
 *  Print final results
909
 *
910
 *  Purpose:
911
 *      This function is called to Print final results
912
 *
913
 *  Parameters:
914
 *      None
915
 *
916
 *  Returns:
917
 *      Nothing
918
 *
919
 *========================================================================*/
920
 
921
void pri_final(void)
922
{
923
    ty_s_data  *ptr;
924
    unsigned    i;
925
    int         j, last_class;
926
    char        suppress_classes;                /* Boolean. Printout class files too */
927
    char        *report_title;
928
 
929
    cur( 0, 5 );
930
    printf( "Generate final result printouts\n" );
931
    if( ck_data( -1, C_ELAPSED ) )
932
        return;                                  /* check data for all legs */
933
 
934
    /*
935
    **  If a non HTML report then ask if the user want to supress the class
936
    **  printout. For an HTML report always do the class reports as the two
937
    **  are interlinked
938
    */
29 - 939
    if ( ! report_html  && ! report_all)
1 root 940
    {
941
        suppress_classes = getyes( "Do you want to suppress class printouts" );
942
    }
943
    else
944
    {
945
        suppress_classes = FALSE;
946
    }
947
 
948
    /*
949
    **  Sort on every thing
950
    **  Then generate all the stats too
951
    */
952
    printf( "\nSorting the data\n" );
953
    do_big_sort();
954
    gen_stats();
955
 
956
    /*
957
     * Now print the data on the printer 
958
     */
959
    printf( "\nGenerating the printed output\n" );
960
    if( !open_printer( "", "finish", 132, report_html, "Finishing Order" ) )
961
        return;
962
 
963
    /*
964
     * Print out the data 
965
     */
966
    print_class_header( -1, TRUE );                      /* Print the header */
967
 
968
    ptr = sort_data;
969
    sort_team_data( 0, S_L );                     /* Re-sort on elapsed time */
970
    for( ptr = sort_data, i = 0; i < sort_num; i++, ptr++ )
971
    {
972
        if ( ptr->class == config.nonequestrian_class )
973
            continue;
974
 
975
        g_record( ptr->team, &team_buf );
976
 
977
        /*
978
        **  If printing an HTML report then we need to mark
979
        **  the entry with a reference so that we can link to it
980
        */
981
        if ( report_html )
982
        {
983
            print( "<A NAME=\"Team_%04d\"></A>",team_buf.numb );
984
        }
985
 
986
        /*
987
        **  Print the basics
988
        **      - Place within complete field
989
        **      - Team number - with HTML reference to team file
990
        **      - Class
991
        */
992
        print( "%4.4s ", pr_place( team_buf.leg[0].l_place, ptr->flags.bad_times ) );
993
        if ( report_html ) print( "<A HREF=\"%s#Team_%04d\">", p_filename(filebase, "name" ,"html"), team_buf.numb );
994
        print( "%4d",  team_buf.numb );
995
        if ( report_html ) print( "</A>" );
996
 
997
        print( " %-*s", 3, team_buf.class == 0 ? "" : config.team_class[team_buf.class - 1].abr );
998
 
999
        /*
1000
        **  Print the per-leg data
1001
        **      - Time
1002
        **      - Leg place
1003
        **      - End place
1004
        */
1005
        for( j = 1; j <= config.num_legs; j++ )
1006
        {
13 david 1007
            /*
1008
            **  Ensure that non-equestrian leg data is not displayed
1009
            */
1010
            if ( j == config.equestrian_leg && team_buf.flags.non_equestrian )
1011
            {
1012
                print( "  %-8s %4.4s %4.4s", "-- NE --", "-","-");
1013
            }
1014
            else
1015
            {
1016
                print( "  %-8s %4.4s %4.4s",
1 root 1017
                    time_a( team_buf.leg[j].elapsed ),
1018
                    pr_place( team_buf.leg[j].l_place, ptr->flags.bad_times ),
1019
                    pr_place( team_buf.leg[j].le_place,ptr->flags.bad_times )
1020
                  );
13 david 1021
            }
1 root 1022
        }
1023
 
24 - 1024
       /*
1 root 1025
        **  Print the trailer
1026
        **      - Total time
1027
        **      - Category place - with reference to category file
1028
        */
1029
        print( "  %-8s ",  time_a( team_buf.leg[0].elapsed ) );
1030
        if ( report_html ) print( "<A HREF=\"%s#Team_%04d\">",p_filename(filebase, config.team_class[team_buf.class - 1].abr ,"html"), team_buf.numb );
1031
        print( "%-4.4s", pr_place( team_buf.leg[0].lc_place, ptr->flags.bad_times ) );
1032
        if ( report_html ) print( "</A>" );
1033
 
1034
        print( "\n" );
1035
    }
1036
 
1037
    print_class_stats( -1, TRUE );              /* Print statistics */
18 david 1038
    print_legend(-1, 1 );                       /* Print the legend */
1 root 1039
    close_printer();                            /* Close the printer */
1040
 
1041
    /*
1042
     * Now produce a breakdown on a class by class basis 
1043
     * Now print out the class placement information
1044
     */
1045
 
1046
    if( suppress_classes )
1047
    {
1048
        printf( "WARNING: Class printouts suppressed\n" );
1049
        return;
1050
    }
1051
 
1052
    sort_team_data( 0, S_LC );                 /* Generate class placement data */
1053
    last_class = -1;                           /* Invalid class to start with */
1054
 
1055
    for( ptr = sort_data, i = 0; i < sort_num; i++, ptr++ )
1056
    {
1057
        /*
1058
        **  Detect a change in the "class"
1059
        **  All data is within the one array of data
1060
        **  Use the in-memory class as this MAY differ from that stored
1061
        **  The non-equestrian class does this.
1062
        */
1063
        if( last_class != ptr->class )
1064
        {
1065
            if( last_class >= 0 )
1066
            {
1067
                print_class_stats( last_class, TRUE );
18 david 1068
                print_legend( last_class, 1 );
1 root 1069
                close_printer();
1070
            }
1071
 
1072
            report_title = tprintf( "Category results for : %-*s", LEN_CLASS_NAME, ptr->class == 0 ? "" : config.team_class[ptr->class - 1].full_name );
1073
 
1074
            if( !open_printer( "", config.team_class[ptr->class - 1].abr, 132, report_html, report_title ) )
1075
                continue;
1076
            print_class_header( last_class = ptr->class, TRUE );
1077
        }
1078
 
1079
        /*
1080
        **  Now read in the team record
1081
        */
1082
        g_record( ptr->team, &team_buf );
1083
 
1084
        /*
1085
        **  If printing an HTML report then we need to mark
1086
        **  the entry with a reference so that we can link to it
1087
        */
1088
        if ( report_html )
1089
            print( "<A NAME=\"Team_%04d\"></A>",team_buf.numb );
1090
 
1091
        /*
1092
        **  Print the basics
1093
        **      - Place within the class
1094
        **      - Team number - with HTML reference to team file
1095
        **      - Class
1096
        */
1097
 
1098
        print( "%4.4s ", pr_place( team_buf.leg[0].lc_place, ptr->flags.bad_times ) );
1099
        if ( report_html ) print( "<A HREF=\"%s#Team_%04d\">", p_filename(filebase, "name" ,"html"), team_buf.numb );
1100
        print( "%4d",  team_buf.numb );
1101
        if ( report_html ) print( "</A>" );
1102
        print( " %-*s", 3, team_buf.class == 0 ? "" : config.team_class[team_buf.class - 1].abr );
1103
 
1104
        for( j = 1; j <= config.num_legs; j++ )
1105
        {
1106
            /*
1107
            **  Ensure that non-equestrian leg data is not displayed
1108
            */
1109
            if ( j == config.equestrian_leg && ptr->class == config.nonequestrian_class)
1110
            {
13 david 1111
                print( "  %-8s %4.4s %4.4s", "-- NE --", "-","-");
1 root 1112
            }
1113
            else
1114
            {
1115
                print( "  %-8s %4.4s %4.4s", time_a( team_buf.leg[j].elapsed ),
1116
                       pr_place( team_buf.leg[j].lc_place, ptr->flags.bad_times ),
1117
                       pr_place( team_buf.leg[j].lec_place, ptr->flags.bad_times ) );
1118
            }
1119
        }
1120
 
1121
        /*
1122
        **  Print the trailer
1123
        **      - Total time
1124
        **      - Overall place - with reference to overall place file
1125
        */
1126
        /* print( "  %-8s ", time_a( team_buf.leg[0].elapsed ) ); */
1127
        print( "  %-8s ", time_a( ptr->lege[0] ) );
1128
 
1129
        if ( report_html ) print( "<A HREF=\"%s#Team_%04d\">", p_filename(filebase, "finish" ,"html"), team_buf.numb );
1130
        print( "%4.4s", pr_place( team_buf.leg[0].l_place, ptr->flags.bad_times | (ptr->class == config.nonequestrian_class) ) );
1131
        if ( report_html ) print( "</A>" );
1132
 
1133
        print( "\n" );
1134
    }
1135
 
1136
    print_class_stats( last_class, TRUE );
18 david 1137
    print_legend(last_class,1);
1 root 1138
    close_printer();
1139
 
1140
 
1141
    /*
1142
    **  If we are generating an HTML report then we need to create the file
1143
    **  that contains all the team names - the assumption is that this data
1144
    **  is available
1145
    */
1146
    if ( report_html )
1147
    {
1148
        pri_team();
1149
    }
1150
 
1151
    /*
1152
    **  Generate the awards report.
1153
    **  This is only available as an HTML report
1154
    */
1155
    if ( report_html )
1156
    {
1157
        pri_awards();
1158
    }
1159
 
1160
    /*
1161
    **  Generate the master index page
1162
    */
1163
    if ( report_html )
1164
    {
1165
        pri_master_index();
1166
    }
1167
 
18 david 1168
    pri_name_index_body();
1169
 
1 root 1170
}
1171
 
1172
/*========================================================================
1173
 *
1174
 *  Place to text
1175
 *
1176
 *  Purpose:
1177
 *      This function is called to convert a place to text
1178
 *
1179
 *  Parameters:
1180
 *      place
1181
 *
1182
 *  Returns:
1183
 *      text
1184
 *
1185
 *========================================================================*/
1186
 
1187
char *placing ( int place )
1188
{
1189
    if ( place > MAX_PLACE )
1190
    {
1191
        return tprintf( "Place: %d", place);
1192
    }
1193
    return tprintf ("%s Place", place_text[place]);
1194
}
1195
 
1196
/*========================================================================
1197
 *
1198
 *  Print award results
1199
 *
1200
 *  Purpose:
1201
 *      This function is called to Print award results
27 - 1202
 *      Keep the page to 80 cols, so that it can be pronted on A4
1 root 1203
 *
1204
 *  Parameters:
1205
 *      None
1206
 *
1207
 *  Returns:
1208
 *      Nothing
1209
 *
1210
 *========================================================================*/
1211
void pri_awards(void)
1212
{
1213
    int j;
1214
    int i;
1215
    int k;
1216
    int windex;
1217
    ty_s_data  *ptr;
1218
    int         last_class;
1219
 
1220
    report_html = 1;
27 - 1221
    if( !open_printer( "", "awards", 80, report_html, "Prizes and Awards" ) )
1 root 1222
        return;
1223
 
1224
    /*
1225
    **  Generate an index for this page
1226
    */
1227
    print( "\n");
1228
    print( "<hr>" );
1229
    print( "<A NAME=\"%s\"></A>","INDEX");
1230
    print( "Award Categories");
1231
 
1232
    for( j = 1; j <= config.num_class; j++ )
1233
    {
1234
        /*
1235
        **  Header for the class
1236
        */
1237
        if ( config.class_winners[j-1] <= 0 )
1238
            continue;
1239
 
1240
        print( "\n");
1241
        print( "    <A HREF=\"#%s\">",config.team_class[j-1].full_name);
1242
        print( "%s",  config.team_class[j-1].full_name );
1243
        print( "</A>" );
1244
    }
1245
 
1246
    /*
1247
    **  Manual entries
1248
    */
1249
    print( "\n");
1250
    print( "    <A HREF=\"#%s\">","Hall Of Fame");
1251
    print( "%s",  "Hall Of Fame" );
1252
    print( "</A>" );
1253
 
1254
    print( "\n");
1255
    print( "    <A HREF=\"#%s\">","FASTEST");
1256
    print( "%s",  "FASTEST" );
1257
    print( "</A>" );
1258
 
1259
    /*
1260
    **  Sort the data by class
1261
    */
1262
    sort_team_data( 0, S_LC );      /* Generate class placement data */
1263
    last_class = -1;                /* Invalid class to start with */
1264
 
1265
    /*
1266
    **  Process each category
1267
    */
1268
    for( j = 1; ; j++ )
1269
    {
1270
        /*
1271
        **  Tail for previous entry
1272
        */
1273
        if ( j != 1 )
1274
            print( "<A HREF=\"#%s\">Awards Index</A>","INDEX");
1275
 
1276
        if ( j > config.num_class  )
1277
            break;
1278
 
1279
        /*
1280
        **  Header for the class
1281
        */
1282
        print( "\n");
1283
        print( "<hr>" );
1284
        print( "<A name=\"%s\"></A>",config.team_class[j-1].full_name);
1285
        print( "<A HREF=\"%s\">",p_filename(filebase, config.team_class[j - 1].abr ,"html"));
1286
        print( "%s",  config.team_class[j-1].full_name );
1287
        print( "</A>" );
1288
 
1289
                if ( config.class_winners[j-1] <= 0 )
1290
        {
1291
            print( "\n");
1292
            print( "No winners awarded" );
1293
            continue;
1294
        }
1295
 
1296
        /*
1297
        **  Enties for 'n' the best teams as configured
1298
        */
1299
        windex = 0;                     /* Winners done */
1300
        for( ptr = sort_data, i = 0; i < sort_num; i++, ptr++ )
1301
        {
1302
            if ( ptr->class != j )
1303
            {
1304
                continue;
1305
            }
1306
 
1307
            /*
1308
            **  Now read in the team record
1309
            */
1310
            if( valid_field( ptr->team ) && g_record( ptr->team, &team_buf ) )
1311
            {
1312
                windex++;
1313
 
1314
                /*
1315
                **  If printing an HTML report then we need to mark
1316
                **  the entry with a reference so that we can link to it
1317
                */
1318
                print( "\n");
1319
                print( "<A NAME=\"Team_%04d\">",team_buf.numb );
1320
                print( "</A>" );
1321
 
1322
                /*
1323
                **  Basic information
1324
                **      - Team number - with Xref back to full result
1325
                **      - Full team name
1326
                **      - Full categoray name
1327
                */
1328
                print( "%s", placing(windex) );
1329
 
1330
                print( "  Team Name: <A HREF=\"%s#Team_%04d\">", p_filename(filebase, "name" ,"html"), team_buf.numb );
1331
                print( "%-*s ",     MAX_TM_NAME, team_buf.name );
1332
                print( "</A>" );
1333
 
1334
                print( "  Number: <A HREF=\"%s#Team_%04d\">", p_filename(filebase, "finish" ,"html"), team_buf.numb );
1335
                print( "%4d",       team_buf.numb );
1336
                print( "</A>" );
1337
 
1338
 
1339
                for( k = 0; k < MAX_MEMB; k++ )
1340
                {
1341
 
1342
                    /*
1343
                    **  Skip equestrian leg in the non-equestion display
1344
                    */
1345
                    if ( k + 1 == config.equestrian_leg && ptr->class == config.nonequestrian_class)
1346
                        continue;
1347
 
1348
                    print( "\n");
1349
                    print( "    ");
1350
                    print( "%-*s", MAX_PERSON_NAME, config.leg_name[k] ? config.leg_name[k] : "Competitor"  );
1351
                    print( " %-*s", MAX_PERSON_NAME, team_buf.members[k].name );
1352
 
1353
                    print( "  %-8s", time_a( team_buf.leg[k+1].elapsed ) );
1354
                }
1355
 
1356
                print( "\n");
1357
                print( "    ");
1358
                print_bold( TRUE );
1359
                print( "%-*s %-*s  %-8s", MAX_PERSON_NAME , "Total" ,MAX_PERSON_NAME, "",time_a( team_buf.leg[0].elapsed ) );
1360
                print_bold( FALSE );
1361
                print( "\n" );
1362
            }
1363
 
1364
 
1365
            /*
1366
            **  More to do
1367
            */
1368
            if ( windex >= config.class_winners[j-1] )
1369
            {
1370
                break;
1371
            }
1372
        }
1373
    }
1374
 
1375
    /*
1376
    **  Generate the Hall of Fame information
1377
    */
1378
    print( "\n");
1379
    print( "<hr>" );
1380
    print( "<A name=\"%s\"></A>","Hall Of Fame");
1381
    print( "%s",  "Hall of Fame" );
1382
 
1383
    if ( config.num_fame  )
1384
    {
1385
        for( i = 1; i <= config.num_fame; i++ )
1386
        {
1387
            print( "\n    %-*s", MAX_PERSON_NAME, config.hall_fame[i-1] );
1388
        }
1389
    }
1390
    else
1391
    {
1392
        printf( "\n    There are no new stars for the Hall of Fame");
1393
    }
1394
    print( "<p><A HREF=\"#%s\">Awards Index</A>","INDEX");
1395
 
1396
    /*
1397
    **  Generate the FASTEST information
1398
    */
1399
    print( "<hr>" );
1400
    print( "<A name=\"%s\"></A>","FASTEST");
1401
    print( "%s",  "FASTEST" );
1402
 
1403
    /*
1404
    **  Sort the data and then generate the stats - again
1405
    */
1406
    do_big_sort();
1407
    gen_stats();
1408
 
1409
    for( i = 1; i <= config.num_legs; i++ )
1410
    {
1411
        g_record( stats.fast.team[i][0], &team_buf );
1412
 
1413
        print( "\n");
1414
        print( "    %-13s ", config.leg_name[i - 1] );
17 david 1415
        print( "  Name: <A HREF=\"%s#Team_%04d\">", p_filename(filebase, "name" ,"html"), team_buf.numb );
1 root 1416
        print( "%-*s", MAX_PERSON_NAME, team_buf.members[i-1].name );
1417
        print( "</A>" );
1418
        print( "  Team :<A HREF=\"%s#Team_%04d\">", p_filename(filebase, "finish" ,"html"), team_buf.numb );
27 - 1419
        print( "%4d" , stats.fast.team[i][0] );
1420
        print( "</A> " );
1421
        print( "Time:%s ", time_a( stats.fast.time[i][0] ) );
1 root 1422
 
1423
    }
1424
 
1425
 
17 david 1426
 
1427
 
1 root 1428
    print( "<p><A HREF=\"#%s\">Awards Index</A>","INDEX");
1429
    close_printer();
1430
}
1431
 
1432
/*========================================================================
1433
 *
1434
 *  pri_master_index
1435
 *
1436
 *  Purpose:
1437
 *      This function is called to create an HTML page that references all
1438
 *      the other pages that have been generated
1439
 *
1440
 *      Assume that they are in the same directory
1441
 *
1442
 *  Parameters:
1443
 *      None
1444
 *
1445
 *  Returns:
1446
 *      Nothing
1447
 *
1448
 *========================================================================*/
1449
void pri_master_index_entry(char *name, char *text)
1450
{
1451
    print( "<tr><td>");
1452
    print ("<A HREF=\"%s\">%s</A>\n", p_filename(filebase, name ,"html"), text );
1453
}
1454
 
1455
 
1456
void pri_master_index(void)
1457
{
1458
    int j;
1459
 
1460
    report_html = 1;
1461
    if( !open_printer( "", "index", 132, report_html, "Master Index" ) )
1462
        return;
1463
 
1464
    /*
1465
    **  Names
1466
    */
1467
    print( "<TABLE border=0 align=center>" );
18 david 1468
    pri_master_index_entry( "name", "Team list" );
1469
    pri_master_index_entry( "competitor", "Competitor list" );
1 root 1470
    pri_master_index_entry( "finish", "Finishing Order for all Teams" );
1471
    pri_master_index_entry( "awards", "Prizes and Awards" );
1472
    print( "<tr><td>\n" );
1473
 
1474
    print( "\n" );
1475
    for( j = 1; j <= config.num_class; j++ )
1476
    {
1477
        pri_master_index_entry( config.team_class[j - 1].abr, tprintf("Category Results for: %s", config.team_class[j-1].full_name) );
1478
    }
32 - 1479
 
1 root 1480
    print( "</TABLE>" );
1481
 
1482
    close_printer();
32 - 1483
 
1484
    /*
1485
    **  A small page to hold the Leg End displays
1486
    */
1487
 
1488
    if( !open_printer( "", "legindex", 132, report_html, "Master Index with trace data" ) )
1489
        return;
1490
 
1491
    /*
1492
    **  Names
1493
    */
1494
    print( "<TABLE border=0 align=center>" );
1495
#if 1
1496
    pri_master_index_entry( "name", "Team list" );
1497
    pri_master_index_entry( "competitor", "Competitor list" );
1498
    pri_master_index_entry( "finish", "Finishing Order for all Teams" );
1499
    pri_master_index_entry( "awards", "Prizes and Awards" );
1500
    print( "<tr><td>\n" );
1501
 
1502
    print( "\n" );
1503
    for( j = 1; j <= config.num_class; j++ )
1504
    {
1505
        pri_master_index_entry( config.team_class[j - 1].abr, tprintf("Category Results for: %s", config.team_class[j-1].full_name) );
1506
    }
1507
#endif
1508
    print( "<tr><td>\n" );
1509
 
1510
    print( "\n" );
1511
    for ( leg = 1; leg <= config.num_legs; leg ++ )
1512
    {
1513
        pri_master_index_entry( tprintf("lg%1.1d", leg), tprintf("Leg End Results for: %d", leg) );    
1514
    }
1515
 
1516
    print( "<tr><td>\n" );
1517
    print( "\n" );
1518
 
1519
    for ( leg = 1; leg <= config.num_legs; leg ++ )
1520
    {
1521
        pri_master_index_entry( tprintf("le%1.1d", leg), tprintf("Leg Elapsed Time Results for: %d", leg) );
1522
    }    
1523
 
1524
 
1525
    print( "</TABLE>" );
1526
 
1527
    close_printer();
1528
 
1 root 1529
}
1530
 
1531
 
1532
/*========================================================================
1533
 *
1534
 *  Print interim results
1535
 *
1536
 *  Purpose:
1537
 *      This function is called to Print interim results
1538
 *
1539
 *  Parameters:
1540
 *      None
1541
 *
1542
 *  Returns:
1543
 *      Nothing
1544
 *
1545
 *========================================================================*/
1546
 
1547
void pri_interim(void)
1548
{
1549
    ty_s_data  *ptr;
1550
    unsigned    i;
1551
    int         j, last_class;
29 - 1552
    char        suppress_classes = FALSE;                /* Boolean. Printout class files too */
1 root 1553
    char       *report_title;
1554
 
29 - 1555
    if ( ! report_all )
1556
    {
1557
        cur( 0, 5 );
1558
        printf( "Generate interim result printouts\n" );
1559
        ck_data( -1, C_DISQUAL );                    /* Check the data - dummy check */
1560
        suppress_classes = getyes( "Do you want to suppress class printouts" );
1561
        printf( "\nSorting the data\n" );
1562
    }
1 root 1563
    do_big_sort();                             /* Sort on every thing */
1564
    gen_stats();                               /* Generate the stats too */
1565
 
1566
    printf( "\nGenerating the printed output\n" );
1567
 
1568
    /*
1569
     * Now print the data on the printer 
1570
     */
1571
 
1572
    if( !open_printer( "", "int", 132, report_html, "Interim Results" ) )
1573
        return;
1574
 
1575
    /*
1576
     * Print out the data 
1577
     */
1578
    print_class_header( -1, FALSE );                     /* Print the header */
1579
 
1580
    ptr = sort_data;
1581
    sort_team_data( 0, S_TEAM );                   /* Re-sort on team number */
1582
    for( ptr = sort_data, i = 0; i < sort_num; i++, ptr++ )
1583
    {
1584
        if ( ptr->class == config.nonequestrian_class )
1585
            continue;
1586
 
1587
        g_record( ptr->team, &team_buf );
1588
 
1589
        print( "%4d %4.4s %-*s",
1590
               team_buf.numb,
1591
               pi_place( team_buf.leg[config.num_legs].le_place,
1592
                         ptr->flags.disqualified, team_buf.leg[0].elapsed ),
1593
               3,
1594
               team_buf.class ==
1595
 
1596
        for( j = 1; j <= config.num_legs; j++ )
1597
        {
1598
            print( "  %-8s %4.4s %4.4s",
1599
                   time_fa( team_buf.leg[j].elapsed,
1600
                            ptr->flags.disqualified ),
1601
                   pi_place( team_buf.leg[j].l_place, ptr->flags.disqualified,
1602
                             team_buf.leg[j].elapsed ),
1603
                   pi_place( team_buf.leg[j].le_place,
1604
                             ptr->flags.disqualified,
1605
                             team_buf.leg[j].elapsed ) );
1606
        }
1607
        print( "  %-8s %4.4s\n",
1608
               time_fa( team_buf.leg[0].elapsed, ptr->flags.disqualified ),
1609
               pi_place( team_buf.leg[config.num_legs].lec_place,
1610
                         ptr->flags.disqualified, team_buf.leg[0].elapsed ) );
1611
    }
1612
 
1613
    print_class_stats( -1, FALSE );             /* Print statistics */
18 david 1614
    print_legend(-1, 1);                        /* Print the legend */
1 root 1615
    close_printer();                            /* Close the printer */
1616
 
1617
 
1618
    /*
1619
     * Now produce a breakdown on a class by class basis 
1620
     * Now print out the class placement information
1621
     */
1622
 
1623
    if( suppress_classes )
1624
    {
1625
        printf( "WARNING: Class printouts suppressed\n" );
1626
        return;
1627
    }
1628
 
1629
    sort_team_data( 0, S_CLASS );              /* Generate class placement data */
1630
    last_class = -1;                             /* Invalid class to start with */
1631
 
1632
    for( ptr = sort_data, i = 0; i < sort_num; i++, ptr++ )
1633
    {
1634
        /*
1635
        **  Detect a change in the "class"
1636
        **  All data is within the one array of data
1637
        **  Use the in-memory class as this MAY differ from that stored
1638
        **  The non-equestrian class does this.
1639
        */
1640
        if( last_class != ptr->class )
1641
        {
1642
            if( last_class >= 0 )
1643
            {
1644
                print_class_stats( last_class, TRUE );
18 david 1645
                print_legend(last_class, 1);
1 root 1646
                close_printer();
1647
            }
1648
 
1649
            report_title = tprintf( "Interim Category results for : %-*s", LEN_CLASS_NAME, team_buf.class == 0 ? "" : config.team_class[ptr->class - 1].full_name );
1650
 
1651
            if( !open_printer( "", tprintf( "i%2s", config.team_class[ptr->class - 1].abr ), 132, report_html, report_title ) )
1652
                continue;
1653
            print_class_header( last_class = ptr->class, FALSE );
1654
        }
1655
 
1656
        /*
1657
        **  Now read in the team record
1658
        */
1659
        g_record( ptr->team, &team_buf );
1660
        print( "%4d %4.4s %-*s",
1661
               team_buf.numb,
1662
               pi_place( team_buf.leg[config.num_legs].lec_place,
1663
                         ptr->flags.disqualified, team_buf.leg[0].elapsed ),
1664
               3,
1665
               team_buf.class ==
1666
 
1667
        for( j = 1; j <= config.num_legs; j++ )
1668
        {
1669
            print( "  %-8s %4.4s %4.4s",
1670
                   time_fa( team_buf.leg[j].elapsed,
1671
                            ptr->flags.disqualified ),
1672
                   pi_place( team_buf.leg[j].lc_place,
1673
                             ptr->flags.disqualified,
1674
                             team_buf.leg[j].elapsed ),
1675
                   pi_place( team_buf.leg[j].lec_place,
1676
                             ptr->flags.disqualified,
1677
                             team_buf.leg[j].elapsed ) );
1678
        }
1679
        print( "  %-8s %4.4s\n",
1680
               time_fa( team_buf.leg[0].elapsed, ptr->flags.disqualified ),
1681
               pi_place( team_buf.leg[config.num_legs].le_place,
1682
                         ptr->flags.disqualified, team_buf.leg[0].elapsed ) );
1683
    }
1684
 
1685
    print_class_stats( last_class, FALSE );
18 david 1686
    print_legend(last_class, 1);
1 root 1687
    close_printer();
1688
 
1689
}
1690
 
1691
/*========================================================================
1692
 *
29 - 1693
 *  Print all reports at once
1694
 ^  Its all so fast, these days ...
1695
 *
1696
 *  Purpose:
1697
 *      This function is called to print all reports at once
1698
 *
1699
 *  Parameters:
1700
 *      None
1701
 *
1702
 *  Returns:
1703
 *      Nothing
1704
 *
1705
 *========================================================================*/
1706
 
1707
void pri_all_reports ( void )
1708
{
1709
    int leg;
1710
    report_all = TRUE;
1711
 
1712
    pri_team();
1713
 
1714
    for ( leg = 1; leg <= config.num_legs; leg ++ )
1715
    {
1716
        pri_leg_body ( leg );
1717
        pri_eleg_body ( leg );
32 - 1718
 
1719
        report_html = TRUE;
1720
 
1721
        pri_leg_body ( leg );
1722
        pri_eleg_body ( leg );        
1723
 
1724
        report_html = FALSE;
29 - 1725
    }
1726
 
1727
    pri_final();
1728
    pri_final_html();
1729
    pri_summary();
1730
    pri_awards();
1731
    pri_master_index();
1732
 
1733
    report_all = FALSE;
1734
}
1735
 
1736
 
1737
/*========================================================================
1738
 *
1 root 1739
 *  Print a class header
1740
 *
1741
 *  Purpose:
1742
 *      This function is called to print a class header
1743
 *
1744
 *  Parameters:
1745
 *      class           Name of this class
1746
 *      final           False - prelim results
1747
 *
1748
 *  Returns:
1749
 *      Nothing
1750
 *
1751
 *========================================================================*/
1752
 
1753
void print_class_header( int class, int final )
1754
{
1755
    int         j;
1756
 
1757
    /*
1758
    **  Give a clear indication that the report is preliminary
1759
    */
1760
 
1761
    if( !final )
1762
        print( "PRELIMINARY RESULTS ONLY\n\n" );
1763
 
1764
    /*
1765
    **  Now printout the column headings
1766
    **  This is a two line display
1767
    **
1768
    **  Line-1  Leg names
1769
    */
1770
    print( "%-*s %-*s %-*s", 4, "", 4, "", 3, "" );
1771
    for( j = 1; j <= config.num_legs; j++ )
1772
    {
1773
        print_bold( TRUE );
1774
        print( "  %-*s", 18, config.leg_name[j - 1] );
1775
        print_bold( FALSE );
1776
    }
1777
    print( "  %-8s %-4s\n", "Total", ( class < 0 ) ? "Cat" : "Fin" );
1778
 
1779
 
1780
    /*
1781
    **  Line-2  Details
1782
    */
1783
    print_underline( TRUE );
1784
    print( "%-*s %*s %-*s", 4, final ? "Plce" : "Team",
1785
                            4, final ? "Team" : "Plce",
1786
                            3, "Cat" );
1787
 
1788
    for( j = 1; j <= config.num_legs; j++ )
1789
        print( "  %-8s %-4s %-4s", "Time", " LP", " EP" );
1790
 
1791
    print( "  %-8s %-4s\n", "Time", "Plce" );
1792
    print_underline( FALSE );
1793
}
1794
 
1795
/*========================================================================
1796
 *
1797
 *  Generate the class stats
1798
 *
1799
 *  Purpose:
1800
 *      This function is called to Generate the class stats
1801
 *
1802
 *  Parameters:
1803
 *      c           Class to print
1804
 *      final       TRUE: Final data
1805
 *                  FALSE: Interim data
1806
 *
1807
 *  Returns:
1808
 *      Nothing
1809
 *
1810
 *========================================================================*/
1811
 
1812
void print_class_stats( int c, int final )
1813
{
1814
    int         i, j;
1815
    char        *title;
1816
 
1817
    if( c < 0 )
1818
    {
1819
        title = "Event";
1820
        c = 0;
1821
    }
1822
    else
1823
    {
1824
        title = "Category";
1825
    }
1826
 
1827
    print( "\n" );
1828
    if ( report_html ) print_underline(TRUE);
1829
    print( "%s statistics", title );
1830
    if ( report_html ) print_underline(FALSE);
1831
    print( "\n" );
1832
 
1833
 
1834
    /*
1835
    **  Print the names of the different legs
1836
    */
1837
    print( "%-*s       ", LEN_CLASS_NAME, "" );
1838
    for( i = 1; i <= config.num_legs; i++ )
1839
    {
1840
        print_bold( TRUE );
1841
        print( "%-13s  ", config.leg_name[i - 1] );
1842
        print_bold( FALSE );
1843
    }
1844
    print( "%-13s  \n", final ? "Total" : "" );
1845
 
1846
    /*
1847
    **  Print the fastest teams for each leg and overall
1848
    **  Add cross references to the team names for the fastest teams
1849
    */
1850
    print( "%*s : ", LEN_CLASS_NAME, "Fastest" );
1851
    for( i = 0; i <= config.num_legs; i++ )
1852
    {
1853
        j = i + 1;
1854
        if( i >= config.num_legs )
1855
        {
1856
            if( final )
1857
                j = 0;                           /* Leg-0 last */
1858
            else
1859
                break;
1860
        }
1861
 
1862
        if ( report_html ) print( "<A HREF=\"%s#Team_%04d\">", p_filename(filebase, "name" ,"html"), stats.fast.team[j][c] );
1863
        print( "%4d",  stats.fast.team[j][c] );
1864
        if ( report_html ) print( "</A>" );
1865
        print( " %s  ", time_a( stats.fast.time[j][c] ) );
1866
    }
1867
    print( "\n" );
1868
 
1869
    /*
1870
    **  Print the average time for each leg
1871
    */
1872
    print( "%*s : ", LEN_CLASS_NAME, "Average" );
1873
    for( i = 0; i <= config.num_legs; i++ )
1874
    {
1875
        j = i + 1;
1876
        if( i >= config.num_legs )
1877
        {
1878
            if( final )
1879
                j = 0;                           /* Leg-0 last */
1880
            else
1881
                break;
1882
        }
1883
        print( "     %s  ", time_a( stats.average[j][c] ) );
1884
    }
1885
}
1886
 
1887
/*========================================================================
1888
 *
1889
 *  Print the legend
1890
 *
1891
 *  Purpose:
1892
 *      This function is called to Print the legend
1893
 *
1894
 *  Parameters:
1895
 *      class       - Class currently being printed
18 david 1896
 *      full        - Display full legend
1 root 1897
 *
1898
 *  Returns:
1899
 *      Nothing
1900
 *
1901
 *========================================================================*/
1902
 
18 david 1903
void print_legend ( int class, int full )
1 root 1904
{
1905
 
1906
    int         i;
1907
    char        line[201];
1908
    FILE       *adfile = NULL;
1909
    int         count;
1910
 
1911
    /*
1912
     * First the categories 
1913
     */
1914
    print( "\n\n" );
1915
    if ( report_html ) print_underline(TRUE);
1916
    print( "Category abbreviations" );
1917
    if ( report_html ) print_underline(FALSE);
1918
    print( "\n" );
1919
 
1920
 
1921
    for( i = 1, count = 0; i <= config.num_class; i++ )
1922
    {
1923
#if 0
1924
        /*
1925
        **  Skip any non-equestrian class in the legend
1926
        **  Don't want to tell the general user whats goes on, unless we actually
1927
        **  creating the non-equestrian report.
1928
        */
1929
        if ( class != config.nonequestrian_class  && i == config.nonequestrian_class )
1930
            continue;
1931
#endif
1932
        if ( report_html ) print( "<A HREF=\"%s\">",p_filename(filebase, config.team_class[i - 1].abr ,"html") );
1933
        print( "%-*s", 3, config.team_class[i - 1].abr );
1934
        if ( report_html ) print( "</A>" );
1935
        print( " : %-*s  ", LEN_CLASS_NAME, config.team_class[i - 1].full_name );
1936
 
1937
        if( !( ++count % 5 ) )
1938
            print( "\n" );
1939
    }
1940
 
1941
    /*
1942
    **  Add link to the finish order report
1943
    */
1944
    if ( report_html )
1945
    {
1946
        print( "<A HREF=\"%s\">", p_filename(filebase, "finish" ,"html") );
1947
        print( "%-*s", 3, "All" );
1948
        print( "</A>" );
1949
        print( " : %-*s  ", LEN_CLASS_NAME, "Finishing Order" );
1950
    }
1951
 
1952
    /*
1953
    **  Country data - if countries have been defined
1954
    */
1955
    if( config.num_countries )
1956
    {
1957
        print( "\n\n" );
1958
        if ( report_html ) print_underline(TRUE);
1959
        print( "Country abbreviations" );
1960
        if ( report_html ) print_underline(FALSE);
1961
        print( "\n" );
1962
 
1963
        for( i = 0, count = 0; i < MAX_COUNTRY; i++ )
1964
        {
1965
            if( config.country_name[i].abr[0] )
1966
            {
1967
                print( "%-*s : %-*s  ", 4, config.country_name[i].abr,
1968
                       LEN_CNTRY_NAME, config.country_name[i].full_name );
1969
                if( !( ++count % 5 ) )
1970
                    print( "\n" );
1971
            }
1972
        }
1973
    }
18 david 1974
    print( "\n" );
1 root 1975
 
1976
    /*
1977
     * Other comments 
1978
     */
18 david 1979
    if ( full )
1980
    {
1981
        print( "\nPlace numbers (LP and EP)\n" );
1982
        print( "LP - Placing based on elapsed time within the leg.                Cat Plce - Placing within the category.\n" );
1983
        print( "EP - Placing based on accumulated times to the end of that leg.   Fin Plce - Overall placing within the event.\n" );
1984
    }
1 root 1985
 
1986
    /*
1987
     *  Insert the contents of the config.addendum file
1988
     *  or a defualt message
1989
     */
1990
    if( config.addendum[0] )
1991
        adfile = fopen( config.addendum, "rt" );  /* Open the file for reading */
1992
 
1993
    if( adfile )
1994
    {
1995
        while( fgets( line, sizeof(line)-1, adfile ) )
1996
            print( "%s", line );
1997
    }
1998
    else
1999
    {
2000
        print( "\nTiming and Results by\n" );
2001
        print( "Embedded Solutions\n" );
2002
    }
2003
}
2004
 
2005
/*========================================================================
2006
 *
2007
 *  Return place data
2008
 *
2009
 *  Purpose:
2010
 *      This function is called to return place data
2011
 *
2012
 *      This routine is called to fill a print team_buffer - to allow for
2013
 *      multiple calls to this function ( before the data is used ) a number
2014
 *      of static team_buffers are maintained
2015
 *
2016
 *  Parameters:
2017
 *      num         place - if not bad_times
2018
 *      disq        Disqualified flag
2019
 *      time        Time data is based on
2020
 *
2021
 *  Returns:
2022
 *      This function returns a pointer to the character string for the
2023
 *      number or a pointer to a bad_times string.
2024
 *
2025
 *========================================================================*/
2026
 
2027
char       *pi_place( int num, int disq, time_t time )
2028
{
2029
    static char store[2][5];                     /* 2 stores for 4 digit numbers */
2030
    static int  i = 0;                           /* Current index into store */
2031
    static char *dis = "D";                      /* Disqualified */
2032
    static char *non = "-";                      /* Invalid time */
2033
 
2034
    if( disq )                                   /* Disqualified team */
2035
        return ( dis );
2036
    if( time <= 0 )                              /* Unknown time */
2037
        return ( non );
2038
 
2039
    i++;
2040
    if( i >= 2 )
2041
        i = 0;                                   /* Select next entry */
2042
    sprintf( store[i], "%4d", num );
2043
    return ( store[i] );
2044
 
2045
}
2046
 
2047
/*========================================================================
2048
 *
2049
 *  Return place data
2050
 *
2051
 *  Purpose:
2052
 *      This function is called to Return place data
2053
 *
2054
 *      This routine is called to fill a print team_buffer - to allow for
2055
 *      multiple calls to this function ( before the data is used ) a number
2056
 *      of static team_buffers are maintained
2057
 *
2058
 *  Parameters:
2059
 *      num         place - if not bad_times
2060
 *      disq        Disqualified flag
2061
 *
2062
 *  Returns:
2063
 *      This function returns a pointer to the character string for the
2064
 *      number or a pointer to a bad_times string.
2065
 *
2066
 *========================================================================*/
2067
 
2068
char *pr_place( int num, int disq )
2069
{
2070
    static char store[2][5];                     /* 2 stores for 4 digit numbers */
2071
    static int  i = 0;                           /* Current index into store */
2072
    static char *dis = "U";
2073
 
2074
    if( disq )
2075
        return ( dis );
2076
 
2077
    i++;
2078
    if( i >= 2 )
2079
        i = 0;                                   /* Select next entry */
2080
    sprintf( store[i], "%4d", num );
2081
    return ( store[i] );
2082
 
2083
}
2084
 
2085
/*========================================================================
2086
 *
2087
 *  Check data for bad times
2088
 *
2089
 *  Purpose:
2090
 *      This function is called to Check data for bad times
2091
 *      Scan the sort data structure and locate entries that have incorrect
2092
 *      times.
2093
 *      
2094
 *      Entries that have invalid leg times are displayed to the operator
2095
 *      and the report process can be aborted
2096
 *
2097
 *  Parameters:
2098
 *      leg         Leg to test
2099
 *      mode            Either end or elapsed times to be tested
2100
 *
2101
 *  Returns:
2102
 *      Returns FALSE if the report operation is to be aborted
2103
 *
2104
 *========================================================================*/
2105
 
2106
bool ck_data( int leg, int mode )
2107
{
2108
    ty_s_data  *ptr;
2109
    unsigned    i;
2110
    int         bad = 0;
2111
    int         j = 0;
2112
    int         k, bad_leg;
2113
    time_t     *t;                               /* An array of times */
2114
 
29 - 2115
 
2116
 
1 root 2117
    ptr = sort_data;
2118
    for( i = 1; i <= sort_num; i++, ptr++ )
2119
    {
2120
        bad_leg = 0;
2121
        if( mode == C_DISQUAL )
2122
        {
2123
            ptr->flags.bad_times = ptr->flags.disqualified;
2124
            continue;
2125
        }
2126
 
2127
        if( mode == C_ELAPSED )
2128
            t = ptr->lege;
2129
        else
2130
            t = ptr->leg;
2131
 
2132
        if( ( ptr->flags.bad_times = ptr->flags.disqualified ) == FALSE )
2133
        {
2134
            if( leg <= 0 )
2135
            {
2136
                for( k = 0; k <= config.num_legs; k++ )
2137
                {
2138
                    if ( !(config.equestrian_leg && ptr->flags.non_equestrian && config.equestrian_leg == k  ))
2139
                        bad_leg |= ( t[k] <= 0 );
2140
                }
2141
            }
2142
            else
2143
            {
2144
                bad_leg = t[leg] <= 0;
2145
            }
2146
 
2147
            if( bad_leg )
2148
            {
2149
                ptr->flags.bad_times = TRUE;
29 - 2150
 
2151
                if ( ! report_all )
1 root 2152
                {
29 - 2153
                    if( !bad )
2154
                        printf( "Team with incorrect time information\n" );
2155
                    if( ++j > 15 )
2156
                    {
2157
                        printf( "\n" );
2158
                        j = 0;
2159
                    }
2160
                    printf( "%4d ", ptr->team );
2161
                    bad++;
1 root 2162
                }
2163
            }
2164
        }
2165
    }
2166
 
2167
    if( bad )
2168
    {
2169
        printf( "\n%d teams with incorrect times.\n", bad );
2170
        return ( !getyes
2171
                 ( "These have been flagged as unplaced - continue report" ) );
2172
    }
2173
    return ( FALSE );
2174
}
2175
 
2176
/*========================================================================
2177
 *
2178
 *  Update placing information
2179
 *
2180
 *  Purpose:
2181
 *      This function is called to Update placing information
2182
 *
2183
 *      This routine will rip through the data generating the team placing in
2184
 *      a) Within a leg
2185
 *      b) At the end of a leg
2186
 *      c) Within a leg by  class
2187
 *      d) At the end of a leg by class
2188
 *
2189
 *      This function is provided to allow the display routines to
2190
 *      be accessed and updated without the need to run a report
2191
 *
2192
 *  Parameters:
2193
 *      xxxx        a ptr to the xxxx stuff
2194
 *
2195
 *  Returns:
2196
 *      Nothing
2197
 *
2198
 *========================================================================*/
2199
 
2200
void srt_place(void)
2201
{
2202
    int         i, j;
2203
 
2204
    cur( 0, 5 );
2205
    printf( "Update the team placings to the data base\n" );
2206
    flush_out();
2207
    if( ck_data( -1, C_ELAPSED ) )
2208
        return;
2209
    do_big_sort();
2210
 
2211
    /*
2212
     * Generate the stats and display them on the screen for interest
2213
     * This operation will not hurt - so why not
2214
     */
2215
 
2216
    gen_stats();
2217
    printf( "\nEvent statistics\n\n" );
2218
    printf( "%-*s   %-13s ", LEN_CLASS_NAME, "", "Overall" );
2219
    for( i = 1; i <= config.num_legs; i++ )
2220
        printf( "%-13s ", config.leg_name[i - 1] );
2221
 
2222
    for( j = 0; j <= config.num_class; j++ )
2223
    {
2224
        printf( "\n%-*s : ", LEN_CLASS_NAME,
2225
                j ? config.team_class[j - 1].full_name : "Overall" );
2226
        for( i = 0; i <= config.num_legs; i++ )
2227
        {
2228
            printf( "%4d ", stats.fast.team[i][j] );
2229
            printf( "%s ", time_a( stats.fast.time[i][j] ) );
2230
        }
2231
        printf( "\n%*s : ", LEN_CLASS_NAME, "Average" );
2232
        for( i = 0; i <= config.num_legs; i++ )
2233
        {
2234
            printf( "     %s ", time_a( stats.average[i][j] ) );
2235
        }
2236
    }
2237
    printf( "\nAny key to continue" );
2238
    ( void ) getinp();
2239
}
2240
 
2241
/*========================================================================
2242
 *
2243
 *  Calculate summary information
2244
 *
2245
 *  Purpose:
2246
 *      This function is called to calculate summary information
2247
 *
2248
 *  Parameters:
2249
 *      ptr         - Address of a summary structure to fill in
2250
 *
2251
 *  Returns:
2252
 *      Nothing
2253
 *
2254
 *========================================================================*/
2255
 
2256
void calc_class_summary( t_class_summary * ptr )
2257
{
2258
    int i;
2259
 
2260
    /*
2261
    **  Reset the data
2262
    */
2263
    memset ( ptr, 0, sizeof (*ptr ));
2264
 
2265
    /*
2266
     * Extract the required data from the data base
2267
     * Only save that information required for the operation
2268
     */
2269
 
2270
    for( i = config.min_team; i <= config.max_team; i++ )
2271
    {
2272
        if( valid_field( i ) && g_record( i, &team_buf ) )
2273
        {
2274
            ptr->total.total++;
2275
            ptr->class[team_buf.class].total++;
2276
 
2277
            if ( team_buf.flags.disqualified )
2278
            {
2279
                ptr->class[team_buf.class].disqualified++;
2280
                ptr->total.disqualified++;
2281
            }
2282
 
2283
            if ( config.nonequestrian_class && team_buf.flags.non_equestrian )
2284
            {
2285
                ptr->class[team_buf.class].non_equestrian++;
2286
                ptr->total.non_equestrian++;
2287
            }
2288
        }
2289
    }
13 david 2290
 
2291
    /*
2292
    **  Fix up the totals for the non equestrians
2293
    **  This is not a real category but a summary of the others.
2294
    */
2295
    if ( config.nonequestrian_class  )
2296
    {
2297
        ptr->class[config.nonequestrian_class].total += ptr->total.non_equestrian;
2298
    }
1 root 2299
}
2300
 
2301
/*========================================================================
2302
 *
2303
 *  Display summary information
2304
 *
2305
 *  Purpose:
2306
 *      This function is called to display summary information
2307
 *
2308
 *  Parameters:
2309
 *      None
2310
 *
2311
 *  Returns:
2312
 *      Nothing
2313
 *
2314
 *========================================================================*/
2315
 
2316
void display_summary (void)
2317
{
2318
 
2319
    t_class_summary data;
2320
    int         i;
2321
    int         line = 2;
2322
 
2323
    cur( 0, line );
2324
    printf( "Generating Summary Information" );
2325
    calc_class_summary( & data );
2326
 
2327
 
2328
    /*
2329
    **  Display summary stats
2330
    */
2331
 
2332
    cur( 0, line );
2333
    console_clreol();
2334
    printf( "Summary Information\n\n" );
2335
    printf( "%*s : %-7s %-7s%-7s\n", LEN_CLASS_NAME,
2336
                                      "Category",
2337
                                      "Total",
2338
                                      "Disq",
2339
                                      "NonEq" );
2340
 
2341
    for( i = 0; i < config.num_class; i++ )
2342
    {
2343
        /*
2344
        **  The non-equestrian leg does not have any data
2345
        **  Supress the display
2346
        */
2347
        if ( config.nonequestrian_class == i+1  )
2348
            continue;
2349
 
2350
        printf( "%*s : %-7d %-7d %-7d\n", LEN_CLASS_NAME,
2351
                                          config.team_class[i].full_name,
2352
                                          data.class[i+1].total,
2353
                                          data.class[i+1].disqualified,
2354
                                          data.class[i+1].non_equestrian );
2355
    }
2356
 
2357
    printf( "\n" );
2358
    printf( "%*s : %-7d %-7d %-7d\n", LEN_CLASS_NAME,
2359
                                      "Totals",
2360
                                      data.total.total,
2361
                                      data.total.disqualified,
2362
                                      data.total.non_equestrian );
2363
 
2364
    printf( "\nAny key to continue " );
2365
    getinp();
2366
}
2367
 
13 david 2368
/*========================================================================
2369
 *
2370
 *  Print summary information
2371
 *
2372
 *  Purpose:
2373
 *      This function is called to print summary information
2374
 *
2375
 *  Parameters:
2376
 *      None
2377
 *
2378
 *  Returns:
2379
 *      Nothing
2380
 *
2381
 *========================================================================*/
1 root 2382
 
13 david 2383
void pri_summary (void)
2384
{
2385
 
2386
    t_class_summary data;
2387
    int         i;
2388
    int         line = 2;
2389
 
2390
 
2391
    if( !open_printer( "", "summary", 132, 0, "Summary Information" ) )
2392
        return;
2393
 
2394
    cur( 0, line );
2395
    printf( "Generating Summary Information" );
2396
    calc_class_summary( & data );
2397
 
2398
 
2399
    /*
2400
    **  Display summary stats
2401
    */
2402
 
2403
    print( "%*s : %-7s %-7s%-7s\n", LEN_CLASS_NAME,
2404
                                      "Category",
2405
                                      "Total",
2406
                                      "Disq",
2407
                                      "NonEq" );
2408
 
2409
    for( i = 0; i < config.num_class; i++ )
2410
    {
2411
        /*
2412
        **  The non-equestrian leg does not have any data
2413
        **  Supress the display
2414
        */
2415
        if ( config.nonequestrian_class == i+1  )
2416
            continue;
2417
 
2418
        print( "%*s : %-7d %-7d %-7d\n", LEN_CLASS_NAME,
2419
                                          config.team_class[i].full_name,
2420
                                          data.class[i+1].total,
2421
                                          data.class[i+1].disqualified,
2422
                                          data.class[i+1].non_equestrian );
2423
    }
2424
 
2425
    print( "\n" );
2426
    print( "%*s : %-7d %-7d %-7d\n", LEN_CLASS_NAME,
2427
                                      "Totals",
2428
                                      data.total.total,
2429
                                      data.total.disqualified,
2430
                                      data.total.non_equestrian );
2431
 
2432
    close_printer();
29 - 2433
    if ( !report_all )
2434
    {
2435
        printf( "\nAny key to continue " );
2436
        getinp();
2437
    }
13 david 2438
}
2439
 
2440
 
2441
 
1 root 2442
/*========================================================================
2443
 *
2444
 *  Main sort routine for final data
2445
 *
2446
 *  Purpose:
2447
 *      This function is called to do the report sort routine for final data
2448
 *      This routine will fill all the gaps in the sort_aux structure
2449
 *
2450
 *  Parameters:
2451
 *      None
2452
 *
2453
 *  Returns:
2454
 *      Nothing
2455
 *
2456
 *========================================================================*/
2457
 
2458
void do_big_sort(void)
2459
{
2460
    int         i, k;                            /* Looooopy things */
2461
    unsigned    j;
2462
    ty_s_data  *ptr;                             /* Pointer to sort data */
2463
    int         class;                           /* Current class */
2464
 
2465
    printf( "Sorting it ALL out" );
2466
    flush_out();
2467
 
2468
    for( i = 0; i <= config.num_legs; i++ )
2469
    {
2470
        /*
2471
        **  Sort on leg elapsed time
2472
        **  The save the teams elapsed place in each leg
2473
        */
2474
        sort_team_data( i, S_L );
2475
        for( j = 1, ptr = sort_data; j <= sort_num; j++, ptr++ )
2476
        {
2477
            sort_aux[ptr->team].l_place[i] = j;
2478
            sort_aux[ptr->team].team = ptr->team;
2479
        }
2480
 
2481
        /*
2482
        **  Sort on leg end time
2483
        **  Then save the teams place at the end of each leg
2484
        */
2485
        sort_team_data( i, S_LE );
2486
        for( j = 1, ptr = sort_data; j <= sort_num; j++, ptr++ )
2487
            sort_aux[ptr->team].le_place[i] = j;
2488
 
2489
        /*
2490
        **  Sort on elapsed time per class
2491
        **  The save the teams elapsed place in each leg per class
2492
        */
2493
        sort_team_data( i, S_LC );
2494
        class = -1;
2495
        for( k = 1, j = 1, ptr = sort_data; j <= sort_num; j++, ptr++ )
2496
        {
2497
            if( class != ptr->class )
2498
            {
2499
                k = 1;
2500
                class = ptr->class;
2501
            }
2502
            sort_aux[ptr->team].lc_place[i] = k++;
2503
        }
2504
 
2505
        /*
2506
        **  Sort on end time per class
2507
        **  Then save the teams place at the end of each leg per class
2508
        */
2509
        sort_team_data( i, S_LEC );
2510
        class = -1;
2511
        for( k = 1, j = 1, ptr = sort_data; j <= sort_num; j++, ptr++ )
2512
        {
2513
            if( class != ptr->class )
2514
            {
2515
                k = 1;
2516
                class = ptr->class;
2517
            }
2518
            sort_aux[ptr->team].lec_place[i] = k++;
2519
        }
2520
    }
2521
 
2522
    /*
2523
    **  Write the place information back to disk for use in the displays
2524
    */
2525
    printf( "\nWriting it all back to the disk file" );
2526
    flush_out();
2527
 
2528
    for( i = config.min_team; i <= config.max_team; i++ )
2529
    {
2530
        if( sort_aux[i].team && valid_field( i ) && g_record( i, &team_buf ) )
2531
        {
2532
            for( k = 0; k <= config.num_legs; k++ )
2533
            {
2534
                team_buf.leg[k].l_place = sort_aux[i].l_place[k];
2535
                team_buf.leg[k].le_place = sort_aux[i].le_place[k];
2536
                team_buf.leg[k].lc_place = sort_aux[i].lc_place[k];
2537
                team_buf.leg[k].lec_place = sort_aux[i].lec_place[k];
2538
            }
2539
            put_team_record( i, &team_buf );
2540
        }
2541
    }
2542
}
2543
 
2544
/*========================================================================
2545
 *
2546
 *  Sort in memory buffer
2547
 *
2548
 *  Purpose:
2549
 *      This function is called to Sort in memory buffer
2550
 *
2551
 *  Parameters:
2552
 *      leg         Requested leg
2553
 *      mode        Defines the sort mode
2554
 *
2555
 *  Returns:
2556
 *      Nothing
2557
 *
2558
 *========================================================================*/
2559
 
2560
void sort_team_data( int leg, int mode )
2561
{
2562
 
2563
    unsigned    j;
2564
    ty_s_data  *ptr;
2565
 
2566
    sort_leg = leg;                              /* Leg is global for the comparison function */
2567
    sort_mode = mode;                            /* Mode is global for compare function */
2568
 
2569
    qsort( ( char * ) sort_data, sort_num, sizeof( ty_s_data ), sort_comp );
2570
 
2571
    /*
2572
     * Insert "place data" into the sorted data
2573
     * This simply the index into the array of data - after its been
2574
     * sorted.
2575
     */
2576
    ptr = sort_data;
2577
    for( j = 1; j <= sort_num; j++, ptr++ )
2578
        ptr->place = j;
2579
 
2580
}
2581
 
2582
/*========================================================================
2583
 *
2584
 *  qsort comparison function
2585
 *
2586
 *  Purpose:
2587
 *      This function is called by qsort as a Sort comparison function
2588
 *
2589
 *  Parameters:
2590
 *      a       - 1st record
2591
 *      b       - 2nd record
2592
 *
2593
 *  Returns:
2594
 *      value to qsort
2595
 *
2596
 *========================================================================*/
2597
 
2598
int sort_comp( const void * aa, const void * bb )
2599
{
2600
    const ty_s_data * a = aa;
2601
    const ty_s_data * b = bb;
2602
 
2603
 
2604
    int         i;                               /* One of those */
2605
    time_t      ta, tb;                          /* Leg times */
2606
    int         na, nb;                          /* Number of valid legs */
2607
    time_t      tta, ttb;                        /* Temp times */
2608
 
2609
    /*
2610
    **  Sorting on Team Number
2611
    */
2612
    if( sort_mode == S_TEAM )
2613
        return ( a->team - b->team );
2614
 
2615
    /*
2616
    **  Sorting on Class and Team Number
2617
    */
2618
    if( sort_mode == S_CLASS )
2619
    {
2620
        if( a->class != b->class )
2621
            return ( a->class - b->class );
2622
        else
2623
            return ( a->team - b->team );
2624
    }
2625
 
2626
    /*
2627
    **  Sorting within a class
2628
    **  First sort on the class
2629
    */
2630
    if( sort_mode == S_LEC || sort_mode == S_LC )   /* Sort within a class */
2631
        if( a->class != b->class )
2632
            return ( a->class - b->class );
2633
 
2634
    /*
2635
    **  Now we need to examine the times as we have sorted
2636
    **  on every thing else.
2637
    **
2638
    **  If one of the teams has bad_times, then that team is placed
2639
    **  lower in the sorting order. If both teams have bad times
2640
    **  then sort on team number. ie: Unplaced teams are sorted on
2641
    **  team number
2642
    */
2643
    if( a->flags.bad_times || b->flags.bad_times )  /* Valid data has precedence */
2644
    {
2645
        if( a->flags.bad_times && b->flags.bad_times )
2646
            return ( a->team - b->team );
2647
        else
2648
            return ( a->flags.bad_times ? 1 : -1 );
2649
    }
2650
 
2651
    /*
2652
    **  Not sorting within a class ie: Overall
2653
    **  Non-Equestrian is at the end, so that it doesn't get counted in the
2654
    **  finishing order
2655
    */
2656
    if( sort_mode == S_LE || sort_mode == S_L )     /* Sort NOT within a class */
2657
    {
2658
        if( a->flags.non_equestrian || b->flags.non_equestrian )
2659
        {
2660
            if( a->flags.non_equestrian && b->flags.non_equestrian )
2661
                return ( a->team - b->team );
2662
            else
2663
                return ( a->flags.non_equestrian ? 1 : -1 );
2664
        }
2665
    }
2666
 
2667
 
2668
    /*
2669
    **  Before we sort on times we must determine which time to
2670
    **  use. Finish time, Leg end times, Leg Elapsed times.
2671
    */
2672
 
2673
    switch ( sort_mode )
2674
    {
2675
      /*
2676
      **    Sort on finish times
2677
      */
2678
      case S_FIN:
2679
        ta = a->leg[sort_leg];
2680
        tb = b->leg[sort_leg];
2681
        break;
2682
 
2683
 
2684
      /*
2685
      **    Sort on accumulated leg times
2686
      */
2687
      case S_LE:
2688
      case S_LEC:
2689
        if( sort_leg )
2690
        {
2691
            /*
2692
            **  Calculate accumulated time up to the desired leg
2693
            **  If the two teams have a different number of valid
2694
            **  leg times then order by the team that has completed
2695
            **  more legs.
2696
            */
2697
            ta = tb = ( time_t ) 0;
2698
            na = nb = 0;
2699
            for( i = 1; i <= sort_leg; i++ )
2700
            {
2701
                tta = a->lege[i];
2702
                ttb = b->lege[i];
2703
                if( tta > 0 )
2704
                {
2705
                    na++;
2706
                    ta += tta;
2707
                }
2708
                if( ttb > 0 )
2709
                {
2710
                    nb++;
2711
                    tb += ttb;
2712
                }
2713
            }
2714
            if( na != nb )
2715
                return ( nb - na );
2716
        }
2717
        else
2718
        {
2719
            ta = a->leg[sort_leg] - a->start;
2720
            tb = b->leg[sort_leg] - b->start;
2721
        }
2722
        break;
2723
 
2724
      /*
2725
      **    Sort on Elapsed times
2726
      */
2727
      case S_LC:
2728
      case S_L:
2729
        ta = a->lege[sort_leg];
2730
        tb = b->lege[sort_leg];
2731
        break;
2732
 
2733
      /*
2734
      **    Just to be sure ...
2735
      */
2736
      default:
2737
        return ( 0 );
2738
    }
2739
 
2740
    /*
2741
    **  Finally. Compare the required team times
2742
    */
2743
    if( ta == tb )
2744
        return ( a->team - b->team );
2745
    if( ( ta > 0 ) && ( tb > 0 ) )
2746
        return ( ( int ) ( ta - tb ) );
2747
    return ( ( ta > 0 ) ? -1 : 1 );
2748
}
2749
 
2750
/*========================================================================
2751
 *
18 david 2752
 *  qsort comparison function - competitor names
2753
 *
2754
 *  Purpose:
2755
 *      This function is called by qsort as a Sort comparison function
2756
 *
2757
 *  Parameters:
2758
 *      a       - 1st record
2759
 *      b       - 2nd record
2760
 *
2761
 *  Returns:
2762
 *      value to qsort
2763
 *
2764
 *========================================================================*/
2765
 
2766
int sort_comp_cname( const void * aa, const void * bb )
2767
{
25 - 2768
    ty_s_namedata * a = (ty_s_namedata *)aa;
2769
    ty_s_namedata * b = (ty_s_namedata *)bb;
18 david 2770
 
2771
 
2772
    int         i;                               /* One of those */
2773
 
2774
    /*
2775
    **  Sort by name
2776
    */
2777
    i = strcmp ( a->name, b->name );
2778
    if ( i )
2779
        return ( i );
2780
    a->multi=1;
2781
    b->multi=1;
2782
 
2783
    /*
2784
    **  Sort by Leg
2785
    */
2786
    i = a->leg - b->leg;
2787
    if ( i )
2788
        return ( i );
2789
 
2790
    /*
2791
    **  Sorting on Team Number
2792
    */
2793
    return ( a->team - b->team );
2794
 
2795
}
2796
 
2797
/*========================================================================
2798
 *
1 root 2799
 *  load report data into memory
2800
 *
2801
 *  Purpose:
2802
 *      This routine will pull all the data into memory 
2803
 *      Not all the team data is loaded. Only that essential for the
2804
 *      operation of the sort routine is loaded
2805
 *
2806
 *  Parameters:
2807
 *      None
2808
 *
2809
 *  Returns:
2810
 *      TRUE - All is well
2811
 *
2812
 *========================================================================*/
2813
 
2814
bool load_report_data(void)
2815
{
2816
 
2817
    ty_s_data  *ptr;                             /* pointer to sort data type */
2818
    int         j;
2819
    unsigned    num;
2820
 
2821
    printf( "Loading team information - This will not hurt" );
2822
    flush_out();
2823
 
2824
    /*
2825
     * Fetch memory for the data store
2826
     */
2827
 
2828
    if( sort_data )
2829
        free( ( char * ) sort_data );
2830
    sort_data = 0;
2831
 
2832
    if( sort_aux )
2833
        free( ( char * ) sort_aux );
2834
    sort_aux = 0;
2835
    sort_num = 0;                                /* Counter of records in the array */
2836
 
2837
    /*
2838
    **  Allocate memory for the data structures
2839
    **  This will be free'd
2840
    */
2841
    num = config.max_team - config.min_team + 1 ;
2842
 
2843
    /*
2844
    **  Allow for non-equestrian teams - since some of the data is loaded twice
2845
    **  Take a guess that at most 1/2 the teams will be non-equestrian
2846
    */
2847
    num = num * 3 / 2;
2848
 
2849
    sort_data = ( ty_s_data * ) calloc ( num , sizeof( ty_s_data ) );
2850
    sort_aux = ( ty_s_aux * ) calloc( num + 1, sizeof( ty_s_aux ) );
2851
 
2852
    if( sort_data == 0 || sort_aux == 0 )
2853
    {
2854
        printf( "\n\nError in allocating memory\n" );
2855
        sleep( 5 );
2856
        return ( FALSE );
2857
    }
2858
 
2859
    /*
2860
    **  Load data into the memory based data structure
2861
    **  Only load data for valid-teams
2862
    **  Load essential data
2863
    **      Team Number, class and flags
2864
    **      Leg end and elapsed times
2865
    */
2866
    ptr = sort_data;
2867
    for( team = config.min_team; team <= config.max_team; team++ )
2868
    {
2869
        if( valid_field( team ) )
2870
        {
2871
            g_record( team, &team_buf );
2872
            if( team_buf.flags.valid )
2873
            {
2874
                ptr->team = team;
2875
                for( j = 0; j < MAX_LEGS + 1; j++ )
2876
                {
2877
                    ptr->lege[j] = team_buf.leg[j].elapsed;
2878
                    ptr->leg[j] = team_buf.leg[j].end;
2879
                }
2880
                ptr->start = team_buf.leg[0].start;
2881
                ptr->class = team_buf.class;
2882
 
2883
                ptr->flags = team_buf.flags;
2884
                ptr++;
2885
                sort_num++;
2886
 
2887
                /*
2888
                **  If non-equestrian support is enabled then
2889
                **  duplicate and modify data for the non-equestrian teams
2890
                **      - Change the class
2891
                **      - Modify the leg time
2892
                */
2893
                if ( config.nonequestrian_class && team_buf.flags.non_equestrian )
2894
                {
2895
                    ptr->team = team;
2896
                    ptr->lege[0] = 0;
2897
 
2898
                    for( j = 0; j < MAX_LEGS + 1; j++ )
2899
                    {
2900
                        if ( j == config.equestrian_leg )
2901
                        {
2902
                            ptr->lege[j] = 0;
2903
                            if ( config.equestrian_leg > 1 )
2904
                                ptr->leg[j] = ptr->leg[j-1];
2905
                        }
2906
                        else
2907
                        {
2908
                            if ( j )
2909
                                ptr->lege[j] = team_buf.leg[j].elapsed;
2910
                            ptr->leg[j] = team_buf.leg[j].end;
2911
                            ptr->lege[0] += ptr->lege[j] ;
2912
                        }
2913
                    }
2914
 
2915
                    ptr->start = team_buf.leg[0].start;
2916
                    ptr->class = config.nonequestrian_class;
2917
                    ptr->flags = team_buf.flags;
2918
                    ptr->flags.disqualified = 0;
2919
                    ptr++;
2920
                    sort_num++;
2921
                }
2922
            }
2923
        }
2924
    }
2925
    return ( TRUE );
2926
}
2927
 
2928
/*========================================================================
2929
 *
2930
 *  Generate all the stats
2931
 *
2932
 *  Purpose:
2933
 *      This function is called to Generate all the stats
2934
 *
2935
 *  Parameters:
2936
 *      None
2937
 *
2938
 *  Returns:
2939
 *      Nothing
2940
 *
2941
 *========================================================================*/
2942
 
2943
void gen_stats(void)
2944
{
2945
    ty_s_data  *ptr;
2946
    unsigned    i;
2947
    int         j;
2948
    int         k;
2949
 
2950
    /*
2951
     * Init all the stats 
2952
     */
2953
    for( i = 0; i <= MAX_LEGS; i++ )
2954
    {
2955
        for( j = 0; j <= MAX_CLASS; j++ )
2956
        {
2957
            stats.team[i][j] = 0;
2958
            stats.fast.team[i][j] = 0;
2959
            stats.fast.time[i][j] = ( time_t ) - 1;
2960
            stats.average[i][j] = 0;
2961
        }
2962
    }
2963
 
2964
    for( i = 1, ptr = sort_data; i <= sort_num; i++, ptr++ )
2965
    {
2966
        /*
2967
        **  If there is any bad times in the team record, then none
2968
        **  of the data can be trusted.
2969
        **
2970
        **  If the team has been disqualified, then don't use any
2971
        **  of the data.
2972
        */
2973
        if( ptr->flags.bad_times || ptr->flags.disqualified )
2974
            continue;
2975
 
2976
        for( j = 0; j <= config.num_legs; j++ )
2977
        {
2978
            if( ptr->lege[j] <= 0 )              /* Ignore bad data */
2979
                continue;
2980
 
2981
            /*
2982
            **  Determine fastest team : overall
2983
            **  Ignore the non-equestrian data as this is in the list twice
2984
            */
2985
            if( ( ptr->lege[j] < stats.fast.time[j][0] )
2986
                || ( stats.fast.time[j][0] < 0 ) )
2987
            {
2988
                if ( ptr->class != config.nonequestrian_class )
2989
                {
2990
                    stats.fast.team[j][0] = ptr->team;
2991
                    stats.fast.time[j][0] = ptr->lege[j];
2992
                }
2993
            }
2994
 
2995
            /*
2996
            **  Determine fastest team : within a class
2997
            */
2998
            if( ( ptr->lege[j] < stats.fast.time[j][ptr->class] )
2999
                || stats.fast.time[j][ptr->class] < 0 )
3000
            {
3001
                stats.fast.team[j][ptr->class] = ptr->team;
3002
                stats.fast.time[j][ptr->class] = ptr->lege[j];
3003
            }
3004
 
3005
            /*
3006
            **  Sum the end times : overall
3007
            */
3008
            if ( ptr->class != config.nonequestrian_class )
3009
            {
3010
                stats.average[j][0] += ptr->lege[j];
3011
                stats.team[j][0]++;
3012
            }
3013
 
3014
 
3015
            /*
3016
            **  Sum the end times : within a class
3017
            */
3018
            stats.average[j][ptr->class] += ptr->lege[j];
3019
            stats.team[j][ptr->class]++;
3020
        }
3021
    }
3022
 
3023
    /*
3024
     * Calculate the averages
3025
     */
3026
    for( k = 0; k <= config.num_legs; k++ )
3027
    {
3028
        for( j = 0; j <= config.num_class; j++ )
3029
        {
3030
            if( stats.team[k][j] )
3031
                stats.average[k][j] /= stats.team[k][j];
3032
            else
3033
                stats.average[k][j] = ( time_t ) - 1;
3034
        }
3035
    }
3036
}
3037
 
3038
/********************************* EOF ***********************************/