Subversion Repositories svn1-original

Rev

Details | 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\teamupd.c
6
*
7
* purpose:  Team data edit and display
8
*           This module contains all the functions required to define and
9
*           alter the team definitions
10
*
11
* functions
12
*       team_update             - Update team data on the screen
13
*       team_display            - Display team data on the screen
14
*       leg_mods                - Modify team leg times
15
*       d_display               - Display all team information
16
*       d_leg                   - Display / Update leg time information
17
*       d_field                 - Display / Update field on the screen
18
*       g_tnum                  - Get a team number from the operator
19
*       g_record                - Read a team record from disk
20
*       clr_team                - Clear team data from file
21
*       put_team_record         - Save team record to disk
22
*       init_team_data          - Initialize the team data file
23
*       fix_team_data           - Close team data file
24
*
25
* programmer: David Purdie
26
*
27
* revision  date        by      reason
28
*   00.0    27/01/95    DDP     Tidies up the program and formatted the file
29
*
30
**************************************************************************/
31
 
32
#ifndef HI_TECH_C
33
#include    <fcntl.h>
34
/*#include  <memory.h> */
35
#endif
36
 
37
#include    "consts.h"
38
#include    "structs.h"
39
#include    "proto.h"
40
int         team;                                /* Current team number */
41
team_type   team_buf;                            /* Holds team data currently under display */
42
int         team_fd;                             /* Team data file descriptor */
43
int         leg = 0;                             /* Leg under investigation */
44
 
45
/*========================================================================
46
 *
47
 *  Update team data on the screen
48
 *
49
 *  Purpose:
50
 *      This function is called to update team data on the screen
51
 *      This function will prompt the operator to select a team number
52
 *      If the team is defined then the data will be displayed on the screen
53
 *
54
 *  Parameters:
55
 *      None
56
 *
57
 *  Returns:
58
 *      TRUE - Change made
59
 *
60
 *========================================================================*/
61
 
162 david 62
//void team_update(void)
63
//{
64
//    if( !g_tnum( 0, n_lines - 2, "Enter team number" ) )
65
//        return;                        /* Exit operation */
95 - 66
 
162 david 67
//    /*
68
//     **  Fetch the team record into memory
69
//     **  If the record does not exist a record with an invalid flag
70
//     **  will be returned
71
//     */
95 - 72
 
162 david 73
//    do
74
//    {
75
//        clearscreen();
76
//        g_record( team, &team_buf );
77
//        d_display( M_TEAM );
78
//        put_team_record( team, &team_buf );
95 - 79
 
162 david 80
//    } while( g_tnum( 0, n_lines - 2, "Enter next team or RETURN to exit" ) );
81
//}
95 - 82
 
83
/*=======================================================================
84
 *
85
 *  Display team data on the screen
86
 *
87
 *  Purpose:
88
 *      This function is called to Display team data on the screen
89
 *      This function will prompt the operator to select a team number
90
 *      If the team is defined then the data will be displayed on the screen
91
 *
92
 *  Parameters:
93
 *      None
94
 *
95
 *  Returns:
96
 *      TRUE - Change made
97
 *
98
 *========================================================================*/
99
 
162 david 100
//void team_display(void)
101
//{
102
//    if( !g_tnum( 0, n_lines - 2, "Enter team number" ) )
103
//        return;                        /* Exit operation */
95 - 104
 
162 david 105
//    /*
106
//     * Fetch the team record into memory
107
//     * If the record does not exist a record with an invalid flag
108
//     * will be returned
109
//     */
95 - 110
 
162 david 111
//    do
112
//    {
113
//        clearscreen();
114
//        if( g_record( team, &team_buf ) )
115
//            d_display( M_DISPLAY );
116
//        else
117
//        {
118
//            cur( 0, n_lines - 1 );
119
//            printf( "Team %-1d has not yet been entered", team );
120
//            beep();
121
//        }
122
//    } while( g_tnum( 0, n_lines - 2, "Enter next team or RETURN to exit" ) );
123
//}
95 - 124
 
