| 172 |
- |
1 |
#include "qmconfig.h"
|
|
|
2 |
#include "mainwindow.h"
|
|
|
3 |
#include <QFileDialog>
|
|
|
4 |
#include <QObject>
|
|
|
5 |
#include <QMessageBox>
|
| 174 |
- |
6 |
#include <QFileInfo>
|
|
|
7 |
#include <QFile>
|
| 199 |
david |
8 |
#include <QCoreApplication>
|
| 172 |
- |
9 |
|
| 210 |
- |
10 |
//#define DISPLAY_STRUCTURES
|
| 208 |
- |
11 |
|
| 172 |
- |
12 |
// Global Data
|
| 176 |
- |
13 |
QmConfig config;
|
| 172 |
- |
14 |
|
| 176 |
- |
15 |
|
| 174 |
- |
16 |
/*
|
|
|
17 |
** Local definitions
|
|
|
18 |
*/
|
|
|
19 |
char datfile[20]; /* Name of the data file */
|
|
|
20 |
char filebase[20]; /* Event file name base */
|
| 198 |
- |
21 |
char filepath[300];
|
| 199 |
david |
22 |
char addendumFilepath[300];
|
| 172 |
- |
23 |
|
| 199 |
david |
24 |
|
| 176 |
- |
25 |
void QmConfig::load(const QString &cnfFile)
|
| 172 |
- |
26 |
{
|
| 208 |
- |
27 |
#ifdef DISPLAY_STRUCTURES
|
|
|
28 |
display_structures();
|
|
|
29 |
#endif
|
| 172 |
- |
30 |
fileName = cnfFile;
|
| 199 |
david |
31 |
|
| 172 |
- |
32 |
if ( !fileName.endsWith(".cnf",Qt::CaseInsensitive))
|
|
|
33 |
{
|
|
|
34 |
fileName.append(".cnf");
|
|
|
35 |
}
|
|
|
36 |
if (cnfFile.isEmpty())
|
|
|
37 |
{
|
|
|
38 |
fileName = QFileDialog::getOpenFileName(0, "Select Config File",
|
| 174 |
- |
39 |
filepath,
|
| 172 |
- |
40 |
"Data (*.cnf);;All (*.*)",
|
|
|
41 |
0,
|
|
|
42 |
|
|
|
43 |
);
|
|
|
44 |
}
|
|
|
45 |
|
|
|
46 |
// No file selected
|
|
|
47 |
// Just exit
|
|
|
48 |
if (fileName.isEmpty())
|
|
|
49 |
{
|
| 174 |
- |
50 |
qDebug("No Config file selected");
|
| 172 |
- |
51 |
exit(1);
|
|
|
52 |
}
|
|
|
53 |
|
| 174 |
- |
54 |
//
|
| 227 |
- |
55 |
// Setup file names
|
| 174 |
- |
56 |
//
|
|
|
57 |
QFileInfo info (fileName);
|
|
|
58 |
strncpy(filebase, qPrintable(info.baseName()), 8);
|
|
|
59 |
strcpy( datfile, filebase );
|
|
|
60 |
strcat( datfile, ".dat" );
|
|
|
61 |
|
|
|
62 |
strncpy(filepath, qPrintable(info.absolutePath()), sizeof(filepath)-3);
|
|
|
63 |
strcat(filepath, "/");
|
|
|
64 |
qDebug("FilePath:%s", filepath );
|
|
|
65 |
|
| 172 |
- |
66 |
if ( !open_read_config() )
|
|
|
67 |
{
|
|
|
68 |
if (QMessageBox::Cancel == QMessageBox::question ( 0,
|
|
|
69 |
"Config Load Error",
|
|
|
70 |
"Cannot load or read configuration file.\n"
|
|
|
71 |
"If you continue a new configuration will be created\n"
|
|
|
72 |
"If you cancel then the application will terminate.",
|
|
|
73 |
QMessageBox::Ok | QMessageBox::Cancel
|
|
|
74 |
) )
|
|
|
75 |
{
|
| 174 |
- |
76 |
qDebug("Cancel to bad config");
|
| 172 |
- |
77 |
exit(2);
|
|
|
78 |
}
|
|
|
79 |
}
|
|
|
80 |
}
|
|
|
81 |
|
|
|
82 |
|
|
|
83 |
bool QmConfig::open_read_config( void )
|
|
|
84 |
{
|
|
|
85 |
bool result;
|
|
|
86 |
// Open the file
|
| 176 |
- |
87 |
QFile configFile;
|
| 172 |
- |
88 |
configFile.setFileName(fileName);
|
|
|
89 |
if ( ! configFile.open(QIODevice::ReadOnly) )
|
|
|
90 |
{
|
|
|
91 |
MainWindow::showMessage("Cannot open config File");
|
|
|
92 |
return (false );
|
|
|
93 |
}
|
|
|
94 |
|
| 176 |
- |
95 |
result = read_config(configFile);
|
| 172 |
- |
96 |
configFile.close();
|
|
|
97 |
|
|
|
98 |
if ( result )
|
|
|
99 |
{
|
|
|
100 |
/*
|
| 227 |
- |
101 |
** Post read calculations and fixups
|
|
|
102 |
*/
|
| 176 |
- |
103 |
if( datafilename[0] )
|
| 172 |
- |
104 |
{
|
| 176 |
- |
105 |
strcpy( datfile, datafilename );
|
| 172 |
- |
106 |
strcat( datfile, ".dat" );
|
|
|
107 |
}
|
| 176 |
- |
108 |
nonequestrian_class = lookup_class( nonequestrian_class_abr );
|
| 227 |
- |
109 |
|
|
|
110 |
class_ne_winners_by_class = false;
|
|
|
111 |
for( int i = 0; i < MAX_CLASS; i++ )
|
|
|
112 |
{
|
|
|
113 |
if(class_ne_winners[i])
|
|
|
114 |
{
|
|
|
115 |
class_ne_winners_by_class = true;
|
|
|
116 |
break;
|
|
|
117 |
}
|
|
|
118 |
}
|
|
|
119 |
|
|
|
120 |
|
| 172 |
- |
121 |
}
|
|
|
122 |
return result;
|
|
|
123 |
}
|
|
|
124 |
|
|
|
125 |
/*========================================================================
|
|
|
126 |
*
|
|
|
127 |
* Read in the configuration file
|
|
|
128 |
*
|
|
|
129 |
* Purpose:
|
|
|
130 |
* This function is called to read in the configuration file
|
|
|
131 |
* NOTE: Must be maintained with the Writer function
|
|
|
132 |
*
|
|
|
133 |
* Parameters:
|
|
|
134 |
* fcon File number of the config file
|
|
|
135 |
*
|
|
|
136 |
* Returns:
|
|
|
137 |
* FALSE if an error is encountered
|
|
|
138 |
*
|
|
|
139 |
*========================================================================*/
|
|
|
140 |
|
| 176 |
- |
141 |
bool QmConfig::read_config( QFile &configFile )
|
| 172 |
- |
142 |
{
|
|
|
143 |
int len; /* Length of data read */
|
|
|
144 |
int fsize; /* Length of desired data */
|
|
|
145 |
|
|
|
146 |
/*
|
|
|
147 |
* Event name
|
|
|
148 |
*/
|
| 210 |
- |
149 |
//qDebug( "Reading: Event Name" );
|
| 176 |
- |
150 |
fsize = sizeof( event_name );
|
|
|
151 |
len = configFile.read( event_name, fsize );
|
| 172 |
- |
152 |
if( len != fsize )
|
|
|
153 |
return ( FALSE );
|
|
|
154 |
|
|
|
155 |
/*
|
|
|
156 |
* Leg names
|
|
|
157 |
*/
|
| 210 |
- |
158 |
//qDebug( "Reading: Leg Names" );
|
| 176 |
- |
159 |
fsize = sizeof( leg_name );
|
|
|
160 |
len = configFile.read( (char *)leg_name, fsize );
|
| 172 |
- |
161 |
if( len != fsize )
|
|
|
162 |
return ( FALSE );
|
|
|
163 |
|
|
|
164 |
/*
|
|
|
165 |
* Team definitions
|
|
|
166 |
*/
|
| 210 |
- |
167 |
//qDebug( "Reading: Team Defs" );
|
| 176 |
- |
168 |
fsize = sizeof( t_def );
|
|
|
169 |
len = configFile.read( (char *)t_def, fsize );
|
| 172 |
- |
170 |
if( len != fsize )
|
|
|
171 |
return ( FALSE );
|
|
|
172 |
|
|
|
173 |
/*
|
|
|
174 |
* Number of legs
|
|
|
175 |
*/
|
|
|
176 |
|
| 210 |
- |
177 |
//qDebug( "Reading: Leg Nums" );
|
| 176 |
- |
178 |
fsize = sizeof( num_legs );
|
|
|
179 |
len = configFile.read( (char *)&num_legs, fsize );
|
| 172 |
- |
180 |
if( len != fsize)
|
|
|
181 |
return ( FALSE );
|
|
|
182 |
|
|
|
183 |
/*
|
|
|
184 |
* Number of team splits
|
|
|
185 |
*/
|
|
|
186 |
|
| 210 |
- |
187 |
//qDebug( "Reading: Team Splits" );
|
| 176 |
- |
188 |
fsize = sizeof( num_teams );
|
|
|
189 |
len = configFile.read( (char *)&num_teams, fsize );
|
| 172 |
- |
190 |
if( len != fsize )
|
|
|
191 |
return ( FALSE );
|
|
|
192 |
|
| 176 |
- |
193 |
min_team = t_def[0].start;
|
|
|
194 |
max_team = t_def[num_teams - 1].end;
|
| 172 |
- |
195 |
|
|
|
196 |
/*
|
|
|
197 |
* Class information
|
|
|
198 |
*/
|
| 210 |
- |
199 |
//qDebug( "Reading: Class Data" );
|
| 176 |
- |
200 |
fsize = sizeof( team_class );
|
|
|
201 |
len = configFile.read( (char *)team_class, fsize );
|
| 172 |
- |
202 |
if( len != fsize )
|
|
|
203 |
return ( FALSE );
|
| 176 |
- |
204 |
fsize = sizeof( num_class );
|
|
|
205 |
len = configFile.read( (char *)&num_class, fsize);
|
| 172 |
- |
206 |
if( len != fsize )
|
|
|
207 |
return ( FALSE );
|
|
|
208 |
|
|
|
209 |
/*
|
|
|
210 |
* Country list
|
|
|
211 |
*/
|
|
|
212 |
|
| 210 |
- |
213 |
//qDebug( "Reading: Country Data, Name" );
|
| 176 |
- |
214 |
fsize = sizeof( country_name );
|
|
|
215 |
len = configFile.read( (char *)country_name, fsize );
|
| 172 |
- |
216 |
if( len != fsize )
|
|
|
217 |
return ( FALSE );
|
|
|
218 |
|
| 210 |
- |
219 |
//qDebug( "Reading: Country Data, Number" );
|
| 176 |
- |
220 |
fsize = sizeof( num_countries );
|
|
|
221 |
len = configFile.read( (char *)&num_countries, fsize );
|
| 172 |
- |
222 |
if( len != fsize )
|
|
|
223 |
return ( FALSE );
|
|
|
224 |
|
|
|
225 |
/*
|
|
|
226 |
* Addendum file
|
|
|
227 |
*/
|
|
|
228 |
|
| 210 |
- |
229 |
//qDebug( "Reading: Addendum File" );
|
| 176 |
- |
230 |
fsize = sizeof( addendum );
|
|
|
231 |
len = configFile.read( addendum, fsize );
|
| 172 |
- |
232 |
if( len != fsize )
|
|
|
233 |
return ( configFile.atEnd() );
|
|
|
234 |
|
|
|
235 |
/*
|
|
|
236 |
* Name of the data file
|
|
|
237 |
*/
|
|
|
238 |
|
| 210 |
- |
239 |
//qDebug( "Reading: Name of data file" );
|
| 176 |
- |
240 |
fsize = sizeof( datafilename );
|
|
|
241 |
len = configFile.read( datafilename, fsize );
|
| 172 |
- |
242 |
if( len != fsize )
|
|
|
243 |
return ( configFile.atEnd() );
|
|
|
244 |
|
|
|
245 |
/*
|
|
|
246 |
** Non-equestrian configuration information
|
|
|
247 |
*/
|
| 210 |
- |
248 |
//qDebug( "Reading: NonEquest" );
|
| 176 |
- |
249 |
fsize = sizeof( nonequestrian_class_abr );
|
|
|
250 |
len = configFile.read( nonequestrian_class_abr, fsize );
|
| 172 |
- |
251 |
if( len != fsize )
|
|
|
252 |
return ( configFile.atEnd() );
|
|
|
253 |
|
| 210 |
- |
254 |
//qDebug( "Reading: NonEquest-2" );
|
| 176 |
- |
255 |
fsize = sizeof( equestrian_leg );
|
|
|
256 |
len = configFile.read( (char *)&equestrian_leg, fsize );
|
| 172 |
- |
257 |
if( len != fsize )
|
|
|
258 |
return ( FALSE );
|
|
|
259 |
|
|
|
260 |
/*
|
|
|
261 |
** .txt file output control. Lines per page and perf-skipping
|
|
|
262 |
*/
|
| 210 |
- |
263 |
//qDebug( "Reading: Output Control" );
|
| 176 |
- |
264 |
fsize = sizeof( lines_per_page );
|
|
|
265 |
len = configFile.read( (char *)&lines_per_page, fsize );
|
| 172 |
- |
266 |
if( len != fsize )
|
|
|
267 |
return ( configFile.atEnd() );
|
|
|
268 |
|
| 210 |
- |
269 |
//qDebug( "Reading: Output Control-2" );
|
| 176 |
- |
270 |
fsize = sizeof( perf_skip );
|
|
|
271 |
len = configFile.read( (char *)&perf_skip, fsize );
|
| 172 |
- |
272 |
if( len != fsize )
|
|
|
273 |
return ( FALSE );
|
|
|
274 |
|
| 210 |
- |
275 |
//qDebug( "Reading: Winners Info" );
|
| 176 |
- |
276 |
fsize = sizeof( class_winners );
|
|
|
277 |
len = configFile.read( (char *)&class_winners, fsize );
|
| 172 |
- |
278 |
if( len != fsize )
|
|
|
279 |
return ( FALSE );
|
|
|
280 |
|
| 210 |
- |
281 |
//qDebug( "Reading: Hall of Fame Info" );
|
| 176 |
- |
282 |
fsize = sizeof( hall_fame );
|
|
|
283 |
len = configFile.read( (char *)&hall_fame, fsize );
|
| 172 |
- |
284 |
if( len != fsize )
|
|
|
285 |
return ( FALSE );
|
|
|
286 |
|
| 210 |
- |
287 |
//qDebug( "Reading: Hall of Fame Numbers" );
|
| 208 |
- |
288 |
fsize = sizeof( num_fame );
|
| 176 |
- |
289 |
len = configFile.read( (char *)&num_fame, fsize );
|
| 172 |
- |
290 |
if( len != fsize )
|
|
|
291 |
return ( configFile.atEnd() );
|
|
|
292 |
|
| 227 |
- |
293 |
//qDebug( "Reading: NE Winners Info" );
|
|
|
294 |
fsize = sizeof( class_ne_winners );
|
|
|
295 |
len = configFile.read( (char *)&class_ne_winners, fsize );
|
|
|
296 |
if( len != fsize )
|
|
|
297 |
return ( configFile.atEnd() );
|
| 172 |
- |
298 |
|
|
|
299 |
return ( TRUE );
|
|
|
300 |
}
|
|
|
301 |
|
| 199 |
david |
302 |
/*----------------------------------------------------------------------------
|
|
|
303 |
** FUNCTION : getAddendemFile
|
|
|
304 |
**
|
|
|
305 |
** DESCRIPTION : Returns the full path the the addemdum file
|
|
|
306 |
** The functionwill lookfor the file in a number of
|
|
|
307 |
** locations
|
|
|
308 |
**
|
|
|
309 |
**
|
|
|
310 |
** INPUTS : name - Name of the addenum file
|
|
|
311 |
** create - True. Allow file to be created
|
|
|
312 |
**
|
|
|
313 |
** RETURNS : NULL - No addendum name, or file not found
|
|
|
314 |
** If create' is true then the preferred
|
|
|
315 |
** location will be returned.
|
|
|
316 |
**
|
|
|
317 |
----------------------------------------------------------------------------*/
|
| 172 |
- |
318 |
|
| 199 |
david |
319 |
|
|
|
320 |
const char *QmConfig::getAddendemFile(const QString &name, bool create )
|
|
|
321 |
{
|
|
|
322 |
if (name.isEmpty())
|
|
|
323 |
return NULL;
|
|
|
324 |
|
|
|
325 |
QFile file;
|
|
|
326 |
QString addendumFileName;
|
|
|
327 |
addendumFileName = filepath;
|
|
|
328 |
addendumFileName.append(name);
|
|
|
329 |
QString addendumFileNamePreferred(addendumFileName);
|
|
|
330 |
file.setFileName(addendumFileName);
|
| 200 |
david |
331 |
//qDebug("Try:%s", qPrintable(addendumFileName));
|
| 199 |
david |
332 |
if ( !file.exists())
|
|
|
333 |
{
|
|
|
334 |
addendumFileName = QCoreApplication::applicationDirPath ();
|
|
|
335 |
addendumFileName.append("/");
|
|
|
336 |
addendumFileName.append(name);
|
|
|
337 |
file.setFileName(addendumFileName);
|
| 200 |
david |
338 |
//qDebug("Try:%s", qPrintable(addendumFileName));
|
| 199 |
david |
339 |
if ( !file.exists())
|
|
|
340 |
{
|
|
|
341 |
addendumFileName = QDir::currentPath ();
|
|
|
342 |
addendumFileName.append("/");
|
|
|
343 |
addendumFileName.append(name);
|
|
|
344 |
file.setFileName(addendumFileName);
|
| 200 |
david |
345 |
//qDebug("Try:%s", qPrintable(addendumFileName));
|
| 199 |
david |
346 |
if ( !file.exists())
|
|
|
347 |
{
|
| 200 |
david |
348 |
//qDebug("Addeddum File not found");
|
| 199 |
david |
349 |
if (create)
|
|
|
350 |
{
|
|
|
351 |
addendumFileName = addendumFileNamePreferred;
|
|
|
352 |
}
|
|
|
353 |
else
|
|
|
354 |
{
|
|
|
355 |
return NULL;
|
|
|
356 |
}
|
|
|
357 |
}
|
|
|
358 |
}
|
|
|
359 |
}
|
|
|
360 |
strncpy(addendumFilepath, qPrintable(addendumFileName), sizeof(addendumFilepath));
|
|
|
361 |
return addendumFilepath;
|
|
|
362 |
}
|
|
|
363 |
|
|
|
364 |
|
| 172 |
- |
365 |
/*========================================================================
|
|
|
366 |
*
|
|
|
367 |
* Write out the configuration file
|
|
|
368 |
*
|
|
|
369 |
* Purpose:
|
|
|
370 |
* This function is called to write the configuration file
|
|
|
371 |
* NOTE: Must be maintained with the Reader function
|
|
|
372 |
*
|
|
|
373 |
* Parameters:
|
|
|
374 |
* None
|
|
|
375 |
*
|
|
|
376 |
* Returns:
|
|
|
377 |
* FALSE : Error encountered
|
|
|
378 |
*
|
|
|
379 |
*========================================================================*/
|
|
|
380 |
|
|
|
381 |
bool QmConfig::write_config( void )
|
|
|
382 |
{
|
| 174 |
- |
383 |
if (fileName.isEmpty())
|
|
|
384 |
{
|
|
|
385 |
qDebug("No Config file selected");
|
|
|
386 |
return(false);
|
|
|
387 |
}
|
| 172 |
- |
388 |
/*
|
|
|
389 |
** Open as a binary file
|
|
|
390 |
*/
|
| 174 |
- |
391 |
QFile file;
|
|
|
392 |
file.setFileName(fileName);
|
| 172 |
- |
393 |
if ( ! file.open(QIODevice::WriteOnly | QIODevice::Truncate) )
|
|
|
394 |
{
|
| 174 |
- |
395 |
qDebug("File error: %s", qPrintable(file.errorString()));
|
| 218 |
david |
396 |
MainWindow::showMessage("Cannot write config file");
|
| 172 |
- |
397 |
return (false);
|
|
|
398 |
}
|
|
|
399 |
|
|
|
400 |
/*
|
|
|
401 |
** Write out multiple structures
|
|
|
402 |
** Event name
|
|
|
403 |
** Leg names
|
|
|
404 |
** Team definitions
|
|
|
405 |
** Number of legs
|
|
|
406 |
** Number fo team splits
|
|
|
407 |
** Class information
|
|
|
408 |
** Number of defined classes
|
|
|
409 |
** Country list
|
|
|
410 |
** Number of defined countries
|
| 176 |
- |
411 |
** Legend addendum file name
|
| 172 |
- |
412 |
** Data file name
|
|
|
413 |
*/
|
|
|
414 |
|
| 176 |
- |
415 |
file.write( (const char *) event_name, sizeof( event_name ) );
|
|
|
416 |
file.write( (const char *) leg_name, sizeof( leg_name ) );
|
|
|
417 |
file.write( (const char *) t_def, sizeof( t_def ) );
|
|
|
418 |
file.write( (const char *) &num_legs, sizeof( num_legs ) );
|
|
|
419 |
file.write( (const char *) &num_teams, sizeof( num_teams ) );
|
|
|
420 |
file.write( (const char *) team_class, sizeof( team_class ) );
|
|
|
421 |
file.write( (const char *) &num_class, sizeof( num_class ) );
|
|
|
422 |
file.write( (const char *) country_name, sizeof( country_name ) );
|
|
|
423 |
file.write( (const char *) &num_countries, sizeof( num_countries ) );
|
|
|
424 |
file.write( (const char *) addendum, sizeof( addendum ) );
|
|
|
425 |
file.write( (const char *) datafilename, sizeof( datafilename ) );
|
|
|
426 |
file.write( (const char *) nonequestrian_class_abr, sizeof( nonequestrian_class_abr ) );
|
|
|
427 |
file.write( (const char *) &equestrian_leg, sizeof( equestrian_leg ) );
|
|
|
428 |
file.write( (const char *) &lines_per_page, sizeof( lines_per_page ) );
|
|
|
429 |
file.write( (const char *) &perf_skip, sizeof( perf_skip ) );
|
|
|
430 |
file.write( (const char *) &class_winners, sizeof( class_winners ) );
|
|
|
431 |
file.write( (const char *) &hall_fame, sizeof( hall_fame ) );
|
|
|
432 |
file.write( (const char *) &num_fame, sizeof( num_fame ) );
|
| 227 |
- |
433 |
file.write( (const char *) &class_ne_winners, sizeof( class_ne_winners ) );
|
| 172 |
- |
434 |
|
|
|
435 |
file.close();
|
|
|
436 |
return ( TRUE );
|
|
|
437 |
}
|
| 174 |
- |
438 |
|
|
|
439 |
/*========================================================================
|
|
|
440 |
*
|
|
|
441 |
* Qsort callback: Sort by team
|
|
|
442 |
*
|
|
|
443 |
* Purpose:
|
|
|
444 |
* Function used by the team definition sort operation
|
|
|
445 |
* It will compare two entries of the team def structure and return an
|
|
|
446 |
* integer for gt eq lt conditions.
|
|
|
447 |
* Note : If the start is 0 the team entry does exist and is placed at the
|
|
|
448 |
* end of the sorted list.
|
|
|
449 |
*
|
|
|
450 |
* Parameters:
|
|
|
451 |
* a comparision entry
|
|
|
452 |
* b comparision entry
|
|
|
453 |
*
|
|
|
454 |
* Returns:
|
|
|
455 |
* gt, eq, lt as required
|
|
|
456 |
*
|
|
|
457 |
*========================================================================*/
|
|
|
458 |
|
|
|
459 |
int f_comp_int( const void *aa, const void *bb )
|
|
|
460 |
{
|
|
|
461 |
const ty_t_def *a = (ty_t_def *)aa;
|
|
|
462 |
const ty_t_def *b = (ty_t_def *)bb;
|
|
|
463 |
|
|
|
464 |
if( a->start == 0 )
|
|
|
465 |
return ( 1 );
|
|
|
466 |
else if( b->start == 0 )
|
|
|
467 |
return ( -1 );
|
|
|
468 |
else
|
|
|
469 |
return ( a->start - b->start );
|
|
|
470 |
}
|
|
|
471 |
|
|
|
472 |
/*========================================================================
|
|
|
473 |
*
|
|
|
474 |
* Compact a string
|
|
|
475 |
*
|
|
|
476 |
* Purpose:
|
|
|
477 |
* This function is called remove leading and trailing spaces from
|
|
|
478 |
* a string. Treats other non-printing characters as leading
|
|
|
479 |
* spaces. This solves a problem when importing data from a
|
|
|
480 |
* Microsoft CSV file with empty fields.
|
|
|
481 |
*
|
|
|
482 |
* Parameters:
|
|
|
483 |
* str Address of the string to compact
|
|
|
484 |
*
|
|
|
485 |
* Returns:
|
|
|
486 |
* Nothing
|
|
|
487 |
*
|
|
|
488 |
*========================================================================*/
|
|
|
489 |
|
|
|
490 |
void compact( char *str )
|
|
|
491 |
{
|
|
|
492 |
char *ptr;
|
|
|
493 |
|
|
|
494 |
ptr = str;
|
|
|
495 |
while( *str && ( isspace( *str ) || !isprint( *str ) ) )
|
|
|
496 |
str++;
|
|
|
497 |
strcpy( ptr, str );
|
|
|
498 |
}
|
|
|
499 |
|
|
|
500 |
/*========================================================================
|
|
|
501 |
*
|
|
|
502 |
* Validate a team number
|
|
|
503 |
*
|
|
|
504 |
* Purpose:
|
|
|
505 |
* This function is called to validate a team number
|
|
|
506 |
*
|
|
|
507 |
* Parameters:
|
|
|
508 |
* x Number to validate
|
|
|
509 |
*
|
|
|
510 |
* Returns:
|
|
|
511 |
* TRUE : Valid
|
|
|
512 |
* FALSE : Not valid
|
|
|
513 |
*
|
|
|
514 |
*========================================================================*/
|
|
|
515 |
|
|
|
516 |
bool valid_field( int x )
|
|
|
517 |
{
|
|
|
518 |
int i;
|
|
|
519 |
|
|
|
520 |
for( i = 0; i < config.num_teams; i++ )
|
|
|
521 |
{
|
|
|
522 |
if( x <= config.t_def[i].end && x >= config.t_def[i].start )
|
|
|
523 |
return ( TRUE );
|
|
|
524 |
if( x < config.t_def[i].start )
|
|
|
525 |
break; /* Because the list is sorted */
|
|
|
526 |
}
|
|
|
527 |
return ( FALSE );
|
|
|
528 |
}
|
|
|
529 |
|
|
|
530 |
/*========================================================================
|
|
|
531 |
*
|
|
|
532 |
* Get a class descriptor from existing text
|
|
|
533 |
*
|
|
|
534 |
* Purpose:
|
|
|
535 |
* This function is called to Get a class descriptor
|
|
|
536 |
*
|
|
|
537 |
* Parameters:
|
|
|
538 |
* text - User text to examine
|
|
|
539 |
* config - configuration dtaa to use
|
|
|
540 |
*
|
|
|
541 |
* Returns:
|
|
|
542 |
* An integer which is the index into the config.team_class array
|
|
|
543 |
* The integer is in the range 1 .. num_class
|
|
|
544 |
* A value fo zero indicates the text was not found.
|
|
|
545 |
*
|
|
|
546 |
*========================================================================*/
|
|
|
547 |
|
| 176 |
- |
548 |
int QmConfig::lookup_class( const char *text )
|
| 174 |
- |
549 |
{
|
|
|
550 |
int i;
|
|
|
551 |
|
| 176 |
- |
552 |
// if( config_ptr == NULL )
|
|
|
553 |
// config_ptr = &config;
|
| 174 |
- |
554 |
|
|
|
555 |
/*
|
|
|
556 |
* Attempt to locate the entered class in the list of defined classes
|
|
|
557 |
*/
|
|
|
558 |
|
| 176 |
- |
559 |
for( i = 0; i < num_class; i++ )
|
| 174 |
- |
560 |
{
|
| 176 |
- |
561 |
if( toupper(text[0]) == toupper(team_class[i].abr[0]) &&
|
|
|
562 |
toupper(text[1]) == toupper(team_class[i].abr[1]) )
|
| 174 |
- |
563 |
return ( ++i );
|
|
|
564 |
}
|
|
|
565 |
return ( 0 );
|
|
|
566 |
}
|
| 177 |
- |
567 |
|
|
|
568 |
#ifdef DISPLAY_STRUCTURES
|
|
|
569 |
/*============================================================================
|
|
|
570 |
**
|
|
|
571 |
** Display structure information
|
|
|
572 |
**
|
|
|
573 |
** Purpose: Display internal structure information
|
|
|
574 |
**
|
|
|
575 |
** Parameters: Nothing
|
|
|
576 |
**
|
|
|
577 |
** Returns: Nothing directly
|
|
|
578 |
**
|
|
|
579 |
**===========================================================================*/
|
|
|
580 |
|
|
|
581 |
/*
|
|
|
582 |
** esize - A macro to return the size of a structure element
|
|
|
583 |
** element - print element information
|
|
|
584 |
*/
|
|
|
585 |
#define esize( st, el) ( sizeof(((st *)0)->el))
|
|
|
586 |
#define element( st, el) \
|
| 208 |
- |
587 |
printf( "Offset of %-15s :%4d, Size:%d", #el, offsetof( st, el), esize(st, el) );
|
| 209 |
- |
588 |
#define element2( st, el) \
|
|
|
589 |
printf( "Size of %-15s :%4d", #el, esize(st, el) );
|
| 177 |
- |
590 |
|
|
|
591 |
void display_structures(void)
|
|
|
592 |
{
|
| 208 |
- |
593 |
printf( "Structure: leg_type" );
|
| 177 |
- |
594 |
element( leg_type, start );
|
|
|
595 |
element( leg_type, end );
|
|
|
596 |
element( leg_type, elapsed );
|
|
|
597 |
element( leg_type, l_place );
|
|
|
598 |
element( leg_type, le_place );
|
|
|
599 |
element( leg_type, lc_place );
|
|
|
600 |
element( leg_type, lec_place);
|
|
|
601 |
element( leg_type, manual );
|
| 208 |
- |
602 |
printf( "Sizeof %-18s :%4d", "leg_type", sizeof(leg_type) );
|
| 177 |
- |
603 |
|
|
|
604 |
|
| 208 |
- |
605 |
printf( "" );
|
|
|
606 |
printf( "Structure: team_type" );
|
| 177 |
- |
607 |
element( team_type, numb );
|
|
|
608 |
element( team_type, name );
|
|
|
609 |
element( team_type, leg );
|
|
|
610 |
element( team_type, members);
|
| 208 |
- |
611 |
element( team_type, teamclass );
|
| 177 |
- |
612 |
element( team_type, country);
|
|
|
613 |
element( team_type, flags );
|
| 208 |
- |
614 |
printf( "Sizeof %-18s :%4d", "team_type", sizeof(team_type) );
|
| 177 |
- |
615 |
|
| 209 |
- |
616 |
#if 1
|
| 208 |
- |
617 |
printf( "" );
|
|
|
618 |
printf( "Structure: MARA_CFG" );
|
| 209 |
- |
619 |
element2( QmConfig, event_name );
|
|
|
620 |
element2( QmConfig, leg_name );
|
|
|
621 |
element2( QmConfig, t_def );
|
|
|
622 |
element2( QmConfig, num_legs );
|
|
|
623 |
element2( QmConfig, num_teams );
|
|
|
624 |
element2( QmConfig, max_team );
|
|
|
625 |
element2( QmConfig, min_team );
|
|
|
626 |
element2( QmConfig, team_class );
|
|
|
627 |
element2( QmConfig, num_class );
|
|
|
628 |
element2( QmConfig, country_name );
|
|
|
629 |
element2( QmConfig, num_countries );
|
|
|
630 |
element2( QmConfig, addendum );
|
|
|
631 |
element2( QmConfig, datafilename );
|
|
|
632 |
printf( "Sizeof %-18s :%4d", "QmConfig", sizeof(QmConfig) );
|
| 208 |
- |
633 |
#endif
|
| 177 |
- |
634 |
}
|
|
|
635 |
#endif
|