| 91 |
- |
1 |
/*************************************************************************
|
|
|
2 |
* Copyright (C) 1995 Embedded Solutions
|
|
|
3 |
* All rights reserved
|
|
|
4 |
*
|
|
|
5 |
* file: src\teamupd.c
|
|
|
6 |
*
|
|
|
7 |
* purpose: Team data edit and display
|
|
|
8 |
* This module contains all the functions required to define and
|
|
|
9 |
* alter the team definitions
|
|
|
10 |
*
|
|
|
11 |
* functions
|
|
|
12 |
* team_update - Update team data on the screen
|
|
|
13 |
* team_display - Display team data on the screen
|
|
|
14 |
* leg_mods - Modify team leg times
|
|
|
15 |
* d_display - Display all team information
|
|
|
16 |
* d_leg - Display / Update leg time information
|
|
|
17 |
* d_field - Display / Update field on the screen
|
|
|
18 |
* g_tnum - Get a team number from the operator
|
|
|
19 |
* g_record - Read a team record from disk
|
|
|
20 |
* clr_team - Clear team data from file
|
|
|
21 |
* put_team_record - Save team record to disk
|
|
|
22 |
* init_team_data - Initialize the team data file
|
|
|
23 |
* fix_team_data - Close team data file
|
|
|
24 |
*
|
|
|
25 |
* programmer: David Purdie
|
|
|
26 |
*
|
|
|
27 |
* revision date by reason
|
|
|
28 |
* 00.0 27/01/95 DDP Tidies up the program and formatted the file
|
|
|
29 |
*
|
|
|
30 |
**************************************************************************/
|
|
|
31 |
|
|
|
32 |
#ifndef HI_TECH_C
|
|
|
33 |
#include <fcntl.h>
|
|
|
34 |
/*#include <memory.h> */
|
|
|
35 |
#endif
|
|
|
36 |
|
|
|
37 |
#include "consts.h"
|
|
|
38 |
#include "structs.h"
|
|
|
39 |
#include "proto.h"
|
| 170 |
- |
40 |
#include "mainwindow.h"
|
|
|
41 |
|
|
|
42 |
//int team; /* Current team number */
|
|
|
43 |
//team_type team_buf; /* Holds team data currently under display */
|
| 91 |
- |
44 |
int team_fd; /* Team data file descriptor */
|
| 170 |
- |
45 |
//int leg = 0; /* Leg under investigation */
|
| 91 |
- |
46 |
|
|
|
47 |
/*========================================================================
|
|
|
48 |
*
|
|
|
49 |
* Update team data on the screen
|
|
|
50 |
*
|
|
|
51 |
* Purpose:
|
|
|
52 |
* This function is called to update team data on the screen
|
|
|
53 |
* This function will prompt the operator to select a team number
|
|
|
54 |
* If the team is defined then the data will be displayed on the screen
|
|
|
55 |
*
|
|
|
56 |
* Parameters:
|
|
|
57 |
* None
|
|
|
58 |
*
|
|
|
59 |
* Returns:
|
|
|
60 |
* TRUE - Change made
|
|
|
61 |
*
|
|
|
62 |
*========================================================================*/
|
|
|
63 |
|
| 158 |
david |
64 |
//void team_update(void)
|
|
|
65 |
//{
|
|
|
66 |
// if( !g_tnum( 0, n_lines - 2, "Enter team number" ) )
|
|
|
67 |
// return; /* Exit operation */
|
| 91 |
- |
68 |
|
| 158 |
david |
69 |
// /*
|
|
|
70 |
// ** Fetch the team record into memory
|
|
|
71 |
// ** If the record does not exist a record with an invalid flag
|
|
|
72 |
// ** will be returned
|
|
|
73 |
// */
|
| 91 |
- |
74 |
|
| 158 |
david |
75 |
// do
|
|
|
76 |
// {
|
|
|
77 |
// clearscreen();
|
|
|
78 |
// g_record( team, &team_buf );
|
|
|
79 |
// d_display( M_TEAM );
|
|
|
80 |
// put_team_record( team, &team_buf );
|
| 91 |
- |
81 |
|
| 158 |
david |
82 |
// } while( g_tnum( 0, n_lines - 2, "Enter next team or RETURN to exit" ) );
|
|
|
83 |
//}
|
| 91 |
- |
84 |
|
|
|
85 |
/*=======================================================================
|
|
|
86 |
*
|
|
|
87 |
* Display team data on the screen
|
|
|
88 |
*
|
|
|
89 |
* Purpose:
|
|
|
90 |
* This function is called to Display team data on the screen
|
|
|
91 |
* This function will prompt the operator to select a team number
|
|
|
92 |
* If the team is defined then the data will be displayed on the screen
|
|
|
93 |
*
|
|
|
94 |
* Parameters:
|
|
|
95 |
* None
|
|
|
96 |
*
|
|
|
97 |
* Returns:
|
|
|
98 |
* TRUE - Change made
|
|
|
99 |
*
|
|
|
100 |
*========================================================================*/
|
|
|
101 |
|
| 158 |
david |
102 |
//void team_display(void)
|
|
|
103 |
//{
|
|
|
104 |
// if( !g_tnum( 0, n_lines - 2, "Enter team number" ) )
|
|
|
105 |
// return; /* Exit operation */
|
| 91 |
- |
106 |
|
| 158 |
david |
107 |
// /*
|
|
|
108 |
// * Fetch the team record into memory
|
|
|
109 |
// * If the record does not exist a record with an invalid flag
|
|
|
110 |
// * will be returned
|
|
|
111 |
// */
|
| 91 |
- |
112 |
|
| 158 |
david |
113 |
// do
|
|
|
114 |
// {
|
|
|
115 |
// clearscreen();
|
|
|
116 |
// if( g_record( team, &team_buf ) )
|
|
|
117 |
// d_display( M_DISPLAY );
|
|
|
118 |
// else
|
|
|
119 |
// {
|
|
|
120 |
// cur( 0, n_lines - 1 );
|
|
|
121 |
// printf( "Team %-1d has not yet been entered", team );
|
|
|
122 |
// beep();
|
|
|
123 |
// }
|
|
|
124 |
// } while( g_tnum( 0, n_lines - 2, "Enter next team or RETURN to exit" ) );
|
|
|
125 |
//}
|
| 91 |
- |
126 |
|
|
|
127 |
/*========================================================================
|
|
|
128 |
*
|
|
|
129 |
* Modify team leg times
|
|
|
130 |
*
|
|
|
131 |
* Purpose:
|
|
|
132 |
* This function is called to modify team leg times
|
|
|
133 |
* This function will prompt the operator to select a team number
|
|
|
134 |
* If the team is defined then the data will be displayed on the screen
|
|
|
135 |
*
|
|
|
136 |
* Parameters:
|
|
|
137 |
* None
|
|
|
138 |
*
|
|
|
139 |
* Returns:
|
|
|
140 |
* TRUE - Change made
|
|
|
141 |
*
|
|
|
142 |
*========================================================================*/
|
| 158 |
david |
143 |
//void leg_mods(void)
|
|
|
144 |
//{
|
|
|
145 |
// if( !g_tnum( 0, n_lines - 2, "Enter team number" ) )
|
|
|
146 |
// return; /* Exit operation */
|
| 91 |
- |
147 |
|
| 158 |
david |
148 |
// /*
|
|
|
149 |
// ** Fetch the team record into memory
|
|
|
150 |
// ** If the record does not exist a record with an invalid flag
|
|
|
151 |
// ** will be returned
|
|
|
152 |
// */
|
| 91 |
- |
153 |
|
| 158 |
david |
154 |
// do
|
|
|
155 |
// {
|
|
|
156 |
// clearscreen();
|
|
|
157 |
// if( g_record( team, &team_buf ) )
|
|
|
158 |
// {
|
|
|
159 |
// set_times( &team_buf );
|
|
|
160 |
// d_display( M_LEGS );
|
|
|
161 |
// put_team_record( team, &team_buf );
|
|
|
162 |
// }
|
|
|
163 |
// else
|
|
|
164 |
// {
|
|
|
165 |
// cur( 0, n_lines - 1 );
|
|
|
166 |
// printf( "Team %-1d has not yet been entered", team );
|
|
|
167 |
// beep();
|
|
|
168 |
// }
|
|
|
169 |
// } while( g_tnum( 0, n_lines - 2, "Enter next team or RETURN to exit" ) );
|
| 91 |
- |
170 |
|
| 158 |
david |
171 |
//}
|
| 91 |
- |
172 |
|
|
|
173 |
/*========================================================================
|
|
|
174 |
*
|
|
|
175 |
* Display all team information
|
|
|
176 |
*
|
|
|
177 |
* Purpose:
|
|
|
178 |
* This function is called to display all the team information
|
|
|
179 |
*
|
|
|
180 |
* Parameters:
|
|
|
181 |
* operation Operation to perform
|
|
|
182 |
*
|
|
|
183 |
* Returns:
|
|
|
184 |
* Nothing
|
|
|
185 |
*
|
|
|
186 |
*========================================================================*/
|
| 158 |
david |
187 |
//void d_display( int operation )
|
|
|
188 |
//{
|
|
|
189 |
// int valid = team_buf.flags.valid;
|
|
|
190 |
// int opr;
|
|
|
191 |
// int i, j;
|
|
|
192 |
// int age_sum;
|
| 91 |
- |
193 |
|
| 158 |
david |
194 |
// /*
|
|
|
195 |
// ** Refresh the entire display (using a recursive call)
|
|
|
196 |
// */
|
|
|
197 |
// if( operation != M_DISPLAY )
|
|
|
198 |
// d_display( M_DISPLAY );
|
| 91 |
- |
199 |
|
|
|
200 |
|
| 158 |
david |
201 |
// /*
|
|
|
202 |
// ** Display the team number
|
|
|
203 |
// ** This cannot be edited.
|
|
|
204 |
// */
|
|
|
205 |
// d_field( 0, 0, "Team number : ", D_NUMBER, 6, &team_buf.numb, TRUE,
|
|
|
206 |
// M_DISPLAY );
|
| 91 |
- |
207 |
|
| 158 |
david |
208 |
// /*
|
|
|
209 |
// ** Determine the type of operation required
|
|
|
210 |
// ** Update or Display
|
|
|
211 |
// */
|
|
|
212 |
// opr = ( operation & M_TEAM ) ? M_UPDATE : M_DISPLAY;
|
| 91 |
- |
213 |
|
| 158 |
david |
214 |
// /*
|
|
|
215 |
// ** Display / Update the team name
|
|
|
216 |
// */
|
|
|
217 |
// do
|
|
|
218 |
// {
|
|
|
219 |
// d_field( 20, 0, "Team name : ", D_STRING, MAX_TM_NAME, team_buf.name,
|
|
|
220 |
// valid, opr );
|
|
|
221 |
// if( abort_flag )
|
|
|
222 |
// return;
|
|
|
223 |
// } while( ( opr == M_UPDATE ) && ( !strlen( team_buf.name ) ) );
|
| 91 |
- |
224 |
|
| 158 |
david |
225 |
// /*
|
|
|
226 |
// ** Display / Update the class
|
|
|
227 |
// */
|
|
|
228 |
// do
|
|
|
229 |
// {
|
|
|
230 |
// d_field( 0, 1, "Class : ", D_CLASS, 1, &team_buf.teamclass, valid, opr );
|
|
|
231 |
// if( abort_flag )
|
|
|
232 |
// return;
|
|
|
233 |
// } while( ( opr == M_UPDATE ) && !team_buf.teamclass );
|
| 91 |
- |
234 |
|
| 158 |
david |
235 |
// /*
|
|
|
236 |
// ** The record is now active
|
|
|
237 |
// ** It may not be usefull, but it has the start of a valid recird
|
|
|
238 |
// */
|
|
|
239 |
// if( opr == M_UPDATE )
|
|
|
240 |
// team_buf.flags.valid = TRUE;
|
| 91 |
- |
241 |
|
| 158 |
david |
242 |
// /*
|
|
|
243 |
// ** Display / Update the country name
|
|
|
244 |
// */
|
|
|
245 |
// d_field( 30, 1, "Country :", D_COUNTRY, 4, &team_buf.country, valid,
|
|
|
246 |
// opr );
|
|
|
247 |
// if( abort_flag )
|
|
|
248 |
// return;
|
| 91 |
- |
249 |
|
| 158 |
david |
250 |
// /*
|
|
|
251 |
// ** Display / Update the name and sex of each team member
|
|
|
252 |
// */
|
|
|
253 |
// age_sum = 0;
|
|
|
254 |
// opr = ( operation & M_TEAM ) ? M_UPDATE : M_DISPLAY;
|
|
|
255 |
// for( i = 0; i < MAX_MEMB; i++ )
|
|
|
256 |
// {
|
|
|
257 |
// d_field( 0, 3 + i, "Name : ", D_STRING, MAX_PERSON_NAME,
|
|
|
258 |
// team_buf.members[i].name, valid, opr );
|
|
|
259 |
// if( abort_flag )
|
|
|
260 |
// return;
|
| 91 |
- |
261 |
|
| 158 |
david |
262 |
// d_field( MAX_PERSON_NAME + 10, 3 + i, "Sex : ", D_SEX, 0,
|
|
|
263 |
// &team_buf.members[i].sex, valid, opr );
|
|
|
264 |
// if( abort_flag )
|
|
|
265 |
// return;
|
| 91 |
- |
266 |
|
| 158 |
david |
267 |
// d_field( MAX_PERSON_NAME + 25, 3 + i, "Age : ", D_AGE, 3,
|
|
|
268 |
// &team_buf.members[i].age, valid, opr );
|
|
|
269 |
// if( abort_flag )
|
|
|
270 |
// return;
|
| 91 |
- |
271 |
|
| 158 |
david |
272 |
// /*
|
|
|
273 |
// ** Sum ages
|
|
|
274 |
// ** -1 indicates invalid age
|
|
|
275 |
// */
|
|
|
276 |
// if ( age_sum >= 0 )
|
|
|
277 |
// {
|
|
|
278 |
// ushort age = team_buf.members[i].age;
|
|
|
279 |
// if ( age > 0 && age < 255 )
|
|
|
280 |
// {
|
|
|
281 |
// age_sum += age;
|
|
|
282 |
// }
|
|
|
283 |
// else
|
|
|
284 |
// {
|
|
|
285 |
// age_sum = -1;
|
|
|
286 |
// }
|
|
|
287 |
// }
|
| 91 |
- |
288 |
|
| 158 |
david |
289 |
// }
|
| 91 |
- |
290 |
|
| 158 |
david |
291 |
// /*
|
|
|
292 |
// ** Display / Update the leg informarion for each configured leg
|
|
|
293 |
// */
|
|
|
294 |
// for( j = 1; j <= config.num_legs; j++, i++ )
|
|
|
295 |
// {
|
|
|
296 |
// d_leg( 4 + i, j, &team_buf.leg[j], valid, operation );
|
|
|
297 |
// if( abort_flag )
|
|
|
298 |
// {
|
|
|
299 |
// i += config.num_legs - j + 1;
|
|
|
300 |
// break;
|
|
|
301 |
// }
|
|
|
302 |
// }
|
| 91 |
- |
303 |
|
| 158 |
david |
304 |
// /*
|
|
|
305 |
// ** Display the summary information
|
|
|
306 |
// ** For the team
|
|
|
307 |
// ** Event and class placing information
|
|
|
308 |
// ** Total age
|
|
|
309 |
// */
|
|
|
310 |
// d_leg( 4 + i, 0, &team_buf.leg[0], valid, M_DISPLAY );
|
| 91 |
- |
311 |
|
| 158 |
david |
312 |
// d_field( 0, 6 + i, "Event placing : ", D_NUMBER, 1,
|
|
|
313 |
// &team_buf.leg[0].le_place, valid, M_DISPLAY );
|
|
|
314 |
// d_field( 20, 6 + i, "Class placing : ", D_NUMBER, 1,
|
|
|
315 |
// &team_buf.leg[0].lec_place, valid, M_DISPLAY );
|
|
|
316 |
// d_field( 40, 6 + i, "Total Age : ", D_STRING, 5,
|
|
|
317 |
// age_a(age_sum), valid, M_DISPLAY );
|
| 91 |
- |
318 |
|
|
|
319 |
|
| 158 |
david |
320 |
// if( team_buf.flags.non_equestrian )
|
|
|
321 |
// d_field( 0, 7 + i, "Non-Equestrian", D_NULL, 1, 0, valid, M_DISPLAY );
|
|
|
322 |
// else if( team_buf.flags.disqualified )
|
|
|
323 |
// d_field( 0, 7 + i, "Disqualified", D_NULL, 1, 0, valid, M_DISPLAY );
|
| 91 |
- |
324 |
|
| 158 |
david |
325 |
//}
|
| 91 |
- |
326 |
|
|
|
327 |
/*========================================================================
|
|
|
328 |
*
|
|
|
329 |
* Display / Update leg time information
|
|
|
330 |
*
|
|
|
331 |
* Purpose:
|
|
|
332 |
* This function is called to display and update the leg
|
|
|
333 |
* time information.
|
|
|
334 |
*
|
|
|
335 |
* Parameters:
|
|
|
336 |
* y Screen position
|
|
|
337 |
* leg Leg to process
|
|
|
338 |
* data Leg data
|
|
|
339 |
* valid Data valid flag
|
|
|
340 |
* operation Operation to perform
|
|
|
341 |
*
|
|
|
342 |
* Returns:
|
|
|
343 |
* Nothing
|
|
|
344 |
*
|
|
|
345 |
*========================================================================*/
|
| 158 |
david |
346 |
//void d_leg( int y, int leg, leg_type * data, int valid, int operation )
|
|
|
347 |
//{
|
|
|
348 |
// int i;
|
|
|
349 |
// int oprs, oprf;
|
| 91 |
- |
350 |
|
| 158 |
david |
351 |
// /*
|
|
|
352 |
// ** Display the field header
|
|
|
353 |
// */
|
|
|
354 |
// if( operation == M_DISPLAY )
|
|
|
355 |
// {
|
|
|
356 |
// if( leg != 0 )
|
|
|
357 |
// {
|
|
|
358 |
// d_field( 0, y, "Leg ", D_NUMBER, 1, &leg, TRUE, M_DISPLAY );
|
|
|
359 |
// d_field( 7, y, "", D_STRING, MAX_LEG_NAME,
|
|
|
360 |
// config.leg_name[leg - 1], TRUE, M_DISPLAY );
|
|
|
361 |
// }
|
|
|
362 |
// else
|
|
|
363 |
// d_field( 0, y, "Overall team times", D_STRING, 0, "", TRUE, M_DISPLAY );
|
|
|
364 |
// }
|
| 91 |
- |
365 |
|
| 158 |
david |
366 |
// /*
|
|
|
367 |
// ** If we are doing an update,. then ensure that all the team times
|
|
|
368 |
// ** have been tested
|
|
|
369 |
// */
|
| 91 |
- |
370 |
|
| 158 |
david |
371 |
// if( operation & M_ALL )
|
|
|
372 |
// test_times( &team_buf, 0 ); /* Set up all team times */
|
| 91 |
- |
373 |
|
| 158 |
david |
374 |
// oprs = ( ( parallel_legs )
|
|
|
375 |
// || ( operation & M_ALEGS )
|
|
|
376 |
// || ( operation & M_LEGS ) ) ? M_UPDATE : M_DISPLAY;
|
| 91 |
- |
377 |
|
| 158 |
david |
378 |
// oprf = ( operation & M_LEGS ) ? M_UPDATE : M_DISPLAY;
|
| 91 |
- |
379 |
|
| 158 |
david |
380 |
// /*
|
|
|
381 |
// ** if start time edited then flag as manual entry
|
|
|
382 |
// ** redo calculations and refresh screen with new information
|
|
|
383 |
// */
|
| 91 |
- |
384 |
|
| 158 |
david |
385 |
// if( d_field
|
|
|
386 |
// ( 25, y, data->manual ? "MS " : " S ", D_TIME, 8, &data->start, valid,
|
|
|
387 |
// oprs ) )
|
|
|
388 |
// {
|
|
|
389 |
// data->manual = TRUE;
|
|
|
390 |
// test_times( &team_buf, 0 );
|
|
|
391 |
// for( i = leg; i <= config.num_legs; i++ )
|
|
|
392 |
// d_leg( y + i - leg, i, &team_buf.leg[i], valid, M_DISPLAY );
|
|
|
393 |
// d_leg( y + i - leg, 0, &team_buf.leg[0], valid, M_DISPLAY );
|
|
|
394 |
// }
|
| 91 |
- |
395 |
|
| 158 |
david |
396 |
// /*
|
|
|
397 |
// ** If time changed then redo calcs and refresh screen
|
|
|
398 |
// */
|
|
|
399 |
// if( d_field( 37, y, "F ", D_TIME, 8, &data->end, valid, oprf ) )
|
|
|
400 |
// {
|
|
|
401 |
// set_times( &team_buf );
|
|
|
402 |
// test_times( &team_buf, 0 );
|
|
|
403 |
// for( i = leg; i <= config.num_legs; i++ )
|
|
|
404 |
// d_leg( y + i - leg, i, &team_buf.leg[i], valid, M_DISPLAY );
|
|
|
405 |
// d_leg( y + i - leg, 0, &team_buf.leg[0], valid, M_DISPLAY );
|
|
|
406 |
// }
|
| 91 |
- |
407 |
|
| 158 |
david |
408 |
// d_field( 48, y, "E ", D_TIME, 8, &data->elapsed, valid, M_DISPLAY );
|
|
|
409 |
// if( leg == 0 )
|
|
|
410 |
// {
|
|
|
411 |
// d_field( 60, y, "", D_STRING, 10,
|
|
|
412 |
// ( team_buf.flags.bad_times ==
|
|
|
413 |
// TRUE ) ? "Incomplete" : " ", valid, M_DISPLAY );
|
|
|
414 |
// }
|
|
|
415 |
// else
|
|
|
416 |
// {
|
|
|
417 |
// d_field( 60, y, "", D_NUMBER, 4, &data->le_place, valid, M_DISPLAY );
|
|
|
418 |
// d_field( 65, y, "", D_NUMBER, 4, &data->l_place, valid, M_DISPLAY );
|
|
|
419 |
// d_field( 70, y, "", D_NUMBER, 4, &data->lec_place, valid, M_DISPLAY );
|
|
|
420 |
// d_field( 75, y, "", D_NUMBER, 4, &data->lc_place, valid, M_DISPLAY );
|
|
|
421 |
// }
|
|
|
422 |
//}
|
| 91 |
- |
423 |
|
|
|
424 |
/*========================================================================
|
|
|
425 |
*
|
|
|
426 |
* Display / Update simple time information
|
|
|
427 |
*
|
|
|
428 |
* Purpose:
|
|
|
429 |
* This function is called to display and update the leg
|
|
|
430 |
* time information.
|
|
|
431 |
*
|
|
|
432 |
* Parameters:
|
|
|
433 |
* x, y Screen position
|
|
|
434 |
* prompt Prompt to display
|
|
|
435 |
* data Address of time data
|
|
|
436 |
* valid Data valid flag
|
|
|
437 |
*
|
|
|
438 |
* Returns:
|
|
|
439 |
* Nothing
|
|
|
440 |
*
|
|
|
441 |
*========================================================================*/
|
| 158 |
david |
442 |
//void d_time( int x, int y, const char *prompt, time_t *data, int valid )
|
|
|
443 |
//{
|
|
|
444 |
// d_field( x, y, prompt, D_TIME, 8, ( char * ) data, valid, M_DISPLAY );
|
|
|
445 |
// d_field( x, y, prompt, D_TIME, 8, ( char * ) data, valid, M_UPDATE );
|
|
|
446 |
//}
|
| 91 |
- |
447 |
|
|
|
448 |
/*========================================================================
|
|
|
449 |
*
|
|
|
450 |
* Display / Update field on the screen
|
|
|
451 |
*
|
|
|
452 |
* Purpose:
|
|
|
453 |
*
|
|
|
454 |
* This function is called to display and update a field on the screen
|
|
|
455 |
* This routine will display a record from the team structure
|
|
|
456 |
* The type of data and other parameters is passed in
|
|
|
457 |
* This function is fundimental to the entire display subsystem
|
|
|
458 |
*
|
|
|
459 |
*
|
|
|
460 |
*
|
|
|
461 |
* Parameters:
|
|
|
462 |
* x The screen col
|
|
|
463 |
* y The line number
|
|
|
464 |
* prompt The field lable
|
|
|
465 |
* type type of field
|
|
|
466 |
* length Length of the numeric field
|
|
|
467 |
* data Pointer to the data
|
|
|
468 |
* valid data field is valid
|
|
|
469 |
* operation Operation type
|
|
|
470 |
*
|
|
|
471 |
* Returns:
|
|
|
472 |
* TRUE - Change has been made
|
|
|
473 |
*
|
|
|
474 |
*========================================================================*/
|
| 158 |
david |
475 |
//bool d_field( int x,
|
|
|
476 |
// int y,
|
|
|
477 |
// const char *prompt,
|
|
|
478 |
// int type, int length, const void *data, int valid, int operation )
|
|
|
479 |
//{
|
|
|
480 |
// time_t t;
|
|
|
481 |
// int i;
|
|
|
482 |
// sex_type s;
|
|
|
483 |
// int change = 0;
|
|
|
484 |
// int idata;
|
| 91 |
- |
485 |
|
| 158 |
david |
486 |
// /*
|
|
|
487 |
// ** Position the cursor and display the field title
|
|
|
488 |
// */
|
|
|
489 |
// cur( x, y );
|
|
|
490 |
// printf( "%s", prompt );
|
| 91 |
- |
491 |
|
| 158 |
david |
492 |
// /*
|
|
|
493 |
// ** If the ABORT flag is set then DISPLAY the field
|
|
|
494 |
// */
|
|
|
495 |
// if( abort_flag )
|
|
|
496 |
// operation = M_DISPLAY;
|
| 91 |
- |
497 |
|
| 158 |
david |
498 |
// /*
|
|
|
499 |
// ** Display the current field value
|
|
|
500 |
// ** Only if the data field is valid
|
|
|
501 |
// ** Only if the M_DISPLAY operation is requested
|
|
|
502 |
// */
|
|
|
503 |
// if( valid && ( operation == M_DISPLAY ) )
|
|
|
504 |
// {
|
|
|
505 |
// switch ( type )
|
|
|
506 |
// {
|
|
|
507 |
// case D_STRING:
|
|
|
508 |
// case D_USTRING:
|
|
|
509 |
// printf( "%-*.*s", length, length, (char *)data );
|
|
|
510 |
// break;
|
| 91 |
- |
511 |
|
| 158 |
david |
512 |
// case D_NUMBER:
|
|
|
513 |
// printf( "%-*d", length, *( short * ) data );
|
|
|
514 |
// break;
|
| 91 |
- |
515 |
|
| 158 |
david |
516 |
// case D_SEX:
|
|
|
517 |
// if( *( sex_type * ) data != unknown )
|
|
|
518 |
// printf( "%s",
|
|
|
519 |
// ( *( sex_type * ) data ==
|
|
|
520 |
// male ) ? "Male" : "Female" );
|
|
|
521 |
// break;
|
| 91 |
- |
522 |
|
| 158 |
david |
523 |
// case D_TIME:
|
|
|
524 |
// printf( "%s", time_a( *( time_t * ) data ) );
|
|
|
525 |
// break;
|
| 91 |
- |
526 |
|
| 158 |
david |
527 |
// case D_CLASS:
|
|
|
528 |
// if( *( short * ) data > 0 )
|
|
|
529 |
// {
|
|
|
530 |
// printf( "%2.2s", config.team_class[( *( int * ) data ) - 1].abr );
|
|
|
531 |
// printf( " %-*.*s", LEN_CLASS_NAME, LEN_CLASS_NAME,
|
|
|
532 |
// config.team_class[( *( int * ) data ) - 1].full_name );
|
|
|
533 |
// }
|
|
|
534 |
// break;
|
| 91 |
- |
535 |
|
| 158 |
david |
536 |
// case D_COUNTRY:
|
|
|
537 |
// if( *( short * ) data > 0 )
|
|
|
538 |
// {
|
|
|
539 |
// printf( "%4.4s",
|
|
|
540 |
// config.country_name[( *( int * ) data ) - 1].abr );
|
|
|
541 |
// printf( " %-*.*s", LEN_CNTRY_NAME, LEN_CNTRY_NAME,
|
|
|
542 |
// config.country_name[( *( int * ) data ) -
|
|
|
543 |
// 1].full_name );
|
|
|
544 |
// }
|
|
|
545 |
// break;
|
| 91 |
- |
546 |
|
| 158 |
david |
547 |
// case D_AGE:
|
|
|
548 |
// if( *( uchar * ) data > 0 )
|
|
|
549 |
// {
|
|
|
550 |
// printf( "%-*d", length, *( uchar * ) data );
|
|
|
551 |
// }
|
|
|
552 |
// break;
|
| 91 |
- |
553 |
|
|
|
554 |
|
| 158 |
david |
555 |
// case D_NULL:
|
|
|
556 |
// break;
|
| 91 |
- |
557 |
|
| 158 |
david |
558 |
// default:
|
|
|
559 |
// printf( "Unknown data type" );
|
|
|
560 |
// break;
|
|
|
561 |
// }
|
|
|
562 |
// }
|
| 91 |
- |
563 |
|
| 158 |
david |
564 |
// /*
|
|
|
565 |
// ** If updating the field then extract the required information
|
|
|
566 |
// */
|
|
|
567 |
// if( operation == M_UPDATE )
|
|
|
568 |
// {
|
|
|
569 |
// switch ( type )
|
|
|
570 |
// {
|
|
|
571 |
// case D_STRING:
|
|
|
572 |
// change = ( getstring( length, (char *)data, Alphanum ) );
|
|
|
573 |
// break;
|
| 91 |
- |
574 |
|
| 158 |
david |
575 |
// case D_USTRING:
|
|
|
576 |
// change = ( getstring( length, (char *)data, AlphnumUpper ) );
|
|
|
577 |
// break;
|
| 91 |
- |
578 |
|
| 158 |
david |
579 |
// case D_NUMBER:
|
|
|
580 |
// idata = *(short *)data;
|
|
|
581 |
// change = getnum( length, &idata );
|
|
|
582 |
// if ( change )
|
|
|
583 |
// *( short *)data = idata;
|
|
|
584 |
// break;
|
| 91 |
- |
585 |
|
| 158 |
david |
586 |
// case D_SEX:
|
|
|
587 |
// if( ( s = getsex() ) != unknown )
|
|
|
588 |
// {
|
|
|
589 |
// change = ( *( sex_type * ) data != s );
|
|
|
590 |
// *( sex_type * ) data = s;
|
|
|
591 |
// }
|
|
|
592 |
// break;
|
| 91 |
- |
593 |
|
| 158 |
david |
594 |
// case D_TIME:
|
|
|
595 |
// if( ( t = get_time(*( time_t * ) data) ) >= 0 )
|
|
|
596 |
// {
|
|
|
597 |
// change = ( *( time_t * ) data != t );
|
|
|
598 |
// *( time_t * ) data = t;
|
|
|
599 |
// }
|
|
|
600 |
// break;
|
| 91 |
- |
601 |
|
| 158 |
david |
602 |
// case D_CLASS:
|
|
|
603 |
// if( ( i = getclass() ) != 0 )
|
|
|
604 |
// {
|
|
|
605 |
// change = *( short * ) data != i;
|
|
|
606 |
// *( short * ) data = i;
|
|
|
607 |
// }
|
|
|
608 |
// break;
|
| 91 |
- |
609 |
|
| 158 |
david |
610 |
// case D_COUNTRY:
|
|
|
611 |
// if( ( i = getcountry() ) != 0 )
|
|
|
612 |
// {
|
|
|
613 |
// change = *( short * ) data != i;
|
|
|
614 |
// *( short * ) data = i;
|
|
|
615 |
// }
|
|
|
616 |
// break;
|
| 91 |
- |
617 |
|
| 158 |
david |
618 |
// case D_AGE:
|
|
|
619 |
// idata = *(uchar *)data;
|
|
|
620 |
// change = getnum( length, &idata );
|
|
|
621 |
// if ( change )
|
|
|
622 |
// *( uchar *)data = idata;
|
|
|
623 |
// break;
|
| 91 |
- |
624 |
|
|
|
625 |
|
| 158 |
david |
626 |
// case D_NULL:
|
|
|
627 |
// break;
|
| 91 |
- |
628 |
|
| 158 |
david |
629 |
// default:
|
|
|
630 |
// printf( "Unknown data type" );
|
|
|
631 |
// break;
|
|
|
632 |
// }
|
| 91 |
- |
633 |
|
| 158 |
david |
634 |
// /*
|
|
|
635 |
// ** Having accepted the input now DISPLAY the data (once again)
|
|
|
636 |
// ** Done to allow aborted field to re-display original values
|
|
|
637 |
// */
|
|
|
638 |
// d_field( x, y, prompt, type, length, data, TRUE, M_DISPLAY );
|
|
|
639 |
// }
|
|
|
640 |
// return ( change );
|
|
|
641 |
//}
|
| 91 |
- |
642 |
|
|
|
643 |
/*========================================================================
|
|
|
644 |
*
|
|
|
645 |
* Get a team number from the operator
|
|
|
646 |
*
|
|
|
647 |
* Purpose:
|
|
|
648 |
* This function is called to Get a team number from the operator
|
|
|
649 |
* Prompt the operator for a team number
|
|
|
650 |
* Verify that the team number is valid
|
|
|
651 |
* Allow escape characters in the process
|
|
|
652 |
*
|
|
|
653 |
* This routine will return TRUE if the team number is valid
|
|
|
654 |
* The team number is returned in the global variable "team"
|
|
|
655 |
*
|
|
|
656 |
* Parameters:
|
|
|
657 |
* x,y Screen coords
|
|
|
658 |
* prompt Operator prompt
|
|
|
659 |
*
|
|
|
660 |
* Returns:
|
|
|
661 |
* TRUE : Number OK
|
|
|
662 |
*
|
|
|
663 |
*========================================================================*/
|
| 158 |
david |
664 |
//bool g_tnum( int x, int y, const char *prompt )
|
|
|
665 |
//{
|
|
|
666 |
// int new_team = 0; /* team number that will be input */
|
| 91 |
- |
667 |
|
| 158 |
david |
668 |
// while( TRUE )
|
|
|
669 |
// {
|
|
|
670 |
// team = 0;
|
|
|
671 |
// abort_flag = FALSE;
|
|
|
672 |
// cur( x, y );
|
|
|
673 |
// printf( "%s : ", prompt );
|
|
|
674 |
// //console_clreol();
|
|
|
675 |
// if( !getnum( 6, &new_team ) )
|
|
|
676 |
// return ( FALSE ); /* No input */
|
| 91 |
- |
677 |
|
| 158 |
david |
678 |
// /*
|
|
|
679 |
// * verify that the team number is within the allowed numbers
|
|
|
680 |
// */
|
| 91 |
- |
681 |
|
| 158 |
david |
682 |
// if( !valid_field( new_team ) )
|
|
|
683 |
// {
|
|
|
684 |
// beep();
|
|
|
685 |
// printf( "\nTeam %-1d is not valid", new_team );
|
|
|
686 |
// continue;
|
|
|
687 |
// }
|
|
|
688 |
// team = new_team;
|
|
|
689 |
// return ( TRUE );
|
|
|
690 |
// }
|
|
|
691 |
//}
|
| 91 |
- |
692 |
|
|
|
693 |
/*========================================================================
|
|
|
694 |
*
|
|
|
695 |
* Read a team record from disk
|
|
|
696 |
*
|
|
|
697 |
* Purpose:
|
|
|
698 |
* This function is called to Read a team record from disk
|
|
|
699 |
* Locate the team record in the team data file
|
|
|
700 |
* if the record does not exist create a blank record
|
|
|
701 |
*
|
|
|
702 |
* The function will return FALSE if the record was not on disk
|
|
|
703 |
* otherwise TRUE
|
|
|
704 |
*
|
|
|
705 |
* Parameters:
|
|
|
706 |
* int_team Team record required
|
|
|
707 |
* data Area to return record
|
|
|
708 |
*
|
|
|
709 |
* Returns:
|
|
|
710 |
* FALSE : No data available
|
|
|
711 |
*
|
|
|
712 |
*========================================================================*/
|
|
|
713 |
bool g_record( int _team, team_type * data )
|
|
|
714 |
{
|
|
|
715 |
int len; /* length of record read in */
|
|
|
716 |
long pos; /* File pointer */
|
|
|
717 |
|
|
|
718 |
pos = _team;
|
|
|
719 |
pos *= sizeof( team_type );
|
|
|
720 |
len = lseek( team_fd, pos, 0 );
|
|
|
721 |
len = read( team_fd, ( char * ) data, sizeof( team_type ) );
|
|
|
722 |
if( ( len == sizeof( team_type ) ) && ( _team == data->numb ) )
|
|
|
723 |
return ( data->flags.valid );
|
|
|
724 |
else
|
|
|
725 |
{
|
|
|
726 |
clr_team( _team, data );
|
|
|
727 |
return ( FALSE );
|
|
|
728 |
}
|
|
|
729 |
}
|
|
|
730 |
|
|
|
731 |
/*========================================================================
|
|
|
732 |
*
|
|
|
733 |
* Clear team data from file
|
|
|
734 |
*
|
|
|
735 |
* Purpose:
|
|
|
736 |
* This function is called to Clear team data from file
|
|
|
737 |
* This routine will set the team data to INVALID
|
|
|
738 |
*
|
|
|
739 |
* Parameters:
|
|
|
740 |
* tm Team number
|
|
|
741 |
* data Pointer to the data
|
|
|
742 |
*
|
|
|
743 |
* Returns:
|
|
|
744 |
* Nothing
|
|
|
745 |
*
|
|
|
746 |
*========================================================================*/
|
|
|
747 |
void clr_team( int tm, team_type * data )
|
|
|
748 |
{
|
|
|
749 |
int len;
|
|
|
750 |
|
|
|
751 |
memset( ( char * ) data, 0, ( int ) sizeof( team_type ) );
|
|
|
752 |
data->flags.valid = FALSE;
|
|
|
753 |
data->flags.bad_times = TRUE;
|
|
|
754 |
data->numb = tm;
|
|
|
755 |
for( len = 0; len < MAX_LEGS + 1; len++ )
|
|
|
756 |
{
|
|
|
757 |
data->leg[len].start = -1;
|
|
|
758 |
data->leg[len].end = -1;
|
|
|
759 |
data->leg[len].elapsed = -1;
|
|
|
760 |
data->leg[len].l_place = 0;
|
|
|
761 |
data->leg[len].le_place = 0;
|
|
|
762 |
data->leg[len].lec_place = 0;
|
|
|
763 |
data->leg[len].lc_place = 0;
|
|
|
764 |
data->leg[len].manual = 0;
|
|
|
765 |
}
|
|
|
766 |
}
|
|
|
767 |
|
|
|
768 |
/*========================================================================
|
|
|
769 |
*
|
|
|
770 |
* Save team record to disk
|
|
|
771 |
*
|
|
|
772 |
* Purpose:
|
|
|
773 |
* This function is called to save team record to disk
|
|
|
774 |
*
|
|
|
775 |
* Parameters:
|
|
|
776 |
* _team Team number
|
|
|
777 |
* data Pointer to the data
|
|
|
778 |
*
|
|
|
779 |
* Returns:
|
|
|
780 |
* FALSE : Error in save
|
|
|
781 |
*
|
|
|
782 |
*========================================================================*/
|
|
|
783 |
bool put_team_record( int _team, team_type * data )
|
|
|
784 |
{
|
|
|
785 |
int len; /* length of record read in */
|
|
|
786 |
long pos; /* file pointer */
|
|
|
787 |
|
|
|
788 |
pos = _team;
|
|
|
789 |
pos *= sizeof( team_type );
|
|
|
790 |
lseek( team_fd, pos, 0 );
|
|
|
791 |
len = write( team_fd, ( char * ) data, sizeof( team_type ) );
|
|
|
792 |
if( len != sizeof( team_type ) )
|
|
|
793 |
{
|
| 170 |
- |
794 |
//perror( "Team record write" );
|
|
|
795 |
MainWindow::showMessage("Error Team record write");
|
| 91 |
- |
796 |
}
|
|
|
797 |
return ( len == sizeof( team_type ) );
|
|
|
798 |
}
|
|
|
799 |
|
|
|
800 |
/*========================================================================
|
|
|
801 |
*
|
|
|
802 |
* Initialize the team data file
|
|
|
803 |
*
|
|
|
804 |
* Purpose:
|
|
|
805 |
* This function is called to Initialize the team data file and
|
|
|
806 |
* prepare it for processing
|
|
|
807 |
*
|
|
|
808 |
* Parameters:
|
|
|
809 |
* None
|
|
|
810 |
*
|
|
|
811 |
* Returns:
|
|
|
812 |
* FALSE : Error encountered
|
|
|
813 |
*
|
|
|
814 |
*========================================================================*/
|
|
|
815 |
bool init_team_data(void)
|
|
|
816 |
{
|
|
|
817 |
|
|
|
818 |
team_fd = open( datfile, OPEN_RW, 0 );
|
|
|
819 |
if( team_fd < 0 )
|
|
|
820 |
{
|
|
|
821 |
/*
|
|
|
822 |
* file does not exist - create it
|
|
|
823 |
*/
|
|
|
824 |
printf( "The team data file does not exist.\n" );
|
| 158 |
david |
825 |
// if( getyes( "Create the data file" ) )
|
|
|
826 |
// {
|
|
|
827 |
// team_fd = creat( datfile, 0664 );
|
|
|
828 |
// if( team_fd > 0 )
|
|
|
829 |
// {
|
|
|
830 |
// close( team_fd ); /* Close th file */
|
|
|
831 |
// team_fd = open( datfile, OPEN_RW, 644 );
|
|
|
832 |
// if( team_fd < 0 )
|
|
|
833 |
// perror( "Team datafile" );
|
|
|
834 |
// }
|
|
|
835 |
// }
|
| 91 |
- |
836 |
}
|
|
|
837 |
return ( team_fd >= 0 );
|
|
|
838 |
}
|
|
|
839 |
|
|
|
840 |
/*========================================================================
|
|
|
841 |
*
|
|
|
842 |
* Close team data file
|
|
|
843 |
*
|
|
|
844 |
* Purpose:
|
|
|
845 |
* This function is called to close the team data file
|
|
|
846 |
*
|
|
|
847 |
* Parameters:
|
|
|
848 |
* None
|
|
|
849 |
*
|
|
|
850 |
* Returns:
|
|
|
851 |
* Nothing
|
|
|
852 |
*
|
|
|
853 |
*========================================================================*/
|
|
|
854 |
void fix_team_data(void)
|
|
|
855 |
{
|
|
|
856 |
if( team_fd > 0 )
|
|
|
857 |
close( team_fd );
|
|
|
858 |
}
|
|
|
859 |
|
|
|
860 |
/********************************* EOF ***********************************/
|