Subversion Repositories svn1

Rev

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

Rev Author Line No. Line
1 root 1
/*************************************************************************
2
*           Copyright Xdel Technology Pty. Ltd. 1987
3
*           Copyright (C) 1995 Embedded Solutions
4
*                       All rights reserved
5
*
6
* file:     src\upload.c
7
*
8
* purpose:  Data upload functions
9
*           This module contains all the functions required to upload
10
*           data from the handheld calculators and insert the data
11
*           into the data base as well as functions and a menu to load
12
*           and unload specific data into the data base
13
*
14
* functions
15
*       upload                  - Get Leg to upload
16
*       ins_data                - Insert time info into data base
17
*       supload                 - Extended upload functions menu
18
*       tupload                 - Read in text team information
19
*       t_parse_number          - Parse a number from a CSV line of team text
20
*       t_parse_text            - Parse string from a CSV line of team text
21
*       p_del                   - Test for a delimiter.
22
*       tdnload                 - Generate team name file
23
*       dnload                  - Generate leg timing file
24
*       getfname                - Get a filename from the user
25
*
26
* programmer: David Purdie
27
*
28
* revision  date        by      reason
29
*           May 1990    Margherita Veroni
30
*                               The functions to upload data have been modified
31
*                               to allow leg start times to also be uploaded for
32
*                               any leg. Data being uploaded which contain errors
33
*                               are written to an error file
34
*
35
*   00.0    1-Apr-94    DDP     Changed tdnload() to produce a comma seperated
36
*                               file. This allows external users to see the
37
*                               field delimters better than tabs
38
*
39
*   00.0    27/01/95    DDP     Tidies up the program and formatted the file
40
*
41
**************************************************************************/
42
 
43
#include    <stdio.h>
44
 
45
#include    "consts.h"
46
#include    "structs.h"
47
#include    "proto.h"
48
 
49
/* Variable storage */
50
 
51
char        ufilename[40];                       /* Name of upload file */
52
FILE       *ufile;                               /* Upload file stream */
53
FILE       *efile;                               /* Error file stream */
54
char        line[300];                           /* Input line */
55
char        line_text[133];                      /* Output text */
56
 
57
unsigned char manstart;                          /* Manual start time entry */
58
 
59
 
60
menu_table  sup_menu[] = {
61
    { '1', "Load team information from external file", tupload },
54 - 62
    { '2', "Store team information from external file", tdnload_store },
63
    { '3', "Create external team information file", tdnload },
64
    { '4', "Create external leg data file", dnload },
65
    { '5', "Upload time information", upload },
1 root 66
    { 'q', "Return to main menu", 0 },
67
    { '\0' }
68
};
69
 
70
/*========================================================================
71
 *
72
 *  Get Leg to upload
73
 *
74
 *  Purpose:
75
 *      This function is called to Get Leg to upload
76
 *          Prompt user for leg number and start / end of leg
77
 *          Open disc file
78
 *          Read and parse text. Enter data into team information
79
 *          Maintain error file of errors.
80
 *
81
 *  Parameters:
82
 *      None
83
 *
84
 *  Returns:
85
 *      Nothing
86
 *
87
 *========================================================================*/
88
 