125
/*========================================================================
126
 *
127
 *  Modify team leg times
128
 *
129
 *  Purpose:
130
 *      This function is called to modify team leg times
131
 *      This function will prompt the operator to select a team number
132
 *      If the team is defined then the data will be displayed on the screen
133
 *
134
 *  Parameters:
135
 *      None
136
 *
137
 *  Returns:
138
 *      TRUE - Change made
139
 *
140
 *========================================================================*/
162 david 141
//void leg_mods(void)
142
//{
143
//    if( !g_tnum( 0, n_lines - 2, "Enter team number" ) )
144
//        return;                        /* Exit operation */
95 - 145
 
162 david 146
//    /*
147
//     **  Fetch the team record into memory
148
//     ** If the record does not exist a record with an invalid flag
149
//     ** will be returned
150
//     */
95 - 151
 
162 david 152
//    do
153
//    {
154
//        clearscreen();
155
//        if( g_record( team, &team_buf ) )
156
//        {
157
//            set_times( &team_buf );
158
//            d_display( M_LEGS );
159
//            put_team_record( team, &team_buf );
160
//        }
161
//        else
162
//        {
163
//            cur( 0, n_lines - 1 );
164
//            printf( "Team %-1d has not yet been entered", team );
165
//            beep();
166
//        }
167
//    } while( g_tnum( 0, n_lines - 2, "Enter next team or RETURN to exit" ) );
95 - 168
 
162 david 169
//}
95 - 170
 
171
/*========================================================================
172
 *
173
 *  Display all team information
174
 *
175
 *  Purpose:
176
 *      This function is called to display all the team information
177
 *
178
 *  Parameters:
179
 *      operation       Operation to perform
180
 *
181
 *  Returns:
182
 *      Nothing
183
 *
184
 *========================================================================*/
162 david 185
//void d_display( int operation )
186
//{
187
//    int         valid = team_buf.flags.valid;
188
//    int         opr;
189
//    int         i, j;
190
//    int         age_sum;
95 - 191
 
162 david 192
//    /*
193
//     **  Refresh the entire display (using a recursive call)
194
//     */
195
//    if( operation != M_DISPLAY )
196
//        d_display( M_DISPLAY );
95 - 197
 
198
 
162 david 199
//    /*
200
//     **  Display the team number
201
//     **      This cannot be edited.
202
//     */
203
//    d_field( 0, 0, "Team number : ", D_NUMBER, 6, &team_buf.numb, TRUE,
204
//             M_DISPLAY );
95 - 205
 
162 david 206
//    /*
207
//     **  Determine the type of operation required
208
//     **      Update or Display
209
//     */
210
//    opr = ( operation & M_TEAM ) ? M_UPDATE : M_DISPLAY;
95 - 211
 
162 david 212
//    /*
213
//     **  Display / Update the team name
214
//     */
215
//    do
216
//    {
217
//        d_field( 20, 0, "Team name : ", D_STRING, MAX_TM_NAME, team_buf.name,
218
//                 valid, opr );
219
//        if( abort_flag )
220
//            return;
221
//    } while( ( opr == M_UPDATE ) && ( !strlen( team_buf.name ) ) );
95 - 222
 
162 david 223
//    /*
224
//     **  Display / Update the class
225
//     */
226
//    do
227
//    {
228
//        d_field( 0, 1, "Class : ", D_CLASS, 1, &team_buf.teamclass, valid, opr );
229
//        if( abort_flag )
230
//            return;
231
//    } while( ( opr == M_UPDATE ) && !team_buf.teamclass );
95 - 232
 
162 david 233
//    /*
234
//     **  The record is now active
235
//     **  It may not be usefull, but it has the start of a valid recird
236
//     */
237
//    if( opr == M_UPDATE )
238
//        team_buf.flags.valid = TRUE;
95 - 239
 
162 david 240
//    /*
241
//     **  Display / Update the country name
242
//     */
243
//    d_field( 30, 1, "Country :", D_COUNTRY, 4, &team_buf.country, valid,
244
//             opr );
245
//    if( abort_flag )
246
//        return;
95 - 247
 
162 david 248
//    /*
249
//     **  Display / Update the name and sex of each team member
250
//     */
251
//    age_sum = 0;
252
//    opr = ( operation & M_TEAM ) ? M_UPDATE : M_DISPLAY;
253
//    for( i = 0; i < MAX_MEMB; i++ )
254
//    {
255
//        d_field( 0, 3 + i, "Name : ", D_STRING, MAX_PERSON_NAME,
256
//                 team_buf.members[i].name, valid, opr );
257
//        if( abort_flag )
258
//            return;
95 - 259
 
