X-Git-Url: http://g0dil.de/git?a=blobdiff_plain;f=senf%2FUtils%2FTermlib%2FTerminfo.cc;h=a3ae123609094b3bed958afbfc4d428382a8d8bc;hb=b2fff1b50e0010fdad28cb638987cbf88032e30e;hp=b1eb5c8a1c7ae049dbf21eea50464586b7410273;hpb=c305d6b970e5952fe006270c7184b8bbb10ba2ee;p=senf.git diff --git a/senf/Utils/Termlib/Terminfo.cc b/senf/Utils/Termlib/Terminfo.cc index b1eb5c8..a3ae123 100644 --- a/senf/Utils/Termlib/Terminfo.cc +++ b/senf/Utils/Termlib/Terminfo.cc @@ -134,6 +134,13 @@ char const * const senf::term::Terminfo::properties::StringNames[] = { //-///////////////////////////////////////////////////////////////////////////////////////////////// // senf::term::Terminfo +prefix_ senf::term::Terminfo::InvalidTerminfoException::InvalidTerminfoException(std::string const & term) + : senf::Exception("Unreadable terminfo file") +{ + if (!term.empty()) + append( ": " + term); +} + prefix_ senf::term::Terminfo::Terminfo() {} @@ -145,10 +152,15 @@ prefix_ senf::term::Terminfo::Terminfo(std::string const & term) prefix_ void senf::term::Terminfo::load(std::string const & term) { std::string filename (findTerminfo(term)); - if (filename.empty()) throw InvalidTerminfoException(); + if (filename.empty()) throw InvalidTerminfoException(term); std::ifstream is (filename.c_str()); - if (!is) throw InvalidTerminfoException(); - load(is); + if (!is) throw InvalidTerminfoException(filename); + try { + load(is); + } catch (InvalidTerminfoException & ex) { + ex << ": " << filename; + throw ex; + } } prefix_ bool senf::term::Terminfo::getFlag(properties::Boolean p) @@ -399,6 +411,15 @@ namespace { boost::uint16_t nNumbers; boost::uint16_t nStrings; boost::uint16_t stringPoolSz; + + void letoh() { + magic = le16toh(magic); + namesSz = le16toh(namesSz); + nBooleans = le16toh(nBooleans); + nNumbers = le16toh(nNumbers); + nStrings = le16toh(nStrings); + stringPoolSz = le16toh(stringPoolSz); + } }; } @@ -407,7 +428,9 @@ prefix_ void senf::term::Terminfo::load(std::istream & is) { TerminfoHeader h; is.read(static_cast(static_cast(&h)), sizeof(h)); - if (!is || h.magic != TerminfoMagic) throw InvalidTerminfoException(); + h.letoh(); + if (!is || h.magic != TerminfoMagic) throw InvalidTerminfoException( + "invalid magic number (") << h.magic << "!=" << TerminfoMagic << ")"; name_.resize(h.namesSz); is.read(&(name_[0]), name_.size()); @@ -445,7 +468,7 @@ prefix_ void senf::term::Terminfo::load(std::istream & is) number_t v; is.read(static_cast(static_cast(&v)), sizeof(v)); if (!is) throw InvalidTerminfoException(); - *i = v; + *i = le16toh(v); } stringPool_.resize(h.stringPoolSz);