Rev 61 | 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 <time.h>#include "consts.h"#include "structs.h"#include "proto.h"#undef DISPLAY_STRUCTURESchar invalid_copy; /* Quick nasty test of copy */#if defined(HI_TECH_C) || defined(__TURBOC__)extern unsigned _stklen = 8000; /* Create a long stack */#endifmenu_table main_menu[] = {{ '1', "Enter team data", team_update },{ '2', "Display team information", team_display },{ '3', "Alter leg times", leg_mods },{ '4', "Set leg start times", set_legs },{ '5', "Report generation menu", report },{ '6', "Data consistency check", data_check },{ '7', "Team disqualification operations", f_disqualify },{ '8', "Upload/Download functions", supload },{ 'C', "Configuration menu", conf_menu },{ 'S', "MS-DOS system", ms_system },{ 'q', "Exit program", 0 },{ '\0' }};/*============================================================================* 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[] ){int gross_error = 0;bool do_splash = TRUE;bool do_version = FALSE;bool do_config = FALSE;char *file_name = NULL;/*** 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] ){case 'q':do_splash = FALSE;break;case 'v':do_version = TRUE;break;case 'c' :do_config = TRUE;break;case 'x' :set_commands( &argv[0][2]);break;/*** Unknown switch*/default:usage();}}else{/*** Parameter without a switch** Must be the input file name*/if( file_name ) /* Already defined */usage();file_name = argv[0];}}/*** Parse the command line arguments*/if ( do_splash ){printf( "Mara Copyright David Purdie 1995-2008.\n" );printf( " Version %s", VERSION );#ifdef __MINGW32__printf( " (Mingwin)" );#endif#ifdef __TURBOC__printf( " (TurboC)" );#endifprintf( "\n" );printf( " This program is not to be used without the permission of\n" );printf( " David Purdie.\n" );#ifdef DISPLAY_STRUCTURESdisplay_structures();#endif}if ( do_version ){printf( "Version %s", VERSION );#if END_VALID_DATE > 0printf( "P" );#endif#if defined(LIMIT_TEAMS) && (LIMIT_TEAMS > 0)printf( " (Limited teams)" );#endifprintf( " %s %s\n", __DATE__, __TIME__ );exit( 0 );}/*** Validate parameters** Filename must be supplied*/if ( file_name == NULL )usage();/*** Wait for the user to read the copyright notice*/if ( do_splash ){while( getinp() >= ' ' );}/*** Init the screen subsystem*/init_screen();test_legal_version();/*** Main process operations** This is wrapped in a loop to make it easy to skip to the** exit process bypassing the body.*/do{/*** Process the configuration file*/if( !configure( file_name, do_config ) ){printf( "Program aborted.\n" );gross_error = 1;break;}/*** Initialise the team data file*/if( ! init_team_data() ){gross_error = 2;break;}/*** Process the top level menu*/do_menu( config.event_name, "Select option", main_menu );fix_team_data();break;} while ( FALSE);/*** Restore the screen to its original state*/if ( ! gross_error )cur( 0, n_lines - 1 );fix_screen();printf( "End of marathon\n" );exit( gross_error );}/*============================================================================** Display general usage message** Purpose:* Display general usage message* Used on command line syntax error** Parameters:* None** Returns:* exit code 3**===========================================================================*/void usage(void){init_screen();printf( "Usage : mara [options] configuration_file\n" );printf( " or : mara -v\n" );printf( "\n" );printf( "Options are:\n" );printf( " -c - Create configuration file\n" );printf( " -q - No splash screen\n" );printf( " -v - Display version then exit\n" );printf( " -x<cmds> - Execute commnads\n" );fix_screen();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();}}/*============================================================================**** Test program version**** Purpose: Determine if this version of the program has expired** test against a hard coded date.**** Parameters: Nothing**** Returns: Nothing directly****===========================================================================*/void test_legal_version(void){#if END_VALID_DATE > 0time_t today;time( &today );invalid_copy = ( today >= END_VALID_DATE );if( invalid_copy )printf( "\n\aThis is an illegal copy of this program\n" );#elseinvalid_copy = FALSE;#endif}#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 ***********************************/