162 david 260
//        d_field( MAX_PERSON_NAME + 10, 3 + i, "Sex : ", D_SEX, 0,
261
//                 &team_buf.members[i].sex, valid, opr );
262
//        if( abort_flag )
263
//            return;
95 - 264
 
162 david 265
//        d_field( MAX_PERSON_NAME + 25, 3 + i, "Age : ", D_AGE, 3,
266
//                 &team_buf.members[i].age, valid, opr );
267
//        if( abort_flag )
268
//            return;
95 - 269
 
162 david 270
//        /*
271
//        **  Sum ages
272
//        **  -1 indicates invalid age
273
//        */
274
//        if ( age_sum >= 0 )
275
//        {
276
//            ushort age = team_buf.members[i].age;
277
//            if ( age > 0 && age < 255 )
278
//            {
279
//                age_sum += age;
280
//            }
281
//            else
282
//            {
283
//                age_sum = -1;
284
//            }
285
//        }
95 - 286
 
162 david 287
//    }
95 - 288
 
162 david 289
//    /*
290
//     **  Display / Update the leg informarion for each configured leg
291
//     */
292
//    for( j = 1; j <= config.num_legs; j++, i++ )
293
//    {
294
//        d_leg( 4 + i, j, &team_buf.leg[j], valid, operation );
295
//        if( abort_flag )
296
//        {
297
//            i += config.num_legs - j + 1;
298
//            break;
299
//        }
300
//    }
95 - 301
 
162 david 302
//    /*
303
//     **  Display the summary information
304
//     **      For the team
305
//     **      Event and class placing information
306
//     **      Total age
307
//     */
308
//    d_leg( 4 + i, 0, &team_buf.leg[0], valid, M_DISPLAY );
95 - 309
 
162 david 310
//    d_field( 0, 6 + i, "Event placing : ", D_NUMBER, 1,
311
//             &team_buf.leg[0].le_place, valid, M_DISPLAY );
312
//    d_field( 20, 6 + i, "Class placing : ", D_NUMBER, 1,
313
//             &team_buf.leg[0].lec_place, valid, M_DISPLAY );
314
//    d_field( 40, 6 + i, "Total Age : ", D_STRING, 5,
315
//             age_a(age_sum), valid, M_DISPLAY );
95 - 316
 
317
 
162 david 318
//    if( team_buf.flags.non_equestrian )
319
//        d_field( 0, 7 + i, "Non-Equestrian", D_NULL, 1, 0, valid, M_DISPLAY );
320
//    else if( team_buf.flags.disqualified )
321
//        d_field( 0, 7 + i, "Disqualified", D_NULL, 1, 0, valid, M_DISPLAY );
95 - 322
 
162 david 323
//}
95 - 324
 
325
/*========================================================================
326
 *
327
 *  Display / Update leg time information
328
 *
329
 *  Purpose:
330
 *      This function is called to display and update the leg
331
 *      time information.
332
 *
333
 *  Parameters:
334
 *      y           Screen position
335
 *      leg         Leg to process
336
 *      data        Leg data
337
 *      valid       Data valid flag
338
 *      operation   Operation to perform
339
 *
340
 *  Returns:
341
 *      Nothing
342
 *
343
 *========================================================================*/
162 david 344
//void d_leg( int y, int leg, leg_type * data, int valid, int operation )
345
//{
346
//    int         i;
347
//    int         oprs, oprf;
95 - 348
 
162 david 349
//    /*
350
//     **  Display the field header
351
//     */
352
//    if( operation == M_DISPLAY )
353
//    {
354
//        if( leg != 0 )
355
//        {
356
//            d_field( 0, y, "Leg ", D_NUMBER, 1, &leg, TRUE, M_DISPLAY );
357
//            d_field( 7, y, "", D_STRING, MAX_LEG_NAME,
358
//                     config.leg_name[leg - 1], TRUE, M_DISPLAY );
359
//        }
360
//        else
361
//            d_field( 0, y, "Overall team times", D_STRING, 0, "", TRUE, M_DISPLAY );
362
//    }
95 - 363
 
