Subversion Repositories svn1

Rev

Rev 94 | Rev 126 | 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
    {
112 david 152
        printf( "Program aborted. Config error\n" );
94 - 153
        exit (1);
154
    }
155
 
112 david 156
    if( ! init_team_data() )
157
    {
158
        printf( "Program aborted. Team Data error\n" );
159
        exit (1);
160
    }
94 - 161
 
112 david 162
 
94 - 163
    QApplication a(argc, argv);
164
    MainWindow w;
165
    w.show();
166
 
167
 
168
    /*
91 - 169
    **  Parse the command line arguments
170
    */
171
    if ( do_splash )
172
    {
173
        printf( "Mara   Copyright David Purdie 1995-2008.\n" );
174
        printf( "       Version %s", VERSION );
175
#ifdef __MINGW32__
176
        printf( " (Mingwin)" );
177
#endif
178
#ifdef __TURBOC__
179
        printf( " (TurboC)" );
180
#endif
181
        printf( "\n" );
182
        printf( "       This program is not to be used without the permission of\n" );
183
        printf( "       David Purdie.\n" );
184
 
185
#ifdef DISPLAY_STRUCTURES
186
        display_structures();
187
#endif
188
    }
189
 
190
    if ( do_version )
191
    {
192
        printf( "Version %s", VERSION );
193
#if END_VALID_DATE > 0
194
        printf( "P" );
195
#endif
196
 
197
#if defined(LIMIT_TEAMS) && (LIMIT_TEAMS > 0)
198
        printf( " (Limited teams)" );
199
#endif
200
 
201
        printf( " %s %s\n", __DATE__, __TIME__ );
202
        exit( 0 );
203
    }
204
 
205
    /*
206
    **  Validate parameters
207
    **  Filename must be supplied
208
    */
209
    if ( file_name == NULL )
210
        usage();
94 - 211
    return a.exec();
91 - 212
    /*
213
    **  Wait for the user to read the copyright notice
214
    */
94 - 215
//    if ( do_splash )
216
//    {
217
//        while( getinp() >= ' ' );
218
//    }
91 - 219
 
220
    /*
221
    **  Init the screen subsystem
222
    */
223
    init_screen();
224
    test_legal_version();
225
 
226
    /*
227
    **  Main process operations
228
    **  This is wrapped in a loop to make it easy to skip to the
229
    **  exit process bypassing the body.
230
    */
231
    do
232
    {
233
        /*
234
        **  Process the configuration file
235
        */
236
        if( !configure( file_name, do_config ) )
237
        {
238
            printf( "Program aborted.\n" );
239
            gross_error = 1;
240
            break;
241
        }
242
 
243
        /*
244
        **  Initialise the team data file
245
        */
246
        if( ! init_team_data() )
247
        {
248
            gross_error = 2;
249
            break;
250
        }
251
 
252
        /*
253
        **  Process the top level menu
254
        */
255
        do_menu( config.event_name, "Select option", main_menu );
256
        fix_team_data();
257
        break;
258
 
259
    } while ( FALSE);
260
 
261
    /*
262
    **  Restore the screen to its original state
263
    */
264
    if ( ! gross_error )
265
        cur( 0, n_lines - 1 );
266
    fix_screen();
267
    printf( "End of marathon\n" );
268
    exit( gross_error );
269
}
270
 
271
/*============================================================================
272
 *
273
 *  Display general usage message
274
 *
275
 *  Purpose:
276
 *      Display general usage message
277
 *      Used on command line syntax error
278
 *      
279
 *  Parameters:
280
 *      None
281
 *      
282
 *  Returns:
283
 *      exit code 3
284
 *      
285
 *===========================================================================*/
286
 
287
void usage(void)
288
{
289
    init_screen();
290
    printf( "Usage : mara [options] configuration_file\n" );
291
    printf( " or   : mara -v\n" );
292
    printf( "\n" );
293
    printf( "Options are:\n" );
294
    printf( "   -c       - Create configuration file\n" );
295
    printf( "   -q       - No splash screen\n" );
296
    printf( "   -v       - Display version then exit\n" );
297
    printf( "   -x<cmds> - Execute commnads\n" );
298
    fix_screen();
299
    exit( 3 );
300
}
301
 
