Subversion Repositories svn1-original

Rev

Rev 137 | Rev 163 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

/*************************************************************************
*           Copyright (C) 1992 Embedded Solutions.
*                       All rights reserved
*
* file:         mara.c
*
* purpose:      Main entry point
*               Marathon program  program
*
* functions:
*       main                    - Main entry point
*       usage                   - Display general usage message
*       ms_system               - Temp escape to DOS
*       test_legal_version      - Test program version
*
*
* programmer: David Purdie (DDP)
*
* revision  date        by      reason
*           13-May-91   DDP     Added a nasty.
*                               This program will produce funny results if
*                               the system date is after 1-Jan-92.
*
*           25-Oct-91   DDP     Version 2.01 will not produce funny results
*
*   00.0    6-Nov-92    DDP     Ansified existing code
*   00.0    27/01/95    DDP     Tidies up the program and formatted the file
*
**************************************************************************/
#include    <QtGui/QApplication>

#include    <time.h>
#include    "consts.h"
#include    "structs.h"
#include    "proto.h"

#include    "qmconfigure.h"
#include    "mainwindow.h"

#undef      DISPLAY_STRUCTURES

/*============================================================================
 *  Main entry point
 *
 *  Purpose:
 *      Main enrty point
 *      Load configuration file
 *      Locate data base
 *      Perform copyright stuff
 *      Process top level menu
 *
 *  Parameters:
 *      argc    - number of arguments
 *      argv    - pointer to first argument pointer
 *      
 *      
 *  Returns:
 *      program exit code
 *          0 - All is well
 *          1 -
 *          2 - 
 *
 *===========================================================================*/

int main( int argc, char *argv[] )
{
    char       *file_name = NULL;

    QApplication a(argc, argv);

    /*
    **  Verify command arguments
    */
    if( argc < 2 )
        usage();

    /*
    **  Walk the user arguments and extract switches and file names
    */
    while( --argc )
    {
        argv++;
        if( argv[0][0] == '-' )
        {
            switch( argv[0][1] )
            {
                /*
                **  Unknown switch
                */
              default:
                usage();
            }
        }
        else
        {
            /*
            **  Parameter without a switch
            **  Must be the input file name
            */
            if( file_name )                   /* Already defined */
            {
                qWarning("Mutiple input files found");
            }
            file_name = argv[0];
        }
    }

    /*
    **  Validate parameters
    **  Filename must be supplied
    */

    if ( file_name == NULL )
    {
        qFatal("No marathon file name on command line");
    }

    /*
    **  Process the configuration file
    */
    if( !configure( file_name, FALSE ) )
    {
        qFatal("Program aborted. Config error" );
    }

    if( ! init_team_data() )
    {
        qFatal( "Program aborted. Team Data error" );
    }

    MainWindow w;
    w.show();
    MainWindow::showMessage ("Mara Started", 5000);
    return a.exec();
  }

/*============================================================================
 *
 *  Display general usage message
 *
 *  Purpose:
 *      Display general usage message
 *      Used on command line syntax error
 *      
 *  Parameters:
 *      None
 *      
 *  Returns:
 *      exit code 3
 *      
 *===========================================================================*/

void usage(void)
{
    qDebug( "Usage : mara [options] configuration_file\n" );
    qDebug( " or   : mara -v\n" );
    qDebug( "\n" );
    qDebug( "Options are:\n" );
    qDebug( "   -c       - Create configuration file\n" );
    qDebug( "   -q       - No splash screen\n" );
    qDebug( "   -v       - Display version then exit\n" );
    qDebug( "   -x<cmds> - Execute commnads\n" );
    exit( 3 );
}


/*============================================================================
**
**  Temp escape to DOS
**
**  Purpose:    Temp escape to DOS
**
**  Parameters: None
**      
**  Returns:    Nothing
**
**===========================================================================*/

void ms_system(void)
{
    static char command[101] = "";               /* Save the command here */

    cur( 0, 20 );
    printf( "Command:" );
    if( getstring( 100, command, Alphanum ) )
    {
        printf( "\n" );
        system( command );
        printf( "\nAny key to continue" );
        getinp();
    }
}

#ifdef DISPLAY_STRUCTURES
/*============================================================================
**
**  Display structure information
**
**  Purpose:    Display internal structure information
**
**  Parameters: Nothing
**      
**  Returns:    Nothing directly
**
**===========================================================================*/

/*
**  esize - A macro to return the size of a structure element
**  element - print element information
*/
#define esize( st, el) ( sizeof(((st *)0)->el))
#define element( st, el) \
    printf( "Offset of %-15s :%4d, Size:%d   \n", #el, offsetof( st, el), esize(st, el) );

void display_structures(void)
{
    printf( "Structure: leg_type\n" );
    element( leg_type, start    );
    element( leg_type, end      );
    element( leg_type, elapsed  );
    element( leg_type, l_place  );
    element( leg_type, le_place );
    element( leg_type, lc_place );
    element( leg_type, lec_place);
    element( leg_type, manual   );
    printf( "Sizeof %-18s :%4d\n", "leg_type", sizeof(leg_type) );


    printf( "\n" );
    printf( "Structure: team_type\n" );
    element( team_type, numb   );
    element( team_type, name   );
    element( team_type, leg    );
    element( team_type, members);
    element( team_type, class  );
    element( team_type, country);
    element( team_type, flags  );
    printf( "Sizeof %-18s :%4d\n", "team_type", sizeof(team_type) );

    printf( "\n" );
    printf( "Structure: MARA_CFG\n" );
    element( MARA_CFG, event_name      );
    element( MARA_CFG, leg_name        );
    element( MARA_CFG, t_def           );
    element( MARA_CFG, num_legs        );
    element( MARA_CFG, num_teams       );
    element( MARA_CFG, max_team        );
    element( MARA_CFG, min_team        );
    element( MARA_CFG, team_class      );
    element( MARA_CFG, num_class       );
    element( MARA_CFG, country_name    );
    element( MARA_CFG, num_countries   );
    element( MARA_CFG, addendum        );
    element( MARA_CFG, datafilename    );
    printf( "Sizeof %-18s :%4d\n", "MARA_CFG", sizeof(MARA_CFG) );
}
#endif
/********************************* EOF ***********************************/