Subversion Repositories svn1

Rev

Rev 91 | Rev 112 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
91 - 1
/*************************************************************************
2
*           Copyright (C) 1992 Embedded Solutions.
3
*                       All rights reserved
4
*
5
* file:         mara.c
6
*
7
* purpose:      Main entry point
8
*               Marathon program  program
9
*
10
* functions:
11
*       main                    - Main entry point
12
*       usage                   - Display general usage message
13
*       ms_system               - Temp escape to DOS
14
*       test_legal_version      - Test program version
15
*
16
*
17
* programmer: David Purdie (DDP)
18
*
19
* revision  date        by      reason
20
*           13-May-91   DDP     Added a nasty.
21
*                               This program will produce funny results if
22
*                               the system date is after 1-Jan-92.
23
*
24
*           25-Oct-91   DDP     Version 2.01 will not produce funny results
25
*
26
*   00.0    6-Nov-92    DDP     Ansified existing code
27
*   00.0    27/01/95    DDP     Tidies up the program and formatted the file
28
*
29
**************************************************************************/
94 - 30
#include    <QtGui/QApplication>
91 - 31
 
32
#include    <time.h>
33
#include    "consts.h"
34
#include    "structs.h"
35
#include    "proto.h"
94 - 36
 
37
#include    "qmconfigure.h"
38
#include    "mainwindow.h"
39
 
91 - 40
#undef      DISPLAY_STRUCTURES
41
 
42
char        invalid_copy;                        /* Quick nasty test of copy */
43
 
44
 
45
#if defined(HI_TECH_C) || defined(__TURBOC__)
46
extern unsigned _stklen = 8000;                  /* Create a long stack */
47
#endif
48
 
49
menu_table  main_menu[] = {
50
    { '1', "Enter team data", team_update },
51
    { '2', "Display team information", team_display },
52
    { '3', "Alter leg times", leg_mods },
53
    { '4', "Set leg start times", set_legs },
54
    { '5', "Report generation menu", report },
55
    { '6', "Data consistency check", data_check },
56
    { '7', "Team disqualification operations", f_disqualify },
57
    { '8', "Upload/Download functions", supload },
58
    { 'C', "Configuration menu", conf_menu },
59
    { 'S', "MS-DOS system", ms_system },
60
    { 'q', "Exit program", 0 },
61
    { '\0' }
62
};
63
 
64
/*============================================================================
65
 *  Main entry point
66
 *
67
 *  Purpose:
68
 *      Main enrty point
69
 *      Load configuration file
70
 *      Locate data base
71
 *      Perform copyright stuff
72
 *      Process top level menu
73
 *
74
 *  Parameters:
75
 *      argc    - number of arguments
76
 *      argv    - pointer to first argument pointer
77
 *      
78
 *      
79
 *  Returns:
80
 *      program exit code
81
 *          0 - All is well
82
 *          1 -
83
 *          2 - 
84
 *
85
 *===========================================================================*/
86
 