302
 
303
/*============================================================================
304
**
305
**  Temp escape to DOS
306
**
307
**  Purpose:    Temp escape to DOS
308
**
309
**  Parameters: None
310
**      
311
**  Returns:    Nothing
312
**
313
**===========================================================================*/
314
 
315
void ms_system(void)
316
{
317
    static char command[101] = "";               /* Save the command here */
318
 
319
    cur( 0, 20 );
320
    printf( "Command:" );
321
    if( getstring( 100, command, Alphanum ) )
322
    {
323
        printf( "\n" );
324
        system( command );
325
        printf( "\nAny key to continue" );
326
        getinp();
327
    }
328
}
329
 
330
/*============================================================================
331
**
332
**  Test program version
333
**
334
**  Purpose:    Determine if this version of the program has expired
335
**              test against a hard coded date.
336
**
337
**  Parameters: Nothing
338
**      
339
**  Returns:    Nothing directly
340
**
341
**===========================================================================*/
342
 
343
void test_legal_version(void)
344
{
345
 
346
#if END_VALID_DATE > 0
347
    time_t      today;
348
 
349
    time( &today );
350
    invalid_copy = ( today >= END_VALID_DATE );
351
    if( invalid_copy )
352
        printf( "\n\aThis is an illegal copy of this program\n" );
353
#else
354
    invalid_copy = FALSE;
355
#endif
356
}
357
 
358
#ifdef DISPLAY_STRUCTURES
359
/*============================================================================
360
**
361
**  Display structure information
362
**
363
**  Purpose:    Display internal structure information
364
**
365
**  Parameters: Nothing
366
**      
367
**  Returns:    Nothing directly
368
**
369
**===========================================================================*/
370
 
371
/*
372
**  esize - A macro to return the size of a structure element
373
**  element - print element information
374
*/
375
#define esize( st, el) ( sizeof(((st *)0)->el))
376
#define element( st, el) \
377
    printf( "Offset of %-15s :%4d, Size:%d   \n", #el, offsetof( st, el), esize(st, el) );
378
 
379
void display_structures(void)
380
{
381
    printf( "Structure: leg_type\n" );
382
    element( leg_type, start    );
383
    element( leg_type, end      );
384
    element( leg_type, elapsed  );
385
    element( leg_type, l_place  );
386
    element( leg_type, le_place );
387
    element( leg_type, lc_place );
388
    element( leg_type, lec_place);
389
    element( leg_type, manual   );
390
    printf( "Sizeof %-18s :%4d\n", "leg_type", sizeof(leg_type) );
391
 
392
 
393
    printf( "\n" );
394
    printf( "Structure: team_type\n" );
395
    element( team_type, numb   );
396
    element( team_type, name   );
397
    element( team_type, leg    );
398
    element( team_type, members);
399
    element( team_type, class  );
400
    element( team_type, country);
401
    element( team_type, flags  );
402
    printf( "Sizeof %-18s :%4d\n", "team_type", sizeof(team_type) );
403
 
404
    printf( "\n" );
405
    printf( "Structure: MARA_CFG\n" );
406
    element( MARA_CFG, event_name      );
407
    element( MARA_CFG, leg_name        );
408
    element( MARA_CFG, t_def           );
409
    element( MARA_CFG, num_legs        );
410
    element( MARA_CFG, num_teams       );
411
    element( MARA_CFG, max_team        );
412
    element( MARA_CFG, min_team        );
413
    element( MARA_CFG, team_class      );
414
    element( MARA_CFG, num_class       );
415
    element( MARA_CFG, country_name    );
416
    element( MARA_CFG, num_countries   );
417
    element( MARA_CFG, addendum        );
418
    element( MARA_CFG, datafilename    );
419
    printf( "Sizeof %-18s :%4d\n", "MARA_CFG", sizeof(MARA_CFG) );
420
}
421
#endif
422
/********************************* EOF ***********************************/
423