Subversion Repositories svn1-original

Rev

Rev 381 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
95 - 1
/*************************************************************************
2
*           Copyright (C) 1995 Embedded Solutions
3
*                       All rights reserved
4
*
5
* file:     src\legtime.c
6
*
7
* purpose:  Leg time calculations
8
*
9
* functions
10
*   set_legs                    - Menu: Setup leg times
11
*   tm_lgs                      - Set up the leg start times for leg
12
*   leg_start                   - Set up the leg start times
13
*   tm_fixedstart               - Set the start time for a specific leg
14
*   tm_staggered                - Set a staggered start time for a specific leg
15
*   tm_clearleg                 - Clear start times on a specific leg
16
*   leg_ini                     - Initialize all stored times
17
*   tm_init                     - Initialize all team data
18
*   tm_gen                      - Generate dummy team names
19
*   legs_start_report           - Generate starters report
20
*   ls_timer                    - print the current leg entry
21
*   ls_team                     - print next ( numeric ) leg entry
22
*   sort_legs                   - Qsort callback function
23
*
24
* programmer: David Purdie
25
*
26
* revision  date        by      reason
27
*           11-Oct-89   DDP     leg-3 starttime. Now has an option to generate
28
*                               a printed report of teams and times
29
*
30
*           21-May-90   MV      now able to set start time and generate
31
*                               a printed report for any leg
32
*   00.0    27/01/95    DDP     Tidies up the program and formatted the file
33
*
34
**************************************************************************/
137 david 35
#include    "QDebug"
199 david 36
#include    "mainwindow.h"
95 - 37
#include    "consts.h"
38
#include    "structs.h"
39
#include    "proto.h"
40
 
261 - 41
 
42
void ls_timer_short( t_legs * ptr, int num, bool suppress );
43
void ls_team_short( t_legs * ptr, int num, bool suppress );
44
int sort_team( const void * aa, const void * bb );
45
 
95 - 46
/*========================================================================
47
 *
48
 *  Set up the leg start times for leg
49
 *
50
 *  Purpose:
51
 *      This function is called to Set up the leg start times for leg
52
 *      The start time is based on category information
53
 *
54
 *  Parameters:
55
 *      None
56
 *
57
 *  Returns:
58
 *      Nothing
59
 *
60
 *========================================================================*/
61
 
135 david 62
void tm_lgs1(int leg, time_t starttime, time_t delta, bool report_it, bool clear_it)
95 - 63
{
64
    t_legs     *data;                            /* Address of table */
65
    t_legs     *dptr;                            /* Moving pointer */
66
    int         num_records;                     /* Number of records in array */
67
    int         i;
174 - 68
    team_type   team_buf;
95 - 69
 
70
 
71
    /*
72
    **  Read existing data into memory
73
    */
74
    data = ( t_legs * ) calloc( ( unsigned ) ( config.max_team - config.min_team + 2 ), sizeof( t_legs ) ); /* Fetch memory */
75
    if( !data )
76
    {
137 david 77
        qDebug( "No memory for report" );
95 - 78
        return;
79
    }
80
 
81
    /*
82
     * Extract the required data from the data base
83
     * Only save that information required for the operation
84
     *      - The end time of the previous leg
85
     */
86
    dptr = data;
87
    num_records = 0;
88
    for( i = config.min_team; i <= config.max_team; i++ )
89
    {
90
        if( valid_field( i ) && g_record( i, &team_buf ) )
91
        {
92
            dptr->numb = team_buf.numb;
93
            dptr->start = team_buf.leg[leg-1].end;
94
            dptr->flags = team_buf.flags;
95
            dptr++;
96
            num_records++;
97
        }
98
    }
99
 
100
    /*
101
     * Sort the data into some logical order 
102
     */
103
    qsort( ( char * ) data, num_records, sizeof( t_legs ), sort_legs );
104
 
105
    /*
106
    **  Update the team information based on the start order
107
    **  Ignore validity flags as the data will have been sorted with
108
    **  these in mind.
109
    */
110
    for( dptr = data, i = 0; i < num_records; i++, dptr++ )
111
    {
112
        if( valid_field( dptr->numb ) )
113
        {
114
            g_record( dptr->numb, &team_buf );
115
            team_buf.leg[leg].start = starttime;
116
            starttime += delta;
117
            team_buf.leg[leg].manual = TRUE;
118
 
119
            set_times( &team_buf );
120
            test_times( &team_buf, 0 );
121
            put_team_record( dptr->numb, &team_buf );
122
        }
123
    }
124
 
125
    /*
126
    **  Release the data
127
    */
128
    free( data );
129
 
261 - 130
    if( report_it ) {
137 david 131
        legs_start_report(leg);
261 - 132
    }
95 - 133
 
261 - 134
    if ( clear_it ) {
137 david 135
        tm_clearleg_specified( leg, TRUE);
261 - 136
    }
95 - 137
}
138
 
