FreeBSD: add iso3166 file parsing
authorFneufneu <fneufneu@xbmc.org>
Fri, 11 Feb 2011 16:36:08 +0000 (17:36 +0100)
committerFneufneu <fneufneu@xbmc.org>
Mon, 7 May 2012 07:33:52 +0000 (09:33 +0200)
we don't have iso3166.tab, but we have iso3166 file with little diff
we have 4 field per line like this:
two three number name

xbmc/linux/LinuxTimezone.cpp

index 689bceb..089644b 100644 (file)
@@ -39,6 +39,7 @@ CLinuxTimezone::CLinuxTimezone() : m_IsDST(0)
 {
    char* line = NULL;
    size_t linelen = 0;
+   int nameonfourthfield = 0;
    CStdString s;
    vector<CStdString> tokens;
 
@@ -94,6 +95,11 @@ CLinuxTimezone::CLinuxTimezone() : m_IsDST(0)
 
    // Load countries
    fp = fopen("/usr/share/zoneinfo/iso3166.tab", "r");
+   if (!fp)
+   {
+      fp = fopen("/usr/share/misc/iso3166", "r");
+      nameonfourthfield = 1;
+   }
    if (fp)
    {
       CStdString countryCode;
@@ -114,6 +120,16 @@ CLinuxTimezone::CLinuxTimezone() : m_IsDST(0)
          int i = 2;
          while (s[i] == ' ' || s[i] == '\t') i++;
 
+         if (nameonfourthfield)
+         {
+            // skip three letter
+            while (s[i] != ' ' && s[i] != '\t') i++;
+            while (s[i] == ' ' || s[i] == '\t') i++;
+            // skip number
+            while (s[i] != ' ' && s[i] != '\t') i++;
+            while (s[i] == ' ' || s[i] == '\t') i++;
+         }
+
          countryCode = s.Left(2);
          countryName = s.Mid(i);