Subversion Repositories svn1-original

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;
33 - 928
    bool        class_done[MAX_CLASS+1];
1 root 929
 
930
    cur( 0, 5 );
931
    printf( "Generate final result printouts\n" );
932
    if( ck_data( -1, C_ELAPSED ) )
933
        return;                                  /* check data for all legs */
934
 
935
    /*
936
    **  If a non HTML report then ask if the user want to supress the class
937
    **  printout. For an HTML report always do the class reports as the two
938
    **  are interlinked
939
    */
29 - 940
    if ( ! report_html  && ! report_all)
1 root 941
    {
942
        suppress_classes = getyes( "Do you want to suppress class printouts" );
943
    }
944
    else
945
    {
946
        suppress_classes = FALSE;
947
    }
948
 
949
    /*
950
    **  Sort on every thing
951
    **  Then generate all the stats too
952
    */
953
    printf( "\nSorting the data\n" );
954
    do_big_sort();
955
    gen_stats();
956
 
957
    /*
958
     * Now print the data on the printer 
959
     */
960
    printf( "\nGenerating the printed output\n" );
961
    if( !open_printer( "", "finish", 132, report_html, "Finishing Order" ) )
962
        return;
963
 
964
    /*
965
     * Print out the data 
966
     */
967
    print_class_header( -1, TRUE );                      /* Print the header */
968
 
969
    ptr = sort_data;
970
    sort_team_data( 0, S_L );                     /* Re-sort on elapsed time */
971
    for( ptr = sort_data, i = 0; i < sort_num; i++, ptr++ )
972
    {
973
        if ( ptr->class == config.nonequestrian_class )
974
            continue;
975
 
976
        g_record( ptr->team, &team_buf );
977
 
978
        /*
979
        **  If printing an HTML report then we need to mark
980
        **  the entry with a reference so that we can link to it
981
        */
982
        if ( report_html )
983
        {
984
            print( "<A NAME=\"Team_%04d\"></A>",team_buf.numb );
985
        }
986
 
987
        /*
988
        **  Print the basics
989
        **      - Place within complete field
990
        **      - Team number - with HTML reference to team file
991
        **      - Class
992
        */
993
        print( "%4.4s ", pr_place( team_buf.leg[0].l_place, ptr->flags.bad_times ) );
994
        if ( report_html ) print( "<A HREF=\"%s#Team_%04d\">", p_filename(filebase, "name" ,"html"), team_buf.numb );
995
        print( "%4d",  team_buf.numb );
996
        if ( report_html ) print( "</A>" );
997
 
998
        print( " %-*s", 3, team_buf.class == 0 ? "" : config.team_class[team_buf.class - 1].abr );
999
 
1000
        /*
1001
        **  Print the per-leg data
1002
        **      - Time
1003
        **      - Leg place
1004
        **      - End place
1005
        */
1006
        for( j = 1; j <= config.num_legs; j++ )
1007
        {
13 david 1008
            /*
1009
            **  Ensure that non-equestrian leg data is not displayed
1010
            */
1011
            if ( j == config.equestrian_leg && team_buf.flags.non_equestrian )
1012
            {
1013
                print( "  %-8s %4.4s %4.4s", "-- NE --", "-","-");
1014
            }
1015
            else
1016
            {
1017
                print( "  %-8s %4.4s %4.4s",
1 root 1018
                    time_a( team_buf.leg[j].elapsed ),
1019
                    pr_place( team_buf.leg[j].l_place, ptr->flags.bad_times ),
1020
                    pr_place( team_buf.leg[j].le_place,ptr->flags.bad_times )
1021
                  );
13 david 1022
            }
1 root 1023
        }
1024
 
24 - 1025
       /*
1 root 1026
        **  Print the trailer
1027
        **      - Total time
1028
        **      - Category place - with reference to category file
1029
        */
1030
        print( "  %-8s ",  time_a( team_buf.leg[0].elapsed ) );
1031
        if ( report_html ) print( "<A HREF=\"%s#Team_%04d\">",p_filename(filebase, config.team_class[team_buf.class - 1].abr ,"html"), team_buf.numb );
1032
        print( "%-4.4s", pr_place( team_buf.leg[0].lc_place, ptr->flags.bad_times ) );
1033
        if ( report_html ) print( "</A>" );
1034
 
1035
        print( "\n" );
1036
    }
1037
 
1038
    print_class_stats( -1, TRUE );              /* Print statistics */
18 david 1039
    print_legend(-1, 1 );                       /* Print the legend */
1 root 1040
    close_printer();                            /* Close the printer */
1041
 
1042
    /*
1043
     * Now produce a breakdown on a class by class basis 
1044
     * Now print out the class placement information
1045
     */
1046
 
1047
    if( suppress_classes )
1048
    {
1049
        printf( "WARNING: Class printouts suppressed\n" );
1050
        return;
1051
    }
1052
 
1053
    sort_team_data( 0, S_LC );                 /* Generate class placement data */
1054
    last_class = -1;                           /* Invalid class to start with */
33 - 1055
    memset ( class_done, 0, sizeof(class_done));
1 root 1056
 
33 - 1057
 
1 root 1058
    for( ptr = sort_data, i = 0; i < sort_num; i++, ptr++ )
1059
    {
1060
        /*
1061
        **  Detect a change in the "class"
1062
        **  All data is within the one array of data
1063
        **  Use the in-memory class as this MAY differ from that stored
1064
        **  The non-equestrian class does this.
1065
        */
1066
        if( last_class != ptr->class )
1067
        {
1068
            if( last_class >= 0 )
1069
            {
1070
                print_class_stats( last_class, TRUE );
18 david 1071
                print_legend( last_class, 1 );
1 root 1072
                close_printer();
1073
            }
1074
 
1075
            report_title = tprintf( "Category results for : %-*s", LEN_CLASS_NAME, ptr->class == 0 ? "" : config.team_class[ptr->class - 1].full_name );
1076
 
1077
            if( !open_printer( "", config.team_class[ptr->class - 1].abr, 132, report_html, report_title ) )
1078
                continue;
1079
            print_class_header( last_class = ptr->class, TRUE );
33 - 1080
 
1081
            /*
1082
            **  Mark the class as done
1083
            */
1084
            class_done[ptr->class] = TRUE;
1 root 1085
        }
1086
 
1087
        /*
1088
        **  Now read in the team record
1089
        */
1090
        g_record( ptr->team, &team_buf );
1091
 
1092
        /*
1093
        **  If printing an HTML report then we need to mark
1094
        **  the entry with a reference so that we can link to it
1095
        */
1096
        if ( report_html )
1097
            print( "<A NAME=\"Team_%04d\"></A>",team_buf.numb );
1098
 
1099
        /*
1100
        **  Print the basics
1101
        **      - Place within the class
1102
        **      - Team number - with HTML reference to team file
1103
        **      - Class
1104
        */
1105
 
1106
        print( "%4.4s ", pr_place( team_buf.leg[0].lc_place, ptr->flags.bad_times ) );
1107
        if ( report_html ) print( "<A HREF=\"%s#Team_%04d\">", p_filename(filebase, "name" ,"html"), team_buf.numb );
1108
        print( "%4d",  team_buf.numb );
1109
        if ( report_html ) print( "</A>" );
1110
        print( " %-*s", 3, team_buf.class == 0 ? "" : config.team_class[team_buf.class - 1].abr );
1111
 
1112
        for( j = 1; j <= config.num_legs; j++ )
1113
        {
1114
            /*
1115
            **  Ensure that non-equestrian leg data is not displayed
1116
            */
1117
            if ( j == config.equestrian_leg && ptr->class == config.nonequestrian_class)
1118
            {
13 david 1119
                print( "  %-8s %4.4s %4.4s", "-- NE --", "-","-");
1 root 1120
            }
1121
            else
1122
            {
1123
                print( "  %-8s %4.4s %4.4s", time_a( team_buf.leg[j].elapsed ),
1124
                       pr_place( team_buf.leg[j].lc_place, ptr->flags.bad_times ),
1125
                       pr_place( team_buf.leg[j].lec_place, ptr->flags.bad_times ) );
1126
            }
1127
        }
1128
 
1129
        /*
1130
        **  Print the trailer
1131
        **      - Total time
1132
        **      - Overall place - with reference to overall place file
1133
        */
1134
        /* print( "  %-8s ", time_a( team_buf.leg[0].elapsed ) ); */
1135
        print( "  %-8s ", time_a( ptr->lege[0] ) );
1136
 
1137
        if ( report_html ) print( "<A HREF=\"%s#Team_%04d\">", p_filename(filebase, "finish" ,"html"), team_buf.numb );
1138
        print( "%4.4s", pr_place( team_buf.leg[0].l_place, ptr->flags.bad_times | (ptr->class == config.nonequestrian_class) ) );
1139
        if ( report_html ) print( "</A>" );
1140
 
1141
        print( "\n" );
1142
    }
1143
 
1144
    print_class_stats( last_class, TRUE );
18 david 1145
    print_legend(last_class,1);
1 root 1146
    close_printer();
1147
 
33 - 1148
    /*
1149
    **  Pickup missed classes and create a report
1150
    */
1151
    for( j = 1; j <= config.num_class; j++ )