89
void upload(void)
90
{
91
    int         hh, mm, ss;                      /* Team times */
92
    int         error = 0;                       /* Count of errors */
93
    int         ntms = 0;                        /* Number of teams uploaded */
94
    char        stend[] = "E";                   /* Start or End time */
95
    char       *filename;                        /* Name of file to open */
96
    char       *err_filename;                    /* Name of an error file to open */
97
 
98
    cur( 0, 5 );
99
    while( TRUE )
100
    {
101
        leg = 0;
102
        d_field( 0, 6, "Enter leg to upload :", D_NUMBER, 1, ( char * ) &leg,
103
                 TRUE, M_UPDATE );
104
        if( leg == 0 )
105
            return;                              /* Null leg - just exit */
106
        if( leg <= config.num_legs )             /* Valid leg number - Exit loop */
107
            break;
108
        beep();                                  /* Make a noise and wait for valid number */
109
    }
110
 
111
 
112
    /*
113
     * Find out if Start or End of leg times to be uploaded 
114
     */
115
 
116
    do
117
    {
118
        d_field( 0, 7, "Start or End of leg to upload :", D_USTRING, 1, stend,
119
                 TRUE, M_UPDATE );
120
    } while( ( stend[0] != 'S' ) && ( stend[0] != 'E' ) );
121
    manstart = ( ( stend[0] == 'S' ) ? TRUE : FALSE );
122
    printf( "\n" );
123
 
124
    /*
125
     * Locate the required data file and prepare for processing 
126
     */
127
    filename = tprintf( "%s%d" , manstart ? "Sleg" : "leg" , leg );
128
    ufile = fopen( filename, "rt" );
129
    if( ufile == 0 )
130
    {
131
        printf( "Cannot locate data file - %s\n", filename );
132
        beep();
133
        sleep( 5 );
134
        return;
135
    }
136
 
137
    /*
138
     * create an error file for this leg data 
139
     * duplicate times will stored here
140
     */
141
    err_filename = tprintf( "%s%d.err" , manstart ? "Sleg" : "leg" , leg );
142
    efile = fopen( err_filename, "at" );
143
 
144
    /*
145
     * Process each entry in the file 
146
     */
147
 
148
    if( leg > config.num_legs )
149
        printf( "\nUploading leg%d start information\n", leg );
150
 
151
    while( fgets( line, 101, ufile ) )
152
    {
153
        if( sscanf( line, "%d %d:%d:%d", &team, &hh, &mm, &ss ) != 4 )
154
        {
155
            printf( "Upload error - %s", line );
156
            error++;
157
        }
158
        else
159
        {
160
            if( !ins_data( team, hh, mm, ss ) )
161
                error++;
162
            ntms++;
163
        }
164
    }
165
 
166
    printf( "%d errors detected. %d teams uploaded. Any key to continue ", error, ntms );
167
    getinp();
168
 
169
    fclose( ufile );
170
    fclose( efile );
171
}
172
 
173
/*========================================================================
174
 *
175
 *  Insert time info into data base
176
 *
177
 *  Purpose:
178
 *      This helper function is called to Insert time info into data base
179
 *          Read record
180
 *          Read and convert time
181
 *          Write record
182
 *              Maintain error file
183
 *          Display errors on screen
184
 *
185
 *  Parameters:
186
 *      tm          Team
187
 *      hh          hours
188
 *      mm          minutes
189
 *      ss          seconds
190
 *
191
 *  Returns:
192
 *      Nothing
193
 *
194
 *========================================================================*/
195
 
196
int ins_data( int tm, int hh, int mm, int ss )
197
{
198
    time_t      l_time;                          /* Leg time */
199
    int         ok = TRUE;
200
 
201
    /*
202
     * Calculate the time for the team 
203
     */
204
 
205
    l_time = conv_time( hh, mm, ss );
206
 
207
    /*
208
     * If an error is found - invalid team, team not found or dual time for team
209
     * a message is output to the screen and the data is written to error file
210
     * FALSE is returned
211
     */
212
 
213
    if( !valid_field( tm ) )
214
    {
215
        printf( "Invalid team - %d %2.2d:%2.2d:%2.2d\n", tm, hh, mm, ss );
216
        fprintf( efile, "Invalid team - %d %2.2d:%2.2d:%2.2d\n", tm, hh, mm,
217
                 ss );
218
        ok = FALSE;
219
        return ( ok );
220
    }
221
    if( !g_record( tm, &team_buf ) )
222
    {
223
        printf( "Team not found -% d %2.2d:%2.2d:%2.2d\n", tm, hh, mm, ss );
224
        fprintf( efile, "Team not found - %d %2.2d:%2.2d:%2.2d\n", tm, hh, mm, ss );
225
        ok = FALSE;
226
    }
227
    if( !manstart )
228
    {                                            /* Normal upload */
229
        if( team_buf.leg[leg].end > 0 && team_buf.leg[leg].end != l_time )
230
        {
231
            printf( "Dual time for %d - %2.2d:%2.2d:%2.2d and %s\n", tm, hh,
232
                    mm, ss, time_a( team_buf.leg[leg].end ) );
233
            fprintf( efile, "Dual time for %d - %2.2d:%2.2d:%2.2d and %s\n",
234
                        tm, hh, mm, ss, time_a( team_buf.leg[leg].end )
235
                    ); /* write  duplicate time to error file */
236
            ok = FALSE;
237
            return ( ok );                       /* keep time already in database */
238
        }
239
        team_buf.leg[leg].end = l_time;
240
    }
241
    else
242
    {                                            /* Uplaod start time */
243
        team_buf.leg[leg].start = l_time;
244
        team_buf.leg[leg].manual = TRUE;
245
    }
246
    set_times( &team_buf );                      /* Calc start of next leg */
247
    ( void ) test_times( &team_buf, 0 );         /* Calc elapsed times etc */
248
    put_team_record( tm, &team_buf );
249
    return ( ok );
250
}
251
 
