Clarified that group chunks must have chunks in them
[iffl.git] / xept.cc
blob8ab888904c67f2af0e76d81ac8bd2e543012c8a5
1 // This file is part of the interchange file format library.
2 //
3 // Copyright (C) 2003-2006 by Mike Sharov <msharov@users.sourceforge.net>
4 // This file is free software, distributed under the MIT License.
5 //
6 // xept.cc
7 //
9 #include "xept.h"
11 namespace iff {
13 //----------------------------------------------------------------------
15 /// Wrong format error for \p typeName at \p offset; \p expected format does not match \p actual format.
16 XFormatMismatch::XFormatMismatch (const char* typeName, uoff_t offset, fmt_t expected, fmt_t actual) throw()
17 : exception(),
18 m_TypeName (typeName),
19 m_Offset (offset),
20 m_Expected (expected),
21 m_Actual (actual)
25 /// Writes error description to \p msgbuf. Default fmt is "iff chunk %s at 0x%zX has format %08X (%c%c%c%c), expected %08X (%c%c%c%c)"
26 void XFormatMismatch::info (string& msgbuf, const char* fmt) const throw()
28 if (!fmt) fmt = "iff chunk %s at 0x%zX has format %08X (%c%c%c%c), expected %08X (%c%c%c%c)";
29 char expstr[sizeof(fmt_t)]; *(fmt_t*)(expstr) = m_Expected;
30 char actstr[sizeof(fmt_t)]; *(fmt_t*)(actstr) = m_Actual;
31 for (size_t i = 0; i < sizeof(fmt_t); ++ i) {
32 if (!isprint(expstr[i]))
33 expstr[i] = '.';
34 if (!isprint(actstr[i]))
35 actstr[i] = '.';
37 char dmname [256];
38 strncpy (dmname, m_TypeName, VectorSize(dmname));
39 dmname[VectorSize(dmname)-1] = 0;
40 demangle_type_name (VectorBlock (dmname));
41 try {
42 msgbuf.format (fmt, dmname, m_Offset,
43 m_Actual, actstr[0], actstr[1], actstr[2], actstr[3],
44 m_Expected, expstr[0], expstr[1], expstr[2], expstr[3]);
45 } catch (...) {}
48 //----------------------------------------------------------------------
50 /// Chunk of \p typeName at \p offset is not of the \p expected size.
51 XChunkSizeMismatch::XChunkSizeMismatch (const char* typeName, uoff_t offset, size_t expected, size_t actual) throw()
52 : exception(),
53 m_TypeName (typeName),
54 m_Offset (offset),
55 m_Expected (expected),
56 m_Actual (actual)
60 /// Writes error description to \p msgbuf. Default \p fmt is "iff chunk %s at 0x%zX is %zu bytes, expected %zu"
61 void XChunkSizeMismatch::info (string& msgbuf, const char* fmt) const throw()
63 if (!fmt) fmt = "iff chunk %s at 0x%zX is %zu bytes, expected %zu";
64 char dmname [256];
65 strncpy (dmname, m_TypeName, VectorSize(dmname));
66 dmname[VectorSize(dmname)-1] = 0;
67 demangle_type_name (VectorBlock (dmname));
68 try { msgbuf.format (fmt, dmname, m_Offset, m_Actual, m_Expected); } catch (...) {}
71 //----------------------------------------------------------------------
73 } // namespace iff