1152
    {
1153
        if ( class_done[j] )
1154
        {
1155
            continue;
1156
        }
1 root 1157
 
33 - 1158
        report_title = tprintf( "Category results for : %-*s", LEN_CLASS_NAME, config.team_class[j - 1].full_name );
1159
 
1160
        if( !open_printer( "", config.team_class[j - 1].abr, 132, report_html, report_title ) )
1161
            continue;
1162
        print_class_header( j-1, TRUE );
1163
        print( "\nThere were no competitors in this class\n" );
1164
        print_legend(j,1);
1165
        close_printer();
1166
    }
1167
 
1168
 
1 root 1169
    /*
1170
    **  If we are generating an HTML report then we need to create the file
1171
    **  that contains all the team names - the assumption is that this data
1172
    **  is available
1173
    */
1174
    if ( report_html )
1175
    {
1176
        pri_team();
1177
    }
1178
 
1179
    /*
1180
    **  Generate the awards report.
1181
    **  This is only available as an HTML report
1182
    */
1183
    if ( report_html )
1184
    {
1185
        pri_awards();
1186
    }
1187
 
1188
    /*
1189
    **  Generate the master index page
1190
    */
1191
    if ( report_html )
1192
    {
1193
        pri_master_index();
1194
    }
1195
 
18 david 1196
    pri_name_index_body();
1197
 
1 root 1198
}
1199
 
1200
/*========================================================================
1201
 *
1202
 *  Place to text
1203
 *
1204
 *  Purpose:
1205
 *      This function is called to convert a place to text
1206
 *
1207
 *  Parameters:
1208
 *      place
1209
 *
1210
 *  Returns:
1211
 *      text
1212
 *
1213
 *========================================================================*/
1214
 
1215
char *placing ( int place )
1216
{
1217
    if ( place > MAX_PLACE )
1218
    {
1219
        return tprintf( "Place: %d", place);
1220
    }
1221
    return tprintf ("%s Place", place_text[place]);
1222
}
1223
 
1224
/*========================================================================
1225
 *
1226
 *  Print award results
1227
 *
1228
 *  Purpose:
1229
 *      This function is called to Print award results
27 - 1230
 *      Keep the page to 80 cols, so that it can be pronted on A4
1 root 1231
 *
1232
 *  Parameters:
1233
 *      None
1234
 *
1235
 *  Returns:
1236
 *      Nothing
1237
 *
1238
 *========================================================================*/
1239
void pri_awards(void)
1240
{
1241
    int j;
1242
    int i;
1243
    int k;
1244
    int windex;
1245
    ty_s_data  *ptr;
1246
    int         last_class;
1247
 
1248
    report_html = 1;
27 - 1249
    if( !open_printer( "", "awards", 80, report_html, "Prizes and Awards" ) )
1 root 1250
        return;
1251
 
1252
    /*
1253
    **  Generate an index for this page
1254
    */
1255
    print( "\n");
1256
    print( "<hr>" );
1257
    print( "<A NAME=\"%s\"></A>","INDEX");
1258
    print( "Award Categories");
1259
 
1260
    for( j = 1; j <= config.num_class; j++ )
1261
    {
1262
        /*
1263
        **  Header for the class
1264
        */
1265
        if ( config.class_winners[j-1] <= 0 )
1266
            continue;
1267
 
1268
        print( "\n");
1269
        print( "    <A HREF=\"#%s\">",config.team_class[j-1].full_name);
1270
        print( "%s",  config.team_class[j-1].full_name );
1271
        print( "</A>" );
1272
    }
1273
 
1274
    /*
1275
    **  Manual entries
1276
    */
1277
    print( "\n");
1278
    print( "    <A HREF=\"#%s\">","Hall Of Fame");
1279
    print( "%s",  "Hall Of Fame" );
1280
    print( "</A>" );
1281
 
1282
    print( "\n");
1283
    print( "    <A HREF=\"#%s\">","FASTEST");
1284
    print( "%s",  "FASTEST" );
1285
    print( "</A>" );
1286
 
1287
    /*
1288
    **  Sort the data by class
1289
    */
1290
    sort_team_data( 0, S_LC );      /* Generate class placement data */
1291
    last_class = -1;                /* Invalid class to start with */
1292
 
1293
    /*
1294
    **  Process each category
1295
    */
1296
    for( j = 1; ; j++ )
1297
    {
1298
        /*
1299
        **  Tail for previous entry
1300
        */
1301
        if ( j != 1 )
1302
            print( "<A HREF=\"#%s\">Awards Index</A>","INDEX");
1303
 
1304
        if ( j > config.num_class  )
1305
            break;
1306
 
1307
        /*
1308
        **  Header for the class
1309
        */
1310
        print( "\n");
1311
        print( "<hr>" );
1312
        print( "<A name=\"%s\"></A>",config.team_class[j-1].full_name);
1313
        print( "<A HREF=\"%s\">",p_filename(filebase, config.team_class[j - 1].abr ,"html"));
1314
        print( "%s",  config.team_class[j-1].full_name );
1315
        print( "</A>" );
1316
 
1317
                if ( config.class_winners[j-1] <= 0 )
1318
        {
1319
            print( "\n");
1320
            print( "No winners awarded" );
1321
            continue;
1322
        }
1323
 
1324
        /*
1325
        **  Enties for 'n' the best teams as configured
1326
        */
1327
        windex = 0;                     /* Winners done */
1328
        for( ptr = sort_data, i = 0; i < sort_num; i++, ptr++ )
1329
        {
1330
            if ( ptr->class != j )
1331
            {
1332
                continue;
1333
            }
1334
 
1335
            /*
1336
            **  Now read in the team record
1337
            */
1338
            if( valid_field( ptr->team ) && g_record( ptr->team, &team_buf ) )
1339
            {
1340
                windex++;
1341
 
1342
                /*
1343
                **  If printing an HTML report then we need to mark
1344
                **  the entry with a reference so that we can link to it
1345
                */
1346
                print( "\n");
1347
                print( "<A NAME=\"Team_%04d\">",team_buf.numb );
1348
                print( "</A>" );
1349
 
1350
                /*
1351
                **  Basic information
1352
                **      - Team number - with Xref back to full result
1353
                **      - Full team name
1354
                **      - Full categoray name
1355
                */
1356
                print( "%s", placing(windex) );
1357
 
1358
                print( "  Team Name: <A HREF=\"%s#Team_%04d\">", p_filename(filebase, "name" ,"html"), team_buf.numb );
1359
                print( "%-*s ",     MAX_TM_NAME, team_buf.name );
1360
                print( "</A>" );
1361
 
1362
                print( "  Number: <A HREF=\"%s#Team_%04d\">", p_filename(filebase, "finish" ,"html"), team_buf.numb );
1363
                print( "%4d",       team_buf.numb );
1364
                print( "</A>" );
1365
 
1366
 
1367
                for( k = 0; k < MAX_MEMB; k++ )
1368
                {
1369
 
1370
                    /*
1371
                    **  Skip equestrian leg in the non-equestion display
1372
                    */
1373
                    if ( k + 1 == config.equestrian_leg && ptr->class == config.nonequestrian_class)
1374
                        continue;
1375
 
1376
                    print( "\n");
1377
                    print( "    ");
1378
                    print( "%-*s", MAX_PERSON_NAME, config.leg_name[k] ? config.leg_name[k] : "Competitor"  );
1379
                    print( " %-*s", MAX_PERSON_NAME, team_buf.members[k].name );
1380
 
1381
                    print( "  %-8s", time_a( team_buf.leg[k+1].elapsed ) );
1382
                }
1383
 
1384
                print( "\n");
1385
                print( "    ");
1386
                print_bold( TRUE );
1387
                print( "%-*s %-*s  %-8s", MAX_PERSON_NAME , "Total" ,MAX_PERSON_NAME, "",time_a( team_buf.leg[0].elapsed ) );
1388
                print_bold( FALSE );
1389
                print( "\n" );
1390
            }
1391
 
1392
 
1393
            /*
1394
            **  More to do
1395
            */
1396
            if ( windex >= config.class_winners[j-1] )
1397
            {
1398
                break;
1399
            }
1400
        }
1401
    }
1402
 
1403
    /*
1404
    **  Generate the Hall of Fame information
1405
    */
1406
    print( "\n");
1407
    print( "<hr>" );
1408
    print( "<A name=\"%s\"></A>","Hall Of Fame");
1409
    print( "%s",  "Hall of Fame" );
1410
 
1411
    if ( config.num_fame  )
1412
    {
1413
        for( i = 1; i <= config.num_fame; i++ )
1414
        {
1415
            print( "\n    %-*s", MAX_PERSON_NAME, config.hall_fame[i-1] );
1416
        }
1417
    }
1418
    else
1419
    {
1420
        printf( "\n    There are no new stars for the Hall of Fame");
1421
    }
1422
    print( "<p><A HREF=\"#%s\">Awards Index</A>","INDEX");
1423
 
1424
    /*
1425
    **  Generate the FASTEST information
1426
    */
1427
    print( "<hr>" );
1428
    print( "<A name=\"%s\"></A>","FASTEST");
1429
    print( "%s",  "FASTEST" );
1430
 
1431
    /*
1432
    **  Sort the data and then generate the stats - again
1433
    */
1434
    do_big_sort();
1435
    gen_stats();
1436
 
1437
    for( i = 1; i <= config.num_legs; i++ )
1438
    {
1439
        g_record( stats.fast.team[i][0], &team_buf );
1440
 
1441
        print( "\n");
1442
        print( "    %-13s ", config.leg_name[i - 1] );
17 david 1443
        print( "  Name: <A HREF=\"%s#Team_%04d\">", p_filename(filebase, "name" ,"html"), team_buf.numb );
1 root 1444
        print( "%-*s", MAX_PERSON_NAME, team_buf.members[i-1].name );
1445
        print( "</A>" );
1446
        print( "  Team :<A HREF=\"%s#Team_%04d\">", p_filename(filebase, "finish" ,"html"), team_buf.numb );
27 - 1447
        print( "%4d" , stats.fast.team[i][0] );
1448
        print( "</A> " );
1449
        print( "Time:%s ", time_a( stats.fast.time[i][0] ) );
1 root 1450
 
1451
    }
1452
 
1453
 
17 david 1454
 
1455
 
1 root 1456
    print( "<p><A HREF=\"#%s\">Awards Index</A>","INDEX");
1457
    close_printer();
1458
}
1459
 