139
/*========================================================================
140
 *
141
 *  Set up the leg start times for leg
142
 *
143
 *  Purpose:
144
 *      This function is called to Set up the leg start times for leg
145
 *      The start time is based on current placing with:
146
 *          A constant offset added ( ie: lunch)
147
 *          A fixed increment
148
 *
149
 *  Parameters:
150
 *      None
151
 *
152
 *  Returns:
153
 *      Nothing
154
 *
155
 *========================================================================*/
156
 
134 - 157
void tm_lgs(int leg, time_t delta, bool report_it, bool clear_it)
95 - 158
{
174 - 159
    team_type   team_buf;
160
    int team = config.min_team;                      /* Team we are working with */
95 - 161
    while( team <= config.max_team )
162
    {
163
        if( valid_field( team ) )
164
        {
165
            g_record( team, &team_buf );
166
            if( team_buf.flags.valid && team_buf.leg[leg - 1].end > 0 )
167
            {
168
                team_buf.leg[leg].start = team_buf.leg[leg - 1].end + delta;
169
                team_buf.leg[leg].manual = TRUE;
170
            }
171
            else
172
                team_buf.leg[leg].start = ( time_t ) - 1;
173
 
174
            set_times( &team_buf );
175
            test_times( &team_buf, 0 );
176
            put_team_record( team, &team_buf );
177
        }
178
        team++;
179
    }
180
 
181
    if( report_it )
137 david 182
        legs_start_report(leg);
95 - 183
 
184
    if ( clear_it )
137 david 185
        tm_clearleg_specified( leg, TRUE);
95 - 186
}
187
 
188
/*========================================================================
189
 *
190
 *  Set up the leg start times
191
 *
192
 *  Purpose:
193
 *      This function is called to Set up the leg start times
194
 *
195
 *  Parameters:
196
 *      None
197
 *
198
 *  Returns:
199
 *      Nothing
200
 *
201
 *========================================================================*/
202
 
203
void leg_start(void)
204
{
174 - 205
    team_type   team_buf;
206
    int team = config.min_team;                      /* Team we are working with */
95 - 207
    while( team <= config.max_team )
208
    {
209
        if( valid_field( team ) )
210
        {
211
            ( void ) g_record( team, &team_buf );
212
            if( team_buf.teamclass > 0 && team_buf.teamclass <= config.num_class )
213
                team_buf.leg[0].start =
214
                    config.team_class[team_buf.teamclass - 1].start;
215
            else
216
                team_buf.leg[0].start = ( time_t ) - 1;
217
            team_buf.leg[1].manual = 0;
218
            team_buf.leg[1].start = team_buf.leg[0].start;
219
            team_buf.leg[0].l_place = 0;
220
            team_buf.leg[0].le_place = 0;
221
            team_buf.leg[0].lec_place = 0;
222
            team_buf.leg[0].lc_place = 0;
223
            team_buf.leg[0].manual = FALSE;
224
            set_times( &team_buf );
225
            test_times( &team_buf, 0 );
226
            put_team_record( team, &team_buf );
227
        }
228
        team++;
229
    }
230
}
231
 
