Subversion Repositories svn1

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1 root 1
/*************************************************************************
2
*           Copyright (C) 1995 Embedded Solutions
3
*                       All rights reserved
4
*
5
* file:     src\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
 
62
void team_update(void)
63
{
64
    if( !g_tnum( 0, n_lines - 2, "Enter team number" ) )
65
        return;                        /* Exit operation */
66
 
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
     */
72
 
73
    do
74
    {
75
        clearscreen();
76
        g_record( team, &team_buf );
77
        d_display( M_TEAM );
78
        put_team_record( team, &team_buf );
79
 
80
    } while( g_tnum( 0, n_lines - 2, "Enter next team or RETURN to exit" ) );
81
}
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
 
100
void team_display(void)
101
{
102
    if( !g_tnum( 0, n_lines - 2, "Enter team number" ) )
103
        return;                        /* Exit operation */
104
 
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
     */
110
 
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
}
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
 *========================================================================*/
141
void leg_mods(void)
142
{
143
    if( !g_tnum( 0, n_lines - 2, "Enter team number" ) )
144
        return;                        /* Exit operation */
145
 
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
     */
151
 
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" ) );
168
 
169
}
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
 *========================================================================*/
185
void d_display( int operation )
186
{
187
    int         valid = team_buf.flags.valid;
188
    int         opr;
189
    int         i, j;
45 - 190
    int         age_sum;
1 root 191
 
192
    /*
193
     **  Refresh the entire display (using a recursive call)
194
     */
195
    if( operation != M_DISPLAY )
196
        d_display( M_DISPLAY );
197
 
198
 
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 );
205
 
206
    /*
207
     **  Determine the type of operation required
208
     **      Update or Display
209
     */
210
    opr = ( operation & M_TEAM ) ? M_UPDATE : M_DISPLAY;
211
 
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 ) ) );
222
 
223
    /*
224
     **  Display / Update the class
225
     */
226
    do
227
    {
228
        d_field( 0, 1, "Class : ", D_CLASS, 1, &team_buf.class, valid, opr );
229
        if( abort_flag )
230
            return;
231
    } while( ( opr == M_UPDATE ) && !team_buf.class );
232
 
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;
239
 
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;
247
 
248
    /*
249
     **  Display / Update the name and sex of each team member
250
     */
45 - 251
    age_sum = 0;
1 root 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;
259
 
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;
45 - 264
 
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;
269
 
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
        }
286
 
1 root 287
    }
288
 
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
    }
301
 
302
    /*
303
     **  Display the summary information
304
     **      For the team
305
     **      Event and class placing information
45 - 306
     **      Total age
1 root 307
     */
308
    d_leg( 4 + i, 0, &team_buf.leg[0], valid, M_DISPLAY );
309
 
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 );
45 - 314
    d_field( 40, 6 + i, "Total Age : ", D_STRING, 5,
315
             age_a(age_sum), valid, M_DISPLAY );
316
 
1 root 317
 
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 );
322
 
323
}
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
 *========================================================================*/
344
void d_leg( int y, int leg, leg_type * data, int valid, int operation )
345
{
346
    int         i;
347
    int         oprs, oprf;
348
 
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,
362
                     M_DISPLAY );
363
    }
364
 
365
    /*
366
     **  If we are doing an update,. then ensure that all the team times
367
     **  have been tested
368
     */
369
 
370
    if( operation & M_ALL )
371
        test_times( &team_buf, 0 );              /* Set up all team times */
372
 
373
    oprs = ( ( parallel_legs )
374
             || ( operation & M_ALEGS )
375
             || ( operation & M_LEGS ) ) ? M_UPDATE : M_DISPLAY;
376
 
377
    oprf = ( operation & M_LEGS ) ? M_UPDATE : M_DISPLAY;
378
 
379
    /*
380
     **  if start time edited then flag as manual entry
381
     **  redo calculations and refresh screen with new information
382
     */
383
 
384
    if( d_field
385
        ( 25, y, data->manual ? "MS " : " S ", D_TIME, 8, &data->start, valid,
386
          oprs ) )
387
    {
388
        data->manual = TRUE;
389
        test_times( &team_buf, 0 );
390
        for( i = leg; i <= config.num_legs; i++ )
391
            d_leg( y + i - leg, i, &team_buf.leg[i], valid, M_DISPLAY );
392
        d_leg( y + i - leg, 0, &team_buf.leg[0], valid, M_DISPLAY );
393
    }
394
 
395
    /*
396
     **  If time changed then redo calcs and refresh screen
397
     */
398
    if( d_field( 37, y, "F ", D_TIME, 8, &data->end, valid, oprf ) )