1460
/*========================================================================
1461
 *
1462
 *  pri_master_index
1463
 *
1464
 *  Purpose:
1465
 *      This function is called to create an HTML page that references all
1466
 *      the other pages that have been generated
1467
 *
1468
 *      Assume that they are in the same directory
1469
 *
1470
 *  Parameters:
1471
 *      None
1472
 *
1473
 *  Returns:
1474
 *      Nothing
1475
 *
1476
 *========================================================================*/
1477
void pri_master_index_entry(char *name, char *text)
1478
{
1479
    print( "<tr><td>");
1480
    print ("<A HREF=\"%s\">%s</A>\n", p_filename(filebase, name ,"html"), text );
1481
}
1482
 
1483
 
1484
void pri_master_index(void)
1485
{
1486
    int j;
1487
 
1488
    report_html = 1;
1489
    if( !open_printer( "", "index", 132, report_html, "Master Index" ) )
1490
        return;
1491
 
1492
    /*
1493
    **  Names
1494
    */
1495
    print( "<TABLE border=0 align=center>" );
18 david 1496
    pri_master_index_entry( "name", "Team list" );
1497
    pri_master_index_entry( "competitor", "Competitor list" );
1 root 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
    }
32 - 1507
 
1 root 1508
    print( "</TABLE>" );
1509
 
1510
    close_printer();
32 - 1511
 
1512
    /*
1513
    **  A small page to hold the Leg End displays
1514
    */
1515
 
1516
    if( !open_printer( "", "legindex", 132, report_html, "Master Index with trace data" ) )
1517
        return;
1518
 
1519
    /*
1520
    **  Names
1521
    */
1522
    print( "<TABLE border=0 align=center>" );
1523
#if 1
1524
    pri_master_index_entry( "name", "Team list" );
1525
    pri_master_index_entry( "competitor", "Competitor list" );
1526
    pri_master_index_entry( "finish", "Finishing Order for all Teams" );
1527
    pri_master_index_entry( "awards", "Prizes and Awards" );
1528
    print( "<tr><td>\n" );
1529
 
1530
    print( "\n" );
1531
    for( j = 1; j <= config.num_class; j++ )
1532
    {
1533
        pri_master_index_entry( config.team_class[j - 1].abr, tprintf("Category Results for: %s", config.team_class[j-1].full_name) );
1534
    }
1535
#endif
1536
    print( "<tr><td>\n" );
1537
 
1538
    print( "\n" );
1539
    for ( leg = 1; leg <= config.num_legs; leg ++ )
1540
    {
1541
        pri_master_index_entry( tprintf("lg%1.1d", leg), tprintf("Leg End Results for: %d", leg) );    
1542
    }
1543
 
1544
    print( "<tr><td>\n" );
1545
    print( "\n" );
1546
 
1547
    for ( leg = 1; leg <= config.num_legs; leg ++ )
1548
    {
1549
        pri_master_index_entry( tprintf("le%1.1d", leg), tprintf("Leg Elapsed Time Results for: %d", leg) );
1550
    }    
1551
 
1552
 
1553
    print( "</TABLE>" );
1554
 
1555
    close_printer();
1556
 
1 root 1557
}
1558
 
1559
 
1560
/*========================================================================
1561
 *
1562
 *  Print interim results
1563
 *
1564
 *  Purpose:
1565
 *      This function is called to Print interim results
1566
 *
1567
 *  Parameters:
1568
 *      None
1569
 *
1570
 *  Returns:
1571
 *      Nothing
1572
 *
1573
 *========================================================================*/
1574
 
