Subversion Repositories svn1

Rev

Rev 112 | Rev 133 | 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
/*============================================================================
43
 *  Main entry point
44
 *
45
 *  Purpose:
46
 *      Main enrty point
47
 *      Load configuration file
48
 *      Locate data base
49
 *      Perform copyright stuff
50
 *      Process top level menu
51
 *
52
 *  Parameters:
53
 *      argc    - number of arguments
54
 *      argv    - pointer to first argument pointer
55
 *      
56
 *      
57
 *  Returns:
58
 *      program exit code
59
 *          0 - All is well
60
 *          1 -
61
 *          2 - 
62
 *
63
 *===========================================================================*/
64
 
65
int main( int argc, char *argv[] )
66
{
67
    bool        do_splash = TRUE;
68
    bool        do_version = FALSE;
69
    bool        do_config = FALSE;
70
    char       *file_name = NULL;
71
 
126 david 72
    QApplication a(argc, argv);
73
 
91 - 74
    /*
75
    **  Verify command arguments
76
    */
77
    if( argc < 2 )
78
        usage();
79
 
80
    /*
81
    **  Walk the user arguments and extract switches and file names
82
    */
83
    while( --argc )
84
    {
85
        argv++;
86
        if( argv[0][0] == '-' )
87
        {
88
            switch( argv[0][1] )
89
            {
90
              case 'q':
91
                do_splash = FALSE;
92
                break;
93
 
94
              case 'v':
95
                do_version = TRUE;
96
                break;
97
 
98
              case 'c' :
99
                do_config = TRUE;
100
                break;
101
 
102
              case 'x' :
103
                set_commands( &argv[0][2]);
104
                break;
105
 
106
                /*
107
                **  Unknown switch
108
                */
109
              default:
110
                usage();
111
            }
112
        }
113
        else
114
        {
115
            /*
116
            **  Parameter without a switch
117
            **  Must be the input file name
118
            */
119
            if( file_name )                   /* Already defined */
126 david 120
            {
121
                qWarning("Mutiple input files found");
122
            }
91 - 123
            file_name = argv[0];
124
        }
125
    }
126
 
127
    /*
126 david 128
    **  Validate parameters
129
    **  Filename must be supplied
94 - 130
    */
131
 
126 david 132
    if ( file_name == NULL )
112 david 133
    {
126 david 134
        qFatal("No marathon file name on command line");
112 david 135
    }
94 - 136
 
137
    /*
126 david 138
    **  Process the configuration file
91 - 139
    */
126 david 140
    if( !configure( file_name, FALSE ) )
91 - 141
    {
126 david 142
        qFatal("Program aborted. Config error" );
91 - 143
    }
144
 
126 david 145
    if( ! init_team_data() )
91 - 146
    {
126 david 147
        qFatal( "Program aborted. Team Data error" );
91 - 148
    }
149
 
126 david 150
    MainWindow w;
151
    w.show();
94 - 152
    return a.exec();
126 david 153
  }
91 - 154
 
155
/*============================================================================
156
 *
157
 *  Display general usage message
158
 *
159
 *  Purpose:
160
 *      Display general usage message
161
 *      Used on command line syntax error
162
 *      
163
 *  Parameters:
164
 *      None
165
 *      
166
 *  Returns:
167
 *      exit code 3
168
 *      
169
 *===========================================================================*/
170
 
171
void usage(void)
172
{
173
    init_screen();
174
    printf( "Usage : mara [options] configuration_file\n" );
175
    printf( " or   : mara -v\n" );
176
    printf( "\n" );
177
    printf( "Options are:\n" );
178
    printf( "   -c       - Create configuration file\n" );
179
    printf( "   -q       - No splash screen\n" );
180
    printf( "   -v       - Display version then exit\n" );
181
    printf( "   -x<cmds> - Execute commnads\n" );
182
    fix_screen();
183
    exit( 3 );
184
}
185
 
186
 
187
/*============================================================================
188
**
189
**  Temp escape to DOS
190
**
191
**  Purpose:    Temp escape to DOS
192
**
193
**  Parameters: None
194
**      
195
**  Returns:    Nothing
196
**
197
**===========================================================================*/
198
 
199
void ms_system(void)
200
{
201
    static char command[101] = "";               /* Save the command here */
202
 
203
    cur( 0, 20 );
204
    printf( "Command:" );
205
    if( getstring( 100, command, Alphanum ) )
206
    {
207
        printf( "\n" );
208
        system( command );
209
        printf( "\nAny key to continue" );
210
        getinp();
211
    }
212
}
213
 
214
#ifdef DISPLAY_STRUCTURES
215
/*============================================================================
216
**
217
**  Display structure information
218
**
219
**  Purpose:    Display internal structure information
220
**
221
**  Parameters: Nothing
222
**      
223
**  Returns:    Nothing directly
224
**
225
**===========================================================================*/
226
 
227
/*
228
**  esize - A macro to return the size of a structure element
229
**  element - print element information
230
*/
231
#define esize( st, el) ( sizeof(((st *)0)->el))
232
#define element( st, el) \
233
    printf( "Offset of %-15s :%4d, Size:%d   \n", #el, offsetof( st, el), esize(st, el) );
234
 
235
void display_structures(void)
236
{
237
    printf( "Structure: leg_type\n" );
238
    element( leg_type, start    );
239
    element( leg_type, end      );
240
    element( leg_type, elapsed  );
241
    element( leg_type, l_place  );
242
    element( leg_type, le_place );
243
    element( leg_type, lc_place );
244
    element( leg_type, lec_place);
245
    element( leg_type, manual   );
246
    printf( "Sizeof %-18s :%4d\n", "leg_type", sizeof(leg_type) );
247
 
248
 
249
    printf( "\n" );
250
    printf( "Structure: team_type\n" );
251
    element( team_type, numb   );
252
    element( team_type, name   );
253
    element( team_type, leg    );
254
    element( team_type, members);
255
    element( team_type, class  );
256
    element( team_type, country);
257
    element( team_type, flags  );
258
    printf( "Sizeof %-18s :%4d\n", "team_type", sizeof(team_type) );
259
 
260
    printf( "\n" );
261
    printf( "Structure: MARA_CFG\n" );
262
    element( MARA_CFG, event_name      );
263
    element( MARA_CFG, leg_name        );
264
    element( MARA_CFG, t_def           );
265
    element( MARA_CFG, num_legs        );
266
    element( MARA_CFG, num_teams       );
267
    element( MARA_CFG, max_team        );
268
    element( MARA_CFG, min_team        );
269
    element( MARA_CFG, team_class      );
270
    element( MARA_CFG, num_class       );
271
    element( MARA_CFG, country_name    );
272
    element( MARA_CFG, num_countries   );
273
    element( MARA_CFG, addendum        );
274
    element( MARA_CFG, datafilename    );
275
    printf( "Sizeof %-18s :%4d\n", "MARA_CFG", sizeof(MARA_CFG) );
276
}
277
#endif
278
/********************************* EOF ***********************************/
279