Subversion Repositories svn1-original

Rev

Rev 179 | Rev 181 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 179 Rev 180
Line 5... Line 5...
5
#include <QMessageBox>
5
#include <QMessageBox>
6
#include <QFileInfo>
6
#include <QFileInfo>
7
#include <QFile>
7
#include <QFile>
8
 
8
 
9
// Global Data
9
// Global Data
10
MARA_CFG    config;
10
QmConfig    config;
11
QString     fileName;
-
 
-
 
11
 
12
 
12
 
13
/*
13
/*
14
**  Local definitions
14
**  Local definitions
15
*/
15
*/
16
char        datfile[20];                         /* Name of the data file */
16
char        datfile[20];                         /* Name of the data file */
17
char        filebase[20];                        /* Event file name base */
17
char        filebase[20];                        /* Event file name base */
18
char        filepath[100];
18
char        filepath[100];
19
 
19
 
20
QmConfig::QmConfig(const QString &cnfFile)
20
void QmConfig::load(const QString &cnfFile)
21
{
21
{
22
    fileName = cnfFile;
22
    fileName = cnfFile;
23
    if ( !fileName.endsWith(".cnf",Qt::CaseInsensitive))
23
    if ( !fileName.endsWith(".cnf",Qt::CaseInsensitive))
24
    {
24
    {
25
        fileName.append(".cnf");
25
        fileName.append(".cnf");
Line 73... Line 73...
73
 
73
 
74
bool QmConfig::open_read_config( void )
74
bool QmConfig::open_read_config( void )
75
{
75
{
76
    bool result;
76
    bool result;
77
    // Open the file
77
    // Open the file
-
 
78
    QFile configFile;
78
    configFile.setFileName(fileName);
79
    configFile.setFileName(fileName);
79
    if ( ! configFile.open(QIODevice::ReadOnly) )
80
    if ( ! configFile.open(QIODevice::ReadOnly) )
80
    {
81
    {
81
        MainWindow::showMessage("Cannot open config File");
82
        MainWindow::showMessage("Cannot open config File");
82
        return (false );
83
        return (false );
83
    }
84
    }
84
 
85
 
85
    result = read_config();
86
    result = read_config(configFile);
86
    configFile.close();
87
    configFile.close();
87
 
88
 
88
    if ( result )
89
    if ( result )
89
    {
90
    {
90
        /*
91
        /*
91
         **  Post read calculations and fixups
92
         **  Post read calculations and fixups
92
         */
93
         */
93
        if( config.datafilename[0] )
94
        if( datafilename[0] )
94
        {
95
        {
95
            strcpy( datfile, config.datafilename );
96
            strcpy( datfile, datafilename );
96
            strcat( datfile, ".dat" );
97
            strcat( datfile, ".dat" );
97
        }
98
        }
98
        config.nonequestrian_class = lookup_class( config.nonequestrian_class_abr, &config );
99
        nonequestrian_class = lookup_class( nonequestrian_class_abr );
99
    }
100
    }
100
    return result;
101
    return result;
101
}
102
}
102
 
103
 
103
/*========================================================================
104
/*========================================================================
Line 114... Line 115...
114
 *  Returns:
115
 *  Returns:
115
 *      FALSE if an error is encountered
116
 *      FALSE if an error is encountered
116
 *
117
 *
117
 *========================================================================*/
118
 *========================================================================*/
118
 
119
 
119
bool QmConfig::read_config( void )
120
bool QmConfig::read_config( QFile &configFile  )
120
{
121
{
121
    int         len;                            /* Length of data read */
122
    int         len;                            /* Length of data read */
122
    int         fsize;                          /* Length of desired data */
123
    int         fsize;                          /* Length of desired data */
123
 
124
 
124
    /*
125
    /*
125
     * Event name
126
     * Event name
126
     */
127
     */
127
qDebug( "Reading: Event Name" );
128
qDebug( "Reading: Event Name" );
128
    fsize = sizeof( config.event_name );
129
    fsize = sizeof( event_name );
129
    len = configFile.read( config.event_name, fsize );
130
    len = configFile.read( event_name, fsize );
130
    if( len != fsize )
131
    if( len != fsize )
131
        return ( FALSE );
132
        return ( FALSE );
132
 
133
 
133
    /*
134
    /*
134
     * Leg names
135
     * Leg names
135
     */
136
     */
136
qDebug( "Reading: Leg Names" );
137
qDebug( "Reading: Leg Names" );
137
    fsize = sizeof( config.leg_name );
138
    fsize = sizeof( leg_name );
138
    len = configFile.read( (char *)config.leg_name, fsize );
139
    len = configFile.read( (char *)leg_name, fsize );
139
    if( len != fsize )
140
    if( len != fsize )
140
        return ( FALSE );
141
        return ( FALSE );
141
 
142
 
142
    /*
143
    /*
143
     * Team definitions
144
     * Team definitions
144
     */
145
     */
145
qDebug( "Reading: Team Defs" );
146
qDebug( "Reading: Team Defs" );
146
    fsize = sizeof( config.t_def  );
147
    fsize = sizeof( t_def  );
147
    len = configFile.read( (char *)config.t_def, fsize );
148
    len = configFile.read( (char *)t_def, fsize );
148
    if( len != fsize )
149
    if( len != fsize )
149
        return ( FALSE );
150
        return ( FALSE );
150
 
151
 
151
    /*
152
    /*
152
     * Number of legs
153
     * Number of legs
153
     */
154
     */
154
 
155
 
155
qDebug( "Reading: Leg Nums" );
156
qDebug( "Reading: Leg Nums" );
156
    fsize = sizeof( config.num_legs  );
157
    fsize = sizeof( num_legs  );
157
    len = configFile.read( (char *)&config.num_legs, fsize );
158
    len = configFile.read( (char *)&num_legs, fsize );
158
    if( len != fsize)
159
    if( len != fsize)
159
        return ( FALSE );
160
        return ( FALSE );
160
 
161
 
161
    /*
162
    /*
162
     * Number of team splits
163
     * Number of team splits
163
     */
164
     */
164
 
165
 
165
qDebug( "Reading: Team Splits" );
166
qDebug( "Reading: Team Splits" );
166
    fsize = sizeof( config.num_teams  );
167
    fsize = sizeof( num_teams  );
167
    len = configFile.read( (char *)&config.num_teams, fsize );
168
    len = configFile.read( (char *)&num_teams, fsize );
168
    if( len != fsize )
169
    if( len != fsize )
169
        return ( FALSE );
170
        return ( FALSE );
170
 
171
 
171
    config.min_team = config.t_def[0].start;
172
    min_team = t_def[0].start;
172
    config.max_team = config.t_def[config.num_teams - 1].end;
173
    max_team = t_def[num_teams - 1].end;
173
 
174
 
174
    /*
175
    /*
175
     * Class information
176
     * Class information
176
     */
177
     */
177
qDebug( "Reading: Class Data" );
178
qDebug( "Reading: Class Data" );
178
    fsize = sizeof( config.team_class  );
179
    fsize = sizeof( team_class  );
179
    len = configFile.read( (char *)config.team_class, fsize );
180
    len = configFile.read( (char *)team_class, fsize );
180
    if( len != fsize )
181
    if( len != fsize )
181
        return ( FALSE );
182
        return ( FALSE );
182
    fsize = sizeof( config.num_class  );
183
    fsize = sizeof( num_class  );
183
    len = configFile.read( (char *)&config.num_class, fsize);
184
    len = configFile.read( (char *)&num_class, fsize);
184
    if( len != fsize )
185
    if( len != fsize )
185
        return ( FALSE );
186
        return ( FALSE );
186
 
187
 
187
    /*
188
    /*
188
     * Country list
189
     * Country list
189
     */
190
     */
190
 
191
 
191
qDebug( "Reading: Country Data, Name" );
192
qDebug( "Reading: Country Data, Name" );
192
    fsize = sizeof( config.country_name  );
193
    fsize = sizeof( country_name  );
193
    len = configFile.read( (char *)config.country_name, fsize );
194
    len = configFile.read( (char *)country_name, fsize );
194
    if( len != fsize )
195
    if( len != fsize )
195
        return ( FALSE );
196
        return ( FALSE );
196
 
197
 
197
qDebug( "Reading: Country Data, Number" );
198
qDebug( "Reading: Country Data, Number" );
198
    fsize = sizeof( config.num_countries  );
199
    fsize = sizeof( num_countries  );
199
    len = configFile.read( (char *)&config.num_countries, fsize );
200
    len = configFile.read( (char *)&num_countries, fsize );
200
    if( len != fsize )
201
    if( len != fsize )
201
        return ( FALSE );
202
        return ( FALSE );
202
 
203
 
203
    /*
204
    /*
204
     * Addendum file
205
     * Addendum file
205
     */
206
     */
206
 
207
 
207
qDebug( "Reading: Addendum File" );
208
qDebug( "Reading: Addendum File" );
208
    fsize = sizeof( config.addendum );
209
    fsize = sizeof( addendum );
209
    len = configFile.read( config.addendum, fsize );
210
    len = configFile.read( addendum, fsize );
210
    if( len != fsize )
211
    if( len != fsize )
211
        return ( configFile.atEnd() );
212
        return ( configFile.atEnd() );
212
 
213
 
213
    /*
214
    /*
214
     * Name of the data file
215
     * Name of the data file
215
     */
216
     */
216
 
217
 
217
qDebug( "Reading: Name of data file" );
218
qDebug( "Reading: Name of data file" );
218
    fsize = sizeof( config.datafilename );
219
    fsize = sizeof( datafilename );
219
    len = configFile.read( config.datafilename, fsize );
220
    len = configFile.read( datafilename, fsize );
220
    if( len != fsize )
221
    if( len != fsize )
221
        return ( configFile.atEnd() );
222
        return ( configFile.atEnd() );
222
 
223
 
223
    /*
224
    /*
224
     **  Non-equestrian configuration information
225
     **  Non-equestrian configuration information
225
     */
226
     */
226
qDebug( "Reading: NonEquest" );
227
qDebug( "Reading: NonEquest" );
227
    fsize = sizeof( config.nonequestrian_class_abr );
228
    fsize = sizeof( nonequestrian_class_abr );
228
    len = configFile.read( config.nonequestrian_class_abr, fsize );
229
    len = configFile.read( nonequestrian_class_abr, fsize );
229
    if( len != fsize )
230
    if( len != fsize )
230
        return ( configFile.atEnd() );
231
        return ( configFile.atEnd() );
231
 
232
 
232
qDebug( "Reading: NonEquest-2" );
233
qDebug( "Reading: NonEquest-2" );
233
    fsize = sizeof( config.equestrian_leg );
234
    fsize = sizeof( equestrian_leg );
234
    len = configFile.read( (char *)&config.equestrian_leg, fsize );
235
    len = configFile.read( (char *)&equestrian_leg, fsize );
235
    if( len != fsize )
236
    if( len != fsize )
236
        return ( FALSE );
237
        return ( FALSE );
237
 
238
 
238
    /*
239
    /*
239
    **  .txt file output control. Lines per page and perf-skipping
240
    **  .txt file output control. Lines per page and perf-skipping
240
    */
241
    */
241
qDebug( "Reading: Output Control" );
242
qDebug( "Reading: Output Control" );
242
    fsize = sizeof( config.lines_per_page );
243
    fsize = sizeof( lines_per_page );
243
    len = configFile.read( (char *)&config.lines_per_page, fsize );
244
    len = configFile.read( (char *)&lines_per_page, fsize );
244
    if( len != fsize )
245
    if( len != fsize )
245
        return ( configFile.atEnd() );
246
        return ( configFile.atEnd() );
246
 
247
 
247
qDebug( "Reading: Output Control-2" );
248
qDebug( "Reading: Output Control-2" );
248
    fsize = sizeof( config.perf_skip );
249
    fsize = sizeof( perf_skip );
249
    len = configFile.read( (char *)&config.perf_skip, fsize );
250
    len = configFile.read( (char *)&perf_skip, fsize );
250
    if( len != fsize )
251
    if( len != fsize )
251
        return ( FALSE );
252
        return ( FALSE );
252
 
253
 
253
qDebug( "Reading: Winners Info" );
254
qDebug( "Reading: Winners Info" );
254
    fsize = sizeof( config.class_winners );
255
    fsize = sizeof( class_winners );
255
    len = configFile.read( (char *)&config.class_winners, fsize );
256
    len = configFile.read( (char *)&class_winners, fsize );
256
    if( len != fsize )
257
    if( len != fsize )
257
        return ( FALSE );
258
        return ( FALSE );
258
 
259
 
259
qDebug( "Reading: Hall of Fame Info" );
260
qDebug( "Reading: Hall of Fame Info" );
260
    fsize = sizeof( config.hall_fame );
261
    fsize = sizeof( hall_fame );
261
    len = configFile.read( (char *)&config.hall_fame, fsize );
262
    len = configFile.read( (char *)&hall_fame, fsize );
262
    if( len != fsize )
263
    if( len != fsize )
263
        return ( FALSE );
264
        return ( FALSE );
264
 
265
 
265
qDebug( "Reading: Hall of Fame Numbers" );
266
qDebug( "Reading: Hall of Fame Numbers" );
266
    fsize = sizeof( config.hall_fame );
267
    fsize = sizeof( hall_fame );
267
    len = configFile.read( (char *)&config.num_fame, fsize );
268
    len = configFile.read( (char *)&num_fame, fsize );
268
    if( len != fsize )
269
    if( len != fsize )
269
        return ( configFile.atEnd() );
270
        return ( configFile.atEnd() );
270
 
271
 
271
 
272
 
272
    return ( TRUE );
273
    return ( TRUE );
Line 317... Line 318...
317
     **     Number fo team splits
318
     **     Number fo team splits
318
     **     Class information
319
     **     Class information
319
     **     Number of defined classes
320
     **     Number of defined classes
320
     **     Country list
321
     **     Country list
321
     **     Number of defined countries
322
     **     Number of defined countries
322
     **     Legend config.addendum file name
323
     **     Legend addendum file name
323
     **     Data file name
324
     **     Data file name
324
     */
325
     */
325
 
326
 
326
    file.write( (const char *) config.event_name, sizeof( config.event_name ) );
327
    file.write( (const char *) event_name, sizeof( event_name ) );
327
    file.write( (const char *) config.leg_name, sizeof( config.leg_name ) );
328
    file.write( (const char *) leg_name, sizeof( leg_name ) );
328
    file.write( (const char *) config.t_def, sizeof( config.t_def ) );
329
    file.write( (const char *) t_def, sizeof( t_def ) );
329
    file.write( (const char *) &config.num_legs, sizeof( config.num_legs ) );
330
    file.write( (const char *) &num_legs, sizeof( num_legs ) );
330
    file.write( (const char *) &config.num_teams, sizeof( config.num_teams ) );
331
    file.write( (const char *) &num_teams, sizeof( num_teams ) );
331
    file.write( (const char *) config.team_class, sizeof( config.team_class ) );
332
    file.write( (const char *) team_class, sizeof( team_class ) );
332
    file.write( (const char *) &config.num_class, sizeof( config.num_class ) );
333
    file.write( (const char *) &num_class, sizeof( num_class ) );
333
    file.write( (const char *) config.country_name, sizeof( config.country_name ) );
334
    file.write( (const char *) country_name, sizeof( country_name ) );
334
    file.write( (const char *) &config.num_countries, sizeof( config.num_countries ) );
335
    file.write( (const char *) &num_countries, sizeof( num_countries ) );
335
    file.write( (const char *) config.addendum, sizeof( config.addendum ) );
336
    file.write( (const char *) addendum, sizeof( addendum ) );
336
    file.write( (const char *) config.datafilename, sizeof( config.datafilename ) );
337
    file.write( (const char *) datafilename, sizeof( datafilename ) );
337
    file.write( (const char *) config.nonequestrian_class_abr, sizeof( config.nonequestrian_class_abr ) );
338
    file.write( (const char *) nonequestrian_class_abr, sizeof( nonequestrian_class_abr ) );
338
    file.write( (const char *) &config.equestrian_leg, sizeof( config.equestrian_leg ) );
339
    file.write( (const char *) &equestrian_leg, sizeof( equestrian_leg ) );
339
    file.write( (const char *) &config.lines_per_page, sizeof( config.lines_per_page ) );
340
    file.write( (const char *) &lines_per_page, sizeof( lines_per_page ) );
340
    file.write( (const char *) &config.perf_skip, sizeof( config.perf_skip ) );
341
    file.write( (const char *) &perf_skip, sizeof( perf_skip ) );
341
    file.write( (const char *) &config.class_winners, sizeof( config.class_winners ) );
342
    file.write( (const char *) &class_winners, sizeof( class_winners ) );
342
    file.write( (const char *) &config.hall_fame, sizeof( config.hall_fame ) );
343
    file.write( (const char *) &hall_fame, sizeof( hall_fame ) );
343
    file.write( (const char *) &config.num_fame, sizeof( config.num_fame ) );
344
    file.write( (const char *) &num_fame, sizeof( num_fame ) );
344
 
345
 
345
    file.close();
346
    file.close();
346
    return ( TRUE );
347
    return ( TRUE );
347
}
348
}
348
 
349
 
Line 453... Line 454...
453
 *      The integer is in the range 1 .. num_class
454
 *      The integer is in the range 1 .. num_class
454
 *      A value fo zero indicates the text was not found.
455
 *      A value fo zero indicates the text was not found.
455
 *
456
 *
456
 *========================================================================*/
457
 *========================================================================*/
457
 
458
 
458
int lookup_class( const char *text, MARA_CFG * config_ptr )
459
int QmConfig::lookup_class( const char *text )
459
{
460
{
460
    int         i;
461
    int         i;
461
 
462
 
462
    if( config_ptr == NULL )
463
//    if( config_ptr == NULL )
463
        config_ptr = &config;
464
//        config_ptr = &config;
464
 
465
 
465
    /*
466
    /*
466
     * Attempt to locate the entered class in the list of defined classes
467
     * Attempt to locate the entered class in the list of defined classes
467
     */
468
     */
468
 
469
 
469
    for( i = 0; i < config_ptr->num_class; i++ )
470
    for( i = 0; i < num_class; i++ )
470
    {
471
    {
471
        if( toupper(text[0]) == toupper(config_ptr->team_class[i].abr[0]) &&
472
        if( toupper(text[0]) == toupper(team_class[i].abr[0]) &&
472
            toupper(text[1]) == toupper(config_ptr->team_class[i].abr[1]) )
473
            toupper(text[1]) == toupper(team_class[i].abr[1]) )
473
            return ( ++i );
474
            return ( ++i );
474
    }
475
    }
475
    return ( 0 );
476
    return ( 0 );
476
}
477
}