Subversion Repositories svn1-original

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

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