87
int main( int argc, char *argv[] )
88
{
89
    int         gross_error = 0;
90
 
91
    bool        do_splash = TRUE;
92
    bool        do_version = FALSE;
93
    bool        do_config = FALSE;
94
    char       *file_name = NULL;
95
 
96
    /*
97
    **  Verify command arguments
98
    */
99
    if( argc < 2 )
100
        usage();
101
 
102
    /*
103
    **  Walk the user arguments and extract switches and file names
104
    */
105
    while( --argc )
106
    {
107
        argv++;
108
        if( argv[0][0] == '-' )
109
        {
110
            switch( argv[0][1] )
111
            {
112
              case 'q':
113
                do_splash = FALSE;
114
                break;
115
 
116
              case 'v':
117
                do_version = TRUE;
118
                break;
119
 
120
              case 'c' :
121
                do_config = TRUE;
122
                break;
123
 
124
              case 'x' :
125
                set_commands( &argv[0][2]);
126
                break;
127
 
128
                /*
129
                **  Unknown switch
130
                */
131
              default:
132
                usage();
133
            }
134
        }
135
        else
136
        {
137
            /*
138
            **  Parameter without a switch
139
            **  Must be the input file name
140
            */
141
            if( file_name )                   /* Already defined */
142
                usage();
143
            file_name = argv[0];
144
        }
145
    }
146
 
147
    /*
94 - 148
    **  Process the configuration file
149
    */
150
    if( !configure( file_name, do_config ) )
151
    {
152
        printf( "Program aborted.\n" );
153
        exit (1);
154
    }
155
 
156
 
157
    QApplication a(argc, argv);
158
    MainWindow w;
159
    w.show();
160
 
161
 
162
    /*
91 - 163
    **  Parse the command line arguments
164
    */
165
    if ( do_splash )
166
    {
167
        printf( "Mara   Copyright David Purdie 1995-2008.\n" );
168
        printf( "       Version %s", VERSION );
169
#ifdef __MINGW32__
170
        printf( " (Mingwin)" );
171
#endif
172
#ifdef __TURBOC__
173
        printf( " (TurboC)" );
174
#endif
175
        printf( "\n" );
176
        printf( "       This program is not to be used without the permission of\n" );
177
        printf( "       David Purdie.\n" );
178
 
179
#ifdef DISPLAY_STRUCTURES
180
        display_structures();
181
#endif
182
    }
183
 
184
    if ( do_version )
185
    {
186
        printf( "Version %s", VERSION );
187
#if END_VALID_DATE > 0
188
        printf( "P" );
189
#endif
190
 
191
#if defined(LIMIT_TEAMS) && (LIMIT_TEAMS > 0)
192
        printf( " (Limited teams)" );
193
#endif
194
 
195
        printf( " %s %s\n", __DATE__, __TIME__ );
196
        exit( 0 );
197
    }
198
 
199
    /*
200
    **  Validate parameters
201
    **  Filename must be supplied
202
    */
203
    if ( file_name == NULL )
204
        usage();
94 - 205
    return a.exec();
91 - 206
    /*
207
    **  Wait for the user to read the copyright notice
208
    */
94 - 209
//    if ( do_splash )
210
//    {
211
//        while( getinp() >= ' ' );
212
//    }
91 - 213
 
214
    /*
215
    **  Init the screen subsystem
216
    */
217
    init_screen();
218
    test_legal_version();
219
 
220
    /*
221
    **  Main process operations
222
    **  This is wrapped in a loop to make it easy to skip to the
223
    **  exit process bypassing the body.
224
    */
225
    do
226
    {
227
        /*
228
        **  Process the configuration file
229
        */
230
        if( !configure( file_name, do_config ) )
231
        {
232
            printf( "Program aborted.\n" );
233
            gross_error = 1;
234
            break;
235
        }
236
 
237
        /*
238
        **  Initialise the team data file
239
        */
240
        if( ! init_team_data() )
241
        {
242
            gross_error = 2;
243
            break;
244
        }
245
 
246
        /*
247
        **  Process the top level menu
248
        */
249
        do_menu( config.event_name, "Select option", main_menu );
250
        fix_team_data();
251
        break;
252
 
253
    } while ( FALSE);
254
 
255
    /*
256
    **  Restore the screen to its original state
257
    */
258
    if ( ! gross_error )
259
        cur( 0, n_lines - 1 );
260
    fix_screen();
261
    printf( "End of marathon\n" );
262
    exit( gross_error );
263
}
264
 
265
/*============================================================================
266
 *
267
 *  Display general usage message
268
 *
269
 *  Purpose:
270
 *      Display general usage message
271
 *      Used on command line syntax error
272
 *      
273
 *  Parameters:
274
 *      None
275
 *      
276
 *  Returns:
277
 *      exit code 3
278
 *      
279
 *===========================================================================*/
280
 
281
void usage(void)
282
{
283
    init_screen();
284
    printf( "Usage : mara [options] configuration_file\n" );
285
    printf( " or   : mara -v\n" );
286
    printf( "\n" );
287
    printf( "Options are:\n" );
288
    printf( "   -c       - Create configuration file\n" );
289
    printf( "   -q       - No splash screen\n" );
290
    printf( "   -v       - Display version then exit\n" );
291
    printf( "   -x<cmds> - Execute commnads\n" );
292
    fix_screen();
293
    exit( 3 );
294
}
295
 
