Subversion Repositories svn1-original

Rev

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

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