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)
26 #include <math.h> // rint()
28 #include <stdlib.h> // atof()
31 #include <Debug/fg_debug.h>
33 #include "options.hxx"
36 // Defined the shared options class here
37 fgOPTIONS current_options;
41 fgOPTIONS::fgOPTIONS( void ) {
42 // set initial values/defaults
44 strcpy(airport_id, "");
50 // parse time string in the form of [+-]hh:mm:ss, returns the value in seconds
51 static double parse_time(char *time_str) {
53 double hours, minutes, seconds;
58 // printf("parse_time(): %s\n", time_str);
61 if ( strlen(time_str) ) {
62 if ( time_str[0] == '+' ) {
65 } else if ( time_str[0] == '-' ) {
70 // printf("sign = %d\n", sign);
73 if ( strlen(time_str) ) {
75 while ( (time_str[0] != ':') && (time_str[0] != '\0') ) {
80 if ( time_str[0] == ':' ) {
85 // printf("hours = %.2lf\n", hours);
87 result += hours * 3600.0;
91 if ( strlen(time_str) ) {
93 while ( (time_str[0] != ':') && (time_str[0] != '\0') ) {
98 if ( time_str[0] == ':' ) {
103 // printf("minutes = %.2lf\n", minutes);
105 result += minutes * 60.0;
109 if ( strlen(time_str) ) {
111 while ( (time_str[0] != ':') && (time_str[0] != '\0') ) {
112 num[i] = time_str[0];
118 // printf("seconds = %.2lf\n", seconds);
123 return(sign * result);
127 // parse time offset command line option
128 static int parse_time_offset(char *time_str) {
133 // printf("time offset = %s\n", time_str);
135 result = (int)rint(parse_time(time_str));
137 printf("parse_time_offset(): %d\n", result);
144 // Parse the command line options
145 int fgOPTIONS::parse( int argc, char **argv ) {
148 fgPrintf(FG_GENERAL, FG_INFO, "Processing arguments\n");
151 fgPrintf(FG_GENERAL, FG_INFO, "argv[%d] = %s\n", i, argv[i]);
153 if ( strncmp(argv[i], "--airport-id=", 13) == 0 ) {
155 strncpy(airport_id, argv[i], 4);
156 } else if ( strcmp(argv[i], "--disable-hud") == 0 ) {
158 } else if ( strcmp(argv[i], "--enable-hud") == 0 ) {
160 } else if ( (strcmp(argv[i], "--help") == 0) ||
161 (strcmp(argv[i], "-h") == 0) ) {
162 // help/usage request
163 return(FG_OPTIONS_HELP);
164 } else if ( strncmp(argv[i], "--time-offset=", 14) == 0 ) {
165 time_offset = parse_time_offset(argv[i]);
167 return(FG_OPTIONS_ERROR);
173 return(FG_OPTIONS_OK);
177 // Print usage message
178 void fgOPTIONS::usage ( void ) {
179 printf("Usage: fg [ options ... ]\n");
180 printf("\t--airport-id=ABCD: specify starting postion by airport id\n");
181 printf("\t--disable-hud: disable heads up display\n");
182 printf("\t--enable-hud: enable heads up display\n");
183 printf("\t--help -h: print usage\n");
184 printf("\t--time-offset=[+-]hh:mm:ss: offset local time by this amount\n");
189 fgOPTIONS::~fgOPTIONS( void ) {
194 // Revision 1.2 1998/04/25 15:11:12 curt
195 // Added an command line option to set starting position based on airport ID.
197 // Revision 1.1 1998/04/24 00:49:21 curt
198 // Wrapped "#include <config.h>" in "#ifdef HAVE_CONFIG_H"
199 // Trying out some different option parsing code.
200 // Some code reorganization.