232
/*========================================================================
233
 *
234
 *  Set the start time for a specific leg
235
 *
236
 *  Purpose:
237
 *      This function is called to set the start time for a specific
238
 *      leg to a specified and fixed time
239
 *
240
 *  Parameters:
241
 *      None
242
 *
243
 *  Returns:
244
 *      Nothing
245
 *
246
 *========================================================================*/
247
 
135 david 248
void tm_fixedstart(int leg, time_t starttime, bool report_it, bool clear_it)
95 - 249
{
174 - 250
    team_type   team_buf;
251
    int team = config.min_team;                      /* Team we are working with */
95 - 252
    while( team <= config.max_team )
253
    {
254
        if( valid_field( team ) )
255
        {
256
            g_record( team, &team_buf );
257
            if( team_buf.flags.valid )
258
            {
259
                team_buf.leg[leg].start = starttime;
260
                team_buf.leg[leg].manual = TRUE;
261
            }
262
            else
263
                team_buf.leg[leg].start = ( time_t ) - 1;
264
 
265
            set_times( &team_buf );
266
            test_times( &team_buf, 0 );
267
            put_team_record( team, &team_buf );
268
        }
269
        team++;
270
    }
271
 
272
    if( report_it )
137 david 273
        legs_start_report(leg);
95 - 274
 
275
    if ( clear_it )
137 david 276
        tm_clearleg_specified( leg, TRUE );
95 - 277
}
278
 
279
/*========================================================================
280
 *
281
 *  Set a staggered start time for a specific leg
282
 *
283
 *  Purpose:
284
 *      This function is called to set the start time for a specific
285
 *      leg to a specified and a staggered time
286
 *
287
 *  Parameters:
288
 *      None
289
 *
290
 *  Returns:
291
 *      Nothing
292
 *
293
 *========================================================================*/
294
 
135 david 295
void tm_staggered(int leg, time_t starttime, time_t delta, bool report_it, bool clear_it )
95 - 296
{
174 - 297
    team_type   team_buf;
298
    int team = config.min_team;                      /* Team we are working with */
95 - 299
    while( team <= config.max_team )
300
    {
301
        if( valid_field( team ) )
302
        {
303
            g_record( team, &team_buf );
304
            if( team_buf.flags.valid )
305
            {
306
                team_buf.leg[leg].start = starttime;
307
                starttime += delta;
308
                team_buf.leg[leg].manual = TRUE;
309
            }
310
            else
311
                team_buf.leg[leg].start = ( time_t ) - 1;
312
 
313
            set_times( &team_buf );
314
            test_times( &team_buf, 0 );
315
            put_team_record( team, &team_buf );
316
        }
317
        team++;
318
    }
319
 
320
    if( report_it )
137 david 321
        legs_start_report(leg);
95 - 322
 
323
    if ( clear_it )
137 david 324
        tm_clearleg_specified( leg, TRUE );
95 - 325
}
326
 
327
/*========================================================================
328
 *
329
 *  Clear start times on a specific leg
330
 *
331
 *  Purpose:
332
 *      This function is called to clear start times on a specifc leg
333
 *
334
 *  Parameters:
335
 *      cleg                - Leg to clear
336
 *      manual              - Force manual, else leave alone
337
 *
338
 *  Returns:
339
 *      Nothing
340
 *
341
 *========================================================================*/
342
 