252
/*========================================================================
253
 *
254
 *  Extended upload functions menu
255
 *
256
 *  Purpose:
257
 *      This function is called to Extended upload functions
258
 *
259
 *  Parameters:
260
 *      None
261
 *
262
 *  Returns:
263
 *      Nothing
264
 *
265
 *========================================================================*/
266
 
267
void supload(void)
268
{
269
    do_menu( "Extended data manipulation", "Select option", sup_menu ); /* Call a menu to do it */
270
}
271
 
272
/*========================================================================
273
 *
274
 *  Read in text team information
275
 *
276
 *  Purpose:
277
 *      This function is called to do Read in text team information
278
 *      from a file
279
 *
280
 *      The source file is a comma seperated file and may contain the
281
 *      folowing items
282
 *
283
 *      Team Number     - Mandatory
284
 *      Team Name       - Mandatory
285
 *      Team Catagory   - Mandatory
286
 *
287
 *      Team Names ...  - Optional
288
 *
289
 *  Parameters:
290
 *      None
291
 *
292
 *  Returns:
293
 *      Nothing
294
 *
295
 *========================================================================*/
296
 
297
void tupload(void)
298
{
299
    int         error = 0;
300
    int         i;
301
    char       *linep;
302
    int         class_count[MAX_CLASS];
303
    int         total;
304
 
305
    cur( 0, 5 );
306
    printf( "Read text file of team information" );
307
 
308
    if( !getfname( "Enter name of the file to read :", ".csv" ) )
309
        return;
310
    printf( "\n" );
311
 
312
    ufile = fopen( ufilename, "rt" );             /* Open the file for reading */
313
    if( ufile == 0 )
314
    {
315
        printf( "Cannot locate data file - %s\n", ufilename );
316
        beep();
317
        sleep( 5 );
318
        return;
319
    }
320
 
321
    memset ( class_count, 0, sizeof( class_count ));
322
 
323
    /*
324
    **  Get the data from the file
325
    **  Read in lines one by one
326
    */
327
    while( fgets( line, sizeof(line) - 10 , ufile ) )
328
    {
329
        linep = line;
31 - 330
        int has_data = 0;
1 root 331
        /*
332
        **  Skip blank lines
333
        **  Skip leading white space
334
        */
31 - 335
        for ( linep = line; *linep; linep++ )
336
        {
337
            if ( *linep == (char)0xA0 || *linep == '"' || *linep == ',' || *linep == '\n' ||*linep == '\r')
338
            {
339
                continue;
340
            }
341
            has_data = 1;
342
        }
343
        if ( !has_data )
344
            continue;
345
 
1 root 346
        for ( linep = line; isspace( *linep ); linep++ )
347
        {
348
        }
349
        if ( ! *linep )
350
            continue;
351
 
352
        /*
353
        **  The first entry on the line should be team number
354
        **  If it is not a valid team number then skip
355
        */
356
        if( ! t_parse_number( &linep, &team ) )
357
        {
358
            printf( "No team number: %-30s.\n", line );
359
            error++;
360
        }
361
        else if( ! valid_field( team ) )
362
        {
363
            printf ( "Invalid team number: %d\n", team );
364
            error++;
365
        }
366
        else
367
        {
368
            g_record( team, &team_buf );
369
 
370
            /*
371
            **  Extract a team information from the CSV file
372
            **  These fields will be
373
            **      - Team Name
374
            **      - Category
375
            **      - Member names
376
            */
377
            if ( t_parse_text( &linep, line_text ) )
378
            {
379
                strncpy (team_buf.name,line_text,MAX_TM_NAME);
31 - 380
                if ( ! *line_text )
381
                {
382
                    printf( "Team: %d - No Team Name:%50.50s...\n", team, line );
383
                }
1 root 384
            }
385
 
31 - 386
            if ( t_parse_text( &linep, line_text )  && *line_text)
1 root 387
            {
388
                int cat_found = 0;
389
                team_buf.class = lookup_class( line_text, NULL );
390
                if ( team_buf.class > 0)
391
                {
392
                    /*
393
                    **  The team has a category
394
                    **  Now flag the team as valid - it has ALL
395
                    **  the basic information
396
                    */
397
                    team_buf.flags.valid = TRUE;
398
                    cat_found =1;
399
 
400
                    if ( team_buf.class < MAX_CLASS )
401
                        class_count[team_buf.class]++;
402
                }
403
 
31 - 404
                if ( !cat_found )
1 root 405
                {
406
                    printf( "Team: %d - Invalid category:%s\n", team,line_text );
407
                    error++;
408
                }
409
            }
31 - 410
            else
411
            {
412
                printf( "Team: %d - No category:%50.50s...\n", team, line );
413
                error++;
414
            }
1 root 415
 
416
            for( i = 0; i < MAX_MEMB; i++ )
417
            {
418
                if ( t_parse_text( &linep, line_text ) )
419
                {
420
                    strncpy (team_buf.members[i].name,line_text,MAX_PERSON_NAME);
421
                }
45 - 422
 
423
                int age;
424
                if ( t_parse_number( &linep, &age ) )
425
                {
426
                    team_buf.members[i].age = age;
427
                }
1 root 428
            }
429
 
430
            put_team_record( team, &team_buf );
431
        }
432
 
31 - 433
/*
434
**       printf( ">>>:%s\n", line );
435
**       if ( 'q' == getinp() ) break;
436
*/       
437
 
1 root 438
    }
439
 
440
    /*
441
    **  Display a few upload stats
442
    */
443
    total = 0;
444
    for( i = 0; i < config.num_class; i++ )
445
    {
446
        printf( "%*s : %d\n", LEN_CLASS_NAME, config.team_class[i].full_name, class_count[i+1] );
447
        total += class_count[i+1];
448
    }
449
 
450
    printf( "\n%*s : %d\n", LEN_CLASS_NAME, "Total Uploaded", total );
451
    printf( "%*s : %d\n", LEN_CLASS_NAME, "Errors", error );
452
 
453
 
454
    printf( "\nAny key to continue " );
455
    getinp();
456
 
457
    fclose( ufile );
458
}
459
 
