From df671dc334a725f649d1103a53cdb5075744e971 Mon Sep 17 00:00:00 2001 From: David Rose Date: Sun, 6 Sep 2009 22:54:50 +0000 Subject: [PATCH] consistent code with panda --- direct/src/plugin/p3dMultifileReader.cxx | 31 ++++++++++++------------ 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/direct/src/plugin/p3dMultifileReader.cxx b/direct/src/plugin/p3dMultifileReader.cxx index 2d665a9e15..cf8d7e1e5a 100644 --- a/direct/src/plugin/p3dMultifileReader.cxx +++ b/direct/src/plugin/p3dMultifileReader.cxx @@ -160,21 +160,16 @@ read_header(const string &pathname) { char this_header[_header_size]; _in.seekg(0); - _in.read(this_header, _header_size); - if (_in.fail() || _in.gcount() != (unsigned)_header_size) { - nout - << "Unable to read Multifile header " << pathname << ".\n"; - return false; - } // Here's a special case: if the multifile begins with a hash - // character, then we skip at least 6 characters, and continue - // reading and discarding lines of ASCII text, until we come across - // a nonempty line that does not begin with a hash character. This - // allows a P3D application (which is a multifile) to be run - // directly on the command line on Unix-based systems. - if (this_header[0] == '#') { - int ch = '#'; + // character, then we continue reading and discarding lines of ASCII + // text, until we come across a nonempty line that does not begin + // with a hash character. This allows a P3D application (which is a + // multifile) to be run directly on the command line on Unix-based + // systems. + int ch = _in.get(); + + if (ch == '#') { while (ch != EOF && ch == '#') { // Skip to the end of the line. while (ch != EOF && ch != '\n') { @@ -185,10 +180,14 @@ read_header(const string &pathname) { ch = _in.get(); } } + } - // Now fill up the header. - this_header[0] = ch; - _in.read(this_header + 1, _header_size - 1); + // Now read the actual Multifile header. + this_header[0] = ch; + _in.read(this_header + 1, _header_size - 1); + if (_in.fail() || _in.gcount() != (unsigned)(_header_size - 1)) { + nout << "Unable to read Multifile header: " << pathname << "\n"; + return false; } if (memcmp(this_header, _header, _header_size) != 0) {