From 48906a623383ab5222541ae048e99dd039b62a9a Mon Sep 17 00:00:00 2001 From: Timothy Pearson Date: Fri, 1 Feb 2013 17:25:34 -0600 Subject: Fix FTBFS --- tderadio3/convert-presets/convert-presets.cpp | 192 ++++++++++++++++++++++++++ 1 file changed, 192 insertions(+) create mode 100644 tderadio3/convert-presets/convert-presets.cpp (limited to 'tderadio3/convert-presets/convert-presets.cpp') diff --git a/tderadio3/convert-presets/convert-presets.cpp b/tderadio3/convert-presets/convert-presets.cpp new file mode 100644 index 0000000..7ad2dca --- /dev/null +++ b/tderadio3/convert-presets/convert-presets.cpp @@ -0,0 +1,192 @@ +#ifdef HAVE_CONFIG_H +#include +#endif + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define dev_urandom "/dev/urandom" + +TQString createStationID() +{ + const int buffersize = 32; + unsigned char buffer[buffersize]; + + TQString stime, srandom = ""; + stime.setNum(time(NULL)); + + int fd = open (dev_urandom, O_RDONLY); + read(fd, buffer, buffersize); + close(fd); + for (int i = 0; i < buffersize; ++i) + srandom += TQString().sprintf("%02X", (unsigned int)buffer[i]); + +// kdDebug() << i18n("generated StationID: ") << stime << srandom << endl; + + return stime + srandom; +} + + + + +bool convertFile(const TQString &file) +{ + //////////////////////////////////////////////////////////////////////// + // read input + //////////////////////////////////////////////////////////////////////// + + TQFile presetFile (file); + + if (! presetFile.open(IO_ReadOnly)) { + kdDebug() << "convertFile: " + << i18n("error opening preset file") + << " " << file << " " + << i18n("for reading") << endl; + return false; + } + + TQString xmlData; + + // make sure that qtextstream is gone when we close presetFile + { + TQTextStream ins(&presetFile); + ins.setEncoding(TQTextStream::Locale); + xmlData = ins.read(); + } + + if (xmlData.find("", 0, false) >= 0) { + kdDebug() << "file " << file << " already in new format" << endl; + // but add \n" + xmlData; + } + + } else { + + //////////////////////////////////////////////////////////////////////// + // convert file + //////////////////////////////////////////////////////////////////////// + + TQRegExp qselect(".*"); + TQRegExp docking(".*"); + TQRegExp station("(.*)"); + TQRegExp stationlist(""); + TQRegExp emptyLines("\\n\\s*\\n"); + + #define stationIDElement "stationID" + + qselect.setMinimal(true); + docking.setMinimal(true); + station.setMinimal(true); + + xmlData = "\n" + xmlData; + xmlData.replace(stationlist, "\n\t\tkradio-1.0"); + xmlData.replace(qselect, ""); + xmlData.replace(docking, ""); + xmlData.replace(station, "\n" + "\t\t\t<" stationIDElement ">" + "\\1" + ); + + int p = 0; + int f = 0; + while ( (f = xmlData.find("<" stationIDElement ">", p) ) >= 0) { + xmlData.insert(f + 2 + TQString(stationIDElement).length(), createStationID()); + } + + xmlData.replace(emptyLines, "\n"); + } + + presetFile.close(); + + + //////////////////////////////////////////////////////////////////////// + // write output + //////////////////////////////////////////////////////////////////////// + + if (! presetFile.open(IO_WriteOnly)) { + kdDebug() << "convertFile: " + << i18n("error opening preset file") + << " " << file << " " + << i18n("for writing") << endl; + return false; + } + + TQTextStream outs(&presetFile); + outs.setEncoding(TQTextStream::UnicodeUTF8); + + outs << xmlData; + + if (presetFile.status() != IO_Ok) { + kdDebug() << "StationList::writeXML: " + << i18n("error writing preset file") + << " " << file + << " (" << presetFile.state() << ")" + << endl; + return false; + } + + return true; +} + + +static const char *description = "convert-presets"; + +static KCmdLineOptions options[] = +{ + { "q", I18N_NOOP("be quiet"), 0}, + { "+[preset files]", I18N_NOOP("preset file to convert"), 0 }, + KCmdLineLastOption +}; + +int main(int argc, char *argv[]) +{ + TDEAboutData aboutData("convert-presets", I18N_NOOP("convert-presets"), + VERSION, description, TDEAboutData::License_GPL, + "(c) 2003-2005 Martin Witte", + 0, + "http://sourceforge.net/projects/kradio", + 0); + aboutData.addAuthor("Martin Witte", "", "witte@kawo1.rwth-aachen.de"); + + TDECmdLineArgs::init( argc, argv, &aboutData ); + TDECmdLineArgs::addCmdLineOptions( options ); // Add our own options. + + TDEApplication a (false, false); + + TDECmdLineArgs *args = TDECmdLineArgs::parsedArgs(); + + for (int i = 0; i < args->count(); ++i) { + const char *x = args->arg(i); + if (! convertFile(x)) { + return -1; + } else { + if (! args->isSet("q")) + kdDebug() << x << ": ok" << endl; + } + } + if (args->count() == 0) { + kdDebug() << "no input" << endl; + return -1; + } + + return 0; +} -- cgit v1.2.1