[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-core-devel
Subject: Re: [PATCH] two patches for 114771
From: Stefan Teleman <steleman () nyc ! rr ! com>
Date: 2005-11-27 22:43:44
Message-ID: 200511271743.44411.steleman () nyc ! rr ! com
[Download RAW message or body]
On Wednesday 23 November 2005 14:01, you wrote:
> > i'll have a patch for you on Sunday evening -- i'm on vacation for the
> > next 2 days.
Here it is (attached) -- diff against 3.5.0rc1.
The messy code path which fakes the zone.tab file should only be reached on
Solaris 8 (starting with Solaris 9 /usr/share/lib/zoneinfo/tab/zone_sun.tab
is available, so everything should be read from there).
--Stefan
--
Stefan Teleman 'Nobody Expects the Spanish Inquisition'
steleman@nyc.rr.com -Monty Python
["ktimezones.cpp.1.diff" (text/x-diff)]
--- ktimezones.cpp.kde.orig 2005-10-10 11:06:02.000000000 -0400
+++ ktimezones.cpp 2005-11-27 17:33:46.953067000 -0500
@@ -17,6 +17,13 @@
Boston, MA 02110-1301, USA.
*/
+#include <cerrno>
+#include <climits>
+#include <cstdlib>
+#include <cstring>
+#include <ctime>
+using namespace std;
+
#include <config.h>
#include <ktimezones.h>
@@ -31,15 +38,13 @@
#include <qregexp.h>
#include <qstringlist.h>
#include <qtextstream.h>
-
-#include <cerrno>
-#include <climits>
-#include <cstdlib>
-#include <cstring>
-#include <ctime>
+#include <qdir.h>
#define UTC_ZONE "UTC"
+template class QValueListIterator<QString>;
+typedef QValueListIterator<QString> QStringListIterator;
+
/**
* Find out if the given standard (e.g. "GMT") and daylight savings time
* (e.g. "BST", but which may be empty) abbreviated timezone names match
@@ -362,6 +367,7 @@
// Have we already done all the hard work? If not, create the cache.
if (m_zones)
return *m_zones;
+
m_zones = new ZoneMap();
// Go read the database.
@@ -371,18 +377,31 @@
//
// For Unix its all easy except knowing where to look. Try the LSB location \
first. QFile f;
+#if defined(SOLARIS) || defined(USE_SOLARIS)
+ m_zoneinfoDir = "/usr/share/lib/zoneinfo";
+ f.setName(m_zoneinfoDir + "/tab/zone_sun.tab");
+#else
m_zoneinfoDir = "/usr/share/zoneinfo";
f.setName(m_zoneinfoDir + "/zone.tab");
+#endif
if (!f.open(IO_ReadOnly))
{
kdDebug() << "Can't open " << f.name() << endl;
m_zoneinfoDir = "/usr/lib/zoneinfo";
+#if defined(SOLARIS) || defined(USE_SOLARIS)
+ f.setName(m_zoneinfoDir + "/tab/zone_sun.tab");
+#else
f.setName(m_zoneinfoDir + "/zone.tab");
+#endif
if (!f.open(IO_ReadOnly))
{
kdDebug() << "Can't open " << f.name() << endl;
m_zoneinfoDir = ::getenv("TZDIR");
+#if defined(SOLARIS) || defined(USE_SOLARIS)
+ f.setName(m_zoneinfoDir + "/tab/zone_sun.tab");
+#else
f.setName(m_zoneinfoDir + "/zone.tab");
+#endif
if (m_zoneinfoDir.isEmpty() || !f.open(IO_ReadOnly))
{
kdDebug() << "Can't open " << f.name() << endl;
@@ -393,25 +412,68 @@
//
// where the country code is set to "??" and the lattitude/longitude
// values are dummies.
- m_zoneinfoDir = "/usr/share/lib/zoneinfo";
+ //
+ m_zoneinfoDir = "/usr/share/lib/zoneinfo/src";
+ QDir d(m_zoneinfoDir);
+ d.setFilter( QDir::Files | QDir::Hidden | QDir::NoSymLinks );
+
+ QFile zoneFile;
+ QStringList tokens;
+ QString line;
+ QRegExp zone("^Zone");
+ QRegExp spaceTab("[ \t]");
+ Q_ULONG r = 0L;
+
KTempFile temp;
- KShellProcess reader;
- reader << "/bin/grep" << "-h" << "^Zone" << m_zoneinfoDir << \
"/src/*" << temp.name() << "|" <<
- "/bin/awk" << "'{print \"??\\t+9999+99999\\t\" $2}'";
- // Note the use of blocking here...it is a trivial amount of data!
- temp.close();
- reader.start(KProcess::Block);
f.setName(temp.name());
- if (!temp.status() || !f.open(IO_ReadOnly))
+ if (!f.open(IO_WriteOnly|IO_Truncate))
{
- kdDebug() << "Can't open " << f.name() << endl;
+ kdError() << "Could not open/create temp file for writing" << \
endl; + return *m_zones;
+ }
+ QStringList fileList = d.entryList();
+ line.reserve(1024);
+
+ QTextStream tmpStream(&f);
+ QStringListIterator bItr = fileList.begin();
+ QStringListIterator eItr = fileList.end();
+ QStringListIterator fItr;
+
+ for (fItr = bItr; fItr != eItr; fItr++)
+ {
+ zoneFile.setName(d.filePath((*fItr).latin1()));
+ if (!zoneFile.open(IO_ReadOnly))
+ {
+ kdDebug() << "Could not open file '" << zoneFile.name().latin1() \
<< "' for reading." << endl; + continue;
+ }
+ while (!zoneFile.atEnd())
+ {
+ if ((r = zoneFile.readLine(line, Q_ULONG(1023))) > 0)
+ {
+ if (line.isEmpty() || '#' == line[0])
+ continue;
+
+ if (0 == line.find(zone))
+ {
+ tokens = QStringList::split(spaceTab, line);
+ tmpStream << "??\t+9999+99999\t" << tokens[1].latin1() << \
"\n"; + }
+ }
+ }
+ zoneFile.close();
+ }
+ f.close();
+ if (!f.open(IO_ReadOnly))
+ {
+ kdError() << "Could not reopen temp file for reading." << endl;
return *m_zones;
}
}
}
}
- // Parse the zone.tab.
+ // Parse the zone.tab or the fake temp file.
QTextStream str(&f);
QRegExp lineSeparator("[ \t]");
QRegExp ordinateSeparator("[+-]");
@@ -442,6 +504,12 @@
// Add entry to list.
if (tokens[0] == "??")
tokens[0] = "";
+
+ // Solaris sets the empty Comments field to '-', making it not empty.
+ // Clean it up.
+ if (tokens[3] == "-")
+ tokens[3] = "";
+
KTimezone *timezone = new KTimezone(db, tokens[2], tokens[0], latitude, \
longitude, tokens[3]); add(timezone);
}
@@ -788,3 +856,6 @@
}
return true;
}
+
+// vim: ts=2 sw=2 et
+
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic