2 // options.cxx -- class to handle command line options
4 // Written by Curtis Olson, started April 1998.
6 // Copyright (C) 1998 Curtis L. Olson - curt@me.umn.edu
8 // This program is free software; you can redistribute it and/or
9 // modify it under the terms of the GNU General Public License as
10 // published by the Free Software Foundation; either version 2 of the
11 // License, or (at your option) any later version.
13 // This program is distributed in the hope that it will be useful, but
14 // WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 // General Public License for more details.
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the Free Software
20 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 // (Log is kept at end of this file)
30 #include <math.h> // rint()
32 #include <stdlib.h> // atof(), atoi()
35 #include <Debug/fg_debug.h>
37 #include "options.hxx"
40 // Defined the shared options class here
41 fgOPTIONS current_options;
45 fgOPTIONS::fgOPTIONS( void ) {
46 // set initial values/defaults
48 strcpy(airport_id, "");
69 // parse time string in the form of [+-]hh:mm:ss, returns the value in seconds
70 static double parse_time(char *time_str) {
72 double hours, minutes, seconds;
77 // printf("parse_time(): %s\n", time_str);
80 if ( strlen(time_str) ) {
81 if ( time_str[0] == '+' ) {
84 } else if ( time_str[0] == '-' ) {
89 // printf("sign = %d\n", sign);
92 if ( strlen(time_str) ) {
94 while ( (time_str[0] != ':') && (time_str[0] != '\0') ) {
99 if ( time_str[0] == ':' ) {
104 // printf("hours = %.2lf\n", hours);
106 result += hours * 3600.0;
110 if ( strlen(time_str) ) {
112 while ( (time_str[0] != ':') && (time_str[0] != '\0') ) {
113 num[i] = time_str[0];
117 if ( time_str[0] == ':' ) {
122 // printf("minutes = %.2lf\n", minutes);
124 result += minutes * 60.0;
128 if ( strlen(time_str) ) {
130 while ( (time_str[0] != ':') && (time_str[0] != '\0') ) {
131 num[i] = time_str[0];
137 // printf("seconds = %.2lf\n", seconds);
142 return(sign * result);
146 // parse time offset command line option
147 static int parse_time_offset(char *time_str) {
152 // printf("time offset = %s\n", time_str);
155 result = (int)rint(parse_time(time_str));
157 result = (int)parse_time(time_str);
160 printf("parse_time_offset(): %d\n", result);
166 // Parse an int out of a --foo-bar=n type option
167 static int parse_int(char *arg, int min, int max) {
170 // advance past the '='
171 while ( (arg[0] != '=') && (arg[0] != '\0') ) {
175 if ( arg[0] == '=' ) {
179 printf("parse_int(): arg = %s\n", arg);
183 if ( result < min ) { result = min; }
184 if ( result > max ) { result = max; }
186 printf("parse_int(): result = %d\n", result);
191 // Parse the command line options
192 int fgOPTIONS::parse( int argc, char **argv ) {
195 fgPrintf(FG_GENERAL, FG_INFO, "Processing arguments\n");
198 fgPrintf(FG_GENERAL, FG_INFO, "argv[%d] = %s\n", i, argv[i]);
201 if ( (strcmp(argv[i], "--help") == 0) ||
202 (strcmp(argv[i], "-h") == 0) ) {
203 // help/usage request
204 return(FG_OPTIONS_HELP);
205 } else if ( strcmp(argv[i], "--disable-hud") == 0 ) {
207 } else if ( strcmp(argv[i], "--enable-hud") == 0 ) {
209 } else if ( strncmp(argv[i], "--airport-id=", 13) == 0 ) {
211 strncpy(airport_id, argv[i], 4);
212 } else if ( strcmp(argv[i], "--disable-fog") == 0 ) {
214 } else if ( strcmp(argv[i], "--enable-fog") == 0 ) {
216 } else if ( strcmp(argv[i], "--disable-fullscreen") == 0 ) {
218 } else if ( strcmp(argv[i], "--enable-fullscreen") == 0 ) {
220 } else if ( strcmp(argv[i], "--shading-flat") == 0 ) {
222 } else if ( strcmp(argv[i], "--shading-smooth") == 0 ) {
224 } else if ( strcmp(argv[i], "--disable-skyblend") == 0 ) {
226 } else if ( strcmp(argv[i], "--enable-skyblend") == 0 ) {
228 } else if ( strcmp(argv[i], "--disable-textures") == 0 ) {
230 } else if ( strcmp(argv[i], "--enable-textures") == 0 ) {
232 } else if ( strcmp(argv[i], "--disable-wireframe") == 0 ) {
234 } else if ( strcmp(argv[i], "--enable-wireframe") == 0 ) {
236 } else if ( strncmp(argv[i], "--tile-radius=", 14) == 0 ) {
237 tile_radius = parse_int(argv[i], 3, 9);
238 } else if ( strncmp(argv[i], "--time-offset=", 14) == 0 ) {
239 time_offset = parse_time_offset(argv[i]);
241 return(FG_OPTIONS_ERROR);
247 return(FG_OPTIONS_OK);
251 // Print usage message
252 void fgOPTIONS::usage ( void ) {
253 printf("Usage: fg [ options ... ]\n");
256 printf("General Options:\n");
257 printf("\t--help -h: print usage\n");
260 printf("Features:\n");
261 printf("\t--disable-hud: disable heads up display\n");
262 printf("\t--enable-hud: enable heads up display\n");
265 printf("Initial Position:\n");
266 printf("\t--airport-id=ABCD: specify starting postion by airport id\n");
269 printf("Rendering Options:\n");
270 printf("\t--disable-fog: disable fog/haze\n");
271 printf("\t--enable-fog: enable fog/haze\n");
272 printf("\t--disable-fullscreen: disable fullscreen mode\n");
273 printf("\t--enable-fullscreen: enable fullscreen mode\n");
274 printf("\t--shading-flat: enable flat shading\n");
275 printf("\t--shading-smooth: enable smooth shading\n");
276 printf("\t--disable-skyblend: disable sky blending\n");
277 printf("\t--enable-skyblend: enable sky blending\n");
278 printf("\t--disable-textures: disable textures\n");
279 printf("\t--enable-textures: enable textures\n");
280 printf("\t--disable-wireframe: disable wireframe drawing mode\n");
281 printf("\t--enable-wireframe: enable wireframe drawing mode\n");
284 printf("Scenery Options:\n");
285 printf("\t--tile-radius=n: specify tile radius, must be odd 3, 5, or 7\n");
288 printf("Time Options:\n");
289 printf("\t--time-offset=[+-]hh:mm:ss: offset local time by this amount\n");
294 fgOPTIONS::~fgOPTIONS( void ) {
299 // Revision 1.8 1998/05/07 23:14:16 curt
300 // Added "D" key binding to set autopilot heading.
301 // Made frame rate calculation average out over last 10 frames.
302 // Borland C++ floating point exception workaround.
303 // Added a --tile-radius=n option.
305 // Revision 1.7 1998/05/06 03:16:25 curt
306 // Added an averaged global frame rate counter.
307 // Added an option to control tile radius.
309 // Revision 1.6 1998/05/03 00:47:32 curt
310 // Added an option to enable/disable full-screen mode.
312 // Revision 1.5 1998/04/30 12:34:19 curt
313 // Added command line rendering options:
314 // enable/disable fog/haze
315 // specify smooth/flat shading
316 // disable sky blending and just use a solid color
317 // enable wireframe drawing mode
319 // Revision 1.4 1998/04/28 01:20:22 curt
320 // Type-ified fgTIME and fgVIEW.
321 // Added a command line option to disable textures.
323 // Revision 1.3 1998/04/26 05:01:19 curt
324 // Added an rint() / HAVE_RINT check.
326 // Revision 1.2 1998/04/25 15:11:12 curt
327 // Added an command line option to set starting position based on airport ID.
329 // Revision 1.1 1998/04/24 00:49:21 curt
330 // Wrapped "#include <config.h>" in "#ifdef HAVE_CONFIG_H"
331 // Trying out some different option parsing code.
332 // Some code reorganization.