From 2703d74fbdfccb994252c5b762ba1c3d6a766954 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Sat, 28 Aug 2010 12:47:33 +0200 Subject: [PATCH] Sane output from offset dumper --- library/VersionInfo.cpp | 88 +++++++++++++++++++++------- library/include/dfhack/VersionInfo.h | 3 +- 2 files changed, 70 insertions(+), 21 deletions(-) diff --git a/library/VersionInfo.cpp b/library/VersionInfo.cpp index fe18ec4f4..908de9aeb 100644 --- a/library/VersionInfo.cpp +++ b/library/VersionInfo.cpp @@ -81,7 +81,47 @@ namespace DFHack uint32_t type_offset; // offset of type data for multiclass std::vector subs; }; -} + class indentr + { + public: + friend std::basic_ostream& operator <<(std::basic_ostream&, const indentr &); + indentr(int ns = 0, int size = 4) + { + numspaces = ns; + step = size; + } + void indent () + { + numspaces += step; + if (numspaces < 0) numspaces = 0; + } + void unindent () + { + numspaces -= step; + if (numspaces < 0) numspaces = 0; + } + int get () + { + return numspaces; + } + void set (int ns) + { + numspaces = ns; + if (numspaces < 0) numspaces = 0; + } + private: + int step; + int numspaces; + }; + std::basic_ostream& operator<< (std::basic_ostream& os, const indentr & idtr) + { + for(int i = 0; i < idtr.numspaces ;i++) + { + os << ' '; + } + return os; + } +}; /* * Private data @@ -311,38 +351,41 @@ std::string OffsetGroup::getFullName() return accum; } -std::string OffsetGroup::PrintOffsets() +std::string OffsetGroup::PrintOffsets(int indentation) { uint32_Iter iter; ostringstream ss; + indentr i(indentation); for(iter = OGd->addresses.begin(); iter != OGd->addresses.end(); iter++) { if((*iter).second.first) - ss << "
" << endl; + ss << i << "
" << endl; } int32_Iter iter2; for(iter2 = OGd->offsets.begin(); iter2 != OGd->offsets.end(); iter2++) { - if((*iter).second.first) - ss << "" << endl; + if((*iter2).second.first) + ss << i << "" << endl; } for(iter = OGd->hexvals.begin(); iter != OGd->hexvals.end(); iter++) { if((*iter).second.first) - ss << "" << endl; + ss << i << "" << endl; } strings_Iter iter3; for(iter3 = OGd->strings.begin(); iter3 != OGd->strings.end(); iter3++) { if((*iter3).second.first) - ss << "" << endl; + ss << i << "" << endl; } groups_Iter iter4; for(iter4 = OGd->groups.begin(); iter4 != OGd->groups.end(); iter4++) { - ss << "" << endl; - ss <<(*iter4).second->PrintOffsets(); - ss << "" << endl; + ss << i << "" << endl; + i.indent(); + ss <<(*iter4).second->PrintOffsets(i.get()); + i.unindent(); + ss << i << "" << endl; } return ss.str(); } @@ -959,26 +1002,31 @@ std::string VersionInfo::getMood(const uint32_t moodID) throw Error::MissingMemoryDefinition("Mood", moodID); } - std::string VersionInfo::PrintOffsets() { ostringstream ss; - ss << "" << endl; + indentr i; + ss << i << "" << endl; + i.indent(); switch (getOS()) { case OS_LINUX: - ss << "" << endl; + ss << i << "" << endl; break; case OS_WINDOWS: - ss << "" << endl; - ss << "" << endl; + ss << i << "" << endl; + ss << i << "" << endl; break; default: - ss << " UNKNOWN" << endl; + ss << i << " UNKNOWN" << endl; } - ss << "" << endl; - ss << OffsetGroup::PrintOffsets(); - ss << "" << endl; - ss << "" << endl; + ss << i << "" << endl; + i.indent(); + ss << OffsetGroup::PrintOffsets(i.get()); + i.unindent(); + ss << i << "" << endl; + i.unindent(); + ss << i << "" << endl; + ss << endl; return ss.str(); } \ No newline at end of file diff --git a/library/include/dfhack/VersionInfo.h b/library/include/dfhack/VersionInfo.h index 571ac646a..458a2c5af 100644 --- a/library/include/dfhack/VersionInfo.h +++ b/library/include/dfhack/VersionInfo.h @@ -36,6 +36,7 @@ namespace DFHack * Stubs */ class Process; + class XMLPP; struct t_class; class VersionInfoPrivate; class OffsetGroupPrivate; @@ -71,7 +72,7 @@ namespace DFHack void setAddress (const std::string & key, const std::string & value); void setHexValue (const std::string & key, const std::string & value); void setString (const std::string & key, const std::string & value); - std::string PrintOffsets(); + std::string PrintOffsets(int indentation); std::string getName(); std::string getFullName(); OffsetGroup * getParent();