162 david 364
//    /*
365
//     **  If we are doing an update,. then ensure that all the team times
366
//     **  have been tested
367
//     */
95 - 368
 
162 david 369
//    if( operation & M_ALL )
370
//        test_times( &team_buf, 0 );              /* Set up all team times */
95 - 371
 
162 david 372
//    oprs = ( ( parallel_legs )
373
//             || ( operation & M_ALEGS )
374
//             || ( operation & M_LEGS ) ) ? M_UPDATE : M_DISPLAY;
95 - 375
 
162 david 376
//    oprf = ( operation & M_LEGS ) ? M_UPDATE : M_DISPLAY;
95 - 377
 
162 david 378
//    /*
379
//     **  if start time edited then flag as manual entry
380
//     **  redo calculations and refresh screen with new information
381
//     */
95 - 382
 
162 david 383
//    if( d_field
384
//        ( 25, y, data->manual ? "MS " : " S ", D_TIME, 8, &data->start, valid,
385
//          oprs ) )
386
//    {
387
//        data->manual = TRUE;
388
//        test_times( &team_buf, 0 );
389
//        for( i = leg; i <= config.num_legs; i++ )
390
//            d_leg( y + i - leg, i, &team_buf.leg[i], valid, M_DISPLAY );
391
//        d_leg( y + i - leg, 0, &team_buf.leg[0], valid, M_DISPLAY );
392
//    }
95 - 393
 
162 david 394
//    /*
395
//     **  If time changed then redo calcs and refresh screen
396
//     */
397
//    if( d_field( 37, y, "F ", D_TIME, 8, &data->end, valid, oprf ) )
398
//    {
399
//        set_times( &team_buf );
400
//        test_times( &team_buf, 0 );
401
//        for( i = leg; i <= config.num_legs; i++ )
402
//            d_leg( y + i - leg, i, &team_buf.leg[i], valid, M_DISPLAY );
403
//        d_leg( y + i - leg, 0, &team_buf.leg[0], valid, M_DISPLAY );
404
//    }
95 - 405
 
162 david 406
//    d_field( 48, y, "E ", D_TIME, 8, &data->elapsed, valid, M_DISPLAY );
407
//    if( leg == 0 )
408
//    {
409
//        d_field( 60, y, "", D_STRING, 10,
410
//                 ( team_buf.flags.bad_times ==
411
//                   TRUE ) ? "Incomplete" : "          ", valid, M_DISPLAY );
412
//    }
413
//    else
414
//    {
415
//        d_field( 60, y, "", D_NUMBER, 4, &data->le_place, valid, M_DISPLAY );
416
//        d_field( 65, y, "", D_NUMBER, 4, &data->l_place, valid, M_DISPLAY );
417
//        d_field( 70, y, "", D_NUMBER, 4, &data->lec_place, valid, M_DISPLAY );
418
//        d_field( 75, y, "", D_NUMBER, 4, &data->lc_place, valid, M_DISPLAY );
419
//    }
420
//}
95 - 421
 
422
/*========================================================================
423
 *
424
 *  Display / Update simple time information
425
 *
426
 *  Purpose:
427
 *      This function is called to display and update the leg
428
 *      time information.
429
 *
430
 *  Parameters:
431
 *      x, y        Screen position
432
 *      prompt      Prompt to display
433
 *      data        Address of time data
434
 *      valid       Data valid flag
435
 *
436
 *  Returns:
437
 *      Nothing
438
 *
439
 *========================================================================*/
162 david 440
//void d_time( int x, int y, const char *prompt, time_t *data, int valid )
441
//{
442
//        d_field( x, y, prompt, D_TIME, 8, ( char * ) data, valid, M_DISPLAY );
443
//        d_field( x, y, prompt, D_TIME, 8, ( char * ) data, valid, M_UPDATE );
444
//}
95 - 445
 