460
 
461
/*========================================================================
462
 *
463
 *  Parse a number from a CSV text file
464
 *
465
 *  Purpose:
466
 *      This helper function is called to Parse line of team text
467
 *
468
 *  Parameters:
469
 *      linep           Current input source pointer
470
 *                      Will be updated to point to end of the field
45 - 471
 *                      If the field is a valid number
1 root 472
 *      number          Number extracted
473
 *
474
 *  Returns:
475
 *      TRUE - Number extracted OK
476
 *      FALSE - No number extracted
477
 *
478
 *========================================================================*/
479
 
480
bool t_parse_number( char **linep, int *number )
481
{
482
    long    lnumber;
45 - 483
    char    *work = *linep;
54 - 484
    char    *endp;
1 root 485
 
486
    /*
54 - 487
    **  Extract data from the CSV field
488
    **  May need to remove quotes
489
    **  Use temp work space
1 root 490
    */
54 - 491
    t_parse_text( &work, line_text);
1 root 492
 
493
    /*
54 - 494
    **  Expecting a number
495
    **  strtol will remove leading white space
1 root 496
    */
54 - 497
    lnumber = strtol( line_text, &endp, 10 );
1 root 498
 
499
    /*
500
    **  A valid number ?
54 - 501
    **  All the field must be numeric, otherwise it wasn't a number
1 root 502
    */
54 - 503
    if ( lnumber == 0 || *endp  )
1 root 504
        return FALSE;
505
 
506
    *number = (int) lnumber;
45 - 507
    *linep = work;
1 root 508
    return TRUE;
509
}
510
 