296
 
297
/*============================================================================
298
**
299
**  Temp escape to DOS
300
**
301
**  Purpose:    Temp escape to DOS
302
**
303
**  Parameters: None
304
**      
305
**  Returns:    Nothing
306
**
307
**===========================================================================*/
308
 
309
void ms_system(void)
310
{
311
    static char command[101] = "";               /* Save the command here */
312
 
313
    cur( 0, 20 );
314
    printf( "Command:" );
315
    if( getstring( 100, command, Alphanum ) )
316
    {
317
        printf( "\n" );
318
        system( command );
319
        printf( "\nAny key to continue" );
320
        getinp();
321
    }
322
}
323
 
324
/*============================================================================
325
**
326
**  Test program version
327
**
328
**  Purpose:    Determine if this version of the program has expired
329
**              test against a hard coded date.
330
**
331
**  Parameters: Nothing
332
**      
333
**  Returns:    Nothing directly
334
**
335
**===========================================================================*/
336
 
337
void test_legal_version(void)
338
{
339
 
340
#if END_VALID_DATE > 0
341
    time_t      today;
342
 
343
    time( &today );
344
    invalid_copy = ( today >= END_VALID_DATE );
345
    if( invalid_copy )
346
        printf( "\n\aThis is an illegal copy of this program\n" );
347
#else
348
    invalid_copy = FALSE;
349
#endif
350
}
351
 
352
#ifdef DISPLAY_STRUCTURES
353
/*============================================================================
354
**
355
**  Display structure information
356
**
357
**  Purpose:    Display internal structure information
358
**
359
**  Parameters: Nothing
360
**      
361
**  Returns:    Nothing directly
362
**
363
**===========================================================================*/
364
 
365
/*
366
**  esize - A macro to return the size of a structure element
367
**  element - print element information
368
*/
369
#define esize( st, el) ( sizeof(((st *)0)->el))
370
#define element( st, el) \
371
    printf( "Offset of %-15s :%4d, Size:%d   \n", #el, offsetof( st, el), esize(st, el) );
372
 
373
void display_structures(void)
374
{
375
    printf( "Structure: leg_type\n" );
376
    element( leg_type, start    );
377
    element( leg_type, end      );
378
    element( leg_type, elapsed  );
379
    element( leg_type, l_place  );
380
    element( leg_type, le_place );
381
    element( leg_type, lc_place );
382
    element( leg_type, lec_place);
383
    element( leg_type, manual   );
384
    printf( "Sizeof %-18s :%4d\n", "leg_type", sizeof(leg_type) );
385
 
386
 
387
    printf( "\n" );
388
    printf( "Structure: team_type\n" );
389
    element( team_type, numb   );
390
    element( team_type, name   );
391
    element( team_type, leg    );
392
    element( team_type, members);
393
    element( team_type, class  );
394
    element( team_type, country);
395
    element( team_type, flags  );
396
    printf( "Sizeof %-18s :%4d\n", "team_type", sizeof(team_type) );
397
 
398
    printf( "\n" );
399
    printf( "Structure: MARA_CFG\n" );
400
    element( MARA_CFG, event_name      );
401
    element( MARA_CFG, leg_name        );
402
    element( MARA_CFG, t_def           );
403
    element( MARA_CFG, num_legs        );
404
    element( MARA_CFG, num_teams       );
405
    element( MARA_CFG, max_team        );
406
    element( MARA_CFG, min_team        );
407
    element( MARA_CFG, team_class      );
408
    element( MARA_CFG, num_class       );
409
    element( MARA_CFG, country_name    );
410
    element( MARA_CFG, num_countries   );
411
    element( MARA_CFG, addendum        );
412
    element( MARA_CFG, datafilename    );
413
    printf( "Sizeof %-18s :%4d\n", "MARA_CFG", sizeof(MARA_CFG) );
414
}
415
#endif
416
/********************************* EOF ***********************************/
417