# # # add_file "AbstractParser.cpp" # content [fc2fa0fd3e3b2e83add1dd69a461bcb328467b08] # # add_file "AbstractParser.h" # content [3602e6ed957f2fe41b5c7335af1ebb0ed2547f5b] # # add_file "BasicIOParser.cpp" # content [efa4e089d061a603c1db6ab8553fa4afa0ed3456] # # add_file "BasicIOParser.h" # content [39c50bded66d65ce417ac4bade1bfe3956019e1f] # # add_file "DebugLog.cpp" # content [319ef1250e361a48383b70c7cd52d614b63ef794] # # add_file "DebugLog.h" # content [dc63b4ee3fb60f00c62c32e7c4634e75bc6eae98] # # add_file "Settings.cpp" # content [1605f183154e84e6dcf6afd3e7505afc7d8aad53] # # add_file "Settings.h" # content [c270582aa028c7a903405c024cabd2e6ed0cb965] # # add_file "testfile2.basicio" # content [0e79008ae9a5b52cc1164976e431984dfd9f7484] # # add_file "testfile3.basicio" # content [34ade3052419b9646b8d7b0906f7688e9c97d66b] # # add_file "vocab.h" # content [4e71a34556bdba331e84d2e13221f1d6220c8832] # # patch "basicio_opt.pro" # from [636e4d8dc2eaab4a6e2d7abf40e06bb8232be2ff] # to [fba9c05829c6eac7c9d97ce9c9a58ded77b50032] # # patch "main.cpp" # from [b535470f95cecba14a2024298c11306703ed30e3] # to [747e61cd128927436e3e58bbd4891ec80c320c64] # ============================================================ --- AbstractParser.cpp fc2fa0fd3e3b2e83add1dd69a461bcb328467b08 +++ AbstractParser.cpp fc2fa0fd3e3b2e83add1dd69a461bcb328467b08 @@ -0,0 +1,110 @@ +/*************************************************************************** + * Copyright (C) 2007 by Thomas Keller * + * address@hidden * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation, either version 3 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program. If not, see . * + ***************************************************************************/ + +#include "AbstractParser.h" + +AbstractParser::AbstractParser(const QString & in) +{ + init(in.toUtf8()); +} + +AbstractParser::AbstractParser(const QByteArray & in) +{ + init(in); +} + +void AbstractParser::init(const QByteArray & in) +{ + input = in; + if (input.size() == 0) + charPos = -1; + else + charPos = 0; +} + +AbstractParser::~AbstractParser() +{ + input.clear(); +} + +void AbstractParser::eatSpaces() +{ + while (whatsNext(0) == ' ') { advance(1); } +} + +char AbstractParser::whatsNext(int count /* = 0 */) const +{ + if (charPos == -1) + return '\0'; + + int nextPos = charPos + count; + + if (nextPos >= input.size()) + return '\0'; + + return input.at(nextPos); +} + +void AbstractParser::advance(int count /* = 1 */) +{ + if (charPos == -1) + return; + + if (charPos + count >= input.size()) + { + charPos = -1; + return; + } + + charPos += count; +} + +char AbstractParser::getNext() +{ + const char ch = whatsNext(0); + advance(1); + return ch; +} + +QByteArray AbstractParser::getNext(int count) +{ + if ((charPos + count) > (input.size() - 1)) + { + QByteArray left = getLeftBytes(); + charPos = -1; + return left; + } + + QByteArray next = input.mid(charPos, count); + advance(count); + return next; +} + +QByteArray AbstractParser::getLeftBytes() const +{ + if (charPos == -1) return QByteArray(); + QByteArray left = input.mid(charPos); + return left; +} + +int AbstractParser::getLeftBytesCount() const +{ + if (charPos == -1) return 0; + return input.size() - charPos; +} + ============================================================ --- AbstractParser.h 3602e6ed957f2fe41b5c7335af1ebb0ed2547f5b +++ AbstractParser.h 3602e6ed957f2fe41b5c7335af1ebb0ed2547f5b @@ -0,0 +1,49 @@ +/*************************************************************************** + * Copyright (C) 2007 by Thomas Keller * + * address@hidden * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation, either version 3 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program. If not, see . * + ***************************************************************************/ + +#ifndef ABSTRACT_PARSER_H +#define ABSTRACT_PARSER_H + +#include +#include + +class AbstractParser +{ +public: + AbstractParser(const QByteArray &); + AbstractParser(const QString &); + virtual ~AbstractParser(); + virtual bool parse() = 0; + QByteArray getLeftBytes() const; + int getLeftBytesCount() const; + +protected: + char whatsNext(int count = 0) const; + char getNext(); + QByteArray getNext(int); + void eatSpaces(); + void advance(int count = 1); + +private: + void init(const QByteArray &); + QByteArray input; + int charPos; +}; + +#endif + ============================================================ --- BasicIOParser.cpp efa4e089d061a603c1db6ab8553fa4afa0ed3456 +++ BasicIOParser.cpp efa4e089d061a603c1db6ab8553fa4afa0ed3456 @@ -0,0 +1,148 @@ +/*************************************************************************** + * Copyright (C) 2006 by Thomas Keller * + * address@hidden * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation, either version 3 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program. If not, see . * + ***************************************************************************/ + +#include "BasicIOParser.h" +#include "vocab.h" + +BasicIOParser::BasicIOParser(const QString & input) : AbstractParser(input) {} + +bool BasicIOParser::parse() +{ + while (getLeftBytesCount() > 0) + { + Stanza stanza = getStanza(); + stanzas.append(stanza); + advance(); + } + return true; +} + +Stanza BasicIOParser::getStanza() +{ + Stanza stanza; + + while (true) + { + char next = whatsNext(); + if (next == '\n' || next == '\0') break; + + StanzaEntry entry; + entry.sym = getSymbol(); + if (entry.sym.size() == 0) + { + W("Couldn't get symbol."); + } + QString hash(getHash()); + + // was this a hash? + if (!hash.isNull()) + { + entry.hash = hash; + } + else + { + //grab all string values and put them into a list + while (true) + { + // get value returns an empty string if there are no + // more opening quotes + QString value(getValue()); + if (value.isNull()) break; + entry.vals.append(value); + } + } + stanza.append(entry); + + eatSpaces(); + + char cur = getNext(); + if (cur != '\n' && cur != '\0') + { + W(QString("Expected '\\n' or '\\0', got '%1'").arg(cur)); + } + } + + return stanza; +} + +QString BasicIOParser::getSymbol() +{ + eatSpaces(); + QByteArray payload; + while (true) + { + char cur = whatsNext(); + if ((cur >= 'a' && cur <= 'z') || cur == '_') + { + payload.append(cur); + advance(); + continue; + } + break; + } + + // ascii conv is enough here + return QString(payload); +} + +QString BasicIOParser::getValue() +{ + eatSpaces(); + if (whatsNext() != '"') return QString(); + advance(); + + QByteArray payload; + char last = '\0'; + while (true) + { + char cur = getNext(); + I(cur != '\0'); + // string end? + if (cur == '"' && last != '\\') break; + last = cur; + payload.append(cur); + } + + QString ret = QString::fromUtf8(payload); + ret.replace("\\\\", "\\"); + ret.replace("\\\"", "\""); + return ret; +} + +QString BasicIOParser::getHash() +{ + eatSpaces(); + if (whatsNext() != '[') return QString(); + advance(); + + QString hash; + while (true) + { + char ch = whatsNext(); + if (ch < '0' || (ch > '9' && ch < 'a') || ch > 'f') + { + break; + } + hash.append(ch); + advance(); + } + I(getNext() == ']'); + + return hash; +} + ============================================================ --- BasicIOParser.h 39c50bded66d65ce417ac4bade1bfe3956019e1f +++ BasicIOParser.h 39c50bded66d65ce417ac4bade1bfe3956019e1f @@ -0,0 +1,43 @@ +/*************************************************************************** + * Copyright (C) 2006 by Thomas Keller * + * address@hidden * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation, either version 3 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program. If not, see . * + ***************************************************************************/ + +#ifndef BASICIO_PARSER_H +#define BASICIO_PARSER_H + +#include "AbstractParser.h" +#include "vocab.h" + +class BasicIOParser : public AbstractParser +{ +public: + BasicIOParser(const QString &); + + bool parse(); + inline StanzaList getStanzas() const { return stanzas; } + +private: + Stanza getStanza(); + QString getSymbol(); + QString getValue(); + QString getHash(); + + StanzaList stanzas; +}; + +#endif + ============================================================ --- DebugLog.cpp 319ef1250e361a48383b70c7cd52d614b63ef794 +++ DebugLog.cpp 319ef1250e361a48383b70c7cd52d614b63ef794 @@ -0,0 +1,218 @@ +/*************************************************************************** + * Copyright (C) 2007 by Thomas Keller * + * address@hidden * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation, either version 3 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program. If not, see . * + ***************************************************************************/ + +#include "DebugLog.h" +#include "Settings.h" +#include +#include +#include + +#include +#include +#include + +DebugLog* DebugLog::instance = 0; + +DebugLog* DebugLog::singleton() +{ + if (!instance) + { + instance = new DebugLog(); + } + return instance; +} + +DebugLog::DebugLog() +{ + consoleLogging = Settings::getConsoleLogEnabled(); + fileLogging = Settings::getFileLogEnabled(); + int level = Settings::getLogLevel(); + if (level >= Fatal && level <= Debug) logLevel = static_cast(level); + + if (fileLogging && !openLogfile()) + { + critical(QString("Cannot open logfile '%1' for writing, " + "disable file logging.").arg(logFilePath())); + fileLogging = false; + } + + QString sep; + QDate today = QDate::currentDate(); + sep.fill('=', 40); + log(Info, sep); + log(Info, + QString(" guitone session started (%1)") + .arg(today.toString("yyyy-MM-dd")) + ); + log(Info, sep); +} + +DebugLog::~DebugLog() +{ + if (logFile.isOpen()) closeLogfile(); +} + +bool DebugLog::openLogfile() +{ + logFile.setFileName(logFilePath()); + + QFlags flags = + QIODevice::WriteOnly | QIODevice::Append | + QIODevice::Text | QIODevice::Unbuffered; + + if (!logFile.open(flags)) return false; + + return true; +} + +void DebugLog::log(Type t, QString msg) +{ + if (!fileLogging && !consoleLogging) return; + + if (logLevel == Fatal && t > Fatal) return; + if (logLevel == Critical && t > Critical) return; + if (logLevel == Warn && t > Warn) return; + if (logLevel == Info && t > Info) return; + if (logLevel == Debug && t > Debug) return; + + QMap errors; + errors[0] = "fatal"; + errors[1] = "critical"; + errors[2] = "warning"; + errors[3] = "info"; + errors[4] = "debug"; + + // do not use I here since this calls qFatal and results in + // an endless loop + assert(t <= errors.size()); + + QTime now = QTime::currentTime(); + + QString logStr; + logStr.append( + QString("%1: %2: %3\n") + .arg(now.toString("hh:mm:ss.zzz")) + .arg(errors[t-1]) + .arg(msg) + ); + + QByteArray utf8_msg = logStr.toUtf8(); + + // print the message on console + if (consoleLogging) + { + fprintf(stderr, utf8_msg.constData()); + } + + // print the message to the logfile + if (fileLogging && logFile.isOpen()) + { + logFile.write(utf8_msg); + } +} + +void DebugLog::closeLogfile() +{ + if (logFile.isOpen()) logFile.close(); +} + +#ifndef QT_NO_DEBUG +void DebugLog::debug(QString msg) +{ + singleton()->log(Debug, msg); +} +#else +void DebugLog::debug(QString msg) { Q_UNUSED(msg); } +#endif + +void DebugLog::info(QString msg) +{ + singleton()->log(Info, msg); +} + +void DebugLog::warn(QString msg) +{ + singleton()->log(Warn, msg); +} + +void DebugLog::critical(QString msg) +{ + singleton()->log(Critical, msg); +} + +void DebugLog::fatal(QString msg) +{ + singleton()->log(Fatal, msg); +} + +void DebugLog::setConsoleLogEnabled(bool enabled) +{ + DebugLog * log = singleton(); + log->consoleLogging = enabled; + Settings::setConsoleLogEnabled(enabled); +} + +bool DebugLog::getConsoleLogEnabled() +{ + return singleton()->consoleLogging; +} + +void DebugLog::setFileLogEnabled(bool enabled) +{ + DebugLog * log = singleton(); + if (log->fileLogging && !enabled) + { + log->closeLogfile(); + } + else if (!log->fileLogging && enabled) + { + if (!log->openLogfile()) + { + log->critical(QString("Cannot open logfile '%1' for writing, " + "disable file logging.").arg(logFilePath())); + enabled = false; + } + } + log->fileLogging = enabled; + Settings::setFileLogEnabled(enabled); +} + +bool DebugLog::getFileLogEnabled() +{ + return singleton()->fileLogging; +} + +void DebugLog::setLogLevel(int level) +{ + if (level < Fatal || level > Debug) return; + singleton()->logLevel = static_cast(level); + Settings::setLogLevel(level); +} + +int DebugLog::getLogLevel() +{ + return static_cast(singleton()->logLevel); +} + +QString DebugLog::logFilePath() +{ + QString path(QDir::homePath()); + path.append(QDir::separator()).append("guitone.log"); + return path; +} + ============================================================ --- DebugLog.h dc63b4ee3fb60f00c62c32e7c4634e75bc6eae98 +++ DebugLog.h dc63b4ee3fb60f00c62c32e7c4634e75bc6eae98 @@ -0,0 +1,74 @@ +/*************************************************************************** + * Copyright (C) 2007 by Thomas Keller * + * address@hidden * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation, either version 3 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program. If not, see . * + ***************************************************************************/ + +#ifndef DEBUG_LOG_H +#define DEBUG_LOG_H + +#include +#include + +class DebugLog : public QObject +{ +public: + // higher levels include lower ones, i.e. + // 'warn' also prints out 'critical' and 'fatal'; + // 'debug' prints out everything we have + enum Level {Fatal = 1, Critical, Warn, Info, Debug }; + // as we have different Levels each level's name is also + // the name for a specific log type + typedef Level Type; + + static void setFileLogEnabled(bool); + static void setConsoleLogEnabled(bool); + static void setLogLevel(int); + + static bool getFileLogEnabled(); + static bool getConsoleLogEnabled(); + static int getLogLevel(); + + static QString logFilePath(); + + static void info(QString); + static void debug(QString); + inline static void debug(const char * msg) { return debug(QString::fromUtf8(msg)); } + static void warn(QString); + inline static void warn(const char * msg) { return warn(QString::fromUtf8(msg)); } + static void critical(QString); + inline static void critical(const char * msg) { return critical(QString::fromUtf8(msg)); } + static void fatal(QString); + inline static void fatal(const char * msg) { return fatal(QString::fromUtf8(msg)); } + +private: + + DebugLog(); + ~DebugLog(); + bool openLogfile(); + void closeLogfile(); + void log(Type, QString); + + bool consoleLogging; + bool fileLogging; + Level logLevel; + QFile logFile; + + static DebugLog * singleton(); + static DebugLog * instance; +}; + + +#endif ============================================================ --- Settings.cpp 1605f183154e84e6dcf6afd3e7505afc7d8aad53 +++ Settings.cpp 1605f183154e84e6dcf6afd3e7505afc7d8aad53 @@ -0,0 +1,206 @@ +/*************************************************************************** + * Copyright (C) 2006 by Ingo Maindorfer * + * address@hidden * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation, either version 3 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program. If not, see . * + ***************************************************************************/ + +#include "Settings.h" +#include "vocab.h" + +#include + +Settings * Settings::instance = 0; + +Settings * Settings::singleton() +{ + if (!instance) + { + QCoreApplication::setOrganizationName("Thomas Keller"); + QCoreApplication::setOrganizationDomain("thomaskeller.biz"); + QCoreApplication::setApplicationName("guitone"); + + instance = new Settings(); + } + return instance; +} + +Settings::Settings() : QSettings() {} + +Settings::~Settings() {} + +void Settings::setBool(const QString & name, bool value) +{ + I(!name.isEmpty()); + singleton()->setValue(name, value); +} + +bool Settings::getBool(const QString & name, bool defaultVal) +{ + I(!name.isEmpty()); + return singleton()->value(name, defaultVal).toBool(); +} + +void Settings::setWindowGeometry(const QString & windowClass, const QByteArray & data) +{ + I(!windowClass.isEmpty()); + singleton()->setValue(windowClass, data); +} + +QByteArray Settings::getWindowGeometry(const QString & windowClass) +{ + I(!windowClass.isEmpty()); + return singleton()->value(windowClass).toByteArray(); +} + +void Settings::sync() +{ + singleton()->QSettings::sync(); +} + +QString Settings::getMtnBinaryPath() +{ + return singleton()->value("MtnExePath", "mtn").toString(); +} + +void Settings::setMtnBinaryPath(QString path) +{ + singleton()->setValue("MtnExePath", path); +} + +bool Settings::getConsoleLogEnabled() +{ + return singleton()->value("ConsoleLogEnabled", true).toBool(); +} + +void Settings::setConsoleLogEnabled(bool enabled) +{ + singleton()->setValue("ConsoleLogEnabled", enabled); +} + +bool Settings::getFileLogEnabled() +{ + return singleton()->value("FileLogEnabled", false).toBool(); +} + +void Settings::setFileLogEnabled(bool enabled) +{ + singleton()->setValue("FileLogEnabled", enabled); +} + +int Settings::getLogLevel() +{ + // 4 is debug, see DebugLog.h + return singleton()->value("LogLevel", 4).toInt(); +} + +void Settings::setLogLevel(int verbosity) +{ + singleton()->setValue("LogLevel", verbosity); +} + +void Settings::saveHeaderViewState(QHeaderView *view, QString name) +{ + I(!name.isEmpty()); + QStringList cols; + for (int i=0, j=view->count(); isectionSize(i)). + append(":"). + append(QString::number(view->visualIndex(i))) + ); + } + Settings *settings = singleton(); + settings->setValue(name, cols.join(",")); +} + +void Settings::restoreHeaderViewState(QHeaderView *view, QString name) +{ + I(!name.isEmpty()); + QString colConfig(singleton()->value(name).toString()); + QStringList cols = colConfig.split(",", QString::SkipEmptyParts); + + int colCount = cols.size(); + if (colCount == 0) return; + + int curColCount = view->count(); + + for (int i=0; i < colCount && i < curColCount; i++) + { + QStringList parts = cols.at(i).split(":", QString::SkipEmptyParts); + + I(parts.size() == 2); + + view->resizeSection(i, parts.at(0).toInt()); + view->moveSection(view->visualIndex(i), parts.at(1).toInt()); + } +} + +QByteArray Settings::getSplitterState(QString name) +{ + I(!name.isEmpty()); + return singleton()->value(name).toByteArray(); +} + +void Settings::setSplitterState(const QByteArray & byteArray, QString name) +{ + I(!name.isEmpty()); + Settings *settings = singleton(); + settings->setValue(name, byteArray); +} + +void Settings::setItemList(const QString & name, const QStringList & items) +{ + I(!name.isEmpty()); + Settings *settings = singleton(); + settings->setValue(name, items); +} + +QStringList Settings::getItemList(const QString & name) +{ + I(!name.isEmpty()); + return singleton()->value(name).toStringList(); +} + +void Settings::addItemToList(const QString & name, const QString & item, int maxItems) +{ + QStringList list = getItemList(name); + + // move an already recorded item to the front + int pos = list.indexOf(item); + if (pos > -1) + { + list.move(pos, 0); + } + else + { + if (list.size() > maxItems) + { + list.removeLast(); + } + list.prepend(item); + } + setItemList(name, list); +} + +void Settings::removeItemFromList(const QString & name, const QString & item) +{ + QStringList list = getItemList(name); + int pos = list.indexOf(item); + if (pos == -1) return; + list.removeAt(pos); + setItemList(name, list); +} + ============================================================ --- Settings.h c270582aa028c7a903405c024cabd2e6ed0cb965 +++ Settings.h c270582aa028c7a903405c024cabd2e6ed0cb965 @@ -0,0 +1,67 @@ +/*************************************************************************** + * Copyright (C) 2006 by Ingo Maindorfer * + * address@hidden * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation, either version 3 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program. If not, see . * + ***************************************************************************/ + +#ifndef SETTINGS_H +#define SETTINGS_H + +#include +#include +#include + +class Settings : public QSettings +{ + +public: + static void setBool(const QString &, bool); + static bool getBool(const QString &, bool); + + static void setWindowGeometry(const QString &, const QByteArray &); + static QByteArray getWindowGeometry(const QString &); + + static QStringList getItemList(const QString &); + static void setItemList(const QString &, const QStringList &); + static void addItemToList(const QString&, const QString &, int); + static void removeItemFromList(const QString &, const QString &); + + static QString getMtnBinaryPath(); + static void setMtnBinaryPath(QString); + + static bool getConsoleLogEnabled(); + static void setConsoleLogEnabled(bool); + static bool getFileLogEnabled(); + static void setFileLogEnabled(bool); + static int getLogLevel(); + static void setLogLevel(int); + + static void saveHeaderViewState(QHeaderView *, QString); + static void restoreHeaderViewState(QHeaderView *, QString); + + static QByteArray getSplitterState(QString); + static void setSplitterState(const QByteArray &, QString); + + static void sync(); + +private: + Settings(); + ~Settings(void); + static Settings* singleton(); + static Settings* instance; +}; + + +#endif ============================================================ --- testfile2.basicio 0e79008ae9a5b52cc1164976e431984dfd9f7484 +++ testfile2.basicio 0e79008ae9a5b52cc1164976e431984dfd9f7484 @@ -0,0 +1,65 @@ + path "" +old_type "directory" +new_type "directory" + fs_type "directory" + status "known" + + path "dir1" +old_type "directory" +new_path "dir3/dir1" + fs_type "none" + status "rename_source" + + path "dir1/dir2" +old_type "directory" +new_path "dir3/dir1/dir2" + fs_type "none" + status "rename_source" + + path "dir1/file1" +old_type "file" +new_path "dir3/dir1/file1" + fs_type "none" + status "rename_source" + + path "dir3" +old_type "directory" +new_type "directory" + fs_type "directory" + status "known" + + path "dir3/_MTN" +old_type "directory" +new_type "directory" + fs_type "file" + status "invalid" + + path "dir3/dir1" +new_type "directory" +old_path "dir1" + fs_type "directory" + status "rename_target" "known" + + path "dir3/dir1/dir2" +new_type "directory" +old_path "dir1/dir2" + fs_type "directory" + status "rename_target" "known" + + path "dir3/dir1/file1" +new_type "file" +old_path "dir1/file1" + fs_type "file" + status "rename_target" "known" + + path "new_dir1" +fs_type "directory" + status "unknown" + + path "new_dir1/dir2" +fs_type "directory" + status "unknown" + + path "new_dir1/file1" +fs_type "file" + status "unknown" ============================================================ --- testfile3.basicio 34ade3052419b9646b8d7b0906f7688e9c97d66b +++ testfile3.basicio 34ade3052419b9646b8d7b0906f7688e9c97d66b @@ -0,0 +1,5 @@ + path "" +old_type "directory" +new_type "directory" + fs_type "directory" + status "known" ============================================================ --- vocab.h 4e71a34556bdba331e84d2e13221f1d6220c8832 +++ vocab.h 4e71a34556bdba331e84d2e13221f1d6220c8832 @@ -0,0 +1,102 @@ +#ifndef VOCAB_H +#define VOCAB_H + +// +// global macros and defines +// + +// if you use any of those two, you also have to include Guitone.h +class Guitone; +#define APP reinterpret_cast(qApp) +#define MTN(arg) APP->getMonotoneInstance(arg) + +#include "DebugLog.h" +#ifdef QT_NO_DEBUG +#define D(msg) void(msg) +#else +#define D(msg) DebugLog::debug(QString("%1:%2:%3: %4") \ + .arg(__FILE__).arg(__FUNCTION__).arg(__LINE__).arg(QString(msg))) +#endif + +#define L(msg) DebugLog::info(QString("%1:%2:%3: %4") \ + .arg(__FILE__).arg(__FUNCTION__).arg(__LINE__).arg(QString(msg))) +#define W(msg) DebugLog::warn(QString("%1:%2:%3: %4") \ + .arg(__FILE__).arg(__FUNCTION__).arg(__LINE__).arg(QString(msg))) +#define C(msg) DebugLog::critical(QString("%1:%2:%3: %4") \ + .arg(__FILE__).arg(__FUNCTION__).arg(__LINE__).arg(QString(msg))) +#define F(msg) { \ + DebugLog::fatal(QString("%1:%2:%3: %4") \ + .arg(__FILE__).arg(__FUNCTION__).arg(__LINE__).arg(QString(msg))); \ + abort(); \ + } + +#define I(expr) if (!(expr)) F(QString("invariant \"%1\" violated").arg(#expr)) + +// +// type definitions +// + +#include +#include +#include +#include + +// used for manifest entries, if the bool var is true, the entry is a directory +struct FileEntry { + FileEntry() {} + FileEntry(QString p, bool d) : path(p), is_dir(d) {} + FileEntry(QString p, bool d, QString f) : path(p), is_dir(d), fileid(f) {} + QString path; + bool is_dir; + QString fileid; + QMap attrs; + + inline bool operator<(const FileEntry & other) const + { + return path < other.path; + } +}; + +typedef QList FileEntryList; + +typedef QStringList RevisionList; + +// used for revision certs +typedef QString CertKey; +typedef QString CertValue; +typedef QPair RevisionCert; +typedef QList RevisionCerts; + +// used to store the output of automate certs +typedef struct { + enum Trust { Trusted, Untrusted } trust; + enum Signature { Ok, Bad, Unknown } signature; + QString key; + QString name; + QString value; +} Cert; +typedef QList CertList; + +typedef QList ByteArrayList; + +// used for BasicIOParser and BasicIOWriter +struct StanzaEntry { + StanzaEntry() {} + StanzaEntry(QString s, QString h) : sym(s), hash(h) {} + StanzaEntry(QString s, QStringList v) : sym(s), vals(v) {} + + QString sym; + QString hash; + QStringList vals; +}; + +typedef QList Stanza; +typedef QList StanzaList; + +typedef QString GuitoneException; + +// TODO: maybe we can load workspace normalization into this +typedef QString WorkspacePath; +typedef QString DatabaseFile; + +#endif ============================================================ --- basicio_opt.pro 636e4d8dc2eaab4a6e2d7abf40e06bb8232be2ff +++ basicio_opt.pro fba9c05829c6eac7c9d97ce9c9a58ded77b50032 @@ -1,11 +1,17 @@ ###################################################################### -# Automatically generated by qmake (2.01a) Fr Feb 8 22:06:01 2008 +# Automatically generated by qmake (2.01a) Fr Feb 8 22:13:32 2008 ###################################################################### TEMPLATE = app TARGET = DEPENDPATH += . INCLUDEPATH += . +CONFIG -= app_bundle # Input +HEADERS += AbstractParser.h BasicIOParser.h DebugLog.h Settings.h vocab.h +SOURCES += AbstractParser.cpp \ + BasicIOParser.cpp \ + DebugLog.cpp \ + main.cpp \ + Settings.cpp -SOURCES += main.cpp ============================================================ --- main.cpp b535470f95cecba14a2024298c11306703ed30e3 +++ main.cpp 747e61cd128927436e3e58bbd4891ec80c320c64 @@ -1,20 +1,29 @@ #include -#include "util/BasicIOParser.h" +#include "BasicIOParser.h" - int main(int argc, char ** argv) { - QCoreApplication app(argc, argv); - if (app.arguments().size() != 1) - qFatal("Usage: ./basicio_opt BASIC_IO_FILE"); - QFile fp(app.arguments().at(0)); - if (!fp.open(QIODevice::ReadOnly)) - qFatal("Cannot open file for reading"); - QString contents(fp.readAll()); - fp.close(); - BasicIOParser p(contents); - return static_cast(p.parse()); + QCoreApplication app(argc, argv); + if (app.arguments().size() != 2) + qFatal("Usage: ./basicio_opt BASIC_IO_FILE"); + QFile fp(app.arguments().at(1)); + if (!fp.open(QIODevice::ReadOnly)) + qFatal("Cannot open file for reading"); + QString contents(fp.readAll()); + fp.close(); + BasicIOParser p(contents); +/* + StanzaList stanzas = p.getStanzas(); + foreach (Stanza st, stanzas) + { + foreach (StanzaEntry sten, st) + { + D(QString("/%1/ %2").arg(sten.sym).arg(sten.hash + sten.vals.join(","))); + } + } +*/ + return static_cast(p.parse()); }