1575
void pri_interim(void)
1576
{
1577
    ty_s_data  *ptr;
1578
    unsigned    i;
1579
    int         j, last_class;
29 - 1580
    char        suppress_classes = FALSE;                /* Boolean. Printout class files too */
1 root 1581
    char       *report_title;
1582
 
29 - 1583
    if ( ! report_all )
1584
    {
1585
        cur( 0, 5 );
1586
        printf( "Generate interim result printouts\n" );
1587
        ck_data( -1, C_DISQUAL );                    /* Check the data - dummy check */
1588
        suppress_classes = getyes( "Do you want to suppress class printouts" );
1589
        printf( "\nSorting the data\n" );
1590
    }
1 root 1591
    do_big_sort();                             /* Sort on every thing */
1592
    gen_stats();                               /* Generate the stats too */
1593
 
1594
    printf( "\nGenerating the printed output\n" );
1595
 
1596
    /*
1597
     * Now print the data on the printer 
1598
     */
1599
 
1600
    if( !open_printer( "", "int", 132, report_html, "Interim Results" ) )
1601
        return;
1602
 
1603
    /*
1604
     * Print out the data 
1605
     */
1606
    print_class_header( -1, FALSE );                     /* Print the header */
1607
 
1608
    ptr = sort_data;
1609
    sort_team_data( 0, S_TEAM );                   /* Re-sort on team number */
1610
    for( ptr = sort_data, i = 0; i < sort_num; i++, ptr++ )
1611
    {
1612
        if ( ptr->class == config.nonequestrian_class )
1613
            continue;
1614
 
1615
        g_record( ptr->team, &team_buf );
1616
 
1617
        print( "%4d %4.4s %-*s",
1618
               team_buf.numb,
1619
               pi_place( team_buf.leg[config.num_legs].le_place,
1620
                         ptr->flags.disqualified, team_buf.leg[0].elapsed ),
1621
               3,
1622
               team_buf.class ==
1623
 
1624
        for( j = 1; j <= config.num_legs; j++ )
1625
        {
1626
            print( "  %-8s %4.4s %4.4s",
1627
                   time_fa( team_buf.leg[j].elapsed,
1628
                            ptr->flags.disqualified ),
1629
                   pi_place( team_buf.leg[j].l_place, ptr->flags.disqualified,
1630
                             team_buf.leg[j].elapsed ),
1631
                   pi_place( team_buf.leg[j].le_place,
1632
                             ptr->flags.disqualified,
1633
                             team_buf.leg[j].elapsed ) );
1634
        }
1635
        print( "  %-8s %4.4s\n",
1636
               time_fa( team_buf.leg[0].elapsed, ptr->flags.disqualified ),
1637
               pi_place( team_buf.leg[config.num_legs].lec_place,
1638
                         ptr->flags.disqualified, team_buf.leg[0].elapsed ) );
1639
    }
1640
 
1641
    print_class_stats( -1, FALSE );             /* Print statistics */
18 david 1642
    print_legend(-1, 1);                        /* Print the legend */
1 root 1643
    close_printer();                            /* Close the printer */
1644
 
1645
 
1646
    /*
1647
     * Now produce a breakdown on a class by class basis 
1648
     * Now print out the class placement information
1649
     */
1650
 
1651
    if( suppress_classes )
1652
    {
1653
        printf( "WARNING: Class printouts suppressed\n" );
1654
        return;
1655
    }
1656
 
1657
    sort_team_data( 0, S_CLASS );              /* Generate class placement data */
1658
    last_class = -1;                             /* Invalid class to start with */
1659
 
1660
    for( ptr = sort_data, i = 0; i < sort_num; i++, ptr++ )
1661
    {
1662
        /*
1663
        **  Detect a change in the "class"
1664
        **  All data is within the one array of data
1665
        **  Use the in-memory class as this MAY differ from that stored
1666
        **  The non-equestrian class does this.
1667
        */
1668
        if( last_class != ptr->class )
1669
        {
1670
            if( last_class >= 0 )
1671
            {
1672
                print_class_stats( last_class, TRUE );
18 david 1673
                print_legend(last_class, 1);
1 root 1674
                close_printer();
1675
            }
1676
 
1677
            report_title = tprintf( "Interim Category results for : %-*s", LEN_CLASS_NAME, team_buf.class == 0 ? "" : config.team_class[ptr->class - 1].full_name );
1678
 
1679
            if( !open_printer( "", tprintf( "i%2s", config.team_class[ptr->class - 1].abr ), 132, report_html, report_title ) )
1680
                continue;
1681
            print_class_header( last_class = ptr->class, FALSE );
1682
        }
1683
 
1684
        /*
1685
        **  Now read in the team record
1686
        */
1687
        g_record( ptr->team, &team_buf );
1688
        print( "%4d %4.4s %-*s",
1689
               team_buf.numb,
1690
               pi_place( team_buf.leg[config.num_legs].lec_place,
1691
                         ptr->flags.disqualified, team_buf.leg[0].elapsed ),
1692
               3,
1693
               team_buf.class ==
1694
 
1695
        for( j = 1; j <= config.num_legs; j++ )
1696
        {
1697
            print( "  %-8s %4.4s %4.4s",
1698
                   time_fa( team_buf.leg[j].elapsed,
1699
                            ptr->flags.disqualified ),
1700
                   pi_place( team_buf.leg[j].lc_place,
1701
                             ptr->flags.disqualified,
1702
                             team_buf.leg[j].elapsed ),
1703
                   pi_place( team_buf.leg[j].lec_place,
1704
                             ptr->flags.disqualified,
1705
                             team_buf.leg[j].elapsed ) );
1706
        }
1707
        print( "  %-8s %4.4s\n",
1708
               time_fa( team_buf.leg[0].elapsed, ptr->flags.disqualified ),
1709
               pi_place( team_buf.leg[config.num_legs].le_place,
1710
                         ptr->flags.disqualified, team_buf.leg[0].elapsed ) );
1711
    }
1712
 
1713
    print_class_stats( last_class, FALSE );
18 david 1714
    print_legend(last_class, 1);
1 root 1715
    close_printer();
1716
 
1717
}
1718
 
1719
/*========================================================================
1720
 *
29 - 1721
 *  Print all reports at once
1722
 ^  Its all so fast, these days ...
1723
 *
1724
 *  Purpose:
1725
 *      This function is called to print all reports at once
1726
 *
1727
 *  Parameters:
1728
 *      None
1729
 *
1730
 *  Returns:
1731
 *      Nothing
1732
 *
1733
 *========================================================================*/
1734
 
1735
void pri_all_reports ( void )
1736
{
1737
    int leg;
1738
    report_all = TRUE;
1739
 
1740
    pri_team();
1741
 
1742
    for ( leg = 1; leg <= config.num_legs; leg ++ )
1743
    {
1744
        pri_leg_body ( leg );
1745
        pri_eleg_body ( leg );
32 - 1746
 
1747
        report_html = TRUE;
1748
 
1749
        pri_leg_body ( leg );
1750
        pri_eleg_body ( leg );        
1751
 
1752
        report_html = FALSE;
29 - 1753
    }
1754
 
1755
    pri_final();
1756
    pri_final_html();
1757
    pri_summary();
1758
    pri_awards();
1759
    pri_master_index();
1760
 
1761
    report_all = FALSE;
1762
}
1763
 
1764
 
1765
/*========================================================================
1766
 *
1 root 1767
 *  Print a class header
1768
 *
1769
 *  Purpose:
1770
 *      This function is called to print a class header
1771
 *
1772
 *  Parameters:
1773
 *      class           Name of this class
1774
 *      final           False - prelim results
1775
 *
1776
 *  Returns:
1777
 *      Nothing
1778
 *
1779
 *========================================================================*/
1780
 
1781
void print_class_header( int class, int final )
1782
{
1783
    int         j;
1784
 
1785
    /*
1786
    **  Give a clear indication that the report is preliminary
1787
    */
1788
 
1789
    if( !final )
1790
        print( "PRELIMINARY RESULTS ONLY\n\n" );
1791
 
1792
    /*
1793
    **  Now printout the column headings
1794
    **  This is a two line display
1795
    **
1796
    **  Line-1  Leg names
1797
    */
1798
    print( "%-*s %-*s %-*s", 4, "", 4, "", 3, "" );
1799
    for( j = 1; j <= config.num_legs; j++ )
1800
    {
1801
        print_bold( TRUE );
1802
        print( "  %-*s", 18, config.leg_name[j - 1] );
1803
        print_bold( FALSE );
1804
    }
1805
    print( "  %-8s %-4s\n", "Total", ( class < 0 ) ? "Cat" : "Fin" );
1806
 
1807
 
1808
    /*
1809
    **  Line-2  Details
1810
    */
1811
    print_underline( TRUE );
1812
    print( "%-*s %*s %-*s", 4, final ? "Plce" : "Team",
1813
                            4, final ? "Team" : "Plce",
1814
                            3, "Cat" );
1815
 
1816
    for( j = 1; j <= config.num_legs; j++ )
1817
        print( "  %-8s %-4s %-4s", "Time", " LP", " EP" );
1818
 
1819
    print( "  %-8s %-4s\n", "Time", "Plce" );
1820
    print_underline( FALSE );
1821
}
1822
 
1823
/*========================================================================
1824
 *
1825
 *  Generate the class stats
1826
 *
1827
 *  Purpose:
1828
 *      This function is called to Generate the class stats
1829
 *
1830
 *  Parameters:
1831
 *      c           Class to print
1832
 *      final       TRUE: Final data
1833
 *                  FALSE: Interim data
1834
 *
1835
 *  Returns:
1836
 *      Nothing
1837
 *
1838
 *========================================================================*/
1839
 
1840
void print_class_stats( int c, int final )
1841
{
1842
    int         i, j;
1843
    char        *title;
1844
 
1845
    if( c < 0 )
1846
    {
1847
        title = "Event";
1848
        c = 0;
1849
    }
1850
    else
1851
    {
1852
        title = "Category";
1853
    }
1854
 
1855
    print( "\n" );
1856
    if ( report_html ) print_underline(TRUE);
1857
    print( "%s statistics", title );
1858
    if ( report_html ) print_underline(FALSE);
1859
    print( "\n" );
1860
 
1861
 
1862
    /*
1863
    **  Print the names of the different legs
1864
    */
1865
    print( "%-*s       ", LEN_CLASS_NAME, "" );
1866
    for( i = 1; i <= config.num_legs; i++ )
1867
    {
1868
        print_bold( TRUE );
1869
        print( "%-13s  ", config.leg_name[i - 1] );
1870
        print_bold( FALSE );
1871
    }
1872
    print( "%-13s  \n", final ? "Total" : "" );
1873
 
1874
    /*
1875
    **  Print the fastest teams for each leg and overall
1876
    **  Add cross references to the team names for the fastest teams
1877
    */
1878
    print( "%*s : ", LEN_CLASS_NAME, "Fastest" );
1879
    for( i = 0; i <= config.num_legs; i++ )
1880
    {
1881
        j = i + 1;
1882
        if( i >= config.num_legs )
1883
        {
1884
            if( final )
1885
                j = 0;                           /* Leg-0 last */
1886
            else
1887
                break;
1888
        }
1889
 
1890
        if ( report_html ) print( "<A HREF=\"%s#Team_%04d\">", p_filename(filebase, "name" ,"html"), stats.fast.team[j][c] );
1891
        print( "%4d",  stats.fast.team[j][c] );
1892
        if ( report_html ) print( "</A>" );
1893
        print( " %s  ", time_a( stats.fast.time[j][c] ) );
1894
    }
1895
    print( "\n" );
1896
 
1897
    /*
1898
    **  Print the average time for each leg
1899
    */
1900
    print( "%*s : ", LEN_CLASS_NAME, "Average" );
1901
    for( i = 0; i <= config.num_legs; i++ )
1902
    {
1903
        j = i + 1;
1904
        if( i >= config.num_legs )
1905
        {
1906
            if( final )
1907
                j = 0;                           /* Leg-0 last */
1908
            else
1909
                break;
1910
        }
1911
        print( "     %s  ", time_a( stats.average[j][c] ) );
1912
    }
1913
}
1914
 
1915
/*========================================================================
1916
 *
1917
 *  Print the legend
1918
 *
1919
 *  Purpose:
1920
 *      This function is called to Print the legend
1921
 *
1922
 *  Parameters:
1923
 *      class       - Class currently being printed
18 david 1924
 *      full        - Display full legend
1 root 1925
 *
1926
 *  Returns:
1927
 *      Nothing
1928
 *
1929
 *========================================================================*/
1930
 
18 david 1931
void print_legend ( int class, int full )
1 root 1932
{
1933
 
1934
    int         i;
1935
    char        line[201];
1936
    FILE       *adfile = NULL;
1937
    int         count;
1938
 
1939
    /*
1940
     * First the categories 
1941
     */
1942
    print( "\n\n" );
1943
    if ( report_html ) print_underline(TRUE);
1944
    print( "Category abbreviations" );
1945
    if ( report_html ) print_underline(FALSE);
1946
    print( "\n" );
1947
 
1948
 
1949
    for( i = 1, count = 0; i <= config.num_class; i++ )
1950
    {
1951
#if 0
1952
        /*
1953
        **  Skip any non-equestrian class in the legend
1954
        **  Don't want to tell the general user whats goes on, unless we actually
1955
        **  creating the non-equestrian report.
1956
        */
1957
        if ( class != config.nonequestrian_class  && i == config.nonequestrian_class )
1958
            continue;
1959
#endif
1960
        if ( report_html ) print( "<A HREF=\"%s\">",p_filename(filebase, config.team_class[i - 1].abr ,"html") );
1961
        print( "%-*s", 3, config.team_class[i - 1].abr );
1962
        if ( report_html ) print( "</A>" );
1963
        print( " : %-*s  ", LEN_CLASS_NAME, config.team_class[i - 1].full_name );
1964
 
1965
        if( !( ++count % 5 ) )
1966
            print( "\n" );
1967
    }
1968
 
1969
    /*
1970
    **  Add link to the finish order report
1971
    */
1972
    if ( report_html )
1973
    {
1974
        print( "<A HREF=\"%s\">", p_filename(filebase, "finish" ,"html") );
1975
        print( "%-*s", 3, "All" );
1976
        print( "</A>" );
1977
        print( " : %-*s  ", LEN_CLASS_NAME, "Finishing Order" );
1978
    }
1979
 
1980
    /*
1981
    **  Country data - if countries have been defined
1982
    */
1983
    if( config.num_countries )
1984
    {
1985
        print( "\n\n" );
1986
        if ( report_html ) print_underline(TRUE);
1987
        print( "Country abbreviations" );
1988
        if ( report_html ) print_underline(FALSE);
1989
        print( "\n" );
1990
 
1991
        for( i = 0, count = 0; i < MAX_COUNTRY; i++ )
1992
        {
1993
            if( config.country_name[i].abr[0] )
1994
            {
1995
                print( "%-*s : %-*s  ", 4, config.country_name[i].abr,
1996
                       LEN_CNTRY_NAME, config.country_name[i].full_name );
1997
                if( !( ++count % 5 ) )
1998
                    print( "\n" );
1999
            }
2000
        }
2001
    }
18 david 2002
    print( "\n" );
1 root 2003
 
2004
    /*
2005
     * Other comments 
2006
     */
18 david 2007
    if ( full )
2008
    {
2009
        print( "\nPlace numbers (LP and EP)\n" );
2010
        print( "LP - Placing based on elapsed time within the leg.                Cat Plce - Placing within the category.\n" );
2011
        print( "EP - Placing based on accumulated times to the end of that leg.   Fin Plce - Overall placing within the event.\n" );
2012
    }
1 root 2013
 
2014
    /*
2015
     *  Insert the contents of the config.addendum file
2016
     *  or a defualt message
2017
     */
2018
    if( config.addendum[0] )
2019
        adfile = fopen( config.addendum, "rt" );  /* Open the file for reading */
2020
 
2021
    if( adfile )
2022
    {
2023
        while( fgets( line, sizeof(line)-1, adfile ) )
2024
            print( "%s", line );
2025
    }
2026
    else
2027
    {
2028
        print( "\nTiming and Results by\n" );
2029
        print( "Embedded Solutions\n" );
2030
    }
2031
}
2032
 
2033
/*========================================================================
2034
 *
2035
 *  Return place data
2036
 *
2037
 *  Purpose:
2038
 *      This function is called to return place data
2039
 *
2040
 *      This routine is called to fill a print team_buffer - to allow for
2041
 *      multiple calls to this function ( before the data is used ) a number
2042
 *      of static team_buffers are maintained
2043
 *
2044
 *  Parameters:
2045
 *      num         place - if not bad_times
2046
 *      disq        Disqualified flag
2047
 *      time        Time data is based on
2048
 *
2049
 *  Returns:
2050
 *      This function returns a pointer to the character string for the
2051
 *      number or a pointer to a bad_times string.
2052
 *
2053
 *========================================================================*/
2054
 
2055
char       *pi_place( int num, int disq, time_t time )
2056
{
2057
    static char store[2][5];                     /* 2 stores for 4 digit numbers */
2058
    static int  i = 0;                           /* Current index into store */
2059
    static char *dis = "D";                      /* Disqualified */
2060
    static char *non = "-";                      /* Invalid time */
2061
 
2062
    if( disq )                                   /* Disqualified team */
2063
        return ( dis );
2064
    if( time <= 0 )                              /* Unknown time */
2065
        return ( non );
2066
 
2067
    i++;
2068
    if( i >= 2 )
2069
        i = 0;                                   /* Select next entry */
2070
    sprintf( store[i], "%4d", num );
2071
    return ( store[i] );
2072
 
2073
}
2074
 
2075
/*========================================================================
2076
 *
2077
 *  Return place data
2078
 *
2079
 *  Purpose:
2080
 *      This function is called to Return place data
2081
 *
2082
 *      This routine is called to fill a print team_buffer - to allow for
2083
 *      multiple calls to this function ( before the data is used ) a number
2084
 *      of static team_buffers are maintained
2085
 *
2086
 *  Parameters:
2087
 *      num         place - if not bad_times
2088
 *      disq        Disqualified flag
2089
 *
2090
 *  Returns:
2091
 *      This function returns a pointer to the character string for the
2092
 *      number or a pointer to a bad_times string.
2093
 *
2094
 *========================================================================*/
2095
 
2096
char *pr_place( int num, int disq )
2097
{
2098
    static char store[2][5];                     /* 2 stores for 4 digit numbers */
2099
    static int  i = 0;                           /* Current index into store */
2100
    static char *dis = "U";
2101
 
2102
    if( disq )
2103
        return ( dis );
2104
 
2105
    i++;
2106
    if( i >= 2 )
2107
        i = 0;                                   /* Select next entry */
2108
    sprintf( store[i], "%4d", num );
2109
    return ( store[i] );
2110
 
2111
}
2112
 
2113
/*========================================================================
2114
 *
2115
 *  Check data for bad times
2116
 *
2117
 *  Purpose:
2118
 *      This function is called to Check data for bad times
2119
 *      Scan the sort data structure and locate entries that have incorrect
2120
 *      times.
2121
 *      
2122
 *      Entries that have invalid leg times are displayed to the operator
2123
 *      and the report process can be aborted
2124
 *
2125
 *  Parameters:
2126
 *      leg         Leg to test
2127
 *      mode            Either end or elapsed times to be tested
2128
 *
2129
 *  Returns:
2130
 *      Returns FALSE if the report operation is to be aborted
2131
 *
2132
 *========================================================================*/
2133
 
2134
bool ck_data( int leg, int mode )
2135
{
2136
    ty_s_data  *ptr;
2137
    unsigned    i;
2138
    int         bad = 0;
2139
    int         j = 0;
2140
    int         k, bad_leg;
2141
    time_t     *t;                               /* An array of times */
2142
 
29 - 2143
 
2144
 
1 root 2145
    ptr = sort_data;
2146
    for( i = 1; i <= sort_num; i++, ptr++ )
2147
    {
2148
        bad_leg = 0;
2149
        if( mode == C_DISQUAL )
2150
        {
2151
            ptr->flags.bad_times = ptr->flags.disqualified;
2152
            continue;
2153
        }
2154
 
2155
        if( mode == C_ELAPSED )
2156
            t = ptr->lege;
2157
        else
2158
            t = ptr->leg;
2159
 
2160
        if( ( ptr->flags.bad_times = ptr->flags.disqualified ) == FALSE )
2161
        {
2162
            if( leg <= 0 )
2163
            {
2164
                for( k = 0; k <= config.num_legs; k++ )
2165
                {
2166
                    if ( !(config.equestrian_leg && ptr->flags.non_equestrian && config.equestrian_leg == k  ))
2167
                        bad_leg |= ( t[k] <= 0 );
2168
                }
2169
            }
2170
            else
2171
            {
2172
                bad_leg = t[leg] <= 0;
2173
            }
2174
 
2175
            if( bad_leg )
2176
            {
2177
                ptr->flags.bad_times = TRUE;
29 - 2178
 
2179
                if ( ! report_all )
1 root 2180
                {
29 - 2181
                    if( !bad )
2182
                        printf( "Team with incorrect time information\n" );
2183
                    if( ++j > 15 )
2184
                    {
2185
                        printf( "\n" );
2186
                        j = 0;
2187
                    }
2188
                    printf( "%4d ", ptr->team );
2189
                    bad++;
1 root 2190
                }
2191
            }
2192
        }
2193
    }
2194
 
2195
    if( bad )
2196
    {
2197
        printf( "\n%d teams with incorrect times.\n", bad );
2198
        return ( !getyes
2199
                 ( "These have been flagged as unplaced - continue report" ) );
2200
    }
2201
    return ( FALSE );
2202
}
2203
 
2204
/*========================================================================
2205
 *
2206
 *  Update placing information
2207
 *
2208
 *  Purpose:
2209
 *      This function is called to Update placing information
2210
 *
2211
 *      This routine will rip through the data generating the team placing in
2212
 *      a) Within a leg
2213
 *      b) At the end of a leg
2214
 *      c) Within a leg by  class
2215
 *      d) At the end of a leg by class
2216
 *
2217
 *      This function is provided to allow the display routines to
2218
 *      be accessed and updated without the need to run a report
2219
 *
2220
 *  Parameters:
2221
 *      xxxx        a ptr to the xxxx stuff
2222
 *
2223
 *  Returns:
2224
 *      Nothing
2225
 *
2226
 *========================================================================*/
2227
 
2228
void srt_place(void)
2229
{
2230
    int         i, j;
2231
 
2232
    cur( 0, 5 );
2233
    printf( "Update the team placings to the data base\n" );
2234
    flush_out();
2235
    if( ck_data( -1, C_ELAPSED ) )
2236
        return;
2237
    do_big_sort();
2238
 
2239
    /*
2240
     * Generate the stats and display them on the screen for interest
2241
     * This operation will not hurt - so why not
2242
     */
2243
 
2244
    gen_stats();
2245
    printf( "\nEvent statistics\n\n" );
2246
    printf( "%-*s   %-13s ", LEN_CLASS_NAME, "", "Overall" );
2247
    for( i = 1; i <= config.num_legs; i++ )
2248
        printf( "%-13s ", config.leg_name[i - 1] );
2249
 
2250
    for( j = 0; j <= config.num_class; j++ )
2251
    {
2252
        printf( "\n%-*s : ", LEN_CLASS_NAME,
2253
                j ? config.team_class[j - 1].full_name : "Overall" );
2254
        for( i = 0; i <= config.num_legs; i++ )
2255
        {
2256
            printf( "%4d ", stats.fast.team[i][j] );
2257
            printf( "%s ", time_a( stats.fast.time[i][j] ) );
2258
        }
2259
        printf( "\n%*s : ", LEN_CLASS_NAME, "Average" );
2260
        for( i = 0; i <= config.num_legs; i++ )
2261
        {
2262
            printf( "     %s ", time_a( stats.average[i][j] ) );
2263
        }
2264
    }
2265
    printf( "\nAny key to continue" );
2266
    ( void ) getinp();
2267
}
2268
 
2269
/*========================================================================
2270
 *
2271
 *  Calculate summary information
2272
 *
2273
 *  Purpose:
2274
 *      This function is called to calculate summary information
2275
 *
2276
 *  Parameters:
2277
 *      ptr         - Address of a summary structure to fill in
2278
 *
2279
 *  Returns:
2280
 *      Nothing
2281
 *
2282
 *========================================================================*/
2283
 
2284
void calc_class_summary( t_class_summary * ptr )
2285
{
2286
    int i;
2287
 
2288
    /*
2289
    **  Reset the data
2290
    */
2291
    memset ( ptr, 0, sizeof (*ptr ));
2292
 
2293
    /*
2294
     * Extract the required data from the data base
2295
     * Only save that information required for the operation
2296
     */
2297
 
2298
    for( i = config.min_team; i <= config.max_team; i++ )
2299
    {
2300
        if( valid_field( i ) && g_record( i, &team_buf ) )
2301
        {
2302
            ptr->total.total++;
2303
            ptr->class[team_buf.class].total++;
2304
 
2305
            if ( team_buf.flags.disqualified )
2306
            {
2307
                ptr->class[team_buf.class].disqualified++;
2308
                ptr->total.disqualified++;
2309
            }
2310
 
2311
            if ( config.nonequestrian_class && team_buf.flags.non_equestrian )
2312
            {
2313
                ptr->class[team_buf.class].non_equestrian++;
2314
                ptr->total.non_equestrian++;
2315
            }
2316
        }
2317
    }
13 david 2318
 
2319
    /*
2320
    **  Fix up the totals for the non equestrians
2321
    **  This is not a real category but a summary of the others.
2322
    */
2323
    if ( config.nonequestrian_class  )
2324
    {
2325
        ptr->class[config.nonequestrian_class].total += ptr->total.non_equestrian;
2326
    }
1 root 2327
}
2328
 
2329
/*========================================================================
2330
 *
2331
 *  Display summary information
2332
 *
2333
 *  Purpose:
2334
 *      This function is called to display summary information
2335
 *
2336
 *  Parameters:
2337
 *      None
2338
 *
2339
 *  Returns:
2340
 *      Nothing
2341
 *
2342
 *========================================================================*/
2343
 
2344
void display_summary (void)
2345
{
2346
 
2347
    t_class_summary data;
2348
    int         i;
2349
    int         line = 2;
2350
 
2351
    cur( 0, line );
2352
    printf( "Generating Summary Information" );
2353
    calc_class_summary( & data );
2354
 
2355
 
2356
    /*
2357
    **  Display summary stats
2358
    */
2359
 
2360
    cur( 0, line );
2361
    console_clreol();
2362
    printf( "Summary Information\n\n" );
2363
    printf( "%*s : %-7s %-7s%-7s\n", LEN_CLASS_NAME,
2364
                                      "Category",
2365
                                      "Total",
2366
                                      "Disq",
2367
                                      "NonEq" );
2368
 
2369
    for( i = 0; i < config.num_class; i++ )
2370
    {
2371
        /*
2372
        **  The non-equestrian leg does not have any data
2373
        **  Supress the display
2374
        */
2375
        if ( config.nonequestrian_class == i+1  )
2376
            continue;
2377
 
2378
        printf( "%*s : %-7d %-7d %-7d\n", LEN_CLASS_NAME,
2379
                                          config.team_class[i].full_name,
2380
                                          data.class[i+1].total,
2381
                                          data.class[i+1].disqualified,
2382
                                          data.class[i+1].non_equestrian );
2383
    }
2384
 
2385
    printf( "\n" );
2386
    printf( "%*s : %-7d %-7d %-7d\n", LEN_CLASS_NAME,
2387
                                      "Totals",
2388
                                      data.total.total,
2389
                                      data.total.disqualified,
2390
                                      data.total.non_equestrian );
2391
 
2392
    printf( "\nAny key to continue " );
2393
    getinp();
2394
}
2395
 
13 david 2396
/*========================================================================
2397
 *
2398
 *  Print summary information
2399
 *
2400
 *  Purpose:
2401
 *      This function is called to print summary information
2402
 *
2403
 *  Parameters:
2404
 *      None
2405
 *
2406
 *  Returns:
2407
 *      Nothing
2408
 *
2409
 *========================================================================*/
1 root 2410
 
13 david 2411
void pri_summary (void)
2412
{
2413
 
2414
    t_class_summary data;
2415
    int         i;
2416
    int         line = 2;
2417
 
2418
 
2419
    if( !open_printer( "", "summary", 132, 0, "Summary Information" ) )
2420
        return;
2421
 
2422
    cur( 0, line );
2423
    printf( "Generating Summary Information" );
2424
    calc_class_summary( & data );
2425
 
2426
 
2427
    /*
2428
    **  Display summary stats
2429
    */
2430
 
2431
    print( "%*s : %-7s %-7s%-7s\n", LEN_CLASS_NAME,
2432
                                      "Category",
2433
                                      "Total",
2434
                                      "Disq",
2435
                                      "NonEq" );
2436
 
2437
    for( i = 0; i < config.num_class; i++ )
2438
    {
2439
        /*
2440
        **  The non-equestrian leg does not have any data
2441
        **  Supress the display
2442
        */
2443
        if ( config.nonequestrian_class == i+1  )
2444
            continue;
2445
 
2446
        print( "%*s : %-7d %-7d %-7d\n", LEN_CLASS_NAME,
2447
                                          config.team_class[i].full_name,
2448
                                          data.class[i+1].total,
2449
                                          data.class[i+1].disqualified,
2450
                                          data.class[i+1].non_equestrian );
2451
    }
2452
 
2453
    print( "\n" );
2454
    print( "%*s : %-7d %-7d %-7d\n", LEN_CLASS_NAME,
2455
                                      "Totals",
2456
                                      data.total.total,
2457
                                      data.total.disqualified,
2458
                                      data.total.non_equestrian );
2459
 
2460
    close_printer();
29 - 2461
    if ( !report_all )
2462
    {
2463
        printf( "\nAny key to continue " );
2464
        getinp();
2465
    }
13 david 2466
}
2467
 
2468
 
2469
 
1 root 2470
/*========================================================================
2471
 *
2472
 *  Main sort routine for final data
2473
 *
2474
 *  Purpose:
2475
 *      This function is called to do the report sort routine for final data
2476
 *      This routine will fill all the gaps in the sort_aux structure
2477
 *
2478
 *  Parameters:
2479
 *      None
2480
 *
2481
 *  Returns:
2482
 *      Nothing
2483
 *
2484
 *========================================================================*/
2485
 
2486
void do_big_sort(void)
2487
{
2488
    int         i, k;                            /* Looooopy things */
2489
    unsigned    j;
2490
    ty_s_data  *ptr;                             /* Pointer to sort data */
2491
    int         class;                           /* Current class */
2492
 
2493
    printf( "Sorting it ALL out" );
2494
    flush_out();
2495
 
2496
    for( i = 0; i <= config.num_legs; i++ )
2497
    {
2498
        /*
2499
        **  Sort on leg elapsed time
2500
        **  The save the teams elapsed place in each leg
2501
        */
2502
        sort_team_data( i, S_L );
2503
        for( j = 1, ptr = sort_data; j <= sort_num; j++, ptr++ )
2504
        {
2505
            sort_aux[ptr->team].l_place[i] = j;
2506
            sort_aux[ptr->team].team = ptr->team;
2507
        }
2508
 
2509
        /*
2510
        **  Sort on leg end time
2511
        **  Then save the teams place at the end of each leg
2512
        */
2513
        sort_team_data( i, S_LE );
2514
        for( j = 1, ptr = sort_data; j <= sort_num; j++, ptr++ )
2515
            sort_aux[ptr->team].le_place[i] = j;
2516
 
2517
        /*
2518
        **  Sort on elapsed time per class
2519
        **  The save the teams elapsed place in each leg per class
2520
        */
2521
        sort_team_data( i, S_LC );
2522
        class = -1;
2523
        for( k = 1, j = 1, ptr = sort_data; j <= sort_num; j++, ptr++ )
2524
        {
2525
            if( class != ptr->class )
2526
            {
2527
                k = 1;
2528
                class = ptr->class;
2529
            }
2530
            sort_aux[ptr->team].lc_place[i] = k++;
2531
        }
2532
 
2533
        /*
2534
        **  Sort on end time per class
2535
        **  Then save the teams place at the end of each leg per class
2536
        */
2537
        sort_team_data( i, S_LEC );
2538
        class = -1;
2539
        for( k = 1, j = 1, ptr = sort_data; j <= sort_num; j++, ptr++ )
2540
        {
2541
            if( class != ptr->class )
2542
            {
2543
                k = 1;
2544
                class = ptr->class;
2545
            }
2546
            sort_aux[ptr->team].lec_place[i] = k++;
2547
        }
2548
    }
2549
 
2550
    /*
2551
    **  Write the place information back to disk for use in the displays
2552
    */
2553
    printf( "\nWriting it all back to the disk file" );
2554
    flush_out();
2555
 
2556
    for( i = config.min_team; i <= config.max_team; i++ )
2557
    {
2558
        if( sort_aux[i].team && valid_field( i ) && g_record( i, &team_buf ) )
2559
        {
2560
            for( k = 0; k <= config.num_legs; k++ )
2561
            {
2562
                team_buf.leg[k].l_place = sort_aux[i].l_place[k];
2563
                team_buf.leg[k].le_place = sort_aux[i].le_place[k];
2564
                team_buf.leg[k].lc_place = sort_aux[i].lc_place[k];
2565
                team_buf.leg[k].lec_place = sort_aux[i].lec_place[k];
2566
            }
2567
            put_team_record( i, &team_buf );
2568
        }
2569
    }
2570
}
2571
 
2572
/*========================================================================
2573
 *
2574
 *  Sort in memory buffer
2575
 *
2576
 *  Purpose:
2577
 *      This function is called to Sort in memory buffer
2578
 *
2579
 *  Parameters:
2580
 *      leg         Requested leg
2581
 *      mode        Defines the sort mode
2582
 *
2583
 *  Returns:
2584
 *      Nothing
2585
 *
2586
 *========================================================================*/
2587
 
2588
void sort_team_data( int leg, int mode )
2589
{
2590
 
2591
    unsigned    j;
2592
    ty_s_data  *ptr;
2593
 
2594
    sort_leg = leg;                              /* Leg is global for the comparison function */
2595
    sort_mode = mode;                            /* Mode is global for compare function */
2596
 
2597
    qsort( ( char * ) sort_data, sort_num, sizeof( ty_s_data ), sort_comp );
2598
 
2599
    /*
2600
     * Insert "place data" into the sorted data
2601
     * This simply the index into the array of data - after its been
2602
     * sorted.
2603
     */
2604
    ptr = sort_data;
2605
    for( j = 1; j <= sort_num; j++, ptr++ )
2606
        ptr->place = j;
2607
 
2608
}
2609
 
2610
/*========================================================================
2611
 *
2612
 *  qsort comparison function
2613
 *
2614
 *  Purpose:
2615
 *      This function is called by qsort as a Sort comparison function
2616
 *
2617
 *  Parameters:
2618
 *      a       - 1st record
2619
 *      b       - 2nd record
2620
 *
2621
 *  Returns:
2622
 *      value to qsort
2623
 *
2624
 *========================================================================*/
2625
 
2626
int sort_comp( const void * aa, const void * bb )
2627
{
2628
    const ty_s_data * a = aa;
2629
    const ty_s_data * b = bb;
2630
 
2631
 
2632
    int         i;                               /* One of those */
2633
    time_t      ta, tb;                          /* Leg times */
2634
    int         na, nb;                          /* Number of valid legs */
2635
    time_t      tta, ttb;                        /* Temp times */
2636
 
2637
    /*
2638
    **  Sorting on Team Number
2639
    */
2640
    if( sort_mode == S_TEAM )
2641
        return ( a->team - b->team );
2642
 
2643
    /*
2644
    **  Sorting on Class and Team Number
2645
    */
2646
    if( sort_mode == S_CLASS )
2647
    {
2648
        if( a->class != b->class )
2649
            return ( a->class - b->class );
2650
        else
2651
            return ( a->team - b->team );
2652
    }
2653
 
2654
    /*
2655
    **  Sorting within a class
2656
    **  First sort on the class
2657
    */
2658
    if( sort_mode == S_LEC || sort_mode == S_LC )   /* Sort within a class */
2659
        if( a->class != b->class )
2660
            return ( a->class - b->class );
2661
 
2662
    /*
2663
    **  Now we need to examine the times as we have sorted
2664
    **  on every thing else.
2665
    **
2666
    **  If one of the teams has bad_times, then that team is placed
2667
    **  lower in the sorting order. If both teams have bad times
2668
    **  then sort on team number. ie: Unplaced teams are sorted on
2669
    **  team number
2670
    */
2671
    if( a->flags.bad_times || b->flags.bad_times )  /* Valid data has precedence */
2672
    {
2673
        if( a->flags.bad_times && b->flags.bad_times )
2674
            return ( a->team - b->team );
2675
        else
2676
            return ( a->flags.bad_times ? 1 : -1 );
2677
    }
2678
 
2679
    /*
2680
    **  Not sorting within a class ie: Overall
2681
    **  Non-Equestrian is at the end, so that it doesn't get counted in the
2682
    **  finishing order
2683
    */
2684
    if( sort_mode == S_LE || sort_mode == S_L )     /* Sort NOT within a class */
2685
    {
2686
        if( a->flags.non_equestrian || b->flags.non_equestrian )
2687
        {
2688
            if( a->flags.non_equestrian && b->flags.non_equestrian )
2689
                return ( a->team - b->team );
2690
            else
2691
                return ( a->flags.non_equestrian ? 1 : -1 );
2692
        }
2693
    }
2694
 
2695
 
2696
    /*
2697
    **  Before we sort on times we must determine which time to
2698
    **  use. Finish time, Leg end times, Leg Elapsed times.
2699
    */
2700
 
2701
    switch ( sort_mode )
2702
    {
2703
      /*
2704
      **    Sort on finish times
2705
      */
2706
      case S_FIN:
2707
        ta = a->leg[sort_leg];
2708
        tb = b->leg[sort_leg];
2709
        break;
2710
 
2711
 
2712
      /*
2713
      **    Sort on accumulated leg times
2714
      */
2715
      case S_LE:
2716
      case S_LEC:
2717
        if( sort_leg )
2718
        {
2719
            /*
2720
            **  Calculate accumulated time up to the desired leg
2721
            **  If the two teams have a different number of valid
2722
            **  leg times then order by the team that has completed
2723
            **  more legs.
2724
            */
2725
            ta = tb = ( time_t ) 0;
2726
            na = nb = 0;
2727
            for( i = 1; i <= sort_leg; i++ )
2728
            {
2729
                tta = a->lege[i];
2730
                ttb = b->lege[i];
2731
                if( tta > 0 )
2732
                {
2733
                    na++;
2734
                    ta += tta;
2735
                }
2736
                if( ttb > 0 )
2737
                {
2738
                    nb++;
2739
                    tb += ttb;
2740
                }
2741
            }
2742
            if( na != nb )
2743
                return ( nb - na );
2744
        }
2745
        else
2746
        {
2747
            ta = a->leg[sort_leg] - a->start;
2748
            tb = b->leg[sort_leg] - b->start;
2749
        }
2750
        break;
2751
 
2752
      /*
2753
      **    Sort on Elapsed times
2754
      */
2755
      case S_LC:
2756
      case S_L:
2757
        ta = a->lege[sort_leg];
2758
        tb = b->lege[sort_leg];
2759
        break;
2760
 
2761
      /*
2762
      **    Just to be sure ...
2763
      */
2764
      default:
2765
        return ( 0 );
2766
    }
2767
 
2768
    /*
2769
    **  Finally. Compare the required team times
2770
    */
2771
    if( ta == tb )
2772
        return ( a->team - b->team );
2773
    if( ( ta > 0 ) && ( tb > 0 ) )
2774
        return ( ( int ) ( ta - tb ) );
2775
    return ( ( ta > 0 ) ? -1 : 1 );
2776
}
2777
 
2778
/*========================================================================
2779
 *
18 david 2780
 *  qsort comparison function - competitor names
2781
 *
2782
 *  Purpose:
2783
 *      This function is called by qsort as a Sort comparison function
2784
 *
2785
 *  Parameters:
2786
 *      a       - 1st record
2787
 *      b       - 2nd record
2788
 *
2789
 *  Returns:
2790
 *      value to qsort
2791
 *
2792
 *========================================================================*/
2793
 
2794
int sort_comp_cname( const void * aa, const void * bb )
2795
{
25 - 2796
    ty_s_namedata * a = (ty_s_namedata *)aa;
2797
    ty_s_namedata * b = (ty_s_namedata *)bb;
18 david 2798
 
2799
 
2800
    int         i;                               /* One of those */
2801
 
2802
    /*
2803
    **  Sort by name
2804
    */
2805
    i = strcmp ( a->name, b->name );
2806
    if ( i )
2807
        return ( i );
2808
    a->multi=1;
2809
    b->multi=1;
2810
 
2811
    /*
2812
    **  Sort by Leg
2813
    */
2814
    i = a->leg - b->leg;
2815
    if ( i )
2816
        return ( i );
2817
 
2818
    /*
2819
    **  Sorting on Team Number
2820
    */
2821
    return ( a->team - b->team );
2822
 
2823
}
2824
 
2825
/*========================================================================
2826
 *
1 root 2827
 *  load report data into memory
2828
 *
2829
 *  Purpose:
2830
 *      This routine will pull all the data into memory 
2831
 *      Not all the team data is loaded. Only that essential for the
2832
 *      operation of the sort routine is loaded
2833
 *
2834
 *  Parameters:
2835
 *      None
2836
 *
2837
 *  Returns:
2838
 *      TRUE - All is well
2839
 *
2840
 *========================================================================*/
2841
 
2842
bool load_report_data(void)
2843
{
2844
 
2845
    ty_s_data  *ptr;                             /* pointer to sort data type */
2846
    int         j;
2847
    unsigned    num;
2848
 
2849
    printf( "Loading team information - This will not hurt" );
2850
    flush_out();
2851
 
2852
    /*
2853
     * Fetch memory for the data store
2854
     */
2855
 
2856
    if( sort_data )
2857
        free( ( char * ) sort_data );
2858
    sort_data = 0;
2859
 
2860
    if( sort_aux )
2861
        free( ( char * ) sort_aux );
2862
    sort_aux = 0;
2863
    sort_num = 0;                                /* Counter of records in the array */
2864
 
2865
    /*
2866
    **  Allocate memory for the data structures
2867
    **  This will be free'd
2868
    */
2869
    num = config.max_team - config.min_team + 1 ;
2870
 
2871
    /*
2872
    **  Allow for non-equestrian teams - since some of the data is loaded twice
2873
    **  Take a guess that at most 1/2 the teams will be non-equestrian
2874
    */
2875
    num = num * 3 / 2;
2876
 
2877
    sort_data = ( ty_s_data * ) calloc ( num , sizeof( ty_s_data ) );
2878
    sort_aux = ( ty_s_aux * ) calloc( num + 1, sizeof( ty_s_aux ) );
2879
 
2880
    if( sort_data == 0 || sort_aux == 0 )
2881
    {
2882
        printf( "\n\nError in allocating memory\n" );
2883
        sleep( 5 );
2884
        return ( FALSE );
2885
    }
2886
 
2887
    /*
2888
    **  Load data into the memory based data structure
2889
    **  Only load data for valid-teams
2890
    **  Load essential data
2891
    **      Team Number, class and flags
2892
    **      Leg end and elapsed times
2893
    */
2894
    ptr = sort_data;
2895
    for( team = config.min_team; team <= config.max_team; team++ )
2896
    {
2897
        if( valid_field( team ) )
2898
        {
2899
            g_record( team, &team_buf );
2900
            if( team_buf.flags.valid )
2901
            {
2902
                ptr->team = team;
2903
                for( j = 0; j < MAX_LEGS + 1; j++ )
2904
                {
2905
                    ptr->lege[j] = team_buf.leg[j].elapsed;
2906
                    ptr->leg[j] = team_buf.leg[j].end;
2907
                }
2908
                ptr->start = team_buf.leg[0].start;
2909
                ptr->class = team_buf.class;
2910
 
2911
                ptr->flags = team_buf.flags;
2912
                ptr++;
2913
                sort_num++;
2914
 
2915
                /*
2916
                **  If non-equestrian support is enabled then
2917
                **  duplicate and modify data for the non-equestrian teams
2918
                **      - Change the class
2919
                **      - Modify the leg time
2920
                */
2921
                if ( config.nonequestrian_class && team_buf.flags.non_equestrian )
2922
                {
2923
                    ptr->team = team;
2924
                    ptr->lege[0] = 0;
2925
 
2926
                    for( j = 0; j < MAX_LEGS + 1; j++ )
2927
                    {
2928
                        if ( j == config.equestrian_leg )
2929
                        {
2930
                            ptr->lege[j] = 0;
2931
                            if ( config.equestrian_leg > 1 )
2932
                                ptr->leg[j] = ptr->leg[j-1];
2933
                        }
2934
                        else
2935
                        {
2936
                            if ( j )
2937
                                ptr->lege[j] = team_buf.leg[j].elapsed;
2938
                            ptr->leg[j] = team_buf.leg[j].end;
2939
                            ptr->lege[0] += ptr->lege[j] ;
2940
                        }
2941
                    }
2942
 
2943
                    ptr->start = team_buf.leg[0].start;
2944
                    ptr->class = config.nonequestrian_class;
2945
                    ptr->flags = team_buf.flags;
2946
                    ptr->flags.disqualified = 0;
2947
                    ptr++;
2948
                    sort_num++;
2949
                }
2950
            }
2951
        }
2952
    }
2953
    return ( TRUE );
2954
}
2955
 
2956
/*========================================================================
2957
 *
2958
 *  Generate all the stats
2959
 *
2960
 *  Purpose:
2961
 *      This function is called to Generate all the stats
2962
 *
2963
 *  Parameters:
2964
 *      None
2965
 *
2966
 *  Returns:
2967
 *      Nothing
2968
 *
2969
 *========================================================================*/
2970
 
2971
void gen_stats(void)
2972
{
2973
    ty_s_data  *ptr;
2974
    unsigned    i;
2975
    int         j;
2976
    int         k;
2977
 
2978
    /*
2979
     * Init all the stats 
2980
     */
2981
    for( i = 0; i <= MAX_LEGS; i++ )
2982
    {
2983
        for( j = 0; j <= MAX_CLASS; j++ )
2984
        {
2985
            stats.team[i][j] = 0;
2986
            stats.fast.team[i][j] = 0;
2987
            stats.fast.time[i][j] = ( time_t ) - 1;
2988
            stats.average[i][j] = 0;
2989
        }
2990
    }
2991
 
2992
    for( i = 1, ptr = sort_data; i <= sort_num; i++, ptr++ )
2993
    {
2994
        /*
2995
        **  If there is any bad times in the team record, then none
2996
        **  of the data can be trusted.
2997
        **
2998
        **  If the team has been disqualified, then don't use any
2999
        **  of the data.
3000
        */
3001
        if( ptr->flags.bad_times || ptr->flags.disqualified )
3002
            continue;
3003
 
3004
        for( j = 0; j <= config.num_legs; j++ )
3005
        {
3006
            if( ptr->lege[j] <= 0 )              /* Ignore bad data */
3007
                continue;
3008
 
3009
            /*
3010
            **  Determine fastest team : overall
3011
            **  Ignore the non-equestrian data as this is in the list twice
3012
            */
3013
            if( ( ptr->lege[j] < stats.fast.time[j][0] )
3014
                || ( stats.fast.time[j][0] < 0 ) )
3015
            {
3016
                if ( ptr->class != config.nonequestrian_class )
3017
                {
3018
                    stats.fast.team[j][0] = ptr->team;
3019
                    stats.fast.time[j][0] = ptr->lege[j];
3020
                }
3021
            }
3022
 
3023
            /*
3024
            **  Determine fastest team : within a class
3025
            */
3026
            if( ( ptr->lege[j] < stats.fast.time[j][ptr->class] )
3027
                || stats.fast.time[j][ptr->class] < 0 )
3028
            {
3029
                stats.fast.team[j][ptr->class] = ptr->team;
3030
                stats.fast.time[j][ptr->class] = ptr->lege[j];
3031
            }
3032
 
3033
            /*
3034
            **  Sum the end times : overall
3035
            */
3036
            if ( ptr->class != config.nonequestrian_class )
3037
            {
3038
                stats.average[j][0] += ptr->lege[j];
3039
                stats.team[j][0]++;
3040
            }
3041
 
3042
 
3043
            /*
3044
            **  Sum the end times : within a class
3045
            */
3046
            stats.average[j][ptr->class] += ptr->lege[j];
3047
            stats.team[j][ptr->class]++;
3048
        }
3049
    }
3050
 
3051
    /*
3052
     * Calculate the averages
3053
     */
3054
    for( k = 0; k <= config.num_legs; k++ )
3055
    {
3056
        for( j = 0; j <= config.num_class; j++ )
3057
        {
3058
            if( stats.team[k][j] )
3059
                stats.average[k][j] /= stats.team[k][j];
3060
            else
3061
                stats.average[k][j] = ( time_t ) - 1;
3062
        }
3063
    }
3064
}
3065
 
3066
/********************************* EOF ***********************************/