174 - 343
void tm_clearleg_specified(int leg, bool manual)
95 - 344
{
174 - 345
    team_type   team_buf;
95 - 346
 
347
    /*
348
    **  Validate the users argument
349
    */
174 - 350
    if( leg == 0 )
95 - 351
        return;                              /* Null leg - just exit */
174 - 352
    if( leg > config.num_legs )             /* Valid leg number - Exit loop */
95 - 353
        return;
354
 
174 - 355
    int team = config.min_team;                 /* Team we are working with */
95 - 356
    while( team <= config.max_team )
357
    {
358
        if( valid_field( team ) )
359
        {
360
            g_record( team, &team_buf );
361
            team_buf.leg[leg].manual = manual;
362
            team_buf.leg[leg].start = ( time_t ) -1;
363
 
364
            set_times( &team_buf );
365
            test_times( &team_buf, 0 );
366
            put_team_record( team, &team_buf );
367
        }
368
        team++;
369
    }
370
}
371
 
372
 
373
/*========================================================================
374
 *
375
 *  Initialize all stored times
376
 *
377
 *  Purpose:
378
 *      This function is called to Initialize all stored times
379
 *
380
 *  Parameters:
381
 *      None
382
 *
383
 *  Returns:
384
 *      Nothing
385
 *
386
 *========================================================================*/
387
 
388
void leg_ini(void)
389
{
390
    int         i;
174 - 391
    team_type   team_buf;
95 - 392
 
393
 
174 - 394
    int team = config.min_team;                      /* Team we are working with */
95 - 395
    while( team <= config.max_team )
396
    {
397
        if( valid_field( team ) )
398
        {
399
            ( void ) g_record( team, &team_buf );
400
            for( i = 0; i <= MAX_LEGS; i++ )
401
            {
402
                team_buf.leg[i].start = team_buf.leg[i].end =
403
                    team_buf.leg[i].elapsed = ( time_t ) - 1;
404
                team_buf.leg[i].l_place = 0;
405
                team_buf.leg[i].le_place = 0;
406
                team_buf.leg[i].lec_place = 0;
407
                team_buf.leg[i].lc_place = 0;
408
                team_buf.leg[i].manual = FALSE;
409
            }
410
            if( team_buf.teamclass > 0 && team_buf.teamclass <= config.num_class )
411
                team_buf.leg[0].start =
412
                    config.team_class[team_buf.teamclass - 1].start;
413
            else
414
                team_buf.leg[0].start = ( time_t ) - 1;
415
 
416
            team_buf.leg[1].start = team_buf.leg[0].start;
417
            team_buf.flags.disqualified = FALSE;
418
            team_buf.flags.non_equestrian = FALSE;
419
            put_team_record( team, &team_buf );
420
        }
421
        team++;
422
    }
423
}
424
 
425
/*========================================================================
426
 *
427
 *  Initialize all team data
428
 *
429
 *  Purpose:
430
 *      This function is called to Initialize all team data
431
 *
432
 *  Parameters:
433
 *      None
434
 *
435
 *  Returns:
436
 *      Nothing
437
 *
438
 *========================================================================*/
439
void tm_init(void)
440
{
174 - 441
    team_type   team_buf;
442
    int team = config.min_team;                      /* Team we are working with */
95 - 443
    while( team <= config.max_team )
444
    {
445
        if( valid_field( team ) )
446
        {
447
            clr_team( team, &team_buf );
448
            put_team_record( team, &team_buf );
449
        }
450
        team++;
451
    }
452
}
453
 
454
/*========================================================================
455
 *
456
 *  Generate dummy team names
457
 *
458
 *  Purpose:
459
 *      This function is called to Generate dummy team names
460
 *
461
 *  Parameters:
462
 *      None
463
 *
464
 *  Returns:
465
 *      Nothing
466
 *
467
 *========================================================================*/
468
 
469
void tm_gen(void)
470
{
174 - 471
    team_type   team_buf;
472
    int team = config.min_team;                      /* Team we are working with */
95 - 473
    while( team <= config.max_team )
474
    {
475
        if( valid_field( team ) )
476
        {
477
            ( void ) g_record( team, &team_buf );
478
            team_buf.flags.valid = TRUE;
479
            sprintf( team_buf.name, "Team - %4.4d", team );
480
            team_buf.teamclass = 1;                  /* Set default class */
481
            put_team_record( team, &team_buf );
482
        }
483
        team++;
484
    }
485
}
486
 
