Subversion Repositories svn1-original

Rev

Rev 157 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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