399
    {
400
        set_times( &team_buf );
401
        test_times( &team_buf, 0 );
402
        for( i = leg; i <= config.num_legs; i++ )
403
            d_leg( y + i - leg, i, &team_buf.leg[i], valid, M_DISPLAY );
404
        d_leg( y + i - leg, 0, &team_buf.leg[0], valid, M_DISPLAY );
405
    }
406
 
407
    d_field( 48, y, "E ", D_TIME, 8, &data->elapsed, valid, M_DISPLAY );
408
    if( leg == 0 )
409
    {
410
        d_field( 60, y, "", D_STRING, 10,
411
                 ( team_buf.flags.bad_times ==
412
                   TRUE ) ? "Incomplete" : "          ", valid, M_DISPLAY );
413
    }
414
    else
415
    {
416
        d_field( 60, y, "", D_NUMBER, 4, &data->le_place, valid, M_DISPLAY );
417
        d_field( 65, y, "", D_NUMBER, 4, &data->l_place, valid, M_DISPLAY );
418
        d_field( 70, y, "", D_NUMBER, 4, &data->lec_place, valid, M_DISPLAY );
419
        d_field( 75, y, "", D_NUMBER, 4, &data->lc_place, valid, M_DISPLAY );
420
    }
421
}
422
 
423
/*========================================================================
424
 *
425
 *  Display / Update simple time information
426
 *
427
 *  Purpose:
428
 *      This function is called to display and update the leg
429
 *      time information.
430
 *
431
 *  Parameters:
432
 *      x, y        Screen position
433
 *      prompt      Prompt to display
434
 *      data        Address of time data
435
 *      valid       Data valid flag
436
 *
437
 *  Returns:
438
 *      Nothing
439
 *
440
 *========================================================================*/
441
void d_time( int x, int y, char *prompt, time_t *data, int valid )
442
{
443
        d_field( x, y, prompt, D_TIME, 8, ( char * ) data, valid, M_DISPLAY );
444
        d_field( x, y, prompt, D_TIME, 8, ( char * ) data, valid, M_UPDATE );
445
}
446
 
447
/*========================================================================
448
 *
449
 *  Display / Update field on the screen
450
 *
451
 *  Purpose:
452
 *      
453
 *      This function is called to display and update a field on the screen
454
 *      This routine will display a record from the team structure
455
 *      The type of data and other parameters is passed in
456
 *      This function is fundimental to the entire display subsystem
457
 *
458
 *
459
 *
460
 *  Parameters:
461
 *      x           The screen col
462
 *      y           The line number
463
 *      prompt      The field lable
464
 *      type        type of field
465
 *      length      Length of the numeric field
466
 *      data        Pointer to the data
467
 *      valid       data field is valid
468
 *      operation   Operation type
469
 *
470
 *  Returns:
471
 *      TRUE - Change has been made
472
 *
473
 *========================================================================*/
474
bool d_field( int x,
475
              int y,
476
              char *prompt,
477
              int type, int length, void *data, int valid, int operation )
