Subversion Repositories svn1

Rev

Rev 59 | Go to most recent revision | 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
{
1246
    /*
1247
    **  Generate ALL results with HTML tags
1248
    */
1249
    report_html = TRUE;
1250
    pri_awards();
1251
    report_html = FALSE;
1252
}
1253
 
1254
/*========================================================================
1255
 *
1256
 *  Print award results
1257
 *
1258
 *  Purpose:
1259
 *      This function is called to Print award results
1260
 *      Keep the page to 80 cols, so that it can be pronted on A4
1261
 *
1262
 *  Parameters:
1263
 *      None
1264
 *
1265
 *  Returns:
1266
 *      Nothing
1267
 *
1268
 *========================================================================*/
1 root 1269
void pri_awards(void)
1270
{
1271
    int j;
1272
    int i;
1273
    int k;
1274
    int windex;
1275
    ty_s_data  *ptr;
1276
    int         last_class;
1277
 
27 - 1278
    if( !open_printer( "", "awards", 80, report_html, "Prizes and Awards" ) )
1 root 1279
        return;
1280
 
1281
    /*
1282
    **  Generate an index for this page
1283
    */
1284
    print( "\n");
60 - 1285
    if ( report_html )
1286
    {
1287
        print( "<hr>" );
1288
        print( "<A NAME=\"%s\"></A>","INDEX");
1289
    }
1 root 1290
    print( "Award Categories");
1291
 
1292
    for( j = 1; j <= config.num_class; j++ )
1293
    {
1294
        /*
1295
        **  Header for the class
1296
        */
1297
        if ( config.class_winners[j-1] <= 0 )
1298
            continue;
1299
 
1300
        print( "\n");
60 - 1301
        print( "    ");
1302
        if ( report_html ) print( "<A HREF=\"#%s\">",config.team_class[j-1].full_name);
1 root 1303
        print( "%s",  config.team_class[j-1].full_name );
60 - 1304
        if ( report_html ) print( "</A>" );
1 root 1305
    }
1306
 
1307
    /*
1308
    **  Manual entries
1309
    */
1310
    print( "\n");
60 - 1311
    print( "    ");
1312
    if ( report_html ) print( "<A HREF=\"#%s\">","Hall Of Fame");
1 root 1313
    print( "%s",  "Hall Of Fame" );
60 - 1314
    if ( report_html ) print( "</A>" );
1 root 1315
 
1316
    print( "\n");
60 - 1317
    print( "    ");
1318
    if ( report_html ) print( "<A HREF=\"#%s\">","FASTEST");
1 root 1319
    print( "%s",  "FASTEST" );
60 - 1320
    if ( report_html ) print( "</A>" );
1 root 1321
 
1322
    /*
1323
    **  Sort the data by class
1324
    */
1325
    sort_team_data( 0, S_LC );      /* Generate class placement data */
1326
    last_class = -1;                /* Invalid class to start with */
1327
 
1328
    /*
1329
    **  Process each category
1330
    */
1331
    for( j = 1; ; j++ )
1332
    {
1333
        /*
1334
        **  Tail for previous entry
1335
        */
1336
        if ( j != 1 )
60 - 1337
            if ( report_html ) print( "<A HREF=\"#%s\">Awards Index</A>","INDEX");
1 root 1338
 
1339
        if ( j > config.num_class  )
1340
            break;
1341
 
1342
        /*
1343
        **  Header for the class
1344
        */
1345
        print( "\n");
60 - 1346
        if ( report_html )
1347
        {
1348
            print( "<hr>" );
1349
            print( "<A name=\"%s\"></A>",config.team_class[j-1].full_name);
1350
        }
1351
        else
1352
        {
1353
            print( "\n");
1354
        }
1355
        print( "Category: ");
1356
        if ( report_html ) print( "<A HREF=\"%s\">",p_filename(filebase, config.team_class[j - 1].abr ,"html"));
1 root 1357
        print( "%s",  config.team_class[j-1].full_name );
60 - 1358
        if ( report_html ) print( "</A>" );
1 root 1359
 
60 - 1360
        if ( config.class_winners[j-1] <= 0 )
1 root 1361
        {
1362
            print( "\n");
1363
            print( "No winners awarded" );
1364
            continue;
1365
        }
1366
 
1367
        /*
1368
        **  Enties for 'n' the best teams as configured
1369
        */
1370
        windex = 0;                     /* Winners done */
1371
        for( ptr = sort_data, i = 0; i < sort_num; i++, ptr++ )
1372
        {
1373
            if ( ptr->class != j )
1374
            {
1375
                continue;
1376
            }
1377
 
1378
            /*
1379
            **  Now read in the team record
1380
            */
1381
            if( valid_field( ptr->team ) && g_record( ptr->team, &team_buf ) )
1382
            {
1383
                windex++;
1384
 
1385
                /*
1386
                **  If printing an HTML report then we need to mark
1387
                **  the entry with a reference so that we can link to it
1388
                */
1389
                print( "\n");
60 - 1390
                if ( report_html )
1391
                {
1392
                    print( "<A NAME=\"Team_%04d\">",team_buf.numb );
1393
                    print( "</A>" );
1394
                }
1 root 1395
 
1396
                /*
1397
                **  Basic information
1398
                **      - Team number - with Xref back to full result
1399
                **      - Full team name
1400
                **      - Full categoray name
1401
                */
1402
                print( "%s", placing(windex) );
1403
 
60 - 1404
                print( "  Team Name: ");
1405
                if ( report_html ) print( "<A HREF=\"%s#Team_%04d\">", p_filename(filebase, "name" ,"html"), team_buf.numb );
1 root 1406
                print( "%-*s ",     MAX_TM_NAME, team_buf.name );
60 - 1407
                    if ( report_html ) print( "</A>" );
1 root 1408
 
60 - 1409
                print( "  Number: ");
1410
                if ( report_html ) print( "<A HREF=\"%s#Team_%04d\">", p_filename(filebase, "finish" ,"html"), team_buf.numb );
1 root 1411
                print( "%4d",       team_buf.numb );
60 - 1412
                if ( report_html ) print( "</A>" );
1 root 1413
 
1414
 
1415
                for( k = 0; k < MAX_MEMB; k++ )
1416
                {
1417
 
1418
                    /*
1419
                    **  Skip equestrian leg in the non-equestion display
1420
                    */
1421
                    if ( k + 1 == config.equestrian_leg && ptr->class == config.nonequestrian_class)
1422
                        continue;
1423
 
1424
                    print( "\n");
1425
                    print( "    ");
1426
                    print( "%-*s", MAX_PERSON_NAME, config.leg_name[k] ? config.leg_name[k] : "Competitor"  );
1427
                    print( " %-*s", MAX_PERSON_NAME, team_buf.members[k].name );
1428
 
1429
                    print( "  %-8s", time_a( team_buf.leg[k+1].elapsed ) );
1430
                }
1431
 
1432
                print( "\n");
1433
                print( "    ");
1434
                print_bold( TRUE );
1435
                print( "%-*s %-*s  %-8s", MAX_PERSON_NAME , "Total" ,MAX_PERSON_NAME, "",time_a( team_buf.leg[0].elapsed ) );
1436
                print_bold( FALSE );
1437
                print( "\n" );
1438
            }
1439
 
1440
 
1441
            /*
1442
            **  More to do
1443
            */
1444
            if ( windex >= config.class_winners[j-1] )
1445
            {
1446
                break;
1447
            }
1448
        }
1449
    }
1450
 
1451
    /*
1452
    **  Generate the Hall of Fame information
1453
    */
1454
    print( "\n");
60 - 1455
    if ( report_html )
1456
    {
1457
        print( "<hr>" );
1458
        print( "<A name=\"%s\"></A>","Hall Of Fame");
1459
    }
1 root 1460
    print( "%s",  "Hall of Fame" );
1461
 
1462
    if ( config.num_fame  )
1463
    {
1464
        for( i = 1; i <= config.num_fame; i++ )
1465
        {
60 - 1466
            print( "\n");
1467
            print( "    %-*s", MAX_PERSON_NAME, config.hall_fame[i-1] );
1 root 1468
        }
1469
    }
1470
    else
1471
    {
1472
        printf( "\n    There are no new stars for the Hall of Fame");
1473
    }
60 - 1474
    if ( report_html ) print( "<p><A HREF=\"#%s\">Awards Index</A>","INDEX");
1 root 1475
 
1476
    /*
1477
    **  Generate the FASTEST information
1478
    */
60 - 1479
    print( "\n" );
1480
    if ( report_html )
1481
    {
1482
        print( "<hr>" );
1483
        print( "<A name=\"%s\"></A>","FASTEST");
1484
    }
1485
    else
1486
    {
1487
        print( "\n" );
1488
    }
1 root 1489
    print( "%s",  "FASTEST" );
1490
 
1491
    /*
1492
    **  Sort the data and then generate the stats - again
1493
    */
1494
    do_big_sort();
1495
    gen_stats();
1496
 
1497
    for( i = 1; i <= config.num_legs; i++ )
1498
    {
1499
        g_record( stats.fast.team[i][0], &team_buf );
1500
 
1501
        print( "\n");
1502
        print( "    %-13s ", config.leg_name[i - 1] );
60 - 1503
        print( "  Name: ");
1504
        if ( report_html ) print( "<A HREF=\"%s#Team_%04d\">", p_filename(filebase, "name" ,"html"), team_buf.numb );
1 root 1505
        print( "%-*s", MAX_PERSON_NAME, team_buf.members[i-1].name );
60 - 1506
        if ( report_html ) print( "</A>" );
1507
        print( "  Team :");
1508
        if ( report_html ) print( "<A HREF=\"%s#Team_%04d\">", p_filename(filebase, "finish" ,"html"), team_buf.numb );
27 - 1509
        print( "%4d" , stats.fast.team[i][0] );
60 - 1510
        if ( report_html ) print( "</A> " );
27 - 1511
        print( "Time:%s ", time_a( stats.fast.time[i][0] ) );
1 root 1512
 
1513
    }
1514
 
60 - 1515
    if ( report_html ) print( "<p><A HREF=\"#%s\">Awards Index</A>","INDEX");
1516
    print( "\n");
1 root 1517
    close_printer();
1518
}
1519
 