446
/*========================================================================
447
 *
448
 *  Display / Update field on the screen
449
 *
450
 *  Purpose:
451
 *      
452
 *      This function is called to display and update a field on the screen
453
 *      This routine will display a record from the team structure
454
 *      The type of data and other parameters is passed in
455
 *      This function is fundimental to the entire display subsystem
456
 *
457
 *
458
 *
459
 *  Parameters:
460
 *      x           The screen col
461
 *      y           The line number
462
 *      prompt      The field lable
463
 *      type        type of field
464
 *      length      Length of the numeric field
465
 *      data        Pointer to the data
466
 *      valid       data field is valid
467
 *      operation   Operation type
468
 *
469
 *  Returns:
470
 *      TRUE - Change has been made
471
 *
472
 *========================================================================*/
162 david 473
//bool d_field( int x,
474
//              int y,
475
//              const char *prompt,
476
//              int type, int length, const void *data, int valid, int operation )
477
//{
478
//    time_t      t;
479
//    int         i;
480
//    sex_type    s;
481
//    int         change = 0;
482
//    int         idata;
95 - 483
 
162 david 484
//    /*
485
//     **  Position the cursor and display the field title
486
//     */
487
//    cur( x, y );
488
//    printf( "%s", prompt );
95 - 489
 
162 david 490
//    /*
491
//     **  If the ABORT flag is set then DISPLAY the field
492
//     */
493
//    if( abort_flag )
494
//        operation = M_DISPLAY;
95 - 495
 
162 david 496
//    /*
497
//     **  Display the current field value
498
//     **      Only if the data field is valid
499
//     **      Only if the M_DISPLAY operation is requested
500
//     */
501
//    if( valid && ( operation == M_DISPLAY ) )
502
//    {
503
//        switch ( type )
504
//        {
505
//        case D_STRING:
506
//        case D_USTRING:
507
//            printf( "%-*.*s", length, length, (char *)data );
508
//            break;
95 - 509
 
162 david 510
//        case D_NUMBER:
511
//            printf( "%-*d", length, *( short * ) data );
512
//            break;
95 - 513
 
162 david 514
//        case D_SEX:
515
//            if( *( sex_type * ) data != unknown )
516
//                printf( "%s",
517
//                        ( *( sex_type * ) data ==
518
//                          male ) ? "Male" : "Female" );
519
//            break;
95 - 520
 
162 david 521
//        case D_TIME:
522
//            printf( "%s", time_a( *( time_t * ) data ) );
523
//            break;
95 - 524
 
162 david 525
//        case D_CLASS:
526
//            if( *( short * ) data > 0 )
527
//            {
528
//                printf( "%2.2s", config.team_class[( *( int * ) data ) - 1].abr );
529
//                printf( "  %-*.*s", LEN_CLASS_NAME, LEN_CLASS_NAME,
530
//                        config.team_class[( *( int * ) data ) - 1].full_name );
531
//            }
532
//            break;
95 - 533
 
162 david 534
//        case D_COUNTRY:
535
//            if( *( short * ) data > 0 )
536
//            {
537
//                printf( "%4.4s",
538
//                        config.country_name[( *( int * ) data ) - 1].abr );
539
//                printf( "  %-*.*s", LEN_CNTRY_NAME, LEN_CNTRY_NAME,
540
//                        config.country_name[( *( int * ) data ) -
541
//                                            1].full_name );
542
//            }
543
//            break;
95 - 544
 
162 david 545
//        case D_AGE:
546
//            if( *( uchar * ) data > 0 )
547
//            {
548
//                printf( "%-*d", length, *( uchar * ) data );
549
//            }
550
//            break;
95 - 551
 
552
 
162 david 553
//        case D_NULL:
554
//            break;
95 - 555
 
162 david 556
//        default:
557
//            printf( "Unknown data type" );
558
//            break;
559
//        }
560
//    }
95 - 561
 
162 david 562
//    /*
563
//     **  If updating the field then extract the required information
564
//     */
565
//    if( operation == M_UPDATE )
566
//    {
567
//        switch ( type )
568
//        {
569
//        case D_STRING:
570
//            change = ( getstring( length, (char *)data, Alphanum ) );
571
//            break;
95 - 572
 
162 david 573
//        case D_USTRING:
574
//            change = ( getstring( length, (char *)data, AlphnumUpper ) );
575
//            break;
95 - 576
 
162 david 577
//        case D_NUMBER:
578
//            idata = *(short *)data;
579
//            change = getnum( length, &idata );
580
//            if ( change )
581
//                *( short *)data = idata;
582
//            break;
95 - 583
 
