]> git.mxchange.org Git - flightgear.git/blobdiff - src/Main/metar_main.cxx
Martin Spott: Use standardized Sun directive.
[flightgear.git] / src / Main / metar_main.cxx
index 20b638591602393bd8e3decb1a9fffa18dc0b501..36567ffb30b640fcc9f9636ae46ceaed130546f5 100644 (file)
 
 #include <iomanip>
 #include <sstream>
+#include <string.h>
 
 #include <simgear/debug/logstream.hxx>
-#include <simgear/structure/exception.hxx>
 #include <simgear/environment/metar.hxx>
+#include <simgear/structure/exception.hxx>
 
 using namespace std;
 
 // text color
-#if defined(__linux__) || defined( __sun__ ) ||defined(__CYGWIN__) || defined( __FreeBSD__ )
+#if defined(__linux__) || defined(__sun) || defined(__CYGWIN__) \
+    || defined( __FreeBSD__ ) || defined ( sgi )
 #      define R "\033[31;1m"           // red
 #      define G "\033[32;1m"           // green
 #      define Y "\033[33;1m"           // yellow
@@ -132,9 +134,7 @@ void printReport(SGMetar *m)
        // date/time
        int year = m->getYear();
        int month = m->getMonth();
-       cout << "Report time:\t\t";
-       if (year != -1 && month != -1)
-               cout << year << '/' << month << '/' << m->getDay();
+       cout << "Report time:\t\t" << year << '/' << month << '/' << m->getDay();
        cout << ' ' << m->getHour() << ':';
        cout << setw(2) << setfill('0') << m->getMinute() << " UTC" << endl;
 
@@ -264,7 +264,7 @@ void printReport(SGMetar *m)
 
                // assemble surface string
                vector<string> surface;
-               if ((s = rwy.getDeposit()) && strlen(s))
+               if ((s = rwy.getDepositString()) && strlen(s))
                        surface.push_back(s);
                if ((s = rwy.getExtentString()) && strlen(s))
                        surface.push_back(s);
@@ -426,21 +426,60 @@ void printArgs(SGMetar *m, double airport_elevation)
 }
 
 
-void help()
+void getproxy(string& host, string& port)
+{
+       host = "";
+       port = "80";
+
+       const char *p = getenv("http_proxy");
+       if (!p)
+               return;
+       while (isspace(*p))
+               p++;
+       if (!strncmp(p, "http://", 7))
+               p += 7;
+       if (!*p)
+               return;
+
+       char s[256], *t;
+       strncpy(s, p, 255);
+       s[255] = '\0';
+
+       for (t = s + strlen(s); t > s; t--)
+               if (!isspace(t[-1]) && t[-1] != '/')
+                       break;
+       *t = '\0';
+
+       t = strchr(s, ':');
+       if (t) {
+               *t++ = '\0';
+               port = t;
+       }
+       host = s;
+}
+
+
+void usage()
 {
        printf(
-               "Usage:    metar [-v] [-e elevation] [-r|-c] <list of ICAO airport ids or METAR strings>\n"
-               "          -h|--help            show this help\n"
-               "          -v|--verbose         verbose output\n"
-               "          -r|--report          print report (default)\n"
-               "          -c|--command-line    print command line\n"
-               "          -e E|--elevation E   set airport elevation to E meters\n"
-               "                               (added to cloud bases in command line mode)\n"
+               "Usage: metar [-v] [-e elevation] [-r|-c] <list of ICAO airport ids or METAR strings>\n"
+               "       metar -h\n"
+               "\n"
+               "       -h|--help            show this help\n"
+               "       -v|--verbose         verbose output\n"
+               "       -r|--report          print report (default)\n"
+               "       -c|--command-line    print command line\n"
+               "       -e E|--elevation E   set airport elevation to E meters\n"
+               "                            (added to cloud bases in command line mode)\n"
+               "Environment:\n"
+               "       http_proxy           set proxy in the form \"http://host:port/\"\n"
                "\n"
-               "Examples: metar ksfo koak\n"
-               "          metar -c ksfo -r ksfo\n"
-               "          metar \"LOWL 161500Z 19004KT 160V240 9999 FEW035 SCT300 29/23 Q1006 NOSIG\"\n"
-               "          fgfs  `metar -e 183 -c loww`\n"
+               "Examples:\n"
+               "       $ metar ksfo koak\n"
+               "       $ metar -c ksfo -r ksfo\n"
+               "       $ metar \"LOWL 161500Z 19004KT 160V240 9999 FEW035 SCT300 29/23 Q1006 NOSIG\"\n"
+               "       $ fgfs  `metar -e 183 -c loww`\n"
+               "       $ http_proxy=http://localhost:3128/ metar ksfo\n"
                "\n"
        );
 }
@@ -453,13 +492,16 @@ int main(int argc, char *argv[])
        double elevation = 0.0;
 
        if (argc <= 1) {
-               help();
+               usage();
                return 0;
        }
 
+       string proxy_host, proxy_port;
+       getproxy(proxy_host, proxy_port);
+
        for (int i = 1; i < argc; i++) {
                if (!strcmp(argv[i], "-h") || !strcmp(argv[i], "--help"))
-                       help();
+                       usage();
                else if (!strcmp(argv[i], "-v") || !strcmp(argv[i], "--verbose"))
                        verbose = true;
                else if (!strcmp(argv[i], "-r") || !strcmp(argv[i], "--report"))
@@ -468,13 +510,20 @@ int main(int argc, char *argv[])
                        report = false;
                else if (!strcmp(argv[i], "-e") || !strcmp(argv[i], "--elevation")) {
                        if (++i >= argc) {
-                               cerr << "-e options used without elevation" << endl;
+                               cerr << "-e option used without elevation" << endl;
                                return 1;
                        }
                        elevation = strtod(argv[i], 0);
                } else {
+                       static bool shown = false;
+                       if (verbose && !shown) {
+                               cerr << "Proxy host: '" << proxy_host << "'" << endl;
+                               cerr << "Proxy port: '" << proxy_port << "'" << endl << endl;
+                               shown = true;
+                       }
+
                        try {
-                               SGMetar *m = new SGMetar(argv[i]);
+                               SGMetar *m = new SGMetar(argv[i], proxy_host, proxy_port, "", time(0));
                                //SGMetar *m = new SGMetar("2004/01/11 01:20\nLOWG 110120Z AUTO VRB01KT 0050 1600N R35/0600 FG M06/M06 Q1019 88//////\n");
 
                                if (verbose) {