244 - 487
void tm_recalcElapsed (int leg)
488
{
489
    team_type   team_buf;
490
    int team = config.min_team;                      /* Team we are working with */
491
    while( team <= config.max_team )
492
    {
493
        if( valid_field( team ) )
494
        {
495
            g_record( team, &team_buf );
496
            set_times( &team_buf );
497
            test_times( &team_buf, leg );
498
            put_team_record( team, &team_buf );
499
        }
500
        team++;
501
    }
502
}
95 - 503
 
504
/*========================================================================
505
 *
506
 *  Generate starters report
507
 *
508
 *  Purpose:
509
 *      This routine is used to generate a list of leg start times
261 - 510
 *      This system can cope with a break at the start of each leg
95 - 511
 *
512
 *  Parameters:
513
 *      None
514
 *
515
 *  Returns:
516
 *      Nothing
517
 *
518
 *========================================================================*/
519
 
137 david 520
void legs_start_report(int leg)
95 - 521
{
522
    int         i;
523
    t_legs     *data;                            /* Address of table */
524
    t_legs     *dptr;                            /* Moving pointer */
525
    int         last_team;
526
    int         num_records = 0;                 /* Number of records in array */
527
    char        l_s[40];                         /* Name of start time file */
174 - 528
    team_type   team_buf;
95 - 529
 
530
    data = ( t_legs * ) calloc( ( unsigned ) ( config.max_team - config.min_team + 2 ), sizeof( t_legs ) ); /* Fetch memory */
531
 
532
    if( !data )
533
    {
199 david 534
        MainWindow::showMessage("No memory for report");
95 - 535
        return;
536
    }
537
 
538
    /*
539
     * Extract the required data from the data base
540
     * Only save that information required for the operation
541
     */
542
 
543
    dptr = data;
544
    for( i = config.min_team; i <= config.max_team; i++ )   /* Print team order data */
545
    {
546
        if( valid_field( i ) && g_record( i, &team_buf ) )
547
        {
548
            dptr->numb = team_buf.numb;
549
            dptr->start = team_buf.leg[leg].start;
550
            dptr->flags = team_buf.flags;
551
            dptr++;
552
            num_records++;
553
        }
554
    }
555
 
556
 
557
    /*
558
     * Sort the data into some logical order 
559
     */
560
    qsort( ( char * ) data, num_records, sizeof( t_legs ), sort_legs );
561
 
562
    /*
563
    **  Now print the data on the printer
564
    **      - Generte the name of the printer file
565
    **      - Open the printer
566
    */
261 - 567
    {
568
        sprintf( l_s, "l_%d", leg );
569
        if( !open_printer( "", l_s, 80, text, "Starters Report" ) )
570
            return;
95 - 571
 
261 - 572
        /*
573
         * Print out the header for the file 
574
         */
575
        print( "\nStarters report for leg:%d %-*s\n", leg, 18, config.leg_name[leg - 1] );
576
        print( "Time order listing\n\n" );
95 - 577
 
261 - 578
        print_underline (TRUE);
579
        print( "%-8s   %-5s   %-8s   |   %-5s   %-8s", "Time", "Team", "DeltaT", "Team", "Time" );
580
        print_underline (FALSE);
581
        print( "\n" );
582
 
583
        last_team = 0;
584
        for( dptr = data, i = 0; i < num_records; i++ )
585
        {
586
            ls_timer( dptr++, i, FALSE );
587
            print( "   |   " );
588
            ls_team( &last_team, data );
589
            print( "\n" );
590
        }
591
 
592
        print( "\nTeams without marked times will be started when ALL marked teams\n" );
593
        print( "have been started.\n" );
594
        close_printer();
595
 
596
        /*
597
         ** Tell the main system about this new report
598
         */
599
        MainWindow::registerReport(getPrinterFile(), "Leg Start");
600
    }
601
 
95 - 602
    /*
261 - 603
    **  Alternate report format
604
    */
605
    {
606
        int c1, c2, c3,c4, c1stop;
607
        sprintf( l_s, "l2_%d", leg );
608
        if( !open_printer( "", l_s, 80, text, "Starters Report (2)" ) )
609
            return;
610
 
611
        /*
612
         * Print out the header for the file 
613
         */
614
        print( "\nStarters report for leg:%d %-*s\n", leg, 18, config.leg_name[leg - 1] );
285 david 615
        print( "Starting order listing\n\n" );
261 - 616
 
617
        print_underline (TRUE);
618
        print( "%-8s   %-5s |   ", "Time", "Team");
619
        print( "%-8s   %-5s |   ", "Time", "Team");
620
        print( "%-8s   %-5s |   ", "Time", "Team");
621
        print( "%-8s   %-5s"  ,  "Time", "Team");
622
        print_underline (FALSE);
623
        print( "\n" );
624
 
625
        /*
626
        **  Print in Two columns
627
        **  Need to figure out where the 2nd column starts
628
        */
629
        c1 = 0;
630
        c2 = c1stop = (num_records + 3)/4;
631
        c3 = c2 * 2;
632
        c4 = c2 * 3;
633
 
634
        for( ; c1 < c1stop; c1++, c2++, c3++, c4++ )
635
        {
636
            ls_timer_short( &data[c1], c1, c1 > c1stop );
637
            print( " |   " );
638
            ls_timer_short( &data[c2], c2, c1 > c1stop);
639
            print( " |   " );
640
            ls_timer_short( &data[c3], c3, c1 > c1stop);
641
            print( " |   " );
642
            ls_timer_short( &data[c4], c4, c4 >= num_records);
643
            print( "\n" );
644
        }
645
 
646
        print( "\nTeams without marked times will be started when ALL marked teams\n" );
647
        print( "have been started.\n" );
648
        close_printer();
649
 
650
        /*
651
         ** Tell the main system about this new report
652
         */
653
        MainWindow::registerReport(getPrinterFile(), "Leg Start(2)");
654
    }
655
 
656
    /*
657
    **  Alternate report format - by Team Number
658
    */
659
#if 1
660
    /*
661
     * Sort the data into some logical order 
95 - 662
     */
261 - 663
    qsort( ( char * ) data, num_records, sizeof( t_legs ), sort_team );
95 - 664
 
261 - 665
    {
666
        int c1, c2, c3,c4, c1stop;
667
        sprintf( l_s, "l3_%d", leg );
668
        if( !open_printer( "", l_s, 80, text, "Starters Report (3)" ) )
669
            return;
95 - 670
 
261 - 671
        /*
672
         * Print out the header for the file 
673
         */
674
        print( "\nStarters report for leg:%d %-*s\n", leg, 18, config.leg_name[leg - 1] );
675
        print( "Team order listing\n\n" );
676
 
677
        print_underline (TRUE);
678
        print( "%-5s   %-8s |   ", "Team", "Time");
679
        print( "%-5s   %-8s |   ", "Team", "Time");
680
        print( "%-5s   %-8s |   ", "Team", "Time");
681
        print( "%-5s   %-8s"   , "Team", "Time");
682
        print_underline (FALSE);
95 - 683
        print( "\n" );
261 - 684
 
685
        /*
686
        **  Print in Two columns
687
        **  Need to figure out where the 2nd column starts
688
        */
689
        c1 = 0;
690
        c2 = c1stop = (num_records + 3)/4;
691
        c3 = c2 * 2;
692
        c4 = c2 * 3;
693
 
694
        for( ; c1 < c1stop; c1++, c2++, c3++, c4++ )
695
        {
696
            ls_team_short( &data[c1], c1, c1 > c1stop );
697
            print( " |   " );
698
            ls_team_short( &data[c2], c2, c1 > c1stop);
699
            print( " |   " );
700
            ls_team_short( &data[c3], c3, c1 > c1stop);
701
            print( " |   " );
702
            ls_team_short( &data[c4], c4, c4 >= num_records);
703
            print( "\n" );
704
        }
705
 
706
        print( "\nTeams without marked times will be started when ALL marked teams\n" );
707
        print( "have been started.\n" );
708
        close_printer();
709
 
710
        /*
711
         ** Tell the main system about this new report
712
         */
713
        MainWindow::registerReport(getPrinterFile(), "Leg Start(3)");
95 - 714
    }
261 - 715
#endif
716
 
95 - 717
 
718
    /*
719
    **  Release the resources
261 - 720
    **  Release the data
95 - 721
    */
722
    free( data );
207 - 723
 
95 - 724
}
725
 