511
/*========================================================================
512
 *
513
 *  Parse a text field from a CSV text file
514
 *
515
 *  Purpose:
516
 *      This helper function is called to Parse line of team text
517
 *
518
 *  Parameters:
519
 *      linep           Current input source pointer
520
 *                      Will be updated to point to end of the field
521
 *      number          Address of buffer to insert text into
522
 *
523
 *  Returns:
524
 *      TRUE - Field extracted OK
525
 *      FALSE - No field extracted
526
 *
527
 *========================================================================*/
528
 
529
bool t_parse_text( char **linep, char *text )
530
{
531
    char    uch;
532
    char    *textp = text;
533
    bool    quoted = FALSE;
534
 
535
    /*
536
    **  If we have already reached the end of the line tne indicate
537
    **  That there is no data
538
    */
539
    uch = **linep;
540
    if ( uch == '\n' || uch == '\r' || uch == '\0' )
541
        return ( FALSE );
542
 
543
    /*
544
    **  Extract the next record
545
    */
546
    while ( TRUE )
547
    {
548
        uch = **linep;
549
 
550
        /*
551
        **  End of the field
552
        */
553
        if ( uch == '\n' || uch == '\r' || uch == '\0' )
554
            break;
555
 
556
        (*linep)++;
31 - 557
 
558
        /*
559
        ** Ugly character from MS CSV files
560
        */
561
        if ( uch == (char) 0xA0 )
562
        {
563
            continue;
564
        }
565
 
1 root 566
        if ( !quoted && uch == ',' )
567
        {
568
            break;
569
        }
570
 
571
        /*
572
        **  An unquoted " will start scanning for a matching quote
573
        */
574
        if ( !quoted && uch == '"' )
575
        {
576
            quoted = TRUE;
577
            continue;
578
        }
579
 
580
 
581
        /*
54 - 582
        **  A quoted " may be an embedded quote or the end of a quote
1 root 583
        */
584
        if ( quoted && uch == '"' )
585
        {
586
            if ( **linep != '"' )
587
            {
588
                quoted = FALSE;
589
                continue;
590
            }
591
 
592
            /*
593
            **  Skip one " and pick up the next
594
            */
595
            (*linep)++;
596
 
597
        }
598
 
599
        /*
600
        **  Save this character
601
        */
602
        *textp++ = uch;
603
    }
604
 
605
    /*
606
    **  Clean up the extracted string
607
    */
608
    *textp = 0;
609
    compact ( text );
610
 
611
    return ( TRUE );
612
}
613
 
614
/*========================================================================
615
 *
616
 *  Test for a delimiter.
617
 *
618
 *  Purpose:
619
 *      This function is called to Test for a delimiter.
620
 *
621
 *  Parameters:
622
 *      c           Character to test
623
 *
624
 *  Returns:
625
 *      TRUE if a delimter (space, tab or comma)
626
 *
627
 *========================================================================*/
628
 
629
char p_del( char *c )
630
{
631
    return ( *c == ' ' || *c == '\t' || *c == ',' || *c == '\0' || *c == '\n' || *c == '\r');
632
}
633
 