162 david 584
//        case D_SEX:
585
//            if( ( s = getsex() ) != unknown )
586
//            {
587
//                change = ( *( sex_type * ) data != s );
588
//                *( sex_type * ) data = s;
589
//            }
590
//            break;
95 - 591
 
162 david 592
//        case D_TIME:
593
//            if( ( t = get_time(*( time_t * ) data) ) >= 0 )
594
//            {
595
//                change = ( *( time_t * ) data != t );
596
//                *( time_t * ) data = t;
597
//            }
598
//            break;
95 - 599
 
162 david 600
//        case D_CLASS:
601
//            if( ( i = getclass() ) != 0 )
602
//            {
603
//                change = *( short * ) data != i;
604
//                *( short * ) data = i;
605
//            }
606
//            break;
95 - 607
 
162 david 608
//        case D_COUNTRY:
609
//            if( ( i = getcountry() ) != 0 )
610
//            {
611
//                change = *( short * ) data != i;
612
//                *( short * ) data = i;
613
//            }
614
//            break;
95 - 615
 
162 david 616
//        case D_AGE:
617
//            idata = *(uchar *)data;
618
//            change = getnum( length, &idata );
619
//            if ( change )
620
//                *( uchar *)data = idata;
621
//            break;
95 - 622
 
623
 
162 david 624
//        case D_NULL:
625
//            break;
95 - 626
 
162 david 627
//        default:
628
//            printf( "Unknown data type" );
629
//            break;
630
//        }
95 - 631
 
162 david 632
//        /*
633
//         **  Having accepted the input now DISPLAY the data (once again)
634
//         **      Done to allow aborted field to re-display original values
635
//         */
636
//        d_field( x, y, prompt, type, length, data, TRUE, M_DISPLAY );
637
//    }
638
//    return ( change );
639
//}
95 - 640
 
641
/*========================================================================
642
 *
643
 *  Get a team number from the operator
644
 *
645
 *  Purpose:
646
 *      This function is called to Get a team number from the operator
647
 *          Prompt the operator for a team number
648
 *          Verify that the team number is valid
649
 *          Allow escape characters in the process
650
 *
651
 *          This routine will return TRUE if the team number is valid
652
 *          The team number is returned in the global variable "team"
653
 *
654
 *  Parameters:
655
 *      x,y         Screen coords
656
 *      prompt      Operator prompt
657
 *
658
 *  Returns:
659
 *      TRUE    : Number OK
660
 *
661
 *========================================================================*/
162 david 662
//bool g_tnum( int x, int y, const char *prompt )
663
//{
664
//    int         new_team = 0;                   /* team number that will be input */
95 - 665
 
162 david 666
//    while( TRUE )
667
//    {
668
//        team = 0;
669
//        abort_flag = FALSE;
670
//        cur( x, y );
671
//        printf( "%s : ", prompt );
672
//        //console_clreol();
673
//        if( !getnum( 6, &new_team ) )
674
//            return ( FALSE );                    /* No input */
95 - 675
 
162 david 676
//        /*
677
//         * verify that the team number is within the allowed numbers
678
//         */
95 - 679
 
162 david 680
//        if( !valid_field( new_team ) )
681
//        {
682
//            beep();
683
//            printf( "\nTeam %-1d is not valid", new_team );
684
//            continue;
685
//        }
686
//        team = new_team;
687
//        return ( TRUE );
688
//    }
689
//}
95 - 690
 
691
/*========================================================================
692
 *
693
 *  Read a team record from disk
694
 *
695
 *  Purpose:
696
 *      This function is called to Read a team record from disk
697
 *      Locate the team record in the team data file
698
 *      if the record does not exist create a blank record
699
 *
700
 *      The function will return FALSE if the record was not on disk
701
 *      otherwise TRUE
702
 *
703
 *  Parameters:
704
 *      int_team        Team record required
705
 *      data            Area to return record
706
 *
707
 *  Returns:
708
 *      FALSE : No data available
709
 *
710
 *========================================================================*/
