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()
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, "");
65 // parse time string in the form of [+-]hh:mm:ss, returns the value in seconds
66 static double parse_time(char *time_str) {
68 double hours, minutes, seconds;
73 // printf("parse_time(): %s\n", time_str);
76 if ( strlen(time_str) ) {
77 if ( time_str[0] == '+' ) {
80 } else if ( time_str[0] == '-' ) {
85 // printf("sign = %d\n", sign);
88 if ( strlen(time_str) ) {
90 while ( (time_str[0] != ':') && (time_str[0] != '\0') ) {
95 if ( time_str[0] == ':' ) {
100 // printf("hours = %.2lf\n", hours);
102 result += hours * 3600.0;
106 if ( strlen(time_str) ) {
108 while ( (time_str[0] != ':') && (time_str[0] != '\0') ) {
109 num[i] = time_str[0];
113 if ( time_str[0] == ':' ) {
118 // printf("minutes = %.2lf\n", minutes);
120 result += minutes * 60.0;
124 if ( strlen(time_str) ) {
126 while ( (time_str[0] != ':') && (time_str[0] != '\0') ) {
127 num[i] = time_str[0];
133 // printf("seconds = %.2lf\n", seconds);
138 return(sign * result);
142 // parse time offset command line option
143 static int parse_time_offset(char *time_str) {
148 // printf("time offset = %s\n", time_str);
151 result = (int)rint(parse_time(time_str));
153 result = (int)parse_time(time_str);
156 printf("parse_time_offset(): %d\n", result);
163 // Parse the command line options
164 int fgOPTIONS::parse( int argc, char **argv ) {
167 fgPrintf(FG_GENERAL, FG_INFO, "Processing arguments\n");
170 fgPrintf(FG_GENERAL, FG_INFO, "argv[%d] = %s\n", i, argv[i]);
173 if ( (strcmp(argv[i], "--help") == 0) ||
174 (strcmp(argv[i], "-h") == 0) ) {
175 // help/usage request
176 return(FG_OPTIONS_HELP);
177 } else if ( strcmp(argv[i], "--disable-hud") == 0 ) {
179 } else if ( strcmp(argv[i], "--enable-hud") == 0 ) {
181 } else if ( strncmp(argv[i], "--airport-id=", 13) == 0 ) {
183 strncpy(airport_id, argv[i], 4);
184 } else if ( strcmp(argv[i], "--disable-fog") == 0 ) {
186 } else if ( strcmp(argv[i], "--enable-fog") == 0 ) {
188 } else if ( strcmp(argv[i], "--shading-flat") == 0 ) {
190 } else if ( strcmp(argv[i], "--shading-smooth") == 0 ) {
192 } else if ( strcmp(argv[i], "--disable-skyblend") == 0 ) {
194 } else if ( strcmp(argv[i], "--enable-skyblend") == 0 ) {
196 } else if ( strcmp(argv[i], "--disable-textures") == 0 ) {
198 } else if ( strcmp(argv[i], "--enable-textures") == 0 ) {
200 } else if ( strcmp(argv[i], "--disable-wireframe") == 0 ) {
202 } else if ( strcmp(argv[i], "--enable-wireframe") == 0 ) {
204 } else if ( strncmp(argv[i], "--time-offset=", 14) == 0 ) {
205 time_offset = parse_time_offset(argv[i]);
207 return(FG_OPTIONS_ERROR);
213 return(FG_OPTIONS_OK);
217 // Print usage message
218 void fgOPTIONS::usage ( void ) {
219 printf("Usage: fg [ options ... ]\n");
222 printf("General Options:\n");
223 printf("\t--help -h: print usage\n");
226 printf("Features:\n");
227 printf("\t--disable-hud: disable heads up display\n");
228 printf("\t--enable-hud: enable heads up display\n");
231 printf("Initial Position:\n");
232 printf("\t--airport-id=ABCD: specify starting postion by airport id\n");
235 printf("Rendering Options:\n");
236 printf("\t--disable-fog: disable fog/haze\n");
237 printf("\t--enable-fog: enable fog/haze\n");
238 printf("\t--shading-flat: enable flat shading\n");
239 printf("\t--shading-smooth: enable smooth shading\n");
240 printf("\t--disable-skyblend: disable sky blending\n");
241 printf("\t--enable-skyblend: enable sky blending\n");
242 printf("\t--disable-textures: disable textures\n");
243 printf("\t--enable-textures: enable textures\n");
244 printf("\t--disable-wireframe: disable wireframe drawing mode\n");
245 printf("\t--enable-wireframe: enable wireframe drawing mode\n");
248 printf("Time Options:\n");
249 printf("\t--time-offset=[+-]hh:mm:ss: offset local time by this amount\n");
254 fgOPTIONS::~fgOPTIONS( void ) {
259 // Revision 1.5 1998/04/30 12:34:19 curt
260 // Added command line rendering options:
261 // enable/disable fog/haze
262 // specify smooth/flat shading
263 // disable sky blending and just use a solid color
264 // enable wireframe drawing mode
266 // Revision 1.4 1998/04/28 01:20:22 curt
267 // Type-ified fgTIME and fgVIEW.
268 // Added a command line option to disable textures.
270 // Revision 1.3 1998/04/26 05:01:19 curt
271 // Added an rint() / HAVE_RINT check.
273 // Revision 1.2 1998/04/25 15:11:12 curt
274 // Added an command line option to set starting position based on airport ID.
276 // Revision 1.1 1998/04/24 00:49:21 curt
277 // Wrapped "#include <config.h>" in "#ifdef HAVE_CONFIG_H"
278 // Trying out some different option parsing code.
279 // Some code reorganization.