1520
/*========================================================================
1521
 *
1522
 *  pri_master_index
1523
 *
1524
 *  Purpose:
1525
 *      This function is called to create an HTML page that references all
1526
 *      the other pages that have been generated
1527
 *
1528
 *      Assume that they are in the same directory
1529
 *
1530
 *  Parameters:
1531
 *      None
1532
 *
1533
 *  Returns:
1534
 *      Nothing
1535
 *
1536
 *========================================================================*/
1537
void pri_master_index_entry(char *name, char *text)
1538
{
1539
    print( "<tr><td>");
1540
    print ("<A HREF=\"%s\">%s</A>\n", p_filename(filebase, name ,"html"), text );
1541
}
1542
 
1543
 
1544
void pri_master_index(void)
1545
{
1546
    int j;
1547
 
1548
    report_html = 1;
1549
    if( !open_printer( "", "index", 132, report_html, "Master Index" ) )
1550
        return;
1551
 
1552
    /*
1553
    **  Names
1554
    */
1555
    print( "<TABLE border=0 align=center>" );
18 david 1556
    pri_master_index_entry( "name", "Team list" );
1557
    pri_master_index_entry( "competitor", "Competitor list" );
1 root 1558
    pri_master_index_entry( "finish", "Finishing Order for all Teams" );
1559
    pri_master_index_entry( "awards", "Prizes and Awards" );
1560
    print( "<tr><td>\n" );
1561
 
1562
    print( "\n" );
1563
    for( j = 1; j <= config.num_class; j++ )
1564
    {
1565
        pri_master_index_entry( config.team_class[j - 1].abr, tprintf("Category Results for: %s", config.team_class[j-1].full_name) );
1566
    }
32 - 1567
 
1 root 1568
    print( "</TABLE>" );
1569
 
1570
    close_printer();
32 - 1571
 
1572
    /*
1573
    **  A small page to hold the Leg End displays
1574
    */
1575
 
1576
    if( !open_printer( "", "legindex", 132, report_html, "Master Index with trace data" ) )
1577
        return;
1578
 
1579
    /*
1580
    **  Names
1581
    */
1582
    print( "<TABLE border=0 align=center>" );
1583
#if 1
1584
    pri_master_index_entry( "name", "Team list" );
1585
    pri_master_index_entry( "competitor", "Competitor list" );
1586
    pri_master_index_entry( "finish", "Finishing Order for all Teams" );
1587
    pri_master_index_entry( "awards", "Prizes and Awards" );
1588
    print( "<tr><td>\n" );
1589
 
1590
    print( "\n" );
1591
    for( j = 1; j <= config.num_class; j++ )
1592
    {
1593
        pri_master_index_entry( config.team_class[j - 1].abr, tprintf("Category Results for: %s", config.team_class[j-1].full_name) );
1594
    }
1595
#endif
1596
    print( "<tr><td>\n" );
1597
 
1598
    print( "\n" );
1599
    for ( leg = 1; leg <= config.num_legs; leg ++ )
1600
    {
1601
        pri_master_index_entry( tprintf("lg%1.1d", leg), tprintf("Leg End Results for: %d", leg) );    
1602
    }
1603
 
1604
    print( "<tr><td>\n" );
1605
    print( "\n" );
1606
 
1607
    for ( leg = 1; leg <= config.num_legs; leg ++ )
1608
    {
1609
        pri_master_index_entry( tprintf("le%1.1d", leg), tprintf("Leg Elapsed Time Results for: %d", leg) );
1610
    }    
1611
 
1612
 
1613
    print( "</TABLE>" );
1614
 
1615
    close_printer();
1616
 
1 root 1617
}
1618
 
1619
 
1620
/*========================================================================
1621
 *
1622
 *  Print interim results
1623
 *
1624
 *  Purpose:
1625
 *      This function is called to Print interim results
1626
 *
1627
 *  Parameters:
1628
 *      None
1629
 *
1630
 *  Returns:
1631
 *      Nothing
1632
 *
1633
 *========================================================================*/
1634
 
