Subversion Repositories svn1

Rev

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