726
/*========================================================================
727
 *
728
 *  print the current leg entry
729
 *
730
 *  Purpose:
731
 *      This function is a helper routine to print the current leg entry
732
 *      in time : Team number order
733
 *
734
 *  Parameters:
261 - 735
 *      ptr         Pointer to entry
736
 *      num         Entry index
737
 *      supress     True: Entry is empty
95 - 738
 *
739
 *  Returns:
740
 *      Nothing
741
 *
742
 *========================================================================*/
743
 
261 - 744
void ls_timer( t_legs * ptr, int num, bool suppress )
95 - 745
{
746
    time_t      time;
747
    time_t      delta;
230 - 748
    bool        flags;
95 - 749
 
261 - 750
    if ( suppress )
751
    {
752
        print( "%-8s   %-5s", "","");
753
        print( "   %-8s", "");
754
        return;
755
    }
756
 
95 - 757
    if( num == 0 )
758
        delta = ( time_t ) - 1;
759
    else
760
        delta = ptr[0].start - ptr[-1].start;
761
 
762
    time = ptr->start;
379 david 763
    flags =  ptr->flags.disqualified;
230 - 764
    if(flags)
95 - 765
        time = ( time_t ) - 1;
766
 
230 - 767
    print( "%-8s   %-5d", time_fa( time, flags ), ptr->numb );
95 - 768
    print( "   %-8s", time_fa( delta, TRUE ) );
769
}
770
 
