Subversion Repositories svn1-original

Rev

Details | Last modification | View Log | RSS feed

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