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') ) {
177 if ( result < min ) { result = min; }
178 if ( result > max ) { result = max; }
184 // Parse the command line options
185 int fgOPTIONS::parse( int argc, char **argv ) {
188 fgPrintf(FG_GENERAL, FG_INFO, "Processing arguments\n");
191 fgPrintf(FG_GENERAL, FG_INFO, "argv[%d] = %s\n", i, argv[i]);
194 if ( (strcmp(argv[i], "--help") == 0) ||
195 (strcmp(argv[i], "-h") == 0) ) {
196 // help/usage request
197 return(FG_OPTIONS_HELP);
198 } else if ( strcmp(argv[i], "--disable-hud") == 0 ) {
200 } else if ( strcmp(argv[i], "--enable-hud") == 0 ) {
202 } else if ( strncmp(argv[i], "--airport-id=", 13) == 0 ) {
204 strncpy(airport_id, argv[i], 4);
205 } else if ( strcmp(argv[i], "--disable-fog") == 0 ) {
207 } else if ( strcmp(argv[i], "--enable-fog") == 0 ) {
209 } else if ( strcmp(argv[i], "--disable-fullscreen") == 0 ) {
211 } else if ( strcmp(argv[i], "--enable-fullscreen") == 0 ) {
213 } else if ( strcmp(argv[i], "--shading-flat") == 0 ) {
215 } else if ( strcmp(argv[i], "--shading-smooth") == 0 ) {
217 } else if ( strcmp(argv[i], "--disable-skyblend") == 0 ) {
219 } else if ( strcmp(argv[i], "--enable-skyblend") == 0 ) {
221 } else if ( strcmp(argv[i], "--disable-textures") == 0 ) {
223 } else if ( strcmp(argv[i], "--enable-textures") == 0 ) {
225 } else if ( strcmp(argv[i], "--disable-wireframe") == 0 ) {
227 } else if ( strcmp(argv[i], "--enable-wireframe") == 0 ) {
229 } else if ( strncmp(argv[i], "--tile-radius=", 14) == 0 ) {
230 tile_radius = parse_int(argv[i], 3, 7);
231 } else if ( strncmp(argv[i], "--time-offset=", 14) == 0 ) {
232 time_offset = parse_time_offset(argv[i]);
234 return(FG_OPTIONS_ERROR);
240 return(FG_OPTIONS_OK);
244 // Print usage message
245 void fgOPTIONS::usage ( void ) {
246 printf("Usage: fg [ options ... ]\n");
249 printf("General Options:\n");
250 printf("\t--help -h: print usage\n");
253 printf("Features:\n");
254 printf("\t--disable-hud: disable heads up display\n");
255 printf("\t--enable-hud: enable heads up display\n");
258 printf("Initial Position:\n");
259 printf("\t--airport-id=ABCD: specify starting postion by airport id\n");
262 printf("Rendering Options:\n");
263 printf("\t--disable-fog: disable fog/haze\n");
264 printf("\t--enable-fog: enable fog/haze\n");
265 printf("\t--disable-fullscreen: disable fullscreen mode\n");
266 printf("\t--enable-fullscreen: enable fullscreen mode\n");
267 printf("\t--shading-flat: enable flat shading\n");
268 printf("\t--shading-smooth: enable smooth shading\n");
269 printf("\t--disable-skyblend: disable sky blending\n");
270 printf("\t--enable-skyblend: enable sky blending\n");
271 printf("\t--disable-textures: disable textures\n");
272 printf("\t--enable-textures: enable textures\n");
273 printf("\t--disable-wireframe: disable wireframe drawing mode\n");
274 printf("\t--enable-wireframe: enable wireframe drawing mode\n");
277 printf("Scenery Options:\n");
278 printf("\t--tile-radius=n: specify tile radius, must be odd 3, 5, or 7\n");
281 printf("Time Options:\n");
282 printf("\t--time-offset=[+-]hh:mm:ss: offset local time by this amount\n");
287 fgOPTIONS::~fgOPTIONS( void ) {
292 // Revision 1.7 1998/05/06 03:16:25 curt
293 // Added an averaged global frame rate counter.
294 // Added an option to control tile radius.
296 // Revision 1.6 1998/05/03 00:47:32 curt
297 // Added an option to enable/disable full-screen mode.
299 // Revision 1.5 1998/04/30 12:34:19 curt
300 // Added command line rendering options:
301 // enable/disable fog/haze
302 // specify smooth/flat shading
303 // disable sky blending and just use a solid color
304 // enable wireframe drawing mode
306 // Revision 1.4 1998/04/28 01:20:22 curt
307 // Type-ified fgTIME and fgVIEW.
308 // Added a command line option to disable textures.
310 // Revision 1.3 1998/04/26 05:01:19 curt
311 // Added an rint() / HAVE_RINT check.
313 // Revision 1.2 1998/04/25 15:11:12 curt
314 // Added an command line option to set starting position based on airport ID.
316 // Revision 1.1 1998/04/24 00:49:21 curt
317 // Wrapped "#include <config.h>" in "#ifdef HAVE_CONFIG_H"
318 // Trying out some different option parsing code.
319 // Some code reorganization.