634
char p_eol( char *c )
635
{
636
    return ( *c == '\0' || *c == '\n' || *c == '\r' );
637
}
638
 
639
/*========================================================================
640
 *
641
 *  Generate team name file
642
 *
643
 *  Purpose:
54 - 644
 *      This function is called to Generate team name file in the format
645
 *      that can be read by the load command
646
 *
647
 *      The file contains team number,Team name,Team class
648
 *      The operator is prompted to enter the name of the file
649
 *
650
 *  Parameters:
651
 *      None
652
 *
653
 *  Returns:
654
 *      Nothing
655
 *
656
 *========================================================================*/
657
 
658
void tdnload_store(void)
659
{
660
    int         i;
661
    int         j;
662
 
663
    cur( 0, 5 );
664
    printf( "Create text file of team information" );
665
 
666
    if( !getfname( "Enter name of the file to create :", ".csv.txt" ) )
667
        return;
668
    printf( "\n" );
669
 
670
    /*
671
    **  Open printer, with known filename
672
    */
673
    if( !open_printer_name( ufilename, 2000, FALSE, NULL ) )
674
    {
675
        beep();
676
        sleep( 5 );
677
        return;
678
    }
679
 
680
    /*
681
    **  Print headings
682
    */
683
    csv_print( "%s",   "Team Number" );
684
    csv_print( "%s",   "Team Name" );
685
    csv_print( "%s",   "Class Abr");
686
 
687
    for( j = 1; j <= config.num_legs; j++ )
688
    {
689
        csv_print( "%s", "Competitor Name");
690
        csv_print( "%s", "Age");
691
    }
692
    csv_print("\n");
693
 
694
    /*
695
     * Put the data into the file
696
     */
697
 
698
    for( i = config.min_team; i <= config.max_team; i++ )
699
    {
700
        if( valid_field( i ) && g_record( i, &team_buf ) )
701
        {
702
            /*
703
            **  Basic information
704
            **      - Team number
705
            **      - Full team name
706
            */
707
            csv_print( "%d",   team_buf.numb );
708
            csv_print( "%s",   team_buf.name );
709
            csv_print( "%s",    team_buf.class == 0 ? "" : config.team_class[team_buf.class - 1].abr );
710
            for( j = 1; j <= config.num_legs; j++ )
711
            {
712
                csv_print( "%s", team_buf.members[j-1].name );
713
                csv_print( "%d", team_buf.members[j-1].age );
714
            }
715
            csv_print( "\n" );
716
        }
717
    }
718
    close_printer();
719
}
720
 
721
/*========================================================================
722
 *
723
 *  Generate team name file
724
 *
725
 *  Purpose:
1 root 726
 *      This function is called to Generate team name file
727
 *
728
 *      The file contains team number,Team name,Team class
729
 *      The operator is prompted to enter the name of the file
730
 *
731
 *  Parameters:
732
 *      None
733
 *
734
 *  Returns:
735
 *      Nothing
736
 *
737
 *========================================================================*/
738
 
