diff --git a/Main/GLUTkey.cxx b/Main/GLUTkey.cxx index c60dbb0a0..948db1174 100644 --- a/Main/GLUTkey.cxx +++ b/Main/GLUTkey.cxx @@ -24,7 +24,9 @@ **************************************************************************/ -#include <config.h> +#ifdef HAVE_CONFIG_H +# include <config.h> +#endif #ifdef HAVE_WINDOWS_H # include <windows.h> @@ -42,21 +44,23 @@ #include <Weather/weather.h> #include "GLUTkey.hxx" +#include "options.hxx" #include "views.hxx" -extern int show_hud; /* HUD state */ extern int displayInstruments; /* Handle keyboard events */ void GLUTkey(unsigned char k, int x, int y) { fgCONTROLS *c; + fgOPTIONS *o; struct fgTIME *t; struct fgVIEW *v; struct fgWEATHER *w; c = current_aircraft.controls; + o = ¤t_options; t = &cur_time_params; v = ¤t_view; w = ¤t_weather; @@ -91,7 +95,7 @@ void GLUTkey(unsigned char k, int x, int y) { v->goal_view_offset = FG_PI * 1.75; return; case 72: /* H key */ - show_hud = !show_hud; + o->hud_status = !(o->hud_status); return; case 77: /* M key */ t->warp -= 60; @@ -104,6 +108,7 @@ void GLUTkey(unsigned char k, int x, int y) { return; case 90: /* Z key */ w->visibility /= 1.10; + xglFogf (GL_FOG_START, w->visibility / 10000000.0 ); xglFogf(GL_FOG_END, w->visibility); fgPrintf( FG_INPUT, FG_DEBUG, "Fog density = %.4f\n", w->visibility ); @@ -163,10 +168,15 @@ void GLUTkey(unsigned char k, int x, int y) { return; case 122: /* z key */ w->visibility *= 1.10; + xglFogf (GL_FOG_START, w->visibility / 10000000.0 ); xglFogf(GL_FOG_END, w->visibility); - fgPrintf( FG_INPUT, FG_DEBUG, "Fog density = %.4f\n", w->visibility); + fgPrintf( FG_INPUT, FG_DEBUG, + "Fog density = %.4f\n", w->visibility); return; case 27: /* ESC */ + if( fg_DebugOutput ) { + fclose( fg_DebugOutput ); + } exit(0); } } @@ -256,10 +266,15 @@ void GLUTspecialkey(int k, int x, int y) { /* $Log$ -/* Revision 1.1 1998/04/22 13:25:40 curt -/* C++ - ifing the code. -/* Starting a bit of reorganization of lighting code. +/* Revision 1.2 1998/04/24 00:49:17 curt +/* Wrapped "#include <config.h>" in "#ifdef HAVE_CONFIG_H" +/* Trying out some different option parsing code. +/* Some code reorganization. /* + * Revision 1.1 1998/04/22 13:25:40 curt + * C++ - ifing the code. + * Starting a bit of reorganization of lighting code. + * * Revision 1.33 1998/04/18 04:11:25 curt * Moved fg_debug to it's own library, added zlib support. * @@ -362,7 +377,8 @@ void GLUTspecialkey(int k, int x, int y) { * * Revision 1.4 1997/05/27 17:44:31 curt * Renamed & rearranged variables and routines. Added some initial simple - * timer/alarm routines so the flight model can be updated on a regular interval. + * timer/alarm routines so the flight model can be updated on a regular + * interval. * * Revision 1.3 1997/05/23 15:40:25 curt * Added GNU copyright headers. diff --git a/Main/GLUTkey.hxx b/Main/GLUTkey.hxx index 185afa005..58e0842df 100644 --- a/Main/GLUTkey.hxx +++ b/Main/GLUTkey.hxx @@ -33,7 +33,9 @@ #endif -#include <config.h> +#ifdef HAVE_CONFIG_H +# include <config.h> +#endif #ifdef HAVE_WINDOWS_H # include <windows.h> @@ -52,10 +54,15 @@ void GLUTspecialkey(int k, int x, int y); /* $Log$ -/* Revision 1.1 1998/04/22 13:25:41 curt -/* C++ - ifing the code. -/* Starting a bit of reorganization of lighting code. +/* Revision 1.2 1998/04/24 00:49:18 curt +/* Wrapped "#include <config.h>" in "#ifdef HAVE_CONFIG_H" +/* Trying out some different option parsing code. +/* Some code reorganization. /* + * Revision 1.1 1998/04/22 13:25:41 curt + * C++ - ifing the code. + * Starting a bit of reorganization of lighting code. + * * Revision 1.9 1998/04/21 17:02:36 curt * Prepairing for C++ integration. * diff --git a/Main/GLUTmain.cxx b/Main/GLUTmain.cxx index d45e3ae6f..1f75614f0 100644 --- a/Main/GLUTmain.cxx +++ b/Main/GLUTmain.cxx @@ -23,7 +23,9 @@ // (Log is kept at end of this file) -#include <config.h> +#ifdef HAVE_CONFIG_H +# include <config.h> +#endif #ifdef HAVE_WINDOWS_H # include <windows.h> @@ -36,11 +38,7 @@ #ifdef HAVE_STDLIB_H # include <stdlib.h> #endif -#ifdef HAVE_GETOPT_H -# include <getopt.h> -#endif -#include <Include/cmdargs.h> // Line to command line arguments #include <Include/fg_constants.h> // for VERSION #include <Include/general.h> @@ -50,7 +48,7 @@ #include <Astro/sky.hxx> #include <Astro/stars.hxx> #include <Astro/sun.hxx> -#include <Cockpit/cockpit.h> +#include <Cockpit/cockpit.hxx> #include <Debug/fg_debug.h> #include <Joystick/joystick.h> #include <Math/fg_geodesy.h> @@ -58,15 +56,15 @@ #include <Math/polar.h> #include <Scenery/scenery.h> #include <Scenery/tilemgr.hxx> -#include <Time/event.h> -#include <Time/fg_time.h> -#include <Time/fg_timer.h> +#include <Time/event.hxx> +#include <Time/fg_time.hxx> +#include <Time/fg_timer.hxx> #include <Time/sunpos.hxx> #include <Weather/weather.h> #include "GLUTkey.hxx" #include "fg_init.hxx" -#include "fg_getopt.h" +#include "options.hxx" #include "views.hxx" @@ -80,12 +78,10 @@ static GLint winWidth, winHeight; // Another hack int use_signals = 0; -// Yet another hack. This one used by the HUD code. Michele -int show_hud; - // Yet another other hack. Used for my prototype instrument code. (Durk) int displayInstruments; +/* // The following defines flight gear options. Because glutlib will also // want to parse its own options, those options must not be included here // or they will get parsed by the main program option parser. Hence case @@ -181,6 +177,7 @@ const char *DefaultRootDir = "\\Flightgear"; const char *DefaultAircraft = "Navion.acf"; const char *DefaultDebuglog = "fgdebug.log"; const int DefaultViewMode = HUD_VIEW; +*/ // Debug defaults handled in fg_debug.c @@ -203,7 +200,7 @@ static void fgInitVisuals( void ) { xglLightfv( GL_LIGHT0, GL_POSITION, l->sun_vec ); xglFogi (GL_FOG_MODE, GL_LINEAR); - xglFogf (GL_FOG_START, 10.0); + xglFogf (GL_FOG_START, w->visibility / 10000000.0 ); xglFogf (GL_FOG_END, w->visibility); // xglFogf (GL_FOG_DENSITY, w->visibility); xglHint (GL_FOG_HINT, GL_NICEST /* GL_FASTEST */ ); @@ -320,6 +317,7 @@ static void fgUpdateInstrViewParams( void ) { // Update all Visuals (redraws anything graphics related) static void fgRenderFrame( void ) { struct fgLIGHT *l; + fgOPTIONS *o; struct fgTIME *t; struct fgVIEW *v; double angle; @@ -327,6 +325,7 @@ static void fgRenderFrame( void ) { GLfloat black[4] = { 0.0, 0.0, 0.0, 1.0 }; l = &cur_light_params; + o = ¤t_options; t = &cur_time_params; v = ¤t_view; @@ -396,14 +395,15 @@ static void fgRenderFrame( void ) { xglTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE ) ; xglHint( GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST ) ; // set base color (I don't think this is doing anything here) - xglColor4fv(white); + xglMaterialfv (GL_FRONT, GL_AMBIENT, white); + xglMaterialfv (GL_FRONT, GL_DIFFUSE, white); fgTileMgrRender(); xglDisable( GL_TEXTURE_2D ); // display HUD - if( show_hud ) { + if( o->hud_status ) { fgCockpitUpdate(); } @@ -475,91 +475,8 @@ void fgInitTimeDepCalcs( void ) { } -// Scenery management routines - -/* static void fgSceneryInit_OLD() { */ - /* make scenery */ -/* scenery = fgSceneryCompile_OLD(); - runway = fgRunwayHack_OLD(0.69, 53.07); -} */ - - -/* create the scenery */ -/* GLint fgSceneryCompile_OLD() { - GLint scenery; - - scenery = mesh2GL(mesh_ptr_OLD); - - return(scenery); -} -*/ - -/* hack in a runway */ -/* GLint fgRunwayHack_OLD(double width, double length) { - static GLfloat concrete[4] = { 0.5, 0.5, 0.5, 1.0 }; - static GLfloat line[4] = { 0.9, 0.9, 0.9, 1.0 }; - int i; - int num_lines = 16; - float line_len, line_width_2, cur_pos; - - runway = xglGenLists(1); - xglNewList(runway, GL_COMPILE); - */ - /* draw concrete */ -/* xglBegin(GL_POLYGON); - xglMaterialfv( GL_FRONT, GL_AMBIENT_AND_DIFFUSE, concrete ); - xglNormal3f(0.0, 0.0, 1.0); - - xglVertex3d( 0.0, -width/2.0, 0.0); - xglVertex3d( 0.0, width/2.0, 0.0); - xglVertex3d(length, width/2.0, 0.0); - xglVertex3d(length, -width/2.0, 0.0); - xglEnd(); - */ - /* draw center line */ -/* xglMaterialfv( GL_FRONT, GL_AMBIENT_AND_DIFFUSE, line ); - line_len = length / ( 2 * num_lines + 1); - printf("line_len = %.3f\n", line_len); - line_width_2 = 0.02; - cur_pos = line_len; - for ( i = 0; i < num_lines; i++ ) { - xglBegin(GL_POLYGON); - xglVertex3d( cur_pos, -line_width_2, 0.005); - xglVertex3d( cur_pos, line_width_2, 0.005); - cur_pos += line_len; - xglVertex3d( cur_pos, line_width_2, 0.005); - xglVertex3d( cur_pos, -line_width_2, 0.005); - cur_pos += line_len; - xglEnd(); - } - - xglEndList(); - - return(runway); -} -*/ - -/* draw the scenery */ -/*static void fgSceneryDraw_OLD() { - static float z = 32.35; - - xglPushMatrix(); - - xglCallList(scenery); - - printf("*** Drawing runway at %.2f\n", z); - - xglTranslatef( -398391.28, 120070.41, 32.35); - xglRotatef(170.0, 0.0, 0.0, 1.0); - xglCallList(runway); - - xglPopMatrix(); -} -*/ - - -// What should we do when we have nothing else to do? How about get -// ready for the next move and update the display? +// What should we do when we have nothing else to do? Let's get ready +// for the next move and update the display? static void fgMainLoop( void ) { static int remainder = 0; int elapsed, multi_loop; @@ -664,19 +581,10 @@ static void fgReshape( int width, int height ) { } -// Main ... -int main( int argc, char *argv[] ) { - fgFLIGHT *f; - int parse_result; // Used in command line argument. - - f = current_aircraft.flight; - // First things first... We must have startup options dealt with. - - printf("Flight Gear: Version %s\n\n", VERSION); - - // Initialize the Window/Graphics environment. - - // initialize GLUT +// Initialize GLUT and define a main window +int fgGlutInit( int argc, char **argv ) { + // GLUT will extract all glut specific options so later on we only + // need wory about our own. xglutInit(&argc, argv); // Define Display Parameters @@ -688,82 +596,92 @@ int main( int argc, char *argv[] ) { // Initialize windows xglutCreateWindow("Flight Gear"); - // xglutInit above will extract all non-general program command line. - // We only need wory about our own. + return(1); +} - parse_result = getargs( argc, argv, OptsDefined, CmdLineOptions, NULL); - switch( parse_result ) { - case ALLDONE: - break; +// Initialize GLUT event handlers +int fgGlutInitEvents( void ) { + // call fgReshape() on window resizes + xglutReshapeFunc( fgReshape ); - case HELP: - print_desc( OptsDefined, CmdLineOptions ); - exit(0); + // call GLUTkey() on keyboard event + xglutKeyboardFunc( GLUTkey ); + glutSpecialFunc( GLUTspecialkey ); - case INVALID: - default: - printf( "Flight Gear: Command line invalid."); - exit(0); + // call fgMainLoop() whenever there is + // nothing else to do + xglutIdleFunc( fgMainLoop ); + + // draw the scene + xglutDisplayFunc( fgRenderFrame ); + + return(1); +} + + +// Main ... +int main( int argc, char **argv ) { + fgFLIGHT *f; + int result; // Used in command line argument. + + f = current_aircraft.flight; + + // Initialize the debugging output system + fgInitDebug(); + + fgPrintf(FG_GENERAL, FG_INFO, "Flight Gear: Version %s\n\n", VERSION); + + // Initialize the Window/Graphics environment. + if( !fgGlutInit(argc, argv) ) { + fgPrintf( FG_GENERAL, FG_EXIT, "GLUT initialization failed ...\n" ); } - // Deal with the effects of options no set by manipulating the command - // line, or possibly set to invalid states. + // Parse remaining command line options + result = current_options.parse(argc, argv); - if(( viewArg >= 0) && (viewArg <= 1)) { - show_hud = viewArg; // For now view_mode TRUE - no HUD, else show_hud. - } else { - show_hud = DefaultViewMode; + if ( result != FG_OPTIONS_OK ) { + // Something must have gone horribly wrong with the command + // line parsing or maybe the user just requested help ... :-) + current_options.usage(); + fgPrintf( FG_GENERAL, FG_EXIT, "\nShutting down ...\n"); } - // All other command line option responses are handled in the various - // initialization routines (or ignored if not implemented. - // This is the general house keeping init routine. It initializes the // debug trail scheme and then any other stuff. if( !fgInitGeneral()) { - - // This is the top level init routine which calls all the other - // subsystem initialization routines. If you are adding a - // subsystem to flight gear, its initialization call should - // located in this routine. - if( !fgInitSubsystems()) { - - // setup view parameters, only makes GL calls - fgInitVisuals(); - - if ( use_signals ) { - // init timer routines, signals, etc. Arrange for an - // alarm signal to be generated, etc. - fgInitTimeDepCalcs(); - } - - // Initialize the GLUT Event Handlers. - - // call fgReshape() on window resizes - xglutReshapeFunc( fgReshape ); - - // call key() on keyboard event - xglutKeyboardFunc( GLUTkey ); - glutSpecialFunc( GLUTspecialkey ); - - // call fgMainLoop() whenever there is - // nothing else to do - xglutIdleFunc( fgMainLoop ); - - // draw the scene - xglutDisplayFunc( fgRenderFrame ); - - // pass control off to the GLUT event handler - glutMainLoop(); - - } // End if subsystems initialize ok - } // End if general initializations went ok - - if( fg_DebugOutput ) { - fclose( fg_DebugOutput ); + fgPrintf( FG_GENERAL, FG_EXIT, "General initializations failed ...\n" ); } + + // This is the top level init routine which calls all the other + // subsystem initialization routines. If you are adding a + // subsystem to flight gear, its initialization call should + // located in this routine. + if( !fgInitSubsystems()) { + fgPrintf( FG_GENERAL, FG_EXIT, + "Subsystem initializations failed ...\n" ); + } + + // setup view parameters, only makes GL calls + fgInitVisuals(); + + if ( use_signals ) { + // init timer routines, signals, etc. Arrange for an + // alarm signal to be generated, etc. + fgInitTimeDepCalcs(); + } + + // Initialize the GLUT Event Handlers. + if( !fgGlutInitEvents() ) { + fgPrintf( FG_GENERAL, FG_EXIT, + "GLUT event handler initialization failed ...\n" ); + } + + // pass control off to the GLUT event handler + glutMainLoop(); + + // we never actually get here ... but just in case ... :-) return(0); } @@ -777,6 +695,11 @@ extern "C" { // $Log$ +// Revision 1.3 1998/04/24 00:49:18 curt +// Wrapped "#include <config.h>" in "#ifdef HAVE_CONFIG_H" +// Trying out some different option parsing code. +// Some code reorganization. +// // Revision 1.2 1998/04/22 13:25:41 curt // C++ - ifing the code. // Starting a bit of reorganization of lighting code. @@ -998,7 +921,7 @@ extern "C" { // Changes due to changing sunpos interface. // // Revision 1.5 1997/08/06 21:08:32 curt -// Sun position now//really* works (I think) ... I still have sun time warping +// Sun position now really* works (I think) ... I still have sun time warping // code in place, probably should remove it soon. // // Revision 1.4 1997/08/06 15:41:26 curt diff --git a/Main/Makefile.am b/Main/Makefile.am index dcd61ec5a..30292e068 100644 --- a/Main/Makefile.am +++ b/Main/Makefile.am @@ -8,8 +8,8 @@ fg_SOURCES = \ GLUTkey.cxx GLUTkey.hxx \ GLUTmain.cxx \ fg_config.h \ - fg_getopt.c fg_getopt.h \ fg_init.cxx fg_init.hxx \ + options.cxx options.hxx \ views.cxx views.hxx fg_LDADD = \ diff --git a/Main/Makefile.in b/Main/Makefile.in index e39b4474c..3d13ea6f3 100644 --- a/Main/Makefile.in +++ b/Main/Makefile.in @@ -81,8 +81,8 @@ fg_SOURCES = \ GLUTkey.cxx GLUTkey.hxx \ GLUTmain.cxx \ fg_config.h \ - fg_getopt.c fg_getopt.h \ fg_init.cxx fg_init.hxx \ + options.cxx options.hxx \ views.cxx views.hxx fg_LDADD = \ @@ -116,7 +116,7 @@ X_CFLAGS = @X_CFLAGS@ X_LIBS = @X_LIBS@ X_EXTRA_LIBS = @X_EXTRA_LIBS@ X_PRE_LIBS = @X_PRE_LIBS@ -fg_OBJECTS = GLUTkey.o GLUTmain.o fg_getopt.o fg_init.o views.o +fg_OBJECTS = GLUTkey.o GLUTmain.o fg_init.o options.o views.o fg_DEPENDENCIES = $(top_builddir)/Simulator/Aircraft/libAircraft.la \ $(top_builddir)/Simulator/Astro/libAstro.la \ $(top_builddir)/Simulator/Autopilot/libAutopilot.la \ @@ -139,19 +139,15 @@ CXXFLAGS = @CXXFLAGS@ CXXCOMPILE = $(CXX) $(DEFS) $(INCLUDES) $(CPPFLAGS) $(CXXFLAGS) LTCXXCOMPILE = $(LIBTOOL) --mode=compile $(CXX) $(DEFS) $(INCLUDES) $(CPPFLAGS) $(CXXFLAGS) CXXLINK = $(LIBTOOL) --mode=link $(CXX) $(CXXFLAGS) $(LDFLAGS) -o $@ -CFLAGS = @CFLAGS@ -COMPILE = $(CC) $(DEFS) $(INCLUDES) $(CPPFLAGS) $(CFLAGS) -LTCOMPILE = $(LIBTOOL) --mode=compile $(CC) $(DEFS) $(INCLUDES) $(CPPFLAGS) $(CFLAGS) -LINK = $(LIBTOOL) --mode=link $(CC) $(CFLAGS) $(LDFLAGS) -o $@ -DIST_COMMON = README Makefile.am Makefile.in runfg.bat.in runfg.in +DIST_COMMON = Makefile.am Makefile.in runfg.bat.in runfg.in DISTFILES = $(DIST_COMMON) $(SOURCES) $(HEADERS) $(TEXINFOS) $(EXTRA_DIST) TAR = tar GZIP = --best -DEP_FILES = .deps/GLUTkey.P .deps/GLUTmain.P .deps/fg_getopt.P \ -.deps/fg_init.P .deps/views.P +DEP_FILES = .deps/GLUTkey.P .deps/GLUTmain.P .deps/fg_init.P \ +.deps/options.P .deps/views.P CXXMKDEP = $(CXX) -M $(DEFS) $(INCLUDES) $(CPPFLAGS) $(CXXFLAGS) SOURCES = $(fg_SOURCES) OBJECTS = $(fg_OBJECTS) diff --git a/Main/fg_getopt.c b/Main/fg_getopt.c deleted file mode 100644 index 18ad92b4d..000000000 --- a/Main/fg_getopt.c +++ /dev/null @@ -1,369 +0,0 @@ -/**************************************************************************** -* Modified from the original version found in SciTech's library. Note that -* this in fact may have been copied/derived from a much earlier work as I -* remember seeing a version of it 10 years ago for use in CP/M and it wasn't -* new then. I peeled a routine out of the end of this as it was an alternative -* for Windows code. CH -* -* Copyright (C) 1991-1997 SciTech Software, Inc. -* All rights reserved. -* -* ====================================================================== -* This library is free software; you can use it and/or -* modify it under the terms of the SciTech MGL Software License. -* -* This library is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* SciTech MGL Software License for more details. -* ====================================================================== -* -* Filename: $Workfile: getopt.c $ -* Version: $Revision$ -* -* Language: ANSI C -* Environment: any -* -* Description: This module contains code to parse the command line, -* extracting options and parameters in standard System V -* style. -* -* $Date$ $Author$ -* -* $Id$ -* (Log is kept at end of this file) -* -****************************************************************************/ - -#include <stdio.h> -#include <string.h> -#include <ctype.h> -#include "fg_getopt.h" - -/*------------------------- Global variables ------------------------------*/ - -int nextargv = 1; /* Index into argv array */ -char *nextchar = NULL; /* Pointer to next character */ - -/*-------------------------- Implementation -------------------------------*/ - -#ifdef __WIN32__ -#define IS_SWITCH_CHAR(c) (c == '-') || (c == '/') -#define IS_NOT_SWITCH_CHAR(c) (c != '-') && (c != '/') -#else -#define IS_SWITCH_CHAR(c) (c == '-') -#define IS_NOT_SWITCH_CHAR(c) (c != '-') -#endif - -int fg_getopt(int argc,char **argv,char *format,char **argument) -/**************************************************************************** -* -* Function: getopt -* Parameters: argc - Value passed to program through argc -* variable in the function main. -* argv - Pointer to the argv array that is passed to -* the program in function main. -* format - A string representing the expected format -* of the command line options that need to be -* parsed. -* argument - Pointer to optional argument on command -* line. -* -* Returns: Character code representing the next option parsed from the -* command line by getopt. Returns ALLDONE (-1) when there are -* no more parameters to be parsed on the command line, -* PARAMETER (-2) when the argument being parsed is a -* parameter and not an option switch and lastly INVALID (-3) -* if an error occured while parsing the command line. -* -* Description: Function to parse the command line option switches in -* UNIX System V style. When getopt is called, it returns the -* character code of the next valid option that is parsed from -* the command line as specified by the Format string. The -* format string should be in the following form: -* -* "abcd:e:f:" -* -* where a,b and c represent single switch style options and -* the character code returned by getopt is the only value -* returned. Also d, e and f represent options that expect -* arguments immediately after them on the command line. The -* argument that follows the option on the command line is -* returned via a reference in the pointer argument. Thus -* a valid command line for this format string might be: -* -* myprogram -adlines /b /f format infile outfile -* -* where a and b will be returned as single character options -* with no argument, while d is returned with the argument -* lines and f is returned with the argument format. Note that -* either UNIX style or MS-DOS command switches may be used -* interchangeably under MSDOS, but under UNIX only the UNIX -* style switches are supported. -* -* When getopt returns with PARAMETER (we attempted to parse -* a paramter, not an option), the global variable NextArgv -* will hold an index in the argv array to the argument on the -* command line AFTER the options, ie in the above example the -* string 'infile'. If the parameter is successfully used, -* NextArgv should be incremented and getopt can be called -* again to parse any more options. Thus you can also have -* options interspersed throught the command line. eg: -* -* myprogram -adlines infile /b outfile /f format -* -* can be made to be a valid form of the above command line. -* -****************************************************************************/ -{ - char ch; - char *formatchar; - - if (argc > nextargv) { - if (nextchar == NULL) { - nextchar = argv[nextargv]; /* Index next argument */ - if(nextchar == NULL) { - nextargv++; - return ALLDONE; /* No more options */ - } - if(IS_NOT_SWITCH_CHAR(*nextchar)) { - nextchar = NULL; - return PARAMETER; /* We have a parameter */ - } - nextchar++; /* Move past switch operator */ - if(IS_SWITCH_CHAR(*nextchar)) { - nextchar = NULL; - return INVALID; /* Ignore rest of line */ - } - } - - if ((ch = *(nextchar++)) == 0) { - nextchar = NULL; - return INVALID; /* No options on line */ - } - - if (ch == ':' || (formatchar = strchr(format, ch)) == NULL) - return INVALID; - - if (*(++formatchar) == ':') { /* Expect an argument after option */ - nextargv++; - if (*nextchar == 0) { - if (argc <= nextargv) - return INVALID; - nextchar = argv[nextargv++]; - } - *argument = nextchar; - nextchar = NULL; - } - else { /* We have a switch style option */ - if (*nextchar == 0) { - nextargv++; - nextchar = NULL; - } - *argument = NULL; - } - return ch; /* return the option specifier */ - } - nextchar = NULL; - nextargv++; - return ALLDONE; /* no arguments on command line */ -} - -static int parse_option(Option *optarr, char *argument) -/**************************************************************************** -* -* Function: parse_option -* Parameters: optarr - Description for the option we are parsing -* argument - String to parse -* Returns: INVALID on error, ALLDONE on success. -* -* Description: Parses the argument string depending on the type of argument -* that is expected, filling in the argument for that option. -* Note that to parse a string, we simply return a pointer -* to argument. -* -****************************************************************************/ -{ - int num_read = 0; - - switch ((int)(optarr->type)) { - case OPT_INTEGER: - num_read = sscanf(argument,"%d",(int*)optarr->arg); - break; - case OPT_HEX: - num_read = sscanf(argument,"%x",(int*)optarr->arg); - break; - case OPT_OCTAL: - num_read = sscanf(argument,"%o",(int*)optarr->arg); - break; - case OPT_UNSIGNED: - num_read = sscanf(argument,"%u",(uint*)optarr->arg); - break; - case OPT_LINTEGER: - num_read = sscanf(argument,"%ld",(long*)optarr->arg); - break; - case OPT_LHEX: - num_read = sscanf(argument,"%lx",(long*)optarr->arg); - break; - case OPT_LOCTAL: - num_read = sscanf(argument,"%lo",(long*)optarr->arg); - break; - case OPT_LUNSIGNED: - num_read = sscanf(argument,"%lu",(ulong*)optarr->arg); - break; - case OPT_FLOAT: - num_read = sscanf(argument,"%f",(float*)optarr->arg); - break; - case OPT_DOUBLE: - num_read = sscanf(argument,"%lf",(double*)optarr->arg); - break; - case OPT_LDOUBLE: - num_read = sscanf(argument,"%Lf",(long double*)optarr->arg); - break; - case OPT_STRING: - num_read = 1; /* This always works */ - *((char**)optarr->arg) = argument; - break; - default: - return INVALID; - } - - if (num_read == 0) - return INVALID; - else - return ALLDONE; -} - -int getargs( int argc,char - *argv[], - int num_opt, - Option **optarr, - int (*do_param)(char *param,int num)) - -/**************************************************************************** -* -* Function: getargs -* Parameters: argc - Number of arguments on command line -* argv - Array of command line arguments -* num_opt - Number of options in option array -* optarr - Array to specify how to parse the command line -* do_param - Routine to handle a command line parameter -* Returns: ALLDONE, INVALID or HELP -* -* Description: Function to parse the command line according to a table of -* options. This routine calls getopt above to parse each -* individual option and attempts to parse each option into -* a variable of the specified type. The routine can parse -* integers and long integers in either decimal, octal, -* hexadecimal notation, unsigned integers and unsigned longs, -* strings and option switches. Option switches are simply -* boolean variables that get turned on if the switch was -* parsed. -* -* Parameters are extracted from the command line by calling -* a user supplied routine do_param() to handle each parameter -* as it is encountered. The routine do_param() should accept -* a pointer to the parameter on the command line and an -* integer representing how many parameters have been -* encountered (ie: 1 if this is the first parameter, 10 if -* it is the 10th etc), and return ALLDONE upon successfully -* parsing it or INVALID if the parameter was invalid. -* -* We return either ALLDONE if all the options were -* successfully parsed, INVALID if an invalid option was -* encountered or HELP if any of -h, -H or -? were present -* on the command line. -* -****************************************************************************/ -{ - int i,opt; - char *argument; - int param_num = 1; - char cmdstr[MAXARG*2 + 4]; - - /* Build the command string from the array of options */ - - strcpy(cmdstr,"hH?"); - for (i = 0,opt = 3; i < num_opt; i++,opt++) { - cmdstr[opt] = optarr[i]->opt; - if (optarr[i]->type != OPT_SWITCH) { - cmdstr[++opt] = ':'; - } - } - cmdstr[opt] = '\0'; - - while (true) { - opt = fg_getopt(argc,argv,cmdstr,&argument); - switch (opt) { - case 'H': - case 'h': - case '?': - return HELP; - case ALLDONE: - return ALLDONE; - case INVALID: - return INVALID; - case PARAMETER: - if (do_param == NULL) - return INVALID; - if (do_param(argv[nextargv],param_num) == INVALID) - return INVALID; - nextargv++; - param_num++; - break; - default: - - /* Search for the option in the option array. We are - * guaranteed to find it. - */ - - for (i = 0; i < num_opt; i++) { - if (optarr[i]->opt == opt) - break; - } - if (optarr[i]->type == OPT_SWITCH) - *((bool*)optarr[i]->arg) = true; - else { - if (parse_option( optarr[i],argument) == INVALID) - return INVALID; - } - break; - } - } -} - -void print_desc(int num_opt,Option **optarr) -/**************************************************************************** -* -* Function: print_desc -* Parameters: num_opt - Number of options in the table -* optarr - Table of option descriptions -* -* Description: Prints the description of each option in a standard format -* to the standard output device. The description for each -* option is obtained from the table of options. -* -****************************************************************************/ -{ - int i; - - for (i = 0; i < num_opt; i++) { - if (optarr[i]->type == OPT_SWITCH) - printf(" -%c %s\n",optarr[i]->opt,optarr[i]->desc); - else - printf(" -%c<arg> %s\n",optarr[i]->opt,optarr[i]->desc); - } -} - -// End of getopt.c - - -/* $Log$ -/* Revision 1.2 1998/03/16 21:13:07 curt -/* Patch to fix Solaris function name contention with "getopt()" - -/* johns@ultra2.cs.umr.edu (John Stone) -/* - * Revision 1.1 1998/02/13 00:23:40 curt - * Initial revision. - * - */ diff --git a/Main/fg_getopt.h b/Main/fg_getopt.h deleted file mode 100644 index a6799f48d..000000000 --- a/Main/fg_getopt.h +++ /dev/null @@ -1,145 +0,0 @@ -/**************************************************************************** -* -* Copyright (C) 1991-1997 SciTech Software, Inc. -* All rights reserved. -* -* ====================================================================== -* This library is free software; you can use it and/or -* modify it under the terms of the SciTech MGL Software License. -* -* This library is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* SciTech MGL Software License for more details. -* ====================================================================== -* -* Filename: $Workfile: getopt.h $ -* Version: $Revision$ -* -* Language: ANSI C -* Environment: any -* -* Description: Header file for command line parsing module. This module -* contains code to parse the command line, extracting options -* and parameters in standard System V style. -* -* $Date$ $Author$ -* -* $Id$ -* (Log is kept at end of this file) -* -****************************************************************************/ - - -#ifndef __GETOPT_H -#define __GETOPT_H - - -#ifdef __cplusplus -extern "C" { -#endif - - -//#ifndef __DEBUG_H -//#include "debug.h" -//#endif - -/*---------------------------- Typedef's etc -----------------------------*/ - -#define ALLDONE -1 -#define PARAMETER -2 -#define INVALID -3 -#define HELP -4 - -#define MAXARG 80 - -/* Option type sepecifiers */ - -#define OPT_INTEGER 'd' -#define OPT_HEX 'h' -#define OPT_OCTAL 'o' -#define OPT_UNSIGNED 'u' -#define OPT_LINTEGER 'D' -#define OPT_LHEX 'H' -#define OPT_LOCTAL 'O' -#define OPT_LUNSIGNED 'U' -#define OPT_FLOAT 'f' -#define OPT_DOUBLE 'F' -#define OPT_LDOUBLE 'L' -#define OPT_STRING 's' -#define OPT_SWITCH '!' - -// I need to generate a typedefs file for this. -// -#ifndef uchar -typedef unsigned char uchar; -#endif -#ifndef uint -typedef unsigned int uint; -#endif - -#ifndef ulong -typedef unsigned long ulong; -#endif - -#ifndef bool -#ifndef BOOL -typedef int BOOL; -#endif -typedef BOOL bool; -#endif - -#ifndef true -#ifndef TRUE -#define TRUE 1 -#define FALSE 0 -#endif -#define true TRUE -#define false FALSE -#endif - -typedef struct { - uchar opt; /* The letter to describe the option */ - uchar type; /* Type descriptor for the option */ - void *arg; /* Place to store the argument */ - char *desc; /* Description for this option */ - } Option; - -#define NUM_OPT(a) sizeof(a) / sizeof(Option) - - -/*--------------------------- Global variables ---------------------------*/ - -extern int nextargv; -extern char *nextchar; - -/*------------------------- Function Prototypes --------------------------*/ - -// extern int getopt(int argc,char **argv,char *format,char **argument); - -extern int getargs(int argc, char *argv[],int num_opt, Option ** optarr, - int (*do_param)(char *param,int num)); - -extern void print_desc(int num_opt, Option **optarr); // Not original code - - -#ifdef __cplusplus -} -#endif - - -#endif - - -/* $Log$ -/* Revision 1.3 1998/04/22 13:25:43 curt -/* C++ - ifing the code. -/* Starting a bit of reorganization of lighting code. -/* - * Revision 1.2 1998/04/21 17:02:41 curt - * Prepairing for C++ integration. - * - * Revision 1.1 1998/02/13 00:23:39 curt - * Initial revision. - * - */ diff --git a/Main/fg_init.cxx b/Main/fg_init.cxx index d1f8317ae..ef22e2fce 100644 --- a/Main/fg_init.cxx +++ b/Main/fg_init.cxx @@ -26,12 +26,13 @@ **************************************************************************/ -#include <config.h> +#ifdef HAVE_CONFIG_H +# include <config.h> +#endif #include <stdio.h> #include <stdlib.h> -#include <Include/cmdargs.h> #include <Include/fg_constants.h> #include <Include/general.h> @@ -42,14 +43,14 @@ #include <Astro/stars.hxx> #include <Astro/sun.hxx> #include <Autopilot/autopilot.h> -#include <Cockpit/cockpit.h> +#include <Cockpit/cockpit.hxx> #include <Debug/fg_debug.h> #include <Joystick/joystick.h> #include <Math/fg_random.h> #include <Scenery/scenery.h> #include <Scenery/tilemgr.hxx> -#include <Time/event.h> -#include <Time/fg_time.h> +#include <Time/event.hxx> +#include <Time/fg_time.hxx> #include <Time/light.hxx> #include <Time/sunpos.hxx> #include <Weather/weather.h> @@ -68,31 +69,27 @@ int fgInitGeneral( void ) { g = &general; - fgInitDebug(); - - fgPrintf( FG_GENERAL, FG_INFO, "General Initialization\n" ); - fgPrintf( FG_GENERAL, FG_INFO, "======= ==============\n" ); - - /* seed the random number generater */ - fg_srandom(); - - // determine the fg root path. The command line parser getargs() will - // fill in a root directory if the option was used. - + // determine the fg root path. if( !(g->root_dir) ) { // If not set by command line test for environmental var.. g->root_dir = getenv("FG_ROOT"); if ( !g->root_dir ) { // No root path set? Then assume, we will exit if this is // wrong when looking for support files. - g->root_dir = (char *)DefaultRootDir; + fgPrintf( FG_GENERAL, FG_EXIT, "%s %s\n", + "Cannot continue without environment variable FG_ROOT", + "being defined."); } } fgPrintf( FG_GENERAL, FG_INFO, "FG_ROOT = %s\n\n", g->root_dir); - // Dummy value can be changed if future initializations - // fail a critical task. - return ( 0 /* FALSE */ ); + fgPrintf( FG_GENERAL, FG_INFO, "General Initialization\n" ); + fgPrintf( FG_GENERAL, FG_INFO, "======= ==============\n" ); + + // seed the random number generater + fg_srandom(); + + return ( 1 ); } @@ -104,9 +101,6 @@ int fgInitGeneral( void ) { int fgInitSubsystems( void ) { double cur_elev; - // Ok will be flagged only if we get EVERYTHING done. - int ret_val = 1 /* TRUE */; - fgFLIGHT *f; struct fgLIGHT *l; struct fgTIME *t; @@ -397,24 +391,28 @@ int fgInitSubsystems( void ) { fgPrintf( FG_GENERAL, FG_EXIT, "Error in Joystick initialization!\n" ); } - // Autopilot init added here, by Jeff Goeke-Smith - fgAPInit(¤t_aircraft); - // end added section; + // Autopilot init added here, by Jeff Goeke-Smith + fgAPInit(¤t_aircraft); // One more try here to get the sky synced up fgSkyColorsInit(); - ret_val = 0; fgPrintf(FG_GENERAL, FG_INFO,"\n"); - return ret_val; + + return(1); } /* $Log$ -/* Revision 1.1 1998/04/22 13:25:44 curt -/* C++ - ifing the code. -/* Starting a bit of reorganization of lighting code. +/* Revision 1.2 1998/04/24 00:49:20 curt +/* Wrapped "#include <config.h>" in "#ifdef HAVE_CONFIG_H" +/* Trying out some different option parsing code. +/* Some code reorganization. /* + * Revision 1.1 1998/04/22 13:25:44 curt + * C++ - ifing the code. + * Starting a bit of reorganization of lighting code. + * * Revision 1.56 1998/04/18 04:11:28 curt * Moved fg_debug to it's own library, added zlib support. * diff --git a/Main/options.cxx b/Main/options.cxx new file mode 100644 index 000000000..d1cb3976f --- /dev/null +++ b/Main/options.cxx @@ -0,0 +1,194 @@ +// +// options.cxx -- class to handle command line options +// +// Written by Curtis Olson, started April 1998. +// +// Copyright (C) 1998 Curtis L. Olson - curt@me.umn.edu +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License as +// published by the Free Software Foundation; either version 2 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +// +// $Id$ +// (Log is kept at end of this file) + + +#include <math.h> // rint() +#include <stdio.h> +#include <stdlib.h> // atof() +#include <string.h> + +#include <Debug/fg_debug.h> + +#include "options.hxx" + + +// Defined the shared options class here +fgOPTIONS current_options; + + +// Constructor +fgOPTIONS::fgOPTIONS( void ) { + // set initial values/defaults + + hud_status = 0; + time_offset = 0; +} + + +// parse time string in the form of [+-]hh:mm:ss, returns the value in seconds +static double parse_time(char *time_str) { + char num[256]; + double hours, minutes, seconds; + double result = 0.0; + int sign = 1; + int i; + + // printf("parse_time(): %s\n", time_str); + + // check for sign + if ( strlen(time_str) ) { + if ( time_str[0] == '+' ) { + sign = 1; + time_str++; + } else if ( time_str[0] == '-' ) { + sign = -1; + time_str++; + } + } + // printf("sign = %d\n", sign); + + // get hours + if ( strlen(time_str) ) { + i = 0; + while ( (time_str[0] != ':') && (time_str[0] != '\0') ) { + num[i] = time_str[0]; + time_str++; + i++; + } + if ( time_str[0] == ':' ) { + time_str++; + } + num[i] = '\0'; + hours = atof(num); + // printf("hours = %.2lf\n", hours); + + result += hours * 3600.0; + } + + // get minutes + if ( strlen(time_str) ) { + i = 0; + while ( (time_str[0] != ':') && (time_str[0] != '\0') ) { + num[i] = time_str[0]; + time_str++; + i++; + } + if ( time_str[0] == ':' ) { + time_str++; + } + num[i] = '\0'; + minutes = atof(num); + // printf("minutes = %.2lf\n", minutes); + + result += minutes * 60.0; + } + + // get seconds + if ( strlen(time_str) ) { + i = 0; + while ( (time_str[0] != ':') && (time_str[0] != '\0') ) { + num[i] = time_str[0]; + time_str++; + i++; + } + num[i] = '\0'; + seconds = atof(num); + // printf("seconds = %.2lf\n", seconds); + + result += seconds; + } + + return(sign * result); +} + + +// parse time offset command line option +static int parse_time_offset(char *time_str) { + int result; + + time_str += 14; + + // printf("time offset = %s\n", time_str); + + result = (int)rint(parse_time(time_str)); + + printf("parse_time_offset(): %d\n", result); + + return( result ); + +} + + +// Parse the command line options +int fgOPTIONS::parse( int argc, char **argv ) { + int i = 1; + + fgPrintf(FG_GENERAL, FG_INFO, "Processing arguments\n"); + + while ( i < argc ) { + fgPrintf(FG_GENERAL, FG_INFO, "argv[%d] = %s\n", i, argv[i]); + + if ( strcmp(argv[i], "--disable-hud") == 0 ) { + hud_status = 0; + } else if ( strcmp(argv[i], "--enable-hud") == 0 ) { + hud_status = 1; + } else if ( (strcmp(argv[i], "--help") == 0) || + (strcmp(argv[i], "-h") == 0) ) { + // help/usage request + return(FG_OPTIONS_HELP); + } else if ( strncmp(argv[i], "--time-offset=", 14) == 0 ) { + time_offset = parse_time_offset(argv[i]); + } else { + return(FG_OPTIONS_ERROR); + } + + i++; + } + + return(FG_OPTIONS_OK); +} + + +// Print usage message +void fgOPTIONS::usage ( void ) { + printf("Usage: fg [ options ... ]\n"); + printf("\t--disable-hud: disable heads up display\n"); + printf("\t--enable-hud: enable heads up display\n"); + printf("\t--help -h: print usage\n"); + printf("\t--time-offset=[+-]hh:mm:ss: offset local time by this amount\n"); +} + + +// Destructor +fgOPTIONS::~fgOPTIONS( void ) { +} + + +// $Log$ +// Revision 1.1 1998/04/24 00:49:21 curt +// Wrapped "#include <config.h>" in "#ifdef HAVE_CONFIG_H" +// Trying out some different option parsing code. +// Some code reorganization. +// +// diff --git a/Main/options.hxx b/Main/options.hxx new file mode 100644 index 000000000..566ab99e6 --- /dev/null +++ b/Main/options.hxx @@ -0,0 +1,77 @@ +// +// options.hxx -- class to handle command line options +// +// Written by Curtis Olson, started April 1998. +// +// Copyright (C) 1998 Curtis L. Olson - curt@me.umn.edu +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License as +// published by the Free Software Foundation; either version 2 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +// +// $Id$ +// (Log is kept at end of this file) + + +#ifndef _OPTIONS_HXX +#define _OPTIONS_HXX + + +#ifndef __cplusplus +# error This library requires C++ +#endif + + +#define FG_OPTIONS_OK 0 +#define FG_OPTIONS_HELP 1 +#define FG_OPTIONS_ERROR 2 + + +class fgOPTIONS { + +public: + + // HUD on/off + int hud_status; + + // Offset true time by this many seconds + int time_offset; + + // Constructor + fgOPTIONS( void ); + + // Parse the command line options + int parse( int argc, char **argv ); + + // Print usage message + void usage ( void ); + + // Destructor + ~fgOPTIONS( void ); + +}; + + +extern fgOPTIONS current_options; + + +#endif /* _OPTIONS_HXX */ + + +// $Log$ +// Revision 1.1 1998/04/24 00:49:21 curt +// Wrapped "#include <config.h>" in "#ifdef HAVE_CONFIG_H" +// Trying out some different option parsing code. +// Some code reorganization. +// +// diff --git a/Main/views.cxx b/Main/views.cxx index 1c3901b09..4c3b0062c 100644 --- a/Main/views.cxx +++ b/Main/views.cxx @@ -24,7 +24,9 @@ **************************************************************************/ -#include <config.h> +#ifdef HAVE_CONFIG_H +# include <config.h> +#endif #include <Debug/fg_debug.h> #include <Flight/flight.h> @@ -33,7 +35,7 @@ #include <Math/polar.h> #include <Math/vector.h> #include <Scenery/scenery.h> -#include <Time/fg_time.h> +#include <Time/fg_time.hxx> #include "views.hxx" @@ -190,10 +192,15 @@ void fgViewUpdate(fgFLIGHT *f, struct fgVIEW *v, fgLIGHT *l) { /* $Log$ -/* Revision 1.1 1998/04/22 13:25:45 curt -/* C++ - ifing the code. -/* Starting a bit of reorganization of lighting code. +/* Revision 1.2 1998/04/24 00:49:22 curt +/* Wrapped "#include <config.h>" in "#ifdef HAVE_CONFIG_H" +/* Trying out some different option parsing code. +/* Some code reorganization. /* + * Revision 1.1 1998/04/22 13:25:45 curt + * C++ - ifing the code. + * Starting a bit of reorganization of lighting code. + * * Revision 1.16 1998/04/18 04:11:29 curt * Moved fg_debug to it's own library, added zlib support. * diff --git a/Main/views.hxx b/Main/views.hxx index f40535b7a..3730096fc 100644 --- a/Main/views.hxx +++ b/Main/views.hxx @@ -24,8 +24,8 @@ **************************************************************************/ -#ifndef _VIEWS_H -#define _VIEWS_H +#ifndef _VIEWS_HXX +#define _VIEWS_HXX #ifndef __cplusplus @@ -36,7 +36,7 @@ #include <Include/fg_types.h> #include <Flight/flight.h> #include <Math/mat3.h> -#include <Time/fg_time.h> +#include <Time/fg_time.hxx> #include <Time/light.hxx> @@ -98,10 +98,15 @@ void fgViewUpdate(fgFLIGHT *f, struct fgVIEW *v, fgLIGHT *l); /* $Log$ -/* Revision 1.1 1998/04/22 13:25:46 curt -/* C++ - ifing the code. -/* Starting a bit of reorganization of lighting code. +/* Revision 1.2 1998/04/24 00:49:22 curt +/* Wrapped "#include <config.h>" in "#ifdef HAVE_CONFIG_H" +/* Trying out some different option parsing code. +/* Some code reorganization. /* + * Revision 1.1 1998/04/22 13:25:46 curt + * C++ - ifing the code. + * Starting a bit of reorganization of lighting code. + * * Revision 1.11 1998/04/21 17:02:42 curt * Prepairing for C++ integration. *