261 - 771
/*========================================================================
772
 *
773
 *  print the current leg entry  - short form
774
 *
775
 *  Purpose:
776
 *      This function is a helper routine to print the current leg entry
777
 *      in time : Team number order
778
 *
779
 *  Parameters:
780
 *      ptr         Pointer to entry
781
 *      num         Entry index
782
 *      supress     True: Entry is empty
783
 *
784
 *  Returns:
785
 *      Nothing
786
 *
787
 *========================================================================*/
95 - 788
 
261 - 789
void ls_timer_short( t_legs * ptr, int num, bool suppress )
790
{
791
    time_t      time;
792
    bool        flags;
793
 
794
    if ( suppress )
795
    {
796
        print( "%-8s   %-5s", "","");
797
        return;
798
    }
799
 
800
    time = ptr->start;
379 david 801
    flags =  ptr->flags.disqualified;
261 - 802
    if(flags)
803
        time = ( time_t ) - 1;
804
 
805
    print( "%-8s   %-5d", time_fa( time, flags ), ptr->numb );
806
}
807
 
808
 
95 - 809
/*========================================================================
810
 *
811
 *  print next ( numeric ) leg entry
812
 *
813
 *  Purpose:
814
 *      This helper function is called to print next ( numeric ) leg entry
815
 *      in Team # time order
816
 *
817
 *  Parameters:
818
 *      last        Last one found
819
 *                  Used to relocate my self
820
 *      data        Start of data
821
 *
822
 *  Returns:
823
 *      Nothing
824
 *
825
 *========================================================================*/
826
 