711
bool g_record( int _team, team_type * data )
712
{
713
    int         len;                             /* length of record read in */
714
    long        pos;                             /* File pointer */
715
 
716
    pos = _team;
717
    pos *= sizeof( team_type );
718
    len = lseek( team_fd, pos, 0 );
719
    len = read( team_fd, ( char * ) data, sizeof( team_type ) );
720
    if( ( len == sizeof( team_type ) ) && ( _team == data->numb ) )
721
        return ( data->flags.valid );
722
    else
723
    {
724
        clr_team( _team, data );
725
        return ( FALSE );
726
    }
727
}
728
 
729
/*========================================================================
730
 *
731
 *  Clear team data from file
732
 *
733
 *  Purpose:
734
 *      This function is called to Clear team data from file
735
 *      This routine will set the team data to INVALID
736
 *
737
 *  Parameters:
738
 *      tm          Team number
739
 *      data        Pointer to the data
740
 *
741
 *  Returns:
742
 *      Nothing
743
 *
744
 *========================================================================*/
745
void clr_team( int tm, team_type * data )
746
{
747
    int         len;
748
 
749
    memset( ( char * ) data, 0, ( int ) sizeof( team_type ) );
750
    data->flags.valid = FALSE;
751
    data->flags.bad_times = TRUE;
752
    data->numb = tm;
753
    for( len = 0; len < MAX_LEGS + 1; len++ )
754
    {
755
        data->leg[len].start = -1;
756
        data->leg[len].end = -1;
757
        data->leg[len].elapsed = -1;
758
        data->leg[len].l_place = 0;
759
        data->leg[len].le_place = 0;
760
        data->leg[len].lec_place = 0;
761
        data->leg[len].lc_place = 0;
762
        data->leg[len].manual = 0;
763
    }
764
}
765
 
766
/*========================================================================
767
 *
768
 *  Save team record to disk
769
 *
770
 *  Purpose:
771
 *      This function is called to save team record to disk
772
 *
773
 *  Parameters:
774
 *      _team       Team number
775
 *      data        Pointer to the data
776
 *
777
 *  Returns:
778
 *      FALSE : Error in save
779
 *
780
 *========================================================================*/
781
bool put_team_record( int _team, team_type * data )
782
{
783
    int         len;                             /* length of record read in */
784
    long        pos;                             /* file pointer */
785
 
786
    pos = _team;
787
    pos *= sizeof( team_type );
788
    lseek( team_fd, pos, 0 );
789
    len = write( team_fd, ( char * ) data, sizeof( team_type ) );
790
    if( len != sizeof( team_type ) )
791
    {
792
        perror( "Team record write" );
793
        sleep( 5 );
794
    }
795
    return ( len == sizeof( team_type ) );
796
}
797
 
798
/*========================================================================
799
 *
800
 *  Initialize the team data file
801
 *
802
 *  Purpose:
803
 *      This function is called to Initialize the team data file and
804
 *      prepare it for processing
805
 *
806
 *  Parameters:
807
 *      None
808
 *
809
 *  Returns:
810
 *      FALSE : Error encountered
811
 *
812
 *========================================================================*/
813
bool init_team_data(void)
814
{
815
 
816
    team_fd = open( datfile, OPEN_RW, 0 );
817
    if( team_fd < 0 )
818
    {
819
        /*
820
         * file does not exist - create it 
821
         */
822
        printf( "The team data file does not exist.\n" );
162 david 823
//        if( getyes( "Create the data file" ) )
824
//        {
825
//            team_fd = creat( datfile, 0664 );
826
//            if( team_fd > 0 )
827
//            {
828
//                close( team_fd );                /* Close th file */
829
//                team_fd = open( datfile, OPEN_RW, 644 );
830
//                if( team_fd < 0 )
831
//                    perror( "Team datafile" );
832
//            }
833
//        }
95 - 834
    }
835
    return ( team_fd >= 0 );
836
}
837
 
838
/*========================================================================
839
 *
840
 *  Close team data file
841
 *
842
 *  Purpose:
843
 *      This function is called to close the team data file
844
 *
845
 *  Parameters:
846
 *      None
847
 *
848
 *  Returns:
849
 *      Nothing
850
 *
851
 *========================================================================*/
852
void fix_team_data(void)
853
{
854
    if( team_fd > 0 )
855
        close( team_fd );
856
}
857
 
858
/********************************* EOF ***********************************/