1635
void pri_interim(void)
1636
{
1637
    ty_s_data  *ptr;
1638
    unsigned    i;
1639
    int         j, last_class;
29 - 1640
    char        suppress_classes = FALSE;                /* Boolean. Printout class files too */
1 root 1641
    char       *report_title;
1642
 
29 - 1643
    if ( ! report_all )
1644
    {
1645
        cur( 0, 5 );
1646
        printf( "Generate interim result printouts\n" );
1647
        ck_data( -1, C_DISQUAL );                    /* Check the data - dummy check */
1648
        suppress_classes = getyes( "Do you want to suppress class printouts" );
1649
        printf( "\nSorting the data\n" );
1650
    }
1 root 1651
    do_big_sort();                             /* Sort on every thing */
1652
    gen_stats();                               /* Generate the stats too */
1653
 
1654
    printf( "\nGenerating the printed output\n" );
1655
 
1656
    /*
1657
     * Now print the data on the printer 
1658
     */
1659
 
1660
    if( !open_printer( "", "int", 132, report_html, "Interim Results" ) )
1661
        return;
1662
 
1663
    /*
1664
     * Print out the data 
1665
     */
1666
    print_class_header( -1, FALSE );                     /* Print the header */
1667
 
1668
    ptr = sort_data;
1669
    sort_team_data( 0, S_TEAM );                   /* Re-sort on team number */
1670
    for( ptr = sort_data, i = 0; i < sort_num; i++, ptr++ )
1671
    {
1672
        if ( ptr->class == config.nonequestrian_class )
1673
            continue;
1674
 
1675
        g_record( ptr->team, &team_buf );
1676
 
1677
        print( "%4d %4.4s %-*s",
1678
               team_buf.numb,
1679
               pi_place( team_buf.leg[config.num_legs].le_place,
1680
                         ptr->flags.disqualified, team_buf.leg[0].elapsed ),
1681
               3,
1682
               team_buf.class ==
1683
 
1684
        for( j = 1; j <= config.num_legs; j++ )
1685
        {
1686
            print( "  %-8s %4.4s %4.4s",
1687
                   time_fa( team_buf.leg[j].elapsed,
1688
                            ptr->flags.disqualified ),
1689
                   pi_place( team_buf.leg[j].l_place, ptr->flags.disqualified,
1690
                             team_buf.leg[j].elapsed ),
1691
                   pi_place( team_buf.leg[j].le_place,
1692
                             ptr->flags.disqualified,
1693
                             team_buf.leg[j].elapsed ) );
1694
        }
1695
        print( "  %-8s %4.4s\n",
1696
               time_fa( team_buf.leg[0].elapsed, ptr->flags.disqualified ),
1697
               pi_place( team_buf.leg[config.num_legs].lec_place,
1698
                         ptr->flags.disqualified, team_buf.leg[0].elapsed ) );
1699
    }
1700
 
1701
    print_class_stats( -1, FALSE );             /* Print statistics */
18 david 1702
    print_legend(-1, 1);                        /* Print the legend */
1 root 1703
    close_printer();                            /* Close the printer */
1704
 
1705
 
1706
    /*
1707
     * Now produce a breakdown on a class by class basis 
1708
     * Now print out the class placement information
1709
     */
1710
 
1711
    if( suppress_classes )
1712
    {
1713
        printf( "WARNING: Class printouts suppressed\n" );
1714
        return;
1715
    }
1716
 
1717
    sort_team_data( 0, S_CLASS );              /* Generate class placement data */
1718
    last_class = -1;                             /* Invalid class to start with */
1719
 
1720
    for( ptr = sort_data, i = 0; i < sort_num; i++, ptr++ )
1721
    {
1722
        /*
1723
        **  Detect a change in the "class"
1724
        **  All data is within the one array of data
1725
        **  Use the in-memory class as this MAY differ from that stored
1726
        **  The non-equestrian class does this.
1727
        */
1728
        if( last_class != ptr->class )
1729
        {
1730
            if( last_class >= 0 )
1731
            {
1732
                print_class_stats( last_class, TRUE );
18 david 1733
                print_legend(last_class, 1);
1 root 1734
                close_printer();
1735
            }
1736
 
1737
            report_title = tprintf( "Interim Category results for : %-*s", LEN_CLASS_NAME, team_buf.class == 0 ? "" : config.team_class[ptr->class - 1].full_name );
1738
 
1739
            if( !open_printer( "", tprintf( "i%2s", config.team_class[ptr->class - 1].abr ), 132, report_html, report_title ) )
1740
                continue;
1741
            print_class_header( last_class = ptr->class, FALSE );
1742
        }
1743
 
1744
        /*
1745
        **  Now read in the team record
1746
        */
1747
        g_record( ptr->team, &team_buf );
1748
        print( "%4d %4.4s %-*s",
1749
               team_buf.numb,
1750
               pi_place( team_buf.leg[config.num_legs].lec_place,
1751
                         ptr->flags.disqualified, team_buf.leg[0].elapsed ),
1752
               3,
1753
               team_buf.class ==
1754
 
1755
        for( j = 1; j <= config.num_legs; j++ )
1756
        {
1757
            print( "  %-8s %4.4s %4.4s",
1758
                   time_fa( team_buf.leg[j].elapsed,
1759
                            ptr->flags.disqualified ),
1760
                   pi_place( team_buf.leg[j].lc_place,
1761
                             ptr->flags.disqualified,
1762
                             team_buf.leg[j].elapsed ),
1763
                   pi_place( team_buf.leg[j].lec_place,
1764
                             ptr->flags.disqualified,
1765
                             team_buf.leg[j].elapsed ) );
1766
        }
1767
        print( "  %-8s %4.4s\n",
1768
               time_fa( team_buf.leg[0].elapsed, ptr->flags.disqualified ),
1769
               pi_place( team_buf.leg[config.num_legs].le_place,
1770
                         ptr->flags.disqualified, team_buf.leg[0].elapsed ) );
1771
    }
1772
 
1773
    print_class_stats( last_class, FALSE );
18 david 1774
    print_legend(last_class, 1);
1 root 1775
    close_printer();
1776
 
1777
}
1778
 
51 - 1779
/*----------------------------------------------------------------------------
1780
** FUNCTION           : pri_csv_data
1781
**
1782
** DESCRIPTION        : Generate a CSV file of all the report data
1783
**                      It can then be used to play with the data externally
1784
**
1785
**
1786
** INPUTS             : None
1787
**
1788
** RETURNS            : Yes it does
1789
**
1790
----------------------------------------------------------------------------*/
1791
 
1792
 
1793
void pri_csv_data ( void )
1794
{
1795
    int i;
1796
    int j;
1797
    int age_sum;
1798
 
1799
    /*
1800
    **  Sort on every thing
1801
    **  Then generate all the stats too
1802
    */
1803
    printf( "\nSorting the data\n" );
1804
    do_big_sort();
1805
    gen_stats();
1806
 
1807
    /*
1808
     * Now print the data on the printer 
1809
     */
1810
 
54 - 1811
    if( !open_printer( "full_data", "csv", 2000, FALSE, NULL ) )
51 - 1812
        return;
1813
 
1814
    printf( "\nGenerating the printed output\n" );
1815
 
52 - 1816
    /*
1817
    **  Print headings
1818
    */
1819
    csv_print( "%s",   "Team Number" );
1820
    csv_print( "%s",   "Team Name" );
1821
 
1822
    csv_print( "%s",    "Class Full");
1823
    csv_print( "%s",    "Class Abr");
1824
    csv_print( "%s",    "Class Start Time");
1825
    csv_print( "%s",    "Class Start Time Number");
1826
 
1827
    csv_print( "%s",    "Team Country");
1828
 
1829
    for( j = 1; j <= config.num_legs; j++ )
1830
    {
1831
        csv_print( "%s", "Leg Number" );
1832
        csv_print( "%s", "Leg Name");
1833
        csv_print( "%s", "Competitor Name");
1834
        csv_print( "%s", "Sex" );
1835
        csv_print( "%s", "Age");
1836
        csv_print( "%s", "Start Time");
1837
        csv_print( "%s", "Start Time Number");
1838
        csv_print( "%s", "End Time" );
1839
        csv_print( "%s", "End Time Number" );
1840
        csv_print( "%s", "Elapsed Time");
1841
        csv_print( "%s", "Elapsed Time Number");
1842
        csv_print( "%s", "Leg Place");
1843
        csv_print( "%s", "Leg End Place");
1844
        csv_print( "%s", "Leg Class Place");
1845
        csv_print( "%s", "Leg End Class Place");
1846
        csv_print( "%s", "Manual");
1847
    }
1848
 
1849
    j = 0;
1850
    csv_print( "%s", "Team Start Time");
1851
    csv_print( "%s", "Team Start Time Number");
1852
    csv_print( "%s", "Team End Time");
1853
    csv_print( "%s", "Team End Time Number");
1854
    csv_print( "%s", "Team Elapsed Time");
1855
    csv_print( "%s", "Team Elapsed Time Number");
1856
//            csv_print( "%s", team_buf.leg[j].l_place );
1857
    csv_print( "%s", "Team Leg End Place");
1858
//            csv_print( "%s", team_buf.leg[j].lc_place );
1859
    csv_print( "%s", "Team Leg Class Place");
1860
//            csv_print( "%s", team_buf.leg[j].manual );
1861
 
1862
    csv_print( "%s", "Total Team Age");
1863
    csv_print( "%s", "Flag:valid Team");
1864
    csv_print( "%s", "Flag:bad_times" );
1865
    csv_print( "%s", "Flag:disqualified" );
1866
    csv_print( "%s", "Flag:non_equestrian" );
1867
    csv_print("\n");
1868
 
1869
 
51 - 1870
    for( i = config.min_team; i <= config.max_team; i++ )
1871
    {
1872
        if( valid_field( i ) && g_record( i, &team_buf ) )
1873
        {
1874
            /*
1875
            **  Basic information
1876
            **      - Team number - with Xref back to full result
1877
            **      - Full team name
1878
            **      - Full categoray name - with Xref to category results
1879
            **      - Country name
1880
            */
1881
            csv_print( "%d",   team_buf.numb );
1882
            csv_print( "%s",   team_buf.name );
1883
 
1884
            csv_print( "%s",    team_buf.class == 0 ? "" : config.team_class[team_buf.class - 1].full_name );
1885
            csv_print( "%s",    team_buf.class == 0 ? "" : config.team_class[team_buf.class - 1].abr );
1886
            csv_print( "%s",    time_a (team_buf.class == 0 ? 0 : config.team_class[team_buf.class - 1].start ));
1887
            csv_print( "%d",    team_buf.class == 0 ? 0 : config.team_class[team_buf.class - 1].start );
1888
 
1889
            csv_print( "%s",    config.num_countries == 0
1890
                                || team_buf.country ==
1891
 
1892
 
1893
            age_sum = 0;
1894
            for( j = 1; j <= config.num_legs; j++ )
1895
            {
1896
                csv_print( "%d", j );
1897
                csv_print( "%s", config.leg_name[j - 1] );
1898
                csv_print( "%s", team_buf.members[j-1].name );
1899
                csv_print( "%s", ( team_buf.members[j-1].sex == male ) ? "Male" : "Female" );
1900
                csv_print( "%d", team_buf.members[j-1].age );
1901
                if ( age_sum >= 0 )
1902
                {
1903
                    ushort age = team_buf.members[j-1].age;
1904
                    if ( age > 0 && age < 255 )
1905
                    {
1906
                        age_sum += age;
1907
                    }
1908
                    else
1909
                    {
1910
                        age_sum = -1;
1911
                    }
1912
                }
1913
 
1914
 
1915
                csv_print( "%s", time_a(team_buf.leg[j].start ));
1916
                csv_print( "%d", team_buf.leg[j].start );
1917
                csv_print( "%s", time_a(team_buf.leg[j].end ));
1918
                csv_print( "%d", team_buf.leg[j].end );
1919
                csv_print( "%s", time_a(team_buf.leg[j].elapsed ));
1920
                csv_print( "%d", team_buf.leg[j].elapsed );
1921
                csv_print( "%d", team_buf.leg[j].l_place );
1922
                csv_print( "%d", team_buf.leg[j].le_place );
1923
                csv_print( "%d", team_buf.leg[j].lc_place );
1924
                csv_print( "%d", team_buf.leg[j].lec_place );
1925
                csv_print( "%d", team_buf.leg[j].manual );
1926
            }
1927
 
1928
            j = 0;
1929
            csv_print( "%s", time_a(team_buf.leg[j].start ));
1930
            csv_print( "%d", team_buf.leg[j].start );
1931
            csv_print( "%s", time_a(team_buf.leg[j].end ));
1932
            csv_print( "%d", team_buf.leg[j].end );
1933
            csv_print( "%s", time_a(team_buf.leg[j].elapsed ));
1934
            csv_print( "%d", team_buf.leg[j].elapsed );
52 - 1935
//            csv_print( "%d", team_buf.leg[j].l_place );
51 - 1936
            csv_print( "%d", team_buf.leg[j].le_place );
52 - 1937
//            csv_print( "%d", team_buf.leg[j].lc_place );
51 - 1938
            csv_print( "%d", team_buf.leg[j].lec_place );
52 - 1939
//            csv_print( "%d", team_buf.leg[j].manual );
51 - 1940
 
1941
            csv_print( "%d", age_sum );
1942
            csv_print( "%d", team_buf.flags.valid );
1943
            csv_print( "%d", team_buf.flags.bad_times );
1944
            csv_print( "%d", team_buf.flags.disqualified );
1945
            csv_print( "%d", team_buf.flags.non_equestrian );
1946
 
52 - 1947
//How about class placings
51 - 1948
 
1949
 
1950
            csv_print( "\n" );
1951
        }
1952
    }
1953
 
1954
    close_printer();
1955
}
1956
 
1957
 
1 root 1958
/*========================================================================
1959
 *
29 - 1960
 *  Print all reports at once
51 - 1961
 *  Its all so fast, these days ...
29 - 1962
 *
1963
 *  Purpose:
1964
 *      This function is called to print all reports at once
1965
 *
1966
 *  Parameters:
1967
 *      None
1968
 *
1969
 *  Returns:
1970
 *      Nothing
1971
 *
1972
 *========================================================================*/
1973
 
1974
void pri_all_reports ( void )
1975
{
1976
    int leg;
1977
    report_all = TRUE;
1978
 
1979
    pri_team();
1980
 
1981
    for ( leg = 1; leg <= config.num_legs; leg ++ )
1982
    {
1983
        pri_leg_body ( leg );
1984
        pri_eleg_body ( leg );
32 - 1985
 
1986
        report_html = TRUE;
1987
 
1988
        pri_leg_body ( leg );
1989
        pri_eleg_body ( leg );        
1990
 
1991
        report_html = FALSE;
29 - 1992
    }
1993
 
1994
    pri_final();
1995
    pri_final_html();
52 - 1996
    pri_csv_data();
29 - 1997
    pri_summary();
60 - 1998
    pri_awards_html();
29 - 1999
    pri_awards();
2000
    pri_master_index();
2001
 
2002
    report_all = FALSE;
2003
}
2004
 
2005
 
2006
/*========================================================================
2007
 *
1 root 2008
 *  Print a class header
2009
 *
2010
 *  Purpose:
2011
 *      This function is called to print a class header
2012
 *
2013
 *  Parameters:
2014
 *      class           Name of this class
2015
 *      final           False - prelim results
2016
 *
2017
 *  Returns:
2018
 *      Nothing
2019
 *
2020
 *========================================================================*/
2021
 
2022
void print_class_header( int class, int final )
2023
{
2024
    int         j;
2025
 
2026
    /*
2027
    **  Give a clear indication that the report is preliminary
2028
    */
2029
 
2030
    if( !final )
2031
        print( "PRELIMINARY RESULTS ONLY\n\n" );
2032
 
2033
    /*
2034
    **  Now printout the column headings
2035
    **  This is a two line display
2036
    **
2037
    **  Line-1  Leg names
2038
    */
2039
    print( "%-*s %-*s %-*s", 4, "", 4, "", 3, "" );
2040
    for( j = 1; j <= config.num_legs; j++ )
2041
    {
2042
        print_bold( TRUE );
2043
        print( "  %-*s", 18, config.leg_name[j - 1] );
2044
        print_bold( FALSE );
2045
    }
2046
    print( "  %-8s %-4s\n", "Total", ( class < 0 ) ? "Cat" : "Fin" );
2047
 
2048
 
2049
    /*
2050
    **  Line-2  Details
2051
    */
2052
    print_underline( TRUE );
2053
    print( "%-*s %*s %-*s", 4, final ? "Plce" : "Team",
2054
                            4, final ? "Team" : "Plce",
2055
                            3, "Cat" );
2056
 
2057
    for( j = 1; j <= config.num_legs; j++ )
2058
        print( "  %-8s %-4s %-4s", "Time", " LP", " EP" );
2059
 
2060
    print( "  %-8s %-4s\n", "Time", "Plce" );
2061
    print_underline( FALSE );
2062
}
2063
 
2064
/*========================================================================
2065
 *
2066
 *  Generate the class stats
2067
 *
2068
 *  Purpose:
2069
 *      This function is called to Generate the class stats
2070
 *
2071
 *  Parameters:
2072
 *      c           Class to print
2073
 *      final       TRUE: Final data
2074
 *                  FALSE: Interim data
2075
 *
2076
 *  Returns:
2077
 *      Nothing
2078
 *
2079
 *========================================================================*/
2080
 
2081
void print_class_stats( int c, int final )
2082
{
2083
    int         i, j;
2084
    char        *title;
2085
 
2086
    if( c < 0 )
2087
    {
2088
        title = "Event";
2089
        c = 0;
2090
    }
2091
    else
2092
    {
2093
        title = "Category";
2094
    }
2095
 
2096
    print( "\n" );
2097
    if ( report_html ) print_underline(TRUE);
2098
    print( "%s statistics", title );
2099
    if ( report_html ) print_underline(FALSE);
2100
    print( "\n" );
2101
 
2102
 
2103
    /*
2104
    **  Print the names of the different legs
2105
    */
2106
    print( "%-*s       ", LEN_CLASS_NAME, "" );
2107
    for( i = 1; i <= config.num_legs; i++ )
2108
    {
2109
        print_bold( TRUE );
2110
        print( "%-13s  ", config.leg_name[i - 1] );
2111
        print_bold( FALSE );
2112
    }
2113
    print( "%-13s  \n", final ? "Total" : "" );
2114
 
2115
    /*
2116
    **  Print the fastest teams for each leg and overall
2117
    **  Add cross references to the team names for the fastest teams
2118
    */
2119
    print( "%*s : ", LEN_CLASS_NAME, "Fastest" );
2120
    for( i = 0; i <= config.num_legs; i++ )
2121
    {
2122
        j = i + 1;
2123
        if( i >= config.num_legs )
2124
        {
2125
            if( final )
2126
                j = 0;                           /* Leg-0 last */
2127
            else
2128
                break;
2129
        }
2130
 
2131
        if ( report_html ) print( "<A HREF=\"%s#Team_%04d\">", p_filename(filebase, "name" ,"html"), stats.fast.team[j][c] );
2132
        print( "%4d",  stats.fast.team[j][c] );
2133
        if ( report_html ) print( "</A>" );
2134
        print( " %s  ", time_a( stats.fast.time[j][c] ) );
2135
    }
2136
    print( "\n" );
2137
 
2138
    /*
2139
    **  Print the average time for each leg
2140
    */
2141
    print( "%*s : ", LEN_CLASS_NAME, "Average" );
2142
    for( i = 0; i <= config.num_legs; i++ )
2143
    {
2144
        j = i + 1;
2145
        if( i >= config.num_legs )
2146
        {
2147
            if( final )
2148
                j = 0;                           /* Leg-0 last */
2149
            else
2150
                break;
2151
        }
2152
        print( "     %s  ", time_a( stats.average[j][c] ) );
2153
    }
2154
}
2155
 
2156
/*========================================================================
2157
 *
2158
 *  Print the legend
2159
 *
2160
 *  Purpose:
2161
 *      This function is called to Print the legend
2162
 *
2163
 *  Parameters:
2164
 *      class       - Class currently being printed
18 david 2165
 *      full        - Display full legend
1 root 2166
 *
2167
 *  Returns:
2168
 *      Nothing
2169
 *
2170
 *========================================================================*/
2171
 
18 david 2172
void print_legend ( int class, int full )
1 root 2173
{
2174
 
2175
    int         i;
2176
    char        line[201];
2177
    FILE       *adfile = NULL;
2178
    int         count;
2179
 
2180
    /*
2181
     * First the categories 
2182
     */
2183
    print( "\n\n" );
2184
    if ( report_html ) print_underline(TRUE);
2185
    print( "Category abbreviations" );
2186
    if ( report_html ) print_underline(FALSE);
2187
    print( "\n" );
2188
 
2189
 
2190
    for( i = 1, count = 0; i <= config.num_class; i++ )
2191
    {
2192
#if 0
2193
        /*
2194
        **  Skip any non-equestrian class in the legend
2195
        **  Don't want to tell the general user whats goes on, unless we actually
2196
        **  creating the non-equestrian report.
2197
        */
2198
        if ( class != config.nonequestrian_class  && i == config.nonequestrian_class )
2199
            continue;
2200
#endif
2201
        if ( report_html ) print( "<A HREF=\"%s\">",p_filename(filebase, config.team_class[i - 1].abr ,"html") );
2202
        print( "%-*s", 3, config.team_class[i - 1].abr );
2203
        if ( report_html ) print( "</A>" );
2204
        print( " : %-*s  ", LEN_CLASS_NAME, config.team_class[i - 1].full_name );
2205
 
2206
        if( !( ++count % 5 ) )
2207
            print( "\n" );
2208
    }
2209
 
2210
    /*
2211
    **  Add link to the finish order report
2212
    */
2213
    if ( report_html )
2214
    {
2215
        print( "<A HREF=\"%s\">", p_filename(filebase, "finish" ,"html") );
2216
        print( "%-*s", 3, "All" );
2217
        print( "</A>" );
2218
        print( " : %-*s  ", LEN_CLASS_NAME, "Finishing Order" );
2219
    }
2220
 
2221
    /*
2222
    **  Country data - if countries have been defined
2223
    */
2224
    if( config.num_countries )
2225
    {
2226
        print( "\n\n" );
2227
        if ( report_html ) print_underline(TRUE);
2228
        print( "Country abbreviations" );
2229
        if ( report_html ) print_underline(FALSE);
2230
        print( "\n" );
2231
 
2232
        for( i = 0, count = 0; i < MAX_COUNTRY; i++ )
2233
        {
2234
            if( config.country_name[i].abr[0] )
2235
            {
2236
                print( "%-*s : %-*s  ", 4, config.country_name[i].abr,
2237
                       LEN_CNTRY_NAME, config.country_name[i].full_name );
2238
                if( !( ++count % 5 ) )
2239
                    print( "\n" );
2240
            }
2241
        }
2242
    }
18 david 2243
    print( "\n" );
1 root 2244
 
2245
    /*
2246
     * Other comments 
2247
     */
18 david 2248
    if ( full )
2249
    {
2250
        print( "\nPlace numbers (LP and EP)\n" );
2251
        print( "LP - Placing based on elapsed time within the leg.                Cat Plce - Placing within the category.\n" );
2252
        print( "EP - Placing based on accumulated times to the end of that leg.   Fin Plce - Overall placing within the event.\n" );
59 - 2253
        print( "U  - Placing not available.\n" );
18 david 2254
    }
1 root 2255
 
2256
    /*
2257
     *  Insert the contents of the config.addendum file
2258
     *  or a defualt message
2259
     */
2260
    if( config.addendum[0] )
2261
        adfile = fopen( config.addendum, "rt" );  /* Open the file for reading */
2262
 
2263
    if( adfile )
2264
    {
2265
        while( fgets( line, sizeof(line)-1, adfile ) )
2266
            print( "%s", line );
2267
    }
2268
    else
2269
    {
2270
        print( "\nTiming and Results by\n" );
2271
        print( "Embedded Solutions\n" );
2272
    }
2273
}
2274
 
2275
/*========================================================================
2276
 *
2277
 *  Return place data
2278
 *
2279
 *  Purpose:
2280
 *      This function is called to return place data
2281
 *
2282
 *      This routine is called to fill a print team_buffer - to allow for
2283
 *      multiple calls to this function ( before the data is used ) a number
2284
 *      of static team_buffers are maintained
2285
 *
2286
 *  Parameters:
2287
 *      num         place - if not bad_times
2288
 *      disq        Disqualified flag
2289
 *      time        Time data is based on
2290
 *
2291
 *  Returns:
2292
 *      This function returns a pointer to the character string for the
2293
 *      number or a pointer to a bad_times string.
2294
 *
2295
 *========================================================================*/
2296
 
2297
char       *pi_place( int num, int disq, time_t time )
2298
{
2299
    static char store[2][5];                     /* 2 stores for 4 digit numbers */
2300
    static int  i = 0;                           /* Current index into store */
2301
    static char *dis = "D";                      /* Disqualified */
2302
    static char *non = "-";                      /* Invalid time */
2303
 
2304
    if( disq )                                   /* Disqualified team */
2305
        return ( dis );
2306
    if( time <= 0 )                              /* Unknown time */
2307
        return ( non );
2308
 
2309
    i++;
2310
    if( i >= 2 )
2311
        i = 0;                                   /* Select next entry */
2312
    sprintf( store[i], "%4d", num );
2313
    return ( store[i] );
2314
 
2315
}
2316
 
2317
/*========================================================================
2318
 *
2319
 *  Return place data
2320
 *
2321
 *  Purpose:
2322
 *      This function is called to Return place data
2323
 *
2324
 *      This routine is called to fill a print team_buffer - to allow for
2325
 *      multiple calls to this function ( before the data is used ) a number
2326
 *      of static team_buffers are maintained
2327
 *
2328
 *  Parameters:
2329
 *      num         place - if not bad_times
2330
 *      disq        Disqualified flag
2331
 *
2332
 *  Returns:
2333
 *      This function returns a pointer to the character string for the
2334
 *      number or a pointer to a bad_times string.
2335
 *
2336
 *========================================================================*/
2337
 
2338
char *pr_place( int num, int disq )
2339
{
2340
    static char store[2][5];                     /* 2 stores for 4 digit numbers */
2341
    static int  i = 0;                           /* Current index into store */
2342
    static char *dis = "U";
2343
 
2344
    if( disq )
2345
        return ( dis );
2346
 
2347
    i++;
2348
    if( i >= 2 )
2349
        i = 0;                                   /* Select next entry */
2350
    sprintf( store[i], "%4d", num );
2351
    return ( store[i] );
2352
 
2353
}
2354
 
2355
/*========================================================================
2356
 *
47 - 2357
 *  Return place data
2358
 *
2359
 *  Purpose:
2360
 *      This function is called to Return place data
2361
 *
2362
 *      This routine is called to fill a print team_buffer - to allow for
2363
 *      multiple calls to this function ( before the data is used ) a number
2364
 *      of static team_buffers are maintained
2365
 *
2366
 *  Parameters:
2367
 *      num         place - if not bad_times
2368
 *      disq        Disqualified flag
59 - 2369
 *      ne          Non Equestrian Flag
47 - 2370
 *
2371
 *  Returns:
2372
 *      This function returns a pointer to the character string for the
2373
 *      number or a pointer to a bad_times string.
2374
 *
2375
 *========================================================================*/
2376
 
2377
char *pr_place_ne( int num, int disq, int ne )
2378
{
2379
    static char store[2][5];                     /* 2 stores for 4 digit numbers */
2380
    static int  i = 0;                           /* Current index into store */
2381
    static char *dis = "U";
2382
 
59 - 2383
    if( disq && ! ne )
2384
         return ( dis );
47 - 2385
 
59 - 2386
    if( ++i >= 2 )
47 - 2387
        i = 0;                                   /* Select next entry */
2388
    sprintf( store[i], "%4d", num );
2389
    return ( store[i] );
2390
 
2391
}
2392
 
2393
/*========================================================================
2394
 *
1 root 2395
 *  Check data for bad times
2396
 *
2397
 *  Purpose:
2398
 *      This function is called to Check data for bad times
2399
 *      Scan the sort data structure and locate entries that have incorrect
2400
 *      times.
2401
 *      
2402
 *      Entries that have invalid leg times are displayed to the operator
2403
 *      and the report process can be aborted
2404
 *
2405
 *  Parameters:
2406
 *      leg         Leg to test
2407
 *      mode            Either end or elapsed times to be tested
2408
 *
2409
 *  Returns:
2410
 *      Returns FALSE if the report operation is to be aborted
2411
 *
2412
 *========================================================================*/
2413
 
2414
bool ck_data( int leg, int mode )
2415
{
2416
    ty_s_data  *ptr;
2417
    unsigned    i;
2418
    int         bad = 0;
2419
    int         j = 0;
2420
    int         k, bad_leg;
2421
    time_t     *t;                               /* An array of times */
2422
 
29 - 2423
 
2424
 
1 root 2425
    ptr = sort_data;
2426
    for( i = 1; i <= sort_num; i++, ptr++ )
2427
    {
2428
        bad_leg = 0;
2429
        if( mode == C_DISQUAL )
2430
        {
2431
            ptr->flags.bad_times = ptr->flags.disqualified;
2432
            continue;
2433
        }
2434
 
2435
        if( mode == C_ELAPSED )
2436
            t = ptr->lege;
2437
        else
2438
            t = ptr->leg;
2439
 
50 - 2440
 
2441
        if ( leg >= 0 )
1 root 2442
        {
50 - 2443
            ptr->flags.bad_times = (ptr->flags.disqualified && ! ptr->flags.non_equestrian);
2444
        }
2445
        else
2446
        {
2447
            ptr->flags.bad_times = ptr->flags.disqualified;
2448
        }
2449
 
2450
        if( ! ptr->flags.bad_times )
2451
        {
1 root 2452
            if( leg <= 0 )
2453
            {
2454
                for( k = 0; k <= config.num_legs; k++ )
2455
                {
2456
                    if ( !(config.equestrian_leg && ptr->flags.non_equestrian && config.equestrian_leg == k  ))
2457
                        bad_leg |= ( t[k] <= 0 );
2458
                }
2459
            }
2460
            else
2461
            {
2462
                bad_leg = t[leg] <= 0;
2463
            }
2464
 
2465
            if( bad_leg )
2466
            {
2467
                ptr->flags.bad_times = TRUE;
29 - 2468
 
2469
                if ( ! report_all )
1 root 2470
                {
29 - 2471
                    if( !bad )
2472
                        printf( "Team with incorrect time information\n" );
2473
                    if( ++j > 15 )
2474
                    {
2475
                        printf( "\n" );
2476
                        j = 0;
2477
                    }
2478
                    printf( "%4d ", ptr->team );
2479
                    bad++;
1 root 2480
                }
2481
            }
2482
        }
2483
    }
2484
 
2485
    if( bad )
2486
    {
2487
        printf( "\n%d teams with incorrect times.\n", bad );
2488
        return ( !getyes
2489
                 ( "These have been flagged as unplaced - continue report" ) );
2490
    }
2491
    return ( FALSE );
2492
}
2493
 
2494
/*========================================================================
2495
 *
2496
 *  Update placing information
2497
 *
2498
 *  Purpose:
2499
 *      This function is called to Update placing information
2500
 *
2501
 *      This routine will rip through the data generating the team placing in
2502
 *      a) Within a leg
2503
 *      b) At the end of a leg
2504
 *      c) Within a leg by  class
2505
 *      d) At the end of a leg by class
2506
 *
2507
 *      This function is provided to allow the display routines to
2508
 *      be accessed and updated without the need to run a report
2509
 *
2510
 *  Parameters:
2511
 *      xxxx        a ptr to the xxxx stuff
2512
 *
2513
 *  Returns:
2514
 *      Nothing
2515
 *
2516
 *========================================================================*/
2517
 
2518
void srt_place(void)
2519
{
2520
    int         i, j;
2521
 
2522
    cur( 0, 5 );
2523
    printf( "Update the team placings to the data base\n" );
2524
    flush_out();
2525
    if( ck_data( -1, C_ELAPSED ) )
2526
        return;
2527
    do_big_sort();
2528
 
2529
    /*
2530
     * Generate the stats and display them on the screen for interest
2531
     * This operation will not hurt - so why not
2532
     */
2533
 
2534
    gen_stats();
2535
    printf( "\nEvent statistics\n\n" );
2536
    printf( "%-*s   %-13s ", LEN_CLASS_NAME, "", "Overall" );
2537
    for( i = 1; i <= config.num_legs; i++ )
2538
        printf( "%-13s ", config.leg_name[i - 1] );
2539
 
2540
    for( j = 0; j <= config.num_class; j++ )
2541
    {
2542
        printf( "\n%-*s : ", LEN_CLASS_NAME,
2543
                j ? config.team_class[j - 1].full_name : "Overall" );
2544
        for( i = 0; i <= config.num_legs; i++ )
2545
        {
2546
            printf( "%4d ", stats.fast.team[i][j] );
2547
            printf( "%s ", time_a( stats.fast.time[i][j] ) );
2548
        }
2549
        printf( "\n%*s : ", LEN_CLASS_NAME, "Average" );
2550
        for( i = 0; i <= config.num_legs; i++ )
2551
        {
2552
            printf( "     %s ", time_a( stats.average[i][j] ) );
2553
        }
2554
    }
2555
    printf( "\nAny key to continue" );
2556
    ( void ) getinp();
2557
}
2558
 
2559
/*========================================================================
2560
 *
2561
 *  Calculate summary information
2562
 *
2563
 *  Purpose:
2564
 *      This function is called to calculate summary information
2565
 *
2566
 *  Parameters:
2567
 *      ptr         - Address of a summary structure to fill in
2568
 *
2569
 *  Returns:
2570
 *      Nothing
2571
 *
2572
 *========================================================================*/
2573
 
2574
void calc_class_summary( t_class_summary * ptr )
2575
{
2576
    int i;
2577
 
2578
    /*
2579
    **  Reset the data
2580
    */
2581
    memset ( ptr, 0, sizeof (*ptr ));
2582
 
2583
    /*
2584
     * Extract the required data from the data base
2585
     * Only save that information required for the operation
2586
     */
2587
 
2588
    for( i = config.min_team; i <= config.max_team; i++ )
2589
    {
2590
        if( valid_field( i ) && g_record( i, &team_buf ) )
2591
        {
2592
            ptr->total.total++;
2593
            ptr->class[team_buf.class].total++;
2594
 
2595
            if ( team_buf.flags.disqualified )
2596
            {
2597
                ptr->class[team_buf.class].disqualified++;
2598
                ptr->total.disqualified++;
2599
            }
2600
 
2601
            if ( config.nonequestrian_class && team_buf.flags.non_equestrian )
2602
            {
2603
                ptr->class[team_buf.class].non_equestrian++;
2604
                ptr->total.non_equestrian++;
2605
            }
2606
        }
2607
    }
13 david 2608
 
2609
    /*
2610
    **  Fix up the totals for the non equestrians
2611
    **  This is not a real category but a summary of the others.
2612
    */
2613
    if ( config.nonequestrian_class  )
2614
    {
2615
        ptr->class[config.nonequestrian_class].total += ptr->total.non_equestrian;
2616
    }
1 root 2617
}
2618
 
2619
/*========================================================================
2620
 *
2621
 *  Display summary information
2622
 *
2623
 *  Purpose:
2624
 *      This function is called to display summary information
2625
 *
2626
 *  Parameters:
2627
 *      None
2628
 *
2629
 *  Returns:
2630
 *      Nothing
2631
 *
2632
 *========================================================================*/
2633
 
2634
void display_summary (void)
2635
{
2636
 
2637
    t_class_summary data;
2638
    int         i;
2639
    int         line = 2;
2640
 
2641
    cur( 0, line );
2642
    printf( "Generating Summary Information" );
2643
    calc_class_summary( & data );
2644
 
2645
 
2646
    /*
2647
    **  Display summary stats
2648
    */
2649
 
2650
    cur( 0, line );
2651
    console_clreol();
2652
    printf( "Summary Information\n\n" );
2653
    printf( "%*s : %-7s %-7s%-7s\n", LEN_CLASS_NAME,
2654
                                      "Category",
2655
                                      "Total",
2656
                                      "Disq",
2657
                                      "NonEq" );
2658
 
2659
    for( i = 0; i < config.num_class; i++ )
2660
    {
2661
        /*
2662
        **  The non-equestrian leg does not have any data
2663
        **  Supress the display
2664
        */
2665
        if ( config.nonequestrian_class == i+1  )
2666
            continue;
2667
 
2668
        printf( "%*s : %-7d %-7d %-7d\n", LEN_CLASS_NAME,
2669
                                          config.team_class[i].full_name,
2670
                                          data.class[i+1].total,
2671
                                          data.class[i+1].disqualified,
2672
                                          data.class[i+1].non_equestrian );
2673
    }
2674
 
2675
    printf( "\n" );
2676
    printf( "%*s : %-7d %-7d %-7d\n", LEN_CLASS_NAME,
2677
                                      "Totals",
2678
                                      data.total.total,
2679
                                      data.total.disqualified,
2680
                                      data.total.non_equestrian );
2681
 
2682
    printf( "\nAny key to continue " );
2683
    getinp();
2684
}
2685
 
13 david 2686
/*========================================================================
2687
 *
2688
 *  Print summary information
2689
 *
2690
 *  Purpose:
2691
 *      This function is called to print summary information
2692
 *
2693
 *  Parameters:
2694
 *      None
2695
 *
2696
 *  Returns:
2697
 *      Nothing
2698
 *
2699
 *========================================================================*/
1 root 2700
 
13 david 2701
void pri_summary (void)
2702
{
2703
 
2704
    t_class_summary data;
2705
    int         i;
2706
    int         line = 2;
2707
 
2708
 
2709
    if( !open_printer( "", "summary", 132, 0, "Summary Information" ) )
2710
        return;
2711
 
2712
    cur( 0, line );
2713
    printf( "Generating Summary Information" );
2714
    calc_class_summary( & data );
2715
 
2716
 
2717
    /*
2718
    **  Display summary stats
2719
    */
2720
 
2721
    print( "%*s : %-7s %-7s%-7s\n", LEN_CLASS_NAME,
2722
                                      "Category",
2723
                                      "Total",
2724
                                      "Disq",
2725
                                      "NonEq" );
2726
 
2727
    for( i = 0; i < config.num_class; i++ )
2728
    {
2729
        /*
2730
        **  The non-equestrian leg does not have any data
2731
        **  Supress the display
2732
        */
2733
        if ( config.nonequestrian_class == i+1  )
2734
            continue;
2735
 
2736
        print( "%*s : %-7d %-7d %-7d\n", LEN_CLASS_NAME,
2737
                                          config.team_class[i].full_name,
2738
                                          data.class[i+1].total,
2739
                                          data.class[i+1].disqualified,
2740
                                          data.class[i+1].non_equestrian );
2741
    }
2742
 
2743
    print( "\n" );
2744
    print( "%*s : %-7d %-7d %-7d\n", LEN_CLASS_NAME,
2745
                                      "Totals",
2746
                                      data.total.total,
2747
                                      data.total.disqualified,
2748
                                      data.total.non_equestrian );
2749
 
2750
    close_printer();
29 - 2751
    if ( !report_all )
2752
    {
2753
        printf( "\nAny key to continue " );
2754
        getinp();
2755
    }
13 david 2756
}
2757
 
2758
 
2759
 
1 root 2760
/*========================================================================
2761
 *
2762
 *  Main sort routine for final data
2763
 *
2764
 *  Purpose:
2765
 *      This function is called to do the report sort routine for final data
2766
 *      This routine will fill all the gaps in the sort_aux structure
2767
 *
2768
 *  Parameters:
2769
 *      None
2770
 *
2771
 *  Returns:
2772
 *      Nothing
2773
 *
2774
 *========================================================================*/
2775
 
2776
void do_big_sort(void)
2777
{
2778
    int         i, k;                            /* Looooopy things */
2779
    unsigned    j;
2780
    ty_s_data  *ptr;                             /* Pointer to sort data */
2781
    int         class;                           /* Current class */
2782
 
2783
    printf( "Sorting it ALL out" );
2784
    flush_out();
2785
 
2786
    for( i = 0; i <= config.num_legs; i++ )
2787
    {
2788
        /*
2789
        **  Sort on leg elapsed time
49 - 2790
        **  Then save the teams elapsed place in each leg
1 root 2791
        */
2792
        sort_team_data( i, S_L );
49 - 2793
        for( j = 1, k = 1, ptr = sort_data; j <= sort_num; ptr++, j++ )
1 root 2794
        {
49 - 2795
            if ( ptr->class == config.nonequestrian_class )
2796
                continue;
2797
 
2798
            sort_aux[ptr->team].l_place[i] = k++;
1 root 2799
            sort_aux[ptr->team].team = ptr->team;
2800
        }
2801
 
2802
        /*
2803
        **  Sort on leg end time
2804
        **  Then save the teams place at the end of each leg
2805
        */
2806
        sort_team_data( i, S_LE );
49 - 2807
        for( j = 1, k = 1, ptr = sort_data; j <= sort_num; ptr++, j++ )
2808
        {
2809
            if ( ptr->class == config.nonequestrian_class )
2810
                continue;
2811
 
2812
            sort_aux[ptr->team].le_place[i] = k++;
2813
        }
1 root 2814
 
2815
        /*
2816
        **  Sort on elapsed time per class
2817
        **  The save the teams elapsed place in each leg per class
2818
        */
2819
        sort_team_data( i, S_LC );
2820
        class = -1;
2821
        for( k = 1, j = 1, ptr = sort_data; j <= sort_num; j++, ptr++ )
2822
        {
2823
            if( class != ptr->class )
2824
            {
2825
                k = 1;
2826
                class = ptr->class;
2827
            }
2828
            sort_aux[ptr->team].lc_place[i] = k++;
2829
        }
2830
 
2831
        /*
2832
        **  Sort on end time per class
2833
        **  Then save the teams place at the end of each leg per class
2834
        */
2835
        sort_team_data( i, S_LEC );
2836
        class = -1;
2837
        for( k = 1, j = 1, ptr = sort_data; j <= sort_num; j++, ptr++ )
2838
        {
2839
            if( class != ptr->class )
2840
            {
2841
                k = 1;
2842
                class = ptr->class;
2843
            }
2844
            sort_aux[ptr->team].lec_place[i] = k++;
2845
        }
2846
    }
2847
 
2848
    /*
2849
    **  Write the place information back to disk for use in the displays
2850
    */
2851
    printf( "\nWriting it all back to the disk file" );
2852
    flush_out();
2853
 
2854
    for( i = config.min_team; i <= config.max_team; i++ )
2855
    {
2856
        if( sort_aux[i].team && valid_field( i ) && g_record( i, &team_buf ) )
2857
        {
2858
            for( k = 0; k <= config.num_legs; k++ )
2859
            {
2860
                team_buf.leg[k].l_place = sort_aux[i].l_place[k];
2861
                team_buf.leg[k].le_place = sort_aux[i].le_place[k];
2862
                team_buf.leg[k].lc_place = sort_aux[i].lc_place[k];
2863
                team_buf.leg[k].lec_place = sort_aux[i].lec_place[k];
2864
            }
2865
            put_team_record( i, &team_buf );
2866
        }
2867
    }
2868
}
2869
 
2870
/*========================================================================
2871
 *
2872
 *  Sort in memory buffer
2873
 *
2874
 *  Purpose:
2875
 *      This function is called to Sort in memory buffer
2876
 *
2877
 *  Parameters:
2878
 *      leg         Requested leg
2879
 *      mode        Defines the sort mode
2880
 *
2881
 *  Returns:
2882
 *      Nothing
2883
 *
2884
 *========================================================================*/
2885
 
2886
void sort_team_data( int leg, int mode )
2887
{
2888
 
2889
    unsigned    j;
2890
    ty_s_data  *ptr;
2891
 
2892
    sort_leg = leg;                              /* Leg is global for the comparison function */
2893
    sort_mode = mode;                            /* Mode is global for compare function */
2894
 
2895
    qsort( ( char * ) sort_data, sort_num, sizeof( ty_s_data ), sort_comp );
2896
 
2897
    /*
2898
     * Insert "place data" into the sorted data
2899
     * This simply the index into the array of data - after its been
2900
     * sorted.
2901
     */
2902
    ptr = sort_data;
2903
    for( j = 1; j <= sort_num; j++, ptr++ )
2904
        ptr->place = j;
2905
 
2906
}
2907
 
2908
/*========================================================================
2909
 *
2910
 *  qsort comparison function
2911
 *
2912
 *  Purpose:
2913
 *      This function is called by qsort as a Sort comparison function
2914
 *
2915
 *  Parameters:
2916
 *      a       - 1st record
2917
 *      b       - 2nd record
2918
 *
2919
 *  Returns:
2920
 *      value to qsort
2921
 *
2922
 *========================================================================*/
2923
 
2924
int sort_comp( const void * aa, const void * bb )
2925
{
2926
    const ty_s_data * a = aa;
2927
    const ty_s_data * b = bb;
2928
 
2929
 
2930
    int         i;                               /* One of those */
2931
    time_t      ta, tb;                          /* Leg times */
2932
    int         na, nb;                          /* Number of valid legs */
2933
    time_t      tta, ttb;                        /* Temp times */
2934
 
2935
    /*
2936
    **  Sorting on Team Number
2937
    */
2938
    if( sort_mode == S_TEAM )
2939
        return ( a->team - b->team );
2940
 
2941
    /*
2942
    **  Sorting on Class and Team Number
2943
    */
2944
    if( sort_mode == S_CLASS )
2945
    {
2946
        if( a->class != b->class )
2947
            return ( a->class - b->class );
2948
        else
2949
            return ( a->team - b->team );
2950
    }
2951
 
2952
    /*
2953
    **  Sorting within a class
2954
    **  First sort on the class
2955
    */
2956
    if( sort_mode == S_LEC || sort_mode == S_LC )   /* Sort within a class */
2957
        if( a->class != b->class )
2958
            return ( a->class - b->class );
2959
 
49 - 2960
#if 1
1 root 2961
    /*
49 - 2962
    **  Always put the nonequestrian_class at the end
2963
    **  Simplifies the creation of ordered lists as these
2964
    **  Entries are not present in the main body
2965
    */
2966
    if ( a->class == config.nonequestrian_class ||  b->class == config.nonequestrian_class )
2967
    {
2968
        if ( a->class == config.nonequestrian_class &&  b->class == config.nonequestrian_class )
2969
        {
2970
        }
2971
        else
2972
        {
2973
            return ( a->class == config.nonequestrian_class ? 1 : -1 );
2974
        }
2975
 
2976
    }
2977
#endif
2978
 
2979
    /*
1 root 2980
    **  Now we need to examine the times as we have sorted
2981
    **  on every thing else.
2982
    **
2983
    **  If one of the teams has bad_times, then that team is placed
2984
    **  lower in the sorting order. If both teams have bad times
2985
    **  then sort on team number. ie: Unplaced teams are sorted on
2986
    **  team number
47 - 2987
    **
2988
    **  If not sorting within a class (ie Overall), then Non_Equestrian
2989
    **  is better than a bad time. Places NE before disqualified
2990
    **
2991
    **
2992
    **  Note: NE also have bad_times set
1 root 2993
    */
49 - 2994
#if 1
1 root 2995
    if( a->flags.bad_times || b->flags.bad_times )  /* Valid data has precedence */
2996
    {
48 - 2997
        if( a->flags.bad_times && b->flags.bad_times )
47 - 2998
        {
50 - 2999
            if( a->flags.non_equestrian || b->flags.non_equestrian )
47 - 3000
            {
50 - 3001
                if( a->flags.non_equestrian && b->flags.non_equestrian )
47 - 3002
                {
50 - 3003
                    /*
3004
                    **  Both are non equestrian
3005
                    **  Let the time sort operate ...
3006
                    */
3007
                    //return ( a->team - b->team );
47 - 3008
                }
50 - 3009
                else
3010
                {
3011
                    /* One is equestrian */
3012
                    /* Good times better than NE */
3013
                    return ( a->flags.non_equestrian ? -1 : 1 );
3014
                }
47 - 3015
            }
48 - 3016
            else
50 - 3017
            {
3018
                /* Neither is equestrian */
3019
                return ( a->team - b->team );
3020
            }
47 - 3021
        }
1 root 3022
        else
3023
            return ( a->flags.bad_times ? 1 : -1 );
3024
    }
49 - 3025
#else
3026
    if( a->flags.bad_times || b->flags.bad_times )  /* Valid data has precedence */
3027
    {
3028
        if( a->flags.bad_times && b->flags.bad_times )
3029
            return ( a->team - b->team );
3030
        else
3031
            return ( a->flags.bad_times ? 1 : -1 );
3032
    }
1 root 3033
 
49 - 3034
    /*
3035
    **  Not sorting within a class ie: Overall
3036
    **  Non-Equestrian is at the end, so that it doesn't get counted in the
3037
    **  finishing order
3038
    */
3039
    if( sort_mode == S_LE || sort_mode == S_L )     /* Sort NOT within a class */
3040
    {
3041
        if( a->flags.non_equestrian || b->flags.non_equestrian )
3042
        {
3043
            if( a->flags.non_equestrian && b->flags.non_equestrian )
3044
                return ( a->team - b->team );
3045
            else
3046
                return ( a->flags.non_equestrian ? 1 : -1 );
3047
        }
3048
    }
3049
#endif
1 root 3050
 
3051
    /*
3052
    **  Before we sort on times we must determine which time to
3053
    **  use. Finish time, Leg end times, Leg Elapsed times.
3054
    */
3055
 
3056
    switch ( sort_mode )
3057
    {
3058
      /*
3059
      **    Sort on finish times
3060
      */
3061
      case S_FIN:
3062
        ta = a->leg[sort_leg];
3063
        tb = b->leg[sort_leg];
3064
        break;
3065
 
3066
 
3067
      /*
3068
      **    Sort on accumulated leg times
3069
      */
3070
      case S_LE:
3071
      case S_LEC:
3072
        if( sort_leg )
3073
        {
3074
            /*
3075
            **  Calculate accumulated time up to the desired leg
3076
            **  If the two teams have a different number of valid
3077
            **  leg times then order by the team that has completed
3078
            **  more legs.
3079
            */
3080
            ta = tb = ( time_t ) 0;
3081
            na = nb = 0;
3082
            for( i = 1; i <= sort_leg; i++ )
3083
            {
3084
                tta = a->lege[i];
3085
                ttb = b->lege[i];
3086
                if( tta > 0 )
3087
                {
3088
                    na++;
3089
                    ta += tta;
3090
                }
3091
                if( ttb > 0 )
3092
                {
3093
                    nb++;
3094
                    tb += ttb;
3095
                }
3096
            }
3097
            if( na != nb )
3098
                return ( nb - na );
3099
        }
3100
        else
3101
        {
3102
            ta = a->leg[sort_leg] - a->start;
3103
            tb = b->leg[sort_leg] - b->start;
3104
        }
3105
        break;
3106
 
3107
      /*
3108
      **    Sort on Elapsed times
3109
      */
3110
      case S_LC:
3111
      case S_L:
3112
        ta = a->lege[sort_leg];
3113
        tb = b->lege[sort_leg];
3114
        break;
3115
 
3116
      /*
3117
      **    Just to be sure ...
3118
      */
3119
      default:
3120
        return ( 0 );
3121
    }
3122
 
3123
    /*
3124
    **  Finally. Compare the required team times
3125
    */
3126
    if( ta == tb )
3127
        return ( a->team - b->team );
3128
    if( ( ta > 0 ) && ( tb > 0 ) )
3129
        return ( ( int ) ( ta - tb ) );
3130
    return ( ( ta > 0 ) ? -1 : 1 );
3131
}
3132
 
3133
/*========================================================================
3134
 *
18 david 3135
 *  qsort comparison function - competitor names
3136
 *
3137
 *  Purpose:
3138
 *      This function is called by qsort as a Sort comparison function
3139
 *
3140
 *  Parameters:
3141
 *      a       - 1st record
3142
 *      b       - 2nd record
3143
 *
3144
 *  Returns:
3145
 *      value to qsort
3146
 *
3147
 *========================================================================*/
3148
 
3149
int sort_comp_cname( const void * aa, const void * bb )
3150
{
25 - 3151
    ty_s_namedata * a = (ty_s_namedata *)aa;
3152
    ty_s_namedata * b = (ty_s_namedata *)bb;
18 david 3153
 
3154
 
3155
    int         i;                               /* One of those */
3156
 
3157
    /*
3158
    **  Sort by name
3159
    */
3160
    i = strcmp ( a->name, b->name );
3161
    if ( i )
3162
        return ( i );
3163
    a->multi=1;
3164
    b->multi=1;
3165
 
3166
    /*
3167
    **  Sort by Leg
3168
    */
3169
    i = a->leg - b->leg;
3170
    if ( i )
3171
        return ( i );
3172
 
3173
    /*
3174
    **  Sorting on Team Number
3175
    */
3176
    return ( a->team - b->team );
3177
 
3178
}
3179
 
3180
/*========================================================================
3181
 *
1 root 3182
 *  load report data into memory
3183
 *
3184
 *  Purpose:
3185
 *      This routine will pull all the data into memory 
3186
 *      Not all the team data is loaded. Only that essential for the
3187
 *      operation of the sort routine is loaded
3188
 *
3189
 *  Parameters:
3190
 *      None
3191
 *
3192
 *  Returns:
3193
 *      TRUE - All is well
3194
 *
3195
 *========================================================================*/
3196
 
3197
bool load_report_data(void)
3198
{
3199
 
3200
    ty_s_data  *ptr;                             /* pointer to sort data type */
48 - 3201
    ty_s_data  *last;
1 root 3202
    int         j;
3203
    unsigned    num;
3204
 
3205
    printf( "Loading team information - This will not hurt" );
3206
    flush_out();
3207
 
3208
    /*
3209
     * Fetch memory for the data store
3210
     */
3211
 
3212
    if( sort_data )
3213
        free( ( char * ) sort_data );
3214
    sort_data = 0;
3215
 
3216
    if( sort_aux )
3217
        free( ( char * ) sort_aux );
3218
    sort_aux = 0;
3219
    sort_num = 0;                                /* Counter of records in the array */
3220
 
3221
    /*
3222
    **  Allocate memory for the data structures
3223
    **  This will be free'd
3224
    */
3225
    num = config.max_team - config.min_team + 1 ;
3226
 
3227
    /*
3228
    **  Allow for non-equestrian teams - since some of the data is loaded twice
3229
    **  Take a guess that at most 1/2 the teams will be non-equestrian
3230
    */
3231
    num = num * 3 / 2;
3232
 
3233
    sort_data = ( ty_s_data * ) calloc ( num , sizeof( ty_s_data ) );
3234
    sort_aux = ( ty_s_aux * ) calloc( num + 1, sizeof( ty_s_aux ) );
3235
 
3236
    if( sort_data == 0 || sort_aux == 0 )
3237
    {
3238
        printf( "\n\nError in allocating memory\n" );
3239
        sleep( 5 );
3240
        return ( FALSE );
3241
    }
3242
 
3243
    /*
3244
    **  Load data into the memory based data structure
3245
    **  Only load data for valid-teams
3246
    **  Load essential data
3247
    **      Team Number, class and flags
3248
    **      Leg end and elapsed times
3249
    */
3250
    ptr = sort_data;
3251
    for( team = config.min_team; team <= config.max_team; team++ )
3252
    {
3253
        if( valid_field( team ) )
3254
        {
3255
            g_record( team, &team_buf );
3256
            if( team_buf.flags.valid )
3257
            {
48 - 3258
                last = ptr;
1 root 3259
                ptr->team = team;
3260
                for( j = 0; j < MAX_LEGS + 1; j++ )
3261
                {
3262
                    ptr->lege[j] = team_buf.leg[j].elapsed;
3263
                    ptr->leg[j] = team_buf.leg[j].end;
3264
                }
3265
                ptr->start = team_buf.leg[0].start;
3266
                ptr->class = team_buf.class;
3267
 
3268
                ptr->flags = team_buf.flags;
3269
                ptr++;
3270
                sort_num++;
3271
 
3272
                /*
3273
                **  If non-equestrian support is enabled then
3274
                **  duplicate and modify data for the non-equestrian teams
3275
                **      - Change the class
3276
                **      - Modify the leg time
3277
                */
49 - 3278
#if 1
1 root 3279
                if ( config.nonequestrian_class && team_buf.flags.non_equestrian )
3280
                {
3281
                    ptr->team = team;
3282
                    ptr->lege[0] = 0;
3283
 
3284
                    for( j = 0; j < MAX_LEGS + 1; j++ )
3285
                    {
3286
                        if ( j == config.equestrian_leg )
3287
                        {
48 - 3288
                            last->lege[j] = ptr->lege[j] = 0;
1 root 3289
                            if ( config.equestrian_leg > 1 )
48 - 3290
                                last->leg[j] = ptr->leg[j] = ptr->leg[j-1];
1 root 3291
                        }
3292
                        else
3293
                        {
3294
                            if ( j )
48 - 3295
                                last-> lege[j] = ptr->lege[j] = team_buf.leg[j].elapsed;
3296
                            last->leg[j] = ptr->leg[j] = team_buf.leg[j].end;
1 root 3297
                            ptr->lege[0] += ptr->lege[j] ;
48 - 3298
                            last->lege[0] = ptr->lege[0] ;
1 root 3299
                        }
3300
                    }
3301
 
48 - 3302
                    last->start = ptr->start = team_buf.leg[0].start;
1 root 3303
                    ptr->class = config.nonequestrian_class;
3304
                    ptr->flags = team_buf.flags;
3305
                    ptr->flags.disqualified = 0;
48 - 3306
 
3307
 
1 root 3308
                    ptr++;
3309
                    sort_num++;
3310
                }
49 - 3311
#endif
1 root 3312
            }
3313
        }
3314
    }
3315
    return ( TRUE );
3316
}
3317
 
3318
/*========================================================================
3319
 *
3320
 *  Generate all the stats
3321
 *
3322
 *  Purpose:
3323
 *      This function is called to Generate all the stats
3324
 *
3325
 *  Parameters:
3326
 *      None
3327
 *
3328
 *  Returns:
3329
 *      Nothing
3330
 *
3331
 *========================================================================*/
3332
 
3333
void gen_stats(void)
3334
{
3335
    ty_s_data  *ptr;
3336
    unsigned    i;
3337
    int         j;
3338
    int         k;
3339
 
3340
    /*
3341
     * Init all the stats 
3342
     */
3343
    for( i = 0; i <= MAX_LEGS; i++ )
3344
    {
3345
        for( j = 0; j <= MAX_CLASS; j++ )
3346
        {
3347
            stats.team[i][j] = 0;
3348
            stats.fast.team[i][j] = 0;
3349
            stats.fast.time[i][j] = ( time_t ) - 1;
3350
            stats.average[i][j] = 0;
3351
        }
3352
    }
3353
 
3354
    for( i = 1, ptr = sort_data; i <= sort_num; i++, ptr++ )
3355
    {
3356
        /*
3357
        **  If there is any bad times in the team record, then none
3358
        **  of the data can be trusted.
3359
        **
3360
        **  If the team has been disqualified, then don't use any
3361
        **  of the data.
3362
        */
3363
        if( ptr->flags.bad_times || ptr->flags.disqualified )
3364
            continue;
3365
 
3366
        for( j = 0; j <= config.num_legs; j++ )
3367
        {
3368
            if( ptr->lege[j] <= 0 )              /* Ignore bad data */
3369
                continue;
3370
 
3371
            /*
3372
            **  Determine fastest team : overall
3373
            **  Ignore the non-equestrian data as this is in the list twice
3374
            */
3375
            if( ( ptr->lege[j] < stats.fast.time[j][0] )
3376
                || ( stats.fast.time[j][0] < 0 ) )
3377
            {
3378
                if ( ptr->class != config.nonequestrian_class )
3379
                {
3380
                    stats.fast.team[j][0] = ptr->team;
3381
                    stats.fast.time[j][0] = ptr->lege[j];
3382
                }
3383
            }
3384
 
3385
            /*
3386
            **  Determine fastest team : within a class
3387
            */
3388
            if( ( ptr->lege[j] < stats.fast.time[j][ptr->class] )
3389
                || stats.fast.time[j][ptr->class] < 0 )
3390
            {
3391
                stats.fast.team[j][ptr->class] = ptr->team;
3392
                stats.fast.time[j][ptr->class] = ptr->lege[j];
3393
            }
3394
 
3395
            /*
3396
            **  Sum the end times : overall
3397
            */
3398
            if ( ptr->class != config.nonequestrian_class )
3399
            {
3400
                stats.average[j][0] += ptr->lege[j];
3401
                stats.team[j][0]++;
3402
            }
3403
 
3404
 
3405
            /*
3406
            **  Sum the end times : within a class
3407
            */
3408
            stats.average[j][ptr->class] += ptr->lege[j];
3409
            stats.team[j][ptr->class]++;
3410
        }
3411
    }
3412
 
3413
    /*
3414
     * Calculate the averages
3415
     */
3416
    for( k = 0; k <= config.num_legs; k++ )
3417
    {
3418
        for( j = 0; j <= config.num_class; j++ )
3419
        {
3420
            if( stats.team[k][j] )
3421
                stats.average[k][j] /= stats.team[k][j];
3422
            else
3423
                stats.average[k][j] = ( time_t ) - 1;
3424
        }
3425
    }
3426
}
3427
 
3428
/********************************* EOF ***********************************/