]> git.wh0rd.org - ICEs.git/blame - 137054/ice.ii.2
initial import
[ICEs.git] / 137054 / ice.ii.2
CommitLineData
45516216 1 extern "C++" {
2 namespace std { class exception { public: exception() throw() { } virtual ~exception() throw(); virtual const char* what() const throw(); }; class bad_exception : public exception { public: bad_exception() throw() { } virtual ~bad_exception() throw(); }; typedef void (*terminate_handler) (); typedef void (*unexpected_handler) (); terminate_handler set_terminate(terminate_handler) throw(); void terminate() __attribute__ ((__noreturn__)); unexpected_handler set_unexpected(unexpected_handler) throw(); void unexpected() __attribute__ ((__noreturn__)); bool uncaught_exception() throw(); }
3 }
4 typedef int ptrdiff_t;
5 typedef unsigned int size_t;
6 extern "C" {
7 extern void *memcpy (void *__restrict __dest, __const void *__restrict __src, size_t __n) throw () __attribute__ ((__nonnull__ (1, 2)));
8 extern void *memset (void *__s, int __c, size_t __n) throw () __attribute__ ((__nonnull__ (1)));
9 extern int memcmp (__const void *__s1, __const void *__s2, size_t __n) throw () __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1, 2)));
10 extern char *strchr (__const char *__s, int __c) throw () __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1)));
11 extern char *strstr (__const char *__haystack, __const char *__needle) throw () __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1, 2)));
12 extern size_t strlen (__const char *__s) throw () __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1)));
13 }
14 typedef long SLONG;
15 typedef unsigned long ULONG;
16 typedef unsigned char UCHAR;
17 typedef short SSHORT;
18 typedef unsigned short USHORT;
19 typedef long ISC_STATUS;
20 typedef ISC_STATUS ISC_STATUS_ARRAY[20];
21 typedef struct {
22 }
23 ISC_TIMESTAMP;
24 typedef char TEXT;
25 namespace Firebird {
26 class status_exception : public std::exception { public: status_exception(const ISC_STATUS *status_vector, bool permanent) throw(); virtual ~status_exception() throw(); virtual const char* what() const throw() { return "Firebird::status_exception"; } const ISC_STATUS* value() const throw() { return m_status_vector; } bool strings_permanent() const throw() { return m_strings_permanent; } bool status_known() const throw() { return m_status_known; } static void raise(const ISC_STATUS *status_vector); static void raise(); static void raise(ISC_STATUS status, ...); protected: status_exception() throw(); void set_status(const ISC_STATUS *new_vector, bool permanent) throw(); private: ISC_STATUS_ARRAY m_status_vector; bool m_strings_permanent; bool m_status_known; void release_vector() throw(); };
27 class fatal_exception : public status_exception { public: explicit fatal_exception(const char* message); static void raiseFmt(const char* format, ...); const char* what() const throw() { return reinterpret_cast<const char*>(value()[3]); } static void raise(const char* message); };
28 __extension__ typedef long long int __quad_t;
29 __extension__ typedef __quad_t __off64_t;
30 __extension__ typedef int __ssize_t;
31 typedef struct _IO_FILE FILE;
32 typedef unsigned int wint_t;
33 typedef struct { int __count; union { wint_t __wch; char __wchb[4]; } __value; }
34 __mbstate_t;
35 typedef __builtin_va_list __gnuc_va_list;
36 typedef __ssize_t __io_read_fn (void *__cookie, char *__buf, size_t __nbytes);
37 typedef __ssize_t __io_write_fn (void *__cookie, __const char *__buf, size_t __n);
38 typedef int __io_seek_fn (void *__cookie, __off64_t *__pos, int __w);
39 typedef int __io_close_fn (void *__cookie);
40 typedef struct { __io_read_fn *read; __io_write_fn *write; __io_seek_fn *seek; __io_close_fn *close; }
41 _IO_cookie_io_functions_t;
42 typedef __gnuc_va_list va_list;
43 extern struct _IO_FILE *stderr;
44 extern int fprintf (FILE *__restrict __stream, __const char *__restrict __format, ...);
45 extern void abort (void) throw () __attribute__ ((__noreturn__));
46 }
47 typedef long long int SINT64;
48 class AtomicCounter {
49 };
50 extern "C" {
51 void gds__log(const TEXT*, ...);
52 }
53 namespace Firebird {
54 struct FreeMemoryBlock { FreeMemoryBlock* fbk_next_fragment; };
55 struct MemoryBlock { USHORT mbk_flags; SSHORT mbk_type; union { struct { USHORT mbk_length; USHORT mbk_prev_length; } small; ULONG mbk_large_length; }; union { class MemoryPool* mbk_pool; FreeMemoryBlock* mbk_prev_fragment; }; const char mbk_valgrind_redzone[8]; };
56 }
57 using Firebird::MemoryPool;
58 inline static MemoryPool* getDefaultMemoryPool() {
59 }
60 inline void* operator new[](size_t s, Firebird::MemoryPool& pool) {
61 }
62 namespace Firebird {
63 class PermanentStorage { private: MemoryPool& pool; protected: explicit PermanentStorage(MemoryPool& p) : pool(p) { } MemoryPool& getPool() const { return pool; } };
64 class AutoStorage : public PermanentStorage { private: void ProbeStack() const; public: static MemoryPool& getAutoMemoryPool(); protected: AutoStorage() : PermanentStorage(getAutoMemoryPool()) { ProbeStack(); } explicit AutoStorage(MemoryPool& p) : PermanentStorage(p) { } };
65 class AbstractString : private AutoStorage { public: typedef char char_type; typedef size_t size_type; typedef ptrdiff_t difference_type; typedef char* pointer; typedef const char* const_pointer; typedef char& reference; typedef const char& const_reference; typedef char value_type; typedef pointer iterator; typedef const_pointer const_iterator; static const size_type npos; enum {INLINE_BUFFER_SIZE = 32, INIT_RESERVE = 16 }; protected: typedef USHORT internal_size_type; char_type inlineBuffer[INLINE_BUFFER_SIZE]; char_type* stringBuffer; internal_size_type stringLength, bufferSize; private: inline void checkPos(size_type pos) const { if (pos >= length()) { fatal_exception::raise("Firebird::string - pos out of range"); } } static inline void checkLength(size_type len) { if (len > max_length()) { fatal_exception::raise("Firebird::string - length exceeds predefined limit"); } } void reserveBuffer(size_type newLen) { size_type newSize = newLen + 1; if (newSize > bufferSize) { checkLength(newLen); if (newSize / 2 < bufferSize) newSize = bufferSize * 2; if (newSize > max_length() + 1) newSize = max_length() + 1; char_type *newBuffer = new(getPool()) char_type[newSize]; memcpy(newBuffer, stringBuffer, sizeof(char_type) * (stringLength + 1)); if (stringBuffer != inlineBuffer) delete[] stringBuffer; stringBuffer = newBuffer; bufferSize = static_cast<internal_size_type>(newSize); } } void initialize(size_type len) { if (len < INLINE_BUFFER_SIZE) { stringBuffer = inlineBuffer; bufferSize = INLINE_BUFFER_SIZE; } else { stringBuffer = __null; checkLength(len); size_type newSize = len + 1 + INIT_RESERVE; if (newSize > max_length() + 1) newSize = max_length() + 1; stringBuffer = new(getPool()) char_type[newSize]; bufferSize = static_cast<internal_size_type>(newSize); } stringLength = static_cast<internal_size_type>(len); stringBuffer[stringLength] = 0; } void shrinkBuffer() { } protected: AbstractString(size_type sizeL, const_pointer datap); AbstractString(const_pointer p1, size_type n1, const_pointer p2, size_type n2); AbstractString(const AbstractString& v); inline AbstractString() : stringBuffer(inlineBuffer), stringLength(0), bufferSize(INLINE_BUFFER_SIZE) { stringBuffer[0] = 0; } AbstractString(size_type sizeL, char_type c); inline explicit AbstractString(MemoryPool& p) : AutoStorage(p), stringBuffer(inlineBuffer), stringLength(0), bufferSize(INLINE_BUFFER_SIZE) { stringBuffer[0] = 0; } inline AbstractString(MemoryPool& p, const AbstractString& v) : AutoStorage(p) { initialize(v.length()); memcpy(stringBuffer, v.c_str(), stringLength); } inline AbstractString(MemoryPool& p, const char_type* s, size_type l) : AutoStorage(p) { initialize(l); memcpy(stringBuffer, s, l); } pointer Modify(void) { return stringBuffer; } static void AdjustRange(size_type length, size_type& pos, size_type& n); pointer baseAssign(size_type n); pointer baseAppend(size_type n); pointer baseInsert(size_type p0, size_type n); void baseErase(size_type p0, size_type n); enum TrimType {TrimLeft, TrimRight, TrimBoth}; void baseTrim(TrimType WhereTrim, const_pointer ToTrim); public: inline const_pointer c_str() const { return stringBuffer; } inline size_type length() const { return stringLength; } inline const_pointer nullStr() const { return stringLength ? stringBuffer : 0; } inline size_type recalculate_length() { stringLength = strlen(stringBuffer); return stringLength; } void reserve(size_type n = 0); void resize(size_type n, char_type c = ' '); inline size_type copy_from(pointer s, size_type n, size_type pos = 0) const { AdjustRange(length(), pos, n); memcpy(s, c_str() + pos, n); return n; } inline size_type find(const AbstractString& str, size_type pos = 0) const { return find(str.c_str(), pos); } inline size_type find(const_pointer s, size_type pos = 0) const { const_pointer p = strstr(c_str() + pos, s); return p ? p - c_str() : npos; } inline size_type find(char_type c, size_type pos = 0) const { const_pointer p = strchr(c_str() + pos, c); return p ? p - c_str() : npos; } inline size_type rfind(const AbstractString& str, size_type pos = npos) const { return rfind(str.c_str(), pos); } size_type rfind(const_pointer s, size_type pos = npos) const; size_type rfind(char_type c, size_type pos = npos) const; inline size_type find_first_of(const AbstractString& str, size_type pos = 0) const { return find_first_of(str.c_str(), pos, str.length()); } size_type find_first_of(const_pointer s, size_type pos, size_type n) const; inline size_type find_first_of(const_pointer s, size_type pos = 0) const { return find_first_of(s, pos, strlen(s)); } inline size_type find_first_of(char_type c, size_type pos = 0) const { return find(c, pos); } inline size_type find_last_of(const AbstractString& str, size_type pos = npos) const { return find_last_of(str.c_str(), pos, str.length()); } size_type find_last_of(const_pointer s, size_type pos, size_type n = npos) const; inline size_type find_last_of(const_pointer s, size_type pos = npos) const { return find_last_of(s, pos, strlen(s)); } inline size_type find_last_of(char_type c, size_type pos = npos) const { return rfind(c, pos); } inline size_type find_first_not_of(const AbstractString& str, size_type pos = 0) const { return find_first_not_of(str.c_str(), pos, str.length()); } size_type find_first_not_of(const_pointer s, size_type pos, size_type n) const; inline size_type find_first_not_of(const_pointer s, size_type pos = 0) const { return find_first_not_of(s, pos, strlen(s)); } inline size_type find_first_not_of(char_type c, size_type pos = 0) const { const char s[2] = {c, 0}; return find_first_not_of(s, pos, 1); } inline size_type find_last_not_of(const AbstractString& str, size_type pos = npos) const { return find_last_not_of(str.c_str(), pos, str.length()); } size_type find_last_not_of(const_pointer s, size_type pos, size_type n = npos) const; inline size_type find_last_not_of(const_pointer s, size_type pos = npos) const { return find_last_not_of(s, pos, strlen(s)); } inline size_type find_last_not_of(char_type c, size_type pos = npos) const { const char s[2] = {c, 0}; return find_last_not_of(s, pos, 1); } inline iterator begin() { return Modify(); } inline const_iterator begin() const { return c_str(); } inline iterator end() { return Modify() + length(); } inline const_iterator end() const { return c_str() + length(); } inline const_reference at(size_type pos) const { checkPos(pos); return c_str()[pos]; } inline reference at(size_type pos) { checkPos(pos); return Modify()[pos]; } inline const_reference operator[](size_type pos) const { return at(pos); } inline reference operator[](size_type pos) { return at(pos); } inline const_pointer data() const { return c_str(); } inline size_type size() const { return length(); } static inline size_type max_length() { return 0xfffe; } inline size_type capacity() const { return bufferSize - 1; } inline bool empty() const { return length() == 0; } inline bool hasData() const { return !empty(); } inline bool isEmpty() const { return empty(); } void upper(); void lower(); inline void ltrim(const_pointer ToTrim = " ") { baseTrim(TrimLeft, ToTrim); } inline void rtrim(const_pointer ToTrim = " ") { baseTrim(TrimRight, ToTrim); } inline void trim(const_pointer ToTrim = " ") { baseTrim(TrimBoth, ToTrim); } inline void alltrim(const_pointer ToTrim = " ") { baseTrim(TrimBoth, ToTrim); } bool LoadFromFile(FILE *file); void vprintf(const char* Format, va_list params); void printf(const char* Format, ...); inline int copyTo(pointer to, size_type toSize) const { {if (!(to)) {fprintf (stderr, "GDS Assertion failure: %s %""d""\n", "../src/include/../common/classes/fb_string.h", 363); abort();}}; {if (!(toSize)) {fprintf (stderr, "GDS Assertion failure: %s %""d""\n", "../src/include/../common/classes/fb_string.h", 364); abort();}}; if (--toSize > length()) { toSize = length(); } memcpy(to, c_str(), toSize); to[toSize] = 0; return toSize; } inline ~AbstractString() { if (stringBuffer != inlineBuffer) delete[] stringBuffer; } };
66 class StringComparator { public: static inline int compare(AbstractString::const_pointer s1, AbstractString::const_pointer s2, AbstractString::size_type n) { return memcmp(s1, s2, n); } };
67 class PathNameComparator { public: static int compare(AbstractString::const_pointer s1, AbstractString::const_pointer s2, AbstractString::size_type n); };
68 template<typename Comparator> class StringBase : public AbstractString { typedef StringBase<Comparator> StringType; protected: inline StringBase<Comparator>(const_pointer p1, size_type n1, const_pointer p2, size_type n2) : AbstractString(p1, n1, p2, n2) {} private: inline StringType add(const_pointer s, size_type n) const { return StringBase<Comparator>(c_str(), length(), s, n); } public: inline StringBase<Comparator>() : AbstractString() {} inline StringBase<Comparator>(const StringType& v) : AbstractString(v) {} inline StringBase<Comparator>(const_pointer s, size_type n) : AbstractString(n, s) {} inline StringBase<Comparator>(const_pointer s) : AbstractString(strlen(s), s) {} inline StringBase<Comparator>(const unsigned char* s) : AbstractString(strlen((char*)s), (char*)s) {} inline StringBase<Comparator>(size_type n, char_type c) : AbstractString(n, c) {} inline StringBase<Comparator>(char_type c) : AbstractString(1, c) {} inline StringBase<Comparator>(const_iterator first, const_iterator last) : AbstractString(last - first, first) {} inline explicit StringBase<Comparator>(MemoryPool& p) : AbstractString(p) {} inline StringBase<Comparator>(MemoryPool& p, const AbstractString& v) : AbstractString(p, v) {} inline StringBase<Comparator>(MemoryPool& p, const char_type* s, size_type l) : AbstractString(p, s, l) {} inline StringType& append(const StringType& str) { {if (!(&str != this)) {fprintf (stderr, "GDS Assertion failure: %s %""d""\n", "../src/include/../common/classes/fb_string.h", 416); abort();}}; return append(str.c_str(), str.length()); } inline StringType& append(const StringType& str, size_type pos, size_type n) { {if (!(&str != this)) {fprintf (stderr, "GDS Assertion failure: %s %""d""\n", "../src/include/../common/classes/fb_string.h", 420); abort();}}; AdjustRange(str.length(), pos, n); return append(str.c_str() + pos, n); } inline StringType& append(const_pointer s, size_type n) { memcpy(baseAppend(n), s, n); return *this; } inline StringType& append(const_pointer s) { return append(s, strlen(s)); } inline StringType& append(size_type n, char_type c) { memset(baseAppend(n), c, n); return *this; } inline StringType& append(const_iterator first, const_iterator last) { return append(first, last - first); } inline StringType& assign(const StringType& str) { {if (!(&str != this)) {fprintf (stderr, "GDS Assertion failure: %s %""d""\n", "../src/include/../common/classes/fb_string.h", 440); abort();}}; return assign(str.c_str(), str.length()); } inline StringType& assign(const StringType& str, size_type pos, size_type n) { {if (!(&str != this)) {fprintf (stderr, "GDS Assertion failure: %s %""d""\n", "../src/include/../common/classes/fb_string.h", 444); abort();}}; AdjustRange(str.length(), pos, n); return assign(&str.c_str()[pos], n); } inline StringType& assign(const_pointer s, size_type n) { memcpy(baseAssign(n), s, n); return *this; } inline StringType& assign(const_pointer s) { return assign(s, strlen(s)); } inline StringType& assign(size_type n, char_type c) { memset(baseAssign(n), c, n); return *this; } inline StringType& assign(const_iterator first, const_iterator last) { return assign(first, last - first); } inline StringType& operator=(const StringType& v) { {if (!(&v != this)) {fprintf (stderr, "GDS Assertion failure: %s %""d""\n", "../src/include/../common/classes/fb_string.h", 464); abort();}}; return assign(v); } inline StringType& operator=(const_pointer s) { return assign(s, strlen(s)); } inline StringType& operator=(char_type c) { return assign(&c, 1); } inline StringType& operator+=(const StringType& v) { {if (!(&v != this)) {fprintf (stderr, "GDS Assertion failure: %s %""d""\n", "../src/include/../common/classes/fb_string.h", 474); abort();}}; return append(v); } inline StringType& operator+=(const_pointer s) { return append(s); } inline StringType& operator+=(char_type c) { return append(1, c); } inline StringType operator+(const StringType& v) const { {if (!(&v != this)) {fprintf (stderr, "GDS Assertion failure: %s %""d""\n", "../src/include/../common/classes/fb_string.h", 484); abort();}}; return add(v.c_str(), v.length()); } inline StringType operator+(const_pointer s) const { return add(s, strlen(s)); } inline StringType operator+(char_type c) const { return add(&c, 1); } inline StringBase<StringComparator> ToString() const { return StringBase<StringComparator>(c_str()); } inline StringBase<PathNameComparator> ToPathName() const { return StringBase<PathNameComparator>(c_str()); } inline StringType& insert(size_type p0, const StringType& str) { {if (!(&str != this)) {fprintf (stderr, "GDS Assertion failure: %s %""d""\n", "../src/include/../common/classes/fb_string.h", 502); abort();}}; return insert(p0, str.c_str(), str.length()); } inline StringType& insert(size_type p0, const StringType& str, size_type pos, size_type n) { {if (!(&str != this)) {fprintf (stderr, "GDS Assertion failure: %s %""d""\n", "../src/include/../common/classes/fb_string.h", 506); abort();}}; AdjustRange(str.length(), pos, n); return insert(p0, &str.c_str()[pos], n); } inline StringType& insert(size_type p0, const_pointer s, size_type n) { if (p0 >= length()) { return append(s, n); } memcpy(baseInsert(p0, n), s, n); return *this; } inline StringType& insert(size_type p0, const_pointer s) { return insert(p0, s, strlen(s)); } inline StringType& insert(size_type p0, size_type n, char_type c) { if (p0 >= length()) { return append(n, c); } memset(baseInsert(p0, n), c, n); return *this; } inline void insert(iterator it, size_type n, char_type c) { insert(it - c_str(), n, c); } inline void insert(iterator it, const_iterator first, const_iterator last) { insert(it - c_str(), first, last - first); } inline StringType& erase(size_type p0 = 0, size_type n = npos) { baseErase(p0, n); return *this; } inline iterator erase(iterator it) { erase(it - c_str(), 1); return it; } inline iterator erase(iterator first, iterator last) { erase(first - c_str(), last - first); return first; } inline StringType& replace(size_type p0, size_type n0, const StringType& str) { {if (!(&str != this)) {fprintf (stderr, "GDS Assertion failure: %s %""d""\n", "../src/include/../common/classes/fb_string.h", 549); abort();}}; return replace(p0, n0, str.c_str(), str.length()); } inline StringType& replace(size_type p0, size_type n0, const StringType& str, size_type pos, size_type n) { {if (!(&str != this)) {fprintf (stderr, "GDS Assertion failure: %s %""d""\n", "../src/include/../common/classes/fb_string.h", 553); abort();}}; AdjustRange(str.length(), pos, n); return replace(p0, n0, &str.c_str()[pos], n); } inline StringType& replace(size_type p0, size_type n0, const_pointer s, size_type n) { erase(p0, n0); return insert(p0, s, n); } inline StringType& replace(size_type p0, size_type n0, const_pointer s) { return replace(p0, n0, s, strlen(s)); } inline StringType& replace(size_type p0, size_type n0, size_type n, char_type c) { erase(p0, n0); return insert(p0, n, c); } inline StringType& replace(iterator first0, iterator last0, const StringType& str) { {if (!(&str != this)) {fprintf (stderr, "GDS Assertion failure: %s %""d""\n", "../src/include/../common/classes/fb_string.h", 569); abort();}}; return replace(first0 - c_str(), last0 - first0, str); } inline StringType& replace(iterator first0, iterator last0, const_pointer s, size_type n) { return replace(first0 - c_str(), last0 - first0, s, n); } inline StringType& replace(iterator first0, iterator last0, const_pointer s) { return replace(first0 - c_str(), last0 - first0, s); } inline StringType& replace(iterator first0, iterator last0, size_type n, char_type c) { return replace(first0 - c_str(), last0 - first0, n, c); } inline StringType& replace(iterator first0, iterator last0, const_iterator first, const_iterator last) { return replace(first0 - c_str(), last0 - first0, first, last - first); } inline StringType substr(size_type pos = 0, size_type n = npos) const { AdjustRange(length(), pos, n); return StringType(&c_str()[pos], n); } inline int compare(const StringType& str) const { return compare(str.c_str(), str.length()); } inline int compare(size_type p0, size_type n0, const StringType& str) { return compare(p0, n0, str.c_str(), str.length()); } inline int compare(size_type p0, size_type n0, const StringType& str, size_type pos, size_type n) { AdjustRange(str.length(), pos, n); return compare(p0, n0, &str.c_str()[pos], n); } inline int compare(const_pointer s) const { return compare(s, strlen(s)); } int compare(size_type p0, size_type n0, const_pointer s, size_type n) const { AdjustRange(length(), p0, n0); const size_type ml = n0 < n ? n0 : n; const int rc = Comparator::compare(&c_str()[p0], s, ml); return rc ? rc : n0 - n; } int compare(const_pointer s, size_type n) const { const size_type ml = length() < n ? length() : n; const int rc = Comparator::compare(c_str(), s, ml); return rc ? rc : length() - n; } inline bool operator< (const StringType& str) const {return compare(str) < 0;} inline bool operator<=(const StringType& str) const {return compare(str) <= 0;} inline bool operator==(const StringType& str) const {return compare(str) == 0;} inline bool operator>=(const StringType& str) const {return compare(str) >= 0;} inline bool operator> (const StringType& str) const {return compare(str) > 0;} inline bool operator!=(const StringType& str) const {return compare(str) != 0;} inline bool operator< (const char_type* str) const {return compare(str) < 0;} inline bool operator<=(const char_type* str) const {return compare(str) <= 0;} inline bool operator==(const char_type* str) const {return compare(str) == 0;} inline bool operator>=(const char_type* str) const {return compare(str) >= 0;} inline bool operator> (const char_type* str) const {return compare(str) > 0;} inline bool operator!=(const char_type* str) const {return compare(str) != 0;} };
69 typedef StringBase<StringComparator> string;
70 typedef StringBase<PathNameComparator> PathName;
71 }
72 namespace Firebird {
73 class ClumpletReader : protected AutoStorage { public: enum Kind {Tagged, UnTagged, SpbAttach, SpbStart, Tpb }; ClumpletReader(Kind k, const UCHAR* buffer, size_t buffLen); virtual ~ClumpletReader() { } bool isEof() const { return cur_offset >= getBufferLength(); } void moveNext(); void rewind(); bool find(UCHAR tag); UCHAR getClumpTag() const; size_t getClumpLength() const; SLONG getInt() const; bool getBoolean() const; SINT64 getBigInt() const; string& getString(string& str) const; PathName& getPath(PathName& str) const; const UCHAR* getBytes() const; UCHAR getBufferTag() const; size_t getBufferLength() const { size_t rc = getBufferEnd() - getBuffer(); if (rc == 1 && kind != UnTagged && kind != SpbStart) { rc = 0; } return rc; } size_t getCurOffset() const { return cur_offset; } void setCurOffset(size_t newOffset) { cur_offset = newOffset; } void dump() const; protected: enum ClumpletType {TraditionalDpb, SingleTpb, StringSpb, IntSpb, ByteSpb}; ClumpletType getClumpletType(UCHAR tag) const; size_t getClumpletSize(bool wTag, bool wLength, bool wData) const; void adjustSpbState(); size_t cur_offset; const Kind kind; UCHAR spbState; virtual const UCHAR* getBuffer() const { return static_buffer; } virtual const UCHAR* getBufferEnd() const { return static_buffer_end; } virtual void usage_mistake(const char* what) const; virtual void invalid_structure(const char* what) const; private: ClumpletReader(const ClumpletReader& from); ClumpletReader& operator=(const ClumpletReader& from); const UCHAR* static_buffer; const UCHAR* static_buffer_end; };
74 extern int isprint (int) throw ();
75 void ClumpletReader::dump() const { static int dmp = 0; gds__log("*** DUMP ***"); if (dmp) { gds__log("recursion"); return; } dmp++; class ClumpletDump : public ClumpletReader { public: ClumpletDump(Kind k, const UCHAR* buffer, size_t buffLen) : ClumpletReader(k, buffer, buffLen) { } static string hexString(const UCHAR* b, size_t len) { string t1, t2; for (; len > 0; --len, ++b) { if (isprint(*b)) t2 += *b; else { t1.printf("<%02x>", *b); t2 += t1; } } return t2; } protected: virtual void usage_mistake(const char* what) const { fatal_exception::raiseFmt( "Internal error when using clumplet API: %s", what); } virtual void invalid_structure(const char* what) const { fatal_exception::raiseFmt( "Invalid clumplet buffer structure: %s", what); } }; try { ClumpletDump d(kind, getBuffer(), getBufferLength()); int t = (kind == SpbStart || kind == UnTagged) ? -1 : d.getBufferTag(); gds__log("Tag=%d Offset=%d Length=%d Eof=%d\n", t, getCurOffset(), getBufferLength(), isEof()); for (d.rewind(); !(d.isEof()); d.moveNext()) { gds__log("Clump %d at offset %d: %s", d.getClumpTag(), d.getCurOffset(), ClumpletDump::hexString(d.getBytes(), d.getClumpLength()).c_str()); } } catch(const fatal_exception& x) { gds__log("Fatal exception during clumplet dump: %s", x.what()); size_t l = getBufferLength() - getCurOffset(); const UCHAR *p = getBuffer() + getCurOffset(); gds__log("Plain dump starting with offset %d: %s", getCurOffset(), ClumpletDump::hexString(p, l).c_str()); } dmp--; }
76 }