]> git.mxchange.org Git - flightgear.git/blob - src/Main/options.cxx
Added --disable-random-objects and --enable-random-objects options.
[flightgear.git] / src / Main / options.cxx
1 // options.cxx -- class to handle command line options
2 //
3 // Written by Curtis Olson, started April 1998.
4 //
5 // Copyright (C) 1998  Curtis L. Olson  - curt@me.umn.edu
6 //
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License as
9 // published by the Free Software Foundation; either version 2 of the
10 // License, or (at your option) any later version.
11 //
12 // This program is distributed in the hope that it will be useful, but
13 // WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15 // General Public License for more details.
16 //
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software
19 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 //
21 // $Id$
22
23
24 #ifdef HAVE_CONFIG_H
25 #  include <config.h>
26 #endif
27
28 #include <simgear/compiler.h>
29 #include <simgear/misc/exception.hxx>
30
31 #include <math.h>               // rint()
32 #include <stdio.h>
33 #include <stdlib.h>             // atof(), atoi()
34 #include <string.h>             // strcmp()
35
36 #include STL_STRING
37
38 #include <simgear/misc/sgstream.hxx>
39 #include <simgear/misc/sg_path.hxx>
40 #include <simgear/route/route.hxx>
41 #include <simgear/route/waypoint.hxx>
42
43 // #include <Include/general.hxx>
44 // #include <Airports/simple.hxx>
45 // #include <Cockpit/cockpit.hxx>
46 // #include <FDM/flight.hxx>
47 // #include <FDM/UIUCModel/uiuc_aircraftdir.h>
48 #ifdef FG_NETWORK_OLK
49 #  include <NetworkOLK/network.h>
50 #endif
51
52 #include <GUI/gui.h>
53
54 #include "globals.hxx"
55 #include "fg_init.hxx"
56 #include "fg_props.hxx"
57 #include "options.hxx"
58 #include "viewmgr.hxx"
59
60 SG_USING_STD(string);
61 SG_USING_NAMESPACE(std);
62
63
64 #define NEW_DEFAULT_MODEL_HZ 120
65
66 enum
67 {
68     FG_OPTIONS_OK = 0,
69     FG_OPTIONS_HELP = 1,
70     FG_OPTIONS_ERROR = 2
71 };
72
73 static double
74 atof( const string& str )
75 {
76
77 #ifdef __MWERKS__ 
78     // -dw- if ::atof is called, then we get an infinite loop
79     return std::atof( str.c_str() );
80 #else
81     return ::atof( str.c_str() );
82 #endif
83 }
84
85 static int
86 atoi( const string& str )
87 {
88 #ifdef __MWERKS__ 
89     // -dw- if ::atoi is called, then we get an infinite loop
90     return std::atoi( str.c_str() );
91 #else
92     return ::atoi( str.c_str() );
93 #endif
94 }
95
96
97 /**
98  * Set a few fail-safe default property values.
99  *
100  * These should all be set in $FG_ROOT/preferences.xml, but just
101  * in case, we provide some initial sane values here. This method 
102  * should be invoked *before* reading any init files.
103  */
104 void
105 fgSetDefaults ()
106 {
107     // set a possibly independent location for scenery data
108     char *envp = ::getenv( "FG_SCENERY" );
109
110     if ( envp != NULL ) {
111         // fg_root could be anywhere, so default to environmental
112         // variable $FG_ROOT if it is set.
113         globals->set_fg_scenery(envp);
114     } else {
115         // Otherwise, default to Scenery being in $FG_ROOT/Scenery
116         globals->set_fg_scenery("");
117     }
118                                 // Position (deliberately out of range)
119     fgSetDouble("/position/longitude-deg", 9999.0);
120     fgSetDouble("/position/latitude-deg", 9999.0);
121     fgSetDouble("/position/altitude-ft", -9999.0);
122
123                                 // Orientation
124     fgSetDouble("/orientation/heading-deg", 270);
125     fgSetDouble("/orientation/roll-deg", 0);
126     fgSetDouble("/orientation/pitch-deg", 0.424);
127
128                                 // Velocities
129     fgSetString("/sim/startup/speed-set", "knots");
130     fgSetDouble("/velocities/uBody-fps", 0.0);
131     fgSetDouble("/velocities/vBody-fps", 0.0);
132     fgSetDouble("/velocities/wBody-fps", 0.0);
133     fgSetDouble("/velocities/speed-north-fps", 0.0);
134     fgSetDouble("/velocities/speed-east-fps", 0.0);
135     fgSetDouble("/velocities/speed-down-fps", 0.0);
136     fgSetDouble("/velocities/airspeed-kt", 0.0);
137     fgSetDouble("/velocities/mach", 0.0);
138
139                                 // Miscellaneous
140     fgSetBool("/sim/startup/game-mode", false);
141     fgSetBool("/sim/startup/splash-screen", true);
142     fgSetBool("/sim/startup/intro-music", true);
143     // we want mouse-pointer to have an undefined value if nothing is
144     // specified so we can do the right thing for voodoo-1/2 cards.
145     // fgSetString("/sim/startup/mouse-pointer", "disabled");
146     fgSetString("/sim/control-mode", "joystick");
147     fgSetBool("/sim/auto-coordination", false);
148 #if !defined(WIN32)
149     fgSetString("/sim/startup/browser-app", "netscape");
150 #else
151     fgSetString("/sim/startup/browser-app", "webrun.bat");
152 #endif
153                                 // Features
154     fgSetBool("/sim/hud/visibility", false);
155     fgSetBool("/sim/panel/visibility", true);
156     fgSetBool("/sim/sound/audible", true);
157     fgSetBool("/sim/hud/antialiased", false);
158
159                                 // Flight Model options
160     fgSetString("/sim/flight-model", "jsb");
161     fgSetString("/sim/aero", "c172");
162     fgSetInt("/sim/model-hz", NEW_DEFAULT_MODEL_HZ);
163     fgSetInt("/sim/speed-up", 1);
164     fgSetBool("/sim/startup/trim", false);
165     fgSetBool("/sim/startup/onground", true);
166
167                                 // Rendering options
168     fgSetString("/sim/rendering/fog", "nicest");
169     fgSetBool("/environment/clouds/status", true);
170     fgSetBool("/sim/startup/fullscreen", false);
171     fgSetBool("/sim/rendering/shading", true);
172     fgSetBool("/sim/rendering/skyblend", true);
173     fgSetBool("/sim/rendering/textures", true);
174     fgSetBool("/sim/rendering/wireframe", false);
175     fgSetInt("/sim/startup/xsize", 800);
176     fgSetInt("/sim/startup/ysize", 600);
177     fgSetInt("/sim/rendering/bits-per-pixel", 16);
178     fgSetString("/sim/view-mode", "pilot");
179     fgSetDouble("/sim/current-view/heading-offset-deg", 0);
180     fgSetDouble("/environment/visibility-m", 20000);
181
182                                 // HUD options
183     fgSetString("/sim/startup/units", "feet");
184     fgSetString("/sim/hud/frame-stat-type", "tris");
185         
186                                 // Time options
187     fgSetInt("/sim/startup/time-offset", 0);
188     fgSetString("/sim/startup/time-offset-type", "system-offset");
189     fgSetLong("/sim/time/cur-time-override", 0);
190
191     fgSetBool("/sim/networking/network-olk", false);
192     fgSetString("/sim/networking/call-sign", "Johnny");
193
194                                 // Freeze options
195     fgSetBool("/sim/freeze/master", false);
196     fgSetBool("/sim/freeze/position", false);
197     fgSetBool("/sim/freeze/clock", false);
198     fgSetBool("/sim/freeze/fuel", false);
199 }
200
201
202 static bool
203 parse_wind (const string &wind, double * min_hdg, double * max_hdg,
204             double * speed, double * gust)
205 {
206   string::size_type pos = wind.find('@');
207   if (pos == string::npos)
208     return false;
209   string dir = wind.substr(0, pos);
210   string spd = wind.substr(pos+1);
211   pos = dir.find(':');
212   if (pos == string::npos) {
213     *min_hdg = *max_hdg = atof(dir.c_str());
214   } else {
215     *min_hdg = atof(dir.substr(0,pos).c_str());
216     *max_hdg = atof(dir.substr(pos+1).c_str());
217   }
218   pos = spd.find(':');
219   if (pos == string::npos) {
220     *speed = *gust = atof(spd.c_str());
221   } else {
222     *speed = atof(spd.substr(0,pos).c_str());
223     *gust = atof(spd.substr(pos+1).c_str());
224   }
225   return true;
226 }
227
228 // parse a time string ([+/-]%f[:%f[:%f]]) into hours
229 static double
230 parse_time(const string& time_in) {
231     char *time_str, num[256];
232     double hours, minutes, seconds;
233     double result = 0.0;
234     int sign = 1;
235     int i;
236
237     time_str = (char *)time_in.c_str();
238
239     // printf("parse_time(): %s\n", time_str);
240
241     // check for sign
242     if ( strlen(time_str) ) {
243         if ( time_str[0] == '+' ) {
244             sign = 1;
245             time_str++;
246         } else if ( time_str[0] == '-' ) {
247             sign = -1;
248             time_str++;
249         }
250     }
251     // printf("sign = %d\n", sign);
252
253     // get hours
254     if ( strlen(time_str) ) {
255         i = 0;
256         while ( (time_str[0] != ':') && (time_str[0] != '\0') ) {
257             num[i] = time_str[0];
258             time_str++;
259             i++;
260         }
261         if ( time_str[0] == ':' ) {
262             time_str++;
263         }
264         num[i] = '\0';
265         hours = atof(num);
266         // printf("hours = %.2lf\n", hours);
267
268         result += hours;
269     }
270
271     // get minutes
272     if ( strlen(time_str) ) {
273         i = 0;
274         while ( (time_str[0] != ':') && (time_str[0] != '\0') ) {
275             num[i] = time_str[0];
276             time_str++;
277             i++;
278         }
279         if ( time_str[0] == ':' ) {
280             time_str++;
281         }
282         num[i] = '\0';
283         minutes = atof(num);
284         // printf("minutes = %.2lf\n", minutes);
285
286         result += minutes / 60.0;
287     }
288
289     // get seconds
290     if ( strlen(time_str) ) {
291         i = 0;
292         while ( (time_str[0] != ':') && (time_str[0] != '\0') ) {
293             num[i] = time_str[0];
294             time_str++;
295             i++;
296         }
297         num[i] = '\0';
298         seconds = atof(num);
299         // printf("seconds = %.2lf\n", seconds);
300
301         result += seconds / 3600.0;
302     }
303
304     return(sign * result);
305 }
306
307
308 // parse a date string (yyyy:mm:dd:hh:mm:ss) into a time_t (seconds)
309 static long int 
310 parse_date( const string& date)
311 {
312     struct tm gmt;
313     char * date_str, num[256];
314     int i;
315     // initialize to zero
316     gmt.tm_sec = 0;
317     gmt.tm_min = 0;
318     gmt.tm_hour = 0;
319     gmt.tm_mday = 0;
320     gmt.tm_mon = 0;
321     gmt.tm_year = 0;
322     gmt.tm_isdst = 0; // ignore daylight savings time for the moment
323     date_str = (char *)date.c_str();
324     // get year
325     if ( strlen(date_str) ) {
326         i = 0;
327         while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
328             num[i] = date_str[0];
329             date_str++;
330             i++;
331         }
332         if ( date_str[0] == ':' ) {
333             date_str++;
334         }
335         num[i] = '\0';
336         gmt.tm_year = atoi(num) - 1900;
337     }
338     // get month
339     if ( strlen(date_str) ) {
340         i = 0;
341         while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
342             num[i] = date_str[0];
343             date_str++;
344             i++;
345         }
346         if ( date_str[0] == ':' ) {
347             date_str++;
348         }
349         num[i] = '\0';
350         gmt.tm_mon = atoi(num) -1;
351     }
352     // get day
353     if ( strlen(date_str) ) {
354         i = 0;
355         while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
356             num[i] = date_str[0];
357             date_str++;
358             i++;
359         }
360         if ( date_str[0] == ':' ) {
361             date_str++;
362         }
363         num[i] = '\0';
364         gmt.tm_mday = atoi(num);
365     }
366     // get hour
367     if ( strlen(date_str) ) {
368         i = 0;
369         while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
370             num[i] = date_str[0];
371             date_str++;
372             i++;
373         }
374         if ( date_str[0] == ':' ) {
375             date_str++;
376         }
377         num[i] = '\0';
378         gmt.tm_hour = atoi(num);
379     }
380     // get minute
381     if ( strlen(date_str) ) {
382         i = 0;
383         while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
384             num[i] = date_str[0];
385             date_str++;
386             i++;
387         }
388         if ( date_str[0] == ':' ) {
389             date_str++;
390         }
391         num[i] = '\0';
392         gmt.tm_min = atoi(num);
393     }
394     // get second
395     if ( strlen(date_str) ) {
396         i = 0;
397         while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
398             num[i] = date_str[0];
399             date_str++;
400             i++;
401         }
402         if ( date_str[0] == ':' ) {
403             date_str++;
404         }
405         num[i] = '\0';
406         gmt.tm_sec = atoi(num);
407     }
408     time_t theTime = sgTimeGetGMT( gmt.tm_year, gmt.tm_mon, gmt.tm_mday,
409                                    gmt.tm_hour, gmt.tm_min, gmt.tm_sec );
410     //printf ("Date is %s\n", ctime(&theTime));
411     //printf ("in seconds that is %d\n", theTime);
412     //exit(1);
413     return (theTime);
414 }
415
416
417 // parse angle in the form of [+/-]ddd:mm:ss into degrees
418 static double
419 parse_degree( const string& degree_str) {
420     double result = parse_time( degree_str );
421
422     // printf("Degree = %.4f\n", result);
423
424     return(result);
425 }
426
427
428 // parse time offset string into seconds
429 static int
430 parse_time_offset( const string& time_str) {
431     int result;
432
433     // printf("time offset = %s\n", time_str);
434
435 #ifdef HAVE_RINT
436     result = (int)rint(parse_time(time_str) * 3600.0);
437 #else
438     result = (int)(parse_time(time_str) * 3600.0);
439 #endif
440
441     // printf("parse_time_offset(): %d\n", result);
442
443     return( result );
444 }
445
446
447 // Parse --fov=x.xx type option 
448 static double
449 parse_fov( const string& arg ) {
450     double fov = atof(arg);
451
452     if ( fov < FG_FOV_MIN ) { fov = FG_FOV_MIN; }
453     if ( fov > FG_FOV_MAX ) { fov = FG_FOV_MAX; }
454
455     fgSetDouble("/sim/current-view/field-of-view", fov);
456
457     // printf("parse_fov(): result = %.4f\n", fov);
458
459     return fov;
460 }
461
462
463 // Parse I/O channel option
464 //
465 // Format is "--protocol=medium,direction,hz,medium_options,..."
466 //
467 //   protocol = { native, nmea, garmin, fgfs, rul, pve, etc. }
468 //   medium = { serial, socket, file, etc. }
469 //   direction = { in, out, bi }
470 //   hz = number of times to process channel per second (floating
471 //        point values are ok.
472 //
473 // Serial example "--nmea=serial,dir,hz,device,baud" where
474 // 
475 //  device = OS device name of serial line to be open()'ed
476 //  baud = {300, 1200, 2400, ..., 230400}
477 //
478 // Socket exacmple "--native=socket,dir,hz,machine,port,style" where
479 // 
480 //  machine = machine name or ip address if client (leave empty if server)
481 //  port = port, leave empty to let system choose
482 //  style = tcp or udp
483 //
484 // File example "--garmin=file,dir,hz,filename" where
485 // 
486 //  filename = file system file name
487
488 static bool 
489 add_channel( const string& type, const string& channel_str ) {
490     // cout << "Channel string = " << channel_str << endl;
491
492     globals->get_channel_options_list()->push_back( type + "," + channel_str );
493
494     return true;
495 }
496
497
498 // Parse --wp=ID[@alt]
499 static bool 
500 parse_wp( const string& arg ) {
501     string id, alt_str;
502     double alt = 0.0;
503
504     string::size_type pos = arg.find( "@" );
505     if ( pos != string::npos ) {
506         id = arg.substr( 0, pos );
507         alt_str = arg.substr( pos + 1 );
508         // cout << "id str = " << id << "  alt str = " << alt_str << endl;
509         alt = atof( alt_str.c_str() );
510         if ( !strcmp(fgGetString("/sim/startup/units"), "feet") ) {
511             alt *= SG_FEET_TO_METER;
512         }
513     } else {
514         id = arg;
515     }
516
517     FGAirport a;
518     if ( fgFindAirportID( id, &a ) ) {
519         SGWayPoint wp( a.longitude, a.latitude, alt, SGWayPoint::WGS84, id );
520         globals->get_route()->add_waypoint( wp );
521
522         return true;
523     } else {
524         return false;
525     }
526 }
527
528
529 // Parse --flight-plan=[file]
530 static bool 
531 parse_flightplan(const string& arg)
532 {
533     sg_gzifstream in(arg.c_str());
534     if ( !in.is_open() ) {
535         return false;
536     }
537     while ( true ) {
538         string line;
539
540 #if defined( macintosh )
541         getline( in, line, '\r' );
542 #else
543         getline( in, line, '\n' );
544 #endif
545
546         // catch extraneous (DOS) line ending character
547         if ( line[line.length() - 1] < 32 ) {
548             line = line.substr( 0, line.length()-1 );
549         }
550
551         if ( in.eof() ) {
552             break;
553         }
554         parse_wp(line);
555     }
556
557     return true;
558 }
559
560
561 // Parse a single option
562 static int 
563 parse_option (const string& arg) 
564 {
565     // General Options
566     if ( (arg == "--help") || (arg == "-h") ) {
567         // help/usage request
568         return(FG_OPTIONS_HELP);
569     } else if ( arg == "--disable-game-mode") {
570         fgSetBool("/sim/startup/game-mode", false);
571     } else if ( arg == "--enable-game-mode" ) {
572         fgSetBool("/sim/startup/game-mode", true);
573     } else if ( arg == "--disable-splash-screen" ) {
574         fgSetBool("/sim/startup/splash-screen", false); 
575     } else if ( arg == "--enable-splash-screen" ) {
576         fgSetBool("/sim/startup/splash-screen", true);
577     } else if ( arg == "--disable-intro-music" ) {
578         fgSetBool("/sim/startup/intro-music", false);
579     } else if ( arg == "--enable-intro-music" ) {
580         fgSetBool("/sim/startup/intro-music", true);
581     } else if ( arg == "--disable-mouse-pointer" ) {
582         fgSetString("/sim/startup/mouse-pointer", "disabled");
583     } else if ( arg == "--enable-mouse-pointer" ) {
584         fgSetString("/sim/startup/mouse-pointer", "enabled");
585     } else if ( arg == "--disable-random-objects" ) {
586         fgSetBool("/sim/rendering/random-objects", false);
587     } else if ( arg == "--enable-random-objects" ) {
588         fgSetBool("/sim/rendering/random-objects", true);
589     } else if ( arg == "--disable-freeze" ) {
590         fgSetBool("/sim/freeze/master", false);
591     } else if ( arg == "--enable-freeze" ) {
592         fgSetBool("/sim/freeze/master", true);
593     } else if ( arg == "--disable-fuel-freeze" ) {
594         fgSetBool("/sim/freeze/fuel", false);
595     } else if ( arg == "--enable-fuel-freeze" ) {
596         fgSetBool("/sim/freeze/fuel", true);
597     } else if ( arg == "--disable-clock-freeze" ) {
598         fgSetBool("/sim/freeze/clock", false);
599     } else if ( arg == "--enable-clock-freeze" ) {
600         fgSetBool("/sim/freeze/clock", true);
601     } else if ( arg == "--disable-anti-alias-hud" ) {
602         fgSetBool("/sim/hud/antialiased", false);
603     } else if ( arg == "--enable-anti-alias-hud" ) {
604         fgSetBool("/sim/hud/antialiased", true);
605     } else if ( arg.find( "--control=") == 0 ) {
606         fgSetString("/sim/control-mode", arg.substr(10).c_str());
607     } else if ( arg == "--disable-auto-coordination" ) {
608         fgSetBool("/sim/auto-coordination", false);
609     } else if ( arg == "--enable-auto-coordination" ) {
610         fgSetBool("/sim/auto-coordination", true);
611     } else if ( arg.find( "--browser-app=") == 0 ) {
612         fgSetString("/sim/startup/browser-app", arg.substr(14).c_str());
613     } else if ( arg == "--disable-hud" ) {
614         fgSetBool("/sim/hud/visibility", false);
615     } else if ( arg == "--enable-hud" ) {
616         fgSetBool("/sim/hud/visibility", true);
617     } else if ( arg == "--disable-panel" ) {
618         fgSetBool("/sim/panel/visibility", false);
619     } else if ( arg == "--enable-panel" ) {
620         fgSetBool("/sim/panel/visibility", true);
621     } else if ( arg == "--disable-sound" ) {
622         fgSetBool("/sim/sound/audible", false);
623     } else if ( arg == "--enable-sound" ) {
624         fgSetBool("/sim/sound/audible", true);
625     } else if ( arg.find( "--airport-id=") == 0 ) {
626                                 // NB: changed property name!!!
627         fgSetString("/sim/startup/airport-id", arg.substr(13).c_str());
628     } else if ( arg.find( "--offset-distance=") == 0 ) {
629         fgSetDouble("/sim/startup/offset-distance", atof(arg.substr(18)));
630     } else if ( arg.find( "--offset-azimuth=") == 0 ) {
631         fgSetDouble("/sim/startup/offset-azimuth", atof(arg.substr(17))); 
632     } else if ( arg.find( "--lon=" ) == 0 ) {
633         fgSetDouble("/position/longitude-deg",
634                               parse_degree(arg.substr(6)));
635         fgSetString("/sim/startup/airport-id", "");
636     } else if ( arg.find( "--lat=" ) == 0 ) {
637         fgSetDouble("/position/latitude-deg",
638                               parse_degree(arg.substr(6)));
639         fgSetString("/sim/startup/airport-id", "");
640     } else if ( arg.find( "--altitude=" ) == 0 ) {
641         fgSetBool("/sim/startup/onground", false);
642         if ( !strcmp(fgGetString("/sim/startup/units"), "feet") )
643             fgSetDouble("/position/altitude-ft", atof(arg.substr(11)));
644         else
645             fgSetDouble("/position/altitude-ft",
646                         atof(arg.substr(11)) * SG_METER_TO_FEET);
647     } else if ( arg.find( "--uBody=" ) == 0 ) {
648         fgSetString("/sim/startup/speed-set", "UVW");
649         if ( !strcmp(fgGetString("/sim/startup/units"), "feet") )
650           fgSetDouble("/velocities/uBody-fps", atof(arg.substr(8)));
651         else
652           fgSetDouble("/velocities/uBody-fps",
653                                atof(arg.substr(8)) * SG_METER_TO_FEET);
654     } else if ( arg.find( "--vBody=" ) == 0 ) {
655         fgSetString("/sim/startup/speed-set", "UVW");
656         if ( !strcmp(fgGetString("/sim/startup/units"), "feet") )
657           fgSetDouble("/velocities/vBody-fps", atof(arg.substr(8)));
658         else
659           fgSetDouble("/velocities/vBody-fps",
660                                atof(arg.substr(8)) * SG_METER_TO_FEET);
661     } else if ( arg.find( "--wBody=" ) == 0 ) {
662         fgSetString("/sim/startup/speed-set", "UVW");
663         if ( !strcmp(fgGetString("/sim/startup/units"), "feet") )
664           fgSetDouble("/velocities/wBody-fps", atof(arg.substr(8)));
665         else
666           fgSetDouble("/velocities/wBody-fps",
667                                atof(arg.substr(8)) * SG_METER_TO_FEET);
668     } else if ( arg.find( "--vNorth=" ) == 0 ) {
669         fgSetString("/sim/startup/speed-set", "NED");
670         if ( !strcmp(fgGetString("/sim/startup/units"), "feet") )
671           fgSetDouble("/velocities/speed-north-fps", atof(arg.substr(9)));
672         else
673           fgSetDouble("/velocities/speed-north-fps",
674                                atof(arg.substr(9)) * SG_METER_TO_FEET);
675     } else if ( arg.find( "--vEast=" ) == 0 ) {
676         fgSetString("/sim/startup/speed-set", "NED");
677         if ( !strcmp(fgGetString("/sim/startup/units"), "feet") )
678           fgSetDouble("/velocities/speed-east-fps", atof(arg.substr(8)));
679         else
680           fgSetDouble("/velocities/speed-east-fps",
681                       atof(arg.substr(8)) * SG_METER_TO_FEET);
682     } else if ( arg.find( "--vDown=" ) == 0 ) {
683         fgSetString("/sim/startup/speed-set", "NED");
684         if ( !strcmp(fgGetString("/sim/startup/units"), "feet") )
685           fgSetDouble("/velocities/speed-down-fps", atof(arg.substr(8)));
686         else
687           fgSetDouble("/velocities/speed-down-fps",
688                                atof(arg.substr(8)) * SG_METER_TO_FEET);
689     } else if ( arg.find( "--vc=" ) == 0) {
690         fgSetString("/sim/startup/speed-set", "knots");
691         fgSetDouble("/velocities/airspeed-kt", atof(arg.substr(5)));
692     } else if ( arg.find( "--mach=" ) == 0) {
693         fgSetString("/sim/startup/speed-set", "mach");
694         fgSetDouble("/velocities/mach", atof(arg.substr(7)));
695     } else if ( arg.find( "--heading=" ) == 0 ) {
696         fgSetDouble("/orientation/heading-deg", atof(arg.substr(10)));
697     } else if ( arg.find( "--roll=" ) == 0 ) {
698         fgSetDouble("/orientation/roll-deg", atof(arg.substr(7)));
699     } else if ( arg.find( "--pitch=" ) == 0 ) {
700         fgSetDouble("/orientation/pitch-deg", atof(arg.substr(8)));
701     } else if ( arg.find( "--glideslope=" ) == 0 ) {
702         fgSetDouble("/velocities/glideslope", atof(arg.substr(13))
703                                           *SG_DEGREES_TO_RADIANS);
704     }  else if ( arg.find( "--roc=" ) == 0 ) {
705         fgSetDouble("/velocities/vertical-speed-fps", atof(arg.substr(6))/60);
706     } else if ( arg.find( "--fg-root=" ) == 0 ) {
707         globals->set_fg_root(arg.substr( 10 ));
708     } else if ( arg.find( "--fg-scenery=" ) == 0 ) {
709         globals->set_fg_scenery(arg.substr( 13 ));
710     } else if ( arg.find( "--fdm=" ) == 0 ) {
711         fgSetString("/sim/flight-model", arg.substr(6).c_str());
712     } else if ( arg.find( "--aero=" ) == 0 ) {
713         fgSetString("/sim/aero", arg.substr(7).c_str());
714     } else if ( arg.find( "--aircraft-dir=" ) == 0 ) {
715         fgSetString("/sim/aircraft-dir", arg.substr(15).c_str());
716     } else if ( arg.find( "--model-hz=" ) == 0 ) {
717         fgSetInt("/sim/model-hz", atoi(arg.substr(11)));
718     } else if ( arg.find( "--speed=" ) == 0 ) {
719         fgSetInt("/sim/speed-up", atoi(arg.substr(8)));
720     } else if ( arg.find( "--trim") == 0) {
721         fgSetBool("/sim/startup/trim", true);
722     } else if ( arg.find( "--notrim") == 0) {
723         fgSetBool("/sim/startup/trim", false);
724     } else if ( arg.find( "--on-ground") == 0) {
725         fgSetBool("/sim/startup/onground", true);
726     } else if ( arg.find( "--in-air") == 0) {
727         fgSetBool("/sim/startup/onground", false);
728     } else if ( arg == "--fog-disable" ) {
729         fgSetString("/sim/rendering/fog", "disabled");
730     } else if ( arg == "--fog-fastest" ) {
731         fgSetString("/sim/rendering/fog", "fastest");
732     } else if ( arg == "--fog-nicest" ) {
733         fgSetString("/sim/fog", "nicest");
734     } else if ( arg == "--disable-clouds" ) {
735         fgSetBool("/environment/clouds/status", false);
736     } else if ( arg == "--enable-clouds" ) {
737         fgSetBool("/environment/clouds/status", true);
738     } else if ( arg.find( "--fov=" ) == 0 ) {
739         parse_fov( arg.substr(6) );
740     } else if ( arg == "--disable-fullscreen" ) {
741         fgSetBool("/sim/startup/fullscreen", false);
742     } else if ( arg== "--enable-fullscreen") {
743         fgSetBool("/sim/startup/fullscreen", true);
744     } else if ( arg == "--shading-flat") {
745         fgSetBool("/sim/rendering/shading", false);
746     } else if ( arg == "--shading-smooth") {
747         fgSetBool("/sim/rendering/shading", true);
748     } else if ( arg == "--disable-skyblend") {
749         fgSetBool("/sim/rendering/skyblend", false);
750     } else if ( arg== "--enable-skyblend" ) {
751         fgSetBool("/sim/rendering/skyblend", true);
752     } else if ( arg == "--disable-textures" ) {
753         fgSetBool("/sim/rendering/textures", false);
754     } else if ( arg == "--enable-textures" ) {
755         fgSetBool("/sim/rendering/textures", true);
756     } else if ( arg == "--disable-wireframe" ) {
757         fgSetBool("/sim/rendering/wireframe", false);
758     } else if ( arg == "--enable-wireframe" ) {
759         fgSetBool("/sim/rendering/wireframe", true);
760     } else if ( arg.find( "--geometry=" ) == 0 ) {
761         bool geometry_ok = true;
762         int xsize = 0, ysize = 0;
763         string geometry = arg.substr( 11 );
764         string::size_type i = geometry.find('x');
765
766         if (i != string::npos) {
767             xsize = atoi(geometry.substr(0, i));
768             ysize = atoi(geometry.substr(i+1));
769         } else {
770             geometry_ok = false;
771         }
772
773         if ( xsize <= 0 || ysize <= 0 ) {
774             xsize = 640;
775             ysize = 480;
776             geometry_ok = false;
777         }
778
779         if ( !geometry_ok ) {
780             SG_LOG( SG_GENERAL, SG_ALERT, "Unknown geometry: " << geometry );
781             SG_LOG( SG_GENERAL, SG_ALERT,
782                     "Setting geometry to " << xsize << 'x' << ysize << '\n');
783         } else {
784           SG_LOG( SG_GENERAL, SG_INFO,
785                   "Setting geometry to " << xsize << 'x' << ysize << '\n');
786           fgSetInt("/sim/startup/xsize", xsize);
787           fgSetInt("/sim/startup/ysize", ysize);
788         }
789     } else if ( arg.find( "--bpp=" ) == 0 ) {
790         string bits_per_pix = arg.substr( 6 );
791         if ( bits_per_pix == "16" ) {
792             fgSetInt("/sim/rendering/bits-per-pixel", 16);
793         } else if ( bits_per_pix == "24" ) {
794             fgSetInt("/sim/rendering/bits-per-pixel", 24);
795         } else if ( bits_per_pix == "32" ) {
796             fgSetInt("/sim/rendering/bits-per-pixel", 32);
797         } else {
798           SG_LOG(SG_GENERAL, SG_ALERT, "Unsupported bpp " << bits_per_pix);
799         }
800     } else if ( arg == "--units-feet" ) {
801         fgSetString("/sim/startup/units", "feet");
802     } else if ( arg == "--units-meters" ) {
803         fgSetString("/sim/startup/units", "meters");
804     } else if ( arg.find( "--time-offset" ) == 0 ) {
805         fgSetInt("/sim/startup/time-offset",
806                  parse_time_offset( (arg.substr(14)) ));
807         fgSetString("/sim/startup/time-offset-type", "system-offset");
808     } else if ( arg.find( "--time-match-real") == 0 ) {
809         fgSetString("/sim/startup/time-offset-type", "system-offset");
810     } else if ( arg.find( "--time-match-local") == 0 ) {
811         fgSetString("/sim/startup/time-offset-type", "latitude-offset");
812     } else if ( arg.find( "--start-date-sys=") == 0 ) {
813         fgSetInt("/sim/startup/time-offset", parse_date((arg.substr(17))));
814         fgSetString("/sim/startup/time-offset-type", "system");
815     } else if ( arg.find( "--start-date-lat=") == 0 ) {
816         fgSetInt("/sim/startup/time-offset", parse_date((arg.substr(17))));
817         fgSetString("/sim/startup/time-offset-type", "latitude");
818     } else if ( arg.find( "--start-date-gmt=") == 0 ) {
819         fgSetInt("/sim/startup/time-offset", parse_date((arg.substr(17))));
820         fgSetString("/sim/startup/time-offset-type", "gmt");
821     } else if ( arg == "--hud-tris" ) {
822         fgSetString("/sim/hud/frame-stat-type", "tris");
823     } else if ( arg == "--hud-culled" ) {
824         fgSetString("/sim/hud/frame-stat-type", "culled");
825     } else if ( arg.find( "--atc610x" ) == 0 ) {
826         add_channel( "atc610x", "dummy" );
827     } else if ( arg.find( "--atlas=" ) == 0 ) {
828         add_channel( "atlas", arg.substr(8) );
829     } else if ( arg.find( "--httpd=" ) == 0 ) {
830         add_channel( "httpd", arg.substr(8) );
831 #ifdef FG_JPEG_SERVER
832     } else if ( arg.find( "--jpg-httpd=" ) == 0 ) {
833         add_channel( "jpg-httpd", arg.substr(12) );
834 #endif
835     } else if ( arg.find( "--native=" ) == 0 ) {
836         add_channel( "native", arg.substr(9) );
837     } else if ( arg.find( "--native-ctrls=" ) == 0 ) {
838         add_channel( "native_ctrls", arg.substr(15) );
839     } else if ( arg.find( "--native-fdm=" ) == 0 ) {
840         add_channel( "native_fdm", arg.substr(13) );
841     } else if ( arg.find( "--opengc=" ) == 0 ) {
842         // char stop;
843         // cout << "Adding channel for OpenGC Display" << endl; cin >> stop;
844         add_channel( "opengc", arg.substr(9) );
845     } else if ( arg.find( "--garmin=" ) == 0 ) {
846         add_channel( "garmin", arg.substr(9) );
847     } else if ( arg.find( "--nmea=" ) == 0 ) {
848         add_channel( "nmea", arg.substr(7) );
849     } else if ( arg.find( "--props=" ) == 0 ) {
850         add_channel( "props", arg.substr(8) );
851     } else if ( arg.find( "--telnet=" ) == 0 ) {
852         add_channel( "telnet", arg.substr(9) );
853     } else if ( arg.find( "--pve=" ) == 0 ) {
854         add_channel( "pve", arg.substr(6) );
855     } else if ( arg.find( "--ray=" ) == 0 ) {
856         add_channel( "ray", arg.substr(6) );
857     } else if ( arg.find( "--rul=" ) == 0 ) {
858         add_channel( "rul", arg.substr(6) );
859     } else if ( arg.find( "--joyclient=" ) == 0 ) {
860         add_channel( "joyclient", arg.substr(12) );
861 #ifdef FG_NETWORK_OLK
862     } else if ( arg == "--disable-network-olk" ) {
863         fgSetBool("/sim/networking/olk", false);
864     } else if ( arg== "--enable-network-olk") {
865         fgSetBool("/sim/networking/olk", true);
866     } else if ( arg == "--net-hud" ) {
867         fgSetBool("/sim/hud/net-display", true);
868         net_hud_display = 1;    // FIXME
869     } else if ( arg.find( "--net-id=") == 0 ) {
870         fgSetString("sim/networking/call-sign", arg.substr(9).c_str());
871 #endif
872     } else if ( arg.find( "--prop:" ) == 0 ) {
873         string assign = arg.substr(7);
874         string::size_type pos = assign.find('=');
875         if ( pos == arg.npos || pos == 0 ) {
876             SG_LOG( SG_GENERAL, SG_ALERT, "Bad property assignment: " << arg );
877             return FG_OPTIONS_ERROR;
878         }
879         string name = assign.substr(0, pos);
880         string value = assign.substr(pos + 1);
881         fgSetString(name.c_str(), value.c_str());
882         // SG_LOG(SG_GENERAL, SG_INFO, "Setting default value of property "
883         //        << name << " to \"" << value << '"');
884     } else if ( arg.find("--trace-read=") == 0) {
885         string name = arg.substr(13);
886         SG_LOG(SG_GENERAL, SG_INFO, "Tracing reads for property " << name);
887         fgGetNode(name.c_str(), true)
888           ->setAttribute(SGPropertyNode::TRACE_READ, true);
889     } else if ( arg.find("--trace-write=") == 0) {
890         string name = arg.substr(14);
891         SG_LOG(SG_GENERAL, SG_INFO, "Tracing writes for property " << name);
892         fgGetNode(name.c_str(), true)
893           ->setAttribute(SGPropertyNode::TRACE_WRITE, true);
894     } else if ( arg.find( "--view-offset=" ) == 0 ) {
895         // $$$ begin - added VS Renganathan, 14 Oct 2K
896         // for multi-window outside window imagery
897         string woffset = arg.substr( 14 );
898         double default_view_offset = 0.0;
899         if ( woffset == "LEFT" ) {
900                default_view_offset = SGD_PI * 0.25;
901         } else if ( woffset == "RIGHT" ) {
902             default_view_offset = SGD_PI * 1.75;
903         } else if ( woffset == "CENTER" ) {
904             default_view_offset = 0.00;
905         } else {
906             default_view_offset = atof( woffset.c_str() ) * SGD_DEGREES_TO_RADIANS;
907         }
908         /* apparently not used (CLO, 11 Jun 2002) 
909            FGViewer *pilot_view =
910               (FGViewer *)globals->get_viewmgr()->get_view( 0 ); */
911         // this will work without calls to the viewer...
912         fgSetDouble( "/sim/current-view/heading-offset-deg",
913                      default_view_offset  * SGD_RADIANS_TO_DEGREES );
914     // $$$ end - added VS Renganathan, 14 Oct 2K
915     } else if ( arg.find( "--visibility=" ) == 0 ) {
916         fgSetDouble("/environment/visibility-m", atof(arg.substr(13)));
917     } else if ( arg.find( "--visibility-miles=" ) == 0 ) {
918         double visibility = atof(arg.substr(19)) * 5280.0 * SG_FEET_TO_METER;
919         fgSetDouble("/environment/visibility-m", visibility);
920     } else if ( arg.find( "--wind=" ) == 0 ) {
921         double min_hdg, max_hdg, speed, gust;
922         if (!parse_wind(arg.substr(7), &min_hdg, &max_hdg, &speed, &gust)) {
923           SG_LOG( SG_GENERAL, SG_ALERT, "bad wind value " << arg.substr(7) );
924           return FG_OPTIONS_ERROR;
925         }
926         fgSetDouble("/environment/wind-from-heading-deg", min_hdg);
927         fgSetDouble("/environment/params/min-wind-from-heading-deg", min_hdg);
928         fgSetDouble("/environment/params/max-wind-from-heading-deg", max_hdg);
929         fgSetDouble("/environment/wind-speed-kt", speed);
930         fgSetDouble("/environment/params/base-wind-speed-kt", speed);
931         fgSetDouble("/environment/params/gust-wind-speed-kt", gust);
932
933         string val = arg.substr(7);
934         string::size_type pos = val.find('@');
935         if ( pos == string::npos ) {
936           SG_LOG( SG_GENERAL, SG_ALERT, "bad wind value " << val );
937           return FG_OPTIONS_ERROR;
938         }
939         SG_LOG(SG_GENERAL, SG_INFO, "WIND: " << min_hdg << '@' << 
940                speed << " knots" << endl);
941
942 #ifdef FG_WEATHERCM
943         // convert to fps
944         speed *= SG_NM_TO_METER * SG_METER_TO_FEET * (1.0/3600);
945         while (min_hdg > 360)
946           min_hdg -= 360;
947         while (min_hdg <= 0)
948           min_hdg += 360;
949         min_hdg *= SGD_DEGREES_TO_RADIANS;
950         fgSetDouble("/environment/wind-from-north-fps", speed * cos(dir));
951         fgSetDouble("/environment/wind-from-east-fps", speed * sin(dir));
952 #endif // FG_WEATHERCM
953
954     } else if ( arg.find( "--wp=" ) == 0 ) {
955         parse_wp( arg.substr( 5 ) );
956     } else if ( arg.find( "--flight-plan=") == 0) {
957         parse_flightplan ( arg.substr (14) );
958     } else if ( arg.find( "--config=" ) == 0 ) {
959         string file = arg.substr(9);
960         try {
961           readProperties(file, globals->get_props());
962         } catch (const sg_exception &e) {
963           string message = "Error loading config file: ";
964           message += e.getFormattedMessage();
965           SG_LOG(SG_INPUT, SG_ALERT, message);
966           exit(2);
967         }
968     } else if ( arg.find( "--aircraft=" ) == 0 ) {
969         // read in the top level aircraft definition file
970         SGPath apath( globals->get_fg_root() );
971         apath.append( "Aircraft" );
972         apath.append( arg.substr(11) );
973         apath.concat( "-set.xml" );
974         SG_LOG(SG_INPUT, SG_INFO, "Reading aircraft: " << arg.substr(11)
975             << " from " << apath.str());
976         readProperties( apath.str(), globals->get_props() );
977     } else {
978         SG_LOG( SG_GENERAL, SG_ALERT, "Unknown option '" << arg << "'" );
979         return FG_OPTIONS_ERROR;
980     }
981     
982     return FG_OPTIONS_OK;
983 }
984
985
986 // Scan the command line options for an fg_root definition and set
987 // just that.
988 string
989 fgScanForRoot (int argc, char **argv) 
990 {
991     int i = 1;
992
993     SG_LOG(SG_GENERAL, SG_INFO, "Scanning for root: command line");
994
995     while ( i < argc ) {
996         SG_LOG( SG_GENERAL, SG_DEBUG, "argv[" << i << "] = " << argv[i] );
997
998         string arg = argv[i];
999         if ( arg.find( "--fg-root=" ) == 0 ) {
1000             return arg.substr( 10 );
1001         }
1002
1003         i++;
1004     }
1005
1006     return "";
1007 }
1008
1009
1010 // Scan the config file for an fg_root definition and set just that.
1011 string
1012 fgScanForRoot (const string& path)
1013 {
1014     sg_gzifstream in( path );
1015     if ( !in.is_open() )
1016       return "";
1017
1018     SG_LOG( SG_GENERAL, SG_INFO, "Scanning for root: " << path );
1019
1020     in >> skipcomment;
1021 #ifndef __MWERKS__
1022     while ( ! in.eof() ) {
1023 #else
1024     char c = '\0';
1025     while ( in.get(c) && c != '\0' ) {
1026         in.putback(c);
1027 #endif
1028         string line;
1029
1030 #if defined( macintosh )
1031         getline( in, line, '\r' );
1032 #else
1033         getline( in, line, '\n' );
1034 #endif
1035
1036         // catch extraneous (DOS) line ending character
1037         if ( line[line.length() - 1] < 32 ) {
1038             line = line.substr( 0, line.length()-1 );
1039         }
1040
1041         if ( line.find( "--fg-root=" ) == 0 ) {
1042             return line.substr( 10 );
1043         }
1044
1045         in >> skipcomment;
1046     }
1047
1048     return "";
1049 }
1050
1051
1052 // Parse the command line options
1053 void
1054 fgParseArgs (int argc, char **argv)
1055 {
1056     bool in_options = true;
1057
1058     SG_LOG(SG_GENERAL, SG_INFO, "Processing command line arguments");
1059
1060     for (int i = 1; i < argc; i++) {
1061         string arg = argv[i];
1062
1063         if (in_options && (arg.find('-') == 0)) {
1064           if (arg == "--") {
1065             in_options = false;
1066           } else {
1067             int result = parse_option(arg);
1068             if ( (result == FG_OPTIONS_HELP) ||
1069                  (result == FG_OPTIONS_ERROR) ) {
1070               fgUsage();
1071               exit(-1);
1072             }
1073           }
1074         } else {
1075           in_options = false;
1076           SG_LOG(SG_GENERAL, SG_INFO,
1077                  "Reading command-line property file " << arg);
1078           readProperties(arg, globals->get_props());
1079         }
1080     }
1081
1082     SG_LOG(SG_GENERAL, SG_INFO, "Finished command line arguments");
1083 }
1084
1085
1086 // Parse config file options
1087 void
1088 fgParseOptions (const string& path) {
1089     sg_gzifstream in( path );
1090     if ( !in.is_open() ) {
1091         return;
1092     }
1093
1094     SG_LOG( SG_GENERAL, SG_INFO, "Processing config file: " << path );
1095
1096     in >> skipcomment;
1097 #ifndef __MWERKS__
1098     while ( ! in.eof() ) {
1099 #else
1100     char c = '\0';
1101     while ( in.get(c) && c != '\0' ) {
1102         in.putback(c);
1103 #endif
1104         string line;
1105
1106 #if defined( macintosh )
1107         getline( in, line, '\r' );
1108 #else
1109         getline( in, line, '\n' );
1110 #endif
1111
1112         // catch extraneous (DOS) line ending character
1113         if ( line[line.length() - 1] < 32 ) {
1114             line = line.substr( 0, line.length()-1 );
1115         }
1116
1117         if ( parse_option( line ) == FG_OPTIONS_ERROR ) {
1118             SG_LOG( SG_GENERAL, SG_ALERT, 
1119                     "Config file parse error: " << path << " '" 
1120                     << line << "'" );
1121             fgUsage();
1122             exit(-1);
1123         }
1124         in >> skipcomment;
1125     }
1126 }
1127
1128
1129 // Print usage message
1130 void 
1131 fgUsage ()
1132 {
1133     SGPropertyNode options_root;
1134     SGPath opath( globals->get_fg_root() );
1135     opath.append( "options.xml" );
1136
1137     cout << "" << endl;
1138
1139     try {
1140         readProperties(opath.c_str(), &options_root);
1141     } catch (const sg_exception &ex) {
1142         cout << "Unable to read the help file." << endl;
1143         cout << "Make sure the file options.xml is located in the FlightGear base directory," << endl;
1144         cout << "and the location of the base directory is specified bij setting $FG_ROOT or" << endl;
1145         cout << "by adding --fg-root=path as a program argument." << endl;
1146         
1147         exit(-1);
1148     }
1149
1150     SGPropertyNode *options = options_root.getNode("options");
1151     if (!options) {
1152         SG_LOG( SG_GENERAL, SG_ALERT,
1153                 "Error reading options.xml: <options> directive not found." );
1154         exit(-1);
1155     }
1156
1157     SGPropertyNode *usage = options->getNode("usage");
1158     if (usage) {
1159         cout << "Usage: " << usage->getStringValue() << endl;
1160     }
1161
1162     vector<SGPropertyNode_ptr>section = options->getChildren("section");
1163     for (unsigned int j = 0; j < section.size(); j++) {
1164
1165         SGPropertyNode *name = section[j]->getNode("name");
1166         if (name) {
1167             cout << endl << name->getStringValue() << ":" << endl;
1168         }
1169
1170         vector<SGPropertyNode_ptr>option = section[j]->getChildren("option");
1171         for (unsigned int k = 0; k < option.size(); k++) {
1172
1173             SGPropertyNode *name = option[k]->getNode("name");
1174             SGPropertyNode *short_name = option[k]->getNode("short");
1175             SGPropertyNode *key = option[k]->getNode("key");
1176             SGPropertyNode *arg = option[k]->getNode("arg");
1177
1178             if (name) {
1179                 string tmp = name->getStringValue();
1180
1181                 if (key){
1182                     tmp.append(":");
1183                     tmp.append(key->getStringValue());
1184                 }
1185                 if (arg) {
1186                     tmp.append("=");
1187                     tmp.append(arg->getStringValue());
1188                 }
1189                 if (short_name) {
1190                     tmp.append(", -");
1191                     tmp.append(short_name->getStringValue());
1192                 }
1193
1194                 char cstr[96];
1195                 if (tmp.size() <= 25) {
1196                     snprintf(cstr, 96, "   --%-27s", tmp.c_str());
1197                 } else {
1198                     snprintf(cstr, 96, "\n   --%s\n%32c", tmp.c_str(), ' ');
1199                 }
1200                 string msg = cstr;
1201
1202                 SGPropertyNode *desc = option[k]->getNode("description");
1203                 if (desc) {
1204                     msg += desc->getStringValue();
1205
1206                     for ( unsigned int l = 1;
1207                           (desc = option[k]->getNode("description", l, false));
1208                           l++ )
1209                     {
1210                         snprintf(cstr, 96, "\n%32c%s", ' ',
1211                                  desc->getStringValue());
1212                         msg += cstr;
1213                     }
1214                 }
1215                 cout << msg << endl;
1216             }
1217         }
1218     }
1219 }