Subversion Repositories svn1-original

Rev

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