Subversion Repositories svn1-original

Rev

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