478
{
479
    time_t      t;
480
    int         i;
481
    sex_type    s;
482
    int         change = 0;
483
    int         idata;
484
 
485
    /*
486
     **  Position the cursor and display the field title
487
     */
488
    cur( x, y );
489
    printf( "%s", prompt );
490
 
491
    /*
492
     **  If the ABORT flag is set then DISPLAY the field
493
     */
494
    if( abort_flag )
495
        operation = M_DISPLAY;
496
 
497
    /*
498
     **  Display the current field value
499
     **      Only if the data field is valid
500
     **      Only if the M_DISPLAY operation is requested
501
     */
502
    if( valid && ( operation == M_DISPLAY ) )
503
    {
504
        switch ( type )
505
        {
506
        case D_STRING:
507
        case D_USTRING:
508
            printf( "%-*.*s", length, length, (char *)data );
509
            break;
510
 
511
        case D_NUMBER:
512
            printf( "%-*d", length, *( short * ) data );
513
            break;
514
 
515
        case D_SEX:
516
            if( *( sex_type * ) data != unknown )
517
                printf( "%s",
518
                        ( *( sex_type * ) data ==
519
                          male ) ? "Male" : "Female" );
520
            break;
521
 
522
        case D_TIME:
523
            printf( "%s", time_a( *( time_t * ) data ) );
524
            break;
525
 
526
        case D_CLASS:
527
            if( *( short * ) data > 0 )
528
            {
529
                printf( "%2.2s", config.team_class[( *( int * ) data ) - 1].abr );
530
                printf( "  %-*.*s", LEN_CLASS_NAME, LEN_CLASS_NAME,
531
                        config.team_class[( *( int * ) data ) - 1].full_name );
532
            }
533
            break;
534
 
535
        case D_COUNTRY:
536
            if( *( short * ) data > 0 )
537
            {
538
                printf( "%4.4s",
539
                        config.country_name[( *( int * ) data ) - 1].abr );
540
                printf( "  %-*.*s", LEN_CNTRY_NAME, LEN_CNTRY_NAME,
541
                        config.country_name[( *( int * ) data ) -
542
                                            1].full_name );
543
            }
544
            break;
545
 
45 - 546
        case D_AGE:
547
            if( *( uchar * ) data > 0 )
548
            {
549
                printf( "%-*d", length, *( uchar * ) data );
550
            }
551
            break;
552
 
553
 
1 root 554
        case D_NULL:
555
            break;
556
 
557
        default:
558
            printf( "Unknown data type" );
559
            break;
560
        }
561
    }
562
 
563
    /*
564
     **  If updating the field then extract the required information
565
     */
566
    if( operation == M_UPDATE )
567
    {
568
        switch ( type )
569
        {
570
        case D_STRING:
571
            change = ( getstring( length, data, Alphanum ) );
572
            break;
573
 
574
        case D_USTRING:
575
            change = ( getstring( length, data, AlphnumUpper ) );
576
            break;
577
 
578
        case D_NUMBER:
579
            idata = *(short *)data;
580
            change = getnum( length, &idata );
581
            if ( change )
582
                *( short *)data = idata;
583
            break;
584
 
585
        case D_SEX:
586
            if( ( s = getsex() ) != unknown )
587
            {
588
                change = ( *( sex_type * ) data != s );
589
                *( sex_type * ) data = s;
590
            }
591
            break;
592
 
593
        case D_TIME:
594
            if( ( t = get_time(*( time_t * ) data) ) >= 0 )
595
            {
596
                change = ( *( time_t * ) data != t );
597
                *( time_t * ) data = t;
598
            }
599
            break;
600
 
601
        case D_CLASS:
602
            if( ( i = getclass() ) != 0 )
603
            {
604
                change = *( short * ) data != i;
605
                *( short * ) data = i;
606
            }
607
            break;
608
 
609
        case D_COUNTRY:
610
            if( ( i = getcountry() ) != 0 )
611
            {
612
                change = *( short * ) data != i;
613
                *( short * ) data = i;
614
            }
615
            break;
616
 
45 - 617
        case D_AGE:
618
            idata = *(uchar *)data;
619
            change = getnum( length, &idata );
620
            if ( change )
621
                *( uchar *)data = idata;
622
            break;
623
 
624
 
1 root 625
        case D_NULL:
626
            break;
627
 
628
        default:
629
            printf( "Unknown data type" );
630
            break;
631
        }
632
 
633
        /*
634
         **  Having accepted the input now DISPLAY the data (once again)
635
         **      Done to allow aborted field to re-display original values
636
         */
637
        d_field( x, y, prompt, type, length, data, TRUE, M_DISPLAY );
638
    }
639
    return ( change );
640
}
641
 
642
/*========================================================================
643
 *
644
 *  Get a team number from the operator
645
 *
646
 *  Purpose:
647
 *      This function is called to Get a team number from the operator
648
 *          Prompt the operator for a team number
649
 *          Verify that the team number is valid
650
 *          Allow escape characters in the process
651
 *
652
 *          This routine will return TRUE if the team number is valid
653
 *          The team number is returned in the global variable "team"
654
 *
655
 *  Parameters:
656
 *      x,y         Screen coords
657
 *      prompt      Operator prompt
658
 *
659
 *  Returns:
660
 *      TRUE    : Number OK
661
 *
662
 *========================================================================*/
663
bool g_tnum( int x, int y, char *prompt )
664
{
665
    int         new_team = 0;                   /* team number that will be input */
666
 
667
    while( TRUE )
668
    {
669
        team = 0;
670
        abort_flag = FALSE;
671
        cur( x, y );
672
        printf( "%s : ", prompt );
673
        console_clreol();
674
        if( !getnum( 6, &new_team ) )
675
            return ( FALSE );                    /* No input */
676
 
677
        /*
678
         * verify that the team number is within the allowed numbers 
679
         */
680
 
681
        if( !valid_field( new_team ) )
682
        {
683
            beep();
684
            printf( "\nTeam %-1d is not valid", new_team );
685
            continue;
686
        }
687
        team = new_team;
688
        return ( TRUE );
689
    }
690
}
691
 
