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, "");
66 // parse time string in the form of [+-]hh:mm:ss, returns the value in seconds
67 static double parse_time(char *time_str) {
69 double hours, minutes, seconds;
74 // printf("parse_time(): %s\n", time_str);
77 if ( strlen(time_str) ) {
78 if ( time_str[0] == '+' ) {
81 } else if ( time_str[0] == '-' ) {
86 // printf("sign = %d\n", sign);
89 if ( strlen(time_str) ) {
91 while ( (time_str[0] != ':') && (time_str[0] != '\0') ) {
96 if ( time_str[0] == ':' ) {
101 // printf("hours = %.2lf\n", hours);
103 result += hours * 3600.0;
107 if ( strlen(time_str) ) {
109 while ( (time_str[0] != ':') && (time_str[0] != '\0') ) {
110 num[i] = time_str[0];
114 if ( time_str[0] == ':' ) {
119 // printf("minutes = %.2lf\n", minutes);
121 result += minutes * 60.0;
125 if ( strlen(time_str) ) {
127 while ( (time_str[0] != ':') && (time_str[0] != '\0') ) {
128 num[i] = time_str[0];
134 // printf("seconds = %.2lf\n", seconds);
139 return(sign * result);
143 // parse time offset command line option
144 static int parse_time_offset(char *time_str) {
149 // printf("time offset = %s\n", time_str);
152 result = (int)rint(parse_time(time_str));
154 result = (int)parse_time(time_str);
157 printf("parse_time_offset(): %d\n", result);
164 // Parse the command line options
165 int fgOPTIONS::parse( int argc, char **argv ) {
168 fgPrintf(FG_GENERAL, FG_INFO, "Processing arguments\n");
171 fgPrintf(FG_GENERAL, FG_INFO, "argv[%d] = %s\n", i, argv[i]);
174 if ( (strcmp(argv[i], "--help") == 0) ||
175 (strcmp(argv[i], "-h") == 0) ) {
176 // help/usage request
177 return(FG_OPTIONS_HELP);
178 } else if ( strcmp(argv[i], "--disable-hud") == 0 ) {
180 } else if ( strcmp(argv[i], "--enable-hud") == 0 ) {
182 } else if ( strncmp(argv[i], "--airport-id=", 13) == 0 ) {
184 strncpy(airport_id, argv[i], 4);
185 } else if ( strcmp(argv[i], "--disable-fog") == 0 ) {
187 } else if ( strcmp(argv[i], "--enable-fog") == 0 ) {
189 } else if ( strcmp(argv[i], "--disable-fullscreen") == 0 ) {
191 } else if ( strcmp(argv[i], "--enable-fullscreen") == 0 ) {
193 } else if ( strcmp(argv[i], "--shading-flat") == 0 ) {
195 } else if ( strcmp(argv[i], "--shading-smooth") == 0 ) {
197 } else if ( strcmp(argv[i], "--disable-skyblend") == 0 ) {
199 } else if ( strcmp(argv[i], "--enable-skyblend") == 0 ) {
201 } else if ( strcmp(argv[i], "--disable-textures") == 0 ) {
203 } else if ( strcmp(argv[i], "--enable-textures") == 0 ) {
205 } else if ( strcmp(argv[i], "--disable-wireframe") == 0 ) {
207 } else if ( strcmp(argv[i], "--enable-wireframe") == 0 ) {
209 } else if ( strncmp(argv[i], "--time-offset=", 14) == 0 ) {
210 time_offset = parse_time_offset(argv[i]);
212 return(FG_OPTIONS_ERROR);
218 return(FG_OPTIONS_OK);
222 // Print usage message
223 void fgOPTIONS::usage ( void ) {
224 printf("Usage: fg [ options ... ]\n");
227 printf("General Options:\n");
228 printf("\t--help -h: print usage\n");
231 printf("Features:\n");
232 printf("\t--disable-hud: disable heads up display\n");
233 printf("\t--enable-hud: enable heads up display\n");
236 printf("Initial Position:\n");
237 printf("\t--airport-id=ABCD: specify starting postion by airport id\n");
240 printf("Rendering Options:\n");
241 printf("\t--disable-fog: disable fog/haze\n");
242 printf("\t--enable-fog: enable fog/haze\n");
243 printf("\t--disable-fullscreen: disable fullscreen mode\n");
244 printf("\t--enable-fullscreen: enable fullscreen mode\n");
245 printf("\t--shading-flat: enable flat shading\n");
246 printf("\t--shading-smooth: enable smooth shading\n");
247 printf("\t--disable-skyblend: disable sky blending\n");
248 printf("\t--enable-skyblend: enable sky blending\n");
249 printf("\t--disable-textures: disable textures\n");
250 printf("\t--enable-textures: enable textures\n");
251 printf("\t--disable-wireframe: disable wireframe drawing mode\n");
252 printf("\t--enable-wireframe: enable wireframe drawing mode\n");
255 printf("Time Options:\n");
256 printf("\t--time-offset=[+-]hh:mm:ss: offset local time by this amount\n");
261 fgOPTIONS::~fgOPTIONS( void ) {
266 // Revision 1.6 1998/05/03 00:47:32 curt
267 // Added an option to enable/disable full-screen mode.
269 // Revision 1.5 1998/04/30 12:34:19 curt
270 // Added command line rendering options:
271 // enable/disable fog/haze
272 // specify smooth/flat shading
273 // disable sky blending and just use a solid color
274 // enable wireframe drawing mode
276 // Revision 1.4 1998/04/28 01:20:22 curt
277 // Type-ified fgTIME and fgVIEW.
278 // Added a command line option to disable textures.
280 // Revision 1.3 1998/04/26 05:01:19 curt
281 // Added an rint() / HAVE_RINT check.
283 // Revision 1.2 1998/04/25 15:11:12 curt
284 // Added an command line option to set starting position based on airport ID.
286 // Revision 1.1 1998/04/24 00:49:21 curt
287 // Wrapped "#include <config.h>" in "#ifdef HAVE_CONFIG_H"
288 // Trying out some different option parsing code.
289 // Some code reorganization.