827
void ls_team( int *last, t_legs * data )
828
{
829
    t_legs     *min;
830
    time_t      time;
230 - 831
    bool        flags;
95 - 832
 
833
    for( min = 0; data->numb; data++ )
834
    {
835
        if( data->numb > *last && ( min == 0 || data->numb < min->numb ) )
836
            min = data;
837
    }
838
    *last = min->numb;                           /* Save current team as done */
839
 
840
    time = min->start;
379 david 841
    flags =  min->flags.disqualified;
230 - 842
    if( flags )
95 - 843
        time = ( time_t ) - 1;
230 - 844
    print( "%-5d   %-8s", min->numb, time_fa( time, flags ) );
95 - 845
}
846
 
847
/*========================================================================
848
 *
261 - 849
 *  print next ( numeric ) leg entry - Short Form
850
 *
851
 *  Purpose:
852
 *      This helper function is called to print next ( numeric ) leg entry
853
 *      in Team # time order
854
 *
855
 *  Parameters:
856
 *      last        Last one found
857
 *                  Used to relocate my self
858
 *      data        Start of data
859
 *
860
 *  Returns:
861
 *      Nothing
862
 *
863
 *========================================================================*/
864
 
865
void ls_team_short( t_legs * ptr, int num, bool suppress )
866
{
867
    time_t      time;
868
    bool        flags;
869
 
870
    if ( suppress )
871
    {
872
        print( "%-5s   %-8s", "","");
873
        return;
874
    }
875
 
876
    time = ptr->start;
379 david 877
    flags =  ptr->flags.disqualified;
261 - 878
    if(flags)
879
        time = ( time_t ) - 1;
880
 
881
    print( "%-5d   %-8s", ptr->numb, time_fa( time, flags ) );
882
}
883
 
884
 
885
/*========================================================================
886
 *
95 - 887
 *  Qsort callback function
888
 *
889
 *  Purpose:
890
 *      This function is provided to Qsort() to sort the teams
891
 *
892
 *  Parameters:
893
 *      a           - Leg entry to compare
894
 *      b           - Leg entry to compare
895
 *
896
 *
897
 *  Returns:
898
 *      -1      a < b
899
 *       0      a = b
900
 *       1      a > b
901
 *
902
 *========================================================================*/
903
 
904
int sort_legs( const void * aa, const void * bb )
905
{
906
 
907
    const t_legs * a = (const t_legs *)aa;
908
    const t_legs * b = (const t_legs *)bb;
909
 
910
    int         a_bad;
911
    int         b_bad;
912
 
379 david 913
    a_bad = a->flags.disqualified || a->start <= 0;
914
    b_bad = b->flags.disqualified || b->start <= 0;
95 - 915
 
916
    if( a_bad || b_bad )                         /* Valid data has precedence */
917
    {
918
        if( a_bad && b_bad )
919
            return ( a->numb - b->numb );
920
        else
921
            return ( a_bad ? 1 : -1 );
922
    }
923
 
924
    if( a->start == b->start )
925
        return ( a->numb - b->numb );
926
    else
927
    {
928
        if( ( a->start > 0 ) && ( b->start > 0 ) )
929
            return ( ( int ) ( a->start - b->start ) );
930
        else
931
            return ( ( a->start > 0 ) ? -1 : 1 );
932
    }
933
}
934
 
261 - 935
/*========================================================================
936
 *
937
 *  Qsort callback function
938
 *
939
 *  Purpose:
940
 *      This function is provided to Qsort() to sort the teams
941
 *
942
 *  Parameters:
943
 *      a           - Leg entry to compare
944
 *      b           - Leg entry to compare
945
 *
946
 *
947
 *  Returns:
948
 *      -1      a < b
949
 *       0      a = b
950
 *       1      a > b
951
 *
952
 *========================================================================*/
953
 
954
int sort_team( const void * aa, const void * bb )
955
{
956
 
957
    const t_legs * a = (const t_legs *)aa;
958
    const t_legs * b = (const t_legs *)bb;
959
 
960
    return ( a->numb - b->numb );
961
}
962
 
963
 
95 - 964
/********************************* EOF ***********************************/