692
/*========================================================================
693
 *
694
 *  Read a team record from disk
695
 *
696
 *  Purpose:
697
 *      This function is called to Read a team record from disk
698
 *      Locate the team record in the team data file
699
 *      if the record does not exist create a blank record
700
 *
701
 *      The function will return FALSE if the record was not on disk
702
 *      otherwise TRUE
703
 *
704
 *  Parameters:
705
 *      int_team        Team record required
706
 *      data            Area to return record
707
 *
708
 *  Returns:
709
 *      FALSE : No data available
710
 *
711
 *========================================================================*/
712
bool g_record( int _team, team_type * data )
713
{
714
    int         len;                             /* length of record read in */
715
    long        pos;                             /* File pointer */
716
 
717
    pos = _team;
718
    pos *= sizeof( team_type );
719
    len = lseek( team_fd, pos, 0 );
720
    len = read( team_fd, ( char * ) data, sizeof( team_type ) );
721
    if( ( len == sizeof( team_type ) ) && ( _team == data->numb ) )
722
        return ( data->flags.valid );
723
    else
724
    {
725
        clr_team( _team, data );
726
        return ( FALSE );
727
    }
728
}
729
 
730
/*========================================================================
731
 *
732
 *  Clear team data from file
733
 *
734
 *  Purpose:
735
 *      This function is called to Clear team data from file
736
 *      This routine will set the team data to INVALID
737
 *
738
 *  Parameters:
739
 *      tm          Team number
740
 *      data        Pointer to the data
741
 *
742
 *  Returns:
743
 *      Nothing
744
 *
745
 *========================================================================*/
746
void clr_team( int tm, team_type * data )
747
{
748
    int         len;
749
 
750
    memset( ( char * ) data, 0, ( int ) sizeof( team_type ) );
751
    data->flags.valid = FALSE;
752
    data->flags.bad_times = TRUE;
753
    data->numb = tm;
754
    for( len = 0; len < MAX_LEGS + 1; len++ )
755
    {
756
        data->leg[len].start = -1;
757
        data->leg[len].end = -1;
758
        data->leg[len].elapsed = -1;
759
        data->leg[len].l_place = 0;
760
        data->leg[len].le_place = 0;
761
        data->leg[len].lec_place = 0;
762
        data->leg[len].lc_place = 0;
763
        data->leg[len].manual = 0;
764
    }
765
}
766
 
767
/*========================================================================
768
 *
769
 *  Save team record to disk
770
 *
771
 *  Purpose:
772
 *      This function is called to save team record to disk
773
 *
774
 *  Parameters:
775
 *      _team       Team number
776
 *      data        Pointer to the data
777
 *
778
 *  Returns:
779
 *      FALSE : Error in save
780
 *
781
 *========================================================================*/
782
bool put_team_record( int _team, team_type * data )
783
{
784
    int         len;                             /* length of record read in */
785
    long        pos;                             /* file pointer */
786
 
787
    pos = _team;
788
    pos *= sizeof( team_type );
789
    lseek( team_fd, pos, 0 );
790
    len = write( team_fd, ( char * ) data, sizeof( team_type ) );
791
    if( len != sizeof( team_type ) )
792
    {
793
        perror( "Team record write" );
794
        sleep( 5 );
795
    }
796
    return ( len == sizeof( team_type ) );
797
}
798
 
799
/*========================================================================
800
 *
801
 *  Initialize the team data file
802
 *
803
 *  Purpose:
804
 *      This function is called to Initialize the team data file and
805
 *      prepare it for processing
806
 *
807
 *  Parameters:
808
 *      None
809
 *
810
 *  Returns:
811
 *      FALSE : Error encountered
812
 *
813
 *========================================================================*/
814
bool init_team_data(void)
815
{
816
 
817
    team_fd = open( datfile, OPEN_RW, 0 );
818
    if( team_fd < 0 )
819
    {
820
        /*
821
         * file does not exist - create it 
822
         */
823
        printf( "The team data file does not exist.\n" );
824
        if( getyes( "Create the data file" ) )
825
        {
826
            team_fd = creat( datfile, 0664 );
827
            if( team_fd > 0 )
828
            {
829
                close( team_fd );                /* Close th file */
830
                team_fd = open( datfile, OPEN_RW, 644 );
831
                if( team_fd < 0 )
832
                    perror( "Team datafile" );
833
            }
834
        }
835
    }
836
    return ( team_fd >= 0 );
837
}
838
 
839
/*========================================================================
840
 *
841
 *  Close team data file
842
 *
843
 *  Purpose:
844
 *      This function is called to close the team data file
845
 *
846
 *  Parameters:
847
 *      None
848
 *
849
 *  Returns:
850
 *      Nothing
851
 *
852
 *========================================================================*/
853
void fix_team_data(void)
854
{
855
    if( team_fd > 0 )
856
        close( team_fd );
857
}
858
 
859
/********************************* EOF ***********************************/