739
void tdnload(void)
740
{
741
    int         i;
742
 
743
    cur( 0, 5 );
744
    printf( "Create text file of team information" );
745
 
746
    if( !getfname( "Enter name of the file to create :", ".txt" ) )
747
        return;
748
    printf( "\n" );
749
 
750
    ufile = fopen( ufilename, "wt" );             /* Open the file for writing */
751
    if( ufile == 0 )
752
    {
753
        printf( "Cannot create data file - %s\n", ufilename );
754
        beep();
755
        sleep( 5 );
756
        return;
757
    }
758
 
759
    /*
54 - 760
     * Put the data into the file
1 root 761
     */
762
 
763
    for( i = config.min_team; i <= config.max_team; i++ )
764
    {
765
        if( valid_field( i ) && g_record( i, &team_buf ) )
766
        {
767
            fprintf( ufile, "%-5d,%-30s,%-5s\n",
768
                     team_buf.numb,
769
                     team_buf.name,
770
                     team_buf.class >
771
 
772
        }
773
    }
774
    fclose( ufile );
775
}
776
 
777
/*========================================================================
778
 *
779
 *  Generate leg timing file
780
 *
781
 *  Purpose:
782
 *      This function is called to Generate leg timing file
783
 *
784
 *  Parameters:
785
 *      None
786
 *
787
 *  Returns:
788
 *      Nothing
789
 *
790
 *========================================================================*/
791
 
792
void dnload(void)
793
{
794
    int         i;
795
    char        stend[] = "E";
796
 
797
    cur( 0, 5 );
798
    printf( "Generate leg data files" );
799
    while( TRUE )
800
    {
801
        leg = 0;
802
        d_field( 0, 6, "Enter leg to save :", D_NUMBER, 1, ( char * ) &leg,
803
                 TRUE, M_UPDATE );
804
        if( leg == 0 )
805
            return;                              /* Null leg - just exit */
806
        if( leg <= config.num_legs )             /* Valid leg number - exit loop */
807
            break;
808
        beep();                                /* Make a noise and keep waiting for valid number */
809
 
810
    }
811
 
812
 
813
    /*
54 - 814
     * Find out if Start or End of leg times to be saved
1 root 815
     */
816
 
817
    do
818
    {
819
        d_field( 0, 7, "Start of End of leg to save :", D_USTRING, 1, stend,
820
                 TRUE, M_UPDATE );
821
    } while( ( stend[0] != 'S' ) && ( stend[0] != 'E' ) );
822
    manstart = ( stend[0] == 'S' ? TRUE : FALSE );
823
 
824
    /*
54 - 825
     * Locate the required data file and prepare for processing
1 root 826
     */
827
 
828
    printf( "\n" );
829
    sprintf( ufilename, ( manstart ? "Sleg%d" : "leg%d" ), leg );   /* Create the file name */
830
    ufile = fopen( ufilename, "wt" );             /* Open the file for writing */
831
    if( ufile == 0 )
832
    {
833
        printf( "Cannot create data file - %s\n", ufilename );
834
        beep();
835
        sleep( 5 );
836
        return;
837
    }
838
 
839
    /*
54 - 840
     * Write the data to the data file
1 root 841
     */
842
 
843
    for( i = config.min_team; i <= config.max_team; i++ )
844
    {
845
        if( valid_field( i ) && g_record( i, &team_buf ) )
846
        {
847
            if( !manstart
848
                && ( leg <= config.num_legs && team_buf.leg[leg].end >= 0 ) )
849
                fprintf( ufile, "%d %s\n", i,
850
                         time_a( team_buf.leg[leg].end ) );
851
 
852
            if( manstart && team_buf.leg[leg].start >= 0 )
853
                fprintf( ufile, "%d %s\n", i,
854
                         time_a( team_buf.leg[leg].start ) );
855
        }
856
    }
857
    fclose( ufile );
858
}
859
 
860
/*========================================================================
861
 *
862
 *  Get a filename from the user
863
 *
864
 *  Purpose:
865
 *      This function is called to Get a filename from the user
866
 *
867
 *  Parameters:
868
 *      prompt      User prompt
869
 *      ext         File extension
870
 *
871
 *  Returns:
872
 *      TRUE: all is well
873
 *
874
 *========================================================================*/
875
 
876
char getfname( char *prompt, char *ext )
877
{
878
    /*
879
    **  Create a default name if non is present
880
    */
881
    if ( ! *ufilename )
882
    {
883
        sprintf( ufilename, "%s%s", filebase, ext );
884
    }
885
 
886
    d_field( 0, 6, prompt, D_STRING, 40, ufilename, TRUE, M_UPDATE );
887
    if( abort_flag )
888
        return ( FALSE );
889
 
890
    compact( ufilename );
891
    if( ufilename[0] )
892
        return ( TRUE );
893
    return ( FALSE );
894
}
895
 
896
/********************************* EOF ***********************************/