Clean up code formatting with clang-format; add a custom clang-format style that tries to approximate the existing OST code style
This commit is contained in:
parent
184b260d9f
commit
ccf8a62fa4
|
@ -0,0 +1,115 @@
|
|||
---
|
||||
Language: Cpp
|
||||
|
||||
AccessModifierOffset: -4
|
||||
AlignAfterOpenBracket: Align
|
||||
AlignConsecutiveAssignments: true
|
||||
AlignConsecutiveDeclarations: true
|
||||
AlignEscapedNewlines: Left
|
||||
AlignOperands: true
|
||||
AlignTrailingComments: true
|
||||
AllowAllParametersOfDeclarationOnNextLine: true
|
||||
AllowShortBlocksOnASingleLine: false
|
||||
AllowShortCaseLabelsOnASingleLine: false
|
||||
AllowShortFunctionsOnASingleLine: None
|
||||
AllowShortIfStatementsOnASingleLine: false
|
||||
AllowShortLoopsOnASingleLine: false
|
||||
AlwaysBreakAfterDefinitionReturnType: None
|
||||
AlwaysBreakAfterReturnType: None
|
||||
AlwaysBreakBeforeMultilineStrings: false
|
||||
AlwaysBreakTemplateDeclarations: false
|
||||
BinPackArguments: false
|
||||
BinPackParameters: false
|
||||
BraceWrapping:
|
||||
AfterClass: true
|
||||
AfterControlStatement: true
|
||||
AfterEnum: true
|
||||
AfterFunction: true
|
||||
AfterNamespace: true
|
||||
AfterObjCDeclaration: true
|
||||
AfterStruct: true
|
||||
AfterUnion: true
|
||||
AfterExternBlock: true
|
||||
BeforeCatch: true
|
||||
BeforeElse: true
|
||||
IndentBraces: false
|
||||
SplitEmptyFunction: true
|
||||
SplitEmptyRecord: true
|
||||
SplitEmptyNamespace: true
|
||||
BreakBeforeBinaryOperators: None
|
||||
BreakBeforeBraces: Custom
|
||||
BreakBeforeInheritanceComma: false
|
||||
BreakBeforeTernaryOperators: false
|
||||
BreakConstructorInitializersBeforeComma: false
|
||||
BreakConstructorInitializers: BeforeColon
|
||||
BreakAfterJavaFieldAnnotations: false
|
||||
BreakStringLiterals: true
|
||||
ColumnLimit: 120
|
||||
CommentPragmas: '^ IWYU pragma:'
|
||||
CompactNamespaces: false
|
||||
ConstructorInitializerAllOnOneLineOrOnePerLine: true
|
||||
ConstructorInitializerIndentWidth: 4
|
||||
ContinuationIndentWidth: 4
|
||||
Cpp11BracedListStyle: true
|
||||
DerivePointerAlignment: false
|
||||
DisableFormat: false
|
||||
ExperimentalAutoDetectBinPacking: false
|
||||
FixNamespaceComments: true
|
||||
ForEachMacros:
|
||||
- foreach
|
||||
- Q_FOREACH
|
||||
- BOOST_FOREACH
|
||||
IncludeBlocks: Preserve
|
||||
IncludeCategories:
|
||||
- Regex: '^"(llvm|llvm-c|clang|clang-c)/'
|
||||
Priority: 2
|
||||
- Regex: '^(<|"(gtest|gmock|isl|json)/)'
|
||||
Priority: 3
|
||||
- Regex: '.*'
|
||||
Priority: 1
|
||||
IncludeIsMainRegex: '(Test)?$'
|
||||
IndentCaseLabels: false
|
||||
IndentPPDirectives: AfterHash
|
||||
IndentWidth: 4
|
||||
IndentWrappedFunctionNames: false
|
||||
JavaScriptQuotes: Leave
|
||||
JavaScriptWrapImports: true
|
||||
KeepEmptyLinesAtTheStartOfBlocks: true
|
||||
MacroBlockBegin: ''
|
||||
MacroBlockEnd: ''
|
||||
MaxEmptyLinesToKeep: 2
|
||||
NamespaceIndentation: None
|
||||
ObjCBlockIndentWidth: 2
|
||||
ObjCSpaceAfterProperty: false
|
||||
ObjCSpaceBeforeProtocolList: true
|
||||
PenaltyBreakAssignment: 2
|
||||
PenaltyBreakBeforeFirstCallParameter: 19
|
||||
PenaltyBreakComment: 300
|
||||
PenaltyBreakFirstLessLess: 120
|
||||
PenaltyBreakString: 1000
|
||||
PenaltyExcessCharacter: 1000000
|
||||
PenaltyReturnTypeOnItsOwnLine: 60
|
||||
PointerAlignment: Left
|
||||
RawStringFormats:
|
||||
- Delimiter: pb
|
||||
Language: TextProto
|
||||
BasedOnStyle: google
|
||||
ReflowComments: false
|
||||
SortIncludes: false
|
||||
SortUsingDeclarations: true
|
||||
SpaceAfterCStyleCast: false
|
||||
SpaceAfterTemplateKeyword: false
|
||||
SpaceBeforeAssignmentOperators: true
|
||||
SpaceBeforeParens: ControlStatements
|
||||
SpaceInEmptyParentheses: false
|
||||
SpacesBeforeTrailingComments: 1
|
||||
SpacesInAngles: false
|
||||
SpacesInContainerLiterals: true
|
||||
SpacesInCStyleCastParentheses: false
|
||||
SpacesInParentheses: false
|
||||
SpacesInSquareBrackets: false
|
||||
Standard: Auto
|
||||
TabWidth: 4
|
||||
UseTab: Never
|
||||
...
|
||||
|
|
@ -1,2 +1 @@
|
|||
#define BUILD_NUM _T("0")
|
||||
|
||||
|
|
|
@ -3,29 +3,29 @@
|
|||
// Portions created by Tripwire, Inc. are copyright (C) 2000-2018 Tripwire,
|
||||
// Inc. Tripwire is a registered trademark of Tripwire, Inc. All rights
|
||||
// reserved.
|
||||
//
|
||||
//
|
||||
// This program is free software. The contents of this file are subject
|
||||
// to the terms of the GNU General Public License as published by the
|
||||
// Free Software Foundation; either version 2 of the License, or (at your
|
||||
// option) any later version. You may redistribute it and/or modify it
|
||||
// only in compliance with the GNU General Public License.
|
||||
//
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful.
|
||||
// However, this program is distributed AS-IS WITHOUT ANY
|
||||
// WARRANTY; INCLUDING THE IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS
|
||||
// FOR A PARTICULAR PURPOSE. Please see the GNU General Public License
|
||||
// for more details.
|
||||
//
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
|
||||
// USA.
|
||||
//
|
||||
//
|
||||
// Nothing in the GNU General Public License or any other license to use
|
||||
// the code or files shall permit you to use Tripwire's trademarks,
|
||||
// service marks, or other intellectual property without Tripwire's
|
||||
// prior written consent.
|
||||
//
|
||||
//
|
||||
// If you have any questions, please contact Tripwire, Inc. at either
|
||||
// info@tripwire.org or www.tripwire.org.
|
||||
//
|
||||
|
@ -49,34 +49,34 @@
|
|||
#include "file.h"
|
||||
#include "stringutil.h"
|
||||
|
||||
#include "corestrings.h" // for: STR_ERR2_ARCH_CRYPTO_ERR
|
||||
#include "corestrings.h" // for: STR_ERR2_ARCH_CRYPTO_ERR
|
||||
|
||||
//=============================================================================
|
||||
// eArchiveCrypto
|
||||
//=============================================================================
|
||||
TSTRING eArchiveCrypto::GetMsg( ) const
|
||||
TSTRING eArchiveCrypto::GetMsg() const
|
||||
{
|
||||
// RAD: Updated this to use new stringtable
|
||||
return ( mMsg + TSS_GetString( cCore, core::STR_ERR2_ARCH_CRYPTO_ERR ) );
|
||||
return (mMsg + TSS_GetString(cCore, core::STR_ERR2_ARCH_CRYPTO_ERR));
|
||||
}
|
||||
|
||||
|
||||
//=============================================================================
|
||||
// cArchive
|
||||
// cArchive
|
||||
//=============================================================================
|
||||
|
||||
// convenience methods
|
||||
//
|
||||
// Specific Read functions throw eArchive if EOF is reached because
|
||||
// if the caller is requesting a certain amount of data to be present,
|
||||
// if the caller is requesting a certain amount of data to be present,
|
||||
// reaching EOF is unexpected
|
||||
//
|
||||
// ReadBlob and WriteBlob return number of bytes read or written. Notice
|
||||
// that ReadBlob does not throw an exception since eventually EOF is expected.
|
||||
//
|
||||
// ReadBlob can take NULL as a destination pointer
|
||||
//
|
||||
// All write functions throw exceptions for unexpected events like
|
||||
//
|
||||
// All write functions throw exceptions for unexpected events like
|
||||
// running out of memory or disk space.
|
||||
//
|
||||
|
||||
|
@ -105,7 +105,7 @@ void cArchive::ReadInt64(int64& ret) // throw(eArchive)
|
|||
}
|
||||
|
||||
// NOTE:BAM 10/11/99 -- we store unsigned size, but it really only works with
|
||||
// lengths < INT16_MAX due to sign extension in integral promotion during the
|
||||
// lengths < INT16_MAX due to sign extension in integral promotion during the
|
||||
// resize() in ReadString().
|
||||
// format for written string: 16-bit unsigned size, then a list of 16-bit UCS2 (Unicode) characters
|
||||
// not including terminating NULL
|
||||
|
@ -113,25 +113,25 @@ void cArchive::ReadString(TSTRING& ret) // throw(eArchive)
|
|||
{
|
||||
// read in size of string
|
||||
int16 size;
|
||||
ReadInt16( size );
|
||||
ReadInt16(size);
|
||||
|
||||
// create buffer for WCHAR16 string
|
||||
wc16_string ws;
|
||||
ws.resize( size );
|
||||
ws.resize(size);
|
||||
WCHAR16* pwc = (WCHAR16*)ws.data();
|
||||
|
||||
for( int n = 0; n < size; n++ )
|
||||
for (int n = 0; n < size; n++)
|
||||
{
|
||||
int16 i16;
|
||||
ReadInt16( i16 );
|
||||
ReadInt16(i16);
|
||||
*pwc++ = i16;
|
||||
}
|
||||
|
||||
// convert WCHAR16 string to a TSTRING
|
||||
ret = cStringUtil::WstrToTstr( ws );
|
||||
ret = cStringUtil::WstrToTstr(ws);
|
||||
}
|
||||
|
||||
int cArchive::ReadBlob(void* pBlob, int count)
|
||||
int cArchive::ReadBlob(void* pBlob, int count)
|
||||
{
|
||||
return Read(pBlob, count);
|
||||
}
|
||||
|
@ -155,7 +155,7 @@ void cArchive::WriteInt64(int64 i) // throw(eArchive)
|
|||
}
|
||||
|
||||
// NOTE:BAM 10/11/99 -- we store unsigned size, but it really only works with
|
||||
// lengths < INT16_MAX due to sign extension in integral promotion during the
|
||||
// lengths < INT16_MAX due to sign extension in integral promotion during the
|
||||
// resize() in ReadString().
|
||||
// format for written string: 16-bit unsigned size, then a list of 16-bit UCS2 (Unicode) characters
|
||||
// not including terminating NULL
|
||||
|
@ -163,20 +163,20 @@ void cArchive::WriteString(TSTRING s) // throw(eArchive)
|
|||
{
|
||||
// convert string to a UCS2 string
|
||||
wc16_string ws;
|
||||
cStringUtil::Convert( ws, s ); // Make convert "type-dispatched"
|
||||
cStringUtil::Convert(ws, s); // Make convert "type-dispatched"
|
||||
|
||||
// we assume that we can represent the size as a unsigned 16-bit number
|
||||
// we assume that we can represent the size as a unsigned 16-bit number
|
||||
// (we actually write it as a signed number, but we cast it)
|
||||
if( ws.length() > TSS_INT16_MAX )
|
||||
ThrowAndAssert( eArchiveStringTooLong() );
|
||||
if (ws.length() > TSS_INT16_MAX)
|
||||
ThrowAndAssert(eArchiveStringTooLong());
|
||||
|
||||
WriteInt16( static_cast<int16>( ws.length() ) );
|
||||
WriteInt16(static_cast<int16>(ws.length()));
|
||||
|
||||
// write out each 16 bit character
|
||||
// RAD:09/03/99 -- Optimized for performance with "const"
|
||||
wc16_string::const_iterator at = ws.begin();
|
||||
while ( at != ws.end() )
|
||||
WriteInt16( *at++ );
|
||||
while (at != ws.end())
|
||||
WriteInt16(*at++);
|
||||
}
|
||||
|
||||
|
||||
|
@ -190,27 +190,30 @@ int32 cArchive::GetStorageSize(const TSTRING& str)
|
|||
{
|
||||
int32 size = sizeof(int32); // the length is always stored
|
||||
//
|
||||
// after the length, all of the characters in the string are written as 16-bit values,
|
||||
// after the length, all of the characters in the string are written as 16-bit values,
|
||||
// except for the null character
|
||||
//
|
||||
size += ( str.length() * 2 );
|
||||
size += (str.length() * 2);
|
||||
|
||||
return size;
|
||||
}
|
||||
|
||||
int64 cArchive::Copy(cArchive* pFrom, int64 amt)
|
||||
{
|
||||
enum { BUF_SIZE = 2048 };
|
||||
int8 buf[BUF_SIZE];
|
||||
int64 amtLeft = amt;
|
||||
enum
|
||||
{
|
||||
BUF_SIZE = 2048
|
||||
};
|
||||
int8 buf[BUF_SIZE];
|
||||
int64 amtLeft = amt;
|
||||
|
||||
while(amtLeft > 0)
|
||||
while (amtLeft > 0)
|
||||
{
|
||||
int64 amtToRead = amtLeft > (int64)BUF_SIZE ? (int64)BUF_SIZE : amtLeft;
|
||||
int64 amtRead = pFrom->ReadBlob(buf, static_cast<int>( amtToRead ) );
|
||||
int64 amtRead = pFrom->ReadBlob(buf, static_cast<int>(amtToRead));
|
||||
amtLeft -= amtRead;
|
||||
WriteBlob(buf, static_cast<int>( amtRead ) );
|
||||
if(amtRead < amtToRead)
|
||||
WriteBlob(buf, static_cast<int>(amtRead));
|
||||
if (amtRead < amtToRead)
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -224,7 +227,7 @@ int64 cArchive::Copy(cArchive* pFrom, int64 amt)
|
|||
|
||||
cMemMappedArchive::cMemMappedArchive()
|
||||
{
|
||||
mpMappedMem = 0;
|
||||
mpMappedMem = 0;
|
||||
mMappedOffset = 0;
|
||||
mMappedLength = 0;
|
||||
}
|
||||
|
@ -269,13 +272,13 @@ void cMemMappedArchive::SetNewMap(void* pMap, int64 offset, int64 length) const
|
|||
{
|
||||
if (pMap == 0)
|
||||
{
|
||||
mpMappedMem = 0;
|
||||
mpMappedMem = 0;
|
||||
mMappedOffset = 0;
|
||||
mMappedLength = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
mpMappedMem = pMap;
|
||||
mpMappedMem = pMap;
|
||||
mMappedOffset = offset;
|
||||
mMappedLength = length;
|
||||
}
|
||||
|
@ -288,14 +291,13 @@ void cMemMappedArchive::SetNewMap(void* pMap, int64 offset, int64 length) const
|
|||
// mapped.
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
cMemoryArchive::cMemoryArchive(int maxSize)
|
||||
: mMaxAllocatedLen(maxSize)
|
||||
cMemoryArchive::cMemoryArchive(int maxSize) : mMaxAllocatedLen(maxSize)
|
||||
{
|
||||
ASSERT(maxSize > 0);
|
||||
mpMemory = 0;
|
||||
mpMemory = 0;
|
||||
mAllocatedLen = 0;
|
||||
mLogicalSize = 0;
|
||||
mReadHead = 0;
|
||||
mLogicalSize = 0;
|
||||
mReadHead = 0;
|
||||
}
|
||||
|
||||
cMemoryArchive::~cMemoryArchive()
|
||||
|
@ -321,13 +323,15 @@ void cMemoryArchive::Seek(int64 offset, SeekFrom from) // throw(eArchive)
|
|||
offset = mLogicalSize + (int)offset;
|
||||
break;
|
||||
default:
|
||||
ThrowAndAssert(eArchiveSeek(TSS_GetString( cCore, core::STR_MEMARCHIVE_FILENAME), TSS_GetString( cCore, core::STR_MEMARCHIVE_ERRSTR)));
|
||||
ThrowAndAssert(eArchiveSeek(TSS_GetString(cCore, core::STR_MEMARCHIVE_FILENAME),
|
||||
TSS_GetString(cCore, core::STR_MEMARCHIVE_ERRSTR)));
|
||||
}
|
||||
|
||||
if (offset > mLogicalSize)
|
||||
ThrowAndAssert(eArchiveSeek(TSS_GetString( cCore, core::STR_MEMARCHIVE_FILENAME), TSS_GetString( cCore, core::STR_MEMARCHIVE_ERRSTR)));
|
||||
ThrowAndAssert(eArchiveSeek(TSS_GetString(cCore, core::STR_MEMARCHIVE_FILENAME),
|
||||
TSS_GetString(cCore, core::STR_MEMARCHIVE_ERRSTR)));
|
||||
|
||||
mReadHead = static_cast<int>( offset );
|
||||
mReadHead = static_cast<int>(offset);
|
||||
}
|
||||
|
||||
int64 cMemoryArchive::CurrentPos() const
|
||||
|
@ -350,8 +354,8 @@ void cMemoryArchive::Truncate()
|
|||
|
||||
void cMemoryArchive::MapArchive(int64 offset, int64 len) // throw(eArchive)
|
||||
{
|
||||
if ( offset + (int)len > mLogicalSize )
|
||||
AllocateMemory( static_cast<int>( offset + len ) );
|
||||
if (offset + (int)len > mLogicalSize)
|
||||
AllocateMemory(static_cast<int>(offset + len));
|
||||
|
||||
SetNewMap(mpMemory + offset, offset, len);
|
||||
}
|
||||
|
@ -404,9 +408,9 @@ void cMemoryArchive::AllocateMemory(int len) // throw(eArchive)
|
|||
ThrowAndAssert(eArchiveOutOfMem());
|
||||
#endif
|
||||
|
||||
if( 0 == mAllocatedLen )
|
||||
if (0 == mAllocatedLen)
|
||||
mAllocatedLen = MIN_ALLOCATED_SIZE;
|
||||
|
||||
|
||||
while (mAllocatedLen < len)
|
||||
mAllocatedLen *= 2;
|
||||
|
||||
|
@ -416,7 +420,7 @@ void cMemoryArchive::AllocateMemory(int len) // throw(eArchive)
|
|||
memcpy(pNewMem, mpMemory, mLogicalSize);
|
||||
delete [] mpMemory;
|
||||
}
|
||||
mpMemory = pNewMem;
|
||||
mpMemory = pNewMem;
|
||||
mLogicalSize = len;
|
||||
|
||||
// update memory map if there is one
|
||||
|
@ -436,7 +440,7 @@ void cMemoryArchive::AllocateMemory(int len) // throw(eArchive)
|
|||
ASSERT(mpMemory);
|
||||
memcpy(pNewMem, mpMemory, len);
|
||||
delete [] mpMemory;
|
||||
mpMemory = pNewMem;
|
||||
mpMemory = pNewMem;
|
||||
mLogicalSize = len;
|
||||
|
||||
// update memory map if there is one
|
||||
|
@ -464,33 +468,27 @@ public:
|
|||
//-----------------------------------------------------------------------------
|
||||
// cFixedMemArchive
|
||||
//-----------------------------------------------------------------------------
|
||||
cFixedMemArchive::cFixedMemArchive()
|
||||
: mpMemory (0),
|
||||
mSize (0),
|
||||
mReadHead (0)
|
||||
cFixedMemArchive::cFixedMemArchive() : mpMemory(0), mSize(0), mReadHead(0)
|
||||
{
|
||||
}
|
||||
|
||||
cFixedMemArchive::cFixedMemArchive( int8* pMem, int32 size )
|
||||
: mpMemory (0),
|
||||
mSize (0),
|
||||
mReadHead (0)
|
||||
cFixedMemArchive::cFixedMemArchive(int8* pMem, int32 size) : mpMemory(0), mSize(0), mReadHead(0)
|
||||
{
|
||||
Attach( pMem, size );
|
||||
Attach(pMem, size);
|
||||
}
|
||||
|
||||
cFixedMemArchive::~cFixedMemArchive()
|
||||
{
|
||||
}
|
||||
|
||||
void cFixedMemArchive::Attach( int8* pMem, int32 size )
|
||||
void cFixedMemArchive::Attach(int8* pMem, int32 size)
|
||||
{
|
||||
mpMemory = pMem;
|
||||
mSize = size;
|
||||
mReadHead = 0;
|
||||
mpMemory = pMem;
|
||||
mSize = size;
|
||||
mReadHead = 0;
|
||||
}
|
||||
|
||||
void cFixedMemArchive::Seek(int64 offset, SeekFrom from) // throw(eArchive)
|
||||
void cFixedMemArchive::Seek(int64 offset, SeekFrom from) // throw(eArchive)
|
||||
{
|
||||
switch (from)
|
||||
{
|
||||
|
@ -503,21 +501,23 @@ void cFixedMemArchive::Seek(int64 offset, SeekFrom from) // throw(eArchive)
|
|||
offset = mSize + (int)offset;
|
||||
break;
|
||||
default:
|
||||
ThrowAndAssert(eArchiveSeek(TSS_GetString( cCore, core::STR_MEMARCHIVE_FILENAME), TSS_GetString( cCore, core::STR_MEMARCHIVE_ERRSTR)));
|
||||
ThrowAndAssert(eArchiveSeek(TSS_GetString(cCore, core::STR_MEMARCHIVE_FILENAME),
|
||||
TSS_GetString(cCore, core::STR_MEMARCHIVE_ERRSTR)));
|
||||
}
|
||||
|
||||
if (offset > mSize)
|
||||
ThrowAndAssert(eArchiveSeek(TSS_GetString( cCore, core::STR_MEMARCHIVE_FILENAME), TSS_GetString( cCore, core::STR_MEMARCHIVE_ERRSTR)));
|
||||
ThrowAndAssert(eArchiveSeek(TSS_GetString(cCore, core::STR_MEMARCHIVE_FILENAME),
|
||||
TSS_GetString(cCore, core::STR_MEMARCHIVE_ERRSTR)));
|
||||
|
||||
mReadHead = static_cast<int32>( offset );
|
||||
mReadHead = static_cast<int32>(offset);
|
||||
}
|
||||
|
||||
int64 cFixedMemArchive::CurrentPos() const
|
||||
int64 cFixedMemArchive::CurrentPos() const
|
||||
{
|
||||
return mReadHead;
|
||||
}
|
||||
|
||||
int64 cFixedMemArchive::Length() const
|
||||
int64 cFixedMemArchive::Length() const
|
||||
{
|
||||
return mSize;
|
||||
}
|
||||
|
@ -527,12 +527,12 @@ bool cFixedMemArchive::EndOfFile()
|
|||
return (mReadHead >= mSize);
|
||||
}
|
||||
|
||||
int cFixedMemArchive::Read(void* pDest, int count) // throw(eArchive)
|
||||
int cFixedMemArchive::Read(void* pDest, int count) // throw(eArchive)
|
||||
{
|
||||
ASSERT( pDest );
|
||||
ASSERT(pDest);
|
||||
if (mReadHead + count > mSize)
|
||||
{
|
||||
count = static_cast<int>( mSize - mReadHead );
|
||||
count = static_cast<int>(mSize - mReadHead);
|
||||
if (count <= 0)
|
||||
return 0;
|
||||
}
|
||||
|
@ -545,11 +545,11 @@ int cFixedMemArchive::Read(void* pDest, int count) // throw(eArchive)
|
|||
return count;
|
||||
}
|
||||
|
||||
int cFixedMemArchive::Write(const void* pDest, int count) // throw(eArchive)
|
||||
int cFixedMemArchive::Write(const void* pDest, int count) // throw(eArchive)
|
||||
{
|
||||
if (mReadHead + count > mSize)
|
||||
{
|
||||
ASSERT( false );
|
||||
ASSERT(false);
|
||||
throw eArchiveWrite();
|
||||
}
|
||||
|
||||
|
@ -566,11 +566,9 @@ int cFixedMemArchive::Write(const void* pDest, int count) // throw(eArchive)
|
|||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//Ctor -- Initialize member variables to 0 or NULL equivalents.
|
||||
cFileArchive::cFileArchive() :
|
||||
mFileSize(0),
|
||||
mReadHead(0),
|
||||
isWritable(false)
|
||||
{}
|
||||
cFileArchive::cFileArchive() : mFileSize(0), mReadHead(0), isWritable(false)
|
||||
{
|
||||
}
|
||||
|
||||
cFileArchive::~cFileArchive()
|
||||
{
|
||||
|
@ -578,16 +576,16 @@ cFileArchive::~cFileArchive()
|
|||
|
||||
bool cFileArchive::EndOfFile()
|
||||
{
|
||||
return ( mReadHead >= mFileSize );
|
||||
return (mReadHead >= mFileSize);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// Seek -- This is where the actual offset is performed. The default
|
||||
// for each archive will be 0.
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
void cFileArchive::Seek( int64 offset, SeekFrom from) // throw(eArchive)
|
||||
void cFileArchive::Seek(int64 offset, SeekFrom from) // throw(eArchive)
|
||||
{
|
||||
try
|
||||
try
|
||||
{
|
||||
switch (from)
|
||||
{
|
||||
|
@ -600,19 +598,19 @@ void cFileArchive::Seek( int64 offset, SeekFrom from) // throw(eArchive)
|
|||
offset = mFileSize + offset;
|
||||
break;
|
||||
default:
|
||||
throw eArchiveSeek( mCurrentFilename, iFSServices::GetInstance()->GetErrString() ) ;
|
||||
throw eArchiveSeek(mCurrentFilename, iFSServices::GetInstance()->GetErrString());
|
||||
}
|
||||
|
||||
if ( offset > mFileSize )
|
||||
throw eArchiveSeek( mCurrentFilename, iFSServices::GetInstance()->GetErrString() ) ;
|
||||
if (offset > mFileSize)
|
||||
throw eArchiveSeek(mCurrentFilename, iFSServices::GetInstance()->GetErrString());
|
||||
mReadHead = offset;
|
||||
|
||||
mCurrentFile.Seek(mReadHead, cFile::SEEK_BEGIN);
|
||||
//This is where the actual read/writehead is set!!
|
||||
}//try
|
||||
catch( eFile& fileError )
|
||||
//This is where the actual read/writehead is set!!
|
||||
} //try
|
||||
catch (eFile& fileError)
|
||||
{
|
||||
throw( eArchiveSeek( mCurrentFilename, fileError.GetDescription() ) );
|
||||
throw(eArchiveSeek(mCurrentFilename, fileError.GetDescription()));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -626,13 +624,13 @@ int64 cFileArchive::CurrentPos(void) const
|
|||
/////////////////////////////////////////////////////////////////////////
|
||||
int64 cFileArchive::Length(void) const
|
||||
{
|
||||
try
|
||||
try
|
||||
{
|
||||
return mCurrentFile.GetSize();
|
||||
}
|
||||
catch(eFile& fileError)
|
||||
catch (eFile& fileError)
|
||||
{
|
||||
throw( eArchiveSeek( mCurrentFilename, fileError.GetDescription() ) );
|
||||
throw(eArchiveSeek(mCurrentFilename, fileError.GetDescription()));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -641,26 +639,26 @@ int64 cFileArchive::Length(void) const
|
|||
/////////////////////////////////////////////////////////////////////////
|
||||
void cFileArchive::OpenRead(const TCHAR* filename, uint32 openFlags)
|
||||
{
|
||||
try
|
||||
try
|
||||
{
|
||||
// set up open flags
|
||||
uint32 flags = cFile::OPEN_READ;
|
||||
flags |= ( ( openFlags & FA_OPEN_TRUNCATE ) ? cFile::OPEN_TRUNCATE : 0 );
|
||||
flags |= ( ( openFlags & FA_OPEN_TEXT ) ? cFile::OPEN_TEXT : 0 );
|
||||
flags |= ( ( openFlags & FA_SCANNING ) ? cFile::OPEN_SCANNING : 0 );
|
||||
flags |= ( ( openFlags & FA_DIRECT ) ? cFile::OPEN_DIRECT : 0 );
|
||||
flags |= ((openFlags & FA_OPEN_TRUNCATE) ? cFile::OPEN_TRUNCATE : 0);
|
||||
flags |= ((openFlags & FA_OPEN_TEXT) ? cFile::OPEN_TEXT : 0);
|
||||
flags |= ((openFlags & FA_SCANNING) ? cFile::OPEN_SCANNING : 0);
|
||||
flags |= ((openFlags & FA_DIRECT) ? cFile::OPEN_DIRECT : 0);
|
||||
|
||||
mOpenFlags = openFlags;
|
||||
mOpenFlags = openFlags;
|
||||
mCurrentFilename = filename;
|
||||
mCurrentFile.Open( filename, flags );
|
||||
mCurrentFile.Open(filename, flags);
|
||||
isWritable = false;
|
||||
|
||||
mFileSize = mCurrentFile.GetSize();
|
||||
mReadHead = mCurrentFile.Seek( 0, cFile::SEEK_BEGIN );
|
||||
mFileSize = mCurrentFile.GetSize();
|
||||
mReadHead = mCurrentFile.Seek(0, cFile::SEEK_BEGIN);
|
||||
}
|
||||
catch(eFile& fileError)
|
||||
catch (eFile& fileError)
|
||||
{
|
||||
throw(eArchiveOpen( mCurrentFilename, fileError.GetDescription() ) );
|
||||
throw(eArchiveOpen(mCurrentFilename, fileError.GetDescription()));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -669,26 +667,26 @@ void cFileArchive::OpenRead(const TCHAR* filename, uint32 openFlags)
|
|||
/////////////////////////////////////////////////////////////////////////
|
||||
void cFileArchive::OpenReadWrite(const TCHAR* filename, uint32 openFlags)
|
||||
{
|
||||
try
|
||||
{
|
||||
try
|
||||
{
|
||||
// set up open flags
|
||||
uint32 flags = cFile::OPEN_WRITE;
|
||||
flags |= ( ( openFlags & FA_OPEN_TRUNCATE ) ? cFile::OPEN_TRUNCATE : 0 );
|
||||
flags |= ( ( openFlags & FA_OPEN_TEXT ) ? cFile::OPEN_TEXT : 0 );
|
||||
flags |= ( ( openFlags & FA_SCANNING ) ? cFile::OPEN_SCANNING : 0 );
|
||||
flags |= ( ( openFlags & FA_DIRECT ) ? cFile::OPEN_DIRECT : 0 );
|
||||
flags |= ((openFlags & FA_OPEN_TRUNCATE) ? cFile::OPEN_TRUNCATE : 0);
|
||||
flags |= ((openFlags & FA_OPEN_TEXT) ? cFile::OPEN_TEXT : 0);
|
||||
flags |= ((openFlags & FA_SCANNING) ? cFile::OPEN_SCANNING : 0);
|
||||
flags |= ((openFlags & FA_DIRECT) ? cFile::OPEN_DIRECT : 0);
|
||||
|
||||
mOpenFlags = openFlags;
|
||||
mOpenFlags = openFlags;
|
||||
mCurrentFilename = filename;
|
||||
mCurrentFile.Open( filename, flags );
|
||||
mCurrentFile.Open(filename, flags);
|
||||
isWritable = true;
|
||||
|
||||
mFileSize = mCurrentFile.GetSize();
|
||||
mReadHead = mCurrentFile.Seek( 0, cFile::SEEK_BEGIN );
|
||||
mReadHead = mCurrentFile.Seek(0, cFile::SEEK_BEGIN);
|
||||
}
|
||||
catch(eFile& fileError)
|
||||
catch (eFile& fileError)
|
||||
{
|
||||
throw( eArchiveOpen( mCurrentFilename, fileError.GetDescription() ) );
|
||||
throw(eArchiveOpen(mCurrentFilename, fileError.GetDescription()));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -706,66 +704,65 @@ TSTRING cFileArchive::GetCurrentFilename(void) const
|
|||
/////////////////////////////////////////////////////////////////////////
|
||||
void cFileArchive::Close()
|
||||
{
|
||||
try
|
||||
try
|
||||
{
|
||||
mCurrentFile.Close();
|
||||
mFileSize = 0;
|
||||
mReadHead = 0;
|
||||
mFileSize = 0;
|
||||
mReadHead = 0;
|
||||
|
||||
mCurrentFilename = _T("");
|
||||
}
|
||||
catch(eFile& fileError)
|
||||
catch (eFile& fileError)
|
||||
{
|
||||
throw( eArchive( mCurrentFilename, fileError.GetDescription() ) );
|
||||
throw(eArchive(mCurrentFilename, fileError.GetDescription()));
|
||||
}
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
// Read -- Read places bytes in location designated by pDest. Returns
|
||||
// Read -- Read places bytes in location designated by pDest. Returns
|
||||
// The actual amount read into *pDest.
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
int cFileArchive::Read(void* pDest, int count)
|
||||
{
|
||||
|
||||
try
|
||||
try
|
||||
{
|
||||
if ( mReadHead + count > mFileSize && !(mOpenFlags & FA_DIRECT))
|
||||
count = static_cast<int>( mFileSize - mReadHead );
|
||||
if (mReadHead + count > mFileSize && !(mOpenFlags & FA_DIRECT))
|
||||
count = static_cast<int>(mFileSize - mReadHead);
|
||||
|
||||
if ( pDest != NULL )
|
||||
if (pDest != NULL)
|
||||
{
|
||||
int nbRead =
|
||||
static_cast<int>( mCurrentFile.Read( pDest, count ) );
|
||||
int nbRead = static_cast<int>(mCurrentFile.Read(pDest, count));
|
||||
|
||||
// 'count' may not be equal to 'nbRead' if the file is open in
|
||||
// text mode.
|
||||
count = nbRead;
|
||||
if(count < 0) count = 0;
|
||||
if (count < 0)
|
||||
count = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
int i;
|
||||
int i;
|
||||
int32 dummy;
|
||||
for (i = count; ; i -= sizeof(int32))
|
||||
for (i = count;; i -= sizeof(int32))
|
||||
{
|
||||
if (i < (int)sizeof(int32))
|
||||
{
|
||||
if (i > 0)
|
||||
mCurrentFile.Read( &dummy, i );
|
||||
mCurrentFile.Read(&dummy, i);
|
||||
break;
|
||||
}
|
||||
mCurrentFile.Read( &dummy, i );
|
||||
mCurrentFile.Read(&dummy, i);
|
||||
}
|
||||
}
|
||||
|
||||
mReadHead += count;
|
||||
return count;
|
||||
}
|
||||
catch( eFile& fileError )
|
||||
catch (eFile& fileError)
|
||||
{
|
||||
throw( eArchiveRead( mCurrentFilename, fileError.GetDescription() ) );
|
||||
throw(eArchiveRead(mCurrentFilename, fileError.GetDescription()));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
|
@ -774,38 +771,38 @@ int cFileArchive::Read(void* pDest, int count)
|
|||
/////////////////////////////////////////////////////////////////////////
|
||||
int cFileArchive::Write(const void* pDest, int count) // throw(eArchive)
|
||||
{
|
||||
try
|
||||
try
|
||||
{
|
||||
int64 actual_count = 0;
|
||||
ASSERT( mCurrentFile.isWritable );
|
||||
ASSERT(mCurrentFile.isWritable);
|
||||
|
||||
actual_count = mCurrentFile.Write( pDest, count );
|
||||
actual_count = mCurrentFile.Write(pDest, count);
|
||||
|
||||
if ( actual_count < count )
|
||||
if (actual_count < count)
|
||||
{
|
||||
//Disk full??
|
||||
throw eArchiveWrite( mCurrentFilename, iFSServices::GetInstance()->GetErrString() ) ;
|
||||
throw eArchiveWrite(mCurrentFilename, iFSServices::GetInstance()->GetErrString());
|
||||
}
|
||||
|
||||
// increment the read/write head
|
||||
mReadHead += actual_count;
|
||||
|
||||
// increase the size, if needed
|
||||
if( mReadHead > mFileSize )
|
||||
if (mReadHead > mFileSize)
|
||||
{
|
||||
#if 0 // IS_SUNPRO
|
||||
// These two lines seem to be all there is between code that crashes and code that works for sunpro
|
||||
#if 0 // IS_SUNPRO \
|
||||
// These two lines seem to be all there is between code that crashes and code that works for sunpro
|
||||
cDebug d("cFileArchive::Write()");
|
||||
d.TraceDebug(_T("file(%s) adjusted mFileSize = %d mReadHead = %d\n"), mCurrentFilename.c_str(), (int)mFileSize, (int)mReadHead);
|
||||
#endif
|
||||
#endif
|
||||
mFileSize = mReadHead;
|
||||
}
|
||||
|
||||
return (int)actual_count;
|
||||
}
|
||||
catch( eFile& fileError )
|
||||
catch (eFile& fileError)
|
||||
{
|
||||
throw( eArchiveWrite( mCurrentFilename, fileError.GetDescription() ) );
|
||||
throw(eArchiveWrite(mCurrentFilename, fileError.GetDescription()));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -813,91 +810,92 @@ int cFileArchive::Write(const void* pDest, int count) // throw(eArchive)
|
|||
/////////////////////////////////////////////////////////////////////////
|
||||
// Truncate
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
void cFileArchive::Truncate() // throw(eArchive)
|
||||
void cFileArchive::Truncate() // throw(eArchive)
|
||||
{
|
||||
ASSERT( mCurrentFile.IsOpen() );
|
||||
ASSERT( mCurrentFile.isWritable );
|
||||
ASSERT(mCurrentFile.IsOpen());
|
||||
ASSERT(mCurrentFile.isWritable);
|
||||
|
||||
try
|
||||
try
|
||||
{
|
||||
mCurrentFile.Truncate ( mReadHead );
|
||||
mCurrentFile.Truncate(mReadHead);
|
||||
}
|
||||
catch( eFile& fileError )
|
||||
catch (eFile& fileError)
|
||||
{
|
||||
//TODO: create an error number for truncate...
|
||||
throw( eArchiveWrite( mCurrentFilename, fileError.GetDescription() ) );
|
||||
throw(eArchiveWrite(mCurrentFilename, fileError.GetDescription()));
|
||||
}
|
||||
|
||||
mFileSize = mReadHead;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
// OpenReadWrite -- Opens the file to be read or written to
|
||||
//
|
||||
// since we'll never open an existing file, the truncateFile flag is unnecessary.
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
void cLockedTemporaryFileArchive::OpenReadWrite( const TCHAR* filename, uint32 openFlags )
|
||||
void cLockedTemporaryFileArchive::OpenReadWrite(const TCHAR* filename, uint32 openFlags)
|
||||
{
|
||||
TSTRING strTempFile;
|
||||
TSTRING strTempFile;
|
||||
|
||||
try {
|
||||
try
|
||||
{
|
||||
|
||||
ASSERT( !mCurrentFile.IsOpen() ); // shouldn't be able to create a new file when we're already open
|
||||
if ( mCurrentFile.IsOpen() )
|
||||
throw( eArchive( mCurrentFilename, _T("Internal Error") ) );
|
||||
ASSERT(!mCurrentFile.IsOpen()); // shouldn't be able to create a new file when we're already open
|
||||
if (mCurrentFile.IsOpen())
|
||||
throw(eArchive(mCurrentFilename, _T("Internal Error")));
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// if filename is NULL, create a temp file for the caller
|
||||
if( filename == NULL )
|
||||
{
|
||||
try
|
||||
{
|
||||
iFSServices::GetInstance()->GetTempDirName( strTempFile );
|
||||
strTempFile += _T("twtempXXXXXX");
|
||||
iFSServices::GetInstance()->MakeTempFilename( strTempFile );
|
||||
}
|
||||
catch( eFSServices& fileError)
|
||||
{
|
||||
TSTRING errStr = TSS_GetString( cCore, core::STR_BAD_TEMPDIRECTORY );
|
||||
throw eArchiveOpen(strTempFile, errStr);
|
||||
}
|
||||
}
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// if filename is NULL, create a temp file for the caller
|
||||
if (filename == NULL)
|
||||
{
|
||||
try
|
||||
{
|
||||
iFSServices::GetInstance()->GetTempDirName(strTempFile);
|
||||
strTempFile += _T("twtempXXXXXX");
|
||||
iFSServices::GetInstance()->MakeTempFilename(strTempFile);
|
||||
}
|
||||
catch (eFSServices& fileError)
|
||||
{
|
||||
TSTRING errStr = TSS_GetString(cCore, core::STR_BAD_TEMPDIRECTORY);
|
||||
throw eArchiveOpen(strTempFile, errStr);
|
||||
}
|
||||
}
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// create file
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// create file
|
||||
|
||||
// set up flags
|
||||
uint32 flags = cFile::OPEN_WRITE | cFile::OPEN_LOCKED_TEMP | cFile::OPEN_CREATE | cFile::OPEN_EXCLUSIVE;
|
||||
if ( openFlags & FA_OPEN_TRUNCATE )
|
||||
flags |= cFile::OPEN_TRUNCATE;
|
||||
if ( openFlags & FA_OPEN_TEXT )
|
||||
flags |= cFile::OPEN_TEXT;
|
||||
// set up flags
|
||||
uint32 flags = cFile::OPEN_WRITE | cFile::OPEN_LOCKED_TEMP | cFile::OPEN_CREATE | cFile::OPEN_EXCLUSIVE;
|
||||
if (openFlags & FA_OPEN_TRUNCATE)
|
||||
flags |= cFile::OPEN_TRUNCATE;
|
||||
if (openFlags & FA_OPEN_TEXT)
|
||||
flags |= cFile::OPEN_TEXT;
|
||||
|
||||
// open file
|
||||
mCurrentFilename = filename ? filename : strTempFile.c_str();
|
||||
mCurrentFile.Open( mCurrentFilename, flags );
|
||||
|
||||
isWritable = true;
|
||||
mFileSize = mCurrentFile.GetSize();
|
||||
mReadHead = mCurrentFile.Seek( 0, cFile::SEEK_BEGIN );
|
||||
// open file
|
||||
mCurrentFilename = filename ? filename : strTempFile.c_str();
|
||||
mCurrentFile.Open(mCurrentFilename, flags);
|
||||
|
||||
isWritable = true;
|
||||
mFileSize = mCurrentFile.GetSize();
|
||||
mReadHead = mCurrentFile.Seek(0, cFile::SEEK_BEGIN);
|
||||
|
||||
#if 0 // IS_SUNPRO
|
||||
cDebug d("cLockedTemporaryFileArchive::OpenReadWrite()");
|
||||
d.TraceDebug(_T("file(%s) set mFileSize to %d mReadHead to %d\n"), mCurrentFilename.c_str(), (int)mFileSize, (int)mReadHead);
|
||||
#endif
|
||||
|
||||
}//try
|
||||
catch (eFile& fileError) {
|
||||
TSTRING errStr = TSS_GetString( cCore, core::STR_BAD_TEMPDIRECTORY );
|
||||
eArchiveOpen e(strTempFile, errStr);
|
||||
throw e;
|
||||
}
|
||||
} //try
|
||||
catch (eFile& fileError)
|
||||
{
|
||||
TSTRING errStr = TSS_GetString(cCore, core::STR_BAD_TEMPDIRECTORY);
|
||||
eArchiveOpen e(strTempFile, errStr);
|
||||
throw e;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
|
@ -907,4 +905,3 @@ void cLockedTemporaryFileArchive::Close()
|
|||
// Note: this deletes the file as well
|
||||
cFileArchive::Close();
|
||||
}
|
||||
|
||||
|
|
|
@ -3,29 +3,29 @@
|
|||
// Portions created by Tripwire, Inc. are copyright (C) 2000-2018 Tripwire,
|
||||
// Inc. Tripwire is a registered trademark of Tripwire, Inc. All rights
|
||||
// reserved.
|
||||
//
|
||||
//
|
||||
// This program is free software. The contents of this file are subject
|
||||
// to the terms of the GNU General Public License as published by the
|
||||
// Free Software Foundation; either version 2 of the License, or (at your
|
||||
// option) any later version. You may redistribute it and/or modify it
|
||||
// only in compliance with the GNU General Public License.
|
||||
//
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful.
|
||||
// However, this program is distributed AS-IS WITHOUT ANY
|
||||
// WARRANTY; INCLUDING THE IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS
|
||||
// FOR A PARTICULAR PURPOSE. Please see the GNU General Public License
|
||||
// for more details.
|
||||
//
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
|
||||
// USA.
|
||||
//
|
||||
//
|
||||
// Nothing in the GNU General Public License or any other license to use
|
||||
// the code or files shall permit you to use Tripwire's trademarks,
|
||||
// service marks, or other intellectual property without Tripwire's
|
||||
// prior written consent.
|
||||
//
|
||||
//
|
||||
// If you have any questions, please contact Tripwire, Inc. at either
|
||||
// info@tripwire.org or www.tripwire.org.
|
||||
//
|
||||
|
@ -56,69 +56,71 @@
|
|||
//=============================================================================
|
||||
// eArchive exception classes
|
||||
//=============================================================================
|
||||
TSS_FILE_EXCEPTION( eArchive, eFileError );
|
||||
TSS_FILE_EXCEPTION( eArchiveOpen, eArchive );
|
||||
TSS_FILE_EXCEPTION( eArchiveWrite, eArchive );
|
||||
TSS_FILE_EXCEPTION( eArchiveRead, eArchive );
|
||||
TSS_FILE_EXCEPTION( eArchiveEOF, eArchive );
|
||||
TSS_FILE_EXCEPTION( eArchiveSeek, eArchive );
|
||||
TSS_FILE_EXCEPTION( eArchiveMemmap, eArchive );
|
||||
TSS_FILE_EXCEPTION( eArchiveOutOfMem, eArchive );
|
||||
TSS_FILE_EXCEPTION( eArchiveInvalidOp, eArchive );
|
||||
TSS_FILE_EXCEPTION( eArchiveFormat, eArchive );
|
||||
TSS_FILE_EXCEPTION( eArchiveNotRegularFile, eArchive );
|
||||
TSS_BEGIN_EXCEPTION( eArchiveCrypto, eArchive )
|
||||
TSS_FILE_EXCEPTION(eArchive, eFileError);
|
||||
TSS_FILE_EXCEPTION(eArchiveOpen, eArchive);
|
||||
TSS_FILE_EXCEPTION(eArchiveWrite, eArchive);
|
||||
TSS_FILE_EXCEPTION(eArchiveRead, eArchive);
|
||||
TSS_FILE_EXCEPTION(eArchiveEOF, eArchive);
|
||||
TSS_FILE_EXCEPTION(eArchiveSeek, eArchive);
|
||||
TSS_FILE_EXCEPTION(eArchiveMemmap, eArchive);
|
||||
TSS_FILE_EXCEPTION(eArchiveOutOfMem, eArchive);
|
||||
TSS_FILE_EXCEPTION(eArchiveInvalidOp, eArchive);
|
||||
TSS_FILE_EXCEPTION(eArchiveFormat, eArchive);
|
||||
TSS_FILE_EXCEPTION(eArchiveNotRegularFile, eArchive);
|
||||
TSS_BEGIN_EXCEPTION(eArchiveCrypto, eArchive)
|
||||
|
||||
virtual TSTRING GetMsg() const;
|
||||
// eCryptoArchive appends a special string to the end of
|
||||
// all exception messages
|
||||
virtual TSTRING GetMsg() const;
|
||||
// eCryptoArchive appends a special string to the end of
|
||||
// all exception messages
|
||||
TSS_END_EXCEPTION()
|
||||
TSS_EXCEPTION( eArchiveStringTooLong, eArchive );
|
||||
TSS_EXCEPTION(eArchiveStringTooLong, eArchive);
|
||||
|
||||
// throw( eArchiveOpen( cErrorUtil::MakeFileError( fileError.GetMsg(), strTempFile ) ) );
|
||||
|
||||
|
||||
//=============================================================================
|
||||
// cArchive
|
||||
// cArchive
|
||||
//=============================================================================
|
||||
|
||||
class cArchive
|
||||
{
|
||||
public:
|
||||
virtual ~cArchive() {}
|
||||
|
||||
virtual ~cArchive()
|
||||
{
|
||||
}
|
||||
|
||||
// convenience methods
|
||||
//
|
||||
// Specific Read functions throw(eArchive) if EOF is reached because
|
||||
// if the caller is requesting a certain amount of data to be present,
|
||||
// if the caller is requesting a certain amount of data to be present,
|
||||
// reaching EOF is unexpected
|
||||
//
|
||||
// ReadBlob and WriteBlob return number of bytes read or written. Notice
|
||||
// that ReadBlob does not throw an exception since eventually EOF is expected.
|
||||
//
|
||||
// ReadBlob can take NULL as a destination pointer
|
||||
//
|
||||
// All write functions throw exceptions for unexpected events like
|
||||
//
|
||||
// All write functions throw exceptions for unexpected events like
|
||||
// running out of memory or disk space.
|
||||
//
|
||||
void ReadInt16(int16& ret); // throw(eArchive)
|
||||
void ReadInt32(int32& ret); // throw(eArchive)
|
||||
void ReadInt64(int64& ret); // throw(eArchive)
|
||||
void ReadString(TSTRING& ret); // throw(eArchive)
|
||||
int ReadBlob(void* pBlob, int count);
|
||||
void WriteInt16(int16 i); // throw(eArchive)
|
||||
void WriteInt32(int32 i); // throw(eArchive)
|
||||
void WriteInt64(int64 i); // throw(eArchive)
|
||||
void WriteString(TSTRING s); // throw(eArchive)
|
||||
void WriteBlob(const void* pBlob, int count); // throw(eArchive)
|
||||
void ReadInt16(int16& ret); // throw(eArchive)
|
||||
void ReadInt32(int32& ret); // throw(eArchive)
|
||||
void ReadInt64(int64& ret); // throw(eArchive)
|
||||
void ReadString(TSTRING& ret); // throw(eArchive)
|
||||
int ReadBlob(void* pBlob, int count);
|
||||
void WriteInt16(int16 i); // throw(eArchive)
|
||||
void WriteInt32(int32 i); // throw(eArchive)
|
||||
void WriteInt64(int64 i); // throw(eArchive)
|
||||
void WriteString(TSTRING s); // throw(eArchive)
|
||||
void WriteBlob(const void* pBlob, int count); // throw(eArchive)
|
||||
|
||||
static int32 GetStorageSize(const TSTRING& str);
|
||||
// this method calculates how many bytes the given string will take up in the archive and returns
|
||||
// that value
|
||||
// NOTE -- if the implementation of ReadString() or WriteString() ever changes, this method will also
|
||||
// need to change.
|
||||
// this method calculates how many bytes the given string will take up in the archive and returns
|
||||
// that value
|
||||
// NOTE -- if the implementation of ReadString() or WriteString() ever changes, this method will also
|
||||
// need to change.
|
||||
|
||||
int64 Copy(cArchive* pFrom, int64 amt); // throw(eArchive)
|
||||
int64 Copy(cArchive* pFrom, int64 amt); // throw(eArchive)
|
||||
// this method copies amt bytes from pFrom to itself, throwing an eArchive if anything goes wrong.
|
||||
|
||||
// only makes sense to call for reading archives
|
||||
|
@ -126,7 +128,7 @@ public:
|
|||
|
||||
protected:
|
||||
// overrides
|
||||
virtual int Read(void* pDest, int count) = 0;
|
||||
virtual int Read(void* pDest, int count) = 0;
|
||||
virtual int Write(const void* pDest, int count) = 0; // throw(eArchive);
|
||||
};
|
||||
|
||||
|
@ -137,15 +139,16 @@ protected:
|
|||
class cBidirArchive : public cArchive
|
||||
{
|
||||
public:
|
||||
enum SeekFrom {
|
||||
enum SeekFrom
|
||||
{
|
||||
BEGINNING = 0,
|
||||
CURRENT = 1,
|
||||
END = -1
|
||||
CURRENT = 1,
|
||||
END = -1
|
||||
};
|
||||
|
||||
virtual void Seek(int64 offset, SeekFrom from) = 0; // throw(eArchive);
|
||||
virtual int64 CurrentPos() const = 0;
|
||||
virtual int64 Length() const = 0;
|
||||
virtual void Seek(int64 offset, SeekFrom from) = 0; // throw(eArchive);
|
||||
virtual int64 CurrentPos() const = 0;
|
||||
virtual int64 Length() const = 0;
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -155,29 +158,30 @@ public:
|
|||
class cMemMappedArchive : public cBidirArchive
|
||||
{
|
||||
public:
|
||||
enum {
|
||||
enum
|
||||
{
|
||||
MAP_TO_EOF = -1
|
||||
};
|
||||
|
||||
cMemMappedArchive();
|
||||
virtual ~cMemMappedArchive();
|
||||
|
||||
virtual void MapArchive(int64 offset, int64 len) = 0; // throw(eArchive);
|
||||
virtual void MapArchive(int64 offset, int64 len) const = 0; // throw(eArchive);
|
||||
virtual void MapArchive(int64 offset, int64 len) = 0; // throw(eArchive);
|
||||
virtual void MapArchive(int64 offset, int64 len) const = 0; // throw(eArchive);
|
||||
// the const version of MapArchive() does not allow the archive to grow in size
|
||||
|
||||
int64 GetMappedOffset() const; // throw(eArchive)
|
||||
int64 GetMappedLength() const; // throw(eArchive)
|
||||
void* GetMap(); // throw(eArchive)
|
||||
const void* GetMap() const;
|
||||
int64 GetMappedOffset() const; // throw(eArchive)
|
||||
int64 GetMappedLength() const; // throw(eArchive)
|
||||
void* GetMap(); // throw(eArchive)
|
||||
const void* GetMap() const;
|
||||
|
||||
protected:
|
||||
mutable void* mpMappedMem;
|
||||
mutable int64 mMappedOffset;
|
||||
mutable int64 mMappedLength;
|
||||
mutable void* mpMappedMem;
|
||||
mutable int64 mMappedOffset;
|
||||
mutable int64 mMappedLength;
|
||||
|
||||
// call in derived class to set above vars
|
||||
void SetNewMap(void* pMap, int64 offset, int64 length) const;
|
||||
void SetNewMap(void* pMap, int64 offset, int64 length) const;
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -193,27 +197,30 @@ public:
|
|||
cMemoryArchive(int maxSize = 0x8000000); // default max size == 128MB
|
||||
~cMemoryArchive();
|
||||
|
||||
virtual bool EndOfFile();
|
||||
virtual void Seek(int64 offset, SeekFrom from); // throw(eArchive)
|
||||
virtual int64 CurrentPos() const;
|
||||
virtual int64 Length() const;
|
||||
virtual void MapArchive(int64 offset, int64 len); // throw(eArchive)
|
||||
virtual void MapArchive(int64 offset, int64 len) const; // throw(eArchive)
|
||||
virtual bool EndOfFile();
|
||||
virtual void Seek(int64 offset, SeekFrom from); // throw(eArchive)
|
||||
virtual int64 CurrentPos() const;
|
||||
virtual int64 Length() const;
|
||||
virtual void MapArchive(int64 offset, int64 len); // throw(eArchive)
|
||||
virtual void MapArchive(int64 offset, int64 len) const; // throw(eArchive)
|
||||
|
||||
void Truncate(); // set the length to the current pos
|
||||
void Truncate(); // set the length to the current pos
|
||||
|
||||
int8* GetMemory() const { return mpMemory; }
|
||||
int8* GetMemory() const
|
||||
{
|
||||
return mpMemory;
|
||||
}
|
||||
|
||||
protected:
|
||||
int8* mpMemory;
|
||||
int mAllocatedLen;
|
||||
int mMaxAllocatedLen;
|
||||
int mLogicalSize;
|
||||
int mReadHead;
|
||||
int8* mpMemory;
|
||||
int mAllocatedLen;
|
||||
int mMaxAllocatedLen;
|
||||
int mLogicalSize;
|
||||
int mReadHead;
|
||||
|
||||
virtual int Read(void* pDest, int count);
|
||||
virtual int Write(const void* pDest, int count); // throw(eArchive)
|
||||
virtual void AllocateMemory(int len); // throw(eArchive)
|
||||
virtual int Read(void* pDest, int count);
|
||||
virtual int Write(const void* pDest, int count); // throw(eArchive)
|
||||
virtual void AllocateMemory(int len); // throw(eArchive)
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -224,30 +231,31 @@ class cFixedMemArchive : public cBidirArchive
|
|||
{
|
||||
public:
|
||||
cFixedMemArchive();
|
||||
cFixedMemArchive( int8* pMem, int32 size );
|
||||
cFixedMemArchive(int8* pMem, int32 size);
|
||||
virtual ~cFixedMemArchive();
|
||||
|
||||
void Attach( int8* pMem, int32 size );
|
||||
// this method associates the archive with pMem and sets the size of the
|
||||
// archive. Unlike cMemoryArchive, this may never grow or shrink in size.
|
||||
void Attach(int8* pMem, int32 size);
|
||||
// this method associates the archive with pMem and sets the size of the
|
||||
// archive. Unlike cMemoryArchive, this may never grow or shrink in size.
|
||||
|
||||
//-----------------------------------
|
||||
// cBidirArchive interface
|
||||
//-----------------------------------
|
||||
virtual void Seek (int64 offset, SeekFrom from) ; // throw(eArchive);
|
||||
virtual int64 CurrentPos () const ;
|
||||
virtual int64 Length () const ;
|
||||
virtual bool EndOfFile();
|
||||
virtual void Seek(int64 offset, SeekFrom from); // throw(eArchive);
|
||||
virtual int64 CurrentPos() const;
|
||||
virtual int64 Length() const;
|
||||
virtual bool EndOfFile();
|
||||
|
||||
protected:
|
||||
//-----------------------------------
|
||||
// cArchive interface
|
||||
//-----------------------------------
|
||||
virtual int Read(void* pDest, int count); // throw(eArchive)
|
||||
virtual int Write(const void* pDest, int count); // throw(eArchive)
|
||||
virtual int Read(void* pDest, int count); // throw(eArchive)
|
||||
virtual int Write(const void* pDest, int count); // throw(eArchive)
|
||||
|
||||
int8* mpMemory;
|
||||
int32 mSize;
|
||||
int32 mReadHead;
|
||||
int8* mpMemory;
|
||||
int32 mSize;
|
||||
int32 mReadHead;
|
||||
};
|
||||
|
||||
class cFileArchive : public cBidirArchive
|
||||
|
@ -258,71 +266,74 @@ public:
|
|||
|
||||
enum OpenFlags
|
||||
{
|
||||
FA_OPEN_TEXT = 0x1,
|
||||
FA_OPEN_TRUNCATE = 0x2,
|
||||
FA_SCANNING = 0x4,
|
||||
FA_DIRECT = 0x8
|
||||
FA_OPEN_TEXT = 0x1,
|
||||
FA_OPEN_TRUNCATE = 0x2,
|
||||
FA_SCANNING = 0x4,
|
||||
FA_DIRECT = 0x8
|
||||
};
|
||||
|
||||
// TODO: Open should throw
|
||||
virtual void OpenRead(const TCHAR* filename, uint32 openFlags = 0 );
|
||||
virtual void OpenReadWrite(const TCHAR* filename, uint32 openFlags = FA_OPEN_TRUNCATE );
|
||||
// opens a file for reading or writing; the file is always created if it doesn't exist,
|
||||
// and is truncated to zero length if truncateFile is set to true;
|
||||
TSTRING GetCurrentFilename(void) const;
|
||||
virtual void Close(void);
|
||||
void Truncate(); // throw(eArchive) // set the length to the current pos
|
||||
virtual void OpenRead(const TCHAR* filename, uint32 openFlags = 0);
|
||||
virtual void OpenReadWrite(const TCHAR* filename, uint32 openFlags = FA_OPEN_TRUNCATE);
|
||||
// opens a file for reading or writing; the file is always created if it doesn't exist,
|
||||
// and is truncated to zero length if truncateFile is set to true;
|
||||
TSTRING GetCurrentFilename(void) const;
|
||||
virtual void Close(void);
|
||||
void Truncate(); // throw(eArchive) // set the length to the current pos
|
||||
|
||||
//-----------------------------------
|
||||
// cBidirArchive interface
|
||||
//-----------------------------------
|
||||
virtual bool EndOfFile();
|
||||
virtual void Seek(int64 offset, SeekFrom from); // throw(eArchive)
|
||||
virtual int64 CurrentPos() const;
|
||||
virtual int64 Length() const;
|
||||
|
||||
|
||||
virtual bool EndOfFile();
|
||||
virtual void Seek(int64 offset, SeekFrom from); // throw(eArchive)
|
||||
virtual int64 CurrentPos() const;
|
||||
virtual int64 Length() const;
|
||||
|
||||
|
||||
protected:
|
||||
int64 mFileSize; //Size of FileArchive
|
||||
int64 mReadHead; //Current position of read/write head
|
||||
int64 mFileSize; //Size of FileArchive
|
||||
int64 mReadHead; //Current position of read/write head
|
||||
//-----------------------------------
|
||||
// cArchive interface
|
||||
//-----------------------------------
|
||||
virtual int Read(void* pDest, int count);
|
||||
virtual int Write(const void* pDest, int count); //throw(eArchive)
|
||||
bool isWritable;
|
||||
cFile mCurrentFile;
|
||||
TSTRING mCurrentFilename; //current file
|
||||
uint32 mOpenFlags;
|
||||
virtual int Read(void* pDest, int count);
|
||||
virtual int Write(const void* pDest, int count); //throw(eArchive)
|
||||
bool isWritable;
|
||||
cFile mCurrentFile;
|
||||
TSTRING mCurrentFilename; //current file
|
||||
uint32 mOpenFlags;
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
// cLockedTemporaryFileArchive -- this class uses as an archive a file
|
||||
// that is not accessable to any other process besides the calling one.
|
||||
// the file will be deleted from the filesystem on Close();
|
||||
//
|
||||
// implemented by using cFileArchive and overwriting open and close
|
||||
//
|
||||
// implemented by using cFileArchive and overwriting open and close
|
||||
// functions
|
||||
//
|
||||
class cLockedTemporaryFileArchive : public cFileArchive
|
||||
{
|
||||
public:
|
||||
virtual void OpenReadWrite ( const TCHAR* filename = NULL, uint32 openFlags = FA_OPEN_TRUNCATE );
|
||||
// creates the file. filename must not exist on the file system.
|
||||
// if filename is NULL, the class will create and use a temporary file.
|
||||
// truncateFile has no meaning
|
||||
virtual void OpenReadWrite(const TCHAR* filename = NULL, uint32 openFlags = FA_OPEN_TRUNCATE);
|
||||
// creates the file. filename must not exist on the file system.
|
||||
// if filename is NULL, the class will create and use a temporary file.
|
||||
// truncateFile has no meaning
|
||||
//virtual void OpenReadWriteThrow ( const TCHAR* filename = NULL, bool truncateFile = true ) throw (eArchive);
|
||||
// this is the same as OpenReadWrite, except an exception is thrown on error (of type
|
||||
// cArchive::ERR_OPEN_FAILED)
|
||||
// this is the same as OpenReadWrite, except an exception is thrown on error (of type
|
||||
// cArchive::ERR_OPEN_FAILED)
|
||||
|
||||
virtual void Close();
|
||||
// close and delete the file
|
||||
virtual void Close();
|
||||
// close and delete the file
|
||||
private:
|
||||
// open for read only makes no sense if we're always creating the file,
|
||||
// open for read only makes no sense if we're always creating the file,
|
||||
// so disallow read only file opens
|
||||
virtual void OpenRead( const TCHAR*, uint32 openFlags = 0 ) { ASSERT( false ); THROW_INTERNAL("archive.h"); }
|
||||
virtual void OpenRead(const TCHAR*, uint32 openFlags = 0)
|
||||
{
|
||||
ASSERT(false);
|
||||
THROW_INTERNAL("archive.h");
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
|
|
@ -3,29 +3,29 @@
|
|||
// Portions created by Tripwire, Inc. are copyright (C) 2000-2018 Tripwire,
|
||||
// Inc. Tripwire is a registered trademark of Tripwire, Inc. All rights
|
||||
// reserved.
|
||||
//
|
||||
//
|
||||
// This program is free software. The contents of this file are subject
|
||||
// to the terms of the GNU General Public License as published by the
|
||||
// Free Software Foundation; either version 2 of the License, or (at your
|
||||
// option) any later version. You may redistribute it and/or modify it
|
||||
// only in compliance with the GNU General Public License.
|
||||
//
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful.
|
||||
// However, this program is distributed AS-IS WITHOUT ANY
|
||||
// WARRANTY; INCLUDING THE IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS
|
||||
// FOR A PARTICULAR PURPOSE. Please see the GNU General Public License
|
||||
// for more details.
|
||||
//
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
|
||||
// USA.
|
||||
//
|
||||
//
|
||||
// Nothing in the GNU General Public License or any other license to use
|
||||
// the code or files shall permit you to use Tripwire's trademarks,
|
||||
// service marks, or other intellectual property without Tripwire's
|
||||
// prior written consent.
|
||||
//
|
||||
//
|
||||
// If you have any questions, please contact Tripwire, Inc. at either
|
||||
// info@tripwire.org or www.tripwire.org.
|
||||
//
|
||||
|
@ -42,48 +42,48 @@
|
|||
#include "ntmbs.h"
|
||||
|
||||
#if IS_ANDROID
|
||||
int mblen(const char *s, size_t n)
|
||||
int mblen(const char* s, size_t n)
|
||||
{
|
||||
return mbtowc(0, s, n);
|
||||
return mbtowc(0, s, n);
|
||||
}
|
||||
#endif
|
||||
|
||||
//
|
||||
//
|
||||
// finds the next whole character in string identified by ['cur'-'end')
|
||||
// identifies beginning of char in 'first', then end of character in 'last'
|
||||
// returns number of TCHARs that make up the next character
|
||||
// if there are no more characters, will return 0 and first = last = end
|
||||
// POSTCONDITIONS:
|
||||
//
|
||||
//
|
||||
// RETURNS:
|
||||
//
|
||||
//
|
||||
// THROWS:
|
||||
//
|
||||
//
|
||||
// COMPLEXITY:
|
||||
//
|
||||
//
|
||||
//
|
||||
|
||||
/* static */
|
||||
bool cCharUtil::PeekNextChar( const TSTRING::const_iterator& cur,
|
||||
const TSTRING::const_iterator& end,
|
||||
TSTRING::const_iterator& first,
|
||||
TSTRING::const_iterator& last )
|
||||
bool cCharUtil::PeekNextChar(const TSTRING::const_iterator& cur,
|
||||
const TSTRING::const_iterator& end,
|
||||
TSTRING::const_iterator& first,
|
||||
TSTRING::const_iterator& last)
|
||||
{
|
||||
//
|
||||
// do we have a valid string here?
|
||||
//
|
||||
if( cur > end )
|
||||
if (cur > end)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if( cur == end )
|
||||
if (cur == end)
|
||||
{
|
||||
first = last = end;
|
||||
return false;
|
||||
}
|
||||
|
||||
if( *cur == _T('\0') )
|
||||
if (*cur == _T('\0'))
|
||||
{
|
||||
first = last = cur;
|
||||
return false;
|
||||
|
@ -93,19 +93,19 @@ bool cCharUtil::PeekNextChar( const TSTRING::const_iterator& cur,
|
|||
|
||||
if (!(*cur))
|
||||
{
|
||||
last = cur;
|
||||
}
|
||||
last = cur;
|
||||
}
|
||||
else
|
||||
{
|
||||
#if !IS_AROS
|
||||
mblen (NULL, 0);
|
||||
int len = mblen(&*cur, MB_CUR_MAX);
|
||||
if (len < 0) //invalid multibyte sequence, but let's not blow up.
|
||||
len = 1;
|
||||
|
||||
last = cur + len;
|
||||
#else // AROS mblen() seems broken (as of 6/2016) so don't use it.
|
||||
last = cur + 1;
|
||||
mblen(NULL, 0);
|
||||
int len = mblen(&*cur, MB_CUR_MAX);
|
||||
if (len < 0) //invalid multibyte sequence, but let's not blow up.
|
||||
len = 1;
|
||||
|
||||
last = cur + len;
|
||||
#else // AROS mblen() seems broken (as of 6/2016) so don't use it.
|
||||
last = cur + 1;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -114,40 +114,38 @@ bool cCharUtil::PeekNextChar( const TSTRING::const_iterator& cur,
|
|||
|
||||
|
||||
//=============================================================================
|
||||
//
|
||||
//
|
||||
// /* static */
|
||||
// bool cCharUtil::PopNextChar( TSTRING::const_iterator& cur,
|
||||
// const TSTRING::const_iterator& end,
|
||||
// TSTRING::const_iterator& first,
|
||||
// bool cCharUtil::PopNextChar( TSTRING::const_iterator& cur,
|
||||
// const TSTRING::const_iterator& end,
|
||||
// TSTRING::const_iterator& first,
|
||||
// TSTRING::const_iterator& last )
|
||||
//-----------------------------------------------------------------------------
|
||||
// REQUIRES:
|
||||
//
|
||||
//
|
||||
// EFFECTS:
|
||||
//
|
||||
//
|
||||
// same as PeekNextChar but increments 'cur' to 'last'
|
||||
//
|
||||
// POSTCONDITIONS:
|
||||
//
|
||||
//
|
||||
// RETURNS:
|
||||
//
|
||||
//
|
||||
// THROWS:
|
||||
//
|
||||
//
|
||||
// COMPLEXITY:
|
||||
//
|
||||
//
|
||||
//
|
||||
|
||||
/* static */
|
||||
bool cCharUtil::PopNextChar( TSTRING::const_iterator& cur,
|
||||
const TSTRING::const_iterator& end,
|
||||
TSTRING::const_iterator& first,
|
||||
TSTRING::const_iterator& last )
|
||||
bool cCharUtil::PopNextChar(TSTRING::const_iterator& cur,
|
||||
const TSTRING::const_iterator& end,
|
||||
TSTRING::const_iterator& first,
|
||||
TSTRING::const_iterator& last)
|
||||
{
|
||||
bool f = PeekNextChar( cur, end, first, last );
|
||||
bool f = PeekNextChar(cur, end, first, last);
|
||||
|
||||
cur = last; // pop causes 'cur' to move to just beyond character ('last')
|
||||
cur = last; // pop causes 'cur' to move to just beyond character ('last')
|
||||
|
||||
return f;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -3,29 +3,29 @@
|
|||
// Portions created by Tripwire, Inc. are copyright (C) 2000-2018 Tripwire,
|
||||
// Inc. Tripwire is a registered trademark of Tripwire, Inc. All rights
|
||||
// reserved.
|
||||
//
|
||||
//
|
||||
// This program is free software. The contents of this file are subject
|
||||
// to the terms of the GNU General Public License as published by the
|
||||
// Free Software Foundation; either version 2 of the License, or (at your
|
||||
// option) any later version. You may redistribute it and/or modify it
|
||||
// only in compliance with the GNU General Public License.
|
||||
//
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful.
|
||||
// However, this program is distributed AS-IS WITHOUT ANY
|
||||
// WARRANTY; INCLUDING THE IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS
|
||||
// FOR A PARTICULAR PURPOSE. Please see the GNU General Public License
|
||||
// for more details.
|
||||
//
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
|
||||
// USA.
|
||||
//
|
||||
//
|
||||
// Nothing in the GNU General Public License or any other license to use
|
||||
// the code or files shall permit you to use Tripwire's trademarks,
|
||||
// service marks, or other intellectual property without Tripwire's
|
||||
// prior written consent.
|
||||
//
|
||||
//
|
||||
// If you have any questions, please contact Tripwire, Inc. at either
|
||||
// info@tripwire.org or www.tripwire.org.
|
||||
//
|
||||
|
@ -44,23 +44,20 @@
|
|||
class cCharUtil
|
||||
{
|
||||
public:
|
||||
|
||||
|
||||
// finds the next whole character in string identified by ['cur'-'end')
|
||||
// identifies beginning of char in 'first', then end of character in 'last'
|
||||
// returns 'are there more characters in string?'
|
||||
// if there are no more characters, will return 0 and first = last = end
|
||||
static bool PeekNextChar( const TSTRING::const_iterator& cur,
|
||||
const TSTRING::const_iterator& end,
|
||||
TSTRING::const_iterator& first,
|
||||
TSTRING::const_iterator& last );
|
||||
|
||||
static bool PeekNextChar(const TSTRING::const_iterator& cur,
|
||||
const TSTRING::const_iterator& end,
|
||||
TSTRING::const_iterator& first,
|
||||
TSTRING::const_iterator& last);
|
||||
|
||||
// same as PeekNextChar but increments 'cur' to 'last'
|
||||
static bool PopNextChar( TSTRING::const_iterator& cur,
|
||||
const TSTRING::const_iterator& end,
|
||||
TSTRING::const_iterator& first,
|
||||
TSTRING::const_iterator& last );
|
||||
static bool PopNextChar(TSTRING::const_iterator& cur,
|
||||
const TSTRING::const_iterator& end,
|
||||
TSTRING::const_iterator& first,
|
||||
TSTRING::const_iterator& last);
|
||||
};
|
||||
|
||||
#endif//__CHARUTIL_H
|
||||
|
||||
#endif //__CHARUTIL_H
|
||||
|
|
|
@ -3,29 +3,29 @@
|
|||
// Portions created by Tripwire, Inc. are copyright (C) 2000-2018 Tripwire,
|
||||
// Inc. Tripwire is a registered trademark of Tripwire, Inc. All rights
|
||||
// reserved.
|
||||
//
|
||||
//
|
||||
// This program is free software. The contents of this file are subject
|
||||
// to the terms of the GNU General Public License as published by the
|
||||
// Free Software Foundation; either version 2 of the License, or (at your
|
||||
// option) any later version. You may redistribute it and/or modify it
|
||||
// only in compliance with the GNU General Public License.
|
||||
//
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful.
|
||||
// However, this program is distributed AS-IS WITHOUT ANY
|
||||
// WARRANTY; INCLUDING THE IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS
|
||||
// FOR A PARTICULAR PURPOSE. Please see the GNU General Public License
|
||||
// for more details.
|
||||
//
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
|
||||
// USA.
|
||||
//
|
||||
//
|
||||
// Nothing in the GNU General Public License or any other license to use
|
||||
// the code or files shall permit you to use Tripwire's trademarks,
|
||||
// service marks, or other intellectual property without Tripwire's
|
||||
// prior written consent.
|
||||
//
|
||||
//
|
||||
// If you have any questions, please contact Tripwire, Inc. at either
|
||||
// info@tripwire.org or www.tripwire.org.
|
||||
//
|
||||
|
@ -38,9 +38,7 @@
|
|||
///////////////////////////////////////////////////////////////////////////////
|
||||
// ctor, dotr
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
cCmdLineParser::cCmdLineParser() :
|
||||
mArgTable(HASH_VERY_SMALL),
|
||||
mLastArgInfo(-1, PARAM_NONE)
|
||||
cCmdLineParser::cCmdLineParser() : mArgTable(HASH_VERY_SMALL), mLastArgInfo(-1, PARAM_NONE)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -51,19 +49,20 @@ cCmdLineParser::~cCmdLineParser()
|
|||
///////////////////////////////////////////////////////////////////////////////
|
||||
// AddArg
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
void cCmdLineParser::AddArg(int argId, const TSTRING& arg, const TSTRING& alias, ParamCount numParams, bool multipleAllowed)
|
||||
void cCmdLineParser::AddArg(
|
||||
int argId, const TSTRING& arg, const TSTRING& alias, ParamCount numParams, bool multipleAllowed)
|
||||
{
|
||||
if(arg.empty() && alias.empty())
|
||||
if (arg.empty() && alias.empty())
|
||||
{
|
||||
// this refers to the list of parameters that comes after all the cmd line switches
|
||||
mLastArgInfo.mId = argId;
|
||||
mLastArgInfo.mNumParams = numParams;
|
||||
return ;
|
||||
return;
|
||||
}
|
||||
|
||||
if(! arg.empty())
|
||||
mArgTable.Insert(arg, cArgInfo(argId, numParams));
|
||||
if(! alias.empty())
|
||||
if (!arg.empty())
|
||||
mArgTable.Insert(arg, cArgInfo(argId, numParams));
|
||||
if (!alias.empty())
|
||||
{
|
||||
// put the alias in the table with a '-' prepended to it so it matches '--'
|
||||
TSTRING str(_T("-"));
|
||||
|
@ -71,8 +70,8 @@ void cCmdLineParser::AddArg(int argId, const TSTRING& arg, const TSTRING& alias,
|
|||
mArgTable.Insert(str, cArgInfo(argId, numParams));
|
||||
}
|
||||
// This argument can appear more than once on the command line.
|
||||
if( multipleAllowed )
|
||||
mMultipleAllowed.insert( argId );
|
||||
if (multipleAllowed)
|
||||
mMultipleAllowed.insert(argId);
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -90,43 +89,39 @@ void cCmdLineParser::AddArg(int argId, const TSTRING& arg, const TSTRING& alias,
|
|||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Parse
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
void cCmdLineParser::Parse(int argc, const TCHAR *const * argv)
|
||||
void cCmdLineParser::Parse(int argc, const TCHAR* const* argv)
|
||||
{
|
||||
// clear out any existing data
|
||||
mArgData.clear();
|
||||
|
||||
const TCHAR* pCurArg = 0;
|
||||
bool bProcessedFinalParams = false; // gets set to true when the parameters to the command line are processed
|
||||
const TCHAR* pCurArg = 0;
|
||||
bool bProcessedFinalParams = false; // gets set to true when the parameters to the command line are processed
|
||||
|
||||
// I assume argv[0] is the executable name...
|
||||
for(int i=1; i < argc; i++)
|
||||
for (int i = 1; i < argc; i++)
|
||||
{
|
||||
if(argv[i][0] == _T('-'))
|
||||
if (argv[i][0] == _T('-'))
|
||||
{
|
||||
pCurArg = argv[i];
|
||||
|
||||
// this is a switch; find it in the table...
|
||||
cArgInfo argInfo;
|
||||
if ( !mArgTable.Lookup( TSTRING(&argv[i][1] ), argInfo ) )
|
||||
if (!mArgTable.Lookup(TSTRING(&argv[i][1]), argInfo))
|
||||
{
|
||||
// unknown switch!
|
||||
throw eCmdLineInvalidArg(
|
||||
TSS_GetString( cCore, core::STR_ERR2_BAD_ARG_PARAMS )
|
||||
+ pCurArg );
|
||||
throw eCmdLineInvalidArg(TSS_GetString(cCore, core::STR_ERR2_BAD_ARG_PARAMS) + pCurArg);
|
||||
}
|
||||
//
|
||||
// make sure this hasn't been specified yet...
|
||||
//
|
||||
if( ArgInList( argInfo.mId ) )
|
||||
if (ArgInList(argInfo.mId))
|
||||
{
|
||||
// Make sure it isn't okay for this one to appear more than once...
|
||||
std::set<int>::iterator it = mMultipleAllowed.find( argInfo.mId );
|
||||
if( it == mMultipleAllowed.end() )
|
||||
std::set<int>::iterator it = mMultipleAllowed.find(argInfo.mId);
|
||||
if (it == mMultipleAllowed.end())
|
||||
{
|
||||
// It wasn't in our list of allowed params, so error.
|
||||
throw eCmdLineMultiArg(
|
||||
TSS_GetString( cCore, core::STR_ERR2_BAD_ARG_PARAMS )
|
||||
+ argv[i] );
|
||||
throw eCmdLineMultiArg(TSS_GetString(cCore, core::STR_ERR2_BAD_ARG_PARAMS) + argv[i]);
|
||||
}
|
||||
}
|
||||
//
|
||||
|
@ -134,24 +129,22 @@ void cCmdLineParser::Parse(int argc, const TCHAR *const * argv)
|
|||
//
|
||||
mArgData.push_back(cArgData(argInfo.mId, TSTRING(argv[i])));
|
||||
cArgData& curArg = mArgData.back();
|
||||
switch( argInfo.mNumParams )
|
||||
switch (argInfo.mNumParams)
|
||||
{
|
||||
case PARAM_NONE:
|
||||
// make sure there are no parameters to this, but be careful because
|
||||
// make sure there are no parameters to this, but be careful because
|
||||
// it is legal to start the parameters to the executable here.
|
||||
if((i+1 < argc) && (argv[i+1][0] != _T('-')))
|
||||
if ((i + 1 < argc) && (argv[i + 1][0] != _T('-')))
|
||||
{
|
||||
// search for any more parameters
|
||||
// TODO: In the future we may want to support a '--' switch that specifies the start
|
||||
// of parameters to the executable.
|
||||
for (int j = i + 2; j < argc; ++j )
|
||||
for (int j = i + 2; j < argc; ++j)
|
||||
{
|
||||
if (argv[j][0] == _T('-'))
|
||||
{
|
||||
// >0 parameter passed !
|
||||
throw eCmdLineBadParam(
|
||||
TSS_GetString( cCore, core::STR_ERR2_BAD_ARG_PARAMS )
|
||||
+ pCurArg );
|
||||
throw eCmdLineBadParam(TSS_GetString(cCore, core::STR_ERR2_BAD_ARG_PARAMS) + pCurArg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -160,29 +153,27 @@ void cCmdLineParser::Parse(int argc, const TCHAR *const * argv)
|
|||
case PARAM_ONE:
|
||||
// get the next parameter...
|
||||
i++;
|
||||
if ( (i >= argc) || (argv[i][0] == _T('-')) )
|
||||
if ((i >= argc) || (argv[i][0] == _T('-')))
|
||||
{
|
||||
// zero parameters passed to something that needed one param
|
||||
throw eCmdLineBadParam(
|
||||
TSS_GetString( cCore, core::STR_ERR2_BAD_ARG_PARAMS )
|
||||
+ pCurArg );
|
||||
throw eCmdLineBadParam(TSS_GetString(cCore, core::STR_ERR2_BAD_ARG_PARAMS) + pCurArg);
|
||||
}
|
||||
|
||||
curArg.mParams.push_back( TSTRING(argv[i]) );
|
||||
curArg.mParams.push_back(TSTRING(argv[i]));
|
||||
break;
|
||||
|
||||
case PARAM_MANY:
|
||||
i++;
|
||||
while((i < argc) && (argv[i][0] != _T('-')))
|
||||
while ((i < argc) && (argv[i][0] != _T('-')))
|
||||
{
|
||||
curArg.mParams.push_back(TSTRING(argv[i]));
|
||||
curArg.mParams.push_back(TSTRING(argv[i]));
|
||||
i++;
|
||||
}
|
||||
i--; // since we have gone too far at this point
|
||||
i--; // since we have gone too far at this point
|
||||
break;
|
||||
|
||||
default:
|
||||
ASSERTMSG( false, "Unknown number of arguments to parser" );
|
||||
ASSERTMSG(false, "Unknown number of arguments to parser");
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@ -191,14 +182,14 @@ void cCmdLineParser::Parse(int argc, const TCHAR *const * argv)
|
|||
// this must be the final "unnamed" arg
|
||||
// first, make sure it is consistent with the current info...
|
||||
bool bResult = true;
|
||||
switch(mLastArgInfo.mNumParams)
|
||||
switch (mLastArgInfo.mNumParams)
|
||||
{
|
||||
case PARAM_NONE:
|
||||
// this is an error; they didn't want any command line parameters...
|
||||
bResult = false;
|
||||
break;
|
||||
case PARAM_ONE:
|
||||
if(i+1 != argc)
|
||||
if (i + 1 != argc)
|
||||
// there is >1 final parameter; it is an error
|
||||
bResult = false;
|
||||
break;
|
||||
|
@ -207,33 +198,28 @@ void cCmdLineParser::Parse(int argc, const TCHAR *const * argv)
|
|||
break;
|
||||
default:
|
||||
ASSERT(false);
|
||||
|
||||
}
|
||||
if(! bResult)
|
||||
if (!bResult)
|
||||
{
|
||||
throw eCmdLineBadParam( );
|
||||
throw eCmdLineBadParam();
|
||||
}
|
||||
|
||||
// ok, we can push the final parameter info onto the list...
|
||||
mArgData.push_back(cArgData(mLastArgInfo.mId));
|
||||
cArgData& curArg = mArgData.back();
|
||||
|
||||
while ( i < argc )
|
||||
|
||||
while (i < argc)
|
||||
{
|
||||
if ( argv[i][0] == _T('-') )
|
||||
if (argv[i][0] == _T('-'))
|
||||
{
|
||||
if ( ! pCurArg )
|
||||
if (!pCurArg)
|
||||
{
|
||||
throw eCmdLineBadSwitchPos(
|
||||
TSS_GetString( cCore, core::STR_ERR2_BAD_ARG_PARAMS )
|
||||
+ argv[i] );
|
||||
throw eCmdLineBadSwitchPos(TSS_GetString(cCore, core::STR_ERR2_BAD_ARG_PARAMS) + argv[i]);
|
||||
}
|
||||
else
|
||||
{
|
||||
// there was an extra parameter passed somewhere!
|
||||
throw eCmdLineBadArgParam(
|
||||
TSS_GetString( cCore, core::STR_ERR2_BAD_ARG_PARAMS )
|
||||
+ pCurArg );
|
||||
throw eCmdLineBadArgParam(TSS_GetString(cCore, core::STR_ERR2_BAD_ARG_PARAMS) + pCurArg);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -241,21 +227,18 @@ void cCmdLineParser::Parse(int argc, const TCHAR *const * argv)
|
|||
curArg.mParams.push_back(TSTRING(argv[i]));
|
||||
i++;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// it is possible not to process the final command line parameters in the "else" case above
|
||||
// (this only occurs if there are no command line parameters specified) so let's make sure that
|
||||
// is consistent with what we are configured with...
|
||||
// NOTE -- it is ok to have no cmd line parameters if they specified PARAM_NONE or PARAM_MANY
|
||||
if(! bProcessedFinalParams)
|
||||
if (!bProcessedFinalParams)
|
||||
{
|
||||
if(mLastArgInfo.mNumParams == PARAM_ONE)
|
||||
if (mLastArgInfo.mNumParams == PARAM_ONE)
|
||||
{
|
||||
throw eCmdLineBadParam( );
|
||||
throw eCmdLineBadParam();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -269,28 +252,24 @@ void cCmdLineParser::Parse(int argc, const TCHAR *const * argv)
|
|||
///////////////////////////////////////////////////////////////////////////////
|
||||
void cCmdLineParser::TestMutEx()
|
||||
{
|
||||
std::list<std::pair<int,int> >::const_iterator i;
|
||||
cCmdLineIter iter1(*this), iter2(*this);
|
||||
for(i = mMutExList.begin(); i != mMutExList.end(); i++)
|
||||
std::list<std::pair<int, int> >::const_iterator i;
|
||||
cCmdLineIter iter1(*this), iter2(*this);
|
||||
for (i = mMutExList.begin(); i != mMutExList.end(); i++)
|
||||
{
|
||||
//TODO -- there is a much more efficent way to do this (using cFCOPropVector, for example)
|
||||
// the command line is presumably small enough, tho, that it probably isn't a big
|
||||
// deal to do it this way.
|
||||
iter1.SeekToArg(i->first);
|
||||
if(! iter1.Done())
|
||||
if (!iter1.Done())
|
||||
{
|
||||
iter2.SeekToArg(i->second);
|
||||
if(! iter2.Done())
|
||||
if (!iter2.Done())
|
||||
{
|
||||
// we have a mutual exclusion violation!
|
||||
throw eCmdLineMutEx(
|
||||
iter1.ActualParam()
|
||||
+ _T(", ")
|
||||
+ iter2.ActualParam() );
|
||||
throw eCmdLineMutEx(iter1.ActualParam() + _T(", ") + iter2.ActualParam());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -298,51 +277,51 @@ void cCmdLineParser::TestMutEx()
|
|||
///////////////////////////////////////////////////////////////////////////////
|
||||
void cCmdLineParser::TestDependency()
|
||||
{
|
||||
std::list< std::pair< std::pair< int, int>, bool > >::const_iterator i;
|
||||
cCmdLineIter iter1(*this), iter2(*this);
|
||||
std::list<std::pair<std::pair<int, int>, bool> >::const_iterator i;
|
||||
cCmdLineIter iter1(*this), iter2(*this);
|
||||
|
||||
for( i = mDependencyList.begin(); i != mDependencyList.end(); ++i)
|
||||
for (i = mDependencyList.begin(); i != mDependencyList.end(); ++i)
|
||||
{
|
||||
iter1.SeekToArg( i->first.first );
|
||||
iter1.SeekToArg(i->first.first);
|
||||
// was it on the command line?
|
||||
if( !iter1.Done() )
|
||||
if (!iter1.Done())
|
||||
{
|
||||
// it was, is the corresponding arg on the command line?
|
||||
iter2.SeekToArg( i->first.second );
|
||||
if( iter2.Done() ) // it wasn't, dependency error
|
||||
iter2.SeekToArg(i->first.second);
|
||||
if (iter2.Done()) // it wasn't, dependency error
|
||||
{
|
||||
TSTRING arg1, arg2, alias1, alias2;
|
||||
cCmdLineParser::LookupArgInfo( i->first.first, arg1, alias1 );
|
||||
cCmdLineParser::LookupArgInfo( i->first.second, arg2, alias2 );
|
||||
cCmdLineParser::LookupArgInfo(i->first.first, arg1, alias1);
|
||||
cCmdLineParser::LookupArgInfo(i->first.second, arg2, alias2);
|
||||
|
||||
// determine in which form the user passed the arguments,
|
||||
// and construct the error message in the same form
|
||||
if ( iter1.ActualParam().length() == 2 )
|
||||
throw eCmdLineDependency( _T("The switch -") + arg1 + _T(" requires -") + arg2 +_T(".") );
|
||||
if (iter1.ActualParam().length() == 2)
|
||||
throw eCmdLineDependency(_T("The switch -") + arg1 + _T(" requires -") + arg2 + _T("."));
|
||||
else
|
||||
throw eCmdLineDependency( _T("The switch --") + alias1 + _T(" requires --") + alias2 + _T(".") );
|
||||
throw eCmdLineDependency(_T("The switch --") + alias1 + _T(" requires --") + alias2 + _T("."));
|
||||
}
|
||||
}
|
||||
else if( i->second )
|
||||
else if (i->second)
|
||||
// only make this second check if the dependencies are MUTUAL,
|
||||
// as indicated (or not) by the bool value.
|
||||
{
|
||||
iter2.SeekToArg( i->first.second );
|
||||
// the first arg in the pair was not on the command line,
|
||||
// so just make sure the second isn't there...
|
||||
if( !iter2.Done() )
|
||||
iter2.SeekToArg(i->first.second);
|
||||
// the first arg in the pair was not on the command line,
|
||||
// so just make sure the second isn't there...
|
||||
if (!iter2.Done())
|
||||
{
|
||||
// arg2 appeared without arg1, so dependency error.
|
||||
TSTRING arg1, arg2, alias1, alias2;
|
||||
cCmdLineParser::LookupArgInfo( i->first.first, arg1, alias1 );
|
||||
cCmdLineParser::LookupArgInfo( i->first.second, arg2, alias2 );
|
||||
cCmdLineParser::LookupArgInfo(i->first.first, arg1, alias1);
|
||||
cCmdLineParser::LookupArgInfo(i->first.second, arg2, alias2);
|
||||
|
||||
// determine in which form the user passed the arguments,
|
||||
// and construct the error message in the same form
|
||||
if ( iter1.ActualParam().length() == 2 )
|
||||
throw eCmdLineDependency( _T("The switch -") + arg2 + _T(" requires -") + arg1 +_T(".") );
|
||||
if (iter1.ActualParam().length() == 2)
|
||||
throw eCmdLineDependency(_T("The switch -") + arg2 + _T(" requires -") + arg1 + _T("."));
|
||||
else
|
||||
throw eCmdLineDependency( _T("The switch --") + alias2 + _T(" requires --") + alias1 + _T(".") );
|
||||
throw eCmdLineDependency(_T("The switch --") + alias2 + _T(" requires --") + alias1 + _T("."));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -364,32 +343,32 @@ void cCmdLineParser::AddMutEx(int argId1, int argId2)
|
|||
///////////////////////////////////////////////////////////////////////////////
|
||||
// AddDependency
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
void cCmdLineParser::AddDependency(int argId1, int argId2, bool mutual )
|
||||
void cCmdLineParser::AddDependency(int argId1, int argId2, bool mutual)
|
||||
{
|
||||
// again, no checking for duplicates... would a set
|
||||
// prove to be a better container for this operation?
|
||||
std::pair< int, int > Args( argId1, argId2 );
|
||||
std::pair< std::pair< int, int >, bool > Dep( Args, mutual );
|
||||
std::pair<int, int> Args(argId1, argId2);
|
||||
std::pair<std::pair<int, int>, bool> Dep(Args, mutual);
|
||||
|
||||
ASSERT(argId1 != argId2);
|
||||
mDependencyList.push_back( Dep);
|
||||
mDependencyList.push_back(Dep);
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// TraceContents
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
#ifdef DEBUG
|
||||
void cCmdLineParser::TraceContents(int dl)
|
||||
void cCmdLineParser::TraceContents(int dl)
|
||||
{
|
||||
cDebug d("cCmdLineParser::TraceContents");
|
||||
if(dl == -1)
|
||||
if (dl == -1)
|
||||
dl = cDebug::D_DEBUG;
|
||||
|
||||
std::list<cArgData>::const_iterator i;
|
||||
for(i = mArgData.begin(); i != mArgData.end(); i++)
|
||||
for (i = mArgData.begin(); i != mArgData.end(); i++)
|
||||
{
|
||||
d.Trace(dl, "* Item id:%d\n", i->mId);
|
||||
for(std::vector<TSTRING>::const_iterator vi = i->mParams.begin(); vi != i->mParams.end(); vi++)
|
||||
for (std::vector<TSTRING>::const_iterator vi = i->mParams.begin(); vi != i->mParams.end(); vi++)
|
||||
{
|
||||
d.Trace(dl, "\t%s\n", vi->c_str());
|
||||
}
|
||||
|
@ -398,7 +377,7 @@ void cCmdLineParser::TraceContents(int dl)
|
|||
d.Trace(dl, "--- Switch id table ---\n");
|
||||
|
||||
cHashTableIter<TSTRING, cArgInfo> iter(mArgTable);
|
||||
for(iter.SeekBegin(); ! iter.Done(); iter.Next())
|
||||
for (iter.SeekBegin(); !iter.Done(); iter.Next())
|
||||
{
|
||||
d.Trace(dl, "[%d] %s\n", iter.Val().mId, iter.Key().c_str());
|
||||
}
|
||||
|
@ -412,16 +391,16 @@ void cCmdLineParser::TraceContents(int dl)
|
|||
///////////////////////////////////////////////////////////////////////////////
|
||||
bool cCmdLineParser::LookupArgInfo(int argId, TSTRING& arg, TSTRING& alias) const
|
||||
{
|
||||
arg = _T("");
|
||||
alias = _T("");
|
||||
arg = _T("");
|
||||
alias = _T("");
|
||||
|
||||
cHashTableIter<TSTRING, cArgInfo> iter(mArgTable);
|
||||
for(iter.SeekBegin(); ! iter.Done(); iter.Next())
|
||||
for (iter.SeekBegin(); !iter.Done(); iter.Next())
|
||||
{
|
||||
if(iter.Val().mId == argId)
|
||||
if (iter.Val().mId == argId)
|
||||
{
|
||||
TSTRING str = iter.Key();
|
||||
if((str.length() > 0) && (str[0] == _T('-')))
|
||||
if ((str.length() > 0) && (str[0] == _T('-')))
|
||||
{
|
||||
// this is the alias!
|
||||
alias = (str.c_str() + 1);
|
||||
|
@ -433,7 +412,7 @@ bool cCmdLineParser::LookupArgInfo(int argId, TSTRING& arg, TSTRING& alias) cons
|
|||
}
|
||||
}
|
||||
}
|
||||
return ((! arg.empty()) || (! alias.empty()));
|
||||
return ((!arg.empty()) || (!alias.empty()));
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -442,9 +421,9 @@ bool cCmdLineParser::LookupArgInfo(int argId, TSTRING& arg, TSTRING& alias) cons
|
|||
bool cCmdLineParser::ArgInList(int argId)
|
||||
{
|
||||
std::list<cArgData>::iterator i;
|
||||
for( i = mArgData.begin(); i != mArgData.end(); i++ )
|
||||
for (i = mArgData.begin(); i != mArgData.end(); i++)
|
||||
{
|
||||
if( i->mId == argId )
|
||||
if (i->mId == argId)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
@ -458,15 +437,13 @@ bool cCmdLineParser::ArgInList(int argId)
|
|||
///////////////////////////////////////////////////////////////////////////////
|
||||
// SeekToArg
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
bool cCmdLineIter::SeekToArg(int argId) const
|
||||
bool cCmdLineIter::SeekToArg(int argId) const
|
||||
{
|
||||
for(SeekBegin(); ! Done(); Next())
|
||||
for (SeekBegin(); !Done(); Next())
|
||||
{
|
||||
if(ArgId() == argId)
|
||||
if (ArgId() == argId)
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -3,36 +3,36 @@
|
|||
// Portions created by Tripwire, Inc. are copyright (C) 2000-2018 Tripwire,
|
||||
// Inc. Tripwire is a registered trademark of Tripwire, Inc. All rights
|
||||
// reserved.
|
||||
//
|
||||
//
|
||||
// This program is free software. The contents of this file are subject
|
||||
// to the terms of the GNU General Public License as published by the
|
||||
// Free Software Foundation; either version 2 of the License, or (at your
|
||||
// option) any later version. You may redistribute it and/or modify it
|
||||
// only in compliance with the GNU General Public License.
|
||||
//
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful.
|
||||
// However, this program is distributed AS-IS WITHOUT ANY
|
||||
// WARRANTY; INCLUDING THE IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS
|
||||
// FOR A PARTICULAR PURPOSE. Please see the GNU General Public License
|
||||
// for more details.
|
||||
//
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
|
||||
// USA.
|
||||
//
|
||||
//
|
||||
// Nothing in the GNU General Public License or any other license to use
|
||||
// the code or files shall permit you to use Tripwire's trademarks,
|
||||
// service marks, or other intellectual property without Tripwire's
|
||||
// prior written consent.
|
||||
//
|
||||
//
|
||||
// If you have any questions, please contact Tripwire, Inc. at either
|
||||
// info@tripwire.org or www.tripwire.org.
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// cmdlineparser.h
|
||||
//
|
||||
// cCmdLineParser.h -- class that tokenizes the command line
|
||||
// cCmdLineParser.h -- class that tokenizes the command line
|
||||
#ifndef __CMDLINEPARSER_H
|
||||
#define __CMDLINEPARSER_H
|
||||
|
||||
|
@ -49,14 +49,15 @@
|
|||
//=============================================================================
|
||||
// eCmdLine
|
||||
//=============================================================================
|
||||
TSS_EXCEPTION( eCmdLine, eError )
|
||||
TSS_EXCEPTION( eCmdLineInvalidArg, eCmdLine ) // an arg on the command line is not recognized
|
||||
TSS_EXCEPTION( eCmdLineBadArgParam, eCmdLine ) // wrong number of parameters to an argument
|
||||
TSS_EXCEPTION( eCmdLineBadParam, eCmdLine ) // wrong number of paramters to the executable (not associated with any arguments)
|
||||
TSS_EXCEPTION( eCmdLineBadSwitchPos,eCmdLine ) // a '-' arg appeared after the final parameter list
|
||||
TSS_EXCEPTION( eCmdLineMutEx, eCmdLine ) // a mutual exclusion error has occured
|
||||
TSS_EXCEPTION( eCmdLineDependency, eCmdLine ) // a dependency error has occurred.
|
||||
TSS_EXCEPTION( eCmdLineMultiArg, eCmdLine ) // an arg was found twice in the command line
|
||||
TSS_EXCEPTION(eCmdLine, eError)
|
||||
TSS_EXCEPTION(eCmdLineInvalidArg, eCmdLine) // an arg on the command line is not recognized
|
||||
TSS_EXCEPTION(eCmdLineBadArgParam, eCmdLine) // wrong number of parameters to an argument
|
||||
TSS_EXCEPTION(eCmdLineBadParam,
|
||||
eCmdLine) // wrong number of paramters to the executable (not associated with any arguments)
|
||||
TSS_EXCEPTION(eCmdLineBadSwitchPos, eCmdLine) // a '-' arg appeared after the final parameter list
|
||||
TSS_EXCEPTION(eCmdLineMutEx, eCmdLine) // a mutual exclusion error has occured
|
||||
TSS_EXCEPTION(eCmdLineDependency, eCmdLine) // a dependency error has occurred.
|
||||
TSS_EXCEPTION(eCmdLineMultiArg, eCmdLine) // an arg was found twice in the command line
|
||||
|
||||
|
||||
/*
|
||||
|
@ -95,93 +96,99 @@ public:
|
|||
|
||||
enum ParamCount
|
||||
{
|
||||
PARAM_NONE, // no parameters to arg
|
||||
PARAM_ONE, // one parameter to arg
|
||||
PARAM_MANY, // zero or more paramters to arg
|
||||
PARAM_NONE, // no parameters to arg
|
||||
PARAM_ONE, // one parameter to arg
|
||||
PARAM_MANY, // zero or more paramters to arg
|
||||
|
||||
PARAM_INVALID // top of enum
|
||||
PARAM_INVALID // top of enum
|
||||
};
|
||||
|
||||
void AddArg(int argId, const TSTRING& arg, const TSTRING& alias, ParamCount numParams, bool multipleAllowed = false);
|
||||
// this method should be called for each argument that can appear on the
|
||||
// command line.
|
||||
// argId -- a number that uniquely identifies the argument; no two arguments
|
||||
// may have the same id (ASSERT-enforced)
|
||||
// arg -- string that comes after the '-'. can be _T("") if there is only
|
||||
// a string representation
|
||||
// alias -- string that comes after '--' which has the same meaning. Can be _T("")
|
||||
// if there is no alias. If both arg and alias are empty strings, then this arg
|
||||
// represents the list of arguments that comes at the end of the command line
|
||||
// numParams -- number of parameters that this argument needs
|
||||
void
|
||||
AddArg(int argId, const TSTRING& arg, const TSTRING& alias, ParamCount numParams, bool multipleAllowed = false);
|
||||
// this method should be called for each argument that can appear on the
|
||||
// command line.
|
||||
// argId -- a number that uniquely identifies the argument; no two arguments
|
||||
// may have the same id (ASSERT-enforced)
|
||||
// arg -- string that comes after the '-'. can be _T("") if there is only
|
||||
// a string representation
|
||||
// alias -- string that comes after '--' which has the same meaning. Can be _T("")
|
||||
// if there is no alias. If both arg and alias are empty strings, then this arg
|
||||
// represents the list of arguments that comes at the end of the command line
|
||||
// numParams -- number of parameters that this argument needs
|
||||
|
||||
void AddMutEx(int argId1, int argId2);
|
||||
// this adds a mutual exclusion constraint. When Parse() is called, if argId1 and
|
||||
// argId2 both exist on the command line, then the parse will fail and the error
|
||||
// value ERR_MUTUAL_EXCLUSION will be set.
|
||||
// this adds a mutual exclusion constraint. When Parse() is called, if argId1 and
|
||||
// argId2 both exist on the command line, then the parse will fail and the error
|
||||
// value ERR_MUTUAL_EXCLUSION will be set.
|
||||
|
||||
void AddDependency(int argId1, int argId2, bool mutual = false );
|
||||
// This adds a dependency constraint. When Parse() is called, if argId1
|
||||
// exists on the command line independent from argId2, then the parse will fail.
|
||||
// If the default param mutual is true, then the command parser will check for
|
||||
// argId1 if argId2 is passed. We do this, since it is possible for one arg to
|
||||
// depend on another, but have the other arg alone on the command line, legally.
|
||||
void AddDependency(int argId1, int argId2, bool mutual = false);
|
||||
// This adds a dependency constraint. When Parse() is called, if argId1
|
||||
// exists on the command line independent from argId2, then the parse will fail.
|
||||
// If the default param mutual is true, then the command parser will check for
|
||||
// argId1 if argId2 is passed. We do this, since it is possible for one arg to
|
||||
// depend on another, but have the other arg alone on the command line, legally.
|
||||
|
||||
void Parse(int argc, const TCHAR *const * argv); // throw eCmdLine
|
||||
void Parse(int argc, const TCHAR* const* argv); // throw eCmdLine
|
||||
// after AddArg() has been called for every argument that could be processed by the
|
||||
// command line, call this to tokenize argv. If the return value is false, then
|
||||
// command line, call this to tokenize argv. If the return value is false, then
|
||||
// the input was invalid in some way; the actual error can be determined by calling
|
||||
// GetErrorInfo() below.
|
||||
|
||||
// void Clear();
|
||||
// clear out all information that this class contains
|
||||
// void Clear();
|
||||
// clear out all information that this class contains
|
||||
|
||||
bool LookupArgInfo(int argId, TSTRING& arg, TSTRING& alias) const;
|
||||
// given an argId, fill out the strings with the argument and alias strings. Returns false
|
||||
// if the argId cannot be found. This method is not very fast, so don't use it often.
|
||||
// given an argId, fill out the strings with the argument and alias strings. Returns false
|
||||
// if the argId cannot be found. This method is not very fast, so don't use it often.
|
||||
|
||||
#ifdef DEBUG
|
||||
void TraceContents(int dl = -1) ;
|
||||
#endif
|
||||
#ifdef DEBUG
|
||||
void TraceContents(int dl = -1);
|
||||
#endif
|
||||
private:
|
||||
void TestMutEx();
|
||||
// tests for mutual exclusion violations; if it fails, the current error is set and false
|
||||
// is returned.
|
||||
// tests for mutual exclusion violations; if it fails, the current error is set and false
|
||||
// is returned.
|
||||
void TestDependency();
|
||||
// tests for all dependency violations.
|
||||
// tests for all dependency violations.
|
||||
bool ArgInList(int argId);
|
||||
// returns true if an argument with the specified id already exists in the list; this is used
|
||||
// to make sure the same arg doesn't appear >1 time on the command line
|
||||
// returns true if an argument with the specified id already exists in the list; this is used
|
||||
// to make sure the same arg doesn't appear >1 time on the command line
|
||||
|
||||
// for storing information on paramers
|
||||
struct cArgInfo
|
||||
{
|
||||
int mId;
|
||||
ParamCount mNumParams;
|
||||
int mId;
|
||||
ParamCount mNumParams;
|
||||
|
||||
cArgInfo(int i = -1, ParamCount p = PARAM_INVALID) : mId(i), mNumParams(p) {}
|
||||
cArgInfo(int i = -1, ParamCount p = PARAM_INVALID) : mId(i), mNumParams(p)
|
||||
{
|
||||
}
|
||||
};
|
||||
// for storing parsed argv information
|
||||
struct cArgData
|
||||
{
|
||||
int mId;
|
||||
std::vector<TSTRING> mParams;
|
||||
TSTRING mActualParam; // a string representation of what was actually on the command line
|
||||
int mId;
|
||||
std::vector<TSTRING> mParams;
|
||||
TSTRING mActualParam; // a string representation of what was actually on the command line
|
||||
|
||||
cArgData(int id = -1, const TSTRING& actualParam = TSTRING(_T(""))) : mId(id), mActualParam(actualParam) {}
|
||||
cArgData(int id = -1, const TSTRING& actualParam = TSTRING(_T(""))) : mId(id), mActualParam(actualParam)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
cHashTable<TSTRING, cArgInfo> mArgTable;
|
||||
cArgInfo mLastArgInfo; // info on the argument that comes at the end of the command line (with no associated '-x' or '--x')
|
||||
std::list<cArgData> mArgData;
|
||||
std::list<std::pair<int,int> > mMutExList; // all of the mutual exclusions
|
||||
std::list< std::pair < std::pair<int,int>, bool > > mDependencyList; // all of the dependencies
|
||||
std::set< int > mMultipleAllowed;
|
||||
cHashTable<TSTRING, cArgInfo> mArgTable;
|
||||
cArgInfo
|
||||
mLastArgInfo; // info on the argument that comes at the end of the command line (with no associated '-x' or '--x')
|
||||
std::list<cArgData> mArgData;
|
||||
std::list<std::pair<int, int> > mMutExList; // all of the mutual exclusions
|
||||
std::list<std::pair<std::pair<int, int>, bool> > mDependencyList; // all of the dependencies
|
||||
std::set<int> mMultipleAllowed;
|
||||
|
||||
friend class cCmdLineIter;
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// cCmdLineIter -- used to iterate over the tokenized command line parameters;
|
||||
// cCmdLineIter -- used to iterate over the tokenized command line parameters;
|
||||
// is only useful after cCmdLineParser::Parse() has been called.
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
class cCmdLineIter
|
||||
|
@ -190,36 +197,35 @@ public:
|
|||
cCmdLineIter(const cCmdLineParser& parser);
|
||||
|
||||
// iteration
|
||||
void SeekBegin() const;
|
||||
bool Done() const;
|
||||
bool IsEmpty() const;
|
||||
void Next() const;
|
||||
void SeekBegin() const;
|
||||
bool Done() const;
|
||||
bool IsEmpty() const;
|
||||
void Next() const;
|
||||
|
||||
bool SeekToArg(int argId) const;
|
||||
// seeks to the argument with the given argId. returns
|
||||
// false and Done() == true if it couldn't find it.
|
||||
bool SeekToArg(int argId) const;
|
||||
// seeks to the argument with the given argId. returns
|
||||
// false and Done() == true if it couldn't find it.
|
||||
|
||||
// access to the argument data
|
||||
int ArgId() const;
|
||||
// returns the id of this arg; ASSERTs if Done() == true
|
||||
int NumParams() const;
|
||||
// returns the number of parameters this argument has
|
||||
const TSTRING& ActualParam() const;
|
||||
// returns exactly what was passed on the command line (ie -- what the user typed)
|
||||
const TSTRING& ParamAt(int index) const;
|
||||
// returns the parameter at the specified index. ASSERTs if
|
||||
// the index is out of range.
|
||||
int ArgId() const;
|
||||
// returns the id of this arg; ASSERTs if Done() == true
|
||||
int NumParams() const;
|
||||
// returns the number of parameters this argument has
|
||||
const TSTRING& ActualParam() const;
|
||||
// returns exactly what was passed on the command line (ie -- what the user typed)
|
||||
const TSTRING& ParamAt(int index) const;
|
||||
// returns the parameter at the specified index. ASSERTs if
|
||||
// the index is out of range.
|
||||
|
||||
private:
|
||||
const std::list<cCmdLineParser::cArgData>& mList;
|
||||
const std::list<cCmdLineParser::cArgData>& mList;
|
||||
mutable std::list<cCmdLineParser::cArgData>::const_iterator mIter;
|
||||
};
|
||||
|
||||
//#############################################################################
|
||||
// inline implementation
|
||||
//#############################################################################
|
||||
inline cCmdLineIter::cCmdLineIter(const cCmdLineParser& parser) :
|
||||
mList(parser.mArgData)
|
||||
inline cCmdLineIter::cCmdLineIter(const cCmdLineParser& parser) : mList(parser.mArgData)
|
||||
{
|
||||
SeekBegin();
|
||||
}
|
||||
|
@ -241,22 +247,22 @@ inline void cCmdLineIter::Next() const
|
|||
}
|
||||
inline int cCmdLineIter::ArgId() const
|
||||
{
|
||||
ASSERT(! Done());
|
||||
ASSERT(!Done());
|
||||
return mIter->mId;
|
||||
}
|
||||
inline int cCmdLineIter::NumParams() const
|
||||
{
|
||||
ASSERT(! Done());
|
||||
ASSERT(!Done());
|
||||
return mIter->mParams.size();
|
||||
}
|
||||
|
||||
inline const TSTRING& cCmdLineIter::ActualParam() const
|
||||
inline const TSTRING& cCmdLineIter::ActualParam() const
|
||||
{
|
||||
ASSERT(! Done());
|
||||
ASSERT(!Done());
|
||||
return mIter->mActualParam;
|
||||
}
|
||||
|
||||
inline const TSTRING& cCmdLineIter::ParamAt(int index) const
|
||||
inline const TSTRING& cCmdLineIter::ParamAt(int index) const
|
||||
{
|
||||
ASSERT((index >= 0) && (index < NumParams()));
|
||||
return mIter->mParams[index];
|
||||
|
@ -264,4 +270,3 @@ inline const TSTRING& cCmdLineIter::ParamAt(int index) const
|
|||
|
||||
|
||||
#endif
|
||||
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -3,29 +3,29 @@
|
|||
// Portions created by Tripwire, Inc. are copyright (C) 2000-2018 Tripwire,
|
||||
// Inc. Tripwire is a registered trademark of Tripwire, Inc. All rights
|
||||
// reserved.
|
||||
//
|
||||
//
|
||||
// This program is free software. The contents of this file are subject
|
||||
// to the terms of the GNU General Public License as published by the
|
||||
// Free Software Foundation; either version 2 of the License, or (at your
|
||||
// option) any later version. You may redistribute it and/or modify it
|
||||
// only in compliance with the GNU General Public License.
|
||||
//
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful.
|
||||
// However, this program is distributed AS-IS WITHOUT ANY
|
||||
// WARRANTY; INCLUDING THE IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS
|
||||
// FOR A PARTICULAR PURPOSE. Please see the GNU General Public License
|
||||
// for more details.
|
||||
//
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
|
||||
// USA.
|
||||
//
|
||||
//
|
||||
// Nothing in the GNU General Public License or any other license to use
|
||||
// the code or files shall permit you to use Tripwire's trademarks,
|
||||
// service marks, or other intellectual property without Tripwire's
|
||||
// prior written consent.
|
||||
//
|
||||
//
|
||||
// If you have any questions, please contact Tripwire, Inc. at either
|
||||
// info@tripwire.org or www.tripwire.org.
|
||||
//
|
||||
|
@ -60,17 +60,17 @@
|
|||
|
||||
/// Requirements
|
||||
|
||||
#include "platform.h" // for: Platform specific code
|
||||
#include "ntmbs.h" // for: NTBS, NTMBS, NTWCS, and NTDBS types
|
||||
#include "platform.h" // for: Platform specific code
|
||||
#include "ntmbs.h" // for: NTBS, NTMBS, NTWCS, and NTDBS types
|
||||
|
||||
|
||||
/// Exceptions
|
||||
|
||||
TSS_EXCEPTION( eConverter, eError );
|
||||
TSS_EXCEPTION( eConverterReset, eConverter );
|
||||
TSS_EXCEPTION( eConverterFatal, eConverter );
|
||||
TSS_EXCEPTION( eConverterUnsupportedConversion, eConverter );
|
||||
TSS_EXCEPTION( eConverterUnknownCodepage, eConverter );
|
||||
TSS_EXCEPTION(eConverter, eError);
|
||||
TSS_EXCEPTION(eConverterReset, eConverter);
|
||||
TSS_EXCEPTION(eConverterFatal, eConverter);
|
||||
TSS_EXCEPTION(eConverterUnsupportedConversion, eConverter);
|
||||
TSS_EXCEPTION(eConverterUnknownCodepage, eConverter);
|
||||
|
||||
|
||||
/// Classes
|
||||
|
@ -90,45 +90,38 @@ TSS_EXCEPTION( eConverterUnknownCodepage, eConverter );
|
|||
*/
|
||||
class iCodeConverter
|
||||
{
|
||||
public:
|
||||
|
||||
static iCodeConverter* GetInstance(); // Singleton
|
||||
static void Finit();
|
||||
public:
|
||||
static iCodeConverter* GetInstance(); // Singleton
|
||||
static void Finit();
|
||||
|
||||
|
||||
/// Subclass Responsibilities
|
||||
virtual int Convert(ntmbs_t, // NTMBS buffer
|
||||
size_t, // Capacity in mbchar_t's (bytes)
|
||||
const_ntdbs_t, // null terminated two-byte wide character (UCS2 rep)
|
||||
size_t nCount) = 0; // Amount to convert in dbchar_t's
|
||||
// returns number of buffer items converted, -1 on error
|
||||
|
||||
/// Subclass Responsibilities
|
||||
virtual
|
||||
int
|
||||
Convert(
|
||||
ntmbs_t, // NTMBS buffer
|
||||
size_t, // Capacity in mbchar_t's (bytes)
|
||||
const_ntdbs_t, // null terminated two-byte wide character (UCS2 rep)
|
||||
size_t nCount ) = 0; // Amount to convert in dbchar_t's
|
||||
// returns number of buffer items converted, -1 on error
|
||||
|
||||
|
||||
virtual
|
||||
int
|
||||
Convert(
|
||||
ntdbs_t, // NTDBS (Null-terminated two byte sequence) buf
|
||||
size_t, // Capacity in dbchar_t's
|
||||
const_ntmbs_t, // Null-terminated multi-byte sequence
|
||||
size_t ) = 0; // Capacity in mbchar_t's (bytes)
|
||||
// returns number of buffer items converted, -1 on error
|
||||
virtual int Convert(ntdbs_t, // NTDBS (Null-terminated two byte sequence) buf
|
||||
size_t, // Capacity in dbchar_t's
|
||||
const_ntmbs_t, // Null-terminated multi-byte sequence
|
||||
size_t) = 0; // Capacity in mbchar_t's (bytes)
|
||||
// returns number of buffer items converted, -1 on error
|
||||
|
||||
protected:
|
||||
protected:
|
||||
iCodeConverter()
|
||||
{
|
||||
}
|
||||
virtual ~iCodeConverter()
|
||||
{
|
||||
}
|
||||
|
||||
iCodeConverter() {}
|
||||
virtual ~iCodeConverter() {}
|
||||
|
||||
private:
|
||||
|
||||
static iCodeConverter* CreateConverter();
|
||||
static iCodeConverter* CreateGoodEnoughConverter();
|
||||
|
||||
static iCodeConverter* m_pInst;
|
||||
private:
|
||||
static iCodeConverter* CreateConverter();
|
||||
static iCodeConverter* CreateGoodEnoughConverter();
|
||||
|
||||
static iCodeConverter* m_pInst;
|
||||
};
|
||||
|
||||
|
||||
|
@ -139,74 +132,70 @@ class iCodeConverter
|
|||
#ifdef HAVE_ICONV_H
|
||||
#include <iconv.h>
|
||||
|
||||
#ifdef HAVE_LANGINFO_H
|
||||
#ifndef __USE_XOPEN
|
||||
#define __USE_XOPEN 1
|
||||
#endif
|
||||
#include <langinfo.h>
|
||||
#endif
|
||||
# ifdef HAVE_LANGINFO_H
|
||||
# ifndef __USE_XOPEN
|
||||
# define __USE_XOPEN 1
|
||||
# endif
|
||||
# include <langinfo.h>
|
||||
# endif
|
||||
|
||||
class cIconvUtil
|
||||
{
|
||||
public:
|
||||
|
||||
static const char* GetCodePageID(); // gets code page id for current locale, throws if error
|
||||
static bool GetCodePageID( const char** ppCP );
|
||||
static const char* GetIconvDbIdentifier();
|
||||
static const char* GetMiddleIdentifier();
|
||||
static void ResetConverter( iconv_t );
|
||||
static bool TestConverter( const char* pTo, const char* pFrom );
|
||||
static iconv_t OpenHandle( const char* pTo, const char* pFrom ); // throws
|
||||
static void CloseHandle( iconv_t ic );
|
||||
public:
|
||||
static const char* GetCodePageID(); // gets code page id for current locale, throws if error
|
||||
static bool GetCodePageID(const char** ppCP);
|
||||
static const char* GetIconvDbIdentifier();
|
||||
static const char* GetMiddleIdentifier();
|
||||
static void ResetConverter(iconv_t);
|
||||
static bool TestConverter(const char* pTo, const char* pFrom);
|
||||
static iconv_t OpenHandle(const char* pTo, const char* pFrom); // throws
|
||||
static void CloseHandle(iconv_t ic);
|
||||
};
|
||||
|
||||
|
||||
class cIconvConverter : public iCodeConverter
|
||||
{
|
||||
public:
|
||||
public:
|
||||
static bool Test(); // is there a conversion for the current codepage?
|
||||
|
||||
static bool Test(); // is there a conversion for the current codepage?
|
||||
virtual int Convert(ntmbs_t, size_t, const_ntdbs_t, size_t);
|
||||
virtual int Convert(ntdbs_t, size_t, const_ntmbs_t, size_t);
|
||||
|
||||
virtual int Convert( ntmbs_t, size_t, const_ntdbs_t, size_t );
|
||||
virtual int Convert( ntdbs_t, size_t, const_ntmbs_t, size_t );
|
||||
cIconvConverter();
|
||||
virtual ~cIconvConverter();
|
||||
|
||||
cIconvConverter();
|
||||
virtual ~cIconvConverter();
|
||||
private:
|
||||
void Init();
|
||||
|
||||
private:
|
||||
void Init();
|
||||
|
||||
iconv_t icToDb;
|
||||
iconv_t icFromDb;
|
||||
iconv_t icToDb;
|
||||
iconv_t icFromDb;
|
||||
};
|
||||
|
||||
class cDoubleIconvConverter : public iCodeConverter
|
||||
{
|
||||
public:
|
||||
public:
|
||||
static bool Test(); // is there a conversion for the current codepage?
|
||||
|
||||
static bool Test(); // is there a conversion for the current codepage?
|
||||
virtual int Convert(ntmbs_t, size_t, const_ntdbs_t, size_t);
|
||||
virtual int Convert(ntdbs_t, size_t, const_ntmbs_t, size_t);
|
||||
|
||||
virtual int Convert( ntmbs_t, size_t, const_ntdbs_t, size_t );
|
||||
virtual int Convert( ntdbs_t, size_t, const_ntmbs_t, size_t );
|
||||
cDoubleIconvConverter();
|
||||
virtual ~cDoubleIconvConverter();
|
||||
|
||||
cDoubleIconvConverter();
|
||||
virtual ~cDoubleIconvConverter();
|
||||
private:
|
||||
void Init();
|
||||
|
||||
private:
|
||||
iconv_t icMbToUTF8;
|
||||
iconv_t icUTF8ToDb;
|
||||
|
||||
void Init();
|
||||
|
||||
iconv_t icMbToUTF8;
|
||||
iconv_t icUTF8ToDb;
|
||||
|
||||
iconv_t icDbToUTF8;
|
||||
iconv_t icUTF8ToMb;
|
||||
iconv_t icDbToUTF8;
|
||||
iconv_t icUTF8ToMb;
|
||||
};
|
||||
|
||||
#endif // HAVE_ICONV_H
|
||||
|
||||
|
||||
/// QUESTION:RAD -- Why not just have one platform-specific of the below
|
||||
/// QUESTION:RAD -- Why not just have one platform-specific of the below
|
||||
|
||||
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
// cWcharIs32BitUcs2Converterer
|
||||
|
@ -214,16 +203,18 @@ class cDoubleIconvConverter : public iCodeConverter
|
|||
|
||||
#if WCHAR_IS_32_BITS
|
||||
|
||||
// TODO:BAM -- this is not really correct! Convert will not honor nSource!!
|
||||
// TODO:BAM -- this is not really correct! Convert will not honor nSource!!
|
||||
// it looks for the first null char!
|
||||
|
||||
class cWcharIs32BitUcs2Converterer : public iCodeConverter
|
||||
{
|
||||
public:
|
||||
virtual int Convert( ntmbs_t, size_t, const_ntdbs_t, size_t );
|
||||
virtual int Convert( ntdbs_t, size_t, const_ntmbs_t, size_t );
|
||||
|
||||
virtual ~cWcharIs32BitUcs2Converterer() {}
|
||||
public:
|
||||
virtual int Convert(ntmbs_t, size_t, const_ntdbs_t, size_t);
|
||||
virtual int Convert(ntdbs_t, size_t, const_ntmbs_t, size_t);
|
||||
|
||||
virtual ~cWcharIs32BitUcs2Converterer()
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
#endif // WCHAR_IS_32_BITS
|
||||
|
@ -234,16 +225,18 @@ public:
|
|||
|
||||
#if WCHAR_IS_16_BITS
|
||||
|
||||
// TODO:BAM -- this is not really correct! Convert will not honor nSource!!
|
||||
// TODO:BAM -- this is not really correct! Convert will not honor nSource!!
|
||||
// it looks for the first null char!
|
||||
|
||||
class cWcharIs16BitUcs2Converterer : public iCodeConverter
|
||||
{
|
||||
public:
|
||||
virtual int Convert( ntmbs_t, size_t, const_ntdbs_t, size_t );
|
||||
virtual int Convert( ntdbs_t, size_t, const_ntmbs_t, size_t );
|
||||
|
||||
virtual ~cWcharIs16BitUcs2Converterer() {}
|
||||
public:
|
||||
virtual int Convert(ntmbs_t, size_t, const_ntdbs_t, size_t);
|
||||
virtual int Convert(ntdbs_t, size_t, const_ntmbs_t, size_t);
|
||||
|
||||
virtual ~cWcharIs16BitUcs2Converterer()
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
#endif // WCHAR_IS_16_BITS
|
||||
|
@ -252,31 +245,33 @@ public:
|
|||
// converts mbchars > 0x7F to our reserved space
|
||||
class cGoodEnoughConverterer : public iCodeConverter
|
||||
{
|
||||
public:
|
||||
virtual int Convert( ntmbs_t, size_t, const_ntdbs_t, size_t );
|
||||
virtual int Convert( ntdbs_t, size_t, const_ntmbs_t, size_t );
|
||||
|
||||
virtual ~cGoodEnoughConverterer() {}
|
||||
public:
|
||||
virtual int Convert(ntmbs_t, size_t, const_ntdbs_t, size_t);
|
||||
virtual int Convert(ntdbs_t, size_t, const_ntmbs_t, size_t);
|
||||
|
||||
virtual ~cGoodEnoughConverterer()
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
class cConvertUtil
|
||||
{
|
||||
enum
|
||||
{
|
||||
enum
|
||||
{
|
||||
TSS_UCS2_RESERVED_START = 0xE800u, // E000-E8FF is private use range, but
|
||||
TSS_UCS2_RESERVED_END = 0xE8FFu, // SJIS and EUC use E000-E757
|
||||
TSS_HIGH_ASCII_START = 0x0080u,
|
||||
TSS_HIGH_ASCII_END = 0x00FFu
|
||||
};
|
||||
public:
|
||||
static dbchar_t ConvertNonChar( mbchar_t ch );
|
||||
static mbchar_t ConvertNonChar( dbchar_t ch );
|
||||
|
||||
static bool ValueInReservedRange( mbchar_t ch );
|
||||
static bool ValueInReservedRange( dbchar_t ch );
|
||||
public:
|
||||
static dbchar_t ConvertNonChar(mbchar_t ch);
|
||||
static mbchar_t ConvertNonChar(dbchar_t ch);
|
||||
|
||||
static bool ValueInReservedRange(mbchar_t ch);
|
||||
static bool ValueInReservedRange(dbchar_t ch);
|
||||
};
|
||||
|
||||
|
||||
#endif //__CODECONVERT_H
|
||||
|
||||
|
|
|
@ -3,29 +3,29 @@
|
|||
// Portions created by Tripwire, Inc. are copyright (C) 2000-2018 Tripwire,
|
||||
// Inc. Tripwire is a registered trademark of Tripwire, Inc. All rights
|
||||
// reserved.
|
||||
//
|
||||
//
|
||||
// This program is free software. The contents of this file are subject
|
||||
// to the terms of the GNU General Public License as published by the
|
||||
// Free Software Foundation; either version 2 of the License, or (at your
|
||||
// option) any later version. You may redistribute it and/or modify it
|
||||
// only in compliance with the GNU General Public License.
|
||||
//
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful.
|
||||
// However, this program is distributed AS-IS WITHOUT ANY
|
||||
// WARRANTY; INCLUDING THE IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS
|
||||
// FOR A PARTICULAR PURPOSE. Please see the GNU General Public License
|
||||
// for more details.
|
||||
//
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
|
||||
// USA.
|
||||
//
|
||||
//
|
||||
// Nothing in the GNU General Public License or any other license to use
|
||||
// the code or files shall permit you to use Tripwire's trademarks,
|
||||
// service marks, or other intellectual property without Tripwire's
|
||||
// prior written consent.
|
||||
//
|
||||
//
|
||||
// If you have any questions, please contact Tripwire, Inc. at either
|
||||
// info@tripwire.org or www.tripwire.org.
|
||||
//
|
||||
|
@ -39,21 +39,21 @@
|
|||
#include "core.h"
|
||||
#include "coreerrors.h"
|
||||
|
||||
#include "codeconvert.h" // for: iCodeConverter::GetInstance
|
||||
#include "twlocale.h" // for: cTWLocale::InitGlobalLocale
|
||||
#include "codeconvert.h" // for: iCodeConverter::GetInstance
|
||||
#include "twlocale.h" // for: cTWLocale::InitGlobalLocale
|
||||
|
||||
TSS_ImplementPackage( cCore )
|
||||
TSS_ImplementPackage(cCore)
|
||||
|
||||
cCore::cCore()
|
||||
{
|
||||
TSS_REGISTER_PKG_ERRORS( core );
|
||||
TSS_REGISTER_PKG_ERRORS(core);
|
||||
|
||||
// NOTE: Initialize code converter when cCore is a dependency
|
||||
// of another package (created on first call to GetInstance(),
|
||||
// forcing creation here to hasten the display of any errors)
|
||||
|
||||
cDebug::SetDebugLevel( cDebug::D_DEBUG );
|
||||
cDebug::AddOutTarget( cDebug::OUT_STDOUT );
|
||||
cDebug::SetDebugLevel(cDebug::D_DEBUG);
|
||||
cDebug::AddOutTarget(cDebug::OUT_STDOUT);
|
||||
|
||||
cTWLocale::InitGlobalLocale();
|
||||
|
||||
|
@ -64,4 +64,3 @@ cCore::~cCore()
|
|||
{
|
||||
iCodeConverter::Finit();
|
||||
}
|
||||
|
||||
|
|
|
@ -3,29 +3,29 @@
|
|||
// Portions created by Tripwire, Inc. are copyright (C) 2000-2018 Tripwire,
|
||||
// Inc. Tripwire is a registered trademark of Tripwire, Inc. All rights
|
||||
// reserved.
|
||||
//
|
||||
//
|
||||
// This program is free software. The contents of this file are subject
|
||||
// to the terms of the GNU General Public License as published by the
|
||||
// Free Software Foundation; either version 2 of the License, or (at your
|
||||
// option) any later version. You may redistribute it and/or modify it
|
||||
// only in compliance with the GNU General Public License.
|
||||
//
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful.
|
||||
// However, this program is distributed AS-IS WITHOUT ANY
|
||||
// WARRANTY; INCLUDING THE IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS
|
||||
// FOR A PARTICULAR PURPOSE. Please see the GNU General Public License
|
||||
// for more details.
|
||||
//
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
|
||||
// USA.
|
||||
//
|
||||
//
|
||||
// Nothing in the GNU General Public License or any other license to use
|
||||
// the code or files shall permit you to use Tripwire's trademarks,
|
||||
// service marks, or other intellectual property without Tripwire's
|
||||
// prior written consent.
|
||||
//
|
||||
//
|
||||
// If you have any questions, please contact Tripwire, Inc. at either
|
||||
// info@tripwire.org or www.tripwire.org.
|
||||
//
|
||||
|
@ -43,20 +43,18 @@
|
|||
|
||||
//--Requirements
|
||||
|
||||
#include "package.h" // for: Packaging Abstraction
|
||||
#include "package.h" // for: Packaging Abstraction
|
||||
|
||||
//--Classes
|
||||
|
||||
TSS_BeginPackage( cCore )
|
||||
TSS_BeginPackage(cCore)
|
||||
|
||||
TSS_DECLARE_STRINGTABLE;
|
||||
|
||||
public:
|
||||
public:
|
||||
cCore();
|
||||
~cCore();
|
||||
|
||||
cCore();
|
||||
~cCore();
|
||||
|
||||
TSS_EndPackage( cCore )
|
||||
TSS_EndPackage(cCore)
|
||||
|
||||
#endif //__CORE_H
|
||||
|
||||
|
|
|
@ -3,29 +3,29 @@
|
|||
// Portions created by Tripwire, Inc. are copyright (C) 2000-2018 Tripwire,
|
||||
// Inc. Tripwire is a registered trademark of Tripwire, Inc. All rights
|
||||
// reserved.
|
||||
//
|
||||
//
|
||||
// This program is free software. The contents of this file are subject
|
||||
// to the terms of the GNU General Public License as published by the
|
||||
// Free Software Foundation; either version 2 of the License, or (at your
|
||||
// option) any later version. You may redistribute it and/or modify it
|
||||
// only in compliance with the GNU General Public License.
|
||||
//
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful.
|
||||
// However, this program is distributed AS-IS WITHOUT ANY
|
||||
// WARRANTY; INCLUDING THE IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS
|
||||
// FOR A PARTICULAR PURPOSE. Please see the GNU General Public License
|
||||
// for more details.
|
||||
//
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
|
||||
// USA.
|
||||
//
|
||||
//
|
||||
// Nothing in the GNU General Public License or any other license to use
|
||||
// the code or files shall permit you to use Tripwire's trademarks,
|
||||
// service marks, or other intellectual property without Tripwire's
|
||||
// prior written consent.
|
||||
//
|
||||
//
|
||||
// If you have any questions, please contact Tripwire, Inc. at either
|
||||
// info@tripwire.org or www.tripwire.org.
|
||||
//
|
||||
|
@ -49,118 +49,118 @@
|
|||
#include "ntmbs.h"
|
||||
#include "displayencoder.h"
|
||||
|
||||
TSS_BEGIN_ERROR_REGISTRATION( core )
|
||||
TSS_BEGIN_ERROR_REGISTRATION(core)
|
||||
|
||||
/// Internal
|
||||
|
||||
TSS_REGISTER_ERROR( eInternal(), _T("Internal error.") )
|
||||
TSS_REGISTER_ERROR(eInternal(), _T("Internal error."))
|
||||
|
||||
|
||||
/// General
|
||||
|
||||
TSS_REGISTER_ERROR( eErrorGeneral(), _T("General Error") );
|
||||
TSS_REGISTER_ERROR( eOpen(), _T("File could not be opened.") );
|
||||
TSS_REGISTER_ERROR( eOpenRead(), _T("File could not be opened for reading.") );
|
||||
TSS_REGISTER_ERROR( eOpenWrite(), _T("File could not be opened for writing.") );
|
||||
TSS_REGISTER_ERROR( eBadModeSwitch(), _T("Unknown mode specified.") );
|
||||
TSS_REGISTER_ERROR( eBadCmdLine(), _T("Command line error.") );
|
||||
TSS_REGISTER_ERROR(eErrorGeneral(), _T("General Error"));
|
||||
TSS_REGISTER_ERROR(eOpen(), _T("File could not be opened."));
|
||||
TSS_REGISTER_ERROR(eOpenRead(), _T("File could not be opened for reading."));
|
||||
TSS_REGISTER_ERROR(eOpenWrite(), _T("File could not be opened for writing."));
|
||||
TSS_REGISTER_ERROR(eBadModeSwitch(), _T("Unknown mode specified."));
|
||||
TSS_REGISTER_ERROR(eBadCmdLine(), _T("Command line error."));
|
||||
|
||||
|
||||
/// Archive
|
||||
/// Archive
|
||||
|
||||
TSS_REGISTER_ERROR( eArchive(), _T("Archive error.") )
|
||||
TSS_REGISTER_ERROR( eArchiveOpen(), _T("File could not be opened.") )
|
||||
TSS_REGISTER_ERROR( eArchiveWrite(), _T("File could not be written.") )
|
||||
TSS_REGISTER_ERROR( eArchiveRead(), _T("File could not be read.") )
|
||||
TSS_REGISTER_ERROR( eArchiveEOF(), _T("End of file reached.") )
|
||||
TSS_REGISTER_ERROR( eArchiveSeek(), _T("File seek failed.") )
|
||||
TSS_REGISTER_ERROR( eArchiveMemmap(), _T("Memory mapped archive file invalid.") )
|
||||
TSS_REGISTER_ERROR( eArchiveOutOfMem(), _T("Archive ran out of memory.") )
|
||||
TSS_REGISTER_ERROR( eArchiveInvalidOp(),_T("Archive logic error.") )
|
||||
TSS_REGISTER_ERROR( eArchiveFormat(), _T("Archive file format invalid.") )
|
||||
TSS_REGISTER_ERROR( eArchiveNotRegularFile(), _T("File is not a regular file.") )
|
||||
TSS_REGISTER_ERROR( eArchiveCrypto(), _T("File could not be decrypted.") )
|
||||
TSS_REGISTER_ERROR( eArchiveStringTooLong(), _T("String was too long.") )
|
||||
TSS_REGISTER_ERROR(eArchive(), _T("Archive error."))
|
||||
TSS_REGISTER_ERROR(eArchiveOpen(), _T("File could not be opened."))
|
||||
TSS_REGISTER_ERROR(eArchiveWrite(), _T("File could not be written."))
|
||||
TSS_REGISTER_ERROR(eArchiveRead(), _T("File could not be read."))
|
||||
TSS_REGISTER_ERROR(eArchiveEOF(), _T("End of file reached."))
|
||||
TSS_REGISTER_ERROR(eArchiveSeek(), _T("File seek failed."))
|
||||
TSS_REGISTER_ERROR(eArchiveMemmap(), _T("Memory mapped archive file invalid."))
|
||||
TSS_REGISTER_ERROR(eArchiveOutOfMem(), _T("Archive ran out of memory."))
|
||||
TSS_REGISTER_ERROR(eArchiveInvalidOp(), _T("Archive logic error."))
|
||||
TSS_REGISTER_ERROR(eArchiveFormat(), _T("Archive file format invalid."))
|
||||
TSS_REGISTER_ERROR(eArchiveNotRegularFile(), _T("File is not a regular file."))
|
||||
TSS_REGISTER_ERROR(eArchiveCrypto(), _T("File could not be decrypted."))
|
||||
TSS_REGISTER_ERROR(eArchiveStringTooLong(), _T("String was too long."))
|
||||
|
||||
|
||||
/// File
|
||||
|
||||
TSS_REGISTER_ERROR( eFile(), _T("File error.") )
|
||||
TSS_REGISTER_ERROR( eFileOpen(), _T("File could not be opened.") )
|
||||
TSS_REGISTER_ERROR( eFileWrite(), _T("File could not be written.") )
|
||||
TSS_REGISTER_ERROR( eFileRead(), _T("File could not be read.") )
|
||||
TSS_REGISTER_ERROR( eFileEOF(), _T("End of file reached.") )
|
||||
TSS_REGISTER_ERROR( eFileSeek(), _T("File seek failed.") )
|
||||
TSS_REGISTER_ERROR( eFileInvalidOp(), _T("File logic error.") )
|
||||
TSS_REGISTER_ERROR( eFileTrunc(), _T("File could not be truncated.") )
|
||||
TSS_REGISTER_ERROR( eFileClose(), _T("File could not be closed.") )
|
||||
TSS_REGISTER_ERROR( eFileFlush(), _T("File could not be flushed.") )
|
||||
TSS_REGISTER_ERROR( eFileRewind(), _T("File could not be rewound.") )
|
||||
TSS_REGISTER_ERROR(eFile(), _T("File error."))
|
||||
TSS_REGISTER_ERROR(eFileOpen(), _T("File could not be opened."))
|
||||
TSS_REGISTER_ERROR(eFileWrite(), _T("File could not be written."))
|
||||
TSS_REGISTER_ERROR(eFileRead(), _T("File could not be read."))
|
||||
TSS_REGISTER_ERROR(eFileEOF(), _T("End of file reached."))
|
||||
TSS_REGISTER_ERROR(eFileSeek(), _T("File seek failed."))
|
||||
TSS_REGISTER_ERROR(eFileInvalidOp(), _T("File logic error."))
|
||||
TSS_REGISTER_ERROR(eFileTrunc(), _T("File could not be truncated."))
|
||||
TSS_REGISTER_ERROR(eFileClose(), _T("File could not be closed."))
|
||||
TSS_REGISTER_ERROR(eFileFlush(), _T("File could not be flushed."))
|
||||
TSS_REGISTER_ERROR(eFileRewind(), _T("File could not be rewound."))
|
||||
|
||||
|
||||
/// General API failures
|
||||
TSS_REGISTER_ERROR(eUnix(), _T("Unix API failure.") )
|
||||
TSS_REGISTER_ERROR(eUnix(), _T("Unix API failure."))
|
||||
|
||||
|
||||
/// FSServices
|
||||
|
||||
TSS_REGISTER_ERROR( eFSServices(), _T("File system error.") )
|
||||
TSS_REGISTER_ERROR( eFSServicesGeneric(),_T("File system error.") )
|
||||
TSS_REGISTER_ERROR(eFSServices(), _T("File system error."))
|
||||
TSS_REGISTER_ERROR(eFSServicesGeneric(), _T("File system error."))
|
||||
|
||||
|
||||
/// Serializer
|
||||
|
||||
TSS_REGISTER_ERROR( eSerializerUnknownType(), _T("Unknown type encountered in file.\nFile format may not be valid for this platform.") )
|
||||
TSS_REGISTER_ERROR( eSerializerInputStreamFmt(), _T("Invalid input stream format.") )
|
||||
TSS_REGISTER_ERROR( eSerializerOutputStreamFmt(), _T("Invalid output stream format.") )
|
||||
TSS_REGISTER_ERROR( eSerializerInputStremTypeArray(), _T("A bad index was encountered in file.") )
|
||||
TSS_REGISTER_ERROR( eSerializerArchive(), _T("File read encountered an archive error.") )
|
||||
TSS_REGISTER_ERROR( eSerializerVersionMismatch(), _T("File version mismatch.") )
|
||||
TSS_REGISTER_ERROR( eSerializerEncryption(), _T("File encryption error.") )
|
||||
TSS_REGISTER_ERROR( eSerializer(), _T("File format error.") )
|
||||
TSS_REGISTER_ERROR(eSerializerUnknownType(),
|
||||
_T("Unknown type encountered in file.\nFile format may not be valid for this platform."))
|
||||
TSS_REGISTER_ERROR(eSerializerInputStreamFmt(), _T("Invalid input stream format."))
|
||||
TSS_REGISTER_ERROR(eSerializerOutputStreamFmt(), _T("Invalid output stream format."))
|
||||
TSS_REGISTER_ERROR(eSerializerInputStremTypeArray(), _T("A bad index was encountered in file."))
|
||||
TSS_REGISTER_ERROR(eSerializerArchive(), _T("File read encountered an archive error."))
|
||||
TSS_REGISTER_ERROR(eSerializerVersionMismatch(), _T("File version mismatch."))
|
||||
TSS_REGISTER_ERROR(eSerializerEncryption(), _T("File encryption error."))
|
||||
TSS_REGISTER_ERROR(eSerializer(), _T("File format error."))
|
||||
|
||||
|
||||
/// Command Line
|
||||
|
||||
TSS_REGISTER_ERROR( eCmdLine(), _T("Command line parsing error.") )
|
||||
TSS_REGISTER_ERROR( eCmdLineInvalidArg(), _T("Invalid argument passed on command line.") )
|
||||
TSS_REGISTER_ERROR( eCmdLineBadArgParam(), _T("Incorrect number of parameters to a command line argument.") )
|
||||
TSS_REGISTER_ERROR( eCmdLineBadParam(), _T("Incorrect number of parameters on command line.") )
|
||||
TSS_REGISTER_ERROR( eCmdLineBadSwitchPos(), _T("Switch appears after final command line parameter.") )
|
||||
TSS_REGISTER_ERROR( eCmdLineMutEx(), _T("Specified command line switches are mutually exclusive.") )
|
||||
TSS_REGISTER_ERROR( eCmdLineDependency(), _T("Command line parameter missing.") )
|
||||
TSS_REGISTER_ERROR( eCmdLineMultiArg(), _T("Command line argument specified more than once.") )
|
||||
TSS_REGISTER_ERROR(eCmdLine(), _T("Command line parsing error."))
|
||||
TSS_REGISTER_ERROR(eCmdLineInvalidArg(), _T("Invalid argument passed on command line."))
|
||||
TSS_REGISTER_ERROR(eCmdLineBadArgParam(), _T("Incorrect number of parameters to a command line argument."))
|
||||
TSS_REGISTER_ERROR(eCmdLineBadParam(), _T("Incorrect number of parameters on command line."))
|
||||
TSS_REGISTER_ERROR(eCmdLineBadSwitchPos(), _T("Switch appears after final command line parameter."))
|
||||
TSS_REGISTER_ERROR(eCmdLineMutEx(), _T("Specified command line switches are mutually exclusive."))
|
||||
TSS_REGISTER_ERROR(eCmdLineDependency(), _T("Command line parameter missing."))
|
||||
TSS_REGISTER_ERROR(eCmdLineMultiArg(), _T("Command line argument specified more than once."))
|
||||
|
||||
|
||||
/// TWLocale
|
||||
|
||||
TSS_REGISTER_ERROR( eTWLocale(), _T("Localization error.") )
|
||||
TSS_REGISTER_ERROR( eTWLocaleBadNumFormat(),_T("Bad number format.") )
|
||||
TSS_REGISTER_ERROR(eTWLocale(), _T("Localization error."))
|
||||
TSS_REGISTER_ERROR(eTWLocaleBadNumFormat(), _T("Bad number format."))
|
||||
|
||||
|
||||
/// Character Handling (defined in ntmbs.h)
|
||||
|
||||
TSS_REGISTER_ERROR( eCharacter(), _T("General Character Handling Error.") )
|
||||
TSS_REGISTER_ERROR( eCharacterEncoding(), _T("Character Encoding Error.") )
|
||||
TSS_REGISTER_ERROR(eCharacter(), _T("General Character Handling Error."))
|
||||
TSS_REGISTER_ERROR(eCharacterEncoding(), _T("Character Encoding Error."))
|
||||
|
||||
|
||||
/// Character Conversion Handling (defined in <codeconvert.h>)
|
||||
|
||||
TSS_REGISTER_ERROR( eConverter(), _T("General conversion error.") )
|
||||
TSS_REGISTER_ERROR( eConverterReset(), _T("Converter handle could not be reset.") )
|
||||
TSS_REGISTER_ERROR( eConverterFatal(), _T("Catastrophic conversion error.") )
|
||||
TSS_REGISTER_ERROR( eConverterUnsupportedConversion(), _T("Unsupported character conversion.") )
|
||||
TSS_REGISTER_ERROR( eConverterUnknownCodepage(), _T("Could not identify code page.") )
|
||||
TSS_REGISTER_ERROR(eConverter(), _T("General conversion error."))
|
||||
TSS_REGISTER_ERROR(eConverterReset(), _T("Converter handle could not be reset."))
|
||||
TSS_REGISTER_ERROR(eConverterFatal(), _T("Catastrophic conversion error."))
|
||||
TSS_REGISTER_ERROR(eConverterUnsupportedConversion(), _T("Unsupported character conversion."))
|
||||
TSS_REGISTER_ERROR(eConverterUnknownCodepage(), _T("Could not identify code page."))
|
||||
|
||||
//
|
||||
// Display Encoder
|
||||
//
|
||||
|
||||
TSS_REGISTER_ERROR( eEncoder(), _T("Display encoder error.") )
|
||||
TSS_REGISTER_ERROR( eBadDecoderInput(), _T("Bad input to display encoder.") )
|
||||
TSS_REGISTER_ERROR( eBadHexConversion(), _T("Bad hex conversion in display encoder.") )
|
||||
TSS_REGISTER_ERROR( eUnknownEscapeEncoding(), _T("Unknown encoding in display encoder input.") )
|
||||
TSS_REGISTER_ERROR(eEncoder(), _T("Display encoder error."))
|
||||
TSS_REGISTER_ERROR(eBadDecoderInput(), _T("Bad input to display encoder."))
|
||||
TSS_REGISTER_ERROR(eBadHexConversion(), _T("Bad hex conversion in display encoder."))
|
||||
TSS_REGISTER_ERROR(eUnknownEscapeEncoding(), _T("Unknown encoding in display encoder input."))
|
||||
|
||||
|
||||
TSS_END_ERROR_REGISTRATION()
|
||||
|
||||
|
|
|
@ -3,29 +3,29 @@
|
|||
// Portions created by Tripwire, Inc. are copyright (C) 2000-2018 Tripwire,
|
||||
// Inc. Tripwire is a registered trademark of Tripwire, Inc. All rights
|
||||
// reserved.
|
||||
//
|
||||
//
|
||||
// This program is free software. The contents of this file are subject
|
||||
// to the terms of the GNU General Public License as published by the
|
||||
// Free Software Foundation; either version 2 of the License, or (at your
|
||||
// option) any later version. You may redistribute it and/or modify it
|
||||
// only in compliance with the GNU General Public License.
|
||||
//
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful.
|
||||
// However, this program is distributed AS-IS WITHOUT ANY
|
||||
// WARRANTY; INCLUDING THE IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS
|
||||
// FOR A PARTICULAR PURPOSE. Please see the GNU General Public License
|
||||
// for more details.
|
||||
//
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
|
||||
// USA.
|
||||
//
|
||||
//
|
||||
// Nothing in the GNU General Public License or any other license to use
|
||||
// the code or files shall permit you to use Tripwire's trademarks,
|
||||
// service marks, or other intellectual property without Tripwire's
|
||||
// prior written consent.
|
||||
//
|
||||
//
|
||||
// If you have any questions, please contact Tripwire, Inc. at either
|
||||
// info@tripwire.org or www.tripwire.org.
|
||||
//
|
||||
|
@ -41,8 +41,7 @@
|
|||
|
||||
#include "core/errortable.h"
|
||||
|
||||
TSS_DECLARE_ERROR_REGISTRATION( core )
|
||||
|
||||
TSS_DECLARE_ERROR_REGISTRATION(core)
|
||||
|
||||
#endif//__COREERRORS_H
|
||||
|
||||
#endif //__COREERRORS_H
|
||||
|
|
|
@ -3,29 +3,29 @@
|
|||
// Portions created by Tripwire, Inc. are copyright (C) 2000-2018 Tripwire,
|
||||
// Inc. Tripwire is a registered trademark of Tripwire, Inc. All rights
|
||||
// reserved.
|
||||
//
|
||||
//
|
||||
// This program is free software. The contents of this file are subject
|
||||
// to the terms of the GNU General Public License as published by the
|
||||
// Free Software Foundation; either version 2 of the License, or (at your
|
||||
// option) any later version. You may redistribute it and/or modify it
|
||||
// only in compliance with the GNU General Public License.
|
||||
//
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful.
|
||||
// However, this program is distributed AS-IS WITHOUT ANY
|
||||
// WARRANTY; INCLUDING THE IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS
|
||||
// FOR A PARTICULAR PURPOSE. Please see the GNU General Public License
|
||||
// for more details.
|
||||
//
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
|
||||
// USA.
|
||||
//
|
||||
//
|
||||
// Nothing in the GNU General Public License or any other license to use
|
||||
// the code or files shall permit you to use Tripwire's trademarks,
|
||||
// service marks, or other intellectual property without Tripwire's
|
||||
// prior written consent.
|
||||
//
|
||||
//
|
||||
// If you have any questions, please contact Tripwire, Inc. at either
|
||||
// info@tripwire.org or www.tripwire.org.
|
||||
//
|
||||
|
@ -35,39 +35,35 @@
|
|||
// Creator.: Robert DiFalco (rdifalco)
|
||||
//
|
||||
|
||||
#include "stdcore.h" // for: pch (required by all core source modules)
|
||||
#include "corestrings.h" // for: cCore and core::STR_IDS
|
||||
#include "stdcore.h" // for: pch (required by all core source modules)
|
||||
#include "corestrings.h" // for: cCore and core::STR_IDS
|
||||
|
||||
|
||||
TSS_BeginStringtable( cCore )
|
||||
TSS_BeginStringtable(cCore)
|
||||
|
||||
TSS_StringEntry( core::STR_ERR2_ARCH_CRYPTO_ERR, _T("File could not be decrypted.") ),
|
||||
TSS_StringEntry( core::STR_ERR2_BAD_ARG_PARAMS, _T("Argument: ") ),
|
||||
TSS_StringEntry( core::STR_ERROR_ERROR, _T("### Error") ),
|
||||
TSS_StringEntry( core::STR_ERROR_WARNING, _T("### Warning") ),
|
||||
TSS_StringEntry( core::STR_ERROR_COLON, _T(":") ),
|
||||
TSS_StringEntry( core::STR_ERROR_HEADER, _T("### ") ),
|
||||
TSS_StringEntry( core::STR_ERROR_EXITING, _T("Exiting...") ),
|
||||
TSS_StringEntry( core::STR_ERROR_CONTINUING, _T("Continuing...") ),
|
||||
TSS_StringEntry( core::STR_ERR2_FILENAME, _T("Filename: ") ),
|
||||
TSS_StringEntry( core::STR_ERROR_FILENAME, _T("Filename: ") ),
|
||||
TSS_StringEntry( core::STR_UNKNOWN, _T("Unknown") ),
|
||||
TSS_StringEntry( core::STR_NUMBER_TOO_BIG, _T("Number too big") ),
|
||||
TSS_StringEntry( core::STR_SIGNAL, _T("Software interrupt forced exit:") ),
|
||||
TSS_StringEntry( core::STR_NEWLINE, _T("\n") ),
|
||||
TSS_StringEntry( core::STR_MEMARCHIVE_FILENAME, _T("Error occured in internal memory file") ),
|
||||
TSS_StringEntry( core::STR_MEMARCHIVE_ERRSTR, _T("") ),
|
||||
TSS_StringEntry( core::STR_ENDOFTIME, _T("Tripwire is not designed to run past the year 2038.\nNow exiting...") ),
|
||||
TSS_StringEntry( core::STR_UNKNOWN_TIME, _T("Unknown time") ),
|
||||
TSS_StringEntry( core::STR_BAD_TEMPDIRECTORY, _T("Solution: Check existence/permissions for directory specified by TEMPDIRECTORY in config file") ),
|
||||
TSS_StringEntry(core::STR_ERR2_ARCH_CRYPTO_ERR, _T("File could not be decrypted.")),
|
||||
TSS_StringEntry(core::STR_ERR2_BAD_ARG_PARAMS, _T("Argument: ")),
|
||||
TSS_StringEntry(core::STR_ERROR_ERROR, _T("### Error")),
|
||||
TSS_StringEntry(core::STR_ERROR_WARNING, _T("### Warning")), TSS_StringEntry(core::STR_ERROR_COLON, _T(":")),
|
||||
TSS_StringEntry(core::STR_ERROR_HEADER, _T("### ")), TSS_StringEntry(core::STR_ERROR_EXITING, _T("Exiting...")),
|
||||
TSS_StringEntry(core::STR_ERROR_CONTINUING, _T("Continuing...")),
|
||||
TSS_StringEntry(core::STR_ERR2_FILENAME, _T("Filename: ")),
|
||||
TSS_StringEntry(core::STR_ERROR_FILENAME, _T("Filename: ")), TSS_StringEntry(core::STR_UNKNOWN, _T("Unknown")),
|
||||
TSS_StringEntry(core::STR_NUMBER_TOO_BIG, _T("Number too big")),
|
||||
TSS_StringEntry(core::STR_SIGNAL, _T("Software interrupt forced exit:")),
|
||||
TSS_StringEntry(core::STR_NEWLINE, _T("\n")),
|
||||
TSS_StringEntry(core::STR_MEMARCHIVE_FILENAME, _T("Error occured in internal memory file")),
|
||||
TSS_StringEntry(core::STR_MEMARCHIVE_ERRSTR, _T("")),
|
||||
TSS_StringEntry(core::STR_ENDOFTIME, _T("Tripwire is not designed to run past the year 2038.\nNow exiting...")),
|
||||
TSS_StringEntry(core::STR_UNKNOWN_TIME, _T("Unknown time")),
|
||||
TSS_StringEntry(
|
||||
core::STR_BAD_TEMPDIRECTORY,
|
||||
_T("Solution: Check existence/permissions for directory specified by TEMPDIRECTORY in config file")),
|
||||
/// Particularly useful for eCharacter and eCharacterEncoding
|
||||
|
||||
TSS_StringEntry( core::STR_ERR_ISNULL, _T("Argument cannot be null.") ),
|
||||
TSS_StringEntry( core::STR_ERR_OVERFLOW, _T("An overflow has been detected.") ),
|
||||
TSS_StringEntry( core::STR_ERR_UNDERFLOW, _T("An underflow has been detected.") ),
|
||||
TSS_StringEntry( core::STR_ERR_BADCHAR, _T("Input contained an invalid character.") )
|
||||
|
||||
TSS_EndStringtable( cCore )
|
||||
|
||||
|
||||
TSS_StringEntry(core::STR_ERR_ISNULL, _T("Argument cannot be null.")),
|
||||
TSS_StringEntry(core::STR_ERR_OVERFLOW, _T("An overflow has been detected.")),
|
||||
TSS_StringEntry(core::STR_ERR_UNDERFLOW, _T("An underflow has been detected.")),
|
||||
TSS_StringEntry(core::STR_ERR_BADCHAR, _T("Input contained an invalid character."))
|
||||
|
||||
TSS_EndStringtable(cCore)
|
||||
|
|
|
@ -3,29 +3,29 @@
|
|||
// Portions created by Tripwire, Inc. are copyright (C) 2000-2018 Tripwire,
|
||||
// Inc. Tripwire is a registered trademark of Tripwire, Inc. All rights
|
||||
// reserved.
|
||||
//
|
||||
//
|
||||
// This program is free software. The contents of this file are subject
|
||||
// to the terms of the GNU General Public License as published by the
|
||||
// Free Software Foundation; either version 2 of the License, or (at your
|
||||
// option) any later version. You may redistribute it and/or modify it
|
||||
// only in compliance with the GNU General Public License.
|
||||
//
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful.
|
||||
// However, this program is distributed AS-IS WITHOUT ANY
|
||||
// WARRANTY; INCLUDING THE IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS
|
||||
// FOR A PARTICULAR PURPOSE. Please see the GNU General Public License
|
||||
// for more details.
|
||||
//
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
|
||||
// USA.
|
||||
//
|
||||
//
|
||||
// Nothing in the GNU General Public License or any other license to use
|
||||
// the code or files shall permit you to use Tripwire's trademarks,
|
||||
// service marks, or other intellectual property without Tripwire's
|
||||
// prior written consent.
|
||||
//
|
||||
//
|
||||
// If you have any questions, please contact Tripwire, Inc. at either
|
||||
// info@tripwire.org or www.tripwire.org.
|
||||
//
|
||||
|
@ -40,42 +40,24 @@
|
|||
#define __CORESTRINGS_H
|
||||
|
||||
|
||||
#include "core.h" // for: STRINGTABLE syntax
|
||||
#include "core.h" // for: STRINGTABLE syntax
|
||||
|
||||
|
||||
//--Message Keys
|
||||
|
||||
TSS_BeginStringIds( core )
|
||||
|
||||
TSS_BeginStringIds(core)
|
||||
|
||||
STR_ERR2_ARCH_CRYPTO_ERR,
|
||||
STR_ERR2_BAD_ARG_PARAMS,
|
||||
STR_ERROR_ERROR,
|
||||
STR_ERROR_WARNING,
|
||||
STR_ERROR_COLON,
|
||||
STR_ERROR_HEADER,
|
||||
STR_ERROR_EXITING,
|
||||
STR_ERROR_CONTINUING,
|
||||
STR_ERR2_FILENAME,
|
||||
STR_ERROR_FILENAME,
|
||||
STR_NUMBER_TOO_BIG,
|
||||
STR_UNKNOWN,
|
||||
STR_SIGNAL,
|
||||
STR_NEWLINE,
|
||||
STR_MEMARCHIVE_FILENAME,
|
||||
STR_MEMARCHIVE_ERRSTR,
|
||||
STR_ENDOFTIME,
|
||||
STR_UNKNOWN_TIME,
|
||||
STR_BAD_TEMPDIRECTORY,
|
||||
STR_ERR2_BAD_ARG_PARAMS, STR_ERROR_ERROR, STR_ERROR_WARNING, STR_ERROR_COLON, STR_ERROR_HEADER, STR_ERROR_EXITING,
|
||||
STR_ERROR_CONTINUING, STR_ERR2_FILENAME, STR_ERROR_FILENAME, STR_NUMBER_TOO_BIG, STR_UNKNOWN, STR_SIGNAL,
|
||||
STR_NEWLINE, STR_MEMARCHIVE_FILENAME, STR_MEMARCHIVE_ERRSTR, STR_ENDOFTIME, STR_UNKNOWN_TIME, STR_BAD_TEMPDIRECTORY,
|
||||
|
||||
/// Particularly useful for eCharacterSet and eCharacterEncoding
|
||||
|
||||
STR_ERR_ISNULL,
|
||||
STR_ERR_OVERFLOW,
|
||||
STR_ERR_UNDERFLOW,
|
||||
STR_ERR_ISNULL, STR_ERR_OVERFLOW, STR_ERR_UNDERFLOW,
|
||||
STR_ERR_BADCHAR
|
||||
|
||||
TSS_EndStringIds( core )
|
||||
TSS_EndStringIds(core)
|
||||
|
||||
|
||||
#endif //__CORESTRINGS_H
|
||||
|
||||
|
|
|
@ -3,29 +3,29 @@
|
|||
// Portions created by Tripwire, Inc. are copyright (C) 2000-2018 Tripwire,
|
||||
// Inc. Tripwire is a registered trademark of Tripwire, Inc. All rights
|
||||
// reserved.
|
||||
//
|
||||
//
|
||||
// This program is free software. The contents of this file are subject
|
||||
// to the terms of the GNU General Public License as published by the
|
||||
// Free Software Foundation; either version 2 of the License, or (at your
|
||||
// option) any later version. You may redistribute it and/or modify it
|
||||
// only in compliance with the GNU General Public License.
|
||||
//
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful.
|
||||
// However, this program is distributed AS-IS WITHOUT ANY
|
||||
// WARRANTY; INCLUDING THE IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS
|
||||
// FOR A PARTICULAR PURPOSE. Please see the GNU General Public License
|
||||
// for more details.
|
||||
//
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
|
||||
// USA.
|
||||
//
|
||||
//
|
||||
// Nothing in the GNU General Public License or any other license to use
|
||||
// the code or files shall permit you to use Tripwire's trademarks,
|
||||
// service marks, or other intellectual property without Tripwire's
|
||||
// prior written consent.
|
||||
//
|
||||
//
|
||||
// If you have any questions, please contact Tripwire, Inc. at either
|
||||
// info@tripwire.org or www.tripwire.org.
|
||||
//
|
||||
|
@ -37,17 +37,17 @@
|
|||
|
||||
#ifdef DEBUG
|
||||
|
||||
#ifndef va_start
|
||||
#include <cstdarg>
|
||||
#endif
|
||||
# ifndef va_start
|
||||
# include <cstdarg>
|
||||
# endif
|
||||
#include <cwchar>
|
||||
#include <fstream>
|
||||
#include <cstdio>
|
||||
|
||||
int cDebug::mDebugLevel(10);
|
||||
uint32 cDebug::mOutMask(cDebug::OUT_TRACE);
|
||||
int cDebug::mDebugLevel(10);
|
||||
uint32 cDebug::mOutMask(cDebug::OUT_TRACE);
|
||||
std::ofstream cDebug::logfile;
|
||||
//mDebugLevel default == 10, mOutMask default == OUT_TRACE.
|
||||
//mDebugLevel default == 10, mOutMask default == OUT_TRACE.
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Constructors and Destructor
|
||||
|
@ -61,32 +61,31 @@ cDebug::cDebug(const char* label)
|
|||
mLabel[cnt] = '\0';
|
||||
}
|
||||
|
||||
cDebug::cDebug(const cDebug &rhs)
|
||||
cDebug::cDebug(const cDebug& rhs)
|
||||
{
|
||||
strncpy(mLabel, rhs.mLabel, MAX_LABEL);
|
||||
}
|
||||
|
||||
cDebug::~cDebug()
|
||||
{
|
||||
if(logfile)
|
||||
if (logfile)
|
||||
logfile.close();
|
||||
}
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Trace -- Outputs a format string only if the passed integer value is <=
|
||||
// the "global debug level" (indicated by mDebugLevel).
|
||||
// the "global debug level" (indicated by mDebugLevel).
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
void cDebug::Trace(int levelNum, const char* format, ...)
|
||||
{
|
||||
if (levelNum > mDebugLevel)
|
||||
return;
|
||||
// create the output buffer
|
||||
// create the output buffer
|
||||
va_list args;
|
||||
va_start(args, format);
|
||||
DoTrace(format, args);
|
||||
va_end(args);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -96,10 +95,10 @@ void cDebug::Trace(int levelNum, const char* format, ...)
|
|||
// console, etc...
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void cDebug::DoTrace(const char *format, va_list &args)
|
||||
void cDebug::DoTrace(const char* format, va_list& args)
|
||||
{
|
||||
size_t guard1 = 0xBABABABA;
|
||||
char out[2048];
|
||||
char out[2048];
|
||||
size_t guard2 = 0xBABABABA;
|
||||
|
||||
vsnprintf(out, 2048, format, args);
|
||||
|
@ -135,14 +134,14 @@ void cDebug::DoTrace(const char *format, va_list &args)
|
|||
logfile.flush();
|
||||
}
|
||||
}
|
||||
#ifdef DEBUG
|
||||
# ifdef DEBUG
|
||||
|
||||
//
|
||||
// wrappers around Trace() that requires less typing
|
||||
// TODO: this is quick and dirty, but lets me check in all these files right away. --ghk
|
||||
//
|
||||
|
||||
void cDebug::TraceAlways(const char *format, ...)
|
||||
void cDebug::TraceAlways(const char* format, ...)
|
||||
{
|
||||
if (D_ALWAYS > mDebugLevel)
|
||||
return;
|
||||
|
@ -154,7 +153,7 @@ void cDebug::TraceAlways(const char *format, ...)
|
|||
va_end(args);
|
||||
}
|
||||
|
||||
void cDebug::TraceError(const char *format, ...)
|
||||
void cDebug::TraceError(const char* format, ...)
|
||||
{
|
||||
if (D_ERROR > mDebugLevel)
|
||||
return;
|
||||
|
@ -166,7 +165,7 @@ void cDebug::TraceError(const char *format, ...)
|
|||
va_end(args);
|
||||
}
|
||||
|
||||
void cDebug::TraceWarning(const char *format, ...)
|
||||
void cDebug::TraceWarning(const char* format, ...)
|
||||
{
|
||||
if (D_WARNING > mDebugLevel)
|
||||
return;
|
||||
|
@ -178,7 +177,7 @@ void cDebug::TraceWarning(const char *format, ...)
|
|||
va_end(args);
|
||||
}
|
||||
|
||||
void cDebug::TraceDebug(const char *format, ...)
|
||||
void cDebug::TraceDebug(const char* format, ...)
|
||||
{
|
||||
if (D_DEBUG > mDebugLevel)
|
||||
return;
|
||||
|
@ -190,7 +189,7 @@ void cDebug::TraceDebug(const char *format, ...)
|
|||
va_end(args);
|
||||
}
|
||||
|
||||
void cDebug::TraceDetail(const char *format, ...)
|
||||
void cDebug::TraceDetail(const char* format, ...)
|
||||
{
|
||||
if (D_DETAIL > mDebugLevel)
|
||||
return;
|
||||
|
@ -202,7 +201,7 @@ void cDebug::TraceDetail(const char *format, ...)
|
|||
va_end(args);
|
||||
}
|
||||
|
||||
void cDebug::TraceNever(const char *format, ...)
|
||||
void cDebug::TraceNever(const char* format, ...)
|
||||
{
|
||||
if (D_NEVER > mDebugLevel)
|
||||
return;
|
||||
|
@ -214,15 +213,15 @@ void cDebug::TraceNever(const char *format, ...)
|
|||
va_end(args);
|
||||
}
|
||||
|
||||
void cDebug::TraceVaArgs( int iDebugLevel, const char *format, va_list &args )
|
||||
void cDebug::TraceVaArgs(int iDebugLevel, const char* format, va_list& args)
|
||||
{
|
||||
if ( iDebugLevel <= mDebugLevel )
|
||||
DoTrace( format, args);
|
||||
if (iDebugLevel <= mDebugLevel)
|
||||
DoTrace(format, args);
|
||||
}
|
||||
#endif // DEBUG
|
||||
# endif // DEBUG
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// AddOutTarget -- Attempts to add a new target for trace/debug output.
|
||||
// AddOutTarget -- Attempts to add a new target for trace/debug output.
|
||||
// FAILS ONLY IF caller attempts to SET OUT_FILE via this function.
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
bool cDebug::AddOutTarget(OutTarget target)
|
||||
|
@ -231,7 +230,8 @@ bool cDebug::AddOutTarget(OutTarget target)
|
|||
mOutMask |= OUT_STDOUT;
|
||||
if (target == OUT_TRACE)
|
||||
mOutMask |= OUT_TRACE;
|
||||
if (target == OUT_FILE) {
|
||||
if (target == OUT_FILE)
|
||||
{
|
||||
mOutMask |= OUT_FILE;
|
||||
return false;
|
||||
}
|
||||
|
@ -259,7 +259,7 @@ bool cDebug::RemoveOutTarget(OutTarget target)
|
|||
///////////////////////////////////////////////////////////////////////////////
|
||||
bool cDebug::HasOutTarget(OutTarget target)
|
||||
{
|
||||
|
||||
|
||||
if (target == OUT_STDOUT)
|
||||
return ((mOutMask & OUT_STDOUT) != 0);
|
||||
else if (target == OUT_TRACE)
|
||||
|
@ -271,25 +271,27 @@ bool cDebug::HasOutTarget(OutTarget target)
|
|||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// SetOutputFile -- Attempts to set the output file for Logfile member to
|
||||
// SetOutputFile -- Attempts to set the output file for Logfile member to
|
||||
// the string passed in.
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
bool cDebug::SetOutputFile(const char* filename)
|
||||
{
|
||||
// TODO -- make sure this does the right thing if a log file is
|
||||
// TODO -- make sure this does the right thing if a log file is
|
||||
// already open!
|
||||
// TODO -- make this work with wide chars
|
||||
// TODO -- make this work with wide chars
|
||||
if (!logfile)
|
||||
logfile.open(filename, std::ios_base::out | std::ios_base::ate | std::ios_base::app);
|
||||
else
|
||||
logfile.setf(std::ios_base::hex, std::ios_base::basefield);
|
||||
//make sure info. will not be clobbered.
|
||||
//make sure info. will not be clobbered.
|
||||
|
||||
//Should be open now- if not, abort.
|
||||
if (!logfile) {
|
||||
if (!logfile)
|
||||
{
|
||||
mOutMask ^= OUT_FILE;
|
||||
return false;
|
||||
} else
|
||||
}
|
||||
else
|
||||
mOutMask |= OUT_FILE;
|
||||
return true;
|
||||
}
|
||||
|
@ -298,18 +300,18 @@ bool cDebug::SetOutputFile(const char* filename)
|
|||
// DebugOut -- Works just like TRACE. note: there is an internal buffer size
|
||||
// of 1024; traces larger than that will have unpredictable results.
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
void cDebug::DebugOut( const char* lpOutputString, ... )
|
||||
void cDebug::DebugOut(const char* lpOutputString, ...)
|
||||
{
|
||||
char buf[2048];
|
||||
// create the output buffer
|
||||
// create the output buffer
|
||||
va_list args;
|
||||
va_start(args, lpOutputString);
|
||||
vsnprintf(buf, 2048, lpOutputString, args);
|
||||
va_end(args);
|
||||
|
||||
#ifdef DEBUG
|
||||
TCERR << buf;
|
||||
#endif //_DEBUG
|
||||
|
||||
# ifdef DEBUG
|
||||
TCERR << buf;
|
||||
# endif //_DEBUG
|
||||
|
||||
TCOUT.flush();
|
||||
}
|
||||
|
@ -318,4 +320,3 @@ void cDebug::DebugOut( const char* lpOutputString, ... )
|
|||
//////////////////////////////////////////////////////////////////////////////////
|
||||
// ASSERT macro support function
|
||||
//////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
|
215
src/core/debug.h
215
src/core/debug.h
|
@ -3,29 +3,29 @@
|
|||
// Portions created by Tripwire, Inc. are copyright (C) 2000-2018 Tripwire,
|
||||
// Inc. Tripwire is a registered trademark of Tripwire, Inc. All rights
|
||||
// reserved.
|
||||
//
|
||||
//
|
||||
// This program is free software. The contents of this file are subject
|
||||
// to the terms of the GNU General Public License as published by the
|
||||
// Free Software Foundation; either version 2 of the License, or (at your
|
||||
// option) any later version. You may redistribute it and/or modify it
|
||||
// only in compliance with the GNU General Public License.
|
||||
//
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful.
|
||||
// However, this program is distributed AS-IS WITHOUT ANY
|
||||
// WARRANTY; INCLUDING THE IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS
|
||||
// FOR A PARTICULAR PURPOSE. Please see the GNU General Public License
|
||||
// for more details.
|
||||
//
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
|
||||
// USA.
|
||||
//
|
||||
//
|
||||
// Nothing in the GNU General Public License or any other license to use
|
||||
// the code or files shall permit you to use Tripwire's trademarks,
|
||||
// service marks, or other intellectual property without Tripwire's
|
||||
// prior written consent.
|
||||
//
|
||||
//
|
||||
// If you have any questions, please contact Tripwire, Inc. at either
|
||||
// info@tripwire.org or www.tripwire.org.
|
||||
//
|
||||
|
@ -40,19 +40,17 @@
|
|||
#include <assert.h>
|
||||
|
||||
|
||||
|
||||
|
||||
#include <iostream>
|
||||
/* Do it in this order, because autoconf checks for <stdarg.h>
|
||||
* first i.e. if HAVE_VARARGS_H is defined, it is only because
|
||||
* <stdarg.h> couldn't be found.
|
||||
*/
|
||||
#ifdef HAVE_VARARGS_H
|
||||
# include <varargs.h>
|
||||
#include <varargs.h>
|
||||
#else
|
||||
# ifdef HAVE_STDARG_H
|
||||
# include <stdarg.h>
|
||||
# endif
|
||||
# ifdef HAVE_STDARG_H
|
||||
# include <stdarg.h>
|
||||
# endif
|
||||
#endif
|
||||
#include "types.h"
|
||||
|
||||
|
@ -69,8 +67,8 @@
|
|||
//
|
||||
// IMPORTANT:
|
||||
//
|
||||
// strings outputted as trace statements are printed as narrow characters.
|
||||
// passing trace messages with wide characters will have odd results, since
|
||||
// strings outputted as trace statements are printed as narrow characters.
|
||||
// passing trace messages with wide characters will have odd results, since
|
||||
// they will be used as arugments to sprintf(), etc...
|
||||
//
|
||||
|
||||
|
@ -80,19 +78,19 @@ class cDebug
|
|||
public:
|
||||
enum OutTarget
|
||||
{
|
||||
OUT_STDOUT = 1,
|
||||
OUT_TRACE = 2,
|
||||
OUT_FILE = 4
|
||||
OUT_STDOUT = 1,
|
||||
OUT_TRACE = 2,
|
||||
OUT_FILE = 4
|
||||
};
|
||||
|
||||
enum DebugLevel
|
||||
{
|
||||
D_ALWAYS = 0,
|
||||
D_ERROR = 1,
|
||||
D_WARNING = 4,
|
||||
D_DEBUG = 8,
|
||||
D_DETAIL = 16,
|
||||
D_NEVER = 1000
|
||||
D_ERROR = 1,
|
||||
D_WARNING = 4,
|
||||
D_DEBUG = 8,
|
||||
D_DETAIL = 16,
|
||||
D_NEVER = 1000
|
||||
};
|
||||
|
||||
cDebug(const char* pLabel);
|
||||
|
@ -101,65 +99,67 @@ public:
|
|||
|
||||
// These are the preferred tracing interfaces, because you don't need to know
|
||||
// the DebugLevel enums.
|
||||
// Wide/Narrow Chars Issues: If you include a %s in your format string and you
|
||||
// Wide/Narrow Chars Issues: If you include a %s in your format string and you
|
||||
// wish to print out a TCHAR (which might be a natural thing to do) you should
|
||||
// encompas the format string with a _T("") macro, i.e. make it a TSTRING.
|
||||
// The wide character overloads of these functions will expect wide strings
|
||||
// for %s options.
|
||||
//
|
||||
void TraceAlways (const char *format, ...);
|
||||
void TraceError (const char *format, ...);
|
||||
void TraceWarning (const char *format, ...);
|
||||
void TraceDebug (const char *format, ...);
|
||||
void TraceDetail (const char *format, ...);
|
||||
void TraceNever (const char *format, ...);
|
||||
void TraceAlways(const char* format, ...);
|
||||
void TraceError(const char* format, ...);
|
||||
void TraceWarning(const char* format, ...);
|
||||
void TraceDebug(const char* format, ...);
|
||||
void TraceDetail(const char* format, ...);
|
||||
void TraceNever(const char* format, ...);
|
||||
|
||||
|
||||
// these are of use if you are inside a function with a "..." as an argument
|
||||
// and you want to trace those args
|
||||
void TraceVaArgs (int iDebugLevel, const char *format, va_list &args);
|
||||
void TraceVaArgs(int iDebugLevel, const char* format, va_list& args);
|
||||
|
||||
// ...but you can still choose to use this interface...
|
||||
|
||||
void Trace(int levelNum, const char* format, ...);
|
||||
// Outputs based on levelnum. If levelnum <= global debug, print.
|
||||
// Outputs based on levelnum. If levelnum <= global debug, print.
|
||||
|
||||
public:
|
||||
|
||||
static bool AddOutTarget (OutTarget target);
|
||||
static bool RemoveOutTarget (OutTarget target);
|
||||
// used to specify the out target....
|
||||
static bool HasOutTarget (OutTarget target);
|
||||
static bool AddOutTarget(OutTarget target);
|
||||
static bool RemoveOutTarget(OutTarget target);
|
||||
// used to specify the out target....
|
||||
static bool HasOutTarget(OutTarget target);
|
||||
|
||||
static bool SetOutputFile (const char* filename);
|
||||
// specifies the output file name used when OUT_FILE is set
|
||||
static void SetDebugLevel (int level);
|
||||
static int GetDebugLevel (void);
|
||||
// gets and sets the global debug level. Trace output at or below this
|
||||
// level will be output.
|
||||
|
||||
static void DebugOut ( const char* lpOutputString, ... );
|
||||
// Works just like TRACE
|
||||
// note: there is an internal buffer size of 1024; traces larger
|
||||
// than that will have unpredictable and probably bad results
|
||||
static bool SetOutputFile(const char* filename);
|
||||
// specifies the output file name used when OUT_FILE is set
|
||||
static void SetDebugLevel(int level);
|
||||
static int GetDebugLevel(void);
|
||||
// gets and sets the global debug level. Trace output at or below this
|
||||
// level will be output.
|
||||
|
||||
static void DebugOut(const char* lpOutputString, ...);
|
||||
// Works just like TRACE
|
||||
// note: there is an internal buffer size of 1024; traces larger
|
||||
// than that will have unpredictable and probably bad results
|
||||
private:
|
||||
#ifdef DEBUG
|
||||
enum { MAX_LABEL = 128 };
|
||||
enum
|
||||
{
|
||||
MAX_LABEL = 128
|
||||
};
|
||||
|
||||
static int mDebugLevel;
|
||||
static uint32 mOutMask;
|
||||
static std::ofstream logfile;
|
||||
char mLabel[MAX_LABEL];
|
||||
static int mDebugLevel;
|
||||
static uint32 mOutMask;
|
||||
static std::ofstream logfile;
|
||||
char mLabel[MAX_LABEL];
|
||||
|
||||
// helper functions
|
||||
void DoTrace(const char *format, va_list &args);
|
||||
void DoTrace(const char* format, va_list& args);
|
||||
#endif
|
||||
};
|
||||
|
||||
#ifdef DEBUG
|
||||
#define TRACE cDebug::DebugOut
|
||||
# define TRACE cDebug::DebugOut
|
||||
#else
|
||||
#define TRACE 1 ? (void)0 : cDebug::DebugOut
|
||||
# define TRACE 1 ? (void)0 : cDebug::DebugOut
|
||||
#endif // DEBUG
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -179,51 +179,90 @@ inline int cDebug::GetDebugLevel()
|
|||
return mDebugLevel;
|
||||
}
|
||||
|
||||
#else // DEBUG
|
||||
# else // DEBUG
|
||||
|
||||
inline cDebug::cDebug (const char *) {}
|
||||
inline cDebug::~cDebug () {}
|
||||
inline cDebug::cDebug (const cDebug&) {}
|
||||
inline void cDebug::TraceAlways (const char *, ...) {}
|
||||
inline void cDebug::TraceError (const char *, ...) {}
|
||||
inline void cDebug::TraceWarning (const char *, ...) {}
|
||||
inline void cDebug::TraceDebug (const char *, ...) {}
|
||||
inline void cDebug::TraceDetail (const char *, ...) {}
|
||||
inline void cDebug::TraceNever (const char *, ...) {}
|
||||
inline void cDebug::TraceVaArgs (int, const char *, va_list &) {}
|
||||
inline void cDebug::Trace (int, const char*, ...) {}
|
||||
inline bool cDebug::AddOutTarget (OutTarget) { return false; }
|
||||
inline bool cDebug::RemoveOutTarget (OutTarget) { return false; }
|
||||
inline bool cDebug::HasOutTarget (OutTarget) { return false; }
|
||||
inline bool cDebug::SetOutputFile (const char*) { return false; }
|
||||
inline void cDebug::SetDebugLevel (int) {}
|
||||
inline int cDebug::GetDebugLevel (void) { return 0; }
|
||||
inline void cDebug::DebugOut ( const char*, ... ) {}
|
||||
|
||||
#endif // DEBUG
|
||||
inline cDebug::cDebug(const char*)
|
||||
{
|
||||
}
|
||||
inline cDebug::~cDebug()
|
||||
{
|
||||
}
|
||||
inline cDebug::cDebug(const cDebug&)
|
||||
{
|
||||
}
|
||||
inline void cDebug::TraceAlways(const char*, ...)
|
||||
{
|
||||
}
|
||||
inline void cDebug::TraceError(const char*, ...)
|
||||
{
|
||||
}
|
||||
inline void cDebug::TraceWarning(const char*, ...)
|
||||
{
|
||||
}
|
||||
inline void cDebug::TraceDebug(const char*, ...)
|
||||
{
|
||||
}
|
||||
inline void cDebug::TraceDetail(const char*, ...)
|
||||
{
|
||||
}
|
||||
inline void cDebug::TraceNever(const char*, ...)
|
||||
{
|
||||
}
|
||||
inline void cDebug::TraceVaArgs(int, const char*, va_list&)
|
||||
{
|
||||
}
|
||||
inline void cDebug::Trace(int, const char*, ...)
|
||||
{
|
||||
}
|
||||
inline bool cDebug::AddOutTarget(OutTarget)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
inline bool cDebug::RemoveOutTarget(OutTarget)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
inline bool cDebug::HasOutTarget(OutTarget)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
inline bool cDebug::SetOutputFile(const char*)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
inline void cDebug::SetDebugLevel(int)
|
||||
{
|
||||
}
|
||||
inline int cDebug::GetDebugLevel(void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
inline void cDebug::DebugOut(const char*, ...)
|
||||
{
|
||||
}
|
||||
|
||||
# endif // DEBUG
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////
|
||||
// ASSERT macro
|
||||
//////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#define ASSERTMSG( exp, s ) assert( (exp) != 0 )
|
||||
#define ASSERT( exp ) assert( (exp) != 0 )
|
||||
# define ASSERTMSG(exp, s) assert((exp) != 0)
|
||||
# define ASSERT(exp) assert((exp) != 0)
|
||||
// if we are not windows we will just use the standard assert()
|
||||
#define TSS_DebugBreak() ASSERT( false );
|
||||
# define TSS_DebugBreak() ASSERT(false);
|
||||
|
||||
#ifndef ASSERT
|
||||
#error ASSERT did not get defined!!!
|
||||
#endif
|
||||
# ifndef ASSERT
|
||||
# error ASSERT did not get defined!!!
|
||||
# endif
|
||||
|
||||
#ifndef ASSERTMSG
|
||||
#error ASSERTMSG did not get defined!!!
|
||||
#endif
|
||||
# ifndef ASSERTMSG
|
||||
# error ASSERTMSG did not get defined!!!
|
||||
# endif
|
||||
|
||||
#ifndef TSS_DebugBreak
|
||||
#error TSS_DebugBreak did not get defined!!!
|
||||
#endif
|
||||
# ifndef TSS_DebugBreak
|
||||
# error TSS_DebugBreak did not get defined!!!
|
||||
# endif
|
||||
|
||||
#endif //__DEBUG_H
|
||||
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -3,29 +3,29 @@
|
|||
// Portions created by Tripwire, Inc. are copyright (C) 2000-2018 Tripwire,
|
||||
// Inc. Tripwire is a registered trademark of Tripwire, Inc. All rights
|
||||
// reserved.
|
||||
//
|
||||
//
|
||||
// This program is free software. The contents of this file are subject
|
||||
// to the terms of the GNU General Public License as published by the
|
||||
// Free Software Foundation; either version 2 of the License, or (at your
|
||||
// option) any later version. You may redistribute it and/or modify it
|
||||
// only in compliance with the GNU General Public License.
|
||||
//
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful.
|
||||
// However, this program is distributed AS-IS WITHOUT ANY
|
||||
// WARRANTY; INCLUDING THE IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS
|
||||
// FOR A PARTICULAR PURPOSE. Please see the GNU General Public License
|
||||
// for more details.
|
||||
//
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
|
||||
// USA.
|
||||
//
|
||||
//
|
||||
// Nothing in the GNU General Public License or any other license to use
|
||||
// the code or files shall permit you to use Tripwire's trademarks,
|
||||
// service marks, or other intellectual property without Tripwire's
|
||||
// prior written consent.
|
||||
//
|
||||
//
|
||||
// If you have any questions, please contact Tripwire, Inc. at either
|
||||
// info@tripwire.org or www.tripwire.org.
|
||||
//
|
||||
|
@ -40,10 +40,10 @@
|
|||
// EXCEPTION DECLARATION
|
||||
//=========================================================================
|
||||
|
||||
TSS_EXCEPTION( eEncoder, eError );
|
||||
TSS_EXCEPTION( eBadDecoderInput, eEncoder );
|
||||
TSS_EXCEPTION( eBadHexConversion, eEncoder );
|
||||
TSS_EXCEPTION( eUnknownEscapeEncoding, eEncoder );
|
||||
TSS_EXCEPTION(eEncoder, eError);
|
||||
TSS_EXCEPTION(eBadDecoderInput, eEncoder);
|
||||
TSS_EXCEPTION(eBadHexConversion, eEncoder);
|
||||
TSS_EXCEPTION(eUnknownEscapeEncoding, eEncoder);
|
||||
|
||||
//=========================================================================
|
||||
// DECLARATION OF CLASSES
|
||||
|
@ -55,106 +55,101 @@ TSS_EXCEPTION( eUnknownEscapeEncoding, eEncoder );
|
|||
|
||||
class iCharEncoder;
|
||||
|
||||
// TODO:BAM -- i don't think that the order of encodings is important
|
||||
// TODO:BAM -- i don't think that the order of encodings is important
|
||||
// as long as AllIdentifiersUnique and OnlyOneCatagoryPerChar are true
|
||||
class cEncoder
|
||||
{
|
||||
public:
|
||||
enum Encodings
|
||||
{
|
||||
NON_NARROWABLE = 0x01, // WC -> MB, MB alway narrowable:
|
||||
NON_PRINTABLE = 0x02,
|
||||
BACKSLASH = 0x04,
|
||||
DBL_QUOTE = 0x08
|
||||
};
|
||||
|
||||
enum Flags
|
||||
{
|
||||
ROUNDTRIP = 0x01,
|
||||
NON_ROUNDTRIP = 0x02,
|
||||
ALLOW_WHITESPACE = 0x04
|
||||
};
|
||||
public:
|
||||
enum Encodings
|
||||
{
|
||||
NON_NARROWABLE = 0x01, // WC -> MB, MB alway narrowable:
|
||||
NON_PRINTABLE = 0x02,
|
||||
BACKSLASH = 0x04,
|
||||
DBL_QUOTE = 0x08
|
||||
};
|
||||
|
||||
cEncoder( int e, int f ); // mask of Encodings
|
||||
virtual ~cEncoder();
|
||||
enum Flags
|
||||
{
|
||||
ROUNDTRIP = 0x01,
|
||||
NON_ROUNDTRIP = 0x02,
|
||||
ALLOW_WHITESPACE = 0x04
|
||||
};
|
||||
|
||||
void Encode( TSTRING& str ) const;
|
||||
void Decode( TSTRING& str ) const; // TODO:BAM -- throw error!
|
||||
cEncoder(int e, int f); // mask of Encodings
|
||||
virtual ~cEncoder();
|
||||
|
||||
void ValidateSchema() const;
|
||||
bool OnlyOneCatagoryPerChar() const;
|
||||
bool AllIdentifiersUnique() const;
|
||||
bool AllTestsRunOnEncodedString( const TSTRING& str ) const;
|
||||
void Encode(TSTRING& str) const;
|
||||
void Decode(TSTRING& str) const; // TODO:BAM -- throw error!
|
||||
|
||||
private:
|
||||
typedef std::vector< iCharEncoder* > sack_type;
|
||||
|
||||
TSTRING Encode( TSTRING::const_iterator first,
|
||||
TSTRING::const_iterator last,
|
||||
sack_type::const_iterator encoding ) const;
|
||||
|
||||
bool RoundTrip() const;
|
||||
bool AllowWhiteSpace() const;
|
||||
void ValidateSchema() const;
|
||||
bool OnlyOneCatagoryPerChar() const;
|
||||
bool AllIdentifiersUnique() const;
|
||||
bool AllTestsRunOnEncodedString(const TSTRING& str) const;
|
||||
|
||||
sack_type m_encodings;
|
||||
int m_fFlags;
|
||||
private:
|
||||
typedef std::vector<iCharEncoder*> sack_type;
|
||||
|
||||
TSTRING
|
||||
Encode(TSTRING::const_iterator first, TSTRING::const_iterator last, sack_type::const_iterator encoding) const;
|
||||
|
||||
bool RoundTrip() const;
|
||||
bool AllowWhiteSpace() const;
|
||||
|
||||
sack_type m_encodings;
|
||||
int m_fFlags;
|
||||
};
|
||||
|
||||
// encodes ( BACKSLASH | DBL_QUOTE | NON_NARROWABLE | NON_PRINTABLE )
|
||||
|
||||
class cDisplayEncoder : public cEncoder
|
||||
{
|
||||
public:
|
||||
cDisplayEncoder( Flags f = NON_ROUNDTRIP );
|
||||
|
||||
void Encode( TSTRING& str ) const;
|
||||
bool Decode( TSTRING& str ) const;
|
||||
public:
|
||||
cDisplayEncoder(Flags f = NON_ROUNDTRIP);
|
||||
|
||||
static TSTRING EncodeInline( const TSTRING& sIn )
|
||||
{
|
||||
TSTRING sOut = sIn;
|
||||
cDisplayEncoder e;
|
||||
e.Encode( sOut );
|
||||
return sOut;
|
||||
}
|
||||
|
||||
static TSTRING EncodeInlineAllowWS( const TSTRING& sIn )
|
||||
{
|
||||
TSTRING sOut = sIn;
|
||||
cDisplayEncoder e( (Flags)( NON_ROUNDTRIP | ALLOW_WHITESPACE ) );
|
||||
e.Encode( sOut );
|
||||
return sOut;
|
||||
}
|
||||
void Encode(TSTRING& str) const;
|
||||
bool Decode(TSTRING& str) const;
|
||||
|
||||
static TSTRING EncodeInline(const TSTRING& sIn)
|
||||
{
|
||||
TSTRING sOut = sIn;
|
||||
cDisplayEncoder e;
|
||||
e.Encode(sOut);
|
||||
return sOut;
|
||||
}
|
||||
|
||||
static TSTRING EncodeInlineAllowWS(const TSTRING& sIn)
|
||||
{
|
||||
TSTRING sOut = sIn;
|
||||
cDisplayEncoder e((Flags)(NON_ROUNDTRIP | ALLOW_WHITESPACE));
|
||||
e.Encode(sOut);
|
||||
return sOut;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
class cCharEncoderUtil
|
||||
{
|
||||
public:
|
||||
public:
|
||||
static bool IsPrintable(TCHAR ch);
|
||||
static bool IsWhiteSpace(TCHAR ch);
|
||||
|
||||
static bool IsPrintable( TCHAR ch );
|
||||
static bool IsWhiteSpace( TCHAR ch );
|
||||
static TSTRING CharStringToHexValue(const TSTRING& str);
|
||||
|
||||
static TSTRING CharStringToHexValue( const TSTRING& str );
|
||||
static TSTRING HexValueToCharString(const TSTRING& str);
|
||||
|
||||
static TSTRING HexValueToCharString( const TSTRING& str );
|
||||
static TCHAR hex_to_char(TSTRING::const_iterator first, TSTRING::const_iterator last);
|
||||
|
||||
static TCHAR hex_to_char( TSTRING::const_iterator first,
|
||||
TSTRING::const_iterator last );
|
||||
static TSTRING char_to_hex(TCHAR ch);
|
||||
|
||||
static TSTRING char_to_hex( TCHAR ch );
|
||||
|
||||
static TSTRING DecodeHexToChar( TSTRING::const_iterator* pcur,
|
||||
const TSTRING::const_iterator end );
|
||||
static TSTRING DecodeHexToChar(TSTRING::const_iterator* pcur, const TSTRING::const_iterator end);
|
||||
|
||||
|
||||
enum
|
||||
{
|
||||
BYTE_AS_HEX__IN_TCHARS = 2,
|
||||
BYTES_PER_TCHAR = sizeof( TCHAR ),
|
||||
TCHAR_AS_HEX__IN_TCHARS = BYTE_AS_HEX__IN_TCHARS * BYTES_PER_TCHAR
|
||||
};
|
||||
enum
|
||||
{
|
||||
BYTE_AS_HEX__IN_TCHARS = 2,
|
||||
BYTES_PER_TCHAR = sizeof(TCHAR),
|
||||
TCHAR_AS_HEX__IN_TCHARS = BYTE_AS_HEX__IN_TCHARS * BYTES_PER_TCHAR
|
||||
};
|
||||
};
|
||||
|
||||
#endif //__DISPLAYENCODER_H
|
||||
|
@ -241,4 +236,3 @@ typedef cDisplayEncoder_<TCHAR> cDisplayEncoder;
|
|||
#endif //__DISPLAYENCODER_H
|
||||
|
||||
*/
|
||||
|
||||
|
|
|
@ -3,29 +3,29 @@
|
|||
// Portions created by Tripwire, Inc. are copyright (C) 2000-2018 Tripwire,
|
||||
// Inc. Tripwire is a registered trademark of Tripwire, Inc. All rights
|
||||
// reserved.
|
||||
//
|
||||
//
|
||||
// This program is free software. The contents of this file are subject
|
||||
// to the terms of the GNU General Public License as published by the
|
||||
// Free Software Foundation; either version 2 of the License, or (at your
|
||||
// option) any later version. You may redistribute it and/or modify it
|
||||
// only in compliance with the GNU General Public License.
|
||||
//
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful.
|
||||
// However, this program is distributed AS-IS WITHOUT ANY
|
||||
// WARRANTY; INCLUDING THE IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS
|
||||
// FOR A PARTICULAR PURPOSE. Please see the GNU General Public License
|
||||
// for more details.
|
||||
//
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
|
||||
// USA.
|
||||
//
|
||||
//
|
||||
// Nothing in the GNU General Public License or any other license to use
|
||||
// the code or files shall permit you to use Tripwire's trademarks,
|
||||
// service marks, or other intellectual property without Tripwire's
|
||||
// prior written consent.
|
||||
//
|
||||
//
|
||||
// If you have any questions, please contact Tripwire, Inc. at either
|
||||
// info@tripwire.org or www.tripwire.org.
|
||||
//
|
||||
|
@ -40,29 +40,29 @@
|
|||
#include "ntmbs.h"
|
||||
#include <iomanip>
|
||||
|
||||
TSTRING cDisplayUtil::FormatMultiLineString( const TSTRING& str, int nOffset, int nWidth )
|
||||
TSTRING cDisplayUtil::FormatMultiLineString(const TSTRING& str, int nOffset, int nWidth)
|
||||
{
|
||||
TOSTRINGSTREAM sstr;
|
||||
TSTRING strT;
|
||||
bool fFirstLine = true;
|
||||
for( TSTRING::const_iterator i = str.begin(); i != str.end(); i = *i ? i + 1 : i )
|
||||
TSTRING strT;
|
||||
bool fFirstLine = true;
|
||||
for (TSTRING::const_iterator i = str.begin(); i != str.end(); i = *i ? i + 1 : i)
|
||||
{
|
||||
// return found -- add line to output string
|
||||
if( _T('\n') == *i )
|
||||
if (_T('\n') == *i)
|
||||
{
|
||||
// only do offset for strings after the first
|
||||
if( fFirstLine )
|
||||
if (fFirstLine)
|
||||
{
|
||||
fFirstLine = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
{
|
||||
// add offset
|
||||
for( int j = 0; j < nOffset; j++ )
|
||||
for (int j = 0; j < nOffset; j++)
|
||||
sstr << _T(" ");
|
||||
|
||||
// set width
|
||||
sstr << std::setw( nWidth );
|
||||
sstr << std::setw(nWidth);
|
||||
}
|
||||
|
||||
// add to stringstream
|
||||
|
@ -73,28 +73,26 @@ TSTRING cDisplayUtil::FormatMultiLineString( const TSTRING& str, int nOffset, in
|
|||
}
|
||||
else
|
||||
{
|
||||
// add char to string
|
||||
strT.append( i, (TSTRING::const_iterator)(*i ? i + 1 : i) );
|
||||
// add char to string
|
||||
strT.append(i, (TSTRING::const_iterator)(*i ? i + 1 : i));
|
||||
}
|
||||
}
|
||||
|
||||
// add last portion -- no endl
|
||||
}
|
||||
|
||||
// add last portion -- no endl
|
||||
// we want our client to be able to say "out << PropAsString() << endl;"
|
||||
|
||||
// add offset
|
||||
if( ! fFirstLine )
|
||||
if (!fFirstLine)
|
||||
{
|
||||
for( int j = 0; j < nOffset; j++ )
|
||||
for (int j = 0; j < nOffset; j++)
|
||||
sstr << _T(" ");
|
||||
}
|
||||
|
||||
// set width
|
||||
sstr << std::setw( nWidth );
|
||||
sstr << std::setw(nWidth);
|
||||
|
||||
// now add last string
|
||||
sstr << strT;
|
||||
|
||||
return( sstr.str() );
|
||||
return (sstr.str());
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -3,29 +3,29 @@
|
|||
// Portions created by Tripwire, Inc. are copyright (C) 2000-2018 Tripwire,
|
||||
// Inc. Tripwire is a registered trademark of Tripwire, Inc. All rights
|
||||
// reserved.
|
||||
//
|
||||
//
|
||||
// This program is free software. The contents of this file are subject
|
||||
// to the terms of the GNU General Public License as published by the
|
||||
// Free Software Foundation; either version 2 of the License, or (at your
|
||||
// option) any later version. You may redistribute it and/or modify it
|
||||
// only in compliance with the GNU General Public License.
|
||||
//
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful.
|
||||
// However, this program is distributed AS-IS WITHOUT ANY
|
||||
// WARRANTY; INCLUDING THE IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS
|
||||
// FOR A PARTICULAR PURPOSE. Please see the GNU General Public License
|
||||
// for more details.
|
||||
//
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
|
||||
// USA.
|
||||
//
|
||||
//
|
||||
// Nothing in the GNU General Public License or any other license to use
|
||||
// the code or files shall permit you to use Tripwire's trademarks,
|
||||
// service marks, or other intellectual property without Tripwire's
|
||||
// prior written consent.
|
||||
//
|
||||
//
|
||||
// If you have any questions, please contact Tripwire, Inc. at either
|
||||
// info@tripwire.org or www.tripwire.org.
|
||||
//
|
||||
|
@ -41,7 +41,7 @@
|
|||
class cDisplayUtil
|
||||
{
|
||||
public:
|
||||
static TSTRING FormatMultiLineString( const TSTRING& str, int nOffset, int nWidth );
|
||||
static TSTRING FormatMultiLineString(const TSTRING& str, int nOffset, int nWidth);
|
||||
};
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
|
@ -61,18 +61,18 @@ public:
|
|||
//
|
||||
// What happens is that you get output like:
|
||||
// " First Line"
|
||||
// ^ ^^ ^
|
||||
// ^ ^^ ^
|
||||
// |--10 sp-||---15 width--|
|
||||
// "Second Line"
|
||||
// ^
|
||||
// ^
|
||||
// | 0 sp, 0 width
|
||||
//
|
||||
// When you really wanted:
|
||||
// " First Line"
|
||||
// ^ ^^ ^
|
||||
// ^ ^^ ^
|
||||
// |--10 sp-||---15 width--|
|
||||
// " Second Line"
|
||||
// ^ ^^ ^
|
||||
// ^ ^^ ^
|
||||
// |--10 sp-||---15 width--|
|
||||
//
|
||||
//
|
||||
|
@ -84,13 +84,13 @@ public:
|
|||
// So you can output a multiline string and have each line be formatted
|
||||
// like the first one was.
|
||||
//
|
||||
// So, for the preceeding example,
|
||||
// So, for the preceeding example,
|
||||
//
|
||||
// change:
|
||||
// TCOUT << szTenSpaceMargin << setw(15) << szMessage;
|
||||
//
|
||||
// to:
|
||||
// TCOUT << szTenSpaceMargin << setw(15)
|
||||
// TCOUT << szTenSpaceMargin << setw(15)
|
||||
// << cDisplayUtil::FormatMultiLineString( szMessage, 10, 15 );
|
||||
//
|
||||
// Comprende? It's crazy but it works.
|
||||
|
@ -98,4 +98,3 @@ public:
|
|||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
|
||||
#endif // #ifndef __DISPLAYUTIL_H
|
||||
|
||||
|
|
|
@ -3,29 +3,29 @@
|
|||
// Portions created by Tripwire, Inc. are copyright (C) 2000-2018 Tripwire,
|
||||
// Inc. Tripwire is a registered trademark of Tripwire, Inc. All rights
|
||||
// reserved.
|
||||
//
|
||||
//
|
||||
// This program is free software. The contents of this file are subject
|
||||
// to the terms of the GNU General Public License as published by the
|
||||
// Free Software Foundation; either version 2 of the License, or (at your
|
||||
// option) any later version. You may redistribute it and/or modify it
|
||||
// only in compliance with the GNU General Public License.
|
||||
//
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful.
|
||||
// However, this program is distributed AS-IS WITHOUT ANY
|
||||
// WARRANTY; INCLUDING THE IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS
|
||||
// FOR A PARTICULAR PURPOSE. Please see the GNU General Public License
|
||||
// for more details.
|
||||
//
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
|
||||
// USA.
|
||||
//
|
||||
//
|
||||
// Nothing in the GNU General Public License or any other license to use
|
||||
// the code or files shall permit you to use Tripwire's trademarks,
|
||||
// service marks, or other intellectual property without Tripwire's
|
||||
// prior written consent.
|
||||
//
|
||||
//
|
||||
// If you have any questions, please contact Tripwire, Inc. at either
|
||||
// info@tripwire.org or www.tripwire.org.
|
||||
//
|
||||
|
@ -49,9 +49,9 @@ bool CheckEpoch()
|
|||
// Rather than crashing, we will exit with a nice message
|
||||
memset(&time_struct, 0, sizeof(time_struct));
|
||||
time_struct.tm_mday = 1;
|
||||
time_struct.tm_mon = 0;
|
||||
time_struct.tm_mon = 0;
|
||||
time_struct.tm_year = 138;
|
||||
int64 endoftime = cTimeUtil::DateToTime( &time_struct );
|
||||
int64 endoftime = cTimeUtil::DateToTime(&time_struct);
|
||||
|
||||
if (time(0) > endoftime)
|
||||
{
|
||||
|
@ -64,4 +64,3 @@ bool CheckEpoch()
|
|||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
|
|
@ -3,29 +3,29 @@
|
|||
// Portions created by Tripwire, Inc. are copyright (C) 2000-2018 Tripwire,
|
||||
// Inc. Tripwire is a registered trademark of Tripwire, Inc. All rights
|
||||
// reserved.
|
||||
//
|
||||
//
|
||||
// This program is free software. The contents of this file are subject
|
||||
// to the terms of the GNU General Public License as published by the
|
||||
// Free Software Foundation; either version 2 of the License, or (at your
|
||||
// option) any later version. You may redistribute it and/or modify it
|
||||
// only in compliance with the GNU General Public License.
|
||||
//
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful.
|
||||
// However, this program is distributed AS-IS WITHOUT ANY
|
||||
// WARRANTY; INCLUDING THE IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS
|
||||
// FOR A PARTICULAR PURPOSE. Please see the GNU General Public License
|
||||
// for more details.
|
||||
//
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
|
||||
// USA.
|
||||
//
|
||||
//
|
||||
// Nothing in the GNU General Public License or any other license to use
|
||||
// the code or files shall permit you to use Tripwire's trademarks,
|
||||
// service marks, or other intellectual property without Tripwire's
|
||||
// prior written consent.
|
||||
//
|
||||
//
|
||||
// If you have any questions, please contact Tripwire, Inc. at either
|
||||
// info@tripwire.org or www.tripwire.org.
|
||||
//
|
||||
|
@ -42,4 +42,3 @@
|
|||
bool CheckEpoch();
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
@ -3,29 +3,29 @@
|
|||
// Portions created by Tripwire, Inc. are copyright (C) 2000-2018 Tripwire,
|
||||
// Inc. Tripwire is a registered trademark of Tripwire, Inc. All rights
|
||||
// reserved.
|
||||
//
|
||||
//
|
||||
// This program is free software. The contents of this file are subject
|
||||
// to the terms of the GNU General Public License as published by the
|
||||
// Free Software Foundation; either version 2 of the License, or (at your
|
||||
// option) any later version. You may redistribute it and/or modify it
|
||||
// only in compliance with the GNU General Public License.
|
||||
//
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful.
|
||||
// However, this program is distributed AS-IS WITHOUT ANY
|
||||
// WARRANTY; INCLUDING THE IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS
|
||||
// FOR A PARTICULAR PURPOSE. Please see the GNU General Public License
|
||||
// for more details.
|
||||
//
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
|
||||
// USA.
|
||||
//
|
||||
//
|
||||
// Nothing in the GNU General Public License or any other license to use
|
||||
// the code or files shall permit you to use Tripwire's trademarks,
|
||||
// service marks, or other intellectual property without Tripwire's
|
||||
// prior written consent.
|
||||
//
|
||||
//
|
||||
// If you have any questions, please contact Tripwire, Inc. at either
|
||||
// info@tripwire.org or www.tripwire.org.
|
||||
//
|
||||
|
@ -39,13 +39,11 @@
|
|||
///////////////////////////////////////////////////////////////////////////////
|
||||
// CalcHash
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
uint32 eError::CalcHash( const char* name )
|
||||
uint32 eError::CalcHash(const char* name)
|
||||
{
|
||||
CRC_INFO crc;
|
||||
crcInit( crc );
|
||||
crcUpdate( crc, (const uint8*)name, strlen( name ) );
|
||||
crcFinit( crc );
|
||||
crcInit(crc);
|
||||
crcUpdate(crc, (const uint8*)name, strlen(name));
|
||||
crcFinit(crc);
|
||||
return crc.crc;
|
||||
}
|
||||
|
||||
|
||||
|
|
181
src/core/error.h
181
src/core/error.h
|
@ -3,29 +3,29 @@
|
|||
// Portions created by Tripwire, Inc. are copyright (C) 2000-2018 Tripwire,
|
||||
// Inc. Tripwire is a registered trademark of Tripwire, Inc. All rights
|
||||
// reserved.
|
||||
//
|
||||
//
|
||||
// This program is free software. The contents of this file are subject
|
||||
// to the terms of the GNU General Public License as published by the
|
||||
// Free Software Foundation; either version 2 of the License, or (at your
|
||||
// option) any later version. You may redistribute it and/or modify it
|
||||
// only in compliance with the GNU General Public License.
|
||||
//
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful.
|
||||
// However, this program is distributed AS-IS WITHOUT ANY
|
||||
// WARRANTY; INCLUDING THE IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS
|
||||
// FOR A PARTICULAR PURPOSE. Please see the GNU General Public License
|
||||
// for more details.
|
||||
//
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
|
||||
// USA.
|
||||
//
|
||||
//
|
||||
// Nothing in the GNU General Public License or any other license to use
|
||||
// the code or files shall permit you to use Tripwire's trademarks,
|
||||
// service marks, or other intellectual property without Tripwire's
|
||||
// prior written consent.
|
||||
//
|
||||
//
|
||||
// If you have any questions, please contact Tripwire, Inc. at either
|
||||
// info@tripwire.org or www.tripwire.org.
|
||||
//
|
||||
|
@ -42,14 +42,13 @@
|
|||
class eError
|
||||
{
|
||||
public:
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
// Construction and Assignment
|
||||
//-------------------------------------------------------------------------
|
||||
eError( const TSTRING& msg, uint32 flags = 0 );
|
||||
explicit eError( const eError& rhs );
|
||||
explicit eError();
|
||||
void operator=( const eError& rhs );
|
||||
eError(const TSTRING& msg, uint32 flags = 0);
|
||||
explicit eError(const eError& rhs);
|
||||
explicit eError();
|
||||
void operator=(const eError& rhs);
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
// Destruction
|
||||
|
@ -60,54 +59,54 @@ public:
|
|||
// Data Access
|
||||
//-------------------------------------------------------------------------
|
||||
virtual uint32 GetID() const = 0;
|
||||
// returns a system wide unique identifier for this exception. See the
|
||||
// macro below for the typical implementation of this method.
|
||||
// This is used to associate the error with a string description of the
|
||||
// error via the global error table.
|
||||
// returns a system wide unique identifier for this exception. See the
|
||||
// macro below for the typical implementation of this method.
|
||||
// This is used to associate the error with a string description of the
|
||||
// error via the global error table.
|
||||
|
||||
virtual TSTRING GetMsg() const;
|
||||
// returns specific information about the error that occured. Provides
|
||||
// additional information about the error described by GetID(). It should
|
||||
// not provide any information redundant with GetID().
|
||||
//
|
||||
// The string passed to the constructor should be formated properly to
|
||||
// be displayed as the "Second" part of an error message, or the derived
|
||||
// class should override GetMsg() and return a string appropriate for display.
|
||||
|
||||
// returns specific information about the error that occured. Provides
|
||||
// additional information about the error described by GetID(). It should
|
||||
// not provide any information redundant with GetID().
|
||||
//
|
||||
// The string passed to the constructor should be formated properly to
|
||||
// be displayed as the "Second" part of an error message, or the derived
|
||||
// class should override GetMsg() and return a string appropriate for display.
|
||||
|
||||
uint32 GetFlags() const;
|
||||
// Flags are defined below. Currently, these only have an impact on how errors are
|
||||
// displayed.
|
||||
// Flags are defined below. Currently, these only have an impact on how errors are
|
||||
// displayed.
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
// Flags
|
||||
//-------------------------------------------------------------------------
|
||||
enum Flag
|
||||
{
|
||||
NON_FATAL = 0x00000001, // displays "Error" or "Warning" ?
|
||||
SUPRESS_THIRD_MSG = 0x00000002 // supresses the "continuing" or "exiting" message
|
||||
NON_FATAL = 0x00000001, // displays "Error" or "Warning" ?
|
||||
SUPRESS_THIRD_MSG = 0x00000002 // supresses the "continuing" or "exiting" message
|
||||
};
|
||||
|
||||
void SetFlags( uint32 flags );
|
||||
void SetFlags(uint32 flags);
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
// Flag Convenience Methods
|
||||
//-------------------------------------------------------------------------
|
||||
void SetFatality(bool fatal);
|
||||
bool IsFatal() const;
|
||||
// Fatality is set to true by default when eError is constructed. But when an error
|
||||
// it is put in an cErrorBucket chain it the code doing so may wish to set the fatality
|
||||
// to non-fatal to indicate that the error is actually a warning and program flow
|
||||
// is going to continue.
|
||||
void SetSupressThird(bool supressThird);
|
||||
bool SupressThird() const;
|
||||
void SetFatality(bool fatal);
|
||||
bool IsFatal() const;
|
||||
// Fatality is set to true by default when eError is constructed. But when an error
|
||||
// it is put in an cErrorBucket chain it the code doing so may wish to set the fatality
|
||||
// to non-fatal to indicate that the error is actually a warning and program flow
|
||||
// is going to continue.
|
||||
void SetSupressThird(bool supressThird);
|
||||
bool SupressThird() const;
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
// Utility Methods
|
||||
//-------------------------------------------------------------------------
|
||||
static uint32 CalcHash( const char* name );
|
||||
// calculates the CRC32 of the string passed in as name. This methods
|
||||
// asserts that name is non null. This is used to generate unique IDs
|
||||
// for errors.
|
||||
static uint32 CalcHash(const char* name);
|
||||
// calculates the CRC32 of the string passed in as name. This methods
|
||||
// asserts that name is non null. This is used to generate unique IDs
|
||||
// for errors.
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
// Private Implementation
|
||||
|
@ -124,62 +123,69 @@ protected:
|
|||
///////////////////////////////////////////////////////////////////////////////
|
||||
// TSS_BEGIN_EXCEPTION / TSS_END_EXCEPTION
|
||||
//
|
||||
// Serves the same purpose as TSS_EXCEPTION but allows custom data and methods
|
||||
// Serves the same purpose as TSS_EXCEPTION but allows custom data and methods
|
||||
// to be added to the exception class.
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#if HAVE_GCC
|
||||
#define TSS_BEGIN_EXCEPTION_EXPLICIT
|
||||
# define TSS_BEGIN_EXCEPTION_EXPLICIT
|
||||
#else
|
||||
#define TSS_BEGIN_EXCEPTION_EXPLICIT explicit
|
||||
# define TSS_BEGIN_EXCEPTION_EXPLICIT explicit
|
||||
#endif
|
||||
|
||||
#define TSS_BEGIN_EXCEPTION( except, base ) \
|
||||
class except : public base \
|
||||
{\
|
||||
public:\
|
||||
except( const TSTRING& msg, uint32 flags = 0 ) \
|
||||
: base( msg, flags ) {} \
|
||||
TSS_BEGIN_EXCEPTION_EXPLICIT except( const except& rhs ) \
|
||||
: base( rhs ) {} \
|
||||
explicit except() : base() {} \
|
||||
\
|
||||
virtual uint32 GetID() const \
|
||||
{\
|
||||
return CalcHash( #except ); \
|
||||
}\
|
||||
#define TSS_BEGIN_EXCEPTION(except, base) \
|
||||
class except : public base \
|
||||
{ \
|
||||
public: \
|
||||
except(const TSTRING& msg, uint32 flags = 0) : base(msg, flags) \
|
||||
{ \
|
||||
} \
|
||||
TSS_BEGIN_EXCEPTION_EXPLICIT except(const except& rhs) : base(rhs) \
|
||||
{ \
|
||||
} \
|
||||
explicit except() : base() \
|
||||
{ \
|
||||
} \
|
||||
\
|
||||
virtual uint32 GetID() const \
|
||||
{ \
|
||||
return CalcHash(#except); \
|
||||
}
|
||||
|
||||
#define TSS_END_EXCEPTION( ) \
|
||||
};
|
||||
#define TSS_END_EXCEPTION() \
|
||||
} \
|
||||
;
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// TSS_BEGIN_EXCEPTION_NO_CTOR
|
||||
//
|
||||
// Same as TSS_BEGIN_EXCEPTION, but doesn't define any ctors.
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
#define TSS_BEGIN_EXCEPTION_NO_CTOR( except, base ) \
|
||||
class except : public base \
|
||||
{\
|
||||
public:\
|
||||
explicit except() : base() {} \
|
||||
\
|
||||
virtual uint32 GetID() const \
|
||||
{\
|
||||
return CalcHash( #except ); \
|
||||
}\
|
||||
#define TSS_BEGIN_EXCEPTION_NO_CTOR(except, base) \
|
||||
class except : public base \
|
||||
{ \
|
||||
public: \
|
||||
explicit except() : base() \
|
||||
{ \
|
||||
} \
|
||||
\
|
||||
virtual uint32 GetID() const \
|
||||
{ \
|
||||
return CalcHash(#except); \
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// TSS_EXCEPTION
|
||||
//
|
||||
// This is a convenience define for quickly defining an exception class. After
|
||||
// defining a new exception, don't forget to add it to the package's error
|
||||
// defining a new exception, don't forget to add it to the package's error
|
||||
// string file!
|
||||
//
|
||||
// TODO (mdb) -- do we want to cache the CRC? if we store it in a class static
|
||||
// TODO (mdb) -- do we want to cache the CRC? if we store it in a class static
|
||||
// variable, then we will need to define it in the cpp file as well ...
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
#define TSS_EXCEPTION( except, base ) \
|
||||
TSS_BEGIN_EXCEPTION( except, base ) \
|
||||
#define TSS_EXCEPTION(except, base) \
|
||||
TSS_BEGIN_EXCEPTION(except, base) \
|
||||
TSS_END_EXCEPTION()
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
@ -189,41 +195,32 @@ protected:
|
|||
///////////////////////////////////////////////////////////////////////////////
|
||||
// eError
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
inline eError::eError( const TSTRING& msg, uint32 flags )
|
||||
: mMsg ( msg ),
|
||||
mFlags ( flags )
|
||||
inline eError::eError(const TSTRING& msg, uint32 flags) : mMsg(msg), mFlags(flags)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// eError
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
inline eError::eError( const eError& rhs )
|
||||
: mMsg ( rhs.mMsg ),
|
||||
mFlags ( rhs.mFlags )
|
||||
inline eError::eError(const eError& rhs) : mMsg(rhs.mMsg), mFlags(rhs.mFlags)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// eError
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
inline eError::eError( )
|
||||
: mMsg ( _T("") ),
|
||||
mFlags ( 0 )
|
||||
inline eError::eError() : mMsg(_T("")), mFlags(0)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// operator=
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
inline void eError::operator=( const eError& rhs )
|
||||
inline void eError::operator=(const eError& rhs)
|
||||
{
|
||||
mMsg = rhs.mMsg;
|
||||
mFlags = rhs.mFlags;
|
||||
mMsg = rhs.mMsg;
|
||||
mFlags = rhs.mFlags;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -231,7 +228,6 @@ inline void eError::operator=( const eError& rhs )
|
|||
///////////////////////////////////////////////////////////////////////////////
|
||||
inline eError::~eError()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -239,7 +235,7 @@ inline eError::~eError()
|
|||
///////////////////////////////////////////////////////////////////////////////
|
||||
inline TSTRING eError::GetMsg() const
|
||||
{
|
||||
return mMsg;
|
||||
return mMsg;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -253,9 +249,9 @@ inline uint32 eError::GetFlags() const
|
|||
///////////////////////////////////////////////////////////////////////////////
|
||||
// SetFlags
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
inline void eError::SetFlags( uint32 flags )
|
||||
inline void eError::SetFlags(uint32 flags)
|
||||
{
|
||||
mFlags = flags;
|
||||
mFlags = flags;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -275,7 +271,6 @@ inline void eError::SetFatality(bool fatal)
|
|||
inline bool eError::IsFatal() const
|
||||
{
|
||||
return (mFlags & (uint32)NON_FATAL) == 0;
|
||||
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -298,6 +293,4 @@ inline bool eError::SupressThird() const
|
|||
}
|
||||
|
||||
|
||||
|
||||
#endif //__ERROR_H
|
||||
|
||||
|
|
|
@ -3,29 +3,29 @@
|
|||
// Portions created by Tripwire, Inc. are copyright (C) 2000-2018 Tripwire,
|
||||
// Inc. Tripwire is a registered trademark of Tripwire, Inc. All rights
|
||||
// reserved.
|
||||
//
|
||||
//
|
||||
// This program is free software. The contents of this file are subject
|
||||
// to the terms of the GNU General Public License as published by the
|
||||
// Free Software Foundation; either version 2 of the License, or (at your
|
||||
// option) any later version. You may redistribute it and/or modify it
|
||||
// only in compliance with the GNU General Public License.
|
||||
//
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful.
|
||||
// However, this program is distributed AS-IS WITHOUT ANY
|
||||
// WARRANTY; INCLUDING THE IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS
|
||||
// FOR A PARTICULAR PURPOSE. Please see the GNU General Public License
|
||||
// for more details.
|
||||
//
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
|
||||
// USA.
|
||||
//
|
||||
//
|
||||
// Nothing in the GNU General Public License or any other license to use
|
||||
// the code or files shall permit you to use Tripwire's trademarks,
|
||||
// service marks, or other intellectual property without Tripwire's
|
||||
// prior written consent.
|
||||
//
|
||||
//
|
||||
// If you have any questions, please contact Tripwire, Inc. at either
|
||||
// info@tripwire.org or www.tripwire.org.
|
||||
//
|
||||
|
@ -46,32 +46,34 @@
|
|||
class eError;
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// cErrorBucket -- contains an interface that handles error reporting, and
|
||||
// contains a link to a child bucket. Each concrete implementation of the
|
||||
// cErrorBucket -- contains an interface that handles error reporting, and
|
||||
// contains a link to a child bucket. Each concrete implementation of the
|
||||
// cErrorBucket interface will perform its own specific task related to the
|
||||
// error's occurence (print to stderr, store in a queue, etc) and then forward
|
||||
// the error on to its child link. The parent bucket does not own the destruction
|
||||
// the error on to its child link. The parent bucket does not own the destruction
|
||||
// of the pointer to the child bucket.
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
class cErrorBucket
|
||||
{
|
||||
public:
|
||||
cErrorBucket();
|
||||
virtual ~cErrorBucket() {}
|
||||
virtual ~cErrorBucket()
|
||||
{
|
||||
}
|
||||
|
||||
virtual void AddError(const eError& error);
|
||||
// add an error to the bucket
|
||||
// add an error to the bucket
|
||||
|
||||
cErrorBucket* GetChild();
|
||||
// returns the bucket that the current bucket is chained to, or
|
||||
// NULL if nothing is attached to it.
|
||||
// returns the bucket that the current bucket is chained to, or
|
||||
// NULL if nothing is attached to it.
|
||||
cErrorBucket* SetChild(cErrorBucket* pNewChild);
|
||||
// sets the child link of this bucket; returns the old link value
|
||||
// sets the child link of this bucket; returns the old link value
|
||||
|
||||
protected:
|
||||
virtual void HandleError(const eError& error) = 0;
|
||||
// override this to implement error handling functionality specific to
|
||||
// the derived class
|
||||
// override this to implement error handling functionality specific to
|
||||
// the derived class
|
||||
cErrorBucket* mpChild;
|
||||
};
|
||||
|
||||
|
@ -81,8 +83,7 @@ protected:
|
|||
///////////////////
|
||||
// cErrorBucket
|
||||
///////////////////
|
||||
inline cErrorBucket::cErrorBucket() :
|
||||
mpChild(0)
|
||||
inline cErrorBucket::cErrorBucket() : mpChild(0)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -94,9 +95,8 @@ inline cErrorBucket* cErrorBucket::GetChild()
|
|||
inline cErrorBucket* cErrorBucket::SetChild(cErrorBucket* pNewChild)
|
||||
{
|
||||
cErrorBucket* pOldChild = mpChild;
|
||||
mpChild = pNewChild;
|
||||
mpChild = pNewChild;
|
||||
return pOldChild;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
@ -3,29 +3,29 @@
|
|||
// Portions created by Tripwire, Inc. are copyright (C) 2000-2018 Tripwire,
|
||||
// Inc. Tripwire is a registered trademark of Tripwire, Inc. All rights
|
||||
// reserved.
|
||||
//
|
||||
//
|
||||
// This program is free software. The contents of this file are subject
|
||||
// to the terms of the GNU General Public License as published by the
|
||||
// Free Software Foundation; either version 2 of the License, or (at your
|
||||
// option) any later version. You may redistribute it and/or modify it
|
||||
// only in compliance with the GNU General Public License.
|
||||
//
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful.
|
||||
// However, this program is distributed AS-IS WITHOUT ANY
|
||||
// WARRANTY; INCLUDING THE IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS
|
||||
// FOR A PARTICULAR PURPOSE. Please see the GNU General Public License
|
||||
// for more details.
|
||||
//
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
|
||||
// USA.
|
||||
//
|
||||
//
|
||||
// Nothing in the GNU General Public License or any other license to use
|
||||
// the code or files shall permit you to use Tripwire's trademarks,
|
||||
// service marks, or other intellectual property without Tripwire's
|
||||
// prior written consent.
|
||||
//
|
||||
//
|
||||
// If you have any questions, please contact Tripwire, Inc. at either
|
||||
// info@tripwire.org or www.tripwire.org.
|
||||
//
|
||||
|
@ -43,7 +43,7 @@
|
|||
void cErrorBucket::AddError(const eError& error)
|
||||
{
|
||||
HandleError(error);
|
||||
if(mpChild)
|
||||
if (mpChild)
|
||||
mpChild->AddError(error);
|
||||
}
|
||||
|
||||
|
@ -52,10 +52,8 @@ void cErrorBucket::AddError(const eError& error)
|
|||
//#############################################################################
|
||||
void cErrorReporter::PrintErrorMsg(const eError& error, const TSTRING& strExtra)
|
||||
{
|
||||
cDisplayEncoder e(
|
||||
(cDisplayEncoder::Flags) ( cDisplayEncoder::NON_ROUNDTRIP |
|
||||
cDisplayEncoder::ALLOW_WHITESPACE ) );
|
||||
TSTRING errStr;
|
||||
cDisplayEncoder e((cDisplayEncoder::Flags)(cDisplayEncoder::NON_ROUNDTRIP | cDisplayEncoder::ALLOW_WHITESPACE));
|
||||
TSTRING errStr;
|
||||
|
||||
//
|
||||
// if the ID is zero, just return.
|
||||
|
@ -68,19 +66,18 @@ void cErrorReporter::PrintErrorMsg(const eError& error, const TSTRING& strExtra)
|
|||
// point is when we throw ePoly() with no constructor arguments. At some point we want
|
||||
// to stop using the mechanism have non-printing errors, thus we leave in the ASSERT below.
|
||||
// But we don't want to break any release code, thus we return on the next line - June 2, 1999 DMB.
|
||||
ASSERT( error.GetID() != 0 );
|
||||
ASSERT(error.GetID() != 0);
|
||||
|
||||
if( error.GetID() == 0 )
|
||||
if (error.GetID() == 0)
|
||||
return;
|
||||
|
||||
// "First Part" header
|
||||
errStr = TSS_GetString( cCore, error.IsFatal() ? core::STR_ERROR_ERROR
|
||||
: core::STR_ERROR_WARNING );
|
||||
errStr = TSS_GetString(cCore, error.IsFatal() ? core::STR_ERROR_ERROR : core::STR_ERROR_WARNING);
|
||||
|
||||
if (errStr.empty())
|
||||
{
|
||||
TOSTRINGSTREAM strm;
|
||||
ASSERT( sizeof( uint32 ) == sizeof(unsigned int) ); // for cast on next line
|
||||
ASSERT(sizeof(uint32) == sizeof(unsigned int)); // for cast on next line
|
||||
strm << _T("Unknown Error ID ") << (unsigned int)error.GetID();
|
||||
errStr = strm.str();
|
||||
}
|
||||
|
@ -91,10 +88,10 @@ void cErrorReporter::PrintErrorMsg(const eError& error, const TSTRING& strExtra)
|
|||
// "First Part" error string
|
||||
TSTRING prependToSecond;
|
||||
|
||||
// #pragma message("errorbucketimpl.cpp needs a little help in the mb arena, with the findfirst/last and such")
|
||||
// #pragma message("errorbucketimpl.cpp needs a little help in the mb arena, with the findfirst/last and such")
|
||||
|
||||
errStr = cErrorTable::GetInstance()->Get( error.GetID() );
|
||||
if(! errStr.empty())
|
||||
errStr = cErrorTable::GetInstance()->Get(error.GetID());
|
||||
if (!errStr.empty())
|
||||
{
|
||||
// If the first part has a '\n' in it, we take everything following and prepend it to the
|
||||
// second part. This was added to allow specifing a verbose string as the second part
|
||||
|
@ -108,7 +105,7 @@ void cErrorReporter::PrintErrorMsg(const eError& error, const TSTRING& strExtra)
|
|||
|
||||
ASSERT(errStr.length() + len + 6 < 80); // line too big for terminal?
|
||||
// Add 6 to account for "### ' and ': '
|
||||
TCERR << TSS_GetString( cCore, core::STR_ERROR_COLON ) << _T(" ") << errStr;
|
||||
TCERR << TSS_GetString(cCore, core::STR_ERROR_COLON) << _T(" ") << errStr;
|
||||
TCERR << std::endl;
|
||||
}
|
||||
|
||||
|
@ -117,14 +114,14 @@ void cErrorReporter::PrintErrorMsg(const eError& error, const TSTRING& strExtra)
|
|||
const TCHAR SPACE = _T(' ');
|
||||
|
||||
errStr = prependToSecond + error.GetMsg() + strExtra;
|
||||
e.Encode( errStr );
|
||||
if (! errStr.empty())
|
||||
e.Encode(errStr);
|
||||
if (!errStr.empty())
|
||||
{
|
||||
do
|
||||
do
|
||||
{
|
||||
// look for newline chars
|
||||
TSTRING::size_type firstNewLine;
|
||||
TSTRING currentStr = errStr.substr(0, (firstNewLine = errStr.find_first_of(_T('\n'))));
|
||||
TSTRING currentStr = errStr.substr(0, (firstNewLine = errStr.find_first_of(_T('\n'))));
|
||||
errStr.erase(0, (firstNewLine < errStr.length() ? firstNewLine + 1 : firstNewLine));
|
||||
|
||||
// break up the error string in case it is larger than screen width
|
||||
|
@ -132,11 +129,12 @@ void cErrorReporter::PrintErrorMsg(const eError& error, const TSTRING& strExtra)
|
|||
{
|
||||
if (currentStr.length() <= (unsigned int)WIDTH)
|
||||
{
|
||||
TCERR << TSS_GetString( cCore, core::STR_ERROR_HEADER ) << currentStr << std::endl;
|
||||
TCERR << TSS_GetString(cCore, core::STR_ERROR_HEADER) << currentStr << std::endl;
|
||||
break;
|
||||
}
|
||||
|
||||
TSTRING::size_type lastSpace = currentStr.find_last_of(SPACE, currentStr.length() >= WIDTH - 1 ? WIDTH - 1 : TSTRING::npos);
|
||||
TSTRING::size_type lastSpace =
|
||||
currentStr.find_last_of(SPACE, currentStr.length() >= WIDTH - 1 ? WIDTH - 1 : TSTRING::npos);
|
||||
if (lastSpace == TSTRING::npos)
|
||||
{
|
||||
// can't find space to break at so this string will just have to be longer than screen width.
|
||||
|
@ -148,28 +146,21 @@ void cErrorReporter::PrintErrorMsg(const eError& error, const TSTRING& strExtra)
|
|||
lastSpace = currentStr.length();
|
||||
}
|
||||
|
||||
TCERR << TSS_GetString( cCore, core::STR_ERROR_HEADER )
|
||||
<< currentStr.substr( 0, lastSpace )
|
||||
<< std::endl;
|
||||
TCERR << TSS_GetString(cCore, core::STR_ERROR_HEADER) << currentStr.substr(0, lastSpace) << std::endl;
|
||||
|
||||
currentStr.erase( 0, lastSpace + 1 );
|
||||
}
|
||||
while ( !currentStr.empty() );
|
||||
}
|
||||
while ( !errStr.empty() );
|
||||
currentStr.erase(0, lastSpace + 1);
|
||||
} while (!currentStr.empty());
|
||||
} while (!errStr.empty());
|
||||
}
|
||||
|
||||
// "Third Part" print 'exiting' or 'continuing'
|
||||
// note that we supress this part if the appropriate flag is set...
|
||||
//
|
||||
if( (error.GetFlags() & eError::SUPRESS_THIRD_MSG) == 0 )
|
||||
if ((error.GetFlags() & eError::SUPRESS_THIRD_MSG) == 0)
|
||||
{
|
||||
TCERR << TSS_GetString( cCore, core::STR_ERROR_HEADER)
|
||||
<< TSS_GetString(
|
||||
cCore,
|
||||
error.IsFatal()
|
||||
? core::STR_ERROR_EXITING
|
||||
: core::STR_ERROR_CONTINUING ) << std::endl;
|
||||
TCERR << TSS_GetString(cCore, core::STR_ERROR_HEADER)
|
||||
<< TSS_GetString(cCore, error.IsFatal() ? core::STR_ERROR_EXITING : core::STR_ERROR_CONTINUING)
|
||||
<< std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -185,9 +176,7 @@ void cErrorTracer::HandleError(const eError& error)
|
|||
{
|
||||
cDebug d("cErrorTracer::HandleError");
|
||||
|
||||
d.TraceError( _T("%s : %s\n"),
|
||||
cErrorTable::GetInstance()->Get( error.GetID() ).c_str(),
|
||||
error.GetMsg().c_str() );
|
||||
d.TraceError(_T("%s : %s\n"), cErrorTable::GetInstance()->Get(error.GetID()).c_str(), error.GetMsg().c_str());
|
||||
}
|
||||
|
||||
//#############################################################################
|
||||
|
@ -207,17 +196,15 @@ int cErrorQueue::GetNumErrors() const
|
|||
|
||||
void cErrorQueue::HandleError(const eError& error)
|
||||
{
|
||||
mList.push_back( ePoly( error ) );
|
||||
mList.push_back(ePoly(error));
|
||||
}
|
||||
|
||||
cErrorQueueIter::cErrorQueueIter(cErrorQueue& queue) :
|
||||
mList(queue.mList)
|
||||
cErrorQueueIter::cErrorQueueIter(cErrorQueue& queue) : mList(queue.mList)
|
||||
{
|
||||
SeekBegin();
|
||||
}
|
||||
|
||||
cErrorQueueIter::cErrorQueueIter(const cErrorQueue& queue)
|
||||
: mList( ((cErrorQueue*)&queue)->mList )
|
||||
cErrorQueueIter::cErrorQueueIter(const cErrorQueue& queue) : mList(((cErrorQueue*)&queue)->mList)
|
||||
{
|
||||
SeekBegin();
|
||||
}
|
||||
|
@ -240,7 +227,7 @@ bool cErrorQueueIter::Done() const
|
|||
|
||||
const ePoly& cErrorQueueIter::GetError() const
|
||||
{
|
||||
ASSERT(! Done());
|
||||
ASSERT(!Done());
|
||||
return (*mIter);
|
||||
}
|
||||
|
||||
|
@ -255,19 +242,18 @@ void cErrorQueue::Read(iSerializer* pSerializer, int32 version)
|
|||
int32 size;
|
||||
mList.clear();
|
||||
pSerializer->ReadInt32(size);
|
||||
for(int i = 0; i < size; ++i)
|
||||
for (int i = 0; i < size; ++i)
|
||||
{
|
||||
int32 errorNumber;
|
||||
TSTRING errorString;
|
||||
int32 flags;
|
||||
|
||||
pSerializer->ReadInt32 (errorNumber);
|
||||
pSerializer->ReadString (errorString);
|
||||
pSerializer->ReadInt32 (flags);
|
||||
pSerializer->ReadInt32(errorNumber);
|
||||
pSerializer->ReadString(errorString);
|
||||
pSerializer->ReadInt32(flags);
|
||||
|
||||
mList.push_back( ePoly( errorNumber, errorString, flags ) );
|
||||
mList.push_back(ePoly(errorNumber, errorString, flags));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -277,13 +263,12 @@ void cErrorQueue::Write(iSerializer* pSerializer) const
|
|||
{
|
||||
pSerializer->WriteInt32(mList.size());
|
||||
ListType::const_iterator i;
|
||||
for( i = mList.begin(); i != mList.end(); ++i)
|
||||
for (i = mList.begin(); i != mList.end(); ++i)
|
||||
{
|
||||
pSerializer->WriteInt32 ((*i).GetID());
|
||||
pSerializer->WriteInt32((*i).GetID());
|
||||
pSerializer->WriteString((*i).GetMsg());
|
||||
pSerializer->WriteInt32 ((*i).GetFlags());
|
||||
pSerializer->WriteInt32((*i).GetFlags());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -292,15 +277,14 @@ void cErrorQueue::Write(iSerializer* pSerializer) const
|
|||
///////////////////////////////////////////////////////////////////////////////
|
||||
void cErrorQueue::TraceContents(int dl) const
|
||||
{
|
||||
if(dl < 0)
|
||||
if (dl < 0)
|
||||
dl = cDebug::D_DEBUG;
|
||||
|
||||
cDebug d("cFCOErrorQueue::TraceContents");
|
||||
|
||||
cDebug d("cFCOErrorQueue::TraceContents");
|
||||
ListType::const_iterator i;
|
||||
int counter = 0;
|
||||
for(i = mList.begin(); i != mList.end(); i++, counter++)
|
||||
int counter = 0;
|
||||
for (i = mList.begin(); i != mList.end(); i++, counter++)
|
||||
{
|
||||
d.Trace(dl, _T("Error[%d]: num = %x string = %s\n") , counter, (*i).GetID(), (*i).GetMsg().c_str());
|
||||
d.Trace(dl, _T("Error[%d]: num = %x string = %s\n"), counter, (*i).GetID(), (*i).GetMsg().c_str());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -3,35 +3,35 @@
|
|||
// Portions created by Tripwire, Inc. are copyright (C) 2000-2018 Tripwire,
|
||||
// Inc. Tripwire is a registered trademark of Tripwire, Inc. All rights
|
||||
// reserved.
|
||||
//
|
||||
//
|
||||
// This program is free software. The contents of this file are subject
|
||||
// to the terms of the GNU General Public License as published by the
|
||||
// Free Software Foundation; either version 2 of the License, or (at your
|
||||
// option) any later version. You may redistribute it and/or modify it
|
||||
// only in compliance with the GNU General Public License.
|
||||
//
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful.
|
||||
// However, this program is distributed AS-IS WITHOUT ANY
|
||||
// WARRANTY; INCLUDING THE IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS
|
||||
// FOR A PARTICULAR PURPOSE. Please see the GNU General Public License
|
||||
// for more details.
|
||||
//
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
|
||||
// USA.
|
||||
//
|
||||
//
|
||||
// Nothing in the GNU General Public License or any other license to use
|
||||
// the code or files shall permit you to use Tripwire's trademarks,
|
||||
// service marks, or other intellectual property without Tripwire's
|
||||
// prior written consent.
|
||||
//
|
||||
//
|
||||
// If you have any questions, please contact Tripwire, Inc. at either
|
||||
// info@tripwire.org or www.tripwire.org.
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// errorbucketimpl.h
|
||||
//
|
||||
//
|
||||
// This component contains classes derived from cErrorBucket and helper classes.
|
||||
// They were broken out of errorbucket.h becuase many components will only need to
|
||||
// know about cErrorBucket, so we reduce system dependencies by keeping these classes
|
||||
|
@ -60,22 +60,22 @@
|
|||
#endif
|
||||
|
||||
//////////////////////////////////////////////////////
|
||||
// cErrorReporter -- sends all error messages to
|
||||
// cErrorReporter -- sends all error messages to
|
||||
// stderr
|
||||
//////////////////////////////////////////////////////
|
||||
class cErrorReporter : public cErrorBucket
|
||||
{
|
||||
public:
|
||||
static void PrintErrorMsg(const eError& error, const TSTRING& strExtra = _T(""));
|
||||
// function that HandleError() uses to print the error messages to stderr.
|
||||
// this function uses the current authoritative format for error reporting, so
|
||||
// other functions needing to display errors to the user should use this.
|
||||
//
|
||||
// function that HandleError() uses to print the error messages to stderr.
|
||||
// this function uses the current authoritative format for error reporting, so
|
||||
// other functions needing to display errors to the user should use this.
|
||||
//
|
||||
|
||||
// NOTE:bam 5/7/99 -- I don't think the below is true anymore?
|
||||
// NOTE:mdb -- if the error has an ID of zero, nothing will be printed. This
|
||||
// is a way to throw a fatal error where the error reporting has already
|
||||
// occurred.
|
||||
// NOTE:bam 5/7/99 -- I don't think the below is true anymore?
|
||||
// NOTE:mdb -- if the error has an ID of zero, nothing will be printed. This
|
||||
// is a way to throw a fatal error where the error reporting has already
|
||||
// occurred.
|
||||
|
||||
protected:
|
||||
virtual void HandleError(const eError& error);
|
||||
|
@ -100,17 +100,18 @@ protected:
|
|||
class cErrorQueue : public cErrorBucket, public iTypedSerializable
|
||||
{
|
||||
friend class cErrorQueueIter;
|
||||
|
||||
public:
|
||||
void Clear();
|
||||
// remove all errors from the queue
|
||||
void Clear();
|
||||
// remove all errors from the queue
|
||||
int GetNumErrors() const;
|
||||
// returns how many errors are in the queue
|
||||
// returns how many errors are in the queue
|
||||
|
||||
//
|
||||
// iSerializable interface
|
||||
//
|
||||
virtual void Read (iSerializer* pSerializer, int32 version = 0); // throw (eSerializer, eArchive)
|
||||
virtual void Write(iSerializer* pSerializer) const; // throw (eSerializer, eArchive)
|
||||
virtual void Read(iSerializer* pSerializer, int32 version = 0); // throw (eSerializer, eArchive)
|
||||
virtual void Write(iSerializer* pSerializer) const; // throw (eSerializer, eArchive)
|
||||
|
||||
//
|
||||
// Debugging
|
||||
|
@ -119,9 +120,10 @@ public:
|
|||
|
||||
protected:
|
||||
virtual void HandleError(const eError& error);
|
||||
|
||||
private:
|
||||
typedef std::list<ePoly> ListType;
|
||||
ListType mList;
|
||||
ListType mList;
|
||||
|
||||
DECLARE_TYPEDSERIALIZABLE()
|
||||
};
|
||||
|
@ -131,7 +133,9 @@ class cErrorQueueIter
|
|||
public:
|
||||
cErrorQueueIter(cErrorQueue& queue);
|
||||
cErrorQueueIter(const cErrorQueue& queue);
|
||||
~cErrorQueueIter() {}
|
||||
~cErrorQueueIter()
|
||||
{
|
||||
}
|
||||
|
||||
// iteration methods
|
||||
void SeekBegin();
|
||||
|
@ -139,9 +143,9 @@ public:
|
|||
bool Done() const;
|
||||
|
||||
// access to the error
|
||||
const ePoly& GetError() const;
|
||||
// both of these return results are undefined if the iterator
|
||||
// is not valid (ie - IsDone() == true)
|
||||
const ePoly& GetError() const;
|
||||
// both of these return results are undefined if the iterator
|
||||
// is not valid (ie - IsDone() == true)
|
||||
private:
|
||||
cErrorQueue::ListType& mList;
|
||||
cErrorQueue::ListType::iterator mIter;
|
||||
|
@ -153,9 +157,14 @@ private:
|
|||
//////////////////////////////////////////////////////
|
||||
class cErrorBucketNull : public cErrorBucket
|
||||
{
|
||||
virtual void AddError(const eError& ) {}
|
||||
virtual void AddError(const eError&)
|
||||
{
|
||||
}
|
||||
|
||||
protected:
|
||||
virtual void HandleError(const eError& ) {}
|
||||
virtual void HandleError(const eError&)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
//////////////////////////////////////////////////////
|
||||
|
@ -165,10 +174,10 @@ protected:
|
|||
class cErrorBucketPassThru : public cErrorBucket
|
||||
{
|
||||
protected:
|
||||
virtual void HandleError(const eError& ) {}
|
||||
virtual void HandleError(const eError&)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
@ -3,34 +3,34 @@
|
|||
// Portions created by Tripwire, Inc. are copyright (C) 2000-2018 Tripwire,
|
||||
// Inc. Tripwire is a registered trademark of Tripwire, Inc. All rights
|
||||
// reserved.
|
||||
//
|
||||
//
|
||||
// This program is free software. The contents of this file are subject
|
||||
// to the terms of the GNU General Public License as published by the
|
||||
// Free Software Foundation; either version 2 of the License, or (at your
|
||||
// option) any later version. You may redistribute it and/or modify it
|
||||
// only in compliance with the GNU General Public License.
|
||||
//
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful.
|
||||
// However, this program is distributed AS-IS WITHOUT ANY
|
||||
// WARRANTY; INCLUDING THE IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS
|
||||
// FOR A PARTICULAR PURPOSE. Please see the GNU General Public License
|
||||
// for more details.
|
||||
//
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
|
||||
// USA.
|
||||
//
|
||||
//
|
||||
// Nothing in the GNU General Public License or any other license to use
|
||||
// the code or files shall permit you to use Tripwire's trademarks,
|
||||
// service marks, or other intellectual property without Tripwire's
|
||||
// prior written consent.
|
||||
//
|
||||
//
|
||||
// If you have any questions, please contact Tripwire, Inc. at either
|
||||
// info@tripwire.org or www.tripwire.org.
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// errorgeneral.h --
|
||||
// errorgeneral.h --
|
||||
//
|
||||
|
||||
#ifndef __ERRORGENERAL_H
|
||||
|
@ -38,12 +38,11 @@
|
|||
|
||||
#include "error.h"
|
||||
|
||||
TSS_EXCEPTION( eErrorGeneral, eError );
|
||||
TSS_EXCEPTION( eOpen, eErrorGeneral );
|
||||
TSS_EXCEPTION( eOpenRead, eErrorGeneral );
|
||||
TSS_EXCEPTION( eOpenWrite, eErrorGeneral );
|
||||
TSS_EXCEPTION( eBadCmdLine, eErrorGeneral );
|
||||
TSS_EXCEPTION( eBadModeSwitch, eErrorGeneral );
|
||||
TSS_EXCEPTION(eErrorGeneral, eError);
|
||||
TSS_EXCEPTION(eOpen, eErrorGeneral);
|
||||
TSS_EXCEPTION(eOpenRead, eErrorGeneral);
|
||||
TSS_EXCEPTION(eOpenWrite, eErrorGeneral);
|
||||
TSS_EXCEPTION(eBadCmdLine, eErrorGeneral);
|
||||
TSS_EXCEPTION(eBadModeSwitch, eErrorGeneral);
|
||||
|
||||
#endif //#ifndef __ERRORGENERAL_H
|
||||
|
||||
|
|
|
@ -3,29 +3,29 @@
|
|||
// Portions created by Tripwire, Inc. are copyright (C) 2000-2018 Tripwire,
|
||||
// Inc. Tripwire is a registered trademark of Tripwire, Inc. All rights
|
||||
// reserved.
|
||||
//
|
||||
//
|
||||
// This program is free software. The contents of this file are subject
|
||||
// to the terms of the GNU General Public License as published by the
|
||||
// Free Software Foundation; either version 2 of the License, or (at your
|
||||
// option) any later version. You may redistribute it and/or modify it
|
||||
// only in compliance with the GNU General Public License.
|
||||
//
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful.
|
||||
// However, this program is distributed AS-IS WITHOUT ANY
|
||||
// WARRANTY; INCLUDING THE IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS
|
||||
// FOR A PARTICULAR PURPOSE. Please see the GNU General Public License
|
||||
// for more details.
|
||||
//
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
|
||||
// USA.
|
||||
//
|
||||
//
|
||||
// Nothing in the GNU General Public License or any other license to use
|
||||
// the code or files shall permit you to use Tripwire's trademarks,
|
||||
// service marks, or other intellectual property without Tripwire's
|
||||
// prior written consent.
|
||||
//
|
||||
//
|
||||
// If you have any questions, please contact Tripwire, Inc. at either
|
||||
// info@tripwire.org or www.tripwire.org.
|
||||
//
|
||||
|
@ -64,18 +64,18 @@ void cErrorTable::AssertMsgValidity(const TCHAR* msg)
|
|||
if (errSize == TSTRING::npos)
|
||||
errSize = errStr.length();
|
||||
|
||||
#if 0 //TODO: Figure out how to do this properly.
|
||||
# if 0 //TODO: Figure out how to do this properly.
|
||||
TSTRING::size_type errorSize = TSS_GetString( cCore, core::STR_ERROR_ERROR ).length();
|
||||
TSTRING::size_type warningSize = TSS_GetString( cCore, core::STR_ERROR_WARNING ).length();
|
||||
TSTRING::size_type maxHeaderSize = (errorSize > warningSize ? errorSize : warningSize) + 6; // Add 6 to account for "### ' and ': '
|
||||
#else
|
||||
# else
|
||||
// Sunpro got stuck in an infinite loop when we called GetString from this func;
|
||||
TSTRING::size_type errorSize = 9;
|
||||
TSTRING::size_type errorSize = 9;
|
||||
TSTRING::size_type warningSize = 10;
|
||||
TSTRING::size_type maxHeaderSize = (errorSize > warningSize ? errorSize : warningSize) + 6; // Add 6 to account for "### ' and ': '
|
||||
#endif
|
||||
TSTRING::size_type maxHeaderSize =
|
||||
(errorSize > warningSize ? errorSize : warningSize) + 6; // Add 6 to account for "### ' and ': '
|
||||
# endif
|
||||
|
||||
ASSERT(maxHeaderSize + errSize < 80);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
|
|
@ -3,29 +3,29 @@
|
|||
// Portions created by Tripwire, Inc. are copyright (C) 2000-2018 Tripwire,
|
||||
// Inc. Tripwire is a registered trademark of Tripwire, Inc. All rights
|
||||
// reserved.
|
||||
//
|
||||
//
|
||||
// This program is free software. The contents of this file are subject
|
||||
// to the terms of the GNU General Public License as published by the
|
||||
// Free Software Foundation; either version 2 of the License, or (at your
|
||||
// option) any later version. You may redistribute it and/or modify it
|
||||
// only in compliance with the GNU General Public License.
|
||||
//
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful.
|
||||
// However, this program is distributed AS-IS WITHOUT ANY
|
||||
// WARRANTY; INCLUDING THE IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS
|
||||
// FOR A PARTICULAR PURPOSE. Please see the GNU General Public License
|
||||
// for more details.
|
||||
//
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
|
||||
// USA.
|
||||
//
|
||||
//
|
||||
// Nothing in the GNU General Public License or any other license to use
|
||||
// the code or files shall permit you to use Tripwire's trademarks,
|
||||
// service marks, or other intellectual property without Tripwire's
|
||||
// prior written consent.
|
||||
//
|
||||
//
|
||||
// If you have any questions, please contact Tripwire, Inc. at either
|
||||
// info@tripwire.org or www.tripwire.org.
|
||||
//
|
||||
|
@ -34,7 +34,7 @@
|
|||
// Date: 30 April 99
|
||||
// Creator: mdb
|
||||
//
|
||||
// cErrorTable -- singleton derived from Resource_<> that serves as the global
|
||||
// cErrorTable -- singleton derived from Resource_<> that serves as the global
|
||||
// error id to string mapping
|
||||
//
|
||||
#ifndef __ERRORTABLE_H
|
||||
|
@ -59,36 +59,36 @@ public:
|
|||
//
|
||||
// Convenience Methods
|
||||
//
|
||||
void Put( const eError& e, const TCHAR* msg );
|
||||
void Put(const eError& e, const TCHAR* msg);
|
||||
//
|
||||
// Singleton Interface
|
||||
//
|
||||
static cErrorTable* GetInstance();
|
||||
|
||||
private:
|
||||
#ifdef DEBUG
|
||||
#ifdef DEBUG
|
||||
static void AssertMsgValidity(const TCHAR* msg);
|
||||
#endif
|
||||
#endif
|
||||
};
|
||||
|
||||
inline void cErrorTable::Put( const eError& e, const TCHAR* msg )
|
||||
inline void cErrorTable::Put(const eError& e, const TCHAR* msg)
|
||||
{
|
||||
#ifdef DEBUG
|
||||
#ifdef DEBUG
|
||||
AssertMsgValidity(msg);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
inherited::Put( e.GetID(), msg );
|
||||
inherited::Put(e.GetID(), msg);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Convenience Macros
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// These macros make it easy for a module to register errors with the global
|
||||
// These macros make it easy for a module to register errors with the global
|
||||
// error table. Them like this:
|
||||
//
|
||||
// // animalerrors.h
|
||||
// //
|
||||
// //
|
||||
// TSS_DECLARE_ERROR_REGISTRATION( animal )
|
||||
//
|
||||
// // animalerrors.cpp
|
||||
|
@ -109,32 +109,27 @@ inline void cErrorTable::Put( const eError& e, const TCHAR* msg )
|
|||
//===================
|
||||
// cpp file macros
|
||||
//===================
|
||||
#define TSS_BEGIN_ERROR_REGISTRATION( pkgName ) \
|
||||
RegisterErrors##pkgName::RegisterErrors##pkgName() \
|
||||
{
|
||||
# define TSS_BEGIN_ERROR_REGISTRATION(pkgName) \
|
||||
RegisterErrors##pkgName::RegisterErrors##pkgName() \
|
||||
{
|
||||
|
||||
#define TSS_REGISTER_ERROR( err, str ) \
|
||||
cErrorTable::GetInstance()->Put \
|
||||
( err, str );
|
||||
# define TSS_REGISTER_ERROR(err, str) cErrorTable::GetInstance()->Put(err, str);
|
||||
|
||||
#define TSS_END_ERROR_REGISTRATION() \
|
||||
}
|
||||
# define TSS_END_ERROR_REGISTRATION() }
|
||||
|
||||
//===================
|
||||
// h file macros
|
||||
//===================
|
||||
#define TSS_DECLARE_ERROR_REGISTRATION( pkgName ) \
|
||||
struct RegisterErrors##pkgName \
|
||||
{\
|
||||
RegisterErrors##pkgName(); \
|
||||
};
|
||||
# define TSS_DECLARE_ERROR_REGISTRATION(pkgName) \
|
||||
struct RegisterErrors##pkgName \
|
||||
{ \
|
||||
RegisterErrors##pkgName(); \
|
||||
};
|
||||
|
||||
//===================
|
||||
// package init macros
|
||||
//===================
|
||||
#define TSS_REGISTER_PKG_ERRORS( pkgName ) \
|
||||
RegisterErrors##pkgName register##pkgName;
|
||||
# define TSS_REGISTER_PKG_ERRORS(pkgName) RegisterErrors##pkgName register##pkgName;
|
||||
|
||||
|
||||
#endif //__ERRORTABLE_H
|
||||
|
||||
|
|
|
@ -3,29 +3,29 @@
|
|||
// Portions created by Tripwire, Inc. are copyright (C) 2000-2018 Tripwire,
|
||||
// Inc. Tripwire is a registered trademark of Tripwire, Inc. All rights
|
||||
// reserved.
|
||||
//
|
||||
//
|
||||
// This program is free software. The contents of this file are subject
|
||||
// to the terms of the GNU General Public License as published by the
|
||||
// Free Software Foundation; either version 2 of the License, or (at your
|
||||
// option) any later version. You may redistribute it and/or modify it
|
||||
// only in compliance with the GNU General Public License.
|
||||
//
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful.
|
||||
// However, this program is distributed AS-IS WITHOUT ANY
|
||||
// WARRANTY; INCLUDING THE IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS
|
||||
// FOR A PARTICULAR PURPOSE. Please see the GNU General Public License
|
||||
// for more details.
|
||||
//
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
|
||||
// USA.
|
||||
//
|
||||
//
|
||||
// Nothing in the GNU General Public License or any other license to use
|
||||
// the code or files shall permit you to use Tripwire's trademarks,
|
||||
// service marks, or other intellectual property without Tripwire's
|
||||
// prior written consent.
|
||||
//
|
||||
//
|
||||
// If you have any questions, please contact Tripwire, Inc. at either
|
||||
// info@tripwire.org or www.tripwire.org.
|
||||
//
|
||||
|
@ -37,20 +37,19 @@
|
|||
#include "corestrings.h"
|
||||
|
||||
//=============================================================================
|
||||
// class eInternal
|
||||
// class eInternal
|
||||
//=============================================================================
|
||||
|
||||
namespace //unique
|
||||
{
|
||||
TCHAR* tw_itot( int value, TCHAR* string, int radix, int size)
|
||||
{
|
||||
snprintf( string, size, "%d", value );
|
||||
return string;
|
||||
}
|
||||
TCHAR* tw_itot(int value, TCHAR* string, int radix, int size)
|
||||
{
|
||||
snprintf(string, size, "%d", value);
|
||||
return string;
|
||||
}
|
||||
} // namespace
|
||||
|
||||
eInternal::eInternal(TCHAR* sourceFile, int lineNum)
|
||||
: eError(_T(""))
|
||||
eInternal::eInternal(TCHAR* sourceFile, int lineNum) : eError(_T(""))
|
||||
{
|
||||
TCHAR buf[256];
|
||||
|
||||
|
@ -67,18 +66,17 @@ eInternal::eInternal(TCHAR* sourceFile, int lineNum)
|
|||
///////////////////////////////////////////////////////////////////////////////
|
||||
// MakeFileError
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
TSTRING cErrorUtil::MakeFileError( const TSTRING& msg, const TSTRING& fileName )
|
||||
TSTRING cErrorUtil::MakeFileError(const TSTRING& msg, const TSTRING& fileName)
|
||||
{
|
||||
TSTRING ret;
|
||||
ret = TSS_GetString( cCore, core::STR_ERR2_FILENAME );
|
||||
ret.append( fileName );
|
||||
ret.append( 1, _T('\n') );
|
||||
ret = TSS_GetString(cCore, core::STR_ERR2_FILENAME);
|
||||
ret.append(fileName);
|
||||
ret.append(1, _T('\n'));
|
||||
|
||||
if ( msg.length() > 0 )
|
||||
if (msg.length() > 0)
|
||||
{
|
||||
ret.append(msg);
|
||||
}
|
||||
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
|
|
@ -3,29 +3,29 @@
|
|||
// Portions created by Tripwire, Inc. are copyright (C) 2000-2018 Tripwire,
|
||||
// Inc. Tripwire is a registered trademark of Tripwire, Inc. All rights
|
||||
// reserved.
|
||||
//
|
||||
//
|
||||
// This program is free software. The contents of this file are subject
|
||||
// to the terms of the GNU General Public License as published by the
|
||||
// Free Software Foundation; either version 2 of the License, or (at your
|
||||
// option) any later version. You may redistribute it and/or modify it
|
||||
// only in compliance with the GNU General Public License.
|
||||
//
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful.
|
||||
// However, this program is distributed AS-IS WITHOUT ANY
|
||||
// WARRANTY; INCLUDING THE IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS
|
||||
// FOR A PARTICULAR PURPOSE. Please see the GNU General Public License
|
||||
// for more details.
|
||||
//
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
|
||||
// USA.
|
||||
//
|
||||
//
|
||||
// Nothing in the GNU General Public License or any other license to use
|
||||
// the code or files shall permit you to use Tripwire's trademarks,
|
||||
// service marks, or other intellectual property without Tripwire's
|
||||
// prior written consent.
|
||||
//
|
||||
//
|
||||
// If you have any questions, please contact Tripwire, Inc. at either
|
||||
// info@tripwire.org or www.tripwire.org.
|
||||
//
|
||||
|
@ -39,7 +39,7 @@
|
|||
// eInternal -- internal logic errors ( ie -- programming mistakes )
|
||||
// ePoly -- "polymorphic" error that takes its ID as input instead
|
||||
// of from its class name
|
||||
// ThrowAndAssert -- asserts false and throws the specified exception
|
||||
// ThrowAndAssert -- asserts false and throws the specified exception
|
||||
//
|
||||
#ifndef __ERRORUTIL_H
|
||||
#define __ERRORUTIL_H
|
||||
|
@ -58,27 +58,27 @@ public:
|
|||
//-------------------------------------------------------------------------
|
||||
// Construction and Assignment
|
||||
//-------------------------------------------------------------------------
|
||||
ePoly( uint32 id, const TSTRING& msg, uint32 flags = 0 );
|
||||
explicit ePoly( const eError& rhs );
|
||||
explicit ePoly();
|
||||
void operator=( const eError& rhs );
|
||||
ePoly(uint32 id, const TSTRING& msg, uint32 flags = 0);
|
||||
explicit ePoly(const eError& rhs);
|
||||
explicit ePoly();
|
||||
void operator=(const eError& rhs);
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
// ID manipulation
|
||||
//-------------------------------------------------------------------------
|
||||
virtual uint32 GetID() const;
|
||||
void SetID( uint32 id );
|
||||
virtual uint32 GetID() const;
|
||||
void SetID(uint32 id);
|
||||
|
||||
private:
|
||||
uint32 mID;
|
||||
uint32 mID;
|
||||
};
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// eInternal
|
||||
//-----------------------------------------------------------------------------
|
||||
TSS_BEGIN_EXCEPTION( eInternal, eError )
|
||||
TSS_BEGIN_EXCEPTION(eInternal, eError)
|
||||
public:
|
||||
eInternal( TCHAR* file, int lineNum );
|
||||
eInternal(TCHAR* file, int lineNum);
|
||||
TSS_END_EXCEPTION()
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
@ -87,28 +87,32 @@ TSS_END_EXCEPTION()
|
|||
class cErrorUtil
|
||||
{
|
||||
public:
|
||||
static TSTRING MakeFileError( const TSTRING& msg, const TSTRING& fileName );
|
||||
// constructs an error message of the form:
|
||||
// File: <fileName> \n <msg>
|
||||
// This is useful for constructing strings to pass as the msg parameter
|
||||
// to eError constructors.
|
||||
static TSTRING MakeFileError(const TSTRING& msg, const TSTRING& fileName);
|
||||
// constructs an error message of the form:
|
||||
// File: <fileName> \n <msg>
|
||||
// This is useful for constructing strings to pass as the msg parameter
|
||||
// to eError constructors.
|
||||
};
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Convenience Macros
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// NOTE -- we require the developer to supply the file name instead of using
|
||||
// NOTE -- we require the developer to supply the file name instead of using
|
||||
// __FILE__ because that includes the full path to the file, which we
|
||||
// would not like to display to the user.
|
||||
//
|
||||
#define INTERNAL_ERROR(filename) eInternal((TCHAR*)_T(filename), __LINE__)
|
||||
#define THROW_INTERNAL(filename) throw eInternal((TCHAR*)_T(filename), __LINE__)
|
||||
#define INTERNAL_ERROR(filename) eInternal((TCHAR*)_T(filename), __LINE__)
|
||||
#define THROW_INTERNAL(filename) throw eInternal((TCHAR*)_T(filename), __LINE__)
|
||||
|
||||
|
||||
// TODO: ASSERT is always fatal in Unix, perhaps we could #ifdef the ASSERT
|
||||
// to echo to cout the line number the exception occured at?
|
||||
#define ThrowAndAssert(exception) { ASSERT(false); throw exception; }
|
||||
#define ThrowAndAssert(exception) \
|
||||
{ \
|
||||
ASSERT(false); \
|
||||
throw exception; \
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
@ -118,17 +122,14 @@ public:
|
|||
///////////////////////////////////////////////////////////////////////////////
|
||||
// ePoly
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
inline ePoly::ePoly( uint32 id, const TSTRING& msg, uint32 flags )
|
||||
: eError( msg, flags ),
|
||||
mID( id )
|
||||
inline ePoly::ePoly(uint32 id, const TSTRING& msg, uint32 flags) : eError(msg, flags), mID(id)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// ePoly
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
inline ePoly::ePoly( const eError& rhs )
|
||||
inline ePoly::ePoly(const eError& rhs)
|
||||
{
|
||||
*this = rhs;
|
||||
}
|
||||
|
@ -136,21 +137,18 @@ inline ePoly::ePoly( const eError& rhs )
|
|||
///////////////////////////////////////////////////////////////////////////////
|
||||
// ePoly
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
inline ePoly::ePoly()
|
||||
: eError( _T("") ),
|
||||
mID( 0 )
|
||||
inline ePoly::ePoly() : eError(_T("")), mID(0)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// operator=
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
inline void ePoly::operator=( const eError& rhs )
|
||||
inline void ePoly::operator=(const eError& rhs)
|
||||
{
|
||||
mMsg = rhs.GetMsg();
|
||||
mMsg = rhs.GetMsg();
|
||||
mFlags = rhs.GetFlags();
|
||||
mID = rhs.GetID();
|
||||
mID = rhs.GetID();
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -164,10 +162,9 @@ inline uint32 ePoly::GetID() const
|
|||
///////////////////////////////////////////////////////////////////////////////
|
||||
// SetID
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
inline void ePoly::SetID( uint32 id )
|
||||
inline void ePoly::SetID(uint32 id)
|
||||
{
|
||||
mID = id;
|
||||
mID = id;
|
||||
}
|
||||
|
||||
#endif //__ERRORUTIL_H
|
||||
|
||||
|
|
129
src/core/file.h
129
src/core/file.h
|
@ -3,29 +3,29 @@
|
|||
// Portions created by Tripwire, Inc. are copyright (C) 2000-2018 Tripwire,
|
||||
// Inc. Tripwire is a registered trademark of Tripwire, Inc. All rights
|
||||
// reserved.
|
||||
//
|
||||
//
|
||||
// This program is free software. The contents of this file are subject
|
||||
// to the terms of the GNU General Public License as published by the
|
||||
// Free Software Foundation; either version 2 of the License, or (at your
|
||||
// option) any later version. You may redistribute it and/or modify it
|
||||
// only in compliance with the GNU General Public License.
|
||||
//
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful.
|
||||
// However, this program is distributed AS-IS WITHOUT ANY
|
||||
// WARRANTY; INCLUDING THE IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS
|
||||
// FOR A PARTICULAR PURPOSE. Please see the GNU General Public License
|
||||
// for more details.
|
||||
//
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
|
||||
// USA.
|
||||
//
|
||||
//
|
||||
// Nothing in the GNU General Public License or any other license to use
|
||||
// the code or files shall permit you to use Tripwire's trademarks,
|
||||
// service marks, or other intellectual property without Tripwire's
|
||||
// prior written consent.
|
||||
//
|
||||
//
|
||||
// If you have any questions, please contact Tripwire, Inc. at either
|
||||
// info@tripwire.org or www.tripwire.org.
|
||||
//
|
||||
|
@ -55,86 +55,88 @@
|
|||
// eFile exception class
|
||||
//=============================================================================
|
||||
|
||||
TSS_FILE_EXCEPTION( eFile, eFileError );
|
||||
TSS_FILE_EXCEPTION( eFileOpen, eFile );
|
||||
TSS_FILE_EXCEPTION( eFileWrite, eFile );
|
||||
TSS_FILE_EXCEPTION( eFileRead, eFile );
|
||||
TSS_FILE_EXCEPTION( eFileEOF, eFile ); // never used!
|
||||
TSS_FILE_EXCEPTION( eFileSeek, eFile );
|
||||
TSS_FILE_EXCEPTION( eFileInvalidOp, eFile ); // never used!
|
||||
TSS_FILE_EXCEPTION( eFileTrunc, eFile );
|
||||
TSS_FILE_EXCEPTION( eFileClose, eFile ); // never used!
|
||||
TSS_FILE_EXCEPTION( eFileFlush, eFile );
|
||||
TSS_FILE_EXCEPTION( eFileRewind, eFile );
|
||||
TSS_FILE_EXCEPTION(eFile, eFileError);
|
||||
TSS_FILE_EXCEPTION(eFileOpen, eFile);
|
||||
TSS_FILE_EXCEPTION(eFileWrite, eFile);
|
||||
TSS_FILE_EXCEPTION(eFileRead, eFile);
|
||||
TSS_FILE_EXCEPTION(eFileEOF, eFile); // never used!
|
||||
TSS_FILE_EXCEPTION(eFileSeek, eFile);
|
||||
TSS_FILE_EXCEPTION(eFileInvalidOp, eFile); // never used!
|
||||
TSS_FILE_EXCEPTION(eFileTrunc, eFile);
|
||||
TSS_FILE_EXCEPTION(eFileClose, eFile); // never used!
|
||||
TSS_FILE_EXCEPTION(eFileFlush, eFile);
|
||||
TSS_FILE_EXCEPTION(eFileRewind, eFile);
|
||||
|
||||
//=============================================================================
|
||||
// cFile
|
||||
//=============================================================================
|
||||
struct cFile_i;
|
||||
class cFile
|
||||
class cFile
|
||||
{
|
||||
public:
|
||||
typedef off_t File_t;
|
||||
|
||||
enum SeekFrom
|
||||
enum SeekFrom
|
||||
{
|
||||
SEEK_BEGIN = 0,
|
||||
SEEK_CURRENT,
|
||||
SEEK_EOF
|
||||
SEEK_BEGIN = 0,
|
||||
SEEK_CURRENT,
|
||||
SEEK_EOF
|
||||
};
|
||||
|
||||
enum OpenFlags
|
||||
{
|
||||
// note that reading from the file is implicit
|
||||
OPEN_READ = 0x00000001, // not needed, but makes calls nice...
|
||||
OPEN_WRITE = 0x00000002, // we will be writing to the file
|
||||
OPEN_LOCKED_TEMP = 0x00000004, // the file should not be readable by other processes and should be removed when closed
|
||||
OPEN_TRUNCATE = 0x00000008, // opens an empty file. creates it if it doesn't exist. Doesn't make much sense without OF_WRITE
|
||||
OPEN_CREATE = 0x00000010, // create the file if it doesn't exist; this is implicit if OF_TRUNCATE is set
|
||||
OPEN_TEXT = 0x00000020,
|
||||
OPEN_EXCLUSIVE = 0x00000040, // Use O_CREAT | O_EXCL
|
||||
OPEN_SCANNING = 0x00000080, // Open for scanning; set nonblocking & caching accordingly, where available
|
||||
OPEN_DIRECT = 0x00000100 // Use O_DIRECT or platform equivalent
|
||||
// note that reading from the file is implicit
|
||||
OPEN_READ = 0x00000001, // not needed, but makes calls nice...
|
||||
OPEN_WRITE = 0x00000002, // we will be writing to the file
|
||||
OPEN_LOCKED_TEMP =
|
||||
0x00000004, // the file should not be readable by other processes and should be removed when closed
|
||||
OPEN_TRUNCATE =
|
||||
0x00000008, // opens an empty file. creates it if it doesn't exist. Doesn't make much sense without OF_WRITE
|
||||
OPEN_CREATE = 0x00000010, // create the file if it doesn't exist; this is implicit if OF_TRUNCATE is set
|
||||
OPEN_TEXT = 0x00000020,
|
||||
OPEN_EXCLUSIVE = 0x00000040, // Use O_CREAT | O_EXCL
|
||||
OPEN_SCANNING = 0x00000080, // Open for scanning; set nonblocking & caching accordingly, where available
|
||||
OPEN_DIRECT = 0x00000100 // Use O_DIRECT or platform equivalent
|
||||
};
|
||||
|
||||
//Ctor, Dtor, CpyCtor, Operator=:
|
||||
cFile ( void );
|
||||
~cFile ( void );
|
||||
cFile(void);
|
||||
~cFile(void);
|
||||
|
||||
/************ User Interface **************************/
|
||||
|
||||
// Both Open methods ALWAYS open files in BINARY mode!
|
||||
void Open ( const TSTRING& sFileName, uint32 flags = OPEN_READ ); //throw(eFile)
|
||||
void Close ( void ); //throw(eFile)
|
||||
bool IsOpen ( void ) const;
|
||||
void Open(const TSTRING& sFileName, uint32 flags = OPEN_READ); //throw(eFile)
|
||||
void Close(void); //throw(eFile)
|
||||
bool IsOpen(void) const;
|
||||
|
||||
File_t Seek ( File_t offset, SeekFrom From ) const; //throw(eFile)
|
||||
File_t Seek(File_t offset, SeekFrom From) const; //throw(eFile)
|
||||
// Seek returns the current offset after completion
|
||||
File_t Read ( void* buffer, File_t nBytes ) const; //throw(eFile)
|
||||
File_t Read(void* buffer, File_t nBytes) const; //throw(eFile)
|
||||
// Read returns the number of bytes that are actually read. If the nBytes
|
||||
// parameter is 0, 0 bytes will be read and buffer will remain untouched.
|
||||
// If the read head is at EOF, no bytes will be read and 0 will be returned.
|
||||
File_t Write ( const void* buffer, File_t nBytes ); //throw(eFile)
|
||||
File_t Write(const void* buffer, File_t nBytes); //throw(eFile)
|
||||
// Write returns the number of bytes that are actually written.
|
||||
File_t Tell ( void ) const;
|
||||
// Tell returns the current offset.
|
||||
bool Flush ( void ); //throw(eFile)
|
||||
File_t Tell(void) const;
|
||||
// Tell returns the current offset.
|
||||
bool Flush(void); //throw(eFile)
|
||||
// Flush returns 0 if the currently defined stream is successfully flushed.
|
||||
void Rewind ( void ) const; //throw(eFile)
|
||||
void Rewind(void) const; //throw(eFile)
|
||||
// Sets the offset to 0.
|
||||
File_t GetSize ( void ) const;
|
||||
// Returns the size of the current file in bytes. Returns -1 if no file is defined.
|
||||
void Truncate ( File_t offset ); // throw(eFile)
|
||||
File_t GetSize(void) const;
|
||||
// Returns the size of the current file in bytes. Returns -1 if no file is defined.
|
||||
void Truncate(File_t offset); // throw(eFile)
|
||||
|
||||
private:
|
||||
cFile ( const cFile& rhs ); //not impl.
|
||||
cFile& operator= ( const cFile& rhs); //not impl.
|
||||
cFile(const cFile& rhs); //not impl.
|
||||
cFile& operator=(const cFile& rhs); //not impl.
|
||||
|
||||
//Pointer to the insulated implementation
|
||||
cFile_i* mpData;
|
||||
cFile_i* mpData;
|
||||
|
||||
public:
|
||||
bool isWritable;
|
||||
bool isWritable;
|
||||
};
|
||||
|
||||
|
||||
|
@ -143,7 +145,7 @@ class cDosPath
|
|||
public:
|
||||
static TSTRING AsPosix(const TSTRING& in);
|
||||
static TSTRING AsNative(const TSTRING& in);
|
||||
static bool IsAbsolutePath(const TSTRING& in);
|
||||
static bool IsAbsolutePath(const TSTRING& in);
|
||||
static TSTRING BackupName(const TSTRING& in);
|
||||
};
|
||||
|
||||
|
@ -152,7 +154,7 @@ class cArosPath
|
|||
public:
|
||||
static TSTRING AsPosix(const TSTRING& in);
|
||||
static TSTRING AsNative(const TSTRING& in);
|
||||
static bool IsAbsolutePath(const TSTRING& in);
|
||||
static bool IsAbsolutePath(const TSTRING& in);
|
||||
};
|
||||
|
||||
class cRiscosPath
|
||||
|
@ -160,7 +162,7 @@ class cRiscosPath
|
|||
public:
|
||||
static TSTRING AsPosix(const TSTRING& in);
|
||||
static TSTRING AsNative(const TSTRING& in);
|
||||
static bool IsAbsolutePath(const TSTRING& in);
|
||||
static bool IsAbsolutePath(const TSTRING& in);
|
||||
};
|
||||
|
||||
class cRedoxPath
|
||||
|
@ -168,19 +170,18 @@ class cRedoxPath
|
|||
public:
|
||||
static TSTRING AsPosix(const TSTRING& in);
|
||||
static TSTRING AsNative(const TSTRING& in);
|
||||
static bool IsAbsolutePath(const TSTRING& in);
|
||||
static bool IsAbsolutePath(const TSTRING& in);
|
||||
};
|
||||
|
||||
#if IS_DOS_DJGPP
|
||||
#define cDevicePath cDosPath
|
||||
#elif IS_AROS
|
||||
#define cDevicePath cArosPath
|
||||
#elif IS_RISCOS
|
||||
#define cDevicePath cRiscosPath
|
||||
#elif IS_REDOX
|
||||
#define cDevicePath cRedoxPath
|
||||
#endif
|
||||
# if IS_DOS_DJGPP
|
||||
# define cDevicePath cDosPath
|
||||
# elif IS_AROS
|
||||
# define cDevicePath cArosPath
|
||||
# elif IS_RISCOS
|
||||
# define cDevicePath cRiscosPath
|
||||
# elif IS_REDOX
|
||||
# define cDevicePath cRedoxPath
|
||||
# endif
|
||||
|
||||
|
||||
#endif //__FILE_H
|
||||
|
||||
|
|
|
@ -3,29 +3,29 @@
|
|||
// Portions created by Tripwire, Inc. are copyright (C) 2000-2018 Tripwire,
|
||||
// Inc. Tripwire is a registered trademark of Tripwire, Inc. All rights
|
||||
// reserved.
|
||||
//
|
||||
//
|
||||
// This program is free software. The contents of this file are subject
|
||||
// to the terms of the GNU General Public License as published by the
|
||||
// Free Software Foundation; either version 2 of the License, or (at your
|
||||
// option) any later version. You may redistribute it and/or modify it
|
||||
// only in compliance with the GNU General Public License.
|
||||
//
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful.
|
||||
// However, this program is distributed AS-IS WITHOUT ANY
|
||||
// WARRANTY; INCLUDING THE IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS
|
||||
// FOR A PARTICULAR PURPOSE. Please see the GNU General Public License
|
||||
// for more details.
|
||||
//
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
|
||||
// USA.
|
||||
//
|
||||
//
|
||||
// Nothing in the GNU General Public License or any other license to use
|
||||
// the code or files shall permit you to use Tripwire's trademarks,
|
||||
// service marks, or other intellectual property without Tripwire's
|
||||
// prior written consent.
|
||||
//
|
||||
//
|
||||
// If you have any questions, please contact Tripwire, Inc. at either
|
||||
// info@tripwire.org or www.tripwire.org.
|
||||
//
|
||||
|
@ -35,13 +35,13 @@
|
|||
/* On GNU/Hurd, need to define _GNU_SOURCE in order to use O_NOATIME
|
||||
which technically is still a nonstandard extension to open() */
|
||||
#if IS_HURD
|
||||
# define _GNU_SOURCE
|
||||
# define _GNU_SOURCE
|
||||
#endif
|
||||
|
||||
#include "core/stdcore.h"
|
||||
|
||||
#if !IS_UNIX
|
||||
#error Need to be unix to use unixfsservices
|
||||
# error Need to be unix to use unixfsservices
|
||||
#endif
|
||||
|
||||
#include "core/file.h"
|
||||
|
@ -54,7 +54,7 @@
|
|||
#include <errno.h>
|
||||
|
||||
#if HAVE_SYS_FS_VX_IOCTL_H
|
||||
# include <sys/fs/vx_ioctl.h>
|
||||
#include <sys/fs/vx_ioctl.h>
|
||||
#endif
|
||||
|
||||
#include "core/debug.h"
|
||||
|
@ -75,32 +75,32 @@ struct cFile_i
|
|||
cFile_i();
|
||||
~cFile_i();
|
||||
|
||||
int m_fd; //underlying file descriptor
|
||||
FILE* mpCurrStream; //currently defined file stream
|
||||
TSTRING mFileName; //the name of the file we are currently referencing.
|
||||
uint32 mFlags; //Flags used to open the file
|
||||
int m_fd; //underlying file descriptor
|
||||
FILE* mpCurrStream; //currently defined file stream
|
||||
TSTRING mFileName; //the name of the file we are currently referencing.
|
||||
uint32 mFlags; //Flags used to open the file
|
||||
};
|
||||
|
||||
//Ctor
|
||||
cFile_i::cFile_i() :
|
||||
m_fd(-1), mpCurrStream(NULL), mFlags(0)
|
||||
{}
|
||||
cFile_i::cFile_i() : m_fd(-1), mpCurrStream(NULL), mFlags(0)
|
||||
{
|
||||
}
|
||||
|
||||
//Dtor
|
||||
cFile_i::~cFile_i()
|
||||
{
|
||||
if (mpCurrStream != NULL)
|
||||
{
|
||||
fclose( mpCurrStream );
|
||||
fclose(mpCurrStream);
|
||||
mpCurrStream = NULL;
|
||||
|
||||
#if !CAN_UNLINK_WHILE_OPEN // so unlink after close instead
|
||||
if( mFlags & cFile::OPEN_LOCKED_TEMP )
|
||||
if (mFlags & cFile::OPEN_LOCKED_TEMP)
|
||||
{
|
||||
// unlink this file
|
||||
if( 0 != unlink(mFileName.c_str()))
|
||||
// unlink this file
|
||||
if (0 != unlink(mFileName.c_str()))
|
||||
{
|
||||
throw( eFileOpen( mFileName, iFSServices::GetInstance()->GetErrString() ) );
|
||||
throw(eFileOpen(mFileName, iFSServices::GetInstance()->GetErrString()));
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
@ -113,15 +113,14 @@ cFile_i::~cFile_i()
|
|||
///////////////////////////////////////////////////////////////////////////
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
||||
cFile::cFile() :
|
||||
mpData(NULL), isWritable(false)
|
||||
cFile::cFile() : mpData(NULL), isWritable(false)
|
||||
{
|
||||
mpData = new cFile_i;
|
||||
}
|
||||
|
||||
cFile::~cFile()
|
||||
{
|
||||
if( mpData != NULL)
|
||||
if (mpData != NULL)
|
||||
{
|
||||
delete mpData;
|
||||
mpData = NULL;
|
||||
|
@ -133,19 +132,19 @@ cFile::~cFile()
|
|||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#if !USES_DEVICE_PATH
|
||||
void cFile::Open( const TSTRING& sFileName, uint32 flags )
|
||||
void cFile::Open(const TSTRING& sFileName, uint32 flags)
|
||||
{
|
||||
#else
|
||||
void cFile::Open( const TSTRING& sFileNameC, uint32 flags )
|
||||
void cFile::Open(const TSTRING& sFileNameC, uint32 flags)
|
||||
{
|
||||
TSTRING sFileName = cDevicePath::AsNative(sFileNameC);
|
||||
#endif
|
||||
mode_t openmode = 0664;
|
||||
if (mpData->mpCurrStream != NULL)
|
||||
Close();
|
||||
|
||||
|
||||
mpData->mFlags = flags;
|
||||
|
||||
|
||||
//
|
||||
// set up the open permissions
|
||||
//
|
||||
|
@ -155,9 +154,9 @@ void cFile::Open( const TSTRING& sFileNameC, uint32 flags )
|
|||
|
||||
if (flags & OPEN_WRITE)
|
||||
{
|
||||
perm |= O_RDWR;
|
||||
isWritable = true;
|
||||
mode = _T("rb");
|
||||
perm |= O_RDWR;
|
||||
isWritable = true;
|
||||
mode = _T("rb");
|
||||
if (flags & OPEN_TRUNCATE)
|
||||
{
|
||||
perm |= O_TRUNC;
|
||||
|
@ -169,14 +168,15 @@ void cFile::Open( const TSTRING& sFileNameC, uint32 flags )
|
|||
}
|
||||
else
|
||||
{
|
||||
perm |= O_RDONLY;
|
||||
isWritable = false;
|
||||
mode = _T("rb");
|
||||
perm |= O_RDONLY;
|
||||
isWritable = false;
|
||||
mode = _T("rb");
|
||||
}
|
||||
|
||||
if (flags & OPEN_EXCLUSIVE) {
|
||||
if (flags & OPEN_EXCLUSIVE)
|
||||
{
|
||||
perm |= O_CREAT | O_EXCL;
|
||||
openmode = (mode_t) 0600; // Make sure only root can read the file
|
||||
openmode = (mode_t)0600; // Make sure only root can read the file
|
||||
}
|
||||
|
||||
if (flags & OPEN_CREATE)
|
||||
|
@ -196,28 +196,28 @@ void cFile::Open( const TSTRING& sFileNameC, uint32 flags )
|
|||
//Only use O_DIRECT for scanning, since cfg/policy/report reads
|
||||
// don't happen w/ a nice round block size.
|
||||
if ((flags & OPEN_DIRECT) && (flags & OPEN_SCANNING))
|
||||
perm |= O_DIRECT;
|
||||
perm |= O_DIRECT;
|
||||
#endif
|
||||
|
||||
|
||||
//
|
||||
// actually open the file
|
||||
//
|
||||
int fh = _topen( sFileName.c_str(), perm, openmode );
|
||||
if( fh == -1 )
|
||||
int fh = _topen(sFileName.c_str(), perm, openmode);
|
||||
if (fh == -1)
|
||||
{
|
||||
throw( eFileOpen( sFileName, iFSServices::GetInstance()->GetErrString() ) );
|
||||
throw(eFileOpen(sFileName, iFSServices::GetInstance()->GetErrString()));
|
||||
}
|
||||
mpData->m_fd = fh;
|
||||
|
||||
#if CAN_UNLINK_WHILE_OPEN
|
||||
if( flags & OPEN_LOCKED_TEMP )
|
||||
if (flags & OPEN_LOCKED_TEMP)
|
||||
{
|
||||
// unlink this file
|
||||
if( 0 != unlink( sFileName.c_str() ) )
|
||||
// unlink this file
|
||||
if (0 != unlink(sFileName.c_str()))
|
||||
{
|
||||
// we weren't able to unlink file, so close handle and fail
|
||||
close( fh );
|
||||
throw( eFileOpen( sFileName, iFSServices::GetInstance()->GetErrString() ) );
|
||||
close(fh);
|
||||
throw(eFileOpen(sFileName, iFSServices::GetInstance()->GetErrString()));
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
@ -227,27 +227,27 @@ void cFile::Open( const TSTRING& sFileNameC, uint32 flags )
|
|||
//
|
||||
mpData->mpCurrStream = _tfdopen(fh, mode.c_str());
|
||||
|
||||
mpData->mFileName = sFileName; //Set mFileName to the newly opened file.
|
||||
|
||||
mpData->mFileName = sFileName; //Set mFileName to the newly opened file.
|
||||
|
||||
cFile::Rewind();
|
||||
|
||||
#ifdef F_NOCACHE //OSX
|
||||
if ((flags & OPEN_DIRECT) && (flags & OPEN_SCANNING))
|
||||
fcntl(fh, F_NOCACHE, 1);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if IS_SOLARIS
|
||||
if ((flags & OPEN_DIRECT) && (flags & OPEN_SCANNING))
|
||||
directio(fh, DIRECTIO_ON);
|
||||
#endif
|
||||
|
||||
|
||||
#if HAVE_POSIX_FADVISE
|
||||
if (flags & OPEN_SCANNING && !(flags & OPEN_DIRECT))
|
||||
if (flags & OPEN_SCANNING && !(flags & OPEN_DIRECT))
|
||||
{
|
||||
posix_fadvise(fh,0,0, POSIX_FADV_SEQUENTIAL);
|
||||
posix_fadvise(fh,0,0, POSIX_FADV_NOREUSE);
|
||||
posix_fadvise(fh, 0, 0, POSIX_FADV_SEQUENTIAL);
|
||||
posix_fadvise(fh, 0, 0, POSIX_FADV_NOREUSE);
|
||||
}
|
||||
|
||||
|
||||
#elif HAVE_SYS_FS_VX_IOCTL_H
|
||||
if (flags & OPEN_SCANNING)
|
||||
{
|
||||
|
@ -257,7 +257,6 @@ void cFile::Open( const TSTRING& sFileNameC, uint32 flags )
|
|||
ioctl(fh, VX_SETCACHE, VX_SEQ | VX_NOREUSE);
|
||||
}
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -266,37 +265,37 @@ void cFile::Open( const TSTRING& sFileNameC, uint32 flags )
|
|||
///////////////////////////////////////////////////////////////////////////
|
||||
void cFile::Close() //throw(eFile)
|
||||
{
|
||||
if(mpData->mpCurrStream != NULL)
|
||||
if (mpData->mpCurrStream != NULL)
|
||||
{
|
||||
#ifdef HAVE_POSIX_FADVISE
|
||||
posix_fadvise(fileno(mpData->mpCurrStream),0,0, POSIX_FADV_DONTNEED);
|
||||
posix_fadvise(fileno(mpData->mpCurrStream), 0, 0, POSIX_FADV_DONTNEED);
|
||||
#endif
|
||||
|
||||
fclose( mpData->mpCurrStream );
|
||||
fclose(mpData->mpCurrStream);
|
||||
mpData->mpCurrStream = NULL;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
mpData->mFileName.empty();
|
||||
}
|
||||
|
||||
bool cFile::IsOpen( void ) const
|
||||
bool cFile::IsOpen(void) const
|
||||
{
|
||||
return( mpData->mpCurrStream != NULL );
|
||||
return (mpData->mpCurrStream != NULL);
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// Seek -- Positions the read/write offset in mpCurrStream. Returns the
|
||||
// current offset upon completion. Returns 0 if no stream is defined.
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
cFile::File_t cFile::Seek( File_t offset, SeekFrom From) const //throw(eFile)
|
||||
cFile::File_t cFile::Seek(File_t offset, SeekFrom From) const //throw(eFile)
|
||||
{
|
||||
//Check to see if a file as been opened yet...
|
||||
ASSERT( mpData->mpCurrStream != 0);
|
||||
ASSERT(mpData->mpCurrStream != 0);
|
||||
|
||||
int apiFrom;
|
||||
|
||||
switch( From )
|
||||
switch (From)
|
||||
{
|
||||
case cFile::SEEK_BEGIN:
|
||||
apiFrom = SEEK_SET;
|
||||
|
@ -309,11 +308,11 @@ cFile::File_t cFile::Seek( File_t offset, SeekFrom From) const //throw(eFile)
|
|||
break;
|
||||
default:
|
||||
//An invalid SeekFrom parameter was passed.
|
||||
throw( eInternal( _T("file_unix") ) );
|
||||
throw(eInternal(_T("file_unix")));
|
||||
}
|
||||
|
||||
// this is a hack to simulate running out of disk space
|
||||
#if 0
|
||||
// this is a hack to simulate running out of disk space
|
||||
#if 0
|
||||
static int blowupCount = 1;
|
||||
if (++blowupCount == 1075)
|
||||
{
|
||||
|
@ -322,14 +321,14 @@ cFile::File_t cFile::Seek( File_t offset, SeekFrom From) const //throw(eFile)
|
|||
throw std::bad_alloc();
|
||||
}
|
||||
fprintf(stderr, "%d\n", blowupCount);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
if (fseeko( mpData->mpCurrStream, offset, apiFrom ) != 0)
|
||||
if (fseeko(mpData->mpCurrStream, offset, apiFrom) != 0)
|
||||
{
|
||||
#ifdef DEBUG
|
||||
#ifdef DEBUG
|
||||
cDebug d("cFile::Seek");
|
||||
d.TraceDebug("Seek failed!\n");
|
||||
#endif
|
||||
#endif
|
||||
throw eFileSeek();
|
||||
}
|
||||
|
||||
|
@ -340,26 +339,31 @@ cFile::File_t cFile::Seek( File_t offset, SeekFrom From) const //throw(eFile)
|
|||
// Read -- Returns the actual bytes read from mpCurrStream. Returns 0 if
|
||||
// mpCurrStream is undefined.
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
cFile::File_t cFile::Read( void* buffer, File_t nBytes ) const //throw(eFile)
|
||||
cFile::File_t cFile::Read(void* buffer, File_t nBytes) const //throw(eFile)
|
||||
{
|
||||
File_t iBytesRead;
|
||||
|
||||
// Has a file been opened?
|
||||
ASSERT( mpData->mpCurrStream != NULL );
|
||||
ASSERT(mpData->mpCurrStream != NULL);
|
||||
|
||||
// Is the nBytes parameter 0? If so, return without touching buffer:
|
||||
if( nBytes == 0 )
|
||||
if (nBytes == 0)
|
||||
return 0;
|
||||
|
||||
if (mpData->mFlags & OPEN_DIRECT) {
|
||||
if (mpData->mFlags & OPEN_DIRECT)
|
||||
{
|
||||
iBytesRead = read(mpData->m_fd, buffer, nBytes);
|
||||
if (iBytesRead<0) {
|
||||
throw eFileRead(mpData->mFileName, iFSServices::GetInstance()->GetErrString());
|
||||
if (iBytesRead < 0)
|
||||
{
|
||||
throw eFileRead(mpData->mFileName, iFSServices::GetInstance()->GetErrString());
|
||||
}
|
||||
} else {
|
||||
iBytesRead = fread( buffer, sizeof(byte), nBytes, mpData->mpCurrStream );
|
||||
if( ferror( mpData->mpCurrStream ) != 0 ) {
|
||||
throw eFileRead( mpData->mFileName, iFSServices::GetInstance()->GetErrString() ) ;
|
||||
}
|
||||
else
|
||||
{
|
||||
iBytesRead = fread(buffer, sizeof(byte), nBytes, mpData->mpCurrStream);
|
||||
if (ferror(mpData->mpCurrStream) != 0)
|
||||
{
|
||||
throw eFileRead(mpData->mFileName, iFSServices::GetInstance()->GetErrString());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -370,16 +374,16 @@ cFile::File_t cFile::Read( void* buffer, File_t nBytes ) const //throw(eFile)
|
|||
// Write -- Returns the actual number of bytes written to mpCurrStream
|
||||
// Returns 0 if no file has been opened.
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
cFile::File_t cFile::Write( const void* buffer, File_t nBytes ) //throw(eFile)
|
||||
cFile::File_t cFile::Write(const void* buffer, File_t nBytes) //throw(eFile)
|
||||
{
|
||||
File_t actual_count = 0;
|
||||
|
||||
// Has a file been opened? Is it writable?
|
||||
ASSERT( mpData->mpCurrStream != NULL );
|
||||
ASSERT( isWritable );
|
||||
ASSERT(mpData->mpCurrStream != NULL);
|
||||
ASSERT(isWritable);
|
||||
|
||||
if( ( actual_count = fwrite( buffer, sizeof(byte), nBytes, mpData->mpCurrStream ) ) < nBytes )
|
||||
throw eFileWrite( mpData->mFileName, iFSServices::GetInstance()->GetErrString() );
|
||||
if ((actual_count = fwrite(buffer, sizeof(byte), nBytes, mpData->mpCurrStream)) < nBytes)
|
||||
throw eFileWrite(mpData->mFileName, iFSServices::GetInstance()->GetErrString());
|
||||
else
|
||||
return actual_count;
|
||||
}
|
||||
|
@ -390,9 +394,9 @@ cFile::File_t cFile::Write( const void* buffer, File_t nBytes ) //throw(eFil
|
|||
///////////////////////////////////////////////////////////////////////////
|
||||
cFile::File_t cFile::Tell() const
|
||||
{
|
||||
ASSERT( mpData->mpCurrStream != 0);
|
||||
ASSERT(mpData->mpCurrStream != 0);
|
||||
|
||||
return ftell( mpData->mpCurrStream );
|
||||
return ftell(mpData->mpCurrStream);
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
@ -400,23 +404,23 @@ cFile::File_t cFile::Tell() const
|
|||
///////////////////////////////////////////////////////////////////////////
|
||||
bool cFile::Flush() //throw(eFile)
|
||||
{
|
||||
if ( mpData->mpCurrStream == NULL )
|
||||
throw eFileFlush( mpData->mFileName, iFSServices::GetInstance()->GetErrString() );
|
||||
|
||||
return ( fflush( mpData->mpCurrStream) == 0 );
|
||||
if (mpData->mpCurrStream == NULL)
|
||||
throw eFileFlush(mpData->mFileName, iFSServices::GetInstance()->GetErrString());
|
||||
|
||||
return (fflush(mpData->mpCurrStream) == 0);
|
||||
}
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// Rewind -- Sets the offset to the beginning of the file. If mpCurrStream
|
||||
// is NULL, this method returns false. If the rewind operation fails,
|
||||
// an exception is thrown.
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
void cFile::Rewind() const //throw(eFile)
|
||||
void cFile::Rewind() const //throw(eFile)
|
||||
{
|
||||
ASSERT( mpData->mpCurrStream != 0);
|
||||
ASSERT(mpData->mpCurrStream != 0);
|
||||
|
||||
rewind( mpData->mpCurrStream );
|
||||
if( ftell( mpData->mpCurrStream ) != 0 )
|
||||
throw( eFileRewind( mpData->mFileName, iFSServices::GetInstance()->GetErrString() ) );
|
||||
rewind(mpData->mpCurrStream);
|
||||
if (ftell(mpData->mpCurrStream) != 0)
|
||||
throw(eFileRewind(mpData->mFileName, iFSServices::GetInstance()->GetErrString()));
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
@ -429,12 +433,12 @@ cFile::File_t cFile::GetSize() const
|
|||
File_t ret;
|
||||
|
||||
//Has a file been opened? If not, return -1
|
||||
if( mpData->mpCurrStream == NULL )
|
||||
if (mpData->mpCurrStream == NULL)
|
||||
return -1;
|
||||
|
||||
ret = Seek( 0, cFile::SEEK_EOF );
|
||||
Seek( vCurrentOffset, cFile::SEEK_BEGIN );
|
||||
//return the offset to it's position prior to GetSize call.
|
||||
ret = Seek(0, cFile::SEEK_EOF);
|
||||
Seek(vCurrentOffset, cFile::SEEK_BEGIN);
|
||||
//return the offset to it's position prior to GetSize call.
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
@ -442,14 +446,14 @@ cFile::File_t cFile::GetSize() const
|
|||
/////////////////////////////////////////////////////////////////////////
|
||||
// Truncate
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
void cFile::Truncate( File_t offset ) // throw(eFile)
|
||||
void cFile::Truncate(File_t offset) // throw(eFile)
|
||||
{
|
||||
ASSERT( mpData->mpCurrStream != 0);
|
||||
ASSERT( isWritable );
|
||||
ASSERT(mpData->mpCurrStream != 0);
|
||||
ASSERT(isWritable);
|
||||
|
||||
ftruncate( fileno(mpData->mpCurrStream), offset );
|
||||
if( GetSize() != offset )
|
||||
throw( eFileTrunc( mpData->mFileName, iFSServices::GetInstance()->GetErrString() ) );
|
||||
ftruncate(fileno(mpData->mpCurrStream), offset);
|
||||
if (GetSize() != offset)
|
||||
throw(eFileTrunc(mpData->mFileName, iFSServices::GetInstance()->GetErrString()));
|
||||
}
|
||||
|
||||
|
||||
|
@ -472,7 +476,7 @@ bool cDosPath::IsAbsolutePath(const TSTRING& in)
|
|||
}
|
||||
|
||||
// For paths of type C:\DOS
|
||||
TSTRING cDosPath::AsPosix( const TSTRING& in )
|
||||
TSTRING cDosPath::AsPosix(const TSTRING& in)
|
||||
{
|
||||
if (in[0] == '/')
|
||||
{
|
||||
|
@ -481,12 +485,12 @@ TSTRING cDosPath::AsPosix( const TSTRING& in )
|
|||
|
||||
TSTRING out = (cDosPath::IsAbsolutePath(in)) ? ("/dev/" + in) : in;
|
||||
std::replace(out.begin(), out.end(), '\\', '/');
|
||||
out.erase( std::remove(out.begin(), out.end(), ':'), out.end());
|
||||
out.erase(std::remove(out.begin(), out.end(), ':'), out.end());
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
TSTRING cDosPath::AsNative( const TSTRING& in )
|
||||
TSTRING cDosPath::AsNative(const TSTRING& in)
|
||||
{
|
||||
if (in[0] != '/')
|
||||
{
|
||||
|
@ -495,10 +499,10 @@ TSTRING cDosPath::AsNative( const TSTRING& in )
|
|||
|
||||
if (in.find("/dev") != 0 || in.length() < 6)
|
||||
return in;
|
||||
|
||||
|
||||
TSTRING out = "?:/";
|
||||
out[0] = in[5];
|
||||
|
||||
out[0] = in[5];
|
||||
|
||||
if (in.length() >= 8)
|
||||
out.append(in.substr(7));
|
||||
|
||||
|
@ -507,15 +511,15 @@ TSTRING cDosPath::AsNative( const TSTRING& in )
|
|||
return out;
|
||||
}
|
||||
|
||||
TSTRING cDosPath::BackupName( const TSTRING& in )
|
||||
TSTRING cDosPath::BackupName(const TSTRING& in)
|
||||
{
|
||||
TSTRING out = in;
|
||||
TSTRING out = in;
|
||||
std::string::size_type pos = out.find_last_of("\\");
|
||||
if( std::string::npos == pos)
|
||||
if (std::string::npos == pos)
|
||||
return in;
|
||||
|
||||
TSTRING path = in.substr(0, pos);
|
||||
TSTRING name = in.substr(pos,9);
|
||||
TSTRING name = in.substr(pos, 9);
|
||||
std::replace(name.begin(), name.end(), '.', '_');
|
||||
path.append(name);
|
||||
|
||||
|
@ -527,7 +531,7 @@ bool cArosPath::IsAbsolutePath(const TSTRING& in)
|
|||
{
|
||||
if (in.empty())
|
||||
return false;
|
||||
|
||||
|
||||
if (in[0] == '/')
|
||||
return true;
|
||||
|
||||
|
@ -538,7 +542,7 @@ bool cArosPath::IsAbsolutePath(const TSTRING& in)
|
|||
}
|
||||
|
||||
// For paths of type DH0:dir/file
|
||||
TSTRING cArosPath::AsPosix( const TSTRING& in )
|
||||
TSTRING cArosPath::AsPosix(const TSTRING& in)
|
||||
{
|
||||
if (in[0] == '/')
|
||||
{
|
||||
|
@ -551,7 +555,7 @@ TSTRING cArosPath::AsPosix( const TSTRING& in )
|
|||
return out;
|
||||
}
|
||||
|
||||
TSTRING cArosPath::AsNative( const TSTRING& in )
|
||||
TSTRING cArosPath::AsNative(const TSTRING& in)
|
||||
{
|
||||
if (in[0] != '/')
|
||||
{
|
||||
|
@ -559,9 +563,9 @@ TSTRING cArosPath::AsNative( const TSTRING& in )
|
|||
}
|
||||
|
||||
std::string::size_type drive = in.find_first_not_of("/");
|
||||
TSTRING out = (drive != std::string::npos) ? in.substr(drive) : in;
|
||||
TSTRING::size_type t = out.find_first_of('/');
|
||||
if(t != std::string::npos)
|
||||
TSTRING out = (drive != std::string::npos) ? in.substr(drive) : in;
|
||||
TSTRING::size_type t = out.find_first_of('/');
|
||||
if (t != std::string::npos)
|
||||
out[t] = ':';
|
||||
else
|
||||
out.append(":");
|
||||
|
@ -574,7 +578,7 @@ bool cRiscosPath::IsAbsolutePath(const TSTRING& in)
|
|||
{
|
||||
if (in.empty())
|
||||
return false;
|
||||
|
||||
|
||||
if (in[0] == '/')
|
||||
return true;
|
||||
|
||||
|
@ -585,7 +589,7 @@ bool cRiscosPath::IsAbsolutePath(const TSTRING& in)
|
|||
}
|
||||
|
||||
// For paths of type SDFS::Volume.$.dir.file
|
||||
TSTRING cRiscosPath::AsPosix( const TSTRING& in )
|
||||
TSTRING cRiscosPath::AsPosix(const TSTRING& in)
|
||||
{
|
||||
#if IS_RISCOS
|
||||
if (in[0] == '/')
|
||||
|
@ -594,8 +598,8 @@ TSTRING cRiscosPath::AsPosix( const TSTRING& in )
|
|||
}
|
||||
|
||||
TSTRING out;
|
||||
char* unixified = __unixify(in.c_str(), 0,0,0,0);
|
||||
if(unixified)
|
||||
char* unixified = __unixify(in.c_str(), 0, 0, 0, 0);
|
||||
if (unixified)
|
||||
{
|
||||
out.assign(unixified);
|
||||
free(unixified);
|
||||
|
@ -608,7 +612,7 @@ TSTRING cRiscosPath::AsPosix( const TSTRING& in )
|
|||
#endif
|
||||
}
|
||||
|
||||
TSTRING cRiscosPath::AsNative( const TSTRING& in )
|
||||
TSTRING cRiscosPath::AsNative(const TSTRING& in)
|
||||
{
|
||||
#if IS_RISCOS
|
||||
if (in[0] != '/')
|
||||
|
@ -616,11 +620,11 @@ TSTRING cRiscosPath::AsNative( const TSTRING& in )
|
|||
return in;
|
||||
}
|
||||
|
||||
TSTRING out;
|
||||
int buf_size = in.length() + 100; // examples pad by 100
|
||||
TSTRING out;
|
||||
int buf_size = in.length() + 100; // examples pad by 100
|
||||
std::vector<char> buf(buf_size);
|
||||
__riscosify(in.c_str(), 0,0, &buf[0], buf_size, 0);
|
||||
if(buf[0])
|
||||
__riscosify(in.c_str(), 0, 0, &buf[0], buf_size, 0);
|
||||
if (buf[0])
|
||||
{
|
||||
out.assign(&buf[0]);
|
||||
return out;
|
||||
|
@ -637,7 +641,7 @@ bool cRedoxPath::IsAbsolutePath(const TSTRING& in)
|
|||
{
|
||||
if (in.empty())
|
||||
return false;
|
||||
|
||||
|
||||
if (in[0] == '/')
|
||||
return true;
|
||||
|
||||
|
@ -648,21 +652,21 @@ bool cRedoxPath::IsAbsolutePath(const TSTRING& in)
|
|||
}
|
||||
|
||||
// For paths of type file:/dir/file
|
||||
TSTRING cRedoxPath::AsPosix( const TSTRING& in )
|
||||
TSTRING cRedoxPath::AsPosix(const TSTRING& in)
|
||||
{
|
||||
if (in[0] == '/')
|
||||
{
|
||||
return in;
|
||||
}
|
||||
|
||||
TSTRING out = IsAbsolutePath(in) ? '/' + in : in;
|
||||
TSTRING out = IsAbsolutePath(in) ? '/' + in : in;
|
||||
std::string::size_type colon = out.find_first_of(":");
|
||||
if( colon != std::string::npos )
|
||||
if (colon != std::string::npos)
|
||||
out.erase(colon, 1);
|
||||
return out;
|
||||
}
|
||||
|
||||
TSTRING cRedoxPath::AsNative( const TSTRING& in )
|
||||
TSTRING cRedoxPath::AsNative(const TSTRING& in)
|
||||
{
|
||||
if (in[0] != '/')
|
||||
{
|
||||
|
@ -670,9 +674,9 @@ TSTRING cRedoxPath::AsNative( const TSTRING& in )
|
|||
}
|
||||
|
||||
std::string::size_type drive = in.find_first_not_of("/");
|
||||
TSTRING out = (drive != std::string::npos) ? in.substr(drive) : in;
|
||||
TSTRING::size_type slash = out.find_first_of('/');
|
||||
if(slash != std::string::npos)
|
||||
TSTRING out = (drive != std::string::npos) ? in.substr(drive) : in;
|
||||
TSTRING::size_type slash = out.find_first_of('/');
|
||||
if (slash != std::string::npos)
|
||||
out.insert(slash, ":");
|
||||
else
|
||||
out.append(":/");
|
||||
|
|
|
@ -3,29 +3,29 @@
|
|||
// Portions created by Tripwire, Inc. are copyright (C) 2000-2018 Tripwire,
|
||||
// Inc. Tripwire is a registered trademark of Tripwire, Inc. All rights
|
||||
// reserved.
|
||||
//
|
||||
//
|
||||
// This program is free software. The contents of this file are subject
|
||||
// to the terms of the GNU General Public License as published by the
|
||||
// Free Software Foundation; either version 2 of the License, or (at your
|
||||
// option) any later version. You may redistribute it and/or modify it
|
||||
// only in compliance with the GNU General Public License.
|
||||
//
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful.
|
||||
// However, this program is distributed AS-IS WITHOUT ANY
|
||||
// WARRANTY; INCLUDING THE IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS
|
||||
// FOR A PARTICULAR PURPOSE. Please see the GNU General Public License
|
||||
// for more details.
|
||||
//
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
|
||||
// USA.
|
||||
//
|
||||
//
|
||||
// Nothing in the GNU General Public License or any other license to use
|
||||
// the code or files shall permit you to use Tripwire's trademarks,
|
||||
// service marks, or other intellectual property without Tripwire's
|
||||
// prior written consent.
|
||||
//
|
||||
//
|
||||
// If you have any questions, please contact Tripwire, Inc. at either
|
||||
// info@tripwire.org or www.tripwire.org.
|
||||
//
|
||||
|
@ -37,11 +37,10 @@
|
|||
#include "corestrings.h"
|
||||
|
||||
// TODO: Make this use MakeFileError() for consistency
|
||||
eFileError::eFileError( const TSTRING& filename, const TSTRING& description, uint32 flags )
|
||||
: eError( _T(""), flags )
|
||||
eFileError::eFileError(const TSTRING& filename, const TSTRING& description, uint32 flags) : eError(_T(""), flags)
|
||||
{
|
||||
mFilename = filename;
|
||||
mMsg = description;
|
||||
mMsg = description;
|
||||
}
|
||||
|
||||
TSTRING eFileError::GetFilename() const
|
||||
|
@ -58,14 +57,14 @@ TSTRING eFileError::GetDescription() const
|
|||
{
|
||||
TSTRING ret;
|
||||
|
||||
if( ! mFilename.empty() )
|
||||
if (!mFilename.empty())
|
||||
{
|
||||
ret = TSS_GetString( cCore, core::STR_ERROR_FILENAME ) + mFilename;
|
||||
ret = TSS_GetString(cCore, core::STR_ERROR_FILENAME) + mFilename;
|
||||
}
|
||||
|
||||
if( ! mMsg.empty() )
|
||||
if (!mMsg.empty())
|
||||
{
|
||||
if ( ! mFilename.empty() )
|
||||
if (!mFilename.empty())
|
||||
ret += _T("\n");
|
||||
|
||||
ret += mMsg;
|
||||
|
@ -73,4 +72,3 @@ TSTRING eFileError::GetDescription() const
|
|||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
|
|
@ -3,29 +3,29 @@
|
|||
// Portions created by Tripwire, Inc. are copyright (C) 2000-2018 Tripwire,
|
||||
// Inc. Tripwire is a registered trademark of Tripwire, Inc. All rights
|
||||
// reserved.
|
||||
//
|
||||
//
|
||||
// This program is free software. The contents of this file are subject
|
||||
// to the terms of the GNU General Public License as published by the
|
||||
// Free Software Foundation; either version 2 of the License, or (at your
|
||||
// option) any later version. You may redistribute it and/or modify it
|
||||
// only in compliance with the GNU General Public License.
|
||||
//
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful.
|
||||
// However, this program is distributed AS-IS WITHOUT ANY
|
||||
// WARRANTY; INCLUDING THE IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS
|
||||
// FOR A PARTICULAR PURPOSE. Please see the GNU General Public License
|
||||
// for more details.
|
||||
//
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
|
||||
// USA.
|
||||
//
|
||||
//
|
||||
// Nothing in the GNU General Public License or any other license to use
|
||||
// the code or files shall permit you to use Tripwire's trademarks,
|
||||
// service marks, or other intellectual property without Tripwire's
|
||||
// prior written consent.
|
||||
//
|
||||
//
|
||||
// If you have any questions, please contact Tripwire, Inc. at either
|
||||
// info@tripwire.org or www.tripwire.org.
|
||||
//
|
||||
|
@ -51,30 +51,33 @@
|
|||
// ### Insufficient permission to open file. <-- constructor parameter "msg"
|
||||
// ### Exiting... <-- appropriate third message
|
||||
//=============================================================================
|
||||
TSS_BEGIN_EXCEPTION_NO_CTOR( eFileError, eError )
|
||||
TSS_BEGIN_EXCEPTION_NO_CTOR(eFileError, eError)
|
||||
private:
|
||||
TSTRING mFilename;
|
||||
TSTRING mFilename;
|
||||
|
||||
public:
|
||||
eFileError( const TSTRING& filename, const TSTRING& description, uint32 flags = 0 );
|
||||
eFileError(const TSTRING& filename, const TSTRING& description, uint32 flags = 0);
|
||||
|
||||
explicit eFileError( const eFileError& rhs )
|
||||
: eError( rhs ) { mFilename = rhs.mFilename; }
|
||||
eFileError( const TSTRING& msg, uint32 flags = 0 )
|
||||
: eError( msg, flags ) {}
|
||||
explicit eFileError(const eFileError& rhs) : eError(rhs)
|
||||
{
|
||||
mFilename = rhs.mFilename;
|
||||
}
|
||||
eFileError(const TSTRING& msg, uint32 flags = 0) : eError(msg, flags)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
TSTRING GetFilename() const;
|
||||
TSTRING GetDescription() const;
|
||||
virtual TSTRING GetMsg() const;
|
||||
TSTRING GetFilename() const;
|
||||
TSTRING GetDescription() const;
|
||||
virtual TSTRING GetMsg() const;
|
||||
|
||||
TSS_END_EXCEPTION()
|
||||
|
||||
#define TSS_FILE_EXCEPTION( except, base ) \
|
||||
TSS_BEGIN_EXCEPTION( except, base ) \
|
||||
except( const TSTRING& filename, const TSTRING& msg, uint32 flags = 0 ) \
|
||||
: base( filename, msg, flags ) {} \
|
||||
TSS_END_EXCEPTION()
|
||||
# define TSS_FILE_EXCEPTION(except, base) \
|
||||
TSS_BEGIN_EXCEPTION(except, base) \
|
||||
except(const TSTRING& filename, const TSTRING& msg, uint32 flags = 0) : base(filename, msg, flags) \
|
||||
{ \
|
||||
} \
|
||||
TSS_END_EXCEPTION()
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
@ -3,29 +3,29 @@
|
|||
// Portions created by Tripwire, Inc. are copyright (C) 2000-2018 Tripwire,
|
||||
// Inc. Tripwire is a registered trademark of Tripwire, Inc. All rights
|
||||
// reserved.
|
||||
//
|
||||
//
|
||||
// This program is free software. The contents of this file are subject
|
||||
// to the terms of the GNU General Public License as published by the
|
||||
// Free Software Foundation; either version 2 of the License, or (at your
|
||||
// option) any later version. You may redistribute it and/or modify it
|
||||
// only in compliance with the GNU General Public License.
|
||||
//
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful.
|
||||
// However, this program is distributed AS-IS WITHOUT ANY
|
||||
// WARRANTY; INCLUDING THE IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS
|
||||
// FOR A PARTICULAR PURPOSE. Please see the GNU General Public License
|
||||
// for more details.
|
||||
//
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
|
||||
// USA.
|
||||
//
|
||||
//
|
||||
// Nothing in the GNU General Public License or any other license to use
|
||||
// the code or files shall permit you to use Tripwire's trademarks,
|
||||
// service marks, or other intellectual property without Tripwire's
|
||||
// prior written consent.
|
||||
//
|
||||
//
|
||||
// If you have any questions, please contact Tripwire, Inc. at either
|
||||
// info@tripwire.org or www.tripwire.org.
|
||||
//
|
||||
|
@ -38,10 +38,10 @@
|
|||
#include "ntmbs.h"
|
||||
|
||||
// A magic number to put at top of file headers
|
||||
// I changed this magic number in 2.1 since we now support versioning in the file header.
|
||||
// I changed this magic number in 2.1 since we now support versioning in the file header.
|
||||
// (the old magic number was 0x00202039)
|
||||
// I generated the random number using the random.org web site.
|
||||
const uint32 FILE_HEADER_MAGIC_NUMBER = 0x78f9beb3;
|
||||
const uint32 FILE_HEADER_MAGIC_NUMBER = 0x78f9beb3;
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// class cFileHeaderID
|
||||
|
@ -50,48 +50,46 @@ cFileHeaderID::~cFileHeaderID()
|
|||
{
|
||||
}
|
||||
|
||||
void cFileHeaderID::operator=( const TCHAR* pszId )
|
||||
void cFileHeaderID::operator=(const TCHAR* pszId)
|
||||
{
|
||||
// RAD:10/1/99 -- Not Needed
|
||||
// TODO:BAM -- I'm pretty sure that there's a bug hiding here...
|
||||
//size_t len = _tcslen(id);
|
||||
//size_t len = _tcslen(id);
|
||||
//if (len >= 256)
|
||||
//{
|
||||
// ASSERT(false);
|
||||
// mIDLen = 0;
|
||||
// return;
|
||||
//}
|
||||
|
||||
size_t N = ::strlen( pszId );
|
||||
if ( !(N < cFileHeaderID::MAXBYTES) )
|
||||
throw eCharacter( TSS_GetString( cCore, core::STR_ERR_OVERFLOW ) );
|
||||
|
||||
mIDLen = static_cast<int16>( N ); // know len is less than MAXBYTES
|
||||
::memcpy( mID, pszId, N * sizeof(char) );
|
||||
size_t N = ::strlen(pszId);
|
||||
if (!(N < cFileHeaderID::MAXBYTES))
|
||||
throw eCharacter(TSS_GetString(cCore, core::STR_ERR_OVERFLOW));
|
||||
|
||||
mIDLen = static_cast<int16>(N); // know len is less than MAXBYTES
|
||||
::memcpy(mID, pszId, N * sizeof(char));
|
||||
}
|
||||
|
||||
void cFileHeaderID::operator=( const cFileHeaderID& rhs )
|
||||
void cFileHeaderID::operator=(const cFileHeaderID& rhs)
|
||||
{
|
||||
ASSERT( rhs.mIDLen < cFileHeaderID::MAXBYTES );
|
||||
ASSERT(rhs.mIDLen < cFileHeaderID::MAXBYTES);
|
||||
mIDLen = rhs.mIDLen;
|
||||
memcpy(mID, rhs.mID, mIDLen * sizeof(char));
|
||||
}
|
||||
|
||||
int cFileHeaderID::operator==( const cFileHeaderID& rhs ) const
|
||||
int cFileHeaderID::operator==(const cFileHeaderID& rhs) const
|
||||
{
|
||||
return
|
||||
( mIDLen == rhs.mIDLen ) &&
|
||||
( ::memcmp( mID, rhs.mID, mIDLen * sizeof(char) ) == 0 );
|
||||
return (mIDLen == rhs.mIDLen) && (::memcmp(mID, rhs.mID, mIDLen * sizeof(char)) == 0);
|
||||
}
|
||||
|
||||
void cFileHeaderID::Read(iSerializer* pSerializer, int32 /*version*/ ) // throw (eSerializer, eArchive)
|
||||
void cFileHeaderID::Read(iSerializer* pSerializer, int32 /*version*/) // throw (eSerializer, eArchive)
|
||||
{
|
||||
int16 len;
|
||||
pSerializer->ReadInt16( len );
|
||||
if ( (len < 0) || (len >= cFileHeaderID::MAXBYTES ))
|
||||
pSerializer->ReadInt16(len);
|
||||
if ((len < 0) || (len >= cFileHeaderID::MAXBYTES))
|
||||
{
|
||||
// this is invalid!
|
||||
throw eSerializerInputStreamFmt( _T("File Header ID invalid") );
|
||||
throw eSerializerInputStreamFmt(_T("File Header ID invalid"));
|
||||
}
|
||||
pSerializer->ReadBlob(mID, len * sizeof(char));
|
||||
mIDLen = len;
|
||||
|
@ -99,17 +97,16 @@ void cFileHeaderID::Read(iSerializer* pSerializer, int32 /*version*/ ) // throw
|
|||
|
||||
void cFileHeaderID::Write(iSerializer* pSerializer) const // throw (eSerializer, eArchive)
|
||||
{
|
||||
ASSERT( mIDLen >= 0 && mIDLen < cFileHeaderID::MAXBYTES );
|
||||
|
||||
pSerializer->WriteInt16( mIDLen );
|
||||
pSerializer->WriteBlob( mID, mIDLen * sizeof(char) );
|
||||
ASSERT(mIDLen >= 0 && mIDLen < cFileHeaderID::MAXBYTES);
|
||||
|
||||
pSerializer->WriteInt16(mIDLen);
|
||||
pSerializer->WriteBlob(mID, mIDLen * sizeof(char));
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// class cFileHeader
|
||||
|
||||
cFileHeader::cFileHeader()
|
||||
: mVersion(0)
|
||||
cFileHeader::cFileHeader() : mVersion(0)
|
||||
{
|
||||
#ifdef DEBUG
|
||||
mEncoding = LAST_ENCODING; // set to invalid value so we can assert on write
|
||||
|
@ -119,20 +116,14 @@ cFileHeader::cFileHeader()
|
|||
}
|
||||
|
||||
cFileHeader::cFileHeader(const cFileHeader& rhs)
|
||||
: iSerializable(),
|
||||
mID(rhs.mID),
|
||||
mVersion(rhs.mVersion),
|
||||
mEncoding(rhs.mEncoding)
|
||||
: iSerializable(), mID(rhs.mID), mVersion(rhs.mVersion), mEncoding(rhs.mEncoding)
|
||||
{
|
||||
if (rhs.mBaggage.Length() > 0)
|
||||
{
|
||||
mBaggage.MapArchive(0, rhs.mBaggage.Length());
|
||||
rhs.mBaggage.MapArchive(0, rhs.mBaggage.Length());
|
||||
|
||||
::memcpy(
|
||||
mBaggage.GetMap(),
|
||||
rhs.mBaggage.GetMap(),
|
||||
static_cast<size_t>( rhs.mBaggage.Length() ) );
|
||||
|
||||
::memcpy(mBaggage.GetMap(), rhs.mBaggage.GetMap(), static_cast<size_t>(rhs.mBaggage.Length()));
|
||||
|
||||
mBaggage.MapArchive(0, 0);
|
||||
rhs.mBaggage.MapArchive(0, 0);
|
||||
|
@ -171,18 +162,18 @@ void cFileHeader::Read(iSerializer* pSerializer, int32 /*version*/) // throw (eS
|
|||
if ((unsigned int)magicNumber != FILE_HEADER_MAGIC_NUMBER)
|
||||
{
|
||||
d.TraceDebug("Bad magic number");
|
||||
throw eSerializerInputStreamFmt(pSerializer->GetFileName() );
|
||||
throw eSerializerInputStreamFmt(pSerializer->GetFileName());
|
||||
}
|
||||
|
||||
// Note this version refers to the format of this data structure in the
|
||||
// file image. mVersion refers to the version of data that accompanies
|
||||
// file image. mVersion refers to the version of data that accompanies
|
||||
// this cFileHeader, for example the database or report format.
|
||||
pSerializer->ReadInt32(version);
|
||||
if (version > 1)
|
||||
{
|
||||
// don't understand the version
|
||||
d.TraceDebug("Bad version");
|
||||
throw eSerializerInputStreamFmt(pSerializer->GetFileName() );
|
||||
throw eSerializerInputStreamFmt(pSerializer->GetFileName());
|
||||
}
|
||||
|
||||
mID.Read(pSerializer);
|
||||
|
@ -196,7 +187,7 @@ void cFileHeader::Read(iSerializer* pSerializer, int32 /*version*/) // throw (eS
|
|||
pSerializer->ReadInt32(len);
|
||||
|
||||
if (len < 0 || len > 0xffff)
|
||||
throw eSerializerInputStreamFmt(pSerializer->GetFileName() );
|
||||
throw eSerializerInputStreamFmt(pSerializer->GetFileName());
|
||||
|
||||
mBaggage.MapArchive(0, len);
|
||||
|
||||
|
@ -220,12 +211,12 @@ void cFileHeader::Write(iSerializer* pSerializer) const // throw (eSerializer, e
|
|||
ASSERT(mEncoding != LAST_ENCODING);
|
||||
#endif
|
||||
|
||||
// we need to have our own versioning since we are not
|
||||
// we need to have our own versioning since we are not
|
||||
// a iTypedSerializable object.
|
||||
pSerializer->WriteInt32(FILE_HEADER_MAGIC_NUMBER);
|
||||
|
||||
// Note this version refers to the format of this data structure in the
|
||||
// file image. mVersion refers to the version of data that accompanies
|
||||
// file image. mVersion refers to the version of data that accompanies
|
||||
// this cFileHeader, for example the database or report format.
|
||||
pSerializer->WriteInt32(1); // version
|
||||
|
||||
|
@ -233,21 +224,20 @@ void cFileHeader::Write(iSerializer* pSerializer) const // throw (eSerializer, e
|
|||
|
||||
pSerializer->WriteInt32(mVersion);
|
||||
|
||||
pSerializer->WriteInt16( static_cast<int16>(mEncoding) );
|
||||
pSerializer->WriteInt16(static_cast<int16>(mEncoding));
|
||||
|
||||
int32 len = static_cast<int32>( mBaggage.Length() );
|
||||
int32 len = static_cast<int32>(mBaggage.Length());
|
||||
|
||||
ASSERT(len >= 0);
|
||||
ASSERT(len <= 0xFFFF);
|
||||
|
||||
if ( len < 0 || len > 0xFFFF )
|
||||
if (len < 0 || len > 0xFFFF)
|
||||
throw eSerializerOutputStreamFmt();
|
||||
|
||||
pSerializer->WriteInt32(len);
|
||||
if (len > 0)
|
||||
{
|
||||
{
|
||||
mBaggage.MapArchive(0, len);
|
||||
pSerializer->WriteBlob(mBaggage.GetMap(), len);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -3,29 +3,29 @@
|
|||
// Portions created by Tripwire, Inc. are copyright (C) 2000-2018 Tripwire,
|
||||
// Inc. Tripwire is a registered trademark of Tripwire, Inc. All rights
|
||||
// reserved.
|
||||
//
|
||||
//
|
||||
// This program is free software. The contents of this file are subject
|
||||
// to the terms of the GNU General Public License as published by the
|
||||
// Free Software Foundation; either version 2 of the License, or (at your
|
||||
// option) any later version. You may redistribute it and/or modify it
|
||||
// only in compliance with the GNU General Public License.
|
||||
//
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful.
|
||||
// However, this program is distributed AS-IS WITHOUT ANY
|
||||
// WARRANTY; INCLUDING THE IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS
|
||||
// FOR A PARTICULAR PURPOSE. Please see the GNU General Public License
|
||||
// for more details.
|
||||
//
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
|
||||
// USA.
|
||||
//
|
||||
//
|
||||
// Nothing in the GNU General Public License or any other license to use
|
||||
// the code or files shall permit you to use Tripwire's trademarks,
|
||||
// service marks, or other intellectual property without Tripwire's
|
||||
// prior written consent.
|
||||
//
|
||||
//
|
||||
// If you have any questions, please contact Tripwire, Inc. at either
|
||||
// info@tripwire.org or www.tripwire.org.
|
||||
//
|
||||
|
@ -54,13 +54,13 @@ public:
|
|||
cFileHeaderID(const cFileHeaderID& rhs);
|
||||
virtual ~cFileHeaderID();
|
||||
|
||||
void operator = (const TCHAR* id);
|
||||
void operator = (const cFileHeaderID& rhs);
|
||||
int operator == (const cFileHeaderID& rhs) const;
|
||||
int operator != (const cFileHeaderID& rhs) const;
|
||||
void operator=(const TCHAR* id);
|
||||
void operator=(const cFileHeaderID& rhs);
|
||||
int operator==(const cFileHeaderID& rhs) const;
|
||||
int operator!=(const cFileHeaderID& rhs) const;
|
||||
|
||||
virtual void Read (iSerializer* pSerializer, int32 version = 0); // throw (eSerializer, eArchive)
|
||||
virtual void Write(iSerializer* pSerializer) const; // throw (eSerializer, eArchive)
|
||||
virtual void Read(iSerializer* pSerializer, int32 version = 0); // throw (eSerializer, eArchive)
|
||||
virtual void Write(iSerializer* pSerializer) const; // throw (eSerializer, eArchive)
|
||||
|
||||
private:
|
||||
// For now we will store the id as a string.
|
||||
|
@ -68,10 +68,13 @@ private:
|
|||
// the way we implemented cFCONames.
|
||||
// Note: We store the string as narrow chars, since
|
||||
// the program is the only person who will see them.
|
||||
int16 mIDLen;
|
||||
int16 mIDLen;
|
||||
|
||||
enum { MAXBYTES = 256 };
|
||||
char mID[ MAXBYTES ];
|
||||
enum
|
||||
{
|
||||
MAXBYTES = 256
|
||||
};
|
||||
char mID[MAXBYTES];
|
||||
};
|
||||
|
||||
inline cFileHeaderID::cFileHeaderID()
|
||||
|
@ -84,14 +87,12 @@ inline cFileHeaderID::cFileHeaderID(const TCHAR* id)
|
|||
*this = id;
|
||||
}
|
||||
|
||||
inline
|
||||
cFileHeaderID::cFileHeaderID( const cFileHeaderID& rhs ) :
|
||||
iSerializable(), mIDLen( rhs.mIDLen )
|
||||
inline cFileHeaderID::cFileHeaderID(const cFileHeaderID& rhs) : iSerializable(), mIDLen(rhs.mIDLen)
|
||||
{
|
||||
memcpy( mID, rhs.mID, MAXBYTES );
|
||||
memcpy(mID, rhs.mID, MAXBYTES);
|
||||
}
|
||||
|
||||
inline int cFileHeaderID::operator != (const cFileHeaderID& rhs) const
|
||||
inline int cFileHeaderID::operator!=(const cFileHeaderID& rhs) const
|
||||
{
|
||||
return !(*this == rhs);
|
||||
}
|
||||
|
@ -115,26 +116,26 @@ public:
|
|||
LAST_ENCODING
|
||||
};
|
||||
|
||||
void SetID(const cFileHeaderID& id);
|
||||
const cFileHeaderID& GetID() const;
|
||||
void SetID(const cFileHeaderID& id);
|
||||
const cFileHeaderID& GetID() const;
|
||||
|
||||
void SetVersion(uint32 v);
|
||||
uint32 GetVersion() const;
|
||||
void SetVersion(uint32 v);
|
||||
uint32 GetVersion() const;
|
||||
|
||||
void SetEncoding(Encoding e);
|
||||
Encoding GetEncoding() const;
|
||||
void SetEncoding(Encoding e);
|
||||
Encoding GetEncoding() const;
|
||||
|
||||
cMemoryArchive& GetBaggage();
|
||||
const cMemoryArchive& GetBaggage() const;
|
||||
cMemoryArchive& GetBaggage();
|
||||
const cMemoryArchive& GetBaggage() const;
|
||||
|
||||
virtual void Read (iSerializer* pSerializer, int32 version = 0); // throw (eSerializer, eArchive)
|
||||
virtual void Write(iSerializer* pSerializer) const; // throw (eSerializer, eArchive)
|
||||
virtual void Read(iSerializer* pSerializer, int32 version = 0); // throw (eSerializer, eArchive)
|
||||
virtual void Write(iSerializer* pSerializer) const; // throw (eSerializer, eArchive)
|
||||
|
||||
protected:
|
||||
cFileHeaderID mID;
|
||||
uint32 mVersion;
|
||||
Encoding mEncoding;
|
||||
cMemoryArchive mBaggage; // items that have been serialized to this object
|
||||
cFileHeaderID mID;
|
||||
uint32 mVersion;
|
||||
Encoding mEncoding;
|
||||
cMemoryArchive mBaggage; // items that have been serialized to this object
|
||||
};
|
||||
|
||||
inline const cFileHeaderID& cFileHeader::GetID() const
|
||||
|
@ -163,4 +164,3 @@ inline const cMemoryArchive& cFileHeader::GetBaggage() const
|
|||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
@ -3,29 +3,29 @@
|
|||
// Portions created by Tripwire, Inc. are copyright (C) 2000-2018 Tripwire,
|
||||
// Inc. Tripwire is a registered trademark of Tripwire, Inc. All rights
|
||||
// reserved.
|
||||
//
|
||||
//
|
||||
// This program is free software. The contents of this file are subject
|
||||
// to the terms of the GNU General Public License as published by the
|
||||
// Free Software Foundation; either version 2 of the License, or (at your
|
||||
// option) any later version. You may redistribute it and/or modify it
|
||||
// only in compliance with the GNU General Public License.
|
||||
//
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful.
|
||||
// However, this program is distributed AS-IS WITHOUT ANY
|
||||
// WARRANTY; INCLUDING THE IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS
|
||||
// FOR A PARTICULAR PURPOSE. Please see the GNU General Public License
|
||||
// for more details.
|
||||
//
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
|
||||
// USA.
|
||||
//
|
||||
//
|
||||
// Nothing in the GNU General Public License or any other license to use
|
||||
// the code or files shall permit you to use Tripwire's trademarks,
|
||||
// service marks, or other intellectual property without Tripwire's
|
||||
// prior written consent.
|
||||
//
|
||||
//
|
||||
// If you have any questions, please contact Tripwire, Inc. at either
|
||||
// info@tripwire.org or www.tripwire.org.
|
||||
//
|
||||
|
@ -34,8 +34,8 @@
|
|||
// Date....: 8/12/99
|
||||
// Creator.: Brian McFeely (bmcfeely)
|
||||
//
|
||||
// Plauger's 'basic_filebuf::overflow' had a bug,
|
||||
// so I had to reimplement the entire class.
|
||||
// Plauger's 'basic_filebuf::overflow' had a bug,
|
||||
// so I had to reimplement the entire class.
|
||||
//
|
||||
// Plauger had a line: "fwrite(_Str->begin(), _N, 1, _File)"
|
||||
// that should have been: "fwrite(_Str->begin(), 1, _N, _File)"
|
||||
|
@ -47,5 +47,4 @@
|
|||
#include <fstream>
|
||||
#define fixed_basic_ofstream std::basic_ofstream
|
||||
|
||||
#endif//__FIXED_FILEBUF_H
|
||||
|
||||
#endif //__FIXED_FILEBUF_H
|
||||
|
|
|
@ -3,29 +3,29 @@
|
|||
// Portions created by Tripwire, Inc. are copyright (C) 2000-2018 Tripwire,
|
||||
// Inc. Tripwire is a registered trademark of Tripwire, Inc. All rights
|
||||
// reserved.
|
||||
//
|
||||
//
|
||||
// This program is free software. The contents of this file are subject
|
||||
// to the terms of the GNU General Public License as published by the
|
||||
// Free Software Foundation; either version 2 of the License, or (at your
|
||||
// option) any later version. You may redistribute it and/or modify it
|
||||
// only in compliance with the GNU General Public License.
|
||||
//
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful.
|
||||
// However, this program is distributed AS-IS WITHOUT ANY
|
||||
// WARRANTY; INCLUDING THE IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS
|
||||
// FOR A PARTICULAR PURPOSE. Please see the GNU General Public License
|
||||
// for more details.
|
||||
//
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
|
||||
// USA.
|
||||
//
|
||||
//
|
||||
// Nothing in the GNU General Public License or any other license to use
|
||||
// the code or files shall permit you to use Tripwire's trademarks,
|
||||
// service marks, or other intellectual property without Tripwire's
|
||||
// prior written consent.
|
||||
//
|
||||
//
|
||||
// If you have any questions, please contact Tripwire, Inc. at either
|
||||
// info@tripwire.org or www.tripwire.org.
|
||||
//
|
||||
|
@ -43,5 +43,3 @@ iFSServices* iFSServices::mpInstance = 0;
|
|||
//#############################################################################
|
||||
// eFSServices
|
||||
//#############################################################################
|
||||
|
||||
|
||||
|
|
|
@ -3,29 +3,29 @@
|
|||
// Portions created by Tripwire, Inc. are copyright (C) 2000-2018 Tripwire,
|
||||
// Inc. Tripwire is a registered trademark of Tripwire, Inc. All rights
|
||||
// reserved.
|
||||
//
|
||||
//
|
||||
// This program is free software. The contents of this file are subject
|
||||
// to the terms of the GNU General Public License as published by the
|
||||
// Free Software Foundation; either version 2 of the License, or (at your
|
||||
// option) any later version. You may redistribute it and/or modify it
|
||||
// only in compliance with the GNU General Public License.
|
||||
//
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful.
|
||||
// However, this program is distributed AS-IS WITHOUT ANY
|
||||
// WARRANTY; INCLUDING THE IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS
|
||||
// FOR A PARTICULAR PURPOSE. Please see the GNU General Public License
|
||||
// for more details.
|
||||
//
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
|
||||
// USA.
|
||||
//
|
||||
//
|
||||
// Nothing in the GNU General Public License or any other license to use
|
||||
// the code or files shall permit you to use Tripwire's trademarks,
|
||||
// service marks, or other intellectual property without Tripwire's
|
||||
// prior written consent.
|
||||
//
|
||||
//
|
||||
// If you have any questions, please contact Tripwire, Inc. at either
|
||||
// info@tripwire.org or www.tripwire.org.
|
||||
//
|
||||
|
@ -36,7 +36,7 @@
|
|||
//
|
||||
// objective:
|
||||
// abstract all file system calls, except for reading/writing
|
||||
// to elaborate: this class does not handle any file I/O -- we
|
||||
// to elaborate: this class does not handle any file I/O -- we
|
||||
// intend to use streams to abstract out file I/O
|
||||
// abstract case sensitivity of underlying file system
|
||||
//
|
||||
|
@ -66,11 +66,11 @@
|
|||
//=========================================================================
|
||||
|
||||
#if HAVE_SYS_PARAM_H
|
||||
# include <sys/param.h>
|
||||
#include <sys/param.h>
|
||||
#endif
|
||||
|
||||
#if HAVE_SYS_STAT_H
|
||||
# include <sys/stat.h>
|
||||
#include <sys/stat.h>
|
||||
#endif
|
||||
|
||||
|
||||
|
@ -78,28 +78,28 @@
|
|||
// DEFINES AND MACROS
|
||||
//=========================================================================
|
||||
|
||||
// macros for extracting the major and minor portions of int64's:
|
||||
// macros for extracting the major and minor portions of int64's:
|
||||
#if !defined(major)
|
||||
#if !USES_GLIBC
|
||||
#define major(x) ((int)((x) >> 8) & 0xff)
|
||||
#define minor(x) ((int)((x) & 0xff))
|
||||
#else
|
||||
#ifdef WORDS_BIGENDIAN
|
||||
#define major(x) (int)(((char*)&(x))[2])
|
||||
#define minor(x) (int)(((char*)&(x))[3])
|
||||
#else
|
||||
#define major(x) (int)(((char*)&(x))[1])
|
||||
#define minor(x) (int)(((char*)&(x))[0])
|
||||
#endif
|
||||
#endif
|
||||
# if !USES_GLIBC
|
||||
# define major(x) ((int)((x) >> 8) & 0xff)
|
||||
# define minor(x) ((int)((x)&0xff))
|
||||
# else
|
||||
# ifdef WORDS_BIGENDIAN
|
||||
# define major(x) (int)(((char*)&(x))[2])
|
||||
# define minor(x) (int)(((char*)&(x))[3])
|
||||
# else
|
||||
# define major(x) (int)(((char*)&(x))[1])
|
||||
# define minor(x) (int)(((char*)&(x))[0])
|
||||
# endif
|
||||
# endif
|
||||
#endif /* !major */
|
||||
|
||||
//=========================================================================
|
||||
// TYPEDEFS
|
||||
//=========================================================================
|
||||
|
||||
typedef int64 cFSTime;
|
||||
typedef int64 cFSType;
|
||||
typedef int64 cFSTime;
|
||||
typedef int64 cFSType;
|
||||
|
||||
//=========================================================================
|
||||
// GLOBALS
|
||||
|
@ -114,229 +114,232 @@ typedef int64 cFSType;
|
|||
//=========================================================================
|
||||
|
||||
// filesystem access control lists
|
||||
// it is the union of MAX(elem) for all the file systems that we support
|
||||
// it is the union of MAX(elem) for all the file systems that we support
|
||||
/*class cACLElem {
|
||||
// TODO this is just a place holder
|
||||
// uint32 mUid;
|
||||
};*/
|
||||
|
||||
// this class is used only to pass arguments to iFSServices
|
||||
// it is the union of MAX(elem) for all the file systems that we support
|
||||
struct cFSStatArgs {
|
||||
enum FileType {
|
||||
TY_INVALID, // lazy evaluation
|
||||
TY_FILE,
|
||||
TY_DIR,
|
||||
TY_BLOCKDEV,
|
||||
TY_CHARDEV,
|
||||
TY_SYMLINK,
|
||||
TY_FIFO,
|
||||
TY_SOCK,
|
||||
TY_DOOR,
|
||||
TY_PORT,
|
||||
TY_NAMED
|
||||
};
|
||||
// it is the union of MAX(elem) for all the file systems that we support
|
||||
struct cFSStatArgs
|
||||
{
|
||||
enum FileType
|
||||
{
|
||||
TY_INVALID, // lazy evaluation
|
||||
TY_FILE,
|
||||
TY_DIR,
|
||||
TY_BLOCKDEV,
|
||||
TY_CHARDEV,
|
||||
TY_SYMLINK,
|
||||
TY_FIFO,
|
||||
TY_SOCK,
|
||||
TY_DOOR,
|
||||
TY_PORT,
|
||||
TY_NAMED
|
||||
};
|
||||
|
||||
// attr is fs dependent?
|
||||
uint64 dev; // dep
|
||||
int64 ino; // dep
|
||||
int64 mode; // dep
|
||||
int64 nlink; // indep
|
||||
int64 uid; // dep
|
||||
int64 gid; // dep
|
||||
uint64 rdev; // dep
|
||||
int64 size; // indep
|
||||
cFSTime atime; // indep
|
||||
cFSTime mtime; // indep
|
||||
cFSTime ctime; // indep
|
||||
int64 blksize; // indep
|
||||
int64 blocks; // dep
|
||||
int64 fstype; // dep
|
||||
TSTRING usid; // dep
|
||||
TSTRING gsid; // dep
|
||||
// int64 mFileType; // Matt's addition...
|
||||
// attr is fs dependent?
|
||||
uint64 dev; // dep
|
||||
int64 ino; // dep
|
||||
int64 mode; // dep
|
||||
int64 nlink; // indep
|
||||
int64 uid; // dep
|
||||
int64 gid; // dep
|
||||
uint64 rdev; // dep
|
||||
int64 size; // indep
|
||||
cFSTime atime; // indep
|
||||
cFSTime mtime; // indep
|
||||
cFSTime ctime; // indep
|
||||
int64 blksize; // indep
|
||||
int64 blocks; // dep
|
||||
int64 fstype; // dep
|
||||
TSTRING usid; // dep
|
||||
TSTRING gsid; // dep
|
||||
// int64 mFileType; // Matt's addition...
|
||||
|
||||
FileType mFileType; // redundant with other information in this struct, but
|
||||
// broken out for convenience
|
||||
FileType mFileType; // redundant with other information in this struct, but
|
||||
// broken out for convenience
|
||||
|
||||
//TODO: access control list should go here, too
|
||||
//std::list <cACLElem> mACL; // indep
|
||||
//TODO: access control list should go here, too
|
||||
//std::list <cACLElem> mACL; // indep
|
||||
};
|
||||
|
||||
|
||||
|
||||
//=========================================================================
|
||||
//
|
||||
// eFSServices -- exception class
|
||||
//
|
||||
//=========================================================================
|
||||
|
||||
TSS_FILE_EXCEPTION( eFSServices, eFileError );
|
||||
TSS_FILE_EXCEPTION( eFSServicesGeneric, eFSServices );
|
||||
TSS_FILE_EXCEPTION(eFSServices, eFileError);
|
||||
TSS_FILE_EXCEPTION(eFSServicesGeneric, eFSServices);
|
||||
|
||||
//=========================================================================
|
||||
//
|
||||
// iFSServices -- abstracts all file system calls, except for opening, reading,
|
||||
// and writing, which will be handled by standard c++.
|
||||
// and writing, which will be handled by standard c++.
|
||||
// NOTE -- all paths returned from this class will be delimited with a '/'
|
||||
//
|
||||
//=========================================================================
|
||||
|
||||
class iFSServices
|
||||
class iFSServices
|
||||
{
|
||||
public:
|
||||
virtual ~iFSServices() {}
|
||||
///////////////////////////////////////////////////////////////
|
||||
// ENUMS
|
||||
///////////////////////////////////////////////////////////////
|
||||
public:
|
||||
virtual ~iFSServices()
|
||||
{
|
||||
}
|
||||
///////////////////////////////////////////////////////////////
|
||||
// ENUMS
|
||||
///////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////
|
||||
// file creation modes
|
||||
////////////////////////////////////////
|
||||
enum Mode
|
||||
{
|
||||
MODE_DEFAULT = 0,
|
||||
MODE_READ = 1,
|
||||
MODE_WRITE = 2,
|
||||
MODE_SHARE_DELETE = 4,
|
||||
MODE_SHARE_READ = 8,
|
||||
MODE_SHARE_WRITE = 16,
|
||||
MODE_CREATE_EXCL = 32,
|
||||
MODE_CREATE_TRUNCATE = 64
|
||||
};
|
||||
////////////////////////////////////////
|
||||
// file creation modes
|
||||
////////////////////////////////////////
|
||||
enum Mode
|
||||
{
|
||||
MODE_DEFAULT = 0,
|
||||
MODE_READ = 1,
|
||||
MODE_WRITE = 2,
|
||||
MODE_SHARE_DELETE = 4,
|
||||
MODE_SHARE_READ = 8,
|
||||
MODE_SHARE_WRITE = 16,
|
||||
MODE_CREATE_EXCL = 32,
|
||||
MODE_CREATE_TRUNCATE = 64
|
||||
};
|
||||
|
||||
////////////////////////////////////////
|
||||
// maximum path length on platform
|
||||
////////////////////////////////////////
|
||||
enum
|
||||
{
|
||||
////////////////////////////////////////
|
||||
// maximum path length on platform
|
||||
////////////////////////////////////////
|
||||
enum
|
||||
{
|
||||
#ifdef MAXPATHLEN
|
||||
TW_MAX_PATH = MAXPATHLEN
|
||||
TW_MAX_PATH = MAXPATHLEN
|
||||
#else
|
||||
TW_MAX_PATH = 1024
|
||||
TW_MAX_PATH = 1024
|
||||
#endif
|
||||
};
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
// MEMBER FUNCTIONS
|
||||
///////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
////////////////////////////////////////
|
||||
// platform specific functions
|
||||
////////////////////////////////////////
|
||||
virtual bool IsCaseSensitive() const = 0;
|
||||
// returns true if the file system is case sensitive
|
||||
virtual TCHAR GetPathSeparator() const = 0;
|
||||
// returns "/" for unix and "\\" for win32
|
||||
virtual const TCHAR* GetStandardBackupExtension() const = 0;
|
||||
// returns normal string to append to backup files for this os.
|
||||
|
||||
////////////////////////////////////////
|
||||
// process functions
|
||||
////////////////////////////////////////
|
||||
virtual void Sleep( int nSeconds ) const = 0;
|
||||
// makes the current process sleep for the specified number of seconds
|
||||
|
||||
|
||||
////////////////////////////////////////
|
||||
// major filesystem functions
|
||||
////////////////////////////////////////
|
||||
virtual void Stat( const TSTRING& strFileName, cFSStatArgs& pStat ) const = 0;
|
||||
// fills out the cFSStatArgs structure with the stat info for the named file
|
||||
virtual void GetTempDirName( TSTRING& strName ) const = 0;
|
||||
// makes directory if it doesn't exist already. Dirname will end with a delimiter ( '/' )
|
||||
|
||||
virtual void SetTempDirName( TSTRING& tmpName ) = 0;
|
||||
|
||||
virtual TSTRING& MakeTempFilename( TSTRING& strName ) const = 0;
|
||||
// create temporary file
|
||||
// TSTRING must have the form ("baseXXXXXX"), where the X's are replaced with
|
||||
// characters to make it a unique file. There must be at least 6 Xs.
|
||||
///////////////////////////////////////////////////////////////
|
||||
// MEMBER FUNCTIONS
|
||||
///////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
////////////////////////////////////////
|
||||
// minor filesystem functions
|
||||
////////////////////////////////////////
|
||||
virtual void GetHostID( TSTRING& name ) const = 0;
|
||||
////////////////////////////////////////
|
||||
// platform specific functions
|
||||
////////////////////////////////////////
|
||||
virtual bool IsCaseSensitive() const = 0;
|
||||
// returns true if the file system is case sensitive
|
||||
virtual TCHAR GetPathSeparator() const = 0;
|
||||
// returns "/" for unix and "\\" for win32
|
||||
virtual const TCHAR* GetStandardBackupExtension() const = 0;
|
||||
// returns normal string to append to backup files for this os.
|
||||
|
||||
virtual void GetMachineName( TSTRING& name ) const = 0;
|
||||
|
||||
virtual void GetMachineNameFullyQualified( TSTRING& name ) const = 0;
|
||||
|
||||
virtual bool GetCurrentUserName( TSTRING& tstrName ) const = 0;
|
||||
|
||||
virtual bool GetIPAddress( uint32& uiIPAddress ) = 0;
|
||||
////////////////////////////////////////
|
||||
// process functions
|
||||
////////////////////////////////////////
|
||||
virtual void Sleep(int nSeconds) const = 0;
|
||||
// makes the current process sleep for the specified number of seconds
|
||||
|
||||
|
||||
////////////////////////////////////////
|
||||
// directory specific functions
|
||||
////////////////////////////////////////
|
||||
virtual void ReadDir( const TSTRING& strName, std::vector<TSTRING> &vDirContents, bool bFullPaths = true ) const = 0;
|
||||
// puts the contents of the specified directory, except for . and .., into the supplied vector.
|
||||
// if bFullPaths is true, then the vector contains fully qualified path names; otherwise, it only contains the
|
||||
// short names.
|
||||
virtual void GetCurrentDir( TSTRING& strCurDir ) const = 0;
|
||||
// returns the current working directory
|
||||
////////////////////////////////////////
|
||||
// major filesystem functions
|
||||
////////////////////////////////////////
|
||||
virtual void Stat(const TSTRING& strFileName, cFSStatArgs& pStat) const = 0;
|
||||
// fills out the cFSStatArgs structure with the stat info for the named file
|
||||
virtual void GetTempDirName(TSTRING& strName) const = 0;
|
||||
// makes directory if it doesn't exist already. Dirname will end with a delimiter ( '/' )
|
||||
|
||||
virtual void SetTempDirName(TSTRING& tmpName) = 0;
|
||||
|
||||
virtual TSTRING& MakeTempFilename(TSTRING& strName) const = 0;
|
||||
// create temporary file
|
||||
// TSTRING must have the form ("baseXXXXXX"), where the X's are replaced with
|
||||
// characters to make it a unique file. There must be at least 6 Xs.
|
||||
|
||||
|
||||
////////////////////////////////////////
|
||||
// file specific functions
|
||||
////////////////////////////////////////
|
||||
virtual bool FileDelete( const TSTRING& name ) const = 0;
|
||||
|
||||
////////////////////////////////////////
|
||||
// directory and file functions
|
||||
////////////////////////////////////////
|
||||
virtual bool Rename( const TSTRING& strOldName, const TSTRING& strNewName, bool fOverWrite = true ) const = 0;
|
||||
// rename a file
|
||||
|
||||
virtual bool GetUserName( uid_t user_id, TSTRING& tstrUser ) const = 0;
|
||||
virtual bool GetGroupName( gid_t group_id, TSTRING& tstrGroup ) const = 0;
|
||||
////////////////////////////////////////
|
||||
// minor filesystem functions
|
||||
////////////////////////////////////////
|
||||
virtual void GetHostID(TSTRING& name) const = 0;
|
||||
|
||||
//Set whether we try to resolve uid/gid to a name, since Linux static binaries can
|
||||
//have trouble (read: segfaulting) with name resolution given the right nsswitch.conf setup.
|
||||
//This defaults to true if not specified.
|
||||
virtual void SetResolveNames(bool resolve)=0;
|
||||
|
||||
////////////////////////////////////////
|
||||
// miscellaneous utility functions
|
||||
////////////////////////////////////////
|
||||
virtual void ConvertModeToString( uint64 perm, TSTRING& tstrPerm ) const = 0;
|
||||
// takes a int64 permission (from stat) and changes it to look like UNIX's 'ls -l' (e.g. drwxrwxrwx)
|
||||
virtual bool FullPath( TSTRING& fullPath, const TSTRING& relPath, const TSTRING& pathRelFrom = _T("") ) const = 0;
|
||||
// converts relPath into a fully qualified path, storing it in FullPath. If this
|
||||
// fails, false is returned. if the path to which relPath is relative is not CWD, put it in pathRelFrom.
|
||||
// TODO: In some places we have depended on the behaviour that if relPath.empty() == true then we
|
||||
// fail or return an empty string. Should we add this behaviour to the interface?
|
||||
virtual bool GetExecutableFilename( TSTRING& strFullPath, const TSTRING& strFilename ) const = 0;
|
||||
// get the path to the current executable file
|
||||
virtual bool IsRoot( const TSTRING& strPath ) const = 0;
|
||||
// returns true if strPath denotes a root path
|
||||
virtual void GetMachineName(TSTRING& name) const = 0;
|
||||
|
||||
virtual void GetMachineNameFullyQualified(TSTRING& name) const = 0;
|
||||
|
||||
virtual bool GetCurrentUserName(TSTRING& tstrName) const = 0;
|
||||
|
||||
virtual bool GetIPAddress(uint32& uiIPAddress) = 0;
|
||||
|
||||
|
||||
////////////////////////////////////////
|
||||
// error functions
|
||||
////////////////////////////////////////
|
||||
virtual TSTRING GetErrString() const = 0;
|
||||
// Returns an error string that is appropriate for the system, (e.g. errorstr(errno)
|
||||
// on UNIX and FormatError( ..., GetLastError(), ...) in Win32
|
||||
// Call this immediately after a failed system call to get a string
|
||||
// representation of the error event.
|
||||
////////////////////////////////////////
|
||||
// directory specific functions
|
||||
////////////////////////////////////////
|
||||
virtual void ReadDir(const TSTRING& strName, std::vector<TSTRING>& vDirContents, bool bFullPaths = true) const = 0;
|
||||
// puts the contents of the specified directory, except for . and .., into the supplied vector.
|
||||
// if bFullPaths is true, then the vector contains fully qualified path names; otherwise, it only contains the
|
||||
// short names.
|
||||
virtual void GetCurrentDir(TSTRING& strCurDir) const = 0;
|
||||
// returns the current working directory
|
||||
|
||||
|
||||
////////////////////////////////////////
|
||||
// singleton manipulation
|
||||
////////////////////////////////////////
|
||||
static iFSServices* GetInstance();
|
||||
static void SetInstance( iFSServices* pInst );
|
||||
////////////////////////////////////////
|
||||
// file specific functions
|
||||
////////////////////////////////////////
|
||||
virtual bool FileDelete(const TSTRING& name) const = 0;
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
// PRIVATE DATA
|
||||
///////////////////////////////////////////////////////////////
|
||||
private:
|
||||
static iFSServices* mpInstance;
|
||||
////////////////////////////////////////
|
||||
// directory and file functions
|
||||
////////////////////////////////////////
|
||||
virtual bool Rename(const TSTRING& strOldName, const TSTRING& strNewName, bool fOverWrite = true) const = 0;
|
||||
// rename a file
|
||||
|
||||
virtual bool GetUserName(uid_t user_id, TSTRING& tstrUser) const = 0;
|
||||
virtual bool GetGroupName(gid_t group_id, TSTRING& tstrGroup) const = 0;
|
||||
|
||||
//Set whether we try to resolve uid/gid to a name, since Linux static binaries can
|
||||
//have trouble (read: segfaulting) with name resolution given the right nsswitch.conf setup.
|
||||
//This defaults to true if not specified.
|
||||
virtual void SetResolveNames(bool resolve) = 0;
|
||||
|
||||
////////////////////////////////////////
|
||||
// miscellaneous utility functions
|
||||
////////////////////////////////////////
|
||||
virtual void ConvertModeToString(uint64 perm, TSTRING& tstrPerm) const = 0;
|
||||
// takes a int64 permission (from stat) and changes it to look like UNIX's 'ls -l' (e.g. drwxrwxrwx)
|
||||
virtual bool FullPath(TSTRING& fullPath, const TSTRING& relPath, const TSTRING& pathRelFrom = _T("")) const = 0;
|
||||
// converts relPath into a fully qualified path, storing it in FullPath. If this
|
||||
// fails, false is returned. if the path to which relPath is relative is not CWD, put it in pathRelFrom.
|
||||
// TODO: In some places we have depended on the behaviour that if relPath.empty() == true then we
|
||||
// fail or return an empty string. Should we add this behaviour to the interface?
|
||||
virtual bool GetExecutableFilename(TSTRING& strFullPath, const TSTRING& strFilename) const = 0;
|
||||
// get the path to the current executable file
|
||||
virtual bool IsRoot(const TSTRING& strPath) const = 0;
|
||||
// returns true if strPath denotes a root path
|
||||
|
||||
|
||||
////////////////////////////////////////
|
||||
// error functions
|
||||
////////////////////////////////////////
|
||||
virtual TSTRING GetErrString() const = 0;
|
||||
// Returns an error string that is appropriate for the system, (e.g. errorstr(errno)
|
||||
// on UNIX and FormatError( ..., GetLastError(), ...) in Win32
|
||||
// Call this immediately after a failed system call to get a string
|
||||
// representation of the error event.
|
||||
|
||||
|
||||
////////////////////////////////////////
|
||||
// singleton manipulation
|
||||
////////////////////////////////////////
|
||||
static iFSServices* GetInstance();
|
||||
static void SetInstance(iFSServices* pInst);
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
// PRIVATE DATA
|
||||
///////////////////////////////////////////////////////////////
|
||||
private:
|
||||
static iFSServices* mpInstance;
|
||||
};
|
||||
|
||||
|
||||
|
@ -345,16 +348,15 @@ class iFSServices
|
|||
//=========================================================================
|
||||
inline iFSServices* iFSServices::GetInstance()
|
||||
{
|
||||
ASSERT(mpInstance != 0);
|
||||
ASSERT(mpInstance != 0);
|
||||
|
||||
return mpInstance;
|
||||
return mpInstance;
|
||||
}
|
||||
|
||||
inline void iFSServices::SetInstance( iFSServices* pInst )
|
||||
inline void iFSServices::SetInstance(iFSServices* pInst)
|
||||
{
|
||||
mpInstance = pInst;
|
||||
mpInstance = pInst;
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
@ -3,29 +3,29 @@
|
|||
// Portions created by Tripwire, Inc. are copyright (C) 2000-2018 Tripwire,
|
||||
// Inc. Tripwire is a registered trademark of Tripwire, Inc. All rights
|
||||
// reserved.
|
||||
//
|
||||
//
|
||||
// This program is free software. The contents of this file are subject
|
||||
// to the terms of the GNU General Public License as published by the
|
||||
// Free Software Foundation; either version 2 of the License, or (at your
|
||||
// option) any later version. You may redistribute it and/or modify it
|
||||
// only in compliance with the GNU General Public License.
|
||||
//
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful.
|
||||
// However, this program is distributed AS-IS WITHOUT ANY
|
||||
// WARRANTY; INCLUDING THE IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS
|
||||
// FOR A PARTICULAR PURPOSE. Please see the GNU General Public License
|
||||
// for more details.
|
||||
//
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
|
||||
// USA.
|
||||
//
|
||||
//
|
||||
// Nothing in the GNU General Public License or any other license to use
|
||||
// the code or files shall permit you to use Tripwire's trademarks,
|
||||
// service marks, or other intellectual property without Tripwire's
|
||||
// prior written consent.
|
||||
//
|
||||
//
|
||||
// If you have any questions, please contact Tripwire, Inc. at either
|
||||
// info@tripwire.org or www.tripwire.org.
|
||||
//
|
||||
|
@ -44,48 +44,51 @@ public:
|
|||
class cHeap
|
||||
{
|
||||
public:
|
||||
size_t mSize;
|
||||
int8* mpData;
|
||||
size_t mSize;
|
||||
int8* mpData;
|
||||
|
||||
cHeap( size_t size ) : mSize( size ), mpData( new int8[size] ) { ASSERT(mpData != 0); }
|
||||
// Note: The above ASSERT should never occur! If the new failed we should have thrown a bad_alloc().
|
||||
cHeap(size_t size) : mSize(size), mpData(new int8[size])
|
||||
{
|
||||
ASSERT(mpData != 0);
|
||||
}
|
||||
// Note: The above ASSERT should never occur! If the new failed we should have thrown a bad_alloc().
|
||||
};
|
||||
typedef std::vector<cHeap> HeapList;
|
||||
|
||||
size_t mInitialSize;
|
||||
size_t mGrowBy;
|
||||
HeapList mHeaps;
|
||||
TSTRING mName;
|
||||
size_t mCurOff;
|
||||
|
||||
cGrowHeap_i( size_t initialSize, size_t growBy, const TCHAR* name );
|
||||
~cGrowHeap_i() { Clear(); }
|
||||
size_t mInitialSize;
|
||||
size_t mGrowBy;
|
||||
HeapList mHeaps;
|
||||
TSTRING mName;
|
||||
size_t mCurOff;
|
||||
|
||||
size_t AlignSizeRequest( size_t size, size_t alignSize );
|
||||
void* Malloc( size_t size );
|
||||
void Clear();
|
||||
cGrowHeap_i(size_t initialSize, size_t growBy, const TCHAR* name);
|
||||
~cGrowHeap_i()
|
||||
{
|
||||
Clear();
|
||||
}
|
||||
|
||||
size_t AlignSizeRequest(size_t size, size_t alignSize);
|
||||
void* Malloc(size_t size);
|
||||
void Clear();
|
||||
};
|
||||
|
||||
|
||||
cGrowHeap_i::cGrowHeap_i( size_t initialSize, size_t growBy, const TCHAR* name )
|
||||
: mInitialSize( initialSize ),
|
||||
mGrowBy ( growBy ),
|
||||
mName ( name ),
|
||||
mCurOff ( 0 )
|
||||
cGrowHeap_i::cGrowHeap_i(size_t initialSize, size_t growBy, const TCHAR* name)
|
||||
: mInitialSize(initialSize), mGrowBy(growBy), mName(name), mCurOff(0)
|
||||
{
|
||||
// assure that initial size and growby are aligned
|
||||
ASSERT( 0 == ( initialSize % BYTE_ALIGN ) );
|
||||
ASSERT( 0 == ( growBy % BYTE_ALIGN ) );
|
||||
ASSERT(0 == (initialSize % BYTE_ALIGN));
|
||||
ASSERT(0 == (growBy % BYTE_ALIGN));
|
||||
}
|
||||
|
||||
size_t cGrowHeap::TotalMemUsage() const
|
||||
{
|
||||
size_t usage = 0;
|
||||
for( cGrowHeap_i::HeapList::const_iterator i = mpData->mHeaps.begin(); i != mpData->mHeaps.end(); i++ )
|
||||
for (cGrowHeap_i::HeapList::const_iterator i = mpData->mHeaps.begin(); i != mpData->mHeaps.end(); i++)
|
||||
{
|
||||
usage += i->mSize;
|
||||
}
|
||||
if( ! mpData->mHeaps.empty() )
|
||||
if (!mpData->mHeaps.empty())
|
||||
{
|
||||
// take off the unused portion...
|
||||
usage -= (mpData->mHeaps.back().mSize - mpData->mCurOff);
|
||||
|
@ -94,23 +97,23 @@ size_t cGrowHeap::TotalMemUsage() const
|
|||
}
|
||||
|
||||
|
||||
void* cGrowHeap_i::Malloc( size_t size )
|
||||
void* cGrowHeap_i::Malloc(size_t size)
|
||||
{
|
||||
size = AlignSizeRequest( size, BYTE_ALIGN );
|
||||
size = AlignSizeRequest(size, BYTE_ALIGN);
|
||||
|
||||
ASSERT( ( size > 0 ) && ( size < mGrowBy ) );
|
||||
ASSERT((size > 0) && (size < mGrowBy));
|
||||
|
||||
if( size >= mGrowBy )
|
||||
if (size >= mGrowBy)
|
||||
return NULL;
|
||||
|
||||
if( mHeaps.empty() )
|
||||
if (mHeaps.empty())
|
||||
{
|
||||
mHeaps.push_back( cHeap( mInitialSize ) );
|
||||
mHeaps.push_back(cHeap(mInitialSize));
|
||||
ASSERT(mHeaps.back().mpData != 0);
|
||||
mCurOff = 0;
|
||||
mCurOff = 0;
|
||||
}
|
||||
|
||||
if( mCurOff + size < mHeaps.back().mSize )
|
||||
|
||||
if (mCurOff + size < mHeaps.back().mSize)
|
||||
{
|
||||
// we have room to add this to the current heap.
|
||||
//
|
||||
|
@ -122,43 +125,43 @@ void* cGrowHeap_i::Malloc( size_t size )
|
|||
}
|
||||
else
|
||||
{
|
||||
mHeaps.push_back( cHeap( mGrowBy ) );
|
||||
mHeaps.push_back(cHeap(mGrowBy));
|
||||
ASSERT(mHeaps.back().mpData != 0);
|
||||
mCurOff = 0;
|
||||
|
||||
#ifdef _DEUBG
|
||||
void* ret = Malloc( size );
|
||||
ASSERT(ret != 0);
|
||||
return ret;
|
||||
#else
|
||||
return Malloc( size );
|
||||
#endif
|
||||
#ifdef _DEUBG
|
||||
void* ret = Malloc(size);
|
||||
ASSERT(ret != 0);
|
||||
return ret;
|
||||
#else
|
||||
return Malloc(size);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
size_t cGrowHeap_i::AlignSizeRequest( size_t size, size_t alignSize )
|
||||
size_t cGrowHeap_i::AlignSizeRequest(size_t size, size_t alignSize)
|
||||
{
|
||||
// The two's complement algorithm requires a non-zero size request size,
|
||||
// so make make all requests require it so that this function
|
||||
// acts the same no matter what the integer representation
|
||||
if( 0 == size )
|
||||
if (0 == size)
|
||||
size = 1;
|
||||
|
||||
#if USES_2S_COMPLEMENT
|
||||
// This efficient algorithm assumes alignSize is power of two AND a
|
||||
// This efficient algorithm assumes alignSize is power of two AND a
|
||||
// 2's complement representation. Requires non-zero size request
|
||||
ASSERT( 0 == ( alignSize % 2 ) );
|
||||
ASSERT( size > 0 );
|
||||
return( ( size + alignSize - 1 ) & ~( alignSize - 1 ) );
|
||||
ASSERT(0 == (alignSize % 2));
|
||||
ASSERT(size > 0);
|
||||
return ((size + alignSize - 1) & ~(alignSize - 1));
|
||||
#else
|
||||
// this makes no assumption about BYTE_ALIGN or hardware integer representation
|
||||
return( ( ( size / alignSize ) + ( ( size % alignSize ) ? 1 : 0 ) ) * alignSize );
|
||||
return (((size / alignSize) + ((size % alignSize) ? 1 : 0)) * alignSize);
|
||||
#endif
|
||||
}
|
||||
|
||||
void cGrowHeap_i::Clear()
|
||||
{
|
||||
for( HeapList::iterator i = mHeaps.begin(); i != mHeaps.end(); i++ )
|
||||
for (HeapList::iterator i = mHeaps.begin(); i != mHeaps.end(); i++)
|
||||
{
|
||||
delete [] i->mpData;
|
||||
}
|
||||
|
@ -168,27 +171,25 @@ void cGrowHeap_i::Clear()
|
|||
//-----------------------------------------------------------------------------
|
||||
// cGrowHeap
|
||||
//-----------------------------------------------------------------------------
|
||||
cGrowHeap::cGrowHeap( size_t initialSize, size_t growBy, const TCHAR* name ) :
|
||||
mpData( new cGrowHeap_i( initialSize, growBy, name ) )
|
||||
cGrowHeap::cGrowHeap(size_t initialSize, size_t growBy, const TCHAR* name)
|
||||
: mpData(new cGrowHeap_i(initialSize, growBy, name))
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
cGrowHeap::~cGrowHeap()
|
||||
{
|
||||
cDebug d("FCO name heap stats");
|
||||
d.TraceDebug( _T("Total heap memory usage for %s: %d\n"), mpData->mName.c_str(), TotalMemUsage() );
|
||||
|
||||
d.TraceDebug(_T("Total heap memory usage for %s: %d\n"), mpData->mName.c_str(), TotalMemUsage());
|
||||
|
||||
delete mpData;
|
||||
}
|
||||
|
||||
void* cGrowHeap::Malloc( size_t size )
|
||||
void* cGrowHeap::Malloc(size_t size)
|
||||
{
|
||||
return mpData->Malloc( size );
|
||||
return mpData->Malloc(size);
|
||||
}
|
||||
|
||||
void cGrowHeap::Clear()
|
||||
{
|
||||
mpData->Clear();
|
||||
}
|
||||
|
||||
|
|
|
@ -3,29 +3,29 @@
|
|||
// Portions created by Tripwire, Inc. are copyright (C) 2000-2018 Tripwire,
|
||||
// Inc. Tripwire is a registered trademark of Tripwire, Inc. All rights
|
||||
// reserved.
|
||||
//
|
||||
//
|
||||
// This program is free software. The contents of this file are subject
|
||||
// to the terms of the GNU General Public License as published by the
|
||||
// Free Software Foundation; either version 2 of the License, or (at your
|
||||
// option) any later version. You may redistribute it and/or modify it
|
||||
// only in compliance with the GNU General Public License.
|
||||
//
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful.
|
||||
// However, this program is distributed AS-IS WITHOUT ANY
|
||||
// WARRANTY; INCLUDING THE IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS
|
||||
// FOR A PARTICULAR PURPOSE. Please see the GNU General Public License
|
||||
// for more details.
|
||||
//
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
|
||||
// USA.
|
||||
//
|
||||
//
|
||||
// Nothing in the GNU General Public License or any other license to use
|
||||
// the code or files shall permit you to use Tripwire's trademarks,
|
||||
// service marks, or other intellectual property without Tripwire's
|
||||
// prior written consent.
|
||||
//
|
||||
//
|
||||
// If you have any questions, please contact Tripwire, Inc. at either
|
||||
// info@tripwire.org or www.tripwire.org.
|
||||
//
|
||||
|
@ -49,24 +49,23 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
class cGrowHeap_i;
|
||||
|
||||
class cGrowHeap
|
||||
class cGrowHeap
|
||||
{
|
||||
public:
|
||||
cGrowHeap( size_t initialSize, size_t growby, const TCHAR* name );
|
||||
// creates a heap that is initially initialSize big, and increases the
|
||||
// size by growBy every time there is no more room.
|
||||
// initialSize and growby must be a multiple of BYTE_ALIGN
|
||||
cGrowHeap(size_t initialSize, size_t growby, const TCHAR* name);
|
||||
// creates a heap that is initially initialSize big, and increases the
|
||||
// size by growBy every time there is no more room.
|
||||
// initialSize and growby must be a multiple of BYTE_ALIGN
|
||||
~cGrowHeap();
|
||||
|
||||
void* Malloc( size_t size );
|
||||
void Clear();
|
||||
// resets the grow heap's state.
|
||||
size_t TotalMemUsage() const;
|
||||
// returns the total memory usage of this heap
|
||||
void* Malloc(size_t size);
|
||||
void Clear();
|
||||
// resets the grow heap's state.
|
||||
size_t TotalMemUsage() const;
|
||||
// returns the total memory usage of this heap
|
||||
private:
|
||||
cGrowHeap_i* mpData;
|
||||
cGrowHeap_i* mpData;
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
@ -3,34 +3,32 @@
|
|||
// Portions created by Tripwire, Inc. are copyright (C) 2000-2018 Tripwire,
|
||||
// Inc. Tripwire is a registered trademark of Tripwire, Inc. All rights
|
||||
// reserved.
|
||||
//
|
||||
//
|
||||
// This program is free software. The contents of this file are subject
|
||||
// to the terms of the GNU General Public License as published by the
|
||||
// Free Software Foundation; either version 2 of the License, or (at your
|
||||
// option) any later version. You may redistribute it and/or modify it
|
||||
// only in compliance with the GNU General Public License.
|
||||
//
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful.
|
||||
// However, this program is distributed AS-IS WITHOUT ANY
|
||||
// WARRANTY; INCLUDING THE IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS
|
||||
// FOR A PARTICULAR PURPOSE. Please see the GNU General Public License
|
||||
// for more details.
|
||||
//
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
|
||||
// USA.
|
||||
//
|
||||
//
|
||||
// Nothing in the GNU General Public License or any other license to use
|
||||
// the code or files shall permit you to use Tripwire's trademarks,
|
||||
// service marks, or other intellectual property without Tripwire's
|
||||
// prior written consent.
|
||||
//
|
||||
//
|
||||
// If you have any questions, please contact Tripwire, Inc. at either
|
||||
// info@tripwire.org or www.tripwire.org.
|
||||
//
|
||||
//hashtable.cpp : implementation for hashtable which maps const TCHAR*'s to void*'s
|
||||
#include "stdcore.h"
|
||||
#include "hashtable.h"
|
||||
|
||||
|
||||
|
|
|
@ -3,29 +3,29 @@
|
|||
// Portions created by Tripwire, Inc. are copyright (C) 2000-2018 Tripwire,
|
||||
// Inc. Tripwire is a registered trademark of Tripwire, Inc. All rights
|
||||
// reserved.
|
||||
//
|
||||
//
|
||||
// This program is free software. The contents of this file are subject
|
||||
// to the terms of the GNU General Public License as published by the
|
||||
// Free Software Foundation; either version 2 of the License, or (at your
|
||||
// option) any later version. You may redistribute it and/or modify it
|
||||
// only in compliance with the GNU General Public License.
|
||||
//
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful.
|
||||
// However, this program is distributed AS-IS WITHOUT ANY
|
||||
// WARRANTY; INCLUDING THE IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS
|
||||
// FOR A PARTICULAR PURPOSE. Please see the GNU General Public License
|
||||
// for more details.
|
||||
//
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
|
||||
// USA.
|
||||
//
|
||||
//
|
||||
// Nothing in the GNU General Public License or any other license to use
|
||||
// the code or files shall permit you to use Tripwire's trademarks,
|
||||
// service marks, or other intellectual property without Tripwire's
|
||||
// prior written consent.
|
||||
//
|
||||
//
|
||||
// If you have any questions, please contact Tripwire, Inc. at either
|
||||
// info@tripwire.org or www.tripwire.org.
|
||||
//
|
||||
|
@ -34,9 +34,9 @@
|
|||
// implements cHashTable, which maps a key of arbitrary type to a value
|
||||
// of arbitrary type. The key data type MUST have the const byte*()
|
||||
// operator overloaded in order for this to work. TSTRINGS will always
|
||||
// work as the key value because of the overloaded-template-function
|
||||
// work as the key value because of the overloaded-template-function
|
||||
//
|
||||
// Note: Any overloaded const byte*() operator must return an
|
||||
// Note: Any overloaded const byte*() operator must return an
|
||||
// length of key as well. see cDefaultConvert
|
||||
//
|
||||
// IMPORTANT -- cDefaultConvert only works for pointers to objects
|
||||
|
@ -63,12 +63,11 @@
|
|||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Comparison function objects ... these are used by the hash table to determine
|
||||
// equality. The one defined should work for objects that use op== to define
|
||||
// equality. The one defined should work for objects that use op== to define
|
||||
// equality. There is also a specialization for TSTRINGS. If neither of these
|
||||
// fit your needs, you must pass the hash table your own fn pointer or class
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
template<class T>
|
||||
class cDefaultCompare
|
||||
template<class T> class cDefaultCompare
|
||||
{
|
||||
public:
|
||||
bool operator()(const T& lhs, const T& rhs)
|
||||
|
@ -79,19 +78,17 @@ public:
|
|||
/////////////////////////////////////////////////////////
|
||||
// specialization for TSTRINGS
|
||||
/////////////////////////////////////////////////////////
|
||||
template<>
|
||||
inline bool cDefaultCompare<TSTRING>::operator()(const TSTRING& lhs, const TSTRING& rhs)
|
||||
template<> inline bool cDefaultCompare<TSTRING>::operator()(const TSTRING& lhs, const TSTRING& rhs)
|
||||
{
|
||||
return (lhs.compare(rhs) == 0);
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Conversion function objects ... used by the hash table to locate the key in KEY_TYPE
|
||||
// into a byte* and a key length (for hashing purposes). The default implementation
|
||||
// into a byte* and a key length (for hashing purposes). The default implementation
|
||||
// just does a cast. A specialization is also provided for TSTRINGs.
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
template<class T>
|
||||
class cDefaultConvert
|
||||
template<class T> class cDefaultConvert
|
||||
{
|
||||
public:
|
||||
const byte* operator()(const T& obj, int* const pcbKeyLen)
|
||||
|
@ -104,8 +101,7 @@ public:
|
|||
/////////////////////////////////////////////////////////
|
||||
// specialization for TSTRINGS
|
||||
/////////////////////////////////////////////////////////
|
||||
template<>
|
||||
inline const byte* cDefaultConvert<TSTRING>::operator()(const TSTRING& obj, int* const pcbKeyLen )
|
||||
template<> inline const byte* cDefaultConvert<TSTRING>::operator()(const TSTRING& obj, int* const pcbKeyLen)
|
||||
{
|
||||
*pcbKeyLen = sizeof(TCHAR) * obj.length();
|
||||
return (byte*)obj.c_str();
|
||||
|
@ -113,7 +109,7 @@ inline const byte* cDefaultConvert<TSTRING>::operator()(const TSTRING& obj, int*
|
|||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// cHashTable<KEY, VAL, CMP, CONVERTER>
|
||||
// KEY -- the key you are hashing on
|
||||
// KEY -- the key you are hashing on
|
||||
// VAL -- the value you want associated with that key
|
||||
// CMP -- a function object that takes (KEY, KEY) and returns true if they
|
||||
// are equal.
|
||||
|
@ -123,7 +119,8 @@ inline const byte* cDefaultConvert<TSTRING>::operator()(const TSTRING& obj, int*
|
|||
///////////////////////////////////////////////////////////////////////////////
|
||||
// these were moved outside of the class because it sucks to have to name the class with template parameters
|
||||
// ie -- mTable(cHashTable<TSTRING, int>::MEDIUM
|
||||
enum cHashTable_TableSize {
|
||||
enum cHashTable_TableSize
|
||||
{
|
||||
HASH_VERY_SMALL = 17,
|
||||
HASH_SMALL = 2007,
|
||||
HASH_MEDIUM = 6007,
|
||||
|
@ -132,155 +129,165 @@ enum cHashTable_TableSize {
|
|||
};
|
||||
|
||||
// forward declaration
|
||||
template <class KEY_TYPE, class VAL_TYPE, class COMPARE_OP = cDefaultCompare<KEY_TYPE>, class CONVERTER = cDefaultConvert<KEY_TYPE> >
|
||||
template<class KEY_TYPE,
|
||||
class VAL_TYPE,
|
||||
class COMPARE_OP = cDefaultCompare<KEY_TYPE>,
|
||||
class CONVERTER = cDefaultConvert<KEY_TYPE> >
|
||||
class cHashTableIter;
|
||||
|
||||
//General version of cHashTable template:
|
||||
template <class KEY_TYPE, class VAL_TYPE, class COMPARE_OP = cDefaultCompare<KEY_TYPE>, class CONVERTER = cDefaultConvert<KEY_TYPE> >
|
||||
class cHashTable
|
||||
template<class KEY_TYPE,
|
||||
class VAL_TYPE,
|
||||
class COMPARE_OP = cDefaultCompare<KEY_TYPE>,
|
||||
class CONVERTER = cDefaultConvert<KEY_TYPE> >
|
||||
class cHashTable
|
||||
{
|
||||
friend class cHashTableIter<KEY_TYPE, VAL_TYPE, COMPARE_OP, CONVERTER>;
|
||||
friend class cHashTableIter<KEY_TYPE, VAL_TYPE, COMPARE_OP, CONVERTER>;
|
||||
|
||||
public:
|
||||
//structure for hash table nodes.
|
||||
struct node {
|
||||
struct node
|
||||
{
|
||||
KEY_TYPE nKey;
|
||||
VAL_TYPE nData;
|
||||
node* next;
|
||||
node* next;
|
||||
};
|
||||
|
||||
cHashTable(int tblSize = HASH_MEDIUM);
|
||||
~cHashTable();
|
||||
|
||||
bool Insert(KEY_TYPE key, VAL_TYPE data_in);
|
||||
// The pointer, data_in, is stored in a node based on string_in's hashing.
|
||||
//
|
||||
// if (key) already exists in the table, then it's value is replaced by (data_in)
|
||||
// returns true if (key) already existed in table. otherwise, returns false
|
||||
|
||||
// The pointer, data_in, is stored in a node based on string_in's hashing.
|
||||
//
|
||||
// if (key) already exists in the table, then it's value is replaced by (data_in)
|
||||
// returns true if (key) already existed in table. otherwise, returns false
|
||||
|
||||
bool Lookup(KEY_TYPE key, VAL_TYPE& data_out) const;
|
||||
//bool Lookup(TSTRING key, VAL_TYPE& data_out) const;
|
||||
//Lookup returns true if a match is found for string_check. A reference
|
||||
//to the node in the table that matches string_check is passed back (by ref).
|
||||
//Lookup returns true if a match is found for string_check. A reference
|
||||
//to the node in the table that matches string_check is passed back (by ref).
|
||||
bool Remove(KEY_TYPE key);
|
||||
//The node that matches string_out is de-allocated.
|
||||
//The node that matches string_out is de-allocated.
|
||||
|
||||
bool Clear(void);
|
||||
//Clears the entire table and sets all node pointers to NULL
|
||||
bool IsEmpty(void) const;
|
||||
uint32 Hash( const KEY_TYPE& key ) const;
|
||||
//The hashing function, taken from old Tripwire
|
||||
int32 GetNumValues() const { return mValuesInTable; };
|
||||
//Clears the entire table and sets all node pointers to NULL
|
||||
bool IsEmpty(void) const;
|
||||
uint32 Hash(const KEY_TYPE& key) const;
|
||||
//The hashing function, taken from old Tripwire
|
||||
int32 GetNumValues() const
|
||||
{
|
||||
return mValuesInTable;
|
||||
};
|
||||
// returns number of table entries filled
|
||||
|
||||
#ifdef DEBUG
|
||||
void TraceDiagnostics() const;
|
||||
// traces hash table statistics
|
||||
// traces hash table statistics
|
||||
#endif
|
||||
|
||||
private:
|
||||
cHashTable(const cHashTable& rhs); // not impl
|
||||
void operator=(const cHashTable& rhs); // not impl
|
||||
|
||||
cHashTable(const cHashTable& rhs); // not impl
|
||||
void operator=(const cHashTable& rhs); // not impl
|
||||
|
||||
node** mTable;
|
||||
int mTableSize;
|
||||
int32 mValuesInTable;
|
||||
int mTableSize;
|
||||
int32 mValuesInTable;
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// cHashTableIter
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
template <class KEY_TYPE, class VAL_TYPE, class COMPARE_OP, class CONVERTER>
|
||||
class cHashTableIter
|
||||
template<class KEY_TYPE, class VAL_TYPE, class COMPARE_OP, class CONVERTER> class cHashTableIter
|
||||
{
|
||||
public:
|
||||
cHashTableIter(const cHashTable<KEY_TYPE, VAL_TYPE, COMPARE_OP, CONVERTER>& hashTbl);
|
||||
|
||||
void SeekBegin() const;
|
||||
bool Done() const;
|
||||
void Next() const;
|
||||
void SeekBegin() const;
|
||||
bool Done() const;
|
||||
void Next() const;
|
||||
|
||||
const KEY_TYPE& Key() const;
|
||||
const VAL_TYPE& Val() const;
|
||||
VAL_TYPE& Val();
|
||||
const KEY_TYPE& Key() const;
|
||||
const VAL_TYPE& Val() const;
|
||||
VAL_TYPE& Val();
|
||||
|
||||
private:
|
||||
mutable int mCurIndex;
|
||||
mutable int mCurIndex;
|
||||
mutable typename cHashTable<KEY_TYPE, VAL_TYPE, COMPARE_OP, CONVERTER>::node* mpCurNode;
|
||||
const cHashTable<KEY_TYPE, VAL_TYPE, COMPARE_OP, CONVERTER>& mHashTable;
|
||||
const cHashTable<KEY_TYPE, VAL_TYPE, COMPARE_OP, CONVERTER>& mHashTable;
|
||||
|
||||
// helper function
|
||||
void SeekNextValid() const;
|
||||
};
|
||||
|
||||
|
||||
|
||||
//#############################################################################
|
||||
// implementation
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// iterator
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
template <class KEY_TYPE, class VAL_TYPE, class COMPARE_OP, class CONVERTER>
|
||||
inline cHashTableIter<KEY_TYPE, VAL_TYPE, COMPARE_OP, CONVERTER>::cHashTableIter( const cHashTable<KEY_TYPE, VAL_TYPE, COMPARE_OP, CONVERTER>& hashTbl) :
|
||||
mHashTable(hashTbl)
|
||||
template<class KEY_TYPE, class VAL_TYPE, class COMPARE_OP, class CONVERTER>
|
||||
inline cHashTableIter<KEY_TYPE, VAL_TYPE, COMPARE_OP, CONVERTER>::cHashTableIter(
|
||||
const cHashTable<KEY_TYPE, VAL_TYPE, COMPARE_OP, CONVERTER>& hashTbl)
|
||||
: mHashTable(hashTbl)
|
||||
{
|
||||
SeekBegin();
|
||||
}
|
||||
|
||||
template <class KEY_TYPE, class VAL_TYPE, class COMPARE_OP, class CONVERTER>
|
||||
template<class KEY_TYPE, class VAL_TYPE, class COMPARE_OP, class CONVERTER>
|
||||
inline void cHashTableIter<KEY_TYPE, VAL_TYPE, COMPARE_OP, CONVERTER>::SeekBegin() const
|
||||
{
|
||||
mCurIndex = 0;
|
||||
mpCurNode = mHashTable.mTable[0];
|
||||
if(! mpCurNode)
|
||||
if (!mpCurNode)
|
||||
SeekNextValid();
|
||||
}
|
||||
|
||||
template <class KEY_TYPE, class VAL_TYPE, class COMPARE_OP, class CONVERTER>
|
||||
inline bool cHashTableIter<KEY_TYPE, VAL_TYPE, COMPARE_OP, CONVERTER>::Done() const
|
||||
template<class KEY_TYPE, class VAL_TYPE, class COMPARE_OP, class CONVERTER>
|
||||
inline bool cHashTableIter<KEY_TYPE, VAL_TYPE, COMPARE_OP, CONVERTER>::Done() const
|
||||
{
|
||||
return ((mCurIndex < 0) || (mCurIndex >= mHashTable.mTableSize));
|
||||
}
|
||||
|
||||
template <class KEY_TYPE, class VAL_TYPE, class COMPARE_OP, class CONVERTER>
|
||||
inline void cHashTableIter<KEY_TYPE, VAL_TYPE, COMPARE_OP, CONVERTER>::Next() const
|
||||
template<class KEY_TYPE, class VAL_TYPE, class COMPARE_OP, class CONVERTER>
|
||||
inline void cHashTableIter<KEY_TYPE, VAL_TYPE, COMPARE_OP, CONVERTER>::Next() const
|
||||
{
|
||||
SeekNextValid();
|
||||
}
|
||||
|
||||
template <class KEY_TYPE, class VAL_TYPE, class COMPARE_OP, class CONVERTER>
|
||||
template<class KEY_TYPE, class VAL_TYPE, class COMPARE_OP, class CONVERTER>
|
||||
inline void cHashTableIter<KEY_TYPE, VAL_TYPE, COMPARE_OP, CONVERTER>::SeekNextValid() const
|
||||
{
|
||||
if(mpCurNode)
|
||||
if (mpCurNode)
|
||||
mpCurNode = mpCurNode->next;
|
||||
|
||||
// if we're out of range, bail out w/o incrementing index
|
||||
if(mCurIndex >= mHashTable.mTableSize)
|
||||
if (mCurIndex >= mHashTable.mTableSize)
|
||||
return;
|
||||
|
||||
while((! mpCurNode) && (++mCurIndex < mHashTable.mTableSize))
|
||||
while ((!mpCurNode) && (++mCurIndex < mHashTable.mTableSize))
|
||||
{
|
||||
mpCurNode = mHashTable.mTable[mCurIndex];
|
||||
}
|
||||
}
|
||||
|
||||
template <class KEY_TYPE, class VAL_TYPE, class COMPARE_OP, class CONVERTER>
|
||||
template<class KEY_TYPE, class VAL_TYPE, class COMPARE_OP, class CONVERTER>
|
||||
inline const KEY_TYPE& cHashTableIter<KEY_TYPE, VAL_TYPE, COMPARE_OP, CONVERTER>::Key() const
|
||||
{
|
||||
ASSERT(! Done());
|
||||
ASSERT(!Done());
|
||||
return mpCurNode->nKey;
|
||||
}
|
||||
template <class KEY_TYPE, class VAL_TYPE, class COMPARE_OP, class CONVERTER>
|
||||
inline const VAL_TYPE& cHashTableIter<KEY_TYPE, VAL_TYPE, COMPARE_OP, CONVERTER>::Val() const
|
||||
template<class KEY_TYPE, class VAL_TYPE, class COMPARE_OP, class CONVERTER>
|
||||
inline const VAL_TYPE& cHashTableIter<KEY_TYPE, VAL_TYPE, COMPARE_OP, CONVERTER>::Val() const
|
||||
{
|
||||
ASSERT(! Done());
|
||||
ASSERT(!Done());
|
||||
return mpCurNode->nData;
|
||||
}
|
||||
template <class KEY_TYPE, class VAL_TYPE, class COMPARE_OP, class CONVERTER>
|
||||
template<class KEY_TYPE, class VAL_TYPE, class COMPARE_OP, class CONVERTER>
|
||||
inline VAL_TYPE& cHashTableIter<KEY_TYPE, VAL_TYPE, COMPARE_OP, CONVERTER>::Val()
|
||||
{
|
||||
ASSERT(! Done());
|
||||
ASSERT(!Done());
|
||||
return mpCurNode->nData;
|
||||
}
|
||||
|
||||
|
@ -289,32 +296,32 @@ inline VAL_TYPE& cHashTableIter<KEY_TYPE, VAL_TYPE, COMPARE_OP, CONVERTER>::Val(
|
|||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//Default value for tblSize == 6007
|
||||
template <class KEY_TYPE, class VAL_TYPE, class COMPARE_OP, class CONVERTER>
|
||||
template<class KEY_TYPE, class VAL_TYPE, class COMPARE_OP, class CONVERTER>
|
||||
cHashTable<KEY_TYPE, VAL_TYPE, COMPARE_OP, CONVERTER>::cHashTable(int tblSize)
|
||||
{
|
||||
mValuesInTable = 0;
|
||||
mTableSize = tblSize;
|
||||
mTable = new node*[mTableSize];
|
||||
mTableSize = tblSize;
|
||||
mTable = new node*[mTableSize];
|
||||
|
||||
for (int i=0; i < mTableSize; ++i)
|
||||
for (int i = 0; i < mTableSize; ++i)
|
||||
mTable[i] = NULL;
|
||||
}
|
||||
|
||||
//Destructor steps through table and deallocates all dynamic memory
|
||||
template <class KEY_TYPE, class VAL_TYPE, class COMPARE_OP, class CONVERTER>
|
||||
template<class KEY_TYPE, class VAL_TYPE, class COMPARE_OP, class CONVERTER>
|
||||
cHashTable<KEY_TYPE, VAL_TYPE, COMPARE_OP, CONVERTER>::~cHashTable()
|
||||
{
|
||||
for (int i=0; i<mTableSize; ++i)
|
||||
for (int i = 0; i < mTableSize; ++i)
|
||||
{
|
||||
if (mTable[i] != NULL)
|
||||
if (mTable[i] != NULL)
|
||||
{
|
||||
//delete the entire chain:
|
||||
node* curr = mTable[i];
|
||||
node* del;
|
||||
while(curr != NULL)
|
||||
while (curr != NULL)
|
||||
{
|
||||
del = curr;
|
||||
curr=curr->next;
|
||||
del = curr;
|
||||
curr = curr->next;
|
||||
|
||||
delete del;
|
||||
}
|
||||
|
@ -328,17 +335,18 @@ cHashTable<KEY_TYPE, VAL_TYPE, COMPARE_OP, CONVERTER>::~cHashTable()
|
|||
// using seperate chaining (link lists).
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// General Version:
|
||||
template <class KEY_TYPE, class VAL_TYPE, class COMPARE_OP, class CONVERTER>
|
||||
template<class KEY_TYPE, class VAL_TYPE, class COMPARE_OP, class CONVERTER>
|
||||
bool cHashTable<KEY_TYPE, VAL_TYPE, COMPARE_OP, CONVERTER>::Insert(KEY_TYPE key, VAL_TYPE d_in)
|
||||
{
|
||||
COMPARE_OP compare;
|
||||
COMPARE_OP compare;
|
||||
|
||||
int hindex = Hash( key );
|
||||
if (mTable[hindex] == NULL) {
|
||||
int hindex = Hash(key);
|
||||
if (mTable[hindex] == NULL)
|
||||
{
|
||||
//open index, perform insert
|
||||
mTable[hindex] = new node;
|
||||
(mTable[hindex])->nKey = key;
|
||||
(mTable[hindex])->next = NULL;
|
||||
mTable[hindex] = new node;
|
||||
(mTable[hindex])->nKey = key;
|
||||
(mTable[hindex])->next = NULL;
|
||||
(mTable[hindex])->nData = d_in;
|
||||
mValuesInTable++;
|
||||
|
||||
|
@ -348,13 +356,13 @@ bool cHashTable<KEY_TYPE, VAL_TYPE, COMPARE_OP, CONVERTER>::Insert(KEY_TYPE key,
|
|||
{
|
||||
// case 1: key already exists in list -- replace existing one
|
||||
// case 2: key does not exist -- add to end of list
|
||||
|
||||
|
||||
node* nodeptr = mTable[hindex];
|
||||
|
||||
bool found = false;
|
||||
while (true)
|
||||
while (true)
|
||||
{
|
||||
if ( compare(nodeptr->nKey, key))
|
||||
if (compare(nodeptr->nKey, key))
|
||||
{
|
||||
// we found a duplicate!
|
||||
found = true;
|
||||
|
@ -362,24 +370,24 @@ bool cHashTable<KEY_TYPE, VAL_TYPE, COMPARE_OP, CONVERTER>::Insert(KEY_TYPE key,
|
|||
}
|
||||
|
||||
// break if this is the last node in the list
|
||||
if(! nodeptr->next)
|
||||
if (!nodeptr->next)
|
||||
break;
|
||||
|
||||
// otherwise, keep traversing
|
||||
nodeptr = nodeptr->next;
|
||||
}
|
||||
|
||||
|
||||
// add a node if the key was not found
|
||||
if (! found)
|
||||
if (!found)
|
||||
{
|
||||
node *prev = nodeptr;
|
||||
nodeptr = new node;
|
||||
nodeptr->nKey = key;
|
||||
nodeptr->next = NULL;
|
||||
prev->next = nodeptr;
|
||||
|
||||
node* prev = nodeptr;
|
||||
nodeptr = new node;
|
||||
nodeptr->nKey = key;
|
||||
nodeptr->next = NULL;
|
||||
prev->next = nodeptr;
|
||||
|
||||
mValuesInTable++;
|
||||
}
|
||||
}
|
||||
|
||||
// whether it is a new node or not, set the data to this new value
|
||||
nodeptr->nData = d_in;
|
||||
|
@ -392,52 +400,55 @@ bool cHashTable<KEY_TYPE, VAL_TYPE, COMPARE_OP, CONVERTER>::Insert(KEY_TYPE key,
|
|||
// Lookup -- Attempts to find 'string' in the hash table.
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// General Version:
|
||||
template <class KEY_TYPE, class VAL_TYPE, class COMPARE_OP, class CONVERTER>
|
||||
bool
|
||||
cHashTable<KEY_TYPE, VAL_TYPE, COMPARE_OP, CONVERTER>::Lookup(KEY_TYPE key, VAL_TYPE& d_out) const
|
||||
template<class KEY_TYPE, class VAL_TYPE, class COMPARE_OP, class CONVERTER>
|
||||
bool cHashTable<KEY_TYPE, VAL_TYPE, COMPARE_OP, CONVERTER>::Lookup(KEY_TYPE key, VAL_TYPE& d_out) const
|
||||
{
|
||||
COMPARE_OP compare;
|
||||
|
||||
int hindex = Hash( key );
|
||||
int hindex = Hash(key);
|
||||
if (mTable[hindex] == NULL)
|
||||
return false;
|
||||
else {
|
||||
else
|
||||
{
|
||||
node* nodeptr = mTable[hindex];
|
||||
while (nodeptr != NULL)
|
||||
{
|
||||
if( compare(nodeptr->nKey, key)) {
|
||||
if (compare(nodeptr->nKey, key))
|
||||
{
|
||||
d_out = nodeptr->nData;
|
||||
return true;
|
||||
}
|
||||
nodeptr = nodeptr->next;
|
||||
}
|
||||
}
|
||||
return false; //mTable entries exhausted without a match
|
||||
return false; //mTable entries exhausted without a match
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Remove -- Removes a single entry from the hash table. Returns false if
|
||||
// Remove -- Removes a single entry from the hash table. Returns false if
|
||||
// the nKey is not found in the table.
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// General Version -
|
||||
template <class KEY_TYPE, class VAL_TYPE, class COMPARE_OP, class CONVERTER>
|
||||
bool
|
||||
cHashTable<KEY_TYPE, VAL_TYPE, COMPARE_OP, CONVERTER>::Remove(KEY_TYPE key)
|
||||
// General Version -
|
||||
template<class KEY_TYPE, class VAL_TYPE, class COMPARE_OP, class CONVERTER>
|
||||
bool cHashTable<KEY_TYPE, VAL_TYPE, COMPARE_OP, CONVERTER>::Remove(KEY_TYPE key)
|
||||
{
|
||||
COMPARE_OP compare;
|
||||
|
||||
int hindex = Hash( key );
|
||||
if (mTable[hindex] == NULL) {
|
||||
int hindex = Hash(key);
|
||||
if (mTable[hindex] == NULL)
|
||||
{
|
||||
delete (mTable[hindex]);
|
||||
mTable[hindex] = NULL;
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
node* nodeptr = mTable[hindex];
|
||||
node* prev;
|
||||
while(nodeptr != NULL) {
|
||||
while (nodeptr != NULL)
|
||||
{
|
||||
prev = nodeptr;
|
||||
if(compare(mTable[hindex]->nKey, key))
|
||||
if (compare(mTable[hindex]->nKey, key))
|
||||
{
|
||||
prev->next = nodeptr->next;
|
||||
delete nodeptr;
|
||||
|
@ -445,48 +456,48 @@ cHashTable<KEY_TYPE, VAL_TYPE, COMPARE_OP, CONVERTER>::Remove(KEY_TYPE key)
|
|||
mTable[hindex] = NULL;
|
||||
nodeptr = NULL;
|
||||
return true;
|
||||
}//end if
|
||||
} //end if
|
||||
nodeptr = nodeptr->next;
|
||||
}//end while
|
||||
}//end else
|
||||
} //end while
|
||||
} //end else
|
||||
return false; //match was not found, no node deleted
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Clear -- Clears entire hash table so that all indices are NULL
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
template <class KEY_TYPE, class VAL_TYPE, class COMPARE_OP, class CONVERTER>
|
||||
bool
|
||||
cHashTable<KEY_TYPE, VAL_TYPE, COMPARE_OP, CONVERTER>::Clear(void)
|
||||
template<class KEY_TYPE, class VAL_TYPE, class COMPARE_OP, class CONVERTER>
|
||||
bool cHashTable<KEY_TYPE, VAL_TYPE, COMPARE_OP, CONVERTER>::Clear(void)
|
||||
{
|
||||
for (int i=0; i<mTableSize; ++i)
|
||||
for (int i = 0; i < mTableSize; ++i)
|
||||
{
|
||||
if (mTable[i] != NULL) {
|
||||
if (mTable[i] != NULL)
|
||||
{
|
||||
node* curr = mTable[i];
|
||||
node* del;
|
||||
while(curr != NULL) {
|
||||
del = curr;
|
||||
curr=curr->next;
|
||||
while (curr != NULL)
|
||||
{
|
||||
del = curr;
|
||||
curr = curr->next;
|
||||
delete del;
|
||||
if (del == mTable[i])
|
||||
mTable[i] = NULL;
|
||||
del = NULL;
|
||||
|
||||
}//end delete chain loop
|
||||
}//end if mTable[i]!= NULL
|
||||
}//end for
|
||||
|
||||
} //end delete chain loop
|
||||
} //end if mTable[i]!= NULL
|
||||
} //end for
|
||||
return (IsEmpty());
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// IsEmpty --
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
template <class KEY_TYPE, class VAL_TYPE, class COMPARE_OP, class CONVERTER>
|
||||
bool
|
||||
cHashTable<KEY_TYPE, VAL_TYPE, COMPARE_OP, CONVERTER>::IsEmpty(void) const
|
||||
template<class KEY_TYPE, class VAL_TYPE, class COMPARE_OP, class CONVERTER>
|
||||
bool cHashTable<KEY_TYPE, VAL_TYPE, COMPARE_OP, CONVERTER>::IsEmpty(void) const
|
||||
{
|
||||
bool ret = true;
|
||||
for(int i=0; i< mTableSize; ++i)
|
||||
for (int i = 0; i < mTableSize; ++i)
|
||||
ret &= (mTable[i] == NULL);
|
||||
return ret;
|
||||
}
|
||||
|
@ -494,13 +505,13 @@ cHashTable<KEY_TYPE, VAL_TYPE, COMPARE_OP, CONVERTER>::IsEmpty(void) const
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Hash -- performs hashing on key, returns an integer index val.
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
template <class KEY_TYPE, class VAL_TYPE, class COMPARE_OP, class CONVERTER>
|
||||
uint32 cHashTable<KEY_TYPE, VAL_TYPE, COMPARE_OP, CONVERTER>::Hash( const KEY_TYPE& key ) const
|
||||
template<class KEY_TYPE, class VAL_TYPE, class COMPARE_OP, class CONVERTER>
|
||||
uint32 cHashTable<KEY_TYPE, VAL_TYPE, COMPARE_OP, CONVERTER>::Hash(const KEY_TYPE& key) const
|
||||
{
|
||||
CONVERTER converter;
|
||||
int len;
|
||||
const byte* pb = converter( key, &len ); //locates key
|
||||
uint32 hindex;
|
||||
CONVERTER converter;
|
||||
int len;
|
||||
const byte* pb = converter(key, &len); //locates key
|
||||
uint32 hindex;
|
||||
|
||||
hindex = *pb;
|
||||
while (len-- > 0)
|
||||
|
@ -510,24 +521,24 @@ uint32 cHashTable<KEY_TYPE, VAL_TYPE, COMPARE_OP, CONVERTER>::Hash( const KEY_TY
|
|||
|
||||
#ifdef DEBUG
|
||||
|
||||
template <class KEY_TYPE, class VAL_TYPE, class COMPARE_OP, class CONVERTER>
|
||||
template<class KEY_TYPE, class VAL_TYPE, class COMPARE_OP, class CONVERTER>
|
||||
void cHashTable<KEY_TYPE, VAL_TYPE, COMPARE_OP, CONVERTER>::TraceDiagnostics() const
|
||||
{
|
||||
cDebug d("cHashTable::Diagnostics");
|
||||
|
||||
int slotsFilled = 0, numItems = 0, numMultiSlot = 0;
|
||||
int slotsFilled = 0, numItems = 0, numMultiSlot = 0;
|
||||
node* pNode;
|
||||
|
||||
for(int i=0; i < mTableSize; i++)
|
||||
for (int i = 0; i < mTableSize; i++)
|
||||
{
|
||||
if(mTable[i] != NULL)
|
||||
if (mTable[i] != NULL)
|
||||
{
|
||||
slotsFilled++;
|
||||
numItems++;
|
||||
pNode = (mTable[i])->next;
|
||||
if(pNode != NULL)
|
||||
if (pNode != NULL)
|
||||
numMultiSlot++;
|
||||
while(pNode)
|
||||
while (pNode)
|
||||
{
|
||||
numItems++;
|
||||
pNode = pNode->next;
|
||||
|
@ -536,14 +547,17 @@ void cHashTable<KEY_TYPE, VAL_TYPE, COMPARE_OP, CONVERTER>::TraceDiagnostics() c
|
|||
}
|
||||
|
||||
d.TraceDebug("---------------Hash Table Statisics---------------\n");
|
||||
d.TraceDebug("-- Number of slots: %d\n", mTableSize);
|
||||
d.TraceDebug("-- Number of items: %d\n", numItems);
|
||||
d.TraceDebug("-- Slots filled: %d (%lf %%)\n",slotsFilled, ((double)slotsFilled / (double)mTableSize) * 100.0);
|
||||
d.TraceDebug("-- Slots with >1 item: %d (%lf %%)\n",numMultiSlot, ((double)numMultiSlot / (double)slotsFilled) * 100.0);
|
||||
d.TraceDebug("-- Number of slots: %d\n", mTableSize);
|
||||
d.TraceDebug("-- Number of items: %d\n", numItems);
|
||||
d.TraceDebug("-- Slots filled: %d (%lf %%)\n",
|
||||
slotsFilled,
|
||||
((double)slotsFilled / (double)mTableSize) * 100.0);
|
||||
d.TraceDebug("-- Slots with >1 item: %d (%lf %%)\n",
|
||||
numMultiSlot,
|
||||
((double)numMultiSlot / (double)slotsFilled) * 100.0);
|
||||
d.TraceDebug("--------------------------------------------------\n");
|
||||
}
|
||||
#endif // DEBUG
|
||||
# endif // DEBUG
|
||||
|
||||
|
||||
#endif //__HASHTABLE_H
|
||||
|
||||
|
|
182
src/core/ntdbs.h
182
src/core/ntdbs.h
|
@ -3,29 +3,29 @@
|
|||
// Portions created by Tripwire, Inc. are copyright (C) 2000-2018 Tripwire,
|
||||
// Inc. Tripwire is a registered trademark of Tripwire, Inc. All rights
|
||||
// reserved.
|
||||
//
|
||||
//
|
||||
// This program is free software. The contents of this file are subject
|
||||
// to the terms of the GNU General Public License as published by the
|
||||
// Free Software Foundation; either version 2 of the License, or (at your
|
||||
// option) any later version. You may redistribute it and/or modify it
|
||||
// only in compliance with the GNU General Public License.
|
||||
//
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful.
|
||||
// However, this program is distributed AS-IS WITHOUT ANY
|
||||
// WARRANTY; INCLUDING THE IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS
|
||||
// FOR A PARTICULAR PURPOSE. Please see the GNU General Public License
|
||||
// for more details.
|
||||
//
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
|
||||
// USA.
|
||||
//
|
||||
//
|
||||
// Nothing in the GNU General Public License or any other license to use
|
||||
// the code or files shall permit you to use Tripwire's trademarks,
|
||||
// service marks, or other intellectual property without Tripwire's
|
||||
// prior written consent.
|
||||
//
|
||||
//
|
||||
// If you have any questions, please contact Tripwire, Inc. at either
|
||||
// info@tripwire.org or www.tripwire.org.
|
||||
//
|
||||
|
@ -51,13 +51,13 @@
|
|||
#include "ntmbs.h"
|
||||
|
||||
#if IS_KAI
|
||||
#define IS_STDLIB_MODENA 1 // Has special char_traits req's!
|
||||
#ifdef MSIPL_WCHART
|
||||
#define MBSTATE_T_DEFINED
|
||||
#endif
|
||||
# define IS_STDLIB_MODENA 1 // Has special char_traits req's!
|
||||
# ifdef MSIPL_WCHART
|
||||
# define MBSTATE_T_DEFINED
|
||||
# endif
|
||||
#else
|
||||
#define IS_STDLIB_MODENA 0
|
||||
#define MBSTATE_T_DEFINED
|
||||
# define IS_STDLIB_MODENA 0
|
||||
# define MBSTATE_T_DEFINED
|
||||
#endif
|
||||
|
||||
|
||||
|
@ -65,15 +65,24 @@
|
|||
// Char traits for WCHAR16 (aka dbchar_t) and NTMBCS (mctype_t)
|
||||
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
|
||||
#if ( WCHAR_IS_16_BITS )
|
||||
namespace tss { typedef std::wstring dbstring; }
|
||||
#if (WCHAR_IS_16_BITS)
|
||||
namespace tss
|
||||
{
|
||||
typedef std::wstring dbstring;
|
||||
}
|
||||
|
||||
#elif ( WCHAR_IS_32_BITS )
|
||||
namespace std { template <> struct char_traits< dbchar_t >; }
|
||||
namespace tss { typedef std::basic_string<dbchar_t> dbstring; }
|
||||
#elif (WCHAR_IS_32_BITS)
|
||||
namespace std
|
||||
{
|
||||
template<> struct char_traits<dbchar_t>;
|
||||
}
|
||||
namespace tss
|
||||
{
|
||||
typedef std::basic_string<dbchar_t> dbstring;
|
||||
}
|
||||
|
||||
#else
|
||||
#error "wchar_t is not correctly factored!"
|
||||
# error "wchar_t is not correctly factored!"
|
||||
|
||||
#endif
|
||||
|
||||
|
@ -84,151 +93,140 @@
|
|||
|
||||
// specialize *std*::char_traits!!!
|
||||
|
||||
template<>
|
||||
struct std::char_traits< dbchar_t >
|
||||
template<> struct std::char_traits<dbchar_t>
|
||||
{
|
||||
typedef dbchar_t char_type;
|
||||
typedef wint_t int_type;
|
||||
typedef streampos pos_type;
|
||||
typedef streamoff off_type;
|
||||
typedef dbchar_t char_type;
|
||||
typedef wint_t int_type;
|
||||
typedef streampos pos_type;
|
||||
typedef streamoff off_type;
|
||||
|
||||
#ifdef MBSTATE_T_DEFINED
|
||||
typedef mbstate_t state_type;
|
||||
#else
|
||||
typedef int state_type; // Shame on you KAI! This is ANSI-C!
|
||||
#endif
|
||||
# ifdef MBSTATE_T_DEFINED
|
||||
typedef mbstate_t state_type;
|
||||
# else
|
||||
typedef int state_type; // Shame on you KAI! This is ANSI-C!
|
||||
# endif
|
||||
|
||||
static
|
||||
void assign( char_type& lhs, const char_type& rhs ) {
|
||||
static void assign(char_type& lhs, const char_type& rhs)
|
||||
{
|
||||
lhs = rhs;
|
||||
}
|
||||
|
||||
static
|
||||
bool eq( const char_type& lhs, const char_type& rhs ) {
|
||||
static bool eq(const char_type& lhs, const char_type& rhs)
|
||||
{
|
||||
return lhs == rhs;
|
||||
}
|
||||
|
||||
static
|
||||
bool lt( const char_type& lhs, const char_type& rhs ) {
|
||||
return lhs < rhs;
|
||||
static bool lt(const char_type& lhs, const char_type& rhs)
|
||||
{
|
||||
return lhs < rhs;
|
||||
}
|
||||
|
||||
static
|
||||
int compare( const char_type* lhs, const char_type* rhs, size_t N )
|
||||
static int compare(const char_type* lhs, const char_type* rhs, size_t N)
|
||||
{
|
||||
for ( ; N; ++lhs, ++rhs, --N )
|
||||
if ( *lhs != *rhs )
|
||||
return ( *lhs < *rhs ) ? -1 : +1;
|
||||
for (; N; ++lhs, ++rhs, --N)
|
||||
if (*lhs != *rhs)
|
||||
return (*lhs < *rhs) ? -1 : +1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static
|
||||
size_t length( const char_type* psz )
|
||||
static size_t length(const char_type* psz)
|
||||
{
|
||||
if ( psz == 0 )
|
||||
if (psz == 0)
|
||||
return 0;
|
||||
else
|
||||
{
|
||||
const char_type* end;
|
||||
for ( end = psz; *end; end++ );
|
||||
return (size_t)( end - psz );
|
||||
for (end = psz; *end; end++)
|
||||
;
|
||||
return (size_t)(end - psz);
|
||||
}
|
||||
}
|
||||
|
||||
static
|
||||
char_type* copy( char_type* lhs, const char_type* rhs, size_t N )
|
||||
static char_type* copy(char_type* lhs, const char_type* rhs, size_t N)
|
||||
{
|
||||
for ( char_type* at = lhs; N; ++at, ++rhs, --N )
|
||||
for (char_type* at = lhs; N; ++at, ++rhs, --N)
|
||||
*at = *rhs;
|
||||
|
||||
return lhs;
|
||||
}
|
||||
|
||||
static
|
||||
const char_type*
|
||||
find( const char_type* psz, size_t N, const char_type& ch )
|
||||
static const char_type* find(const char_type* psz, size_t N, const char_type& ch)
|
||||
{
|
||||
for ( ; N; ++psz, --N )
|
||||
if ( *psz == ch )
|
||||
for (; N; ++psz, --N)
|
||||
if (*psz == ch)
|
||||
return psz;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static
|
||||
char_type* move( char_type* lhs, const char_type* rhs, size_t N ) {
|
||||
return (char_type*)memmove( lhs, rhs, N * sizeof(char_type) );
|
||||
static char_type* move(char_type* lhs, const char_type* rhs, size_t N)
|
||||
{
|
||||
return (char_type*)memmove(lhs, rhs, N * sizeof(char_type));
|
||||
}
|
||||
|
||||
static
|
||||
char_type* assign( char_type* lhs, size_t N, char_type ch )
|
||||
static char_type* assign(char_type* lhs, size_t N, char_type ch)
|
||||
{
|
||||
for ( char_type* at = lhs; N; ++at, --N )
|
||||
for (char_type* at = lhs; N; ++at, --N)
|
||||
*at = ch;
|
||||
return lhs;
|
||||
}
|
||||
|
||||
static
|
||||
int_type not_eof( const int_type& ch ) {
|
||||
return int_type( !eq( ch, eof() ) ? ch : ~ch );
|
||||
}
|
||||
|
||||
static
|
||||
char_type to_char_type( const int_type& ch )
|
||||
static int_type not_eof(const int_type& ch)
|
||||
{
|
||||
return
|
||||
eq_int_type( ch, to_int_type( ch ) )
|
||||
? ch
|
||||
: char_type(0);
|
||||
return int_type(!eq(ch, eof()) ? ch : ~ch);
|
||||
}
|
||||
|
||||
static
|
||||
int_type to_int_type( const char_type& ch ) {
|
||||
static char_type to_char_type(const int_type& ch)
|
||||
{
|
||||
return eq_int_type(ch, to_int_type(ch)) ? ch : char_type(0);
|
||||
}
|
||||
|
||||
static int_type to_int_type(const char_type& ch)
|
||||
{
|
||||
return (int_type)ch;
|
||||
}
|
||||
|
||||
static
|
||||
bool eq_int_type( const int_type& lhs, const int_type& rhs ) {
|
||||
static bool eq_int_type(const int_type& lhs, const int_type& rhs)
|
||||
{
|
||||
return lhs == rhs;
|
||||
}
|
||||
|
||||
#if IS_STDLIB_MODENA
|
||||
# if IS_STDLIB_MODENA
|
||||
|
||||
// CAUTION:RAD -- Extra members required by Modena!!
|
||||
|
||||
#ifdef MBSTATE_T_DEFINED // This is ANSI-C *not* ANSI-C++!!
|
||||
static
|
||||
state_type get_state( pos_type pos ) {
|
||||
# ifdef MBSTATE_T_DEFINED // This is ANSI-C *not* ANSI-C++!!
|
||||
static state_type get_state(pos_type pos)
|
||||
{
|
||||
return pos.state();
|
||||
}
|
||||
|
||||
static
|
||||
pos_type get_pos( pos_type pos, state_type state ) {
|
||||
return pos_type( pos.offset(), state );
|
||||
static pos_type get_pos(pos_type pos, state_type state)
|
||||
{
|
||||
return pos_type(pos.offset(), state);
|
||||
}
|
||||
#endif//MBSTATE_T_DEFINED
|
||||
# endif //MBSTATE_T_DEFINED
|
||||
|
||||
static
|
||||
char_type newline() {
|
||||
static char_type newline()
|
||||
{
|
||||
return L'\n';
|
||||
}
|
||||
|
||||
static
|
||||
char_type eos() {
|
||||
static char_type eos()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif//IS_STDLIB_MODENA
|
||||
# endif //IS_STDLIB_MODENA
|
||||
|
||||
static
|
||||
int_type eof() {
|
||||
static int_type eof()
|
||||
{
|
||||
return (wint_t)(0xFFFF);
|
||||
}
|
||||
};
|
||||
|
||||
#endif//WCHAR_IS_16_BITS // We already have a dbstring implicitly in wstring!!!
|
||||
# endif //WCHAR_IS_16_BITS // We already have a dbstring implicitly in wstring!!!
|
||||
|
||||
|
||||
#endif//__NTDBS_H
|
||||
|
||||
#endif //__NTDBS_H
|
||||
|
|
|
@ -3,29 +3,29 @@
|
|||
// Portions created by Tripwire, Inc. are copyright (C) 2000-2018 Tripwire,
|
||||
// Inc. Tripwire is a registered trademark of Tripwire, Inc. All rights
|
||||
// reserved.
|
||||
//
|
||||
//
|
||||
// This program is free software. The contents of this file are subject
|
||||
// to the terms of the GNU General Public License as published by the
|
||||
// Free Software Foundation; either version 2 of the License, or (at your
|
||||
// option) any later version. You may redistribute it and/or modify it
|
||||
// only in compliance with the GNU General Public License.
|
||||
//
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful.
|
||||
// However, this program is distributed AS-IS WITHOUT ANY
|
||||
// WARRANTY; INCLUDING THE IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS
|
||||
// FOR A PARTICULAR PURPOSE. Please see the GNU General Public License
|
||||
// for more details.
|
||||
//
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
|
||||
// USA.
|
||||
//
|
||||
//
|
||||
// Nothing in the GNU General Public License or any other license to use
|
||||
// the code or files shall permit you to use Tripwire's trademarks,
|
||||
// service marks, or other intellectual property without Tripwire's
|
||||
// prior written consent.
|
||||
//
|
||||
//
|
||||
// If you have any questions, please contact Tripwire, Inc. at either
|
||||
// info@tripwire.org or www.tripwire.org.
|
||||
//
|
||||
|
@ -38,20 +38,18 @@
|
|||
* Routines to make NTMBS processing easier.
|
||||
*/
|
||||
|
||||
#include "stdcore.h" // for: pch
|
||||
#include "ntmbs.h" // for: These Declarations
|
||||
#include "stdcore.h" // for: pch
|
||||
#include "ntmbs.h" // for: These Declarations
|
||||
|
||||
|
||||
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
// Module-wide Helpers
|
||||
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
|
||||
#ifndef TSS_Raise // Should add file and line info in DEBUG mode!!!!
|
||||
#define TSS_Raise( Xcpt, pkg, ids ) \
|
||||
throw Xcpt( TSS_GetString( pkg, ids ) )
|
||||
|
||||
#endif//TSS_Raise
|
||||
#ifndef TSS_Raise // Should add file and line info in DEBUG mode!!!!
|
||||
# define TSS_Raise(Xcpt, pkg, ids) throw Xcpt(TSS_GetString(pkg, ids))
|
||||
|
||||
#endif //TSS_Raise
|
||||
|
||||
|
||||
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
|
@ -134,32 +132,28 @@ tss::mbsdec( const_ntmbs_t beg, const_ntmbs_t curr )
|
|||
* POSTCONDITIONS:
|
||||
* Returns non-const pointer after moving it.
|
||||
*/
|
||||
ntmbs_t
|
||||
tss::mbsinc( const_ntmbs_t psz )
|
||||
ntmbs_t tss::mbsinc(const_ntmbs_t psz)
|
||||
{
|
||||
cDebug dbg( "tss::mbsinc -" );
|
||||
cDebug dbg("tss::mbsinc -");
|
||||
|
||||
if ( psz == 0 )
|
||||
throw eCharacter( TSS_GetString( cCore, core::STR_ERR_ISNULL ) );
|
||||
if (psz == 0)
|
||||
throw eCharacter(TSS_GetString(cCore, core::STR_ERR_ISNULL));
|
||||
|
||||
int nBytes = ::mblen( (char*)psz, MB_CUR_MAX );
|
||||
if ( nBytes == -1 )
|
||||
int nBytes = ::mblen((char*)psz, MB_CUR_MAX);
|
||||
if (nBytes == -1)
|
||||
{
|
||||
dbg.TraceDebug( "Character Fault: %c\n", *psz );
|
||||
if ( (unsigned char)*psz > 0x7F )
|
||||
dbg.TraceDebug("Character Fault: %c\n", *psz);
|
||||
if ((unsigned char)*psz > 0x7F)
|
||||
{
|
||||
dbg.TraceDebug( "Normalizing.\n" );
|
||||
return (((ntmbs_t)psz) + 1 );
|
||||
dbg.TraceDebug("Normalizing.\n");
|
||||
return (((ntmbs_t)psz) + 1);
|
||||
}
|
||||
|
||||
dbg.TraceDebug( "Incorrectly Formed, Cannot Normalize!\n" );
|
||||
TSS_Raise(
|
||||
eCharacterEncoding,
|
||||
cCore,
|
||||
core::STR_ERR_BADCHAR );
|
||||
dbg.TraceDebug("Incorrectly Formed, Cannot Normalize!\n");
|
||||
TSS_Raise(eCharacterEncoding, cCore, core::STR_ERR_BADCHAR);
|
||||
}
|
||||
|
||||
return ( ((ntmbs_t)psz) + nBytes );
|
||||
return (((ntmbs_t)psz) + nBytes);
|
||||
}
|
||||
|
||||
|
||||
|
@ -180,33 +174,30 @@ tss::mbsinc( const_ntmbs_t psz )
|
|||
* POSTCONDITIONS:
|
||||
* Returns size_t value indicating bytes in the range of [0,nCount).
|
||||
*/
|
||||
size_t
|
||||
tss::mbsbytes( const_ntmbs_t psz, size_t nCount )
|
||||
size_t tss::mbsbytes(const_ntmbs_t psz, size_t nCount)
|
||||
{
|
||||
const_ntmbs_t at = psz;
|
||||
while ( nCount-- )
|
||||
at = tss::mbsinc( at );
|
||||
while (nCount--)
|
||||
at = tss::mbsinc(at);
|
||||
|
||||
return (size_t)((char*)at - (char*)psz);
|
||||
}
|
||||
|
||||
/// To Null terminator
|
||||
|
||||
size_t
|
||||
tss::mbsbytes( const_ntmbs_t psz )
|
||||
size_t tss::mbsbytes(const_ntmbs_t psz)
|
||||
{
|
||||
if ( psz == 0 )
|
||||
throw eCharacter( TSS_GetString( cCore, core::STR_ERR_ISNULL ) );
|
||||
if (psz == 0)
|
||||
throw eCharacter(TSS_GetString(cCore, core::STR_ERR_ISNULL));
|
||||
|
||||
|
||||
const_ntmbs_t at;
|
||||
for ( at = psz; *at; ++at );
|
||||
for (at = psz; *at; ++at)
|
||||
;
|
||||
return (size_t)((char*)at - (char*)psz);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* TSS::mbscount
|
||||
*
|
||||
|
@ -224,25 +215,22 @@ tss::mbsbytes( const_ntmbs_t psz )
|
|||
* POSTCONDITIONS:
|
||||
* Returns size_t value indicating characters in the range of [psz + 0, psz + nBytes).
|
||||
*/
|
||||
size_t
|
||||
tss_mbscount( const_ntmbs_t psz, size_t nBytes )
|
||||
size_t tss_mbscount(const_ntmbs_t psz, size_t nBytes)
|
||||
{
|
||||
size_t nCount = 0;
|
||||
const_ntmbs_t at = psz;
|
||||
const_ntmbs_t end = psz + nBytes;
|
||||
for ( ; at < end; nCount++, at = tss::mbsinc( at ) );
|
||||
size_t nCount = 0;
|
||||
const_ntmbs_t at = psz;
|
||||
const_ntmbs_t end = psz + nBytes;
|
||||
for (; at < end; nCount++, at = tss::mbsinc(at))
|
||||
;
|
||||
return nCount;
|
||||
}
|
||||
|
||||
/// To Null terminator
|
||||
|
||||
size_t
|
||||
tss::mbscount( const_ntmbs_t psz )
|
||||
size_t tss::mbscount(const_ntmbs_t psz)
|
||||
{
|
||||
size_t nCount = 0;
|
||||
for ( ; *psz; psz = tss::mbsinc( psz ), nCount++ );
|
||||
for (; *psz; psz = tss::mbsinc(psz), nCount++)
|
||||
;
|
||||
return nCount;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
646
src/core/ntmbs.h
646
src/core/ntmbs.h
|
@ -3,29 +3,29 @@
|
|||
// Portions created by Tripwire, Inc. are copyright (C) 2000-2018 Tripwire,
|
||||
// Inc. Tripwire is a registered trademark of Tripwire, Inc. All rights
|
||||
// reserved.
|
||||
//
|
||||
//
|
||||
// This program is free software. The contents of this file are subject
|
||||
// to the terms of the GNU General Public License as published by the
|
||||
// Free Software Foundation; either version 2 of the License, or (at your
|
||||
// option) any later version. You may redistribute it and/or modify it
|
||||
// only in compliance with the GNU General Public License.
|
||||
//
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful.
|
||||
// However, this program is distributed AS-IS WITHOUT ANY
|
||||
// WARRANTY; INCLUDING THE IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS
|
||||
// FOR A PARTICULAR PURPOSE. Please see the GNU General Public License
|
||||
// for more details.
|
||||
//
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
|
||||
// USA.
|
||||
//
|
||||
//
|
||||
// Nothing in the GNU General Public License or any other license to use
|
||||
// the code or files shall permit you to use Tripwire's trademarks,
|
||||
// service marks, or other intellectual property without Tripwire's
|
||||
// prior written consent.
|
||||
//
|
||||
//
|
||||
// If you have any questions, please contact Tripwire, Inc. at either
|
||||
// info@tripwire.org or www.tripwire.org.
|
||||
//
|
||||
|
@ -45,9 +45,9 @@
|
|||
|
||||
/// Requirements.
|
||||
|
||||
#include "error.h" // for: TSS_EXCEPTION
|
||||
#include "package.h" // for: TSS_GetString
|
||||
#include "corestrings.h" // for: Utility Strings
|
||||
#include "error.h" // for: TSS_EXCEPTION
|
||||
#include "package.h" // for: TSS_GetString
|
||||
#include "corestrings.h" // for: Utility Strings
|
||||
|
||||
|
||||
/// Type Definitions for Multiple (?), Double (16), and Wide Characters (32)
|
||||
|
@ -55,28 +55,27 @@
|
|||
//--Null-terminated Multibyte Character Sequence
|
||||
|
||||
#ifndef NTMBS_T_DEFINED
|
||||
#define NTMBS_T_DEFINED
|
||||
#ifdef TSS_NTMBS_IS_UNSIGNED // Natural-sign by default
|
||||
typedef unsigned char mbchar_t;
|
||||
typedef unsigned char* ntmbs_t;
|
||||
typedef const unsigned char* const_ntmbs_t;
|
||||
#else //TSS_NTMBS_IS_UNSIGNED
|
||||
typedef char mbchar_t;
|
||||
typedef char* ntmbs_t;
|
||||
typedef const char* const_ntmbs_t;
|
||||
#endif//TSS_NTMBS_IS_UNSIGNED
|
||||
#endif//NTMBS_T_DEFINED
|
||||
# define NTMBS_T_DEFINED
|
||||
# ifdef TSS_NTMBS_IS_UNSIGNED // Natural-sign by default
|
||||
typedef unsigned char mbchar_t;
|
||||
typedef unsigned char* ntmbs_t;
|
||||
typedef const unsigned char* const_ntmbs_t;
|
||||
# else //TSS_NTMBS_IS_UNSIGNED
|
||||
typedef char mbchar_t;
|
||||
typedef char* ntmbs_t;
|
||||
typedef const char* const_ntmbs_t;
|
||||
# endif //TSS_NTMBS_IS_UNSIGNED
|
||||
#endif //NTMBS_T_DEFINED
|
||||
|
||||
|
||||
//--Null-terminated Wide Character Sequence (Could be double or quad byte)
|
||||
|
||||
#ifndef NTWCS_T_DEFINED
|
||||
#define NTWCS_T_DEFINED
|
||||
//typedef wchar_t wchar_t;
|
||||
typedef wchar_t* ntwcs_t;
|
||||
typedef const wchar_t* const_ntwcs_t;
|
||||
#endif//NTWCS_T_DEFINED
|
||||
|
||||
# define NTWCS_T_DEFINED
|
||||
//typedef wchar_t wchar_t;
|
||||
typedef wchar_t* ntwcs_t;
|
||||
typedef const wchar_t* const_ntwcs_t;
|
||||
#endif //NTWCS_T_DEFINED
|
||||
|
||||
|
||||
/// NOTE: Size Specific (2 [double] or 4 [quad] byte wide characters)
|
||||
|
@ -84,57 +83,57 @@
|
|||
//--Null-terminated double(2)-byte Character Sequence
|
||||
|
||||
#ifndef NTDBS_T_DEFINED
|
||||
#define NTDBS_T_DEFINED
|
||||
#if WCHAR_IS_16_BITS
|
||||
typedef wchar_t dbchar_t; // Same size but use NT's type
|
||||
#else
|
||||
typedef uint16 dbchar_t;
|
||||
#endif
|
||||
typedef dbchar_t* ntdbs_t;
|
||||
typedef const dbchar_t* const_ntdbs_t;
|
||||
#endif//NTDBS_T_DEFINED
|
||||
# define NTDBS_T_DEFINED
|
||||
# if WCHAR_IS_16_BITS
|
||||
typedef wchar_t dbchar_t; // Same size but use NT's type
|
||||
# else
|
||||
typedef uint16 dbchar_t;
|
||||
# endif
|
||||
typedef dbchar_t* ntdbs_t;
|
||||
typedef const dbchar_t* const_ntdbs_t;
|
||||
#endif //NTDBS_T_DEFINED
|
||||
|
||||
|
||||
//--Internal, "size-specific" types for type dispatched specializations
|
||||
|
||||
#ifndef NTQBS_T_DEFINED
|
||||
#define NTQBS_T_DEFINED
|
||||
#if WCHAR_IS_32_BITS
|
||||
typedef wchar_t qbchar_t; // Same size but use NT's type
|
||||
#else
|
||||
typedef uint32 qbchar_t;
|
||||
#endif
|
||||
typedef qbchar_t* ntqbs_t;
|
||||
typedef const qbchar_t* const_ntqbs_t;
|
||||
#endif//NTQBS_T_DEFINED
|
||||
|
||||
# define NTQBS_T_DEFINED
|
||||
# if WCHAR_IS_32_BITS
|
||||
typedef wchar_t qbchar_t; // Same size but use NT's type
|
||||
# else
|
||||
typedef uint32 qbchar_t;
|
||||
# endif
|
||||
typedef qbchar_t* ntqbs_t;
|
||||
typedef const qbchar_t* const_ntqbs_t;
|
||||
#endif //NTQBS_T_DEFINED
|
||||
|
||||
|
||||
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
// NTMBS Manipulators
|
||||
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
|
||||
TSS_EXCEPTION( eCharacter, eError );
|
||||
TSS_EXCEPTION( eCharacterEncoding, eCharacter );
|
||||
TSS_EXCEPTION(eCharacter, eError);
|
||||
TSS_EXCEPTION(eCharacterEncoding, eCharacter);
|
||||
|
||||
|
||||
namespace tss
|
||||
{
|
||||
/// Specific Routines (Add as needed)
|
||||
/// Specific Routines (Add as needed)
|
||||
|
||||
//ntmbs_t mbsdec( const_ntmbs_t, const_ntmbs_t );
|
||||
ntmbs_t mbsinc( const_ntmbs_t );
|
||||
//ntmbs_t mbsdec( const_ntmbs_t, const_ntmbs_t );
|
||||
ntmbs_t mbsinc(const_ntmbs_t);
|
||||
|
||||
size_t mbsbytes( const_ntmbs_t, size_t );
|
||||
size_t mbscount( const_ntmbs_t, size_t );
|
||||
size_t mbsbytes(const_ntmbs_t, size_t);
|
||||
size_t mbscount(const_ntmbs_t, size_t);
|
||||
|
||||
size_t mbsbytes( const_ntmbs_t );
|
||||
size_t mbscount( const_ntmbs_t );
|
||||
size_t mbsbytes(const_ntmbs_t);
|
||||
size_t mbscount(const_ntmbs_t);
|
||||
|
||||
inline size_t mbslen( const_ntmbs_t psz ) { // RAD: Yeesh!
|
||||
return tss::mbscount( psz );
|
||||
}
|
||||
}//tss::
|
||||
inline size_t mbslen(const_ntmbs_t psz)
|
||||
{ // RAD: Yeesh!
|
||||
return tss::mbscount(psz);
|
||||
}
|
||||
} // namespace tss
|
||||
|
||||
|
||||
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
|
@ -145,15 +144,14 @@ namespace tss
|
|||
|
||||
namespace tss
|
||||
{
|
||||
/// Increment and Decrement Pointers by (N)
|
||||
/// Increment and Decrement Pointers by (N)
|
||||
|
||||
//--DEC
|
||||
//--DEC
|
||||
|
||||
template< class CT >
|
||||
inline
|
||||
CT* strdec( const CT*, const CT* psz ) {
|
||||
return const_cast<CT*>( psz - 1 );
|
||||
}
|
||||
template<class CT> inline CT* strdec(const CT*, const CT* psz)
|
||||
{
|
||||
return const_cast<CT*>(psz - 1);
|
||||
}
|
||||
|
||||
#if 0
|
||||
template<>
|
||||
|
@ -164,96 +162,86 @@ namespace tss
|
|||
#endif
|
||||
|
||||
|
||||
//--INC
|
||||
//--INC
|
||||
|
||||
template< class CT >
|
||||
inline
|
||||
CT* strinc( const CT* psz )
|
||||
{
|
||||
ASSERT( psz );
|
||||
return const_cast<CT*>( ( *psz ? psz + 1 : psz ) );
|
||||
}
|
||||
template<class CT> inline CT* strinc(const CT* psz)
|
||||
{
|
||||
ASSERT(psz);
|
||||
return const_cast<CT*>((*psz ? psz + 1 : psz));
|
||||
}
|
||||
|
||||
template< class CT, class SIZET >
|
||||
inline
|
||||
CT* strinc( const CT* psz, SIZET N )
|
||||
{
|
||||
ASSERT( psz );
|
||||
return const_cast<CT*>( ( *psz ? psz + N : psz ) );
|
||||
}
|
||||
|
||||
|
||||
template<>
|
||||
inline
|
||||
ntmbs_t strinc( const_ntmbs_t psz )
|
||||
{
|
||||
return tss::mbsinc( psz );
|
||||
}
|
||||
|
||||
template<>
|
||||
inline
|
||||
ntmbs_t strinc( const_ntmbs_t psz, size_t N )
|
||||
{
|
||||
ntmbs_t at = const_cast<ntmbs_t>( psz );
|
||||
while ( N-- )
|
||||
at = tss::mbsinc( at );
|
||||
return at;
|
||||
}
|
||||
template<class CT, class SIZET> inline CT* strinc(const CT* psz, SIZET N)
|
||||
{
|
||||
ASSERT(psz);
|
||||
return const_cast<CT*>((*psz ? psz + N : psz));
|
||||
}
|
||||
|
||||
|
||||
/// Byte and Character Count Mappings
|
||||
template<> inline ntmbs_t strinc(const_ntmbs_t psz)
|
||||
{
|
||||
return tss::mbsinc(psz);
|
||||
}
|
||||
|
||||
template<> inline ntmbs_t strinc(const_ntmbs_t psz, size_t N)
|
||||
{
|
||||
ntmbs_t at = const_cast<ntmbs_t>(psz);
|
||||
while (N--)
|
||||
at = tss::mbsinc(at);
|
||||
return at;
|
||||
}
|
||||
|
||||
|
||||
//--BYTES
|
||||
|
||||
template< class CT >
|
||||
size_t strsize( const CT* psz )
|
||||
{
|
||||
const CT* at = psz;
|
||||
while ( *at ) at++;
|
||||
return (size_t)((char*)at - (char*)psz);
|
||||
}
|
||||
|
||||
template< class CT >
|
||||
size_t strsize( const CT*, size_t N )
|
||||
{
|
||||
return N * sizeof(CT);
|
||||
}
|
||||
|
||||
template<>
|
||||
inline size_t strsize( const_ntmbs_t psz ) {
|
||||
return mbsbytes( psz );
|
||||
}
|
||||
template<>
|
||||
inline size_t strsize( const_ntmbs_t psz, size_t N ) {
|
||||
return mbsbytes( psz, N );
|
||||
}
|
||||
/// Byte and Character Count Mappings
|
||||
|
||||
|
||||
//--COUNT
|
||||
//--BYTES
|
||||
|
||||
template< class CT >
|
||||
size_t strcount( const CT* psz )
|
||||
{
|
||||
const CT* at = psz;
|
||||
while ( *at ) at++;
|
||||
return (size_t)(at - psz);
|
||||
}
|
||||
template<class CT> size_t strsize(const CT* psz)
|
||||
{
|
||||
const CT* at = psz;
|
||||
while (*at)
|
||||
at++;
|
||||
return (size_t)((char*)at - (char*)psz);
|
||||
}
|
||||
|
||||
template< class CT >
|
||||
size_t strcount( const CT*, size_t N )
|
||||
{
|
||||
return N;
|
||||
}
|
||||
|
||||
template<>
|
||||
inline size_t strcount( const_ntmbs_t psz ) {
|
||||
return mbscount( psz );
|
||||
}
|
||||
template<>
|
||||
inline size_t strcount( const_ntmbs_t psz, size_t N ) {
|
||||
return mbscount( psz, N );
|
||||
}
|
||||
template<class CT> size_t strsize(const CT*, size_t N)
|
||||
{
|
||||
return N * sizeof(CT);
|
||||
}
|
||||
|
||||
template<> inline size_t strsize(const_ntmbs_t psz)
|
||||
{
|
||||
return mbsbytes(psz);
|
||||
}
|
||||
template<> inline size_t strsize(const_ntmbs_t psz, size_t N)
|
||||
{
|
||||
return mbsbytes(psz, N);
|
||||
}
|
||||
|
||||
|
||||
//--COUNT
|
||||
|
||||
template<class CT> size_t strcount(const CT* psz)
|
||||
{
|
||||
const CT* at = psz;
|
||||
while (*at)
|
||||
at++;
|
||||
return (size_t)(at - psz);
|
||||
}
|
||||
|
||||
template<class CT> size_t strcount(const CT*, size_t N)
|
||||
{
|
||||
return N;
|
||||
}
|
||||
|
||||
template<> inline size_t strcount(const_ntmbs_t psz)
|
||||
{
|
||||
return mbscount(psz);
|
||||
}
|
||||
template<> inline size_t strcount(const_ntmbs_t psz, size_t N)
|
||||
{
|
||||
return mbscount(psz, N);
|
||||
}
|
||||
|
||||
|
||||
/* These are needed! However, it would be better to just create
|
||||
|
@ -262,7 +250,7 @@ done with it */
|
|||
|
||||
#ifdef TSS_NTMBS_AWARE_SEACH_COMPLETE
|
||||
|
||||
/* CAUTION:RAD -- I changed the traversal logic from "!=" to
|
||||
/* CAUTION:RAD -- I changed the traversal logic from "!=" to
|
||||
"<" to accomodate a basic_string whose end() member does not
|
||||
correctly point after the last valid trail-byte in a string.
|
||||
Really, at != end should be correct, but I don't want to leave
|
||||
|
@ -270,243 +258,209 @@ done with it */
|
|||
under unit test and have all occurances of "at < end" changed
|
||||
to the "more on-purpose" "at != end". */
|
||||
|
||||
/// Various MULTIBYTE aware string searching routines..
|
||||
/// Various MULTIBYTE aware string searching routines..
|
||||
|
||||
//--FIND_FIRST: ITER
|
||||
//--FIND_FIRST: ITER
|
||||
|
||||
template< class InputT, class E >
|
||||
InputT
|
||||
find_first( InputT beg, InputT end, const E& item )
|
||||
{
|
||||
for ( ; beg < end && *beg != item; beg = (InputT)tss::strinc( beg ) );
|
||||
return beg;
|
||||
}
|
||||
|
||||
|
||||
//--FIND_LAST: ITER
|
||||
|
||||
template< class InputT, class E >
|
||||
InputT
|
||||
find_last( InputT beg, InputT end, const E& item )
|
||||
{
|
||||
InputT at = end;
|
||||
for ( ; beg < end ; beg = (InputT)tss::strinc( beg ) );
|
||||
if ( *beg == item )
|
||||
at = beg;
|
||||
|
||||
return at;
|
||||
}
|
||||
template<class InputT, class E> InputT find_first(InputT beg, InputT end, const E& item)
|
||||
{
|
||||
for (; beg < end && *beg != item; beg = (InputT)tss::strinc(beg))
|
||||
;
|
||||
return beg;
|
||||
}
|
||||
|
||||
|
||||
//--FIND_FIRST: STRING
|
||||
//--FIND_LAST: ITER
|
||||
|
||||
template< class StrT >
|
||||
StrT::size_type
|
||||
find_first( const StrT& sin, StrT::const_reference item )
|
||||
{
|
||||
StrT::const_iterator
|
||||
beg = sin.begin();
|
||||
end = sin.end();
|
||||
template<class InputT, class E> InputT find_last(InputT beg, InputT end, const E& item)
|
||||
{
|
||||
InputT at = end;
|
||||
for (; beg < end; beg = (InputT)tss::strinc(beg))
|
||||
;
|
||||
if (*beg == item)
|
||||
at = beg;
|
||||
|
||||
StrT::size_type N;
|
||||
for ( N = 0; beg < end; ++N, beg = (InputT)tss::strinc( beg ) )
|
||||
if ( *beg == item )
|
||||
return at;
|
||||
}
|
||||
|
||||
|
||||
//--FIND_FIRST: STRING
|
||||
|
||||
template<class StrT> StrT::size_type find_first(const StrT& sin, StrT::const_reference item)
|
||||
{
|
||||
StrT::const_iterator beg = sin.begin();
|
||||
end = sin.end();
|
||||
|
||||
StrT::size_type N;
|
||||
for (N = 0; beg < end; ++N, beg = (InputT)tss::strinc(beg))
|
||||
if (*beg == item)
|
||||
return N;
|
||||
|
||||
return StrT::npos;
|
||||
}
|
||||
|
||||
|
||||
//--FIND_LAST: STRING
|
||||
|
||||
template<class StrT> StrT::size_type find_last(const StrT& sin, StrT::const_reference item)
|
||||
{
|
||||
StrT::size_type N = 0;
|
||||
StrT::size_type nResult = StrT::npos;
|
||||
StrT::const_iterator beg = sin.begin();
|
||||
end = sin.end();
|
||||
|
||||
for (; beg < end; beg = (InputT)tss::strinc(beg))
|
||||
;
|
||||
if (*beg == item)
|
||||
nResult = N;
|
||||
|
||||
return N;
|
||||
}
|
||||
|
||||
|
||||
//--FIND_FIRST_OF: ITER
|
||||
|
||||
template<class InputT> InputT find_first_of(InputT beg, InputT end, InputT setbeg, InputT setend)
|
||||
{
|
||||
InputT at;
|
||||
for (; beg < end; beg = (InputT)tss::strinc(beg))
|
||||
;
|
||||
for (at = setbeg; setbeg < setend; at = (InputT)tss::strinc(at))
|
||||
if (*beg == *at)
|
||||
return beg;
|
||||
|
||||
return end;
|
||||
}
|
||||
|
||||
|
||||
//--FIND_FIRST_OF: STRING (SAFE!!!)
|
||||
|
||||
template<class StrT> StrT::size_type find_first_of(const StrT& sin, StrT::const_iterator set)
|
||||
{
|
||||
// Point to beg of input
|
||||
StrT::iterator beg = sin.begin();
|
||||
|
||||
// Start Search
|
||||
StrT::size_type N = 0;
|
||||
for (; beg < sin.end(); ++N, beg = tss::strinc(beg))
|
||||
for (StrT::const_iterator at = set; *at; at = tss::strinc(at))
|
||||
if (*beg == *at)
|
||||
return N;
|
||||
|
||||
return StrT::npos;
|
||||
}
|
||||
|
||||
|
||||
//--FIND_LAST: STRING
|
||||
|
||||
template< class StrT >
|
||||
StrT::size_type
|
||||
find_last( const StrT& sin, StrT::const_reference item )
|
||||
{
|
||||
StrT::size_type N = 0;
|
||||
StrT::size_type nResult = StrT::npos;
|
||||
StrT::const_iterator
|
||||
beg = sin.begin();
|
||||
end = sin.end();
|
||||
|
||||
for ( ; beg < end ; beg = (InputT)tss::strinc( beg ) );
|
||||
if ( *beg == item )
|
||||
nResult = N;
|
||||
|
||||
return N;
|
||||
}
|
||||
return StrT::npos;
|
||||
}
|
||||
|
||||
|
||||
//--FIND_FIRST_OF: ITER
|
||||
//--FIND_FIRST_OF: STRING (NOT SAFE!!!)
|
||||
|
||||
template< class InputT >
|
||||
InputT
|
||||
find_first_of(
|
||||
InputT beg,
|
||||
InputT end,
|
||||
InputT setbeg,
|
||||
InputT setend )
|
||||
{
|
||||
InputT at;
|
||||
for ( ; beg < end; beg = (InputT)tss::strinc( beg ) );
|
||||
for ( at = setbeg; setbeg < setend; at = (InputT)tss::strinc( at ) )
|
||||
if ( *beg == *at )
|
||||
return beg;
|
||||
|
||||
return end;
|
||||
}
|
||||
|
||||
|
||||
//--FIND_FIRST_OF: STRING (SAFE!!!)
|
||||
|
||||
template< class StrT >
|
||||
StrT::size_type
|
||||
find_first_of( const StrT& sin, StrT::const_iterator set )
|
||||
{
|
||||
// Point to beg of input
|
||||
StrT::iterator beg = sin.begin();
|
||||
|
||||
// Start Search
|
||||
StrT::size_type N = 0;
|
||||
for ( ; beg < sin.end(); ++N, beg = tss::strinc( beg ) )
|
||||
for ( StrT::const_iterator at = set; *at; at = tss::strinc( at ) )
|
||||
if ( *beg == *at )
|
||||
return N;
|
||||
|
||||
return StrT::npos;
|
||||
}
|
||||
|
||||
|
||||
//--FIND_FIRST_OF: STRING (NOT SAFE!!!)
|
||||
|
||||
template< class StrT >
|
||||
StrT::size_type
|
||||
find_first_of(
|
||||
const StrT& sin,
|
||||
StrT::const_iterator set,
|
||||
StrT::size_type nPos,
|
||||
StrT::size_type nCount )
|
||||
{
|
||||
template<class StrT>
|
||||
StrT::size_type find_first_of(const StrT& sin, StrT::const_iterator set, StrT::size_type nPos, StrT::size_type nCount)
|
||||
{
|
||||
ASSERT( nPos < tss::strcount( sin.begin() );
|
||||
|
||||
if ( nCount > 0 && nPos < sin.size() )
|
||||
{
|
||||
ASSERT( nCount > tss::strcount( set ) );
|
||||
StrT::const_iterator endset; // Get end of set
|
||||
while ( nCount-- ) endset++;
|
||||
ASSERT(nCount > tss::strcount(set));
|
||||
StrT::const_iterator endset; // Get end of set
|
||||
while (nCount--)
|
||||
endset++;
|
||||
|
||||
// Advance to nPos
|
||||
StrT::const_iterator at = tss::strinc( sin.begin(), nPos );
|
||||
StrT::const_iterator end = sin.end();
|
||||
// Advance to nPos
|
||||
StrT::const_iterator at = tss::strinc(sin.begin(), nPos);
|
||||
StrT::const_iterator end = sin.end();
|
||||
|
||||
// Start Search
|
||||
StrT::size_type N = 0;
|
||||
for ( ; at < end; ++N, at = tss::strinc( at ) )
|
||||
{
|
||||
if ( tss::find( set, endset, *at ) != 0 )
|
||||
return N;
|
||||
}
|
||||
// Start Search
|
||||
StrT::size_type N = 0;
|
||||
for (; at < end; ++N, at = tss::strinc(at))
|
||||
{
|
||||
if (tss::find(set, endset, *at) != 0)
|
||||
return N;
|
||||
}
|
||||
}
|
||||
|
||||
return StrT::npos;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//--FIND_LAST_OF: ITER
|
||||
//--FIND_LAST_OF: ITER
|
||||
|
||||
template< class InputT1, class InputT2 >
|
||||
InputT
|
||||
find_last_of(
|
||||
const InputT1 beg, const InputT1 end,
|
||||
const InputT2 setbeg, const InputT2 setend )
|
||||
template<class InputT1, class InputT2>
|
||||
InputT find_last_of(const InputT1 beg, const InputT1 end, const InputT2 setbeg, const InputT2 setend)
|
||||
{
|
||||
const InputT1 ans = end;
|
||||
for (; beg < end; beg = tss::strinc(beg))
|
||||
;
|
||||
for (InputT2 at = setbeg; setbeg != setend; at = tss::strinc(at))
|
||||
if (*beg == *at)
|
||||
ans = beg;
|
||||
|
||||
return ans;
|
||||
}
|
||||
|
||||
|
||||
//--FIND_LAST_OF: STRING (SAFE!!!)
|
||||
|
||||
template<class StrT> StrT::size_type find_last_of(const StrT& sin, StrT::const_iterator set)
|
||||
{
|
||||
StrT::size_type nResult = StrT::npos;
|
||||
StrT::size_type N = 0;
|
||||
for (; at < end; ++N, at = tss::strinc(at))
|
||||
{
|
||||
const InputT1 ans = end;
|
||||
for ( ; beg < end; beg = tss::strinc( beg ) );
|
||||
for ( InputT2 at = setbeg; setbeg != setend; at = tss::strinc( at ) )
|
||||
if ( *beg == *at )
|
||||
ans = beg;
|
||||
|
||||
return ans;
|
||||
for (StrT::const_iterator at = set; *at; at = tss::strinc(at))
|
||||
if (*beg == *at)
|
||||
nResult = N;
|
||||
}
|
||||
|
||||
return nResult;
|
||||
}
|
||||
|
||||
//--FIND_LAST_OF: STRING (SAFE!!!)
|
||||
|
||||
template< class StrT >
|
||||
StrT::size_type
|
||||
find_last_of( const StrT& sin, StrT::const_iterator set )
|
||||
template<class StrT>
|
||||
StrT::size_type find_last_of(const StrT& sin, StrT::const_iterator set, StrT::size_type nStart, StrT::size_type nCount)
|
||||
{
|
||||
if (nCount > 0 && sin.size())
|
||||
{
|
||||
StrT::size_type nResult = StrT::npos;
|
||||
StrT::size_type N = 0;
|
||||
for ( ; at < end; ++N, at = tss::strinc( at ) )
|
||||
{
|
||||
for ( StrT::const_iterator at = set; *at; at = tss::strinc( at ) )
|
||||
if ( *beg == *at )
|
||||
nResult = N;
|
||||
}
|
||||
|
||||
return nResult;
|
||||
for (StrT::const_iterator at = sin.begin() + (nStart < _Len ? nStart : _Len - 1);; --_U)
|
||||
if (_Tr::find(set, nCount, *_U) != 0)
|
||||
return (_U - _Ptr);
|
||||
else if (_U == _Ptr)
|
||||
break;
|
||||
}
|
||||
|
||||
return StrT::npos;
|
||||
}
|
||||
|
||||
template< class StrT >
|
||||
StrT::size_type
|
||||
find_last_of(
|
||||
const StrT& sin,
|
||||
StrT::const_iterator set,
|
||||
StrT::size_type nStart,
|
||||
StrT::size_type nCount )
|
||||
{
|
||||
if ( nCount > 0 && sin.size() )
|
||||
{
|
||||
for ( StrT::const_iterator at = sin.begin()
|
||||
+ (nStart < _Len ? nStart : _Len - 1); ; --_U)
|
||||
if (_Tr::find(set, nCount, *_U) != 0)
|
||||
return (_U - _Ptr);
|
||||
else if (_U == _Ptr)
|
||||
break;
|
||||
}
|
||||
// TODO:RAD -- find_first_not_of;
|
||||
// TODO:RAD -- find_last_not_of;
|
||||
|
||||
return StrT::npos;
|
||||
}
|
||||
#endif //TSS_NTMBS_AWARE_SEACH_COMPLETE
|
||||
|
||||
// TODO:RAD -- find_first_not_of;
|
||||
// TODO:RAD -- find_last_not_of;
|
||||
namespace util
|
||||
{
|
||||
// Preserves bit values when enlarging a type to a size_t
|
||||
// Good for preventing sign extension
|
||||
template<class E> inline size_t char_to_size(E ch)
|
||||
{
|
||||
// if this fails, 'ch' can't be cast to a
|
||||
// size_t and preserve bit values
|
||||
// if this fails, then you must find another way
|
||||
ASSERT(sizeof(size_t) >= sizeof(E));
|
||||
|
||||
#endif//TSS_NTMBS_AWARE_SEACH_COMPLETE
|
||||
// assert that either 'ch' is an unsigned value (no sign extension possible)
|
||||
// or that 'ch' is the same size as a size_t (no sign extension is possible as well)
|
||||
// if this fails, then you must specialize this function like we did for 'char'
|
||||
ASSERT((int)(E)-1 > (int)0 || sizeof(size_t) == sizeof(E));
|
||||
|
||||
namespace util
|
||||
{
|
||||
// Preserves bit values when enlarging a type to a size_t
|
||||
// Good for preventing sign extension
|
||||
template< class E >
|
||||
inline
|
||||
size_t
|
||||
char_to_size( E ch )
|
||||
{
|
||||
// if this fails, 'ch' can't be cast to a
|
||||
// size_t and preserve bit values
|
||||
// if this fails, then you must find another way
|
||||
ASSERT( sizeof( size_t ) >= sizeof( E ) );
|
||||
|
||||
// assert that either 'ch' is an unsigned value (no sign extension possible)
|
||||
// or that 'ch' is the same size as a size_t (no sign extension is possible as well)
|
||||
// if this fails, then you must specialize this function like we did for 'char'
|
||||
ASSERT( (int)(E)-1 > (int)0 || sizeof( size_t ) == sizeof( E ) );
|
||||
|
||||
return (size_t)ch;
|
||||
}
|
||||
|
||||
|
||||
inline
|
||||
size_t
|
||||
char_to_size( char ch )
|
||||
{
|
||||
return (size_t)(unsigned char)ch;
|
||||
}
|
||||
}
|
||||
}//tss::
|
||||
return (size_t)ch;
|
||||
}
|
||||
|
||||
|
||||
#endif//__NTMBS_H
|
||||
inline size_t char_to_size(char ch)
|
||||
{
|
||||
return (size_t)(unsigned char)ch;
|
||||
}
|
||||
} // namespace util
|
||||
} // namespace tss
|
||||
|
||||
|
||||
#endif //__NTMBS_H
|
||||
|
|
|
@ -3,29 +3,29 @@
|
|||
// Portions created by Tripwire, Inc. are copyright (C) 2000-2018 Tripwire,
|
||||
// Inc. Tripwire is a registered trademark of Tripwire, Inc. All rights
|
||||
// reserved.
|
||||
//
|
||||
//
|
||||
// This program is free software. The contents of this file are subject
|
||||
// to the terms of the GNU General Public License as published by the
|
||||
// Free Software Foundation; either version 2 of the License, or (at your
|
||||
// option) any later version. You may redistribute it and/or modify it
|
||||
// only in compliance with the GNU General Public License.
|
||||
//
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful.
|
||||
// However, this program is distributed AS-IS WITHOUT ANY
|
||||
// WARRANTY; INCLUDING THE IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS
|
||||
// FOR A PARTICULAR PURPOSE. Please see the GNU General Public License
|
||||
// for more details.
|
||||
//
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
|
||||
// USA.
|
||||
//
|
||||
//
|
||||
// Nothing in the GNU General Public License or any other license to use
|
||||
// the code or files shall permit you to use Tripwire's trademarks,
|
||||
// service marks, or other intellectual property without Tripwire's
|
||||
// prior written consent.
|
||||
//
|
||||
//
|
||||
// If you have any questions, please contact Tripwire, Inc. at either
|
||||
// info@tripwire.org or www.tripwire.org.
|
||||
//
|
||||
|
@ -52,7 +52,7 @@
|
|||
// themselves singletons or shared. Using the package interface
|
||||
// guarantees that all shared resources will be properely
|
||||
// initialized before they are used. When creating a package
|
||||
// representation you can declare other packages that your
|
||||
// representation you can declare other packages that your
|
||||
// package depends on, ensuring that predicate packages and their
|
||||
// resources will be initialized before the package that uses
|
||||
// those resources.
|
||||
|
@ -60,8 +60,8 @@
|
|||
// Contents of this File
|
||||
//
|
||||
// TSS_Package( cPackage )
|
||||
// TSS_BeginPackage( cPackage )
|
||||
// TSS_EndPackage( cPackage )
|
||||
// TSS_BeginPackage( cPackage )
|
||||
// TSS_EndPackage( cPackage )
|
||||
// TSS_ImplementPackage( cPackage )
|
||||
// TSS_Dependency( cPackage )
|
||||
//
|
||||
|
@ -71,7 +71,7 @@
|
|||
// TSS_BeginStringtable( cPackage )
|
||||
// TSS_StringEntry( IDS, "message" )
|
||||
// TSS_EndStringtable( cPackage )
|
||||
//
|
||||
//
|
||||
// TSS_BeginStringIds( package_namespace )
|
||||
// TSS_EndStringIds( package_namespace )
|
||||
//
|
||||
|
@ -82,7 +82,7 @@
|
|||
#ifndef __PACKAGE_H
|
||||
#define __PACKAGE_H
|
||||
|
||||
#include "resources.h" // for: cMessage_<KEY,CHAR>
|
||||
#include "resources.h" // for: cMessage_<KEY,CHAR>
|
||||
|
||||
|
||||
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
|
@ -91,90 +91,92 @@
|
|||
|
||||
//--PACKAGE Helpers
|
||||
|
||||
#define TSS_Package( pkg ) \
|
||||
pkg::GetInstance() // Access "the" Package obj
|
||||
#define TSS_Package(pkg) pkg::GetInstance() // Access "the" Package obj
|
||||
|
||||
#define TSS_Dependency( pkg ) \
|
||||
TSS_Package( pkg ) // Declare a Package Depend.
|
||||
#define TSS_Dependency(pkg) TSS_Package(pkg) // Declare a Package Depend.
|
||||
|
||||
|
||||
|
||||
#define TSS_BeginPackage( pkg ) \
|
||||
class pkg : public cPackageBase_< TCHAR > \
|
||||
{ \
|
||||
public: \
|
||||
#define TSS_BeginPackage(pkg) \
|
||||
class pkg : public cPackageBase_<TCHAR> \
|
||||
{ \
|
||||
public: \
|
||||
static pkg& GetInstance();
|
||||
|
||||
|
||||
#define TSS_EndPackage( pkg ) \
|
||||
};
|
||||
#define TSS_EndPackage(pkg) \
|
||||
} \
|
||||
;
|
||||
|
||||
#define TSS_ImplementPackage( pkg ) \
|
||||
pkg& pkg::GetInstance() \
|
||||
{ \
|
||||
#define TSS_ImplementPackage(pkg) \
|
||||
pkg& pkg::GetInstance() \
|
||||
{ \
|
||||
static bool bConstructed = false; \
|
||||
static pkg x; \
|
||||
if ( !bConstructed ) \
|
||||
{ \
|
||||
bConstructed = true; \
|
||||
x.LoadStrings(); \
|
||||
} \
|
||||
return x; \
|
||||
static pkg x; \
|
||||
if (!bConstructed) \
|
||||
{ \
|
||||
bConstructed = true; \
|
||||
x.LoadStrings(); \
|
||||
} \
|
||||
return x; \
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
//--STRINGTABLE Helperfs
|
||||
|
||||
#define TSS_GetString( pkg, id ) \
|
||||
TSS_Package( pkg ).GetString( id ) // Access the Message String
|
||||
#define TSS_GetString(pkg, id) TSS_Package(pkg).GetString(id) // Access the Message String
|
||||
|
||||
|
||||
#define TSS_DECLARE_STRINGTABLE \
|
||||
public: \
|
||||
Messages::String \
|
||||
GetString( \
|
||||
Messages::ConstKeyRef id ) const { \
|
||||
return m_messages.Get( id ); } \
|
||||
void LoadStrings(); \
|
||||
private: \
|
||||
Messages m_messages // Decare a Stringtable
|
||||
#define TSS_DECLARE_STRINGTABLE \
|
||||
public: \
|
||||
Messages::String GetString(Messages::ConstKeyRef id) const \
|
||||
{ \
|
||||
return m_messages.Get(id); \
|
||||
} \
|
||||
void LoadStrings(); \
|
||||
\
|
||||
private: \
|
||||
Messages m_messages // Decare a Stringtable
|
||||
|
||||
|
||||
#ifdef DEBUG
|
||||
#define TSS_BeginStringtable( pkg ) \
|
||||
void pkg::LoadStrings() \
|
||||
{ cDebug d( #pkg "::LoadStrings()" ); \
|
||||
d.TraceDebug("Loading strings for " #pkg " package.\n"); \
|
||||
Messages::Pair astr[] = { // Define a Stringtable
|
||||
#else // DEBUG
|
||||
#define TSS_BeginStringtable( pkg ) \
|
||||
void pkg::LoadStrings() \
|
||||
{ Messages::Pair astr[] = { // Define a Stringtable
|
||||
#endif // DEBUG
|
||||
# define TSS_BeginStringtable(pkg) \
|
||||
void pkg::LoadStrings() \
|
||||
{ \
|
||||
cDebug d(#pkg "::LoadStrings()"); \
|
||||
d.TraceDebug("Loading strings for " #pkg " package.\n"); \
|
||||
Messages::Pair astr[] = { // Define a Stringtable
|
||||
#else // DEBUG
|
||||
# define TSS_BeginStringtable(pkg) \
|
||||
void pkg::LoadStrings() \
|
||||
{ \
|
||||
Messages::Pair astr[] = { // Define a Stringtable
|
||||
#endif // DEBUG
|
||||
|
||||
#define TSS_EndStringtable( pkg ) \
|
||||
}; m_messages.Put( \
|
||||
astr, astr + countof(astr) ); } // End define Strintable
|
||||
#define TSS_EndStringtable(pkg) \
|
||||
} \
|
||||
; \
|
||||
m_messages.Put(astr, astr + countof(astr)); \
|
||||
} // End define Strintable
|
||||
|
||||
|
||||
#define TSS_StringEntry( id, s ) \
|
||||
Messages::Pair( id, s ) // Stringtable Entry
|
||||
#define TSS_StringEntry(id, s) Messages::Pair(id, s) // Stringtable Entry
|
||||
|
||||
#define TSS_BeginStringIds( pns ) \
|
||||
namespace pns { \
|
||||
enum { // Define String IDs
|
||||
|
||||
#define TSS_EndStringIds( pns ) \
|
||||
}; } // End define String IDs
|
||||
#define TSS_BeginStringIds(pns) \
|
||||
namespace pns \
|
||||
{ \
|
||||
enum \
|
||||
{ // Define String IDs
|
||||
|
||||
#define TSS_EndStringIds(pns) \
|
||||
} \
|
||||
; \
|
||||
} // End define String IDs
|
||||
|
||||
|
||||
//=============================================================================
|
||||
// cPackageBase_<CharT> -- Base class for all Package Resources
|
||||
//-----------------------------------------------------------------------------
|
||||
// SYNOPSIS:
|
||||
// SYNOPSIS:
|
||||
// This class is the base class for all package representations
|
||||
// and, thus, establishes the package contract. It's interface
|
||||
// is relied on by the Package singleton wrapper, TSS_Package.
|
||||
|
@ -184,28 +186,25 @@
|
|||
// be called once.
|
||||
//
|
||||
// CONSTRAINTS:
|
||||
// A Package representation template must be instantiated with a
|
||||
// A Package representation template must be instantiated with a
|
||||
// "character concept" that is a valid STDCPP NTCTS.
|
||||
// This will most often be char (for NTBS), wchar_t (for NTWCS),
|
||||
// but may also be unsigned char (for NTMBCS).
|
||||
//
|
||||
// INVARIANTS:
|
||||
// m_nInstances <= 1
|
||||
//
|
||||
//
|
||||
//
|
||||
|
||||
template< class CharT >
|
||||
class cPackageBase_
|
||||
template<class CharT> class cPackageBase_
|
||||
{
|
||||
public:
|
||||
public:
|
||||
typedef cMessages_<int, CharT> Messages;
|
||||
|
||||
typedef cMessages_< int, CharT > Messages;
|
||||
|
||||
void LoadStrings()
|
||||
{
|
||||
}
|
||||
void LoadStrings()
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
#endif//__PACKAGE_H
|
||||
|
||||
#endif //__PACKAGE_H
|
||||
|
|
|
@ -3,29 +3,29 @@
|
|||
// Portions created by Tripwire, Inc. are copyright (C) 2000-2018 Tripwire,
|
||||
// Inc. Tripwire is a registered trademark of Tripwire, Inc. All rights
|
||||
// reserved.
|
||||
//
|
||||
//
|
||||
// This program is free software. The contents of this file are subject
|
||||
// to the terms of the GNU General Public License as published by the
|
||||
// Free Software Foundation; either version 2 of the License, or (at your
|
||||
// option) any later version. You may redistribute it and/or modify it
|
||||
// only in compliance with the GNU General Public License.
|
||||
//
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful.
|
||||
// However, this program is distributed AS-IS WITHOUT ANY
|
||||
// WARRANTY; INCLUDING THE IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS
|
||||
// FOR A PARTICULAR PURPOSE. Please see the GNU General Public License
|
||||
// for more details.
|
||||
//
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
|
||||
// USA.
|
||||
//
|
||||
//
|
||||
// Nothing in the GNU General Public License or any other license to use
|
||||
// the code or files shall permit you to use Tripwire's trademarks,
|
||||
// service marks, or other intellectual property without Tripwire's
|
||||
// prior written consent.
|
||||
//
|
||||
//
|
||||
// If you have any questions, please contact Tripwire, Inc. at either
|
||||
// info@tripwire.org or www.tripwire.org.
|
||||
//
|
||||
|
@ -34,72 +34,72 @@
|
|||
//
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
# include <config.h>
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#ifndef __PLATFORM_H
|
||||
#define __PLATFORM_H
|
||||
# define __PLATFORM_H
|
||||
|
||||
//NOTE: Autoconf is strongly preferred as the Right Way to detect platform-specific features/behaviors.
|
||||
// These macros should really only be used when autoconf can't get the job done.
|
||||
|
||||
//=============================================================================
|
||||
// Enumerations
|
||||
//
|
||||
//
|
||||
// For each of these "enumerations" we create unique integers identifying each
|
||||
// variation. We group similar items together, such as OS_REDHAT and OS_SLACKWARE
|
||||
|
||||
#define OS_UNKNOWN 0
|
||||
# define OS_UNKNOWN 0
|
||||
|
||||
#define OS_WIN32 0x0101
|
||||
#define OS_CYGWIN 0x0102
|
||||
#define OS_DOS_DJGPP 0x0103
|
||||
# define OS_WIN32 0x0101
|
||||
# define OS_CYGWIN 0x0102
|
||||
# define OS_DOS_DJGPP 0x0103
|
||||
|
||||
#define OS_LINUX 0x0201
|
||||
#define OS_ANDROID 0x0202
|
||||
# define OS_LINUX 0x0201
|
||||
# define OS_ANDROID 0x0202
|
||||
|
||||
#define OS_FREEBSD 0x0301
|
||||
#define OS_NETBSD 0x0302
|
||||
#define OS_OPENBSD 0x0303
|
||||
#define OS_DARWIN 0x0304
|
||||
#define OS_DRAGONFLYBSD 0x0305
|
||||
#define OS_MIDNIGHTBSD 0x0306
|
||||
#define OS_MIRBSD 0x0307
|
||||
#define OS_BITRIG 0x0308
|
||||
#define OS_LIBERTYBSD 0x0309
|
||||
# define OS_FREEBSD 0x0301
|
||||
# define OS_NETBSD 0x0302
|
||||
# define OS_OPENBSD 0x0303
|
||||
# define OS_DARWIN 0x0304
|
||||
# define OS_DRAGONFLYBSD 0x0305
|
||||
# define OS_MIDNIGHTBSD 0x0306
|
||||
# define OS_MIRBSD 0x0307
|
||||
# define OS_BITRIG 0x0308
|
||||
# define OS_LIBERTYBSD 0x0309
|
||||
|
||||
#define OS_SOLARIS 0x0400
|
||||
#define OS_AIX 0x0401
|
||||
#define OS_HPUX 0x0402
|
||||
#define OS_IRIX 0x0403
|
||||
#define OS_OSF1 0x0404
|
||||
# define OS_SOLARIS 0x0400
|
||||
# define OS_AIX 0x0401
|
||||
# define OS_HPUX 0x0402
|
||||
# define OS_IRIX 0x0403
|
||||
# define OS_OSF1 0x0404
|
||||
|
||||
#define OS_MINIX 0x0501
|
||||
#define OS_HURD 0x0502
|
||||
#define OS_HAIKU 0x0503
|
||||
#define OS_SYLLABLE 0x0504
|
||||
#define OS_SKYOS 0x0505
|
||||
#define OS_SORTIX 0x0506
|
||||
#define OS_MINT 0x0507
|
||||
#define OS_AROS 0x0508
|
||||
#define OS_RTEMS 0x0509
|
||||
#define OS_RISCOS 0x050A
|
||||
#define OS_REDOX 0x050B
|
||||
#define OS_QNX 0x050C
|
||||
# define OS_MINIX 0x0501
|
||||
# define OS_HURD 0x0502
|
||||
# define OS_HAIKU 0x0503
|
||||
# define OS_SYLLABLE 0x0504
|
||||
# define OS_SKYOS 0x0505
|
||||
# define OS_SORTIX 0x0506
|
||||
# define OS_MINT 0x0507
|
||||
# define OS_AROS 0x0508
|
||||
# define OS_RTEMS 0x0509
|
||||
# define OS_RISCOS 0x050A
|
||||
# define OS_REDOX 0x050B
|
||||
# define OS_QNX 0x050C
|
||||
|
||||
#define COMP_UNKNOWN 0
|
||||
#define COMP_GCC 0x0001
|
||||
#define COMP_CLANG 0x0002
|
||||
# define COMP_UNKNOWN 0
|
||||
# define COMP_GCC 0x0001
|
||||
# define COMP_CLANG 0x0002
|
||||
|
||||
#define COMP_MSVC 0x0101
|
||||
#define COMP_KAI_GCC 0x0201
|
||||
#define COMP_KAI_SUNPRO 0x0202
|
||||
#define COMP_KAI_GLIBC 0x0203
|
||||
#define COMP_KAI_VISUALAGE 0x0204
|
||||
#define COMP_KAI_HPANSIC 0x0205
|
||||
#define COMP_KAI_IRIX 0x0206
|
||||
#define COMP_KAI_OSF1ALPHA 0x0207
|
||||
#define COMP_SUNPRO 0x0301
|
||||
# define COMP_MSVC 0x0101
|
||||
# define COMP_KAI_GCC 0x0201
|
||||
# define COMP_KAI_SUNPRO 0x0202
|
||||
# define COMP_KAI_GLIBC 0x0203
|
||||
# define COMP_KAI_VISUALAGE 0x0204
|
||||
# define COMP_KAI_HPANSIC 0x0205
|
||||
# define COMP_KAI_IRIX 0x0206
|
||||
# define COMP_KAI_OSF1ALPHA 0x0207
|
||||
# define COMP_SUNPRO 0x0301
|
||||
|
||||
//=============================================================================
|
||||
// Platform detection
|
||||
|
@ -112,143 +112,142 @@
|
|||
// OS The OS
|
||||
// COMP The compiler
|
||||
//
|
||||
// PLEASE NOTE: Do not set any preprocessor variable other than the above three in this
|
||||
// PLEASE NOTE: Do not set any preprocessor variable other than the above three in this
|
||||
// section. Use the following sections for anything that does not fall into
|
||||
// the above catagories.
|
||||
|
||||
#if defined(_WIN32)
|
||||
#define OS OS_WIN32
|
||||
#define IS_WIN32 1
|
||||
|
||||
#elif defined(__CYGWIN__)
|
||||
#define OS OS_CYGWIN
|
||||
#define IS_CYGWIN 1
|
||||
# if defined(_WIN32)
|
||||
# define OS OS_WIN32
|
||||
# define IS_WIN32 1
|
||||
|
||||
# elif defined(__CYGWIN__)
|
||||
# define OS OS_CYGWIN
|
||||
# define IS_CYGWIN 1
|
||||
|
||||
# elif defined(__DJGPP__)
|
||||
# define OS OS_DOS_DJGPP
|
||||
# define IS_DOS_DJGPP 1
|
||||
|
||||
|
||||
# elif defined(__ANDROID__)
|
||||
# define OS OS_ANDROID
|
||||
# define IS_ANDROID 1
|
||||
|
||||
# elif defined(__linux__)
|
||||
# define OS OS_LINUX
|
||||
# define IS_LINUX 1
|
||||
|
||||
#elif defined(__DJGPP__)
|
||||
#define OS OS_DOS_DJGPP
|
||||
#define IS_DOS_DJGPP 1
|
||||
|
||||
|
||||
#elif defined(__ANDROID__)
|
||||
#define OS OS_ANDROID
|
||||
#define IS_ANDROID 1
|
||||
|
||||
#elif defined(__linux__)
|
||||
#define OS OS_LINUX
|
||||
#define IS_LINUX 1
|
||||
|
||||
|
||||
// A herd of BSDs. Have to detect MidnightBSD before FreeBSD, and MirOS & Bitrig before OpenBSD
|
||||
// because they also define symbols for their ancestor BSDs.
|
||||
#elif defined(__DragonFly__)
|
||||
#define OS OS_DRAGONFLYBSD
|
||||
#define IS_DRAGONFLYBSD 1
|
||||
# elif defined(__DragonFly__)
|
||||
# define OS OS_DRAGONFLYBSD
|
||||
# define IS_DRAGONFLYBSD 1
|
||||
|
||||
#elif defined(__MidnightBSD__)
|
||||
#define OS OS_MIDNIGHTBSD
|
||||
#define IS_MIDNIGHTBSD 1
|
||||
# elif defined(__MidnightBSD__)
|
||||
# define OS OS_MIDNIGHTBSD
|
||||
# define IS_MIDNIGHTBSD 1
|
||||
|
||||
#elif defined(__FreeBSD__)
|
||||
#define OS OS_FREEBSD
|
||||
#define IS_FREEBSD 1
|
||||
# elif defined(__FreeBSD__)
|
||||
# define OS OS_FREEBSD
|
||||
# define IS_FREEBSD 1
|
||||
|
||||
#elif defined(__NetBSD__)
|
||||
#define OS OS_NETBSD
|
||||
#define IS_NETBSD 1
|
||||
# elif defined(__NetBSD__)
|
||||
# define OS OS_NETBSD
|
||||
# define IS_NETBSD 1
|
||||
|
||||
#elif defined(__MirBSD__)
|
||||
#define OS OS_MIRBSD
|
||||
#define IS_MIRBSD 1
|
||||
# elif defined(__MirBSD__)
|
||||
# define OS OS_MIRBSD
|
||||
# define IS_MIRBSD 1
|
||||
|
||||
#elif defined(__Bitrig__)
|
||||
#define OS OS_BITRIG
|
||||
#define IS_BITRIG 1
|
||||
# elif defined(__Bitrig__)
|
||||
# define OS OS_BITRIG
|
||||
# define IS_BITRIG 1
|
||||
|
||||
#elif defined(TW_LibertyBSD)
|
||||
#define OS OS_LIBERTYBSD
|
||||
#define IS_LIBERTYBSD 1
|
||||
# elif defined(TW_LibertyBSD)
|
||||
# define OS OS_LIBERTYBSD
|
||||
# define IS_LIBERTYBSD 1
|
||||
|
||||
#elif defined(__OpenBSD__)
|
||||
#define OS OS_OPENBSD
|
||||
#define IS_OPENBSD 1
|
||||
# elif defined(__OpenBSD__)
|
||||
# define OS OS_OPENBSD
|
||||
# define IS_OPENBSD 1
|
||||
|
||||
#elif defined(__APPLE__)
|
||||
#define OS OS_DARWIN
|
||||
#define IS_DARWIN 1
|
||||
# elif defined(__APPLE__)
|
||||
# define OS OS_DARWIN
|
||||
# define IS_DARWIN 1
|
||||
|
||||
|
||||
#elif defined(__sun)
|
||||
#define OS OS_SOLARIS
|
||||
#define IS_SOLARIS 1
|
||||
|
||||
#elif defined(_AIX)
|
||||
#define OS OS_AIX
|
||||
#define IS_AIX 1
|
||||
|
||||
#elif defined (__hpux)
|
||||
#define OS OS_HPUX
|
||||
#define IS_HPUX 1
|
||||
|
||||
#elif defined(__sgi)
|
||||
#define OS OS_IRIX
|
||||
#define IS_IRIX 1
|
||||
|
||||
#elif defined(TRU64) || defined(__OSF1__)
|
||||
#define OS OS_OSF1
|
||||
#define IS_OSF1 1
|
||||
|
||||
# elif defined(__sun)
|
||||
# define OS OS_SOLARIS
|
||||
# define IS_SOLARIS 1
|
||||
|
||||
#elif defined(__minix__)
|
||||
#define OS OS_MINIX
|
||||
#define IS_MINIX 1
|
||||
# elif defined(_AIX)
|
||||
# define OS OS_AIX
|
||||
# define IS_AIX 1
|
||||
|
||||
#elif defined(__gnu_hurd__)
|
||||
#define OS OS_HURD
|
||||
#define IS_HURD 1
|
||||
# elif defined(__hpux)
|
||||
# define OS OS_HPUX
|
||||
# define IS_HPUX 1
|
||||
|
||||
#elif defined(__HAIKU__)
|
||||
#define OS OS_HAIKU
|
||||
#define IS_HAIKU 1
|
||||
# elif defined(__sgi)
|
||||
# define OS OS_IRIX
|
||||
# define IS_IRIX 1
|
||||
|
||||
#elif defined(__SYLLABLE__)
|
||||
#define OS OS_SYLLABLE
|
||||
#define IS_SYLLABLE 1
|
||||
|
||||
#elif defined(SKYOS)
|
||||
#define OS OS_SKYOS
|
||||
#define IS_SKYOS 1
|
||||
|
||||
#elif defined(_SORTIX_SOURCE)
|
||||
#define OS OS_SORTIX
|
||||
#define IS_SORTIX 1
|
||||
|
||||
#elif defined(__MINT__)
|
||||
#define OS OS_MINT
|
||||
#define IS_MINT 1
|
||||
|
||||
#elif defined(__AROS__)
|
||||
#define OS OS_AROS
|
||||
#define IS_AROS 1
|
||||
|
||||
#elif defined(__rtems__)
|
||||
#define OS OS_RTEMS
|
||||
#define IS_RTEMS 1
|
||||
# elif defined(TRU64) || defined(__OSF1__)
|
||||
# define OS OS_OSF1
|
||||
# define IS_OSF1 1
|
||||
|
||||
#elif defined(__riscos__)
|
||||
#define OS OS_RISCOS
|
||||
#define IS_RISCOS 1
|
||||
|
||||
#elif defined(__redox__)
|
||||
#define OS OS_REDOX
|
||||
#define IS_REDOX 1
|
||||
# elif defined(__minix__)
|
||||
# define OS OS_MINIX
|
||||
# define IS_MINIX 1
|
||||
|
||||
#elif defined(__QNX__)
|
||||
#define OS OS_QNX
|
||||
#define IS_QNX 1
|
||||
# elif defined(__gnu_hurd__)
|
||||
# define OS OS_HURD
|
||||
# define IS_HURD 1
|
||||
|
||||
# elif defined(__HAIKU__)
|
||||
# define OS OS_HAIKU
|
||||
# define IS_HAIKU 1
|
||||
|
||||
# elif defined(__SYLLABLE__)
|
||||
# define OS OS_SYLLABLE
|
||||
# define IS_SYLLABLE 1
|
||||
|
||||
# elif defined(SKYOS)
|
||||
# define OS OS_SKYOS
|
||||
# define IS_SKYOS 1
|
||||
|
||||
# elif defined(_SORTIX_SOURCE)
|
||||
# define OS OS_SORTIX
|
||||
# define IS_SORTIX 1
|
||||
|
||||
# elif defined(__MINT__)
|
||||
# define OS OS_MINT
|
||||
# define IS_MINT 1
|
||||
|
||||
# elif defined(__AROS__)
|
||||
# define OS OS_AROS
|
||||
# define IS_AROS 1
|
||||
|
||||
# elif defined(__rtems__)
|
||||
# define OS OS_RTEMS
|
||||
# define IS_RTEMS 1
|
||||
|
||||
# elif defined(__riscos__)
|
||||
# define OS OS_RISCOS
|
||||
# define IS_RISCOS 1
|
||||
|
||||
# elif defined(__redox__)
|
||||
# define OS OS_REDOX
|
||||
# define IS_REDOX 1
|
||||
|
||||
# elif defined(__QNX__)
|
||||
# define OS OS_QNX
|
||||
# define IS_QNX 1
|
||||
|
||||
# endif
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
/* XXX: COMP may now not resolve, because autoconf may
|
||||
* detect GCC. This is done in the hopes that all
|
||||
|
@ -262,9 +261,9 @@
|
|||
*
|
||||
* PH - 20010311
|
||||
*/
|
||||
#if !defined(COMP) && !defined(HAVE_GCC)
|
||||
#error COMP definition did not resolve. Check "platform.h".
|
||||
#endif
|
||||
# if !defined(COMP) && !defined(HAVE_GCC)
|
||||
# error COMP definition did not resolve. Check "platform.h".
|
||||
# endif
|
||||
|
||||
//=============================================================================
|
||||
// Platform Macros (a.k.a. "IS_" macros)
|
||||
|
@ -273,7 +272,7 @@
|
|||
// these macros rather than comparing PLATFORM to the unique IDs by hand.
|
||||
//
|
||||
// NB: Programmers are STRONGLY ENCOURAGED not to use the OS detection macros
|
||||
// or compiler detection marcros directly. Instead they should create
|
||||
// or compiler detection marcros directly. Instead they should create
|
||||
// macros specific to the task at hand. For example Win32 and Solaris support
|
||||
// extended permissions for their files. Rather than check IS_WIN32 || IS_SOLARIS,
|
||||
// create a new macro called "HAS_EXTENDED_FILE_PERMISSIONS" and use that.
|
||||
|
@ -289,93 +288,95 @@
|
|||
// int network_order = swap(machine_order);
|
||||
// #endif
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
|
||||
|
||||
// complier detection
|
||||
#define IS_KAI (COMP == COMP_KAI_GCC || COMP == COMP_KAI_SUNPRO || COMP == COMP_KAI_GLIBC || COMP == COMP_KAI_VISUALAGE || COMP == COMP_KAI_HPANSIC || COMP == COMP_KAI_IRIX || COMP == COMP_KAI_OSF1ALPHA)
|
||||
#define IS_MSVC (COMP == COMP_MSVC)
|
||||
#define IS_SUNPRO (COMP == COMP_SUNPRO)
|
||||
# define IS_KAI \
|
||||
(COMP == COMP_KAI_GCC || COMP == COMP_KAI_SUNPRO || COMP == COMP_KAI_GLIBC || COMP == COMP_KAI_VISUALAGE || \
|
||||
COMP == COMP_KAI_HPANSIC || COMP == COMP_KAI_IRIX || COMP == COMP_KAI_OSF1ALPHA)
|
||||
# define IS_MSVC (COMP == COMP_MSVC)
|
||||
# define IS_SUNPRO (COMP == COMP_SUNPRO)
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
|
||||
// Unicode
|
||||
#define SUPPORTS_UNICODE IS_WIN32 // The OS supports Unicode
|
||||
# define SUPPORTS_UNICODE IS_WIN32 // The OS supports Unicode
|
||||
|
||||
// KAI 3.4 uses a much improved stl
|
||||
#define IS_KAI_3_4 (IS_KAI && (COMP == COMP_KAI_IRIX || COMP == COMP_KAI_OSF1ALPHA || COMP == COMP_KAI_GLIBC))
|
||||
# define IS_KAI_3_4 (IS_KAI && (COMP == COMP_KAI_IRIX || COMP == COMP_KAI_OSF1ALPHA || COMP == COMP_KAI_GLIBC))
|
||||
|
||||
// Used in twlocale
|
||||
#define USE_STD_CPP_LOCALE_WORKAROUND (IS_SUNPRO || (IS_KAI && !IS_KAI_3_4)) // TODO:BAM -- name this something more general.
|
||||
#define USE_CLIB_LOCALE IS_KAI || HAVE_GCC
|
||||
#define USES_CLIB_DATE_FUNCTION ( USE_CLIB_LOCALE || IS_SUNPRO || IS_MSVC ) // if we use clib, can't use C++ time_put, and SUNPRO and MSVC add characters
|
||||
# define USE_STD_CPP_LOCALE_WORKAROUND \
|
||||
(IS_SUNPRO || (IS_KAI && !IS_KAI_3_4)) // TODO:BAM -- name this something more general.
|
||||
# define USE_CLIB_LOCALE IS_KAI || HAVE_GCC
|
||||
# define USES_CLIB_DATE_FUNCTION \
|
||||
(USE_CLIB_LOCALE || IS_SUNPRO || \
|
||||
IS_MSVC) // if we use clib, can't use C++ time_put, and SUNPRO and MSVC add characters
|
||||
//#define USE_CLIB_LOCALE (IS_ALPHA || IS_IRIX || (IS_KAI && !IS_KAI_3_4))
|
||||
|
||||
// Threading API
|
||||
// TODO:mdb -- this is not complete or rigorous on the unix side!!!
|
||||
#define SUPPORTS_WIN32_THREADS IS_WIN32
|
||||
#define SUPPORTS_POSIX_THREADS (!SUPPORTS_WIN32_THREADS)
|
||||
// TODO:mdb -- this is not complete or rigorous on the unix side!!!
|
||||
# define SUPPORTS_WIN32_THREADS IS_WIN32
|
||||
# define SUPPORTS_POSIX_THREADS (!SUPPORTS_WIN32_THREADS)
|
||||
|
||||
// Miscellaneous
|
||||
#define WCHAR_IS_16_BITS IS_WIN32
|
||||
#define WCHAR_IS_32_BITS IS_UNIX
|
||||
#define WCHAR_REP_IS_UCS2 IS_WIN32
|
||||
# define WCHAR_IS_16_BITS IS_WIN32
|
||||
# define WCHAR_IS_32_BITS IS_UNIX
|
||||
# define WCHAR_REP_IS_UCS2 IS_WIN32
|
||||
// msystem+mpopen fail on Syllable, so use the libc equivalents until we figure out why.
|
||||
// TODO: Figure out why.
|
||||
#define USES_MPOPEN (IS_UNIX && !IS_SYLLABLE)
|
||||
#define USES_MSYSTEM (IS_UNIX && !IS_SYLLABLE)
|
||||
#define SUPPORTS_WCHART IS_WIN32 // TODO: Remove after getting new ver of KAI
|
||||
#define USES_GLIBC ((COMP == COMP_KAI_GLIBC) || HAVE_GCC)
|
||||
#define SUPPORTS_MEMBER_TEMPLATES ( ! IS_SUNPRO )
|
||||
#define SUPPORTS_EXPLICIT_TEMPLATE_FUNC_INST ( ! IS_SUNPRO )
|
||||
# define USES_MPOPEN (IS_UNIX && !IS_SYLLABLE)
|
||||
# define USES_MSYSTEM (IS_UNIX && !IS_SYLLABLE)
|
||||
# define SUPPORTS_WCHART IS_WIN32 // TODO: Remove after getting new ver of KAI
|
||||
# define USES_GLIBC ((COMP == COMP_KAI_GLIBC) || HAVE_GCC)
|
||||
# define SUPPORTS_MEMBER_TEMPLATES (!IS_SUNPRO)
|
||||
# define SUPPORTS_EXPLICIT_TEMPLATE_FUNC_INST (!IS_SUNPRO)
|
||||
|
||||
#define SUPPORTS_POSIX_SIGNALS (!IS_DOS_DJGPP)
|
||||
#define SUPPORTS_NETWORKING (!IS_SORTIX && !IS_DOS_DJGPP && !IS_REDOX)
|
||||
#define SUPPORTS_SYSLOG (HAVE_SYSLOG_H && !IS_SKYOS && !IS_RISCOS)
|
||||
#define NEEDS_SWAB_IMPL (IS_CYGWIN || IS_SYLLABLE || IS_ANDROID || IS_SORTIX)
|
||||
#define USES_MBLEN (!IS_ANDROID && !IS_AROS)
|
||||
#define USES_DEVICE_PATH (IS_AROS || IS_DOS_DJGPP || IS_RISCOS || IS_REDOX)
|
||||
#define ICONV_CONST_SOURCE (IS_MINIX)
|
||||
#define SUPPORTS_DIRECT_IO (IS_LINUX)
|
||||
# define SUPPORTS_POSIX_SIGNALS (!IS_DOS_DJGPP)
|
||||
# define SUPPORTS_NETWORKING (!IS_SORTIX && !IS_DOS_DJGPP && !IS_REDOX)
|
||||
# define SUPPORTS_SYSLOG (HAVE_SYSLOG_H && !IS_SKYOS && !IS_RISCOS)
|
||||
# define NEEDS_SWAB_IMPL (IS_CYGWIN || IS_SYLLABLE || IS_ANDROID || IS_SORTIX)
|
||||
# define USES_MBLEN (!IS_ANDROID && !IS_AROS)
|
||||
# define USES_DEVICE_PATH (IS_AROS || IS_DOS_DJGPP || IS_RISCOS || IS_REDOX)
|
||||
# define ICONV_CONST_SOURCE (IS_MINIX)
|
||||
# define SUPPORTS_DIRECT_IO (IS_LINUX)
|
||||
// Linux is the only platform where direct i/o hashing has been tested & works properly so far.
|
||||
|
||||
#define SUPPORTS_TERMIOS (!IS_RTEMS && !IS_REDOX)
|
||||
# define SUPPORTS_TERMIOS (!IS_RTEMS && !IS_REDOX)
|
||||
// RTEMS errors are probably just a buildsys issue & this will change or go away.
|
||||
// Redox will probably implement this in the future.
|
||||
|
||||
#define CAN_UNLINK_WHILE_OPEN (!IS_AROS && !IS_RISCOS && !IS_REDOX && !IS_DOS_DJGPP)
|
||||
# define CAN_UNLINK_WHILE_OPEN (!IS_AROS && !IS_RISCOS && !IS_REDOX && !IS_DOS_DJGPP)
|
||||
|
||||
#define SUPPORTS_DOUBLE_SLASH_PATH (IS_CYGWIN)
|
||||
# define SUPPORTS_DOUBLE_SLASH_PATH (IS_CYGWIN)
|
||||
// POSIX standard says paths beginning with 2 slashes are "implementation defined"
|
||||
// (see http://pubs.opengroup.org/onlinepubs/009695399/basedefs/xbd_chap04.html#tag_04_11 )
|
||||
// The only platform OST works on (afaik) that actually defines a double-slash behavior is Cygwin
|
||||
// which uses this syntax for UNC paths. So we'll allow leading double slashes there, but
|
||||
// continue removing them on all other platforms
|
||||
|
||||
#define USE_DEV_URANDOM (HAVE_DEV_URANDOM && ENABLE_DEV_URANDOM)
|
||||
# define USE_DEV_URANDOM (HAVE_DEV_URANDOM && ENABLE_DEV_URANDOM)
|
||||
|
||||
//=============================================================================
|
||||
// Miscellaneous
|
||||
//
|
||||
// Put all items that are not an "IS_" macro here.
|
||||
// Put all items that are not an "IS_" macro here.
|
||||
|
||||
#if IS_BYTE_ALIGNED
|
||||
#define BYTE_ALIGN 8
|
||||
#else
|
||||
#error Unknown Byte alignment
|
||||
#endif
|
||||
# if IS_BYTE_ALIGNED
|
||||
# define BYTE_ALIGN 8
|
||||
# else
|
||||
# error Unknown Byte alignment
|
||||
# endif
|
||||
|
||||
// A scalar that matches the sizeof a pointer
|
||||
typedef unsigned long ptr_size_type; // true for all of our current platforms
|
||||
// TODO: I would like to use a XXXX_t like name
|
||||
typedef unsigned long ptr_size_type; // true for all of our current platforms
|
||||
// TODO: I would like to use a XXXX_t like name
|
||||
|
||||
// Check integer representation
|
||||
#if !(USES_2S_COMPLEMENT)
|
||||
#error "Tripwire will only work on a 2's complement CPU. Check \"platform.h\"."
|
||||
#endif
|
||||
|
||||
|
||||
# if !(USES_2S_COMPLEMENT)
|
||||
# error "Tripwire will only work on a 2's complement CPU. Check \"platform.h\"."
|
||||
# endif
|
||||
|
||||
|
||||
#endif // __PLATFORM_H
|
||||
|
||||
|
|
|
@ -3,29 +3,29 @@
|
|||
// Portions created by Tripwire, Inc. are copyright (C) 2000-2018 Tripwire,
|
||||
// Inc. Tripwire is a registered trademark of Tripwire, Inc. All rights
|
||||
// reserved.
|
||||
//
|
||||
//
|
||||
// This program is free software. The contents of this file are subject
|
||||
// to the terms of the GNU General Public License as published by the
|
||||
// Free Software Foundation; either version 2 of the License, or (at your
|
||||
// option) any later version. You may redistribute it and/or modify it
|
||||
// only in compliance with the GNU General Public License.
|
||||
//
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful.
|
||||
// However, this program is distributed AS-IS WITHOUT ANY
|
||||
// WARRANTY; INCLUDING THE IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS
|
||||
// FOR A PARTICULAR PURPOSE. Please see the GNU General Public License
|
||||
// for more details.
|
||||
//
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
|
||||
// USA.
|
||||
//
|
||||
//
|
||||
// Nothing in the GNU General Public License or any other license to use
|
||||
// the code or files shall permit you to use Tripwire's trademarks,
|
||||
// service marks, or other intellectual property without Tripwire's
|
||||
// prior written consent.
|
||||
//
|
||||
//
|
||||
// If you have any questions, please contact Tripwire, Inc. at either
|
||||
// info@tripwire.org or www.tripwire.org.
|
||||
//
|
||||
|
@ -42,14 +42,14 @@
|
|||
#include "errorutil.h"
|
||||
|
||||
#ifdef DEBUG
|
||||
int cRefCountObj::objectCounter = 0;
|
||||
int cRefCountObj::objectCounter = 0;
|
||||
int cRefCountObj::referenceCounter = 0;
|
||||
|
||||
#include <typeinfo>
|
||||
// ok, this is getting serious!
|
||||
#include <set>
|
||||
typedef std::set<void*> RefSet; // collection of addresses of all reference counted objects
|
||||
RefSet* gpRefCountObj_Objects = 0;
|
||||
typedef std::set<void*> RefSet; // collection of addresses of all reference counted objects
|
||||
RefSet* gpRefCountObj_Objects = 0;
|
||||
|
||||
// a way to see what hasn't been accounted for....
|
||||
struct cRefCountObj_Debug
|
||||
|
@ -57,10 +57,10 @@ struct cRefCountObj_Debug
|
|||
~cRefCountObj_Debug()
|
||||
{
|
||||
RefSet::iterator i;
|
||||
cDebug d("cRefCountObj_Debug");
|
||||
if(gpRefCountObj_Objects)
|
||||
cDebug d("cRefCountObj_Debug");
|
||||
if (gpRefCountObj_Objects)
|
||||
{
|
||||
for(i = gpRefCountObj_Objects->begin(); i != gpRefCountObj_Objects->end(); i++)
|
||||
for (i = gpRefCountObj_Objects->begin(); i != gpRefCountObj_Objects->end(); i++)
|
||||
{
|
||||
d.TraceNever("Refrence Counted Object %p still exists\n", *i);
|
||||
}
|
||||
|
@ -74,7 +74,7 @@ cRefCountObj::cRefCountObj()
|
|||
{
|
||||
mRefCount = 1;
|
||||
|
||||
//std::cout << "Allocated RefObj(" << std::hex << (int)this << ")\n";
|
||||
//std::cout << "Allocated RefObj(" << std::hex << (int)this << ")\n";
|
||||
|
||||
#ifdef DEBUG
|
||||
++objectCounter;
|
||||
|
@ -83,7 +83,7 @@ cRefCountObj::cRefCountObj()
|
|||
cDebug d("cRefCountObj::cRefCountObj");
|
||||
d.TraceNever("Object Created[%p] %s\n", this, typeid(*this).name());
|
||||
|
||||
if(! gpRefCountObj_Objects)
|
||||
if (!gpRefCountObj_Objects)
|
||||
gpRefCountObj_Objects = new RefSet;
|
||||
gpRefCountObj_Objects->insert(this);
|
||||
#endif
|
||||
|
@ -93,22 +93,22 @@ cRefCountObj::~cRefCountObj()
|
|||
{
|
||||
ASSERT(mRefCount == 0);
|
||||
|
||||
//std::cout << "Deleted RefObj(" << std::hex << (int)this << ")\n";
|
||||
//std::cout << "Deleted RefObj(" << std::hex << (int)this << ")\n";
|
||||
|
||||
#ifdef DEBUG
|
||||
--objectCounter;
|
||||
cDebug d("cRefCountObj::~cRefCountObj");
|
||||
d.TraceNever("Object Destroyed[%p] %s Objects Left = %d\n", this, typeid(*this).name(), objectCounter);
|
||||
if(objectCounter == 0)
|
||||
if (objectCounter == 0)
|
||||
{
|
||||
d.TraceDebug("****** All Reference Counted Objects Destroyed! ******\n") ;
|
||||
d.TraceDebug("****** All Reference Counted Objects Destroyed! ******\n");
|
||||
}
|
||||
|
||||
ASSERT(gpRefCountObj_Objects);
|
||||
RefSet::const_iterator i = gpRefCountObj_Objects->find(this);
|
||||
ASSERT(i != gpRefCountObj_Objects->end());
|
||||
gpRefCountObj_Objects->erase(this);
|
||||
if(gpRefCountObj_Objects->size() == 0)
|
||||
if (gpRefCountObj_Objects->size() == 0)
|
||||
{
|
||||
delete gpRefCountObj_Objects;
|
||||
gpRefCountObj_Objects = 0;
|
||||
|
@ -128,9 +128,9 @@ void cRefCountObj::AddRef() const
|
|||
|
||||
++mRefCount;
|
||||
|
||||
#ifdef DEBUG
|
||||
#ifdef DEBUG
|
||||
++referenceCounter;
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
void cRefCountObj::Release() const
|
||||
|
@ -140,13 +140,12 @@ void cRefCountObj::Release() const
|
|||
Delete();
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
#ifdef DEBUG
|
||||
--referenceCounter;
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
void cRefCountObj::Delete() const
|
||||
{
|
||||
delete this;
|
||||
}
|
||||
|
||||
|
|
|
@ -3,29 +3,29 @@
|
|||
// Portions created by Tripwire, Inc. are copyright (C) 2000-2018 Tripwire,
|
||||
// Inc. Tripwire is a registered trademark of Tripwire, Inc. All rights
|
||||
// reserved.
|
||||
//
|
||||
//
|
||||
// This program is free software. The contents of this file are subject
|
||||
// to the terms of the GNU General Public License as published by the
|
||||
// Free Software Foundation; either version 2 of the License, or (at your
|
||||
// option) any later version. You may redistribute it and/or modify it
|
||||
// only in compliance with the GNU General Public License.
|
||||
//
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful.
|
||||
// However, this program is distributed AS-IS WITHOUT ANY
|
||||
// WARRANTY; INCLUDING THE IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS
|
||||
// FOR A PARTICULAR PURPOSE. Please see the GNU General Public License
|
||||
// for more details.
|
||||
//
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
|
||||
// USA.
|
||||
//
|
||||
//
|
||||
// Nothing in the GNU General Public License or any other license to use
|
||||
// the code or files shall permit you to use Tripwire's trademarks,
|
||||
// service marks, or other intellectual property without Tripwire's
|
||||
// prior written consent.
|
||||
//
|
||||
//
|
||||
// If you have any questions, please contact Tripwire, Inc. at either
|
||||
// info@tripwire.org or www.tripwire.org.
|
||||
//
|
||||
|
@ -37,7 +37,7 @@
|
|||
#define __REFCOUNTOBJ_H
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// class cRefCountObj
|
||||
// class cRefCountObj
|
||||
//
|
||||
// Base class for objects that are to be reference counted. Derive from this
|
||||
// class to create an object that will keep track of how many owners it has
|
||||
|
@ -45,7 +45,7 @@
|
|||
//
|
||||
// The convention for using this class it to call AddRef() when you pass
|
||||
// a pointer to the object to a new owner. When the new owner is done with
|
||||
// the object it
|
||||
// the object it
|
||||
//
|
||||
// Note: In the current implementation we do not support a reference counted
|
||||
// object being an owner of itself, either directly or indirectly. For instance
|
||||
|
@ -53,7 +53,7 @@
|
|||
// through some AddChild(cRefCountObj*) function) and then call AddRef() followed
|
||||
// by AddChild(), then call Release(), you will end up with an object of reference
|
||||
// count 1 but no owners outside itself.
|
||||
//
|
||||
//
|
||||
// This is not foreseen to be a problem with the tripwire usage of this class.
|
||||
//
|
||||
// See refcountobj_t.cpp for examples on use.
|
||||
|
@ -67,28 +67,31 @@ public:
|
|||
virtual void AddRef() const;
|
||||
virtual void Release() const;
|
||||
|
||||
int GetRefCount() const { return mRefCount; }
|
||||
// sometimes it is useful to know an object's refrence
|
||||
int GetRefCount() const
|
||||
{
|
||||
return mRefCount;
|
||||
}
|
||||
// sometimes it is useful to know an object's refrence
|
||||
protected:
|
||||
virtual ~cRefCountObj();
|
||||
|
||||
virtual void Delete() const;
|
||||
// override this if you don't want to be destroyed by "delete this"!
|
||||
// override this if you don't want to be destroyed by "delete this"!
|
||||
private:
|
||||
mutable int mRefCount;
|
||||
|
||||
#ifdef DEBUG
|
||||
private:
|
||||
static int objectCounter;
|
||||
static int referenceCounter;
|
||||
static int objectCounter;
|
||||
static int referenceCounter;
|
||||
friend void TestRefCountObj();
|
||||
|
||||
public:
|
||||
static bool AllRefCountObjDestoryed()
|
||||
{
|
||||
return objectCounter == 0 && referenceCounter == 0;
|
||||
static bool AllRefCountObjDestoryed()
|
||||
{
|
||||
return objectCounter == 0 && referenceCounter == 0;
|
||||
}
|
||||
#endif
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
@ -3,29 +3,29 @@
|
|||
// Portions created by Tripwire, Inc. are copyright (C) 2000-2018 Tripwire,
|
||||
// Inc. Tripwire is a registered trademark of Tripwire, Inc. All rights
|
||||
// reserved.
|
||||
//
|
||||
//
|
||||
// This program is free software. The contents of this file are subject
|
||||
// to the terms of the GNU General Public License as published by the
|
||||
// Free Software Foundation; either version 2 of the License, or (at your
|
||||
// option) any later version. You may redistribute it and/or modify it
|
||||
// only in compliance with the GNU General Public License.
|
||||
//
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful.
|
||||
// However, this program is distributed AS-IS WITHOUT ANY
|
||||
// WARRANTY; INCLUDING THE IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS
|
||||
// FOR A PARTICULAR PURPOSE. Please see the GNU General Public License
|
||||
// for more details.
|
||||
//
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
|
||||
// USA.
|
||||
//
|
||||
//
|
||||
// Nothing in the GNU General Public License or any other license to use
|
||||
// the code or files shall permit you to use Tripwire's trademarks,
|
||||
// service marks, or other intellectual property without Tripwire's
|
||||
// prior written consent.
|
||||
//
|
||||
//
|
||||
// If you have any questions, please contact Tripwire, Inc. at either
|
||||
// info@tripwire.org or www.tripwire.org.
|
||||
//
|
||||
|
@ -42,100 +42,90 @@
|
|||
#define __RESOURCES_H
|
||||
|
||||
|
||||
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
// Dependencies
|
||||
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
|
||||
#include <map> // for: Resource Table Implementation
|
||||
#include "debug.h" // for: ASSERT and Trace
|
||||
#include "error.h" // for: eInternal
|
||||
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
|
||||
#include <map> // for: Resource Table Implementation
|
||||
#include "debug.h" // for: ASSERT and Trace
|
||||
#include "error.h" // for: eInternal
|
||||
|
||||
|
||||
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
// Classes Declared in this module
|
||||
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
|
||||
template< class KEY, class RSC > class cResources_;
|
||||
template< class KEY, class CHR > class cMessages_;
|
||||
template<class KEY, class RSC> class cResources_;
|
||||
template<class KEY, class CHR> class cMessages_;
|
||||
|
||||
|
||||
//=============================================================================
|
||||
// cResources_<KEY,REZ> -- Keyed collection of resources
|
||||
//-----------------------------------------------------------------------------
|
||||
// SYNOPSIS:
|
||||
// SYNOPSIS:
|
||||
// Used to maintain a table of resources that are indexed by KEY
|
||||
// type values. The <REZ> type can be any valid type that is
|
||||
// assignable.
|
||||
//
|
||||
//
|
||||
// CONSTRAINTS:
|
||||
// <KEY> must be a valid key type for the std::map concept
|
||||
// <REZ> must be a valid value type for the std::map concept.
|
||||
//
|
||||
// INVARIANTS:
|
||||
//
|
||||
//
|
||||
template< class KeyT, class RscT >
|
||||
class cResources_
|
||||
// INVARIANTS:
|
||||
//
|
||||
//
|
||||
template<class KeyT, class RscT> class cResources_
|
||||
{
|
||||
//--Type Definitions
|
||||
|
||||
private:
|
||||
|
||||
typedef
|
||||
std::map< KeyT, RscT > Table; // Storage Rep
|
||||
|
||||
private:
|
||||
typedef std::map<KeyT, RscT> Table; // Storage Rep
|
||||
|
||||
public:
|
||||
|
||||
// Type definitions
|
||||
|
||||
typedef KeyT Key; // The resource id
|
||||
typedef KeyT& KeyRef;
|
||||
typedef const KeyT& ConstKeyRef;
|
||||
|
||||
typedef RscT Value; // The managed resource
|
||||
typedef Value& ValueRef;
|
||||
typedef const Value& ConstValueRef;
|
||||
|
||||
typedef typename Table::value_type Pair;
|
||||
|
||||
|
||||
public:
|
||||
// Type definitions
|
||||
|
||||
typedef KeyT Key; // The resource id
|
||||
typedef KeyT& KeyRef;
|
||||
typedef const KeyT& ConstKeyRef;
|
||||
|
||||
typedef RscT Value; // The managed resource
|
||||
typedef Value& ValueRef;
|
||||
typedef const Value& ConstValueRef;
|
||||
|
||||
typedef typename Table::value_type Pair;
|
||||
|
||||
|
||||
//--Interface.
|
||||
|
||||
public:
|
||||
|
||||
// Observers
|
||||
|
||||
ConstValueRef Get( ConstKeyRef ) const;
|
||||
public:
|
||||
// Observers
|
||||
|
||||
ConstValueRef Get(ConstKeyRef) const;
|
||||
|
||||
|
||||
// Modifiers
|
||||
// Modifiers
|
||||
|
||||
void Put(const Pair*, const Pair*);
|
||||
void Put(ConstKeyRef, Value);
|
||||
|
||||
|
||||
void Put( const Pair*, const Pair* );
|
||||
void Put( ConstKeyRef, Value );
|
||||
|
||||
|
||||
//--Implementation.
|
||||
|
||||
protected:
|
||||
|
||||
static ConstValueRef DefaultValueRef(); // NOTE:
|
||||
|
||||
private:
|
||||
|
||||
Table m_table;
|
||||
};
|
||||
|
||||
protected:
|
||||
static ConstValueRef DefaultValueRef(); // NOTE:
|
||||
|
||||
private:
|
||||
Table m_table;
|
||||
};
|
||||
|
||||
|
||||
//=============================================================================
|
||||
// cMessages_<KEY,CHAR> -- Specialization of Resources_ for message strings
|
||||
//-----------------------------------------------------------------------------
|
||||
// SYNOPSIS:
|
||||
// Specialization of cResources_<KEY,REZ> to store message strings
|
||||
// instead of generalized resource objects. In the future this can
|
||||
// SYNOPSIS:
|
||||
// Specialization of cResources_<KEY,REZ> to store message strings
|
||||
// instead of generalized resource objects. In the future this can
|
||||
// be refactored to use message objects so that they can come from
|
||||
// a dynamic source (i.e., not a string-literal) such as persistant
|
||||
// storage or some algorithm based on the concatenation of elements.
|
||||
|
@ -145,105 +135,93 @@ class cResources_
|
|||
// not allowing the client to expect a specific character sequence
|
||||
// representation, such as the near ubiquitous const char*. For
|
||||
// example:
|
||||
//
|
||||
// const char* psz = messages.GetAnsi( IDS_SOMESTRING );
|
||||
//
|
||||
//
|
||||
// const char* psz = messages.GetAnsi( IDS_SOMESTRING );
|
||||
//
|
||||
// The above call requires the caller to be responsible for memory
|
||||
// resources in the case of a conversion. However, there is no
|
||||
// clear way to know up front how many bytes will be required.
|
||||
// resources in the case of a conversion. However, there is no
|
||||
// clear way to know up front how many bytes will be required.
|
||||
// Another equally unsatisfactory solution is to allocate the
|
||||
// memory within cMessages and require the caller to release the
|
||||
// the resources when they are done with the message. If we instead
|
||||
// require calls in the following form:
|
||||
//
|
||||
// std::string str = messages.GetAnsi( IDS_SOMESTRING );
|
||||
//
|
||||
//
|
||||
// std::string str = messages.GetAnsi( IDS_SOMESTRING );
|
||||
//
|
||||
// We can allows assume proper resource use regardless of whether
|
||||
// a simple character pointer is returned or newly allocated
|
||||
// a simple character pointer is returned or newly allocated
|
||||
// resources used to convert the stored message.
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
// CONSTRAINTS:
|
||||
// As with all classes which manipulate character sequences, CHAR
|
||||
// must be a valid character type as defined by the STDCPP standard.
|
||||
//
|
||||
//
|
||||
template< class KeyT, class CharT >
|
||||
class cMessages_ : public cResources_< KeyT, const CharT* >
|
||||
template<class KeyT, class CharT> class cMessages_ : public cResources_<KeyT, const CharT*>
|
||||
{
|
||||
//--Type definitions
|
||||
|
||||
protected:
|
||||
|
||||
typedef
|
||||
cResources_<KeyT, const CharT* >
|
||||
Resources;
|
||||
|
||||
public:
|
||||
|
||||
typedef std::basic_string<CharT> String;
|
||||
typedef const KeyT& ConstKeyRef;
|
||||
protected:
|
||||
typedef cResources_<KeyT, const CharT*> Resources;
|
||||
|
||||
public:
|
||||
typedef std::basic_string<CharT> String;
|
||||
typedef const KeyT& ConstKeyRef;
|
||||
|
||||
|
||||
//--Interface.
|
||||
|
||||
public:
|
||||
|
||||
String Get ( ConstKeyRef ) const;
|
||||
std::string GetAnsi( ConstKeyRef ) const;
|
||||
public:
|
||||
String Get(ConstKeyRef) const;
|
||||
std::string GetAnsi(ConstKeyRef) const;
|
||||
#if SUPPORTS_WCHART
|
||||
std::wstring GetWide( ConstKeyRef ) const;
|
||||
#endif//SUPPORTS_WCHART
|
||||
std::wstring GetWide(ConstKeyRef) const;
|
||||
#endif //SUPPORTS_WCHART
|
||||
};
|
||||
|
||||
|
||||
|
||||
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
// IMPLEMENTATION: cResources_<KEY_TYPE, RESOURCE_TYPE>
|
||||
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
|
||||
|
||||
// NOTE: Macros to ease any changes in template arguments
|
||||
|
||||
#define Resource_Template template< class KeyT, class RscT >
|
||||
#define Resource_Class cResources_< KeyT, RscT >
|
||||
|
||||
|
||||
Resource_Template
|
||||
void Resource_Class::Put( const Pair* beg, const Pair* end )
|
||||
#define Resource_Template template<class KeyT, class RscT>
|
||||
#define Resource_Class cResources_<KeyT, RscT>
|
||||
|
||||
|
||||
Resource_Template void Resource_Class::Put(const Pair* beg, const Pair* end)
|
||||
{
|
||||
for ( const Pair* at = beg; at != end; ++at )
|
||||
for (const Pair* at = beg; at != end; ++at)
|
||||
{
|
||||
if ( !m_table.insert( *at ).second )
|
||||
if (!m_table.insert(*at).second)
|
||||
{
|
||||
ASSERTMSG( 0, "Resource key already exists!" );
|
||||
ASSERTMSG(0, "Resource key already exists!");
|
||||
// throw eInternal( "Resource key already exists!" );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// By value allows the user to Resource_table.Put( 6, "Literal" );
|
||||
Resource_Template
|
||||
inline
|
||||
void Resource_Class::Put( ConstKeyRef id, Value sResource )
|
||||
Resource_Template inline void Resource_Class::Put(ConstKeyRef id, Value sResource)
|
||||
{
|
||||
if ( m_table.insert( Pair( id, sResource ) ).second == false )
|
||||
if (m_table.insert(Pair(id, sResource)).second == false)
|
||||
{
|
||||
ASSERTMSG( 0, "Resource key already exists!" );
|
||||
ASSERTMSG(0, "Resource key already exists!");
|
||||
// throw eInternal( "Resource key already exists!" );
|
||||
}
|
||||
}
|
||||
|
||||
Resource_Template
|
||||
typename Resource_Class::ConstValueRef
|
||||
Resource_Class::Get( ConstKeyRef id ) const
|
||||
Resource_Template typename Resource_Class::ConstValueRef Resource_Class::Get(ConstKeyRef id) const
|
||||
{
|
||||
typename Table::const_iterator at = m_table.find( id );
|
||||
|
||||
if ( at == m_table.end() )
|
||||
typename Table::const_iterator at = m_table.find(id);
|
||||
|
||||
if (at == m_table.end())
|
||||
{
|
||||
#ifdef DEBUG
|
||||
#ifdef DEBUG
|
||||
std::cerr << "*** Error Resource_Class::Get() [" __FILE__ ":" << __LINE__ << "]: Resource not found\n";
|
||||
#endif
|
||||
#endif
|
||||
|
||||
return DefaultValueRef();
|
||||
}
|
||||
|
@ -253,40 +231,31 @@ Resource_Class::Get( ConstKeyRef id ) const
|
|||
}
|
||||
}
|
||||
|
||||
Resource_Template
|
||||
typename Resource_Class::ConstValueRef
|
||||
Resource_Class::DefaultValueRef()
|
||||
Resource_Template typename Resource_Class::ConstValueRef Resource_Class::DefaultValueRef()
|
||||
{
|
||||
static Value _default;
|
||||
return _default;
|
||||
}
|
||||
|
||||
|
||||
#undef Resource_Template //template< class KeyT, class RscT >
|
||||
#undef Resource_Class //Resources_<KeyT,RscT>
|
||||
|
||||
|
||||
|
||||
|
||||
#undef Resource_Template //template< class KeyT, class RscT >
|
||||
#undef Resource_Class //Resources_<KeyT,RscT>
|
||||
|
||||
|
||||
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
// IMPLEMENTATION: cMessages_<KEY_TYPE, RESOURCE_TYPE>
|
||||
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
|
||||
|
||||
// NOTE: Macros to ease any changes in template arguments
|
||||
|
||||
#define Message_Template template< class KeyT, class CharT >
|
||||
#define Message_Class cMessages_< KeyT, CharT >
|
||||
|
||||
|
||||
Message_Template
|
||||
inline
|
||||
typename Message_Class::String
|
||||
Message_Class::Get( ConstKeyRef id ) const
|
||||
#define Message_Template template<class KeyT, class CharT>
|
||||
#define Message_Class cMessages_<KeyT, CharT>
|
||||
|
||||
|
||||
Message_Template inline typename Message_Class::String Message_Class::Get(ConstKeyRef id) const
|
||||
{
|
||||
typename Message_Class::Value msg = Resources::Get( id );
|
||||
return
|
||||
( msg == this->DefaultValueRef() )
|
||||
? String()
|
||||
: String( msg );
|
||||
typename Message_Class::Value msg = Resources::Get(id);
|
||||
return (msg == this->DefaultValueRef()) ? String() : String(msg);
|
||||
}
|
||||
|
||||
|
||||
|
@ -294,86 +263,69 @@ Message_Class::Get( ConstKeyRef id ) const
|
|||
|
||||
namespace tss
|
||||
{
|
||||
namespace rsc
|
||||
{
|
||||
/* WARNING:RAD -- Cannot use StringUtil or CodeConvert since
|
||||
namespace rsc
|
||||
{
|
||||
/* WARNING:RAD -- Cannot use StringUtil or CodeConvert since
|
||||
these use ErrorMessages and String Resources! */
|
||||
|
||||
inline
|
||||
void
|
||||
ToNTMBS( std::string& nbs, const std::string& src )
|
||||
{
|
||||
nbs.assign( src );
|
||||
}
|
||||
|
||||
#if SUPPORTS_WCHART
|
||||
|
||||
inline
|
||||
void
|
||||
ToNTMBS( std::string& nbs, const std::wstring& wcs )
|
||||
{
|
||||
nbs.resize( MB_CUR_MAX * wcs.size() );
|
||||
|
||||
size_t nWrote =
|
||||
::wcstombs(
|
||||
const_cast< char * >( nbs.c_str() ),
|
||||
wcs.c_str(), nbs.size() + 1 );
|
||||
|
||||
if ( nWrote == (size_t)-1 )
|
||||
{
|
||||
ASSERTMSG( false, "Conversion error in cMessages_!" );
|
||||
// throw eCharacterEncoding( TSS_GetString( cCore, core::STR_ERR_BADCHAR ) );
|
||||
}
|
||||
|
||||
nbs.resize( nWrote );
|
||||
}
|
||||
|
||||
inline
|
||||
void
|
||||
ToNTWCS( std::wstring& dst, const std::wstring& src )
|
||||
{
|
||||
dst.assign( src );
|
||||
}
|
||||
|
||||
inline
|
||||
void
|
||||
ToNTWCS( std::wstring& wcs, const std::string& nbs )
|
||||
{
|
||||
wcs.resize( nbs.size() );
|
||||
|
||||
size_t nWrote =
|
||||
::mbstowcs(
|
||||
const_cast< wchar_t * >( wcs.c_str() ),
|
||||
nbs.c_str(), wcs.size() + 1 );
|
||||
|
||||
if ( nWrote == (size_t)-1 )
|
||||
{
|
||||
ASSERTMSG( false, "Conversion error in cMessages_!" );
|
||||
// throw eCharacterEncoding( TSS_GetString( cCore, core::STR_ERR_BADCHAR ) );
|
||||
}
|
||||
|
||||
wcs.resize( nWrote );
|
||||
}
|
||||
#endif//SUPPORTS_WCHART
|
||||
}//rsc::
|
||||
}//tss::
|
||||
|
||||
|
||||
Message_Template
|
||||
inline
|
||||
std::string
|
||||
Message_Class::GetAnsi( ConstKeyRef id ) const
|
||||
inline void ToNTMBS(std::string& nbs, const std::string& src)
|
||||
{
|
||||
typename Message_Class::Value msg = Resources::Get( id );
|
||||
|
||||
if ( msg == this->DefaultValueRef() )
|
||||
nbs.assign(src);
|
||||
}
|
||||
|
||||
#if SUPPORTS_WCHART
|
||||
|
||||
inline void ToNTMBS(std::string& nbs, const std::wstring& wcs)
|
||||
{
|
||||
nbs.resize(MB_CUR_MAX * wcs.size());
|
||||
|
||||
size_t nWrote = ::wcstombs(const_cast<char*>(nbs.c_str()), wcs.c_str(), nbs.size() + 1);
|
||||
|
||||
if (nWrote == (size_t)-1)
|
||||
{
|
||||
ASSERTMSG(false, "Conversion error in cMessages_!");
|
||||
// throw eCharacterEncoding( TSS_GetString( cCore, core::STR_ERR_BADCHAR ) );
|
||||
}
|
||||
|
||||
nbs.resize(nWrote);
|
||||
}
|
||||
|
||||
inline void ToNTWCS(std::wstring& dst, const std::wstring& src)
|
||||
{
|
||||
dst.assign(src);
|
||||
}
|
||||
|
||||
inline void ToNTWCS(std::wstring& wcs, const std::string& nbs)
|
||||
{
|
||||
wcs.resize(nbs.size());
|
||||
|
||||
size_t nWrote = ::mbstowcs(const_cast<wchar_t*>(wcs.c_str()), nbs.c_str(), wcs.size() + 1);
|
||||
|
||||
if (nWrote == (size_t)-1)
|
||||
{
|
||||
ASSERTMSG(false, "Conversion error in cMessages_!");
|
||||
// throw eCharacterEncoding( TSS_GetString( cCore, core::STR_ERR_BADCHAR ) );
|
||||
}
|
||||
|
||||
wcs.resize(nWrote);
|
||||
}
|
||||
#endif //SUPPORTS_WCHART
|
||||
} // namespace rsc
|
||||
} // namespace tss
|
||||
|
||||
|
||||
Message_Template inline std::string Message_Class::GetAnsi(ConstKeyRef id) const
|
||||
{
|
||||
typename Message_Class::Value msg = Resources::Get(id);
|
||||
|
||||
if (msg == this->DefaultValueRef())
|
||||
{
|
||||
return std::string();
|
||||
}
|
||||
else
|
||||
{
|
||||
std::string nbs;
|
||||
tss::rsc::ToNTMBS( nbs, String( msg ) );
|
||||
tss::rsc::ToNTMBS(nbs, String(msg));
|
||||
return nbs;
|
||||
}
|
||||
}
|
||||
|
@ -381,37 +333,33 @@ Message_Class::GetAnsi( ConstKeyRef id ) const
|
|||
|
||||
#if SUPPORTS_WCHART
|
||||
|
||||
Message_Template
|
||||
inline
|
||||
std::wstring
|
||||
Message_Class::GetWide( ConstKeyRef id ) const
|
||||
Message_Template inline std::wstring Message_Class::GetWide(ConstKeyRef id) const
|
||||
{
|
||||
Value msg = Resources::Get( id );
|
||||
|
||||
if ( msg == DefaultValueRef() )
|
||||
Value msg = Resources::Get(id);
|
||||
|
||||
if (msg == DefaultValueRef())
|
||||
{
|
||||
return std::string();
|
||||
}
|
||||
else
|
||||
{
|
||||
std::wstring wcs;
|
||||
tss::rsc::ToNTWCS( wcs, String( msg ) );
|
||||
tss::rsc::ToNTWCS(wcs, String(msg));
|
||||
return wcs;
|
||||
}
|
||||
}
|
||||
|
||||
#endif//SUPPORTS_WCHART
|
||||
#endif //SUPPORTS_WCHART
|
||||
|
||||
|
||||
#undef Message_Template
|
||||
#undef Message_Class
|
||||
|
||||
#endif//__RESOURCES_H
|
||||
|
||||
#endif //__RESOURCES_H
|
||||
|
||||
|
||||
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
// OLD CODE * OLD CODE * OLD CODE * OLD CODE * OLD CODE * OLD CODE * OLD CODE
|
||||
// OLD CODE * OLD CODE * OLD CODE * OLD CODE * OLD CODE * OLD CODE * OLD CODE
|
||||
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
|
||||
#ifdef RAD_OLDCODE
|
||||
|
@ -419,125 +367,107 @@ Message_Class::GetWide( ConstKeyRef id ) const
|
|||
//=============================================================================
|
||||
// cMessages_<char & wchar_t> -- Specializations
|
||||
//-----------------------------------------------------------------------------
|
||||
// SYNOPSIS:
|
||||
// SYNOPSIS:
|
||||
// MSVC does not yet support specializations. As a compromise, we fully
|
||||
// specialize on TCHR but assume a key type of "const int".
|
||||
//
|
||||
|
||||
// for SUNPro enums are ints, not const ints
|
||||
#if IS_SUNPRO
|
||||
#define ENUM_TYPE int
|
||||
# define ENUM_TYPE int
|
||||
#else
|
||||
#define ENUM_TYPE const int
|
||||
# define ENUM_TYPE const int
|
||||
#endif
|
||||
|
||||
template<>
|
||||
class cMessages_<ENUM_TYPE, char> :
|
||||
public cResources_< ENUM_TYPE, const char* >
|
||||
template<> class cMessages_<ENUM_TYPE, char> : public cResources_<ENUM_TYPE, const char*>
|
||||
{
|
||||
protected:
|
||||
|
||||
typedef
|
||||
cResources_< ENUM_TYPE, const char* >
|
||||
Resources;
|
||||
|
||||
public:
|
||||
|
||||
typedef std::string String;
|
||||
typedef int ConstKeyRef; // Better than <const int&>
|
||||
protected:
|
||||
typedef cResources_<ENUM_TYPE, const char*> Resources;
|
||||
|
||||
public:
|
||||
typedef std::string String;
|
||||
typedef int ConstKeyRef; // Better than <const int&>
|
||||
|
||||
|
||||
String Get( ConstKeyRef id ) const
|
||||
{
|
||||
Value msg = Resources::Get( id );
|
||||
return ( msg != DefaultValueRef() )
|
||||
? String( msg )
|
||||
: String();
|
||||
}
|
||||
|
||||
String GetAnsi( ConstKeyRef id ) const
|
||||
{
|
||||
return Get( id );
|
||||
}
|
||||
|
||||
String Get(ConstKeyRef id) const
|
||||
{
|
||||
Value msg = Resources::Get(id);
|
||||
return (msg != DefaultValueRef()) ? String(msg) : String();
|
||||
}
|
||||
|
||||
String GetAnsi(ConstKeyRef id) const
|
||||
{
|
||||
return Get(id);
|
||||
}
|
||||
|
||||
#if SUPPORTS_WCHART
|
||||
std::wstring GetWide( ConstKeyRef id ) const
|
||||
std::wstring GetWide(ConstKeyRef id) const
|
||||
{
|
||||
Value msg = Resources::Get(id);
|
||||
|
||||
if (msg == DefaultValueRef())
|
||||
{
|
||||
Value msg = Resources::Get( id );
|
||||
|
||||
if ( msg == DefaultValueRef() )
|
||||
{
|
||||
return std::wstring();
|
||||
}
|
||||
else
|
||||
{
|
||||
String::size_type
|
||||
N = String::traits_type::length( msg );
|
||||
|
||||
std::wstring dst( N, 0x00 );
|
||||
std::ctype< wchar_t >().widen( msg, msg + N, dst.begin() );
|
||||
|
||||
return dst;
|
||||
}
|
||||
return std::wstring();
|
||||
}
|
||||
#endif//SUPPORTS_WCHART
|
||||
else
|
||||
{
|
||||
String::size_type N = String::traits_type::length(msg);
|
||||
|
||||
std::wstring dst(N, 0x00);
|
||||
std::ctype<wchar_t>().widen(msg, msg + N, dst.begin());
|
||||
|
||||
return dst;
|
||||
}
|
||||
}
|
||||
#endif //SUPPORTS_WCHART
|
||||
};
|
||||
|
||||
#if SUPPORTS_WCHART
|
||||
|
||||
template<>
|
||||
class cMessages_<const int, wchar_t> :
|
||||
public cResources_< const int, const wchar_t* >
|
||||
|
||||
template<> class cMessages_<const int, wchar_t> : public cResources_<const int, const wchar_t*>
|
||||
{
|
||||
protected:
|
||||
|
||||
typedef
|
||||
cResources_<const int, const wchar_t* >
|
||||
Resources;
|
||||
|
||||
public:
|
||||
|
||||
typedef std::wstring String;
|
||||
typedef int ConstKeyRef; // Better than <const int&>
|
||||
protected:
|
||||
typedef cResources_<const int, const wchar_t*> Resources;
|
||||
|
||||
public:
|
||||
typedef std::wstring String;
|
||||
typedef int ConstKeyRef; // Better than <const int&>
|
||||
|
||||
|
||||
String Get( ConstKeyRef id ) const
|
||||
{
|
||||
Value msg = Resources::Get( id );
|
||||
if( msg != DefaultValueRef() )
|
||||
return String( msg );
|
||||
else
|
||||
return String();
|
||||
}
|
||||
|
||||
std::string GetAnsi( ConstKeyRef id ) const
|
||||
String Get(ConstKeyRef id) const
|
||||
{
|
||||
Value msg = Resources::Get(id);
|
||||
if (msg != DefaultValueRef())
|
||||
return String(msg);
|
||||
else
|
||||
return String();
|
||||
}
|
||||
|
||||
std::string GetAnsi(ConstKeyRef id) const
|
||||
{
|
||||
Value msg = Resources::Get(id);
|
||||
|
||||
if (msg == DefaultValueRef())
|
||||
{
|
||||
Value msg = Resources::Get( id );
|
||||
|
||||
if ( msg == DefaultValueRef() )
|
||||
{
|
||||
return std::string();
|
||||
}
|
||||
else
|
||||
{
|
||||
String::size_type
|
||||
N = String::traits_type::length( msg );
|
||||
|
||||
std::string dst( N, 0x00 );
|
||||
std::ctype<CharT>().narrow( msg, msg + N, '?', dst.begin() );
|
||||
|
||||
return dst;
|
||||
}
|
||||
return std::string();
|
||||
}
|
||||
|
||||
String GetWide( ConstKeyRef id ) const
|
||||
else
|
||||
{
|
||||
return Get( id );
|
||||
String::size_type N = String::traits_type::length(msg);
|
||||
|
||||
std::string dst(N, 0x00);
|
||||
std::ctype<CharT>().narrow(msg, msg + N, '?', dst.begin());
|
||||
|
||||
return dst;
|
||||
}
|
||||
}
|
||||
|
||||
String GetWide(ConstKeyRef id) const
|
||||
{
|
||||
return Get(id);
|
||||
}
|
||||
};
|
||||
|
||||
#endif//SUPPORTS_WCHART
|
||||
|
||||
#endif//RAD_OLDCODE
|
||||
|
||||
# endif //SUPPORTS_WCHART
|
||||
|
||||
#endif //RAD_OLDCODE
|
||||
|
|
|
@ -3,29 +3,29 @@
|
|||
// Portions created by Tripwire, Inc. are copyright (C) 2000-2018 Tripwire,
|
||||
// Inc. Tripwire is a registered trademark of Tripwire, Inc. All rights
|
||||
// reserved.
|
||||
//
|
||||
//
|
||||
// This program is free software. The contents of this file are subject
|
||||
// to the terms of the GNU General Public License as published by the
|
||||
// Free Software Foundation; either version 2 of the License, or (at your
|
||||
// option) any later version. You may redistribute it and/or modify it
|
||||
// only in compliance with the GNU General Public License.
|
||||
//
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful.
|
||||
// However, this program is distributed AS-IS WITHOUT ANY
|
||||
// WARRANTY; INCLUDING THE IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS
|
||||
// FOR A PARTICULAR PURPOSE. Please see the GNU General Public License
|
||||
// for more details.
|
||||
//
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
|
||||
// USA.
|
||||
//
|
||||
//
|
||||
// Nothing in the GNU General Public License or any other license to use
|
||||
// the code or files shall permit you to use Tripwire's trademarks,
|
||||
// service marks, or other intellectual property without Tripwire's
|
||||
// prior written consent.
|
||||
//
|
||||
//
|
||||
// If you have any questions, please contact Tripwire, Inc. at either
|
||||
// info@tripwire.org or www.tripwire.org.
|
||||
//
|
||||
|
@ -36,8 +36,13 @@
|
|||
#include "serializable.h"
|
||||
|
||||
#if IS_SUNPRO
|
||||
iTypedSerializable::~iTypedSerializable() {}
|
||||
iSerializable::~iSerializable() {}
|
||||
iTyped::~iTyped() {}
|
||||
iTypedSerializable::~iTypedSerializable()
|
||||
{
|
||||
}
|
||||
iSerializable::~iSerializable()
|
||||
{
|
||||
}
|
||||
iTyped::~iTyped()
|
||||
{
|
||||
}
|
||||
#endif
|
||||
|
||||
|
|
|
@ -3,29 +3,29 @@
|
|||
// Portions created by Tripwire, Inc. are copyright (C) 2000-2018 Tripwire,
|
||||
// Inc. Tripwire is a registered trademark of Tripwire, Inc. All rights
|
||||
// reserved.
|
||||
//
|
||||
//
|
||||
// This program is free software. The contents of this file are subject
|
||||
// to the terms of the GNU General Public License as published by the
|
||||
// Free Software Foundation; either version 2 of the License, or (at your
|
||||
// option) any later version. You may redistribute it and/or modify it
|
||||
// only in compliance with the GNU General Public License.
|
||||
//
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful.
|
||||
// However, this program is distributed AS-IS WITHOUT ANY
|
||||
// WARRANTY; INCLUDING THE IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS
|
||||
// FOR A PARTICULAR PURPOSE. Please see the GNU General Public License
|
||||
// for more details.
|
||||
//
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
|
||||
// USA.
|
||||
//
|
||||
//
|
||||
// Nothing in the GNU General Public License or any other license to use
|
||||
// the code or files shall permit you to use Tripwire's trademarks,
|
||||
// service marks, or other intellectual property without Tripwire's
|
||||
// prior written consent.
|
||||
//
|
||||
//
|
||||
// If you have any questions, please contact Tripwire, Inc. at either
|
||||
// info@tripwire.org or www.tripwire.org.
|
||||
//
|
||||
|
@ -46,7 +46,7 @@
|
|||
|
||||
class iSerializer;
|
||||
|
||||
// Some version documentation is in order here:
|
||||
// Some version documentation is in order here:
|
||||
//
|
||||
// Objects that derive from iSerializable do not need to worry about versions, they
|
||||
// should just read and write themselves to and from the serializer.
|
||||
|
@ -56,70 +56,82 @@ class iSerializer;
|
|||
// version number. Neither major or minor version number can be negative and at least one
|
||||
// must be greater than zero.
|
||||
//
|
||||
// When an object is serialized using iSerializer::WriteObject() a header will be written that
|
||||
// includes the current version number will be saved in the archive by. Therefore
|
||||
// iSerializable::Write() implementations do not need to worry about versioning, They need only
|
||||
// When an object is serialized using iSerializer::WriteObject() a header will be written that
|
||||
// includes the current version number will be saved in the archive by. Therefore
|
||||
// iSerializable::Write() implementations do not need to worry about versioning, They need only
|
||||
// write out the object in current format.
|
||||
//
|
||||
// When an object is read back from an archive using iSerializer::ReadObject(),
|
||||
// the version of the serialized object will be read from the header and is passed to
|
||||
// iSerializable::Read(). Each implementation of Read() should this passed in version.
|
||||
// When an object is read back from an archive using iSerializer::ReadObject(),
|
||||
// the version of the serialized object will be read from the header and is passed to
|
||||
// iSerializable::Read(). Each implementation of Read() should this passed in version.
|
||||
// If the version is greater than the current version Read() should throw a eSerializer
|
||||
// exception. If the version is older than the current implementation, Read() should either
|
||||
// read the older format or throw an eSerializer exception.
|
||||
// exception. If the version is older than the current implementation, Read() should either
|
||||
// read the older format or throw an eSerializer exception.
|
||||
//
|
||||
// IMPORTANT: If the version is 0 (the default parameter) then Read() it should read
|
||||
// in the current format of the object. This is important if Read() is called directly.
|
||||
//
|
||||
// In some cases it may be desirable to not incur the overhead of the serializer writing
|
||||
// header information for each serialized object. In this case call iSerializable::Read() and
|
||||
// iSerializable::Write() directly rather than using ReadObject() and WriteObject().
|
||||
// header information for each serialized object. In this case call iSerializable::Read() and
|
||||
// iSerializable::Write() directly rather than using ReadObject() and WriteObject().
|
||||
|
||||
class iSerializable
|
||||
{
|
||||
public:
|
||||
virtual void Read (iSerializer* pSerializer, int32 version = 0) = 0; // throw (eSerializer, eArchive)
|
||||
virtual void Write(iSerializer* pSerializer) const = 0; // throw (eSerializer, eArchive)
|
||||
// objects implement these methods to read and write themselves to a serializer.
|
||||
virtual void Read(iSerializer* pSerializer, int32 version = 0) = 0; // throw (eSerializer, eArchive)
|
||||
virtual void Write(iSerializer* pSerializer) const = 0; // throw (eSerializer, eArchive)
|
||||
// objects implement these methods to read and write themselves to a serializer.
|
||||
|
||||
virtual ~iSerializable() {}
|
||||
virtual ~iSerializable()
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
class iTypedSerializable : public iTyped, public iSerializable
|
||||
{
|
||||
public:
|
||||
typedef iTypedSerializable* (*CreateFunc)();
|
||||
// Pointer to a function that creates an empty version of each typed serializable object
|
||||
// Pointer to a function that creates an empty version of each typed serializable object
|
||||
|
||||
virtual int32 Version() const = 0;
|
||||
// Return the current version of that this serializable object writes.
|
||||
// As a convention version number should be (major_version << 16) | minor_version.
|
||||
// Return the current version of that this serializable object writes.
|
||||
// As a convention version number should be (major_version << 16) | minor_version.
|
||||
|
||||
static int32 MkVersion(int16 major, int16 minor) { return (int32)(((uint32)major << 16) | (uint32)minor); }
|
||||
static int16 MajorVersion(int32 version) { return (int16)((uint32)version >> 16); }
|
||||
static int16 MinorVersion(int32 version) { return (int16)version; }
|
||||
static int32 MkVersion(int16 major, int16 minor)
|
||||
{
|
||||
return (int32)(((uint32)major << 16) | (uint32)minor);
|
||||
}
|
||||
static int16 MajorVersion(int32 version)
|
||||
{
|
||||
return (int16)((uint32)version >> 16);
|
||||
}
|
||||
static int16 MinorVersion(int32 version)
|
||||
{
|
||||
return (int16)version;
|
||||
}
|
||||
|
||||
virtual ~iTypedSerializable() {}
|
||||
virtual ~iTypedSerializable()
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
//////////////////////////////
|
||||
// convenience macros
|
||||
#define DECLARE_TYPEDSERIALIZABLE() \
|
||||
DECLARE_TYPED() \
|
||||
public: \
|
||||
static iTypedSerializable* Create(); \
|
||||
virtual int32 Version() const;
|
||||
# define DECLARE_TYPEDSERIALIZABLE() \
|
||||
DECLARE_TYPED() \
|
||||
public: \
|
||||
static iTypedSerializable* Create(); \
|
||||
virtual int32 Version() const;
|
||||
|
||||
#define IMPLEMENT_TYPEDSERIALIZABLE(CLASS, TYPEDSTRING, VERSION_MAJOR, VERSION_MINOR) \
|
||||
IMPLEMENT_TYPED(CLASS, TYPEDSTRING) \
|
||||
iTypedSerializable* CLASS::Create() \
|
||||
{ \
|
||||
return new CLASS; \
|
||||
} \
|
||||
int32 CLASS::Version() const \
|
||||
{ \
|
||||
return iTypedSerializable::MkVersion(VERSION_MAJOR, VERSION_MINOR); \
|
||||
}
|
||||
# define IMPLEMENT_TYPEDSERIALIZABLE(CLASS, TYPEDSTRING, VERSION_MAJOR, VERSION_MINOR) \
|
||||
IMPLEMENT_TYPED(CLASS, TYPEDSTRING) \
|
||||
iTypedSerializable* CLASS::Create() \
|
||||
{ \
|
||||
return new CLASS; \
|
||||
} \
|
||||
int32 CLASS::Version() const \
|
||||
{ \
|
||||
return iTypedSerializable::MkVersion(VERSION_MAJOR, VERSION_MINOR); \
|
||||
}
|
||||
|
||||
#endif // __SERIALIZABLE_H
|
||||
|
||||
|
|
|
@ -3,29 +3,29 @@
|
|||
// Portions created by Tripwire, Inc. are copyright (C) 2000-2018 Tripwire,
|
||||
// Inc. Tripwire is a registered trademark of Tripwire, Inc. All rights
|
||||
// reserved.
|
||||
//
|
||||
//
|
||||
// This program is free software. The contents of this file are subject
|
||||
// to the terms of the GNU General Public License as published by the
|
||||
// Free Software Foundation; either version 2 of the License, or (at your
|
||||
// option) any later version. You may redistribute it and/or modify it
|
||||
// only in compliance with the GNU General Public License.
|
||||
//
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful.
|
||||
// However, this program is distributed AS-IS WITHOUT ANY
|
||||
// WARRANTY; INCLUDING THE IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS
|
||||
// FOR A PARTICULAR PURPOSE. Please see the GNU General Public License
|
||||
// for more details.
|
||||
//
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
|
||||
// USA.
|
||||
//
|
||||
//
|
||||
// Nothing in the GNU General Public License or any other license to use
|
||||
// the code or files shall permit you to use Tripwire's trademarks,
|
||||
// service marks, or other intellectual property without Tripwire's
|
||||
// prior written consent.
|
||||
//
|
||||
//
|
||||
// If you have any questions, please contact Tripwire, Inc. at either
|
||||
// info@tripwire.org or www.tripwire.org.
|
||||
//
|
||||
|
@ -47,47 +47,47 @@
|
|||
{
|
||||
TSTRING ret;
|
||||
|
||||
if( !eSerializer::mDataSource.empty() )
|
||||
if (!eSerializer::mDataSource.empty())
|
||||
{
|
||||
ret = mMsg;
|
||||
|
||||
switch( eSerializer::mSourceType )
|
||||
switch (eSerializer::mSourceType)
|
||||
{
|
||||
case TY_UNDEFINED:
|
||||
ret.append( mDataSource );
|
||||
ret.append(mDataSource);
|
||||
break;
|
||||
case TY_FILE:
|
||||
ret.append( _T("\nFile: ") );
|
||||
ret.append( mDataSource );
|
||||
ret.append(_T("\nFile: "));
|
||||
ret.append(mDataSource);
|
||||
break;
|
||||
case TY_TEMPFILE:
|
||||
ret.append( _T("\nTemporary File: ") );
|
||||
ret.append( mDataSource );
|
||||
ret.append(_T("\nTemporary File: "));
|
||||
ret.append(mDataSource);
|
||||
break;
|
||||
case TY_MEMORY:
|
||||
ret.append( _T("\nMemory Block: ") ); //uhhh...??
|
||||
ret.append( mDataSource );
|
||||
ret.append(_T("\nMemory Block: ")); //uhhh...??
|
||||
ret.append(mDataSource);
|
||||
break;
|
||||
case TY_PIPE:
|
||||
ret.append( _T("\nNamed Pipe: "));
|
||||
ret.append( mDataSource );
|
||||
ret.append(_T("\nNamed Pipe: "));
|
||||
ret.append(mDataSource);
|
||||
break;
|
||||
case TY_SOCKET:
|
||||
ret.append( _T("\nNetwork Socket: "));
|
||||
ret.append( mDataSource );
|
||||
ret.append(_T("\nNetwork Socket: "));
|
||||
ret.append(mDataSource);
|
||||
break;
|
||||
default:
|
||||
ret.append( _T("\n"));
|
||||
ret.append( mDataSource );
|
||||
ret.append(_T("\n"));
|
||||
ret.append(mDataSource);
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
else
|
||||
{
|
||||
// Just use the base class method...
|
||||
ret = eError::GetMsg();
|
||||
}
|
||||
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
|
|
@ -3,29 +3,29 @@
|
|||
// Portions created by Tripwire, Inc. are copyright (C) 2000-2018 Tripwire,
|
||||
// Inc. Tripwire is a registered trademark of Tripwire, Inc. All rights
|
||||
// reserved.
|
||||
//
|
||||
//
|
||||
// This program is free software. The contents of this file are subject
|
||||
// to the terms of the GNU General Public License as published by the
|
||||
// Free Software Foundation; either version 2 of the License, or (at your
|
||||
// option) any later version. You may redistribute it and/or modify it
|
||||
// only in compliance with the GNU General Public License.
|
||||
//
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful.
|
||||
// However, this program is distributed AS-IS WITHOUT ANY
|
||||
// WARRANTY; INCLUDING THE IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS
|
||||
// FOR A PARTICULAR PURPOSE. Please see the GNU General Public License
|
||||
// for more details.
|
||||
//
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
|
||||
// USA.
|
||||
//
|
||||
//
|
||||
// Nothing in the GNU General Public License or any other license to use
|
||||
// the code or files shall permit you to use Tripwire's trademarks,
|
||||
// service marks, or other intellectual property without Tripwire's
|
||||
// prior written consent.
|
||||
//
|
||||
//
|
||||
// If you have any questions, please contact Tripwire, Inc. at either
|
||||
// info@tripwire.org or www.tripwire.org.
|
||||
//
|
||||
|
@ -46,52 +46,51 @@ class iSerializable;
|
|||
////////////////////////////////////////////////////////////
|
||||
// Serializer Base Exception
|
||||
////////////////////////////////////////////////////////////
|
||||
TSS_BEGIN_EXCEPTION_NO_CTOR( eSerializer, eError )
|
||||
// TODO: What else to add to this enumeration? Locked File? Temp file?
|
||||
enum DataSourceType {
|
||||
TY_UNDEFINED = 0,
|
||||
TY_FILE,
|
||||
TY_TEMPFILE,
|
||||
TY_MEMORY,
|
||||
TY_PIPE,
|
||||
TY_SOCKET
|
||||
};
|
||||
TSS_BEGIN_EXCEPTION_NO_CTOR(eSerializer, eError)
|
||||
// TODO: What else to add to this enumeration? Locked File? Temp file?
|
||||
enum DataSourceType
|
||||
{
|
||||
TY_UNDEFINED = 0,
|
||||
TY_FILE,
|
||||
TY_TEMPFILE,
|
||||
TY_MEMORY,
|
||||
TY_PIPE,
|
||||
TY_SOCKET
|
||||
};
|
||||
|
||||
eSerializer( const TSTRING& msg, const TSTRING& dataSource = _T(""), DataSourceType paramType = TY_UNDEFINED )
|
||||
: eError( msg ),
|
||||
mDataSource( dataSource ),
|
||||
mSourceType( paramType )
|
||||
{}
|
||||
|
||||
virtual TSTRING GetMsg() const;
|
||||
eSerializer(const TSTRING& msg, const TSTRING& dataSource = _T(""), DataSourceType paramType = TY_UNDEFINED)
|
||||
: eError(msg), mDataSource(dataSource), mSourceType(paramType)
|
||||
{
|
||||
}
|
||||
|
||||
virtual TSTRING GetMsg() const;
|
||||
|
||||
private:
|
||||
TSTRING mDataSource;
|
||||
// TSTRING indentifier of the datasource associated with a particular error
|
||||
// (if one exists) EX: a filename.
|
||||
DataSourceType mSourceType;
|
||||
TSTRING mDataSource;
|
||||
// TSTRING indentifier of the datasource associated with a particular error
|
||||
// (if one exists) EX: a filename.
|
||||
DataSourceType mSourceType;
|
||||
TSS_END_EXCEPTION();
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Helper Macro For Serializer Exceptions
|
||||
////////////////////////////////////////////////////////////
|
||||
#define TSS_SERIALIZER_EXCEPTION( except ) \
|
||||
TSS_BEGIN_EXCEPTION_NO_CTOR( except, eSerializer ) \
|
||||
except( const TSTRING& msg, const TSTRING& dataSource = _T(""), DataSourceType paramType = TY_UNDEFINED ) \
|
||||
: eSerializer( msg, dataSource, paramType ) \
|
||||
{}; \
|
||||
#define TSS_SERIALIZER_EXCEPTION(except) \
|
||||
TSS_BEGIN_EXCEPTION_NO_CTOR(except, eSerializer) \
|
||||
except(const TSTRING& msg, const TSTRING& dataSource = _T(""), DataSourceType paramType = TY_UNDEFINED) \
|
||||
: eSerializer(msg, dataSource, paramType){}; \
|
||||
TSS_END_EXCEPTION()
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Specific Exceptions
|
||||
////////////////////////////////////////////////////////////
|
||||
TSS_SERIALIZER_EXCEPTION( eSerializerUnknownType );
|
||||
TSS_SERIALIZER_EXCEPTION( eSerializerInputStreamFmt);
|
||||
TSS_SERIALIZER_EXCEPTION( eSerializerOutputStreamFmt );
|
||||
TSS_SERIALIZER_EXCEPTION( eSerializerInputStremTypeArray );
|
||||
TSS_SERIALIZER_EXCEPTION( eSerializerArchive ); // not used
|
||||
TSS_SERIALIZER_EXCEPTION( eSerializerVersionMismatch );
|
||||
TSS_SERIALIZER_EXCEPTION( eSerializerEncryption );
|
||||
TSS_SERIALIZER_EXCEPTION(eSerializerUnknownType);
|
||||
TSS_SERIALIZER_EXCEPTION(eSerializerInputStreamFmt);
|
||||
TSS_SERIALIZER_EXCEPTION(eSerializerOutputStreamFmt);
|
||||
TSS_SERIALIZER_EXCEPTION(eSerializerInputStremTypeArray);
|
||||
TSS_SERIALIZER_EXCEPTION(eSerializerArchive); // not used
|
||||
TSS_SERIALIZER_EXCEPTION(eSerializerVersionMismatch);
|
||||
TSS_SERIALIZER_EXCEPTION(eSerializerEncryption);
|
||||
|
||||
/*
|
||||
E_UNKNOWN_TYPE = 700,
|
||||
|
@ -107,59 +106,62 @@ class iSerializer
|
|||
{
|
||||
public:
|
||||
// Initializing and closing the archive
|
||||
virtual void Init() = 0; // throw eSerializer
|
||||
virtual void Init() = 0; // throw eSerializer
|
||||
// initializes the serializer; must be called before any reading or writing is done
|
||||
virtual void Finit() = 0;
|
||||
// called after a session of serialization is done; called implicitely by the destructor
|
||||
// if not called explicitely before destruction
|
||||
// called after a session of serialization is done; called implicitely by the destructor
|
||||
// if not called explicitely before destruction
|
||||
|
||||
//Reading and writing objects Init() should have already been called or all these will fail.
|
||||
virtual void WriteObjectDynCreate(const iTypedSerializable* pObj) = 0; // throw (eSerializer, eArchive)
|
||||
// writes an object such that it can be dynamically created when read back in with
|
||||
// ReadObject.
|
||||
virtual iTypedSerializable* ReadObjectDynCreate() = 0; // throw (eSerializer, eArchive);
|
||||
virtual void WriteObjectDynCreate(const iTypedSerializable* pObj) = 0; // throw (eSerializer, eArchive)
|
||||
// writes an object such that it can be dynamically created when read back in with
|
||||
// ReadObject.
|
||||
virtual iTypedSerializable* ReadObjectDynCreate() = 0; // throw (eSerializer, eArchive);
|
||||
// reads an object from the archive, returning a pointer to it. The caller is responsible for
|
||||
// deleteing or Release()ing it when done.
|
||||
virtual void WriteObject(const iTypedSerializable* pObj) = 0; // throw (eSerializer, eArchive)
|
||||
virtual void WriteObject(const iTypedSerializable* pObj) = 0; // throw (eSerializer, eArchive)
|
||||
// writes an object to the archive that will not be dynamically created
|
||||
virtual void ReadObject(iTypedSerializable* pObj) = 0; // throw (eSerializer, eArchive)
|
||||
virtual void ReadObject(iTypedSerializable* pObj) = 0; // throw (eSerializer, eArchive)
|
||||
// reads an object that was written with WriteObject()
|
||||
|
||||
|
||||
// writing interface
|
||||
// all of these can throw eArchive
|
||||
virtual void ReadInt16(int16& ret) = 0;
|
||||
virtual void ReadInt32(int32& ret) = 0;
|
||||
virtual void ReadInt64(int64& ret) = 0;
|
||||
virtual void ReadString(TSTRING& ret) = 0;
|
||||
virtual int ReadBlob(void* pBlob, int count) = 0;
|
||||
virtual void WriteInt16(int16 i) = 0;
|
||||
virtual void WriteInt32(int32 i) = 0;
|
||||
virtual void WriteInt64(int64 i) = 0;
|
||||
virtual void WriteString(const TSTRING& s) = 0;
|
||||
virtual void WriteBlob(const void* pBlob, int count) = 0;
|
||||
virtual void ReadInt16(int16& ret) = 0;
|
||||
virtual void ReadInt32(int32& ret) = 0;
|
||||
virtual void ReadInt64(int64& ret) = 0;
|
||||
virtual void ReadString(TSTRING& ret) = 0;
|
||||
virtual int ReadBlob(void* pBlob, int count) = 0;
|
||||
virtual void WriteInt16(int16 i) = 0;
|
||||
virtual void WriteInt32(int32 i) = 0;
|
||||
virtual void WriteInt64(int64 i) = 0;
|
||||
virtual void WriteString(const TSTRING& s) = 0;
|
||||
virtual void WriteBlob(const void* pBlob, int count) = 0;
|
||||
|
||||
virtual TSTRING GetFileName() const { return _T(""); }
|
||||
// derived classes can implement this to return the file name associated with the serializer.
|
||||
// it is only used in error reporting.
|
||||
virtual TSTRING GetFileName() const
|
||||
{
|
||||
return _T("");
|
||||
}
|
||||
// derived classes can implement this to return the file name associated with the serializer.
|
||||
// it is only used in error reporting.
|
||||
|
||||
// the error enumeration: 700-799
|
||||
enum ErrorNum
|
||||
{
|
||||
E_UNKNOWN_TYPE = 700,
|
||||
E_INPUT_STREAM_FORMAT = 701,
|
||||
E_INPUT_STR_TYPEARRAY = 702, // bad index in to type array
|
||||
E_ARCHIVE = 703,
|
||||
E_VERSION_MISMATCH = 704,
|
||||
E_ENCRYPTION_ERROR = 705,
|
||||
E_OUTPUT_STREAM_FORMAT = 706,
|
||||
E_UNKNOWN_TYPE = 700,
|
||||
E_INPUT_STREAM_FORMAT = 701,
|
||||
E_INPUT_STR_TYPEARRAY = 702, // bad index in to type array
|
||||
E_ARCHIVE = 703,
|
||||
E_VERSION_MISMATCH = 704,
|
||||
E_ENCRYPTION_ERROR = 705,
|
||||
E_OUTPUT_STREAM_FORMAT = 706,
|
||||
E_NUMITEMS
|
||||
};
|
||||
|
||||
virtual ~iSerializer() {}
|
||||
|
||||
virtual ~iSerializer()
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
@ -3,29 +3,29 @@
|
|||
// Portions created by Tripwire, Inc. are copyright (C) 2000-2018 Tripwire,
|
||||
// Inc. Tripwire is a registered trademark of Tripwire, Inc. All rights
|
||||
// reserved.
|
||||
//
|
||||
//
|
||||
// This program is free software. The contents of this file are subject
|
||||
// to the terms of the GNU General Public License as published by the
|
||||
// Free Software Foundation; either version 2 of the License, or (at your
|
||||
// option) any later version. You may redistribute it and/or modify it
|
||||
// only in compliance with the GNU General Public License.
|
||||
//
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful.
|
||||
// However, this program is distributed AS-IS WITHOUT ANY
|
||||
// WARRANTY; INCLUDING THE IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS
|
||||
// FOR A PARTICULAR PURPOSE. Please see the GNU General Public License
|
||||
// for more details.
|
||||
//
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
|
||||
// USA.
|
||||
//
|
||||
//
|
||||
// Nothing in the GNU General Public License or any other license to use
|
||||
// the code or files shall permit you to use Tripwire's trademarks,
|
||||
// service marks, or other intellectual property without Tripwire's
|
||||
// prior written consent.
|
||||
//
|
||||
//
|
||||
// If you have any questions, please contact Tripwire, Inc. at either
|
||||
// info@tripwire.org or www.tripwire.org.
|
||||
//
|
||||
|
@ -34,19 +34,19 @@
|
|||
#include "serializerimpl.h"
|
||||
#include "debug.h"
|
||||
#include "archive.h"
|
||||
#include "ntmbs.h" // for: eCharacterEncoding
|
||||
#include "ntmbs.h" // for: eCharacterEncoding
|
||||
#include "crc32.h"
|
||||
|
||||
// static members
|
||||
cSerializerImpl::SerMap cSerializerImpl::mSerCreateMap ;
|
||||
cSerializerImpl::SerRefCountMap cSerializerImpl::mSerRefCountCreateMap ;
|
||||
cSerializerImpl::SerMap cSerializerImpl::mSerCreateMap;
|
||||
cSerializerImpl::SerRefCountMap cSerializerImpl::mSerRefCountCreateMap;
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// util_GetCrc -- calculates the crc for the narrow version of the type's AsString()
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
static uint32 util_GetCRC( const cType& type )
|
||||
static uint32 util_GetCRC(const cType& type)
|
||||
{
|
||||
//
|
||||
//
|
||||
// convert this to narrow...
|
||||
//
|
||||
|
||||
|
@ -59,19 +59,19 @@ static uint32 util_GetCRC( const cType& type )
|
|||
|
||||
// We only need to count the characters
|
||||
// RAD: Yeesh! This is already done for us in cType::mString!!!
|
||||
const uint8* pszType = (const uint8*)( type.AsString() );
|
||||
int nBytes = ::strlen( (const char*)pszType );
|
||||
const uint8* pszType = (const uint8*)(type.AsString());
|
||||
int nBytes = ::strlen((const char*)pszType);
|
||||
|
||||
ASSERT( sizeof(uint8) == sizeof(byte) );
|
||||
ASSERT( pszType && *pszType );
|
||||
ASSERT(sizeof(uint8) == sizeof(byte));
|
||||
ASSERT(pszType && *pszType);
|
||||
|
||||
//
|
||||
// calculate the crc...
|
||||
//
|
||||
CRC_INFO crc;
|
||||
crcInit( crc );
|
||||
crcUpdate( crc, pszType, nBytes );
|
||||
crcFinit( crc );
|
||||
crcInit(crc);
|
||||
crcUpdate(crc, pszType, nBytes);
|
||||
crcFinit(crc);
|
||||
|
||||
return crc.crc;
|
||||
}
|
||||
|
@ -79,11 +79,8 @@ static uint32 util_GetCRC( const cType& type )
|
|||
//#############################################################################
|
||||
// class cSerializerImpl
|
||||
//#############################################################################
|
||||
cSerializerImpl::cSerializerImpl(cArchive& archive, Mode action, const TSTRING& fileName) :
|
||||
mpArchive(&archive),
|
||||
mMode(action),
|
||||
mbInit(false),
|
||||
mFileName( fileName )
|
||||
cSerializerImpl::cSerializerImpl(cArchive& archive, Mode action, const TSTRING& fileName)
|
||||
: mpArchive(&archive), mMode(action), mbInit(false), mFileName(fileName)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -107,13 +104,13 @@ bool cSerializerImpl::IsWriting() const
|
|||
|
||||
void cSerializerImpl::RegisterSerializable(const cType& type, iTypedSerializable::CreateFunc pFunc)
|
||||
{
|
||||
uint32 crc = util_GetCRC( type );
|
||||
uint32 crc = util_GetCRC(type);
|
||||
|
||||
if( cSerializerImpl::mSerCreateMap.find( crc ) != cSerializerImpl::mSerCreateMap.end() )
|
||||
if (cSerializerImpl::mSerCreateMap.find(crc) != cSerializerImpl::mSerCreateMap.end())
|
||||
{
|
||||
// duplicate entry!
|
||||
//
|
||||
ASSERT( false );
|
||||
ASSERT(false);
|
||||
TOSTRINGSTREAM str;
|
||||
str << _T("Duplicate entry in type table: ") << type.AsString() << std::endl;
|
||||
throw eInternal(str.str());
|
||||
|
@ -123,13 +120,13 @@ void cSerializerImpl::RegisterSerializable(const cType& type, iTypedSerializable
|
|||
|
||||
void cSerializerImpl::RegisterSerializableRefCt(const cType& type, iSerRefCountObj::CreateFunc pFunc)
|
||||
{
|
||||
uint32 crc = util_GetCRC( type );
|
||||
uint32 crc = util_GetCRC(type);
|
||||
|
||||
if( cSerializerImpl::mSerRefCountCreateMap.find( crc ) != cSerializerImpl::mSerRefCountCreateMap.end() )
|
||||
if (cSerializerImpl::mSerRefCountCreateMap.find(crc) != cSerializerImpl::mSerRefCountCreateMap.end())
|
||||
{
|
||||
// duplicate entry!
|
||||
//
|
||||
ASSERT( false );
|
||||
ASSERT(false);
|
||||
TOSTRINGSTREAM str;
|
||||
str << _T("Duplicate entry in type table: ") << type.AsString() << std::ends;
|
||||
throw eInternal(str.str());
|
||||
|
@ -153,7 +150,7 @@ void cSerializerImpl::Init()
|
|||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Finit
|
||||
// Finit
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
void cSerializerImpl::Finit()
|
||||
{
|
||||
|
@ -184,23 +181,23 @@ void cSerializerImpl::WriteObjectDynCreate(const iTypedSerializable* pObj)
|
|||
|
||||
// get the ident for this class type
|
||||
//
|
||||
uint32 crc = util_GetCRC( pObj->GetType() );
|
||||
uint32 crc = util_GetCRC(pObj->GetType());
|
||||
|
||||
//
|
||||
// make sure this type is registered, and figure out if it is refrence counted
|
||||
//
|
||||
SerRefCountMap::iterator i = mSerRefCountCreateMap.find( crc );
|
||||
bool bRefCount = true;
|
||||
if( i == mSerRefCountCreateMap.end() )
|
||||
SerRefCountMap::iterator i = mSerRefCountCreateMap.find(crc);
|
||||
bool bRefCount = true;
|
||||
if (i == mSerRefCountCreateMap.end())
|
||||
{
|
||||
//
|
||||
// maybe it is not refrence counted...
|
||||
//
|
||||
SerMap::iterator si = mSerCreateMap.find( crc );
|
||||
if( si == mSerCreateMap.end() )
|
||||
SerMap::iterator si = mSerCreateMap.find(crc);
|
||||
if (si == mSerCreateMap.end())
|
||||
{
|
||||
d.TraceError("Attempt to serialize unregistered type : %s\n", pObj->GetType().AsString());
|
||||
ThrowAndAssert(eSerializerUnknownType( pObj->GetType().AsString(), mFileName, eSerializer::TY_FILE ));
|
||||
ThrowAndAssert(eSerializerUnknownType(pObj->GetType().AsString(), mFileName, eSerializer::TY_FILE));
|
||||
}
|
||||
bRefCount = false;
|
||||
}
|
||||
|
@ -209,12 +206,12 @@ void cSerializerImpl::WriteObjectDynCreate(const iTypedSerializable* pObj)
|
|||
mpArchive->WriteInt32(pObj->Version());
|
||||
// write a placeholder for the size; we will come back and fill in the right value later...
|
||||
mpArchive->WriteInt32(0xffffffff);
|
||||
|
||||
if(bRefCount)
|
||||
|
||||
if (bRefCount)
|
||||
{
|
||||
// see if the object has already been serialized...
|
||||
int idx;
|
||||
if((idx = mRefCtObjTbl.Lookup(static_cast<const iSerRefCountObj*>(pObj))) == 0)
|
||||
if ((idx = mRefCtObjTbl.Lookup(static_cast<const iSerRefCountObj*>(pObj))) == 0)
|
||||
{
|
||||
// it is not in the table yet; add it and serialize the object
|
||||
idx = mRefCtObjTbl.Add(static_cast<const iSerRefCountObj*>(pObj));
|
||||
|
@ -235,7 +232,6 @@ void cSerializerImpl::WriteObjectDynCreate(const iTypedSerializable* pObj)
|
|||
mpArchive->WriteInt32(0);
|
||||
// ... then write the object.
|
||||
pObj->Write(this);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -247,7 +243,7 @@ iTypedSerializable* cSerializerImpl::ReadObjectDynCreate()
|
|||
cDebug d("cSerializerImpl::ReadObjectDynCreate");
|
||||
//d.TraceDetail("Entering... archive offset = %d\n", mpArchive->CurrentPos());
|
||||
|
||||
int32 size, objIdx;
|
||||
int32 size, objIdx;
|
||||
uint32 crc;
|
||||
// first, get the type...
|
||||
mpArchive->ReadInt32(reinterpret_cast<int32&>(crc));
|
||||
|
@ -263,21 +259,21 @@ iTypedSerializable* cSerializerImpl::ReadObjectDynCreate()
|
|||
//int64 sizePos = mpArchive->CurrentPos();
|
||||
|
||||
mpArchive->ReadInt32(objIdx);
|
||||
if(objIdx == 0)
|
||||
if (objIdx == 0)
|
||||
{
|
||||
// the object is not reference counted; create and read in the object
|
||||
// first, we need to create the object.
|
||||
SerMap::iterator si;
|
||||
si = mSerCreateMap.find(crc);
|
||||
if(si == mSerCreateMap.end())
|
||||
if (si == mSerCreateMap.end())
|
||||
{
|
||||
// unable to find the creation function...
|
||||
d.TraceError("Unable to find creation function for non-ref counted object %d\n", crc);
|
||||
TOSTRINGSTREAM str;
|
||||
#ifdef DEBUG
|
||||
#ifdef DEBUG
|
||||
// Let's only report the actual crc in debug mode
|
||||
str << (int32)crc << std::ends;
|
||||
#endif
|
||||
#endif
|
||||
ThrowAndAssert(eSerializerUnknownType(str.str(), mFileName, eSerializer::TY_FILE));
|
||||
}
|
||||
iTypedSerializable* pObj = ((*si).second)();
|
||||
|
@ -286,7 +282,7 @@ iTypedSerializable* cSerializerImpl::ReadObjectDynCreate()
|
|||
|
||||
// seek past this object in case filepos is not correct!
|
||||
//mpArchive->Seek(sizePos + size, cBidirArchive::BEGINNING);
|
||||
|
||||
|
||||
return pObj;
|
||||
}
|
||||
else
|
||||
|
@ -294,12 +290,12 @@ iTypedSerializable* cSerializerImpl::ReadObjectDynCreate()
|
|||
// refrence counted...
|
||||
iSerRefCountObj* pObj;
|
||||
pObj = mRefCtObjTbl.Lookup(objIdx);
|
||||
if(pObj == NULL)
|
||||
if (pObj == NULL)
|
||||
{
|
||||
// not in table yet...first find the creation function
|
||||
SerRefCountMap::iterator rci;
|
||||
rci = mSerRefCountCreateMap.find(crc);
|
||||
if(rci == mSerRefCountCreateMap.end())
|
||||
if (rci == mSerRefCountCreateMap.end())
|
||||
{
|
||||
// unable to find the creation function...
|
||||
d.TraceError("Unable to find creation function for ref counted object %d\n", crc);
|
||||
|
@ -311,7 +307,7 @@ iTypedSerializable* cSerializerImpl::ReadObjectDynCreate()
|
|||
d.TraceDetail("Creating Ref-Coutnted object [%d] %s(%p)\n", objIdx, pObj->GetType().AsString(), pObj);
|
||||
pObj->Read(this);
|
||||
mRefCtObjTbl.Add(pObj, objIdx);
|
||||
|
||||
|
||||
// seek past this object in case filepos is not correct!
|
||||
//mpArchive->Seek(sizePos + size, cBidirArchive::BEGINNING);
|
||||
|
||||
|
@ -320,10 +316,13 @@ iTypedSerializable* cSerializerImpl::ReadObjectDynCreate()
|
|||
else
|
||||
{
|
||||
// already serialized; just return this object.
|
||||
d.TraceDetail("Adding refrence to previously serialized object [%d] %s(%p)\n", objIdx, pObj->GetType().AsString(), pObj);
|
||||
d.TraceDetail("Adding refrence to previously serialized object [%d] %s(%p)\n",
|
||||
objIdx,
|
||||
pObj->GetType().AsString(),
|
||||
pObj);
|
||||
pObj->AddRef();
|
||||
}
|
||||
|
||||
|
||||
// seek past this object in case filepos is not correct!
|
||||
//mpArchive->Seek(sizePos + size, cBidirArchive::BEGINNING);
|
||||
|
||||
|
@ -349,12 +348,12 @@ void cSerializerImpl::WriteObject(const iTypedSerializable* pObj)
|
|||
// data the object data
|
||||
ASSERT(mpArchive != 0);
|
||||
|
||||
|
||||
|
||||
// 5Nov 98 mdb -- I am removing the read and write of type info for this method; it is never used, since
|
||||
// the object is already created when ReadObject() happens. The only good it might serve is in asserting that
|
||||
// the input stream is valid, but I can do that with the 0xffffffff size below (asserting that it is the same
|
||||
// when it is read back in)
|
||||
/* int i = 0;
|
||||
/* int i = 0;
|
||||
for(; i < mTypeArray.size(); i++)
|
||||
{
|
||||
if(pObj->GetType() == *mTypeArray[i])
|
||||
|
@ -373,13 +372,13 @@ void cSerializerImpl::WriteObject(const iTypedSerializable* pObj)
|
|||
mpArchive->WriteInt32(i);
|
||||
*/
|
||||
|
||||
mpArchive->WriteInt32(0); // place holder for type array index
|
||||
mpArchive->WriteInt32(0); // place holder for type array index
|
||||
mpArchive->WriteInt32(pObj->Version());
|
||||
// write a placeholder for the size; we will come back and fill in the right value later...
|
||||
//int64 sizePos = mpArchive->CurrentPos();
|
||||
mpArchive->WriteInt32(0xffffffff);
|
||||
|
||||
// write out the object!
|
||||
|
||||
// write out the object!
|
||||
pObj->Write(this);
|
||||
|
||||
// finally, we need to go back and patch up the size...
|
||||
|
@ -395,7 +394,7 @@ void cSerializerImpl::ReadObject(iTypedSerializable* pObj)
|
|||
//d.TraceDetail("Entering... archive offset = %d\n", mpArchive->CurrentPos());
|
||||
|
||||
// NOTE -- type index stuff is gone; see the comment in WriteObject()
|
||||
int32 /*typeIdx,*/ size;
|
||||
int32 /*typeIdx,*/ size;
|
||||
// first, get the type...
|
||||
/*
|
||||
mpArchive->ReadInt32(typeIdx);
|
||||
|
@ -410,14 +409,14 @@ void cSerializerImpl::ReadObject(iTypedSerializable* pObj)
|
|||
|
||||
// read in the version
|
||||
int32 dummy, version;
|
||||
mpArchive->ReadInt32(dummy); // old type array index
|
||||
mpArchive->ReadInt32(dummy); // old type array index
|
||||
mpArchive->ReadInt32(version);
|
||||
|
||||
// read in the size and the index...
|
||||
mpArchive->ReadInt32(size);
|
||||
|
||||
// use the size to assert that the file format is correct
|
||||
if(size != (int)0xffffffff)
|
||||
if (size != (int)0xffffffff)
|
||||
{
|
||||
// unknown type index!
|
||||
d.TraceError("Encountered bad size: %d\n", size);
|
||||
|
@ -493,6 +492,5 @@ void cSerializerImpl::WriteBlob(const void* pBlob, int count)
|
|||
///////////////////////////////////////////////////////////////////////////////
|
||||
TSTRING cSerializerImpl::GetFileName() const
|
||||
{
|
||||
return mFileName;
|
||||
return mFileName;
|
||||
}
|
||||
|
||||
|
|
|
@ -3,29 +3,29 @@
|
|||
// Portions created by Tripwire, Inc. are copyright (C) 2000-2018 Tripwire,
|
||||
// Inc. Tripwire is a registered trademark of Tripwire, Inc. All rights
|
||||
// reserved.
|
||||
//
|
||||
//
|
||||
// This program is free software. The contents of this file are subject
|
||||
// to the terms of the GNU General Public License as published by the
|
||||
// Free Software Foundation; either version 2 of the License, or (at your
|
||||
// option) any later version. You may redistribute it and/or modify it
|
||||
// only in compliance with the GNU General Public License.
|
||||
//
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful.
|
||||
// However, this program is distributed AS-IS WITHOUT ANY
|
||||
// WARRANTY; INCLUDING THE IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS
|
||||
// FOR A PARTICULAR PURPOSE. Please see the GNU General Public License
|
||||
// for more details.
|
||||
//
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
|
||||
// USA.
|
||||
//
|
||||
//
|
||||
// Nothing in the GNU General Public License or any other license to use
|
||||
// the code or files shall permit you to use Tripwire's trademarks,
|
||||
// service marks, or other intellectual property without Tripwire's
|
||||
// prior written consent.
|
||||
//
|
||||
//
|
||||
// If you have any questions, please contact Tripwire, Inc. at either
|
||||
// info@tripwire.org or www.tripwire.org.
|
||||
//
|
||||
|
@ -60,75 +60,76 @@ class cArchive;
|
|||
class cSerializerImpl : public iSerializer
|
||||
{
|
||||
public:
|
||||
enum Mode { S_READ, S_WRITE };
|
||||
cSerializerImpl (cArchive& archive, Mode action, const TSTRING& fileName = _T("") );
|
||||
// fileName is only used for error reporting purposes
|
||||
enum Mode
|
||||
{
|
||||
S_READ,
|
||||
S_WRITE
|
||||
};
|
||||
cSerializerImpl(cArchive& archive, Mode action, const TSTRING& fileName = _T(""));
|
||||
// fileName is only used for error reporting purposes
|
||||
virtual ~cSerializerImpl();
|
||||
|
||||
bool IsWriting() const;
|
||||
bool IsWriting() const;
|
||||
|
||||
// Initializing and closing the archive
|
||||
virtual void Init(); // throw eSerializer
|
||||
virtual void Init(); // throw eSerializer
|
||||
// initializes the serializer; must be called before any reading or writing is done
|
||||
virtual void Finit();
|
||||
// called after a session of serialization is done; called implicitely by the destructor
|
||||
// if not called explicitely before destruction
|
||||
// called after a session of serialization is done; called implicitely by the destructor
|
||||
// if not called explicitely before destruction
|
||||
|
||||
//Reading and writing objects Init() should have already been called or all these will fail.
|
||||
virtual void WriteObjectDynCreate(const iTypedSerializable* pObj); // throw (eSerializer, eArchive)
|
||||
// writes an object such that it can be dynamically created when read back in with
|
||||
// ReadObject.
|
||||
virtual iTypedSerializable* ReadObjectDynCreate(); // throw (eSerializer, eArchive);
|
||||
virtual void WriteObjectDynCreate(const iTypedSerializable* pObj); // throw (eSerializer, eArchive)
|
||||
// writes an object such that it can be dynamically created when read back in with
|
||||
// ReadObject.
|
||||
virtual iTypedSerializable* ReadObjectDynCreate(); // throw (eSerializer, eArchive);
|
||||
// reads an object from the archive, returning a pointer to it. The caller is responsible for
|
||||
// deleteing or Release()ing it when done.
|
||||
virtual void WriteObject(const iTypedSerializable* pObj); // throw (eSerializer, eArchive)
|
||||
virtual void WriteObject(const iTypedSerializable* pObj); // throw (eSerializer, eArchive)
|
||||
// writes an object to the archive that will not be dynamically created
|
||||
virtual void ReadObject(iTypedSerializable* pObj); // throw (eSerializer, eArchive)
|
||||
virtual void ReadObject(iTypedSerializable* pObj); // throw (eSerializer, eArchive)
|
||||
// reads an object that was written with WriteObject()
|
||||
|
||||
// members for registering classes to be serialized. One of these must be called exactly once
|
||||
// for each class that is to be serialized.
|
||||
static void RegisterSerializable (const cType& type, iTypedSerializable::CreateFunc pFunc);
|
||||
static void RegisterSerializableRefCt (const cType& type, iSerRefCountObj::CreateFunc pFunc);
|
||||
static void RegisterSerializable(const cType& type, iTypedSerializable::CreateFunc pFunc);
|
||||
static void RegisterSerializableRefCt(const cType& type, iSerRefCountObj::CreateFunc pFunc);
|
||||
|
||||
// writing interface
|
||||
// TODO -- I am not sure if I want to keep these or just have the serializer expose the archive. Actually,
|
||||
// writing interface
|
||||
// TODO -- I am not sure if I want to keep these or just have the serializer expose the archive. Actually,
|
||||
// I think the best thing might be to have iSerializable only know about the archive
|
||||
// Standard data read/write
|
||||
// (All functions can throw eArchave exceptions).
|
||||
virtual void ReadInt16(int16& ret);
|
||||
virtual void ReadInt32(int32& ret);
|
||||
virtual void ReadInt64(int64& ret);
|
||||
virtual void ReadString(TSTRING& ret);
|
||||
virtual int ReadBlob(void* pBlob, int count);
|
||||
virtual void WriteInt16(int16 i);
|
||||
virtual void WriteInt32(int32 i);
|
||||
virtual void WriteInt64(int64 i);
|
||||
virtual void WriteString(const TSTRING& s);
|
||||
virtual void WriteBlob(const void* pBlob, int count);
|
||||
virtual void ReadInt16(int16& ret);
|
||||
virtual void ReadInt32(int32& ret);
|
||||
virtual void ReadInt64(int64& ret);
|
||||
virtual void ReadString(TSTRING& ret);
|
||||
virtual int ReadBlob(void* pBlob, int count);
|
||||
virtual void WriteInt16(int16 i);
|
||||
virtual void WriteInt32(int32 i);
|
||||
virtual void WriteInt64(int64 i);
|
||||
virtual void WriteString(const TSTRING& s);
|
||||
virtual void WriteBlob(const void* pBlob, int count);
|
||||
|
||||
virtual TSTRING GetFileName() const;
|
||||
|
||||
private:
|
||||
cArchive* mpArchive; // the archive we are serializing to
|
||||
Mode mMode; // are we writing or reading?
|
||||
bool mbInit; // has init been called?
|
||||
cSerRefCountTable mRefCtObjTbl; // keeps track of all ref counted objects that
|
||||
// have been read or written during serialization
|
||||
TSTRING mFileName;
|
||||
cArchive* mpArchive; // the archive we are serializing to
|
||||
Mode mMode; // are we writing or reading?
|
||||
bool mbInit; // has init been called?
|
||||
cSerRefCountTable mRefCtObjTbl; // keeps track of all ref counted objects that
|
||||
// have been read or written during serialization
|
||||
TSTRING mFileName;
|
||||
|
||||
// creation function maps
|
||||
typedef std::map<uint32, iTypedSerializable::CreateFunc> SerMap;
|
||||
typedef std::map<uint32, iSerRefCountObj::CreateFunc> SerRefCountMap;
|
||||
static SerMap mSerCreateMap;
|
||||
static SerRefCountMap mSerRefCountCreateMap;
|
||||
typedef std::map<uint32, iTypedSerializable::CreateFunc> SerMap;
|
||||
typedef std::map<uint32, iSerRefCountObj::CreateFunc> SerRefCountMap;
|
||||
static SerMap mSerCreateMap;
|
||||
static SerRefCountMap mSerRefCountCreateMap;
|
||||
|
||||
static void InitSerializableMaps();
|
||||
static void FinitSerializableMaps();
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
@ -3,29 +3,29 @@
|
|||
// Portions created by Tripwire, Inc. are copyright (C) 2000-2018 Tripwire,
|
||||
// Inc. Tripwire is a registered trademark of Tripwire, Inc. All rights
|
||||
// reserved.
|
||||
//
|
||||
//
|
||||
// This program is free software. The contents of this file are subject
|
||||
// to the terms of the GNU General Public License as published by the
|
||||
// Free Software Foundation; either version 2 of the License, or (at your
|
||||
// option) any later version. You may redistribute it and/or modify it
|
||||
// only in compliance with the GNU General Public License.
|
||||
//
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful.
|
||||
// However, this program is distributed AS-IS WITHOUT ANY
|
||||
// WARRANTY; INCLUDING THE IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS
|
||||
// FOR A PARTICULAR PURPOSE. Please see the GNU General Public License
|
||||
// for more details.
|
||||
//
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
|
||||
// USA.
|
||||
//
|
||||
//
|
||||
// Nothing in the GNU General Public License or any other license to use
|
||||
// the code or files shall permit you to use Tripwire's trademarks,
|
||||
// service marks, or other intellectual property without Tripwire's
|
||||
// prior written consent.
|
||||
//
|
||||
//
|
||||
// If you have any questions, please contact Tripwire, Inc. at either
|
||||
// info@tripwire.org or www.tripwire.org.
|
||||
//
|
||||
|
@ -35,39 +35,41 @@
|
|||
#include "archive.h"
|
||||
#include "serializer.h"
|
||||
|
||||
namespace {
|
||||
template<class FROM, class TO>
|
||||
int64 CopyImpl(TO* pTo, FROM* pFrom, int64 amt)
|
||||
namespace
|
||||
{
|
||||
enum { BUF_SIZE = 8192 };
|
||||
int8 buf[BUF_SIZE];
|
||||
int64 amtLeft = amt;
|
||||
template<class FROM, class TO> int64 CopyImpl(TO* pTo, FROM* pFrom, int64 amt)
|
||||
{
|
||||
enum
|
||||
{
|
||||
BUF_SIZE = 8192
|
||||
};
|
||||
int8 buf[BUF_SIZE];
|
||||
int64 amtLeft = amt;
|
||||
|
||||
while(amtLeft > 0)
|
||||
while (amtLeft > 0)
|
||||
{
|
||||
// NOTE: We use int's here rather than int64 because iSerializer and cArchive
|
||||
// only take int's as their size parameter - dmb
|
||||
int amtToRead = amtLeft > BUF_SIZE ? BUF_SIZE : (int)amtLeft;
|
||||
int amtRead = pFrom->ReadBlob(buf, amtToRead );
|
||||
int amtRead = pFrom->ReadBlob(buf, amtToRead);
|
||||
amtLeft -= amtRead;
|
||||
pTo->WriteBlob(buf, amtRead);
|
||||
if(amtRead < amtToRead)
|
||||
if (amtRead < amtToRead)
|
||||
break;
|
||||
}
|
||||
|
||||
// return the amount copied ...
|
||||
return (amt - amtLeft);
|
||||
}
|
||||
}
|
||||
} // namespace
|
||||
|
||||
|
||||
int64 cSerializerUtil::Copy( iSerializer* pDest, cArchive* pSrc, int64 amt )
|
||||
int64 cSerializerUtil::Copy(iSerializer* pDest, cArchive* pSrc, int64 amt)
|
||||
{
|
||||
return CopyImpl( pDest, pSrc, amt );
|
||||
return CopyImpl(pDest, pSrc, amt);
|
||||
}
|
||||
|
||||
int64 cSerializerUtil::Copy( cArchive* pDest, iSerializer* pSrc, int64 amt )
|
||||
int64 cSerializerUtil::Copy(cArchive* pDest, iSerializer* pSrc, int64 amt)
|
||||
{
|
||||
return CopyImpl( pDest, pSrc, amt );
|
||||
return CopyImpl(pDest, pSrc, amt);
|
||||
}
|
||||
|
||||
|
|
|
@ -3,29 +3,29 @@
|
|||
// Portions created by Tripwire, Inc. are copyright (C) 2000-2018 Tripwire,
|
||||
// Inc. Tripwire is a registered trademark of Tripwire, Inc. All rights
|
||||
// reserved.
|
||||
//
|
||||
//
|
||||
// This program is free software. The contents of this file are subject
|
||||
// to the terms of the GNU General Public License as published by the
|
||||
// Free Software Foundation; either version 2 of the License, or (at your
|
||||
// option) any later version. You may redistribute it and/or modify it
|
||||
// only in compliance with the GNU General Public License.
|
||||
//
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful.
|
||||
// However, this program is distributed AS-IS WITHOUT ANY
|
||||
// WARRANTY; INCLUDING THE IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS
|
||||
// FOR A PARTICULAR PURPOSE. Please see the GNU General Public License
|
||||
// for more details.
|
||||
//
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
|
||||
// USA.
|
||||
//
|
||||
//
|
||||
// Nothing in the GNU General Public License or any other license to use
|
||||
// the code or files shall permit you to use Tripwire's trademarks,
|
||||
// service marks, or other intellectual property without Tripwire's
|
||||
// prior written consent.
|
||||
//
|
||||
//
|
||||
// If you have any questions, please contact Tripwire, Inc. at either
|
||||
// info@tripwire.org or www.tripwire.org.
|
||||
//
|
||||
|
@ -44,11 +44,10 @@ class iSerializer;
|
|||
class cSerializerUtil
|
||||
{
|
||||
public:
|
||||
static int64 Copy( iSerializer* pDest, cArchive* pSrc, int64 amt ); // throw( eArchvie, eSerilaizer )
|
||||
static int64 Copy( cArchive* pDest, iSerializer* pSrc, int64 amt ); // throw( eArchvie, eSerilaizer )
|
||||
static int64 Copy(iSerializer* pDest, cArchive* pSrc, int64 amt); // throw( eArchvie, eSerilaizer )
|
||||
static int64 Copy(cArchive* pDest, iSerializer* pSrc, int64 amt); // throw( eArchvie, eSerilaizer )
|
||||
// these two methods copy data from archives to serializers and vice-versa. They
|
||||
// throw exceptions on error; the return value is the amount that was copied.
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
@ -3,41 +3,41 @@
|
|||
// Portions created by Tripwire, Inc. are copyright (C) 2000-2018 Tripwire,
|
||||
// Inc. Tripwire is a registered trademark of Tripwire, Inc. All rights
|
||||
// reserved.
|
||||
//
|
||||
//
|
||||
// This program is free software. The contents of this file are subject
|
||||
// to the terms of the GNU General Public License as published by the
|
||||
// Free Software Foundation; either version 2 of the License, or (at your
|
||||
// option) any later version. You may redistribute it and/or modify it
|
||||
// only in compliance with the GNU General Public License.
|
||||
//
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful.
|
||||
// However, this program is distributed AS-IS WITHOUT ANY
|
||||
// WARRANTY; INCLUDING THE IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS
|
||||
// FOR A PARTICULAR PURPOSE. Please see the GNU General Public License
|
||||
// for more details.
|
||||
//
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
|
||||
// USA.
|
||||
//
|
||||
//
|
||||
// Nothing in the GNU General Public License or any other license to use
|
||||
// the code or files shall permit you to use Tripwire's trademarks,
|
||||
// service marks, or other intellectual property without Tripwire's
|
||||
// prior written consent.
|
||||
//
|
||||
//
|
||||
// If you have any questions, please contact Tripwire, Inc. at either
|
||||
// info@tripwire.org or www.tripwire.org.
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// serstring.cpp -- A serializable interface wrapper around a string
|
||||
// serstring.cpp -- A serializable interface wrapper around a string
|
||||
//
|
||||
#include "stdcore.h"
|
||||
#include "serstring.h"
|
||||
|
||||
IMPLEMENT_TYPEDSERIALIZABLE(cSerializableNString, _T("cSerializableNString"), 0, 1)
|
||||
|
||||
void cSerializableNString::Read (iSerializer* pSerializer, int32 version)
|
||||
void cSerializableNString::Read(iSerializer* pSerializer, int32 version)
|
||||
{
|
||||
int32 len;
|
||||
pSerializer->ReadInt32(len);
|
||||
|
@ -55,7 +55,7 @@ void cSerializableNString::Write(iSerializer* pSerializer) const
|
|||
|
||||
IMPLEMENT_TYPEDSERIALIZABLE(cSerializableWString, _T("cSerializableWString"), 0, 1)
|
||||
|
||||
void cSerializableWString::Read (iSerializer* pSerializer, int32 version)
|
||||
void cSerializableWString::Read(iSerializer* pSerializer, int32 version)
|
||||
{
|
||||
int32 len;
|
||||
pSerializer->ReadInt32(len);
|
||||
|
@ -69,4 +69,3 @@ void cSerializableWString::Write(iSerializer* pSerializer) const
|
|||
pSerializer->WriteInt32(len);
|
||||
pSerializer->WriteBlob(mString.data(), len);
|
||||
}
|
||||
|
||||
|
|
|
@ -3,39 +3,39 @@
|
|||
// Portions created by Tripwire, Inc. are copyright (C) 2000-2018 Tripwire,
|
||||
// Inc. Tripwire is a registered trademark of Tripwire, Inc. All rights
|
||||
// reserved.
|
||||
//
|
||||
//
|
||||
// This program is free software. The contents of this file are subject
|
||||
// to the terms of the GNU General Public License as published by the
|
||||
// Free Software Foundation; either version 2 of the License, or (at your
|
||||
// option) any later version. You may redistribute it and/or modify it
|
||||
// only in compliance with the GNU General Public License.
|
||||
//
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful.
|
||||
// However, this program is distributed AS-IS WITHOUT ANY
|
||||
// WARRANTY; INCLUDING THE IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS
|
||||
// FOR A PARTICULAR PURPOSE. Please see the GNU General Public License
|
||||
// for more details.
|
||||
//
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
|
||||
// USA.
|
||||
//
|
||||
//
|
||||
// Nothing in the GNU General Public License or any other license to use
|
||||
// the code or files shall permit you to use Tripwire's trademarks,
|
||||
// service marks, or other intellectual property without Tripwire's
|
||||
// prior written consent.
|
||||
//
|
||||
//
|
||||
// If you have any questions, please contact Tripwire, Inc. at either
|
||||
// info@tripwire.org or www.tripwire.org.
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// serstring.h -- A serializable interface wrapper around a string
|
||||
// serstring.h -- A serializable interface wrapper around a string
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef __SERSTRING_H
|
||||
#define __SERSTRING_H
|
||||
|
||||
|
||||
#ifndef __SERIALIZABLE_H
|
||||
#include "serializable.h"
|
||||
#endif
|
||||
|
@ -55,9 +55,9 @@ class cSerializableNString : public iTypedSerializable
|
|||
{
|
||||
public:
|
||||
std::string mString;
|
||||
|
||||
virtual ~cSerializableNString() {};
|
||||
virtual void Read (iSerializer* pSerializer, int32 version = 0); // throw (eSerializer, eArchive)
|
||||
|
||||
virtual ~cSerializableNString(){};
|
||||
virtual void Read(iSerializer* pSerializer, int32 version = 0); // throw (eSerializer, eArchive)
|
||||
virtual void Write(iSerializer* pSerializer) const; // throw (eSerializer, eArchive)
|
||||
|
||||
DECLARE_TYPEDSERIALIZABLE()
|
||||
|
@ -70,15 +70,14 @@ class cSerializableWString : public iTypedSerializable
|
|||
{
|
||||
public:
|
||||
std::string mString;
|
||||
|
||||
virtual ~cSerializableWString() {};
|
||||
virtual void Read (iSerializer* pSerializer, int32 version = 0); // throw (eSerializer, eArchive)
|
||||
|
||||
virtual ~cSerializableWString(){};
|
||||
virtual void Read(iSerializer* pSerializer, int32 version = 0); // throw (eSerializer, eArchive)
|
||||
virtual void Write(iSerializer* pSerializer) const; // throw (eSerializer, eArchive)
|
||||
|
||||
DECLARE_TYPEDSERIALIZABLE()
|
||||
};
|
||||
|
||||
typedef cSerializableNString cSerializableTSTRING;
|
||||
|
||||
#endif
|
||||
typedef cSerializableNString cSerializableTSTRING;
|
||||
|
||||
#endif
|
||||
|
|
|
@ -3,29 +3,29 @@
|
|||
// Portions created by Tripwire, Inc. are copyright (C) 2000-2018 Tripwire,
|
||||
// Inc. Tripwire is a registered trademark of Tripwire, Inc. All rights
|
||||
// reserved.
|
||||
//
|
||||
//
|
||||
// This program is free software. The contents of this file are subject
|
||||
// to the terms of the GNU General Public License as published by the
|
||||
// Free Software Foundation; either version 2 of the License, or (at your
|
||||
// option) any later version. You may redistribute it and/or modify it
|
||||
// only in compliance with the GNU General Public License.
|
||||
//
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful.
|
||||
// However, this program is distributed AS-IS WITHOUT ANY
|
||||
// WARRANTY; INCLUDING THE IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS
|
||||
// FOR A PARTICULAR PURPOSE. Please see the GNU General Public License
|
||||
// for more details.
|
||||
//
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
|
||||
// USA.
|
||||
//
|
||||
//
|
||||
// Nothing in the GNU General Public License or any other license to use
|
||||
// the code or files shall permit you to use Tripwire's trademarks,
|
||||
// service marks, or other intellectual property without Tripwire's
|
||||
// prior written consent.
|
||||
//
|
||||
//
|
||||
// If you have any questions, please contact Tripwire, Inc. at either
|
||||
// info@tripwire.org or www.tripwire.org.
|
||||
//
|
||||
|
@ -36,10 +36,9 @@
|
|||
#include "srefcountobj.h"
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// class cSerializableRefCountObj
|
||||
// class cSerializableRefCountObj
|
||||
//
|
||||
|
||||
iSerRefCountObj::~iSerRefCountObj()
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
@ -3,29 +3,29 @@
|
|||
// Portions created by Tripwire, Inc. are copyright (C) 2000-2018 Tripwire,
|
||||
// Inc. Tripwire is a registered trademark of Tripwire, Inc. All rights
|
||||
// reserved.
|
||||
//
|
||||
//
|
||||
// This program is free software. The contents of this file are subject
|
||||
// to the terms of the GNU General Public License as published by the
|
||||
// Free Software Foundation; either version 2 of the License, or (at your
|
||||
// option) any later version. You may redistribute it and/or modify it
|
||||
// only in compliance with the GNU General Public License.
|
||||
//
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful.
|
||||
// However, this program is distributed AS-IS WITHOUT ANY
|
||||
// WARRANTY; INCLUDING THE IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS
|
||||
// FOR A PARTICULAR PURPOSE. Please see the GNU General Public License
|
||||
// for more details.
|
||||
//
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
|
||||
// USA.
|
||||
//
|
||||
//
|
||||
// Nothing in the GNU General Public License or any other license to use
|
||||
// the code or files shall permit you to use Tripwire's trademarks,
|
||||
// service marks, or other intellectual property without Tripwire's
|
||||
// prior written consent.
|
||||
//
|
||||
//
|
||||
// If you have any questions, please contact Tripwire, Inc. at either
|
||||
// info@tripwire.org or www.tripwire.org.
|
||||
//
|
||||
|
@ -49,7 +49,7 @@
|
|||
#endif
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// class cSerializableRefCountObj
|
||||
// class cSerializableRefCountObj
|
||||
//
|
||||
class iSerRefCountObj : public cRefCountObj, public iTypedSerializable
|
||||
{
|
||||
|
@ -59,28 +59,26 @@ public:
|
|||
|
||||
protected:
|
||||
virtual ~iSerRefCountObj();
|
||||
|
||||
};
|
||||
|
||||
//////////////////////////////
|
||||
// convenience macros
|
||||
#define DECLARE_SERREFCOUNT() \
|
||||
DECLARE_TYPED() \
|
||||
public: \
|
||||
static iSerRefCountObj* Create(); \
|
||||
virtual int32 Version() const;
|
||||
# define DECLARE_SERREFCOUNT() \
|
||||
DECLARE_TYPED() \
|
||||
public: \
|
||||
static iSerRefCountObj* Create(); \
|
||||
virtual int32 Version() const;
|
||||
|
||||
#define IMPLEMENT_SERREFCOUNT(CLASS, TYPEDSTRING, VERSION_MAJOR, VERSION_MINOR) \
|
||||
IMPLEMENT_TYPED(CLASS, TYPEDSTRING) \
|
||||
iSerRefCountObj* CLASS::Create() \
|
||||
{ \
|
||||
return new CLASS; \
|
||||
} \
|
||||
int32 CLASS::Version() const \
|
||||
{ \
|
||||
return iTypedSerializable::MkVersion(VERSION_MAJOR, VERSION_MINOR); \
|
||||
}
|
||||
# define IMPLEMENT_SERREFCOUNT(CLASS, TYPEDSTRING, VERSION_MAJOR, VERSION_MINOR) \
|
||||
IMPLEMENT_TYPED(CLASS, TYPEDSTRING) \
|
||||
iSerRefCountObj* CLASS::Create() \
|
||||
{ \
|
||||
return new CLASS; \
|
||||
} \
|
||||
int32 CLASS::Version() const \
|
||||
{ \
|
||||
return iTypedSerializable::MkVersion(VERSION_MAJOR, VERSION_MINOR); \
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
@ -3,29 +3,29 @@
|
|||
// Portions created by Tripwire, Inc. are copyright (C) 2000-2018 Tripwire,
|
||||
// Inc. Tripwire is a registered trademark of Tripwire, Inc. All rights
|
||||
// reserved.
|
||||
//
|
||||
//
|
||||
// This program is free software. The contents of this file are subject
|
||||
// to the terms of the GNU General Public License as published by the
|
||||
// Free Software Foundation; either version 2 of the License, or (at your
|
||||
// option) any later version. You may redistribute it and/or modify it
|
||||
// only in compliance with the GNU General Public License.
|
||||
//
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful.
|
||||
// However, this program is distributed AS-IS WITHOUT ANY
|
||||
// WARRANTY; INCLUDING THE IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS
|
||||
// FOR A PARTICULAR PURPOSE. Please see the GNU General Public License
|
||||
// for more details.
|
||||
//
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
|
||||
// USA.
|
||||
//
|
||||
//
|
||||
// Nothing in the GNU General Public License or any other license to use
|
||||
// the code or files shall permit you to use Tripwire's trademarks,
|
||||
// service marks, or other intellectual property without Tripwire's
|
||||
// prior written consent.
|
||||
//
|
||||
//
|
||||
// If you have any questions, please contact Tripwire, Inc. at either
|
||||
// info@tripwire.org or www.tripwire.org.
|
||||
//
|
||||
|
@ -79,8 +79,8 @@ iSerRefCountObj* cSerRefCountTable::Lookup(int id)
|
|||
return itr == mIDToObjTbl.end() ? NULL : itr->second;
|
||||
}
|
||||
|
||||
// Add an object to the table, optionally specifying an ID. Returns a
|
||||
// unique ID for the object. ASSERTs and throws exception if object is
|
||||
// Add an object to the table, optionally specifying an ID. Returns a
|
||||
// unique ID for the object. ASSERTs and throws exception if object is
|
||||
// already in table or the ID is already taken.
|
||||
int cSerRefCountTable::Add(iSerRefCountObj* pObj, int id)
|
||||
{
|
||||
|
@ -100,8 +100,8 @@ int cSerRefCountTable::Add(iSerRefCountObj* pObj, int id)
|
|||
ThrowAndAssert(eInternal(_T("cSerRefCountTable::Add() passed ID already in table.")));
|
||||
}
|
||||
|
||||
mIDToObjTbl.insert( MapIDTObj::value_type(id, pObj));
|
||||
mObjToIdTbl.insert( MapObjIDT::value_type(pObj, id));
|
||||
mIDToObjTbl.insert(MapIDTObj::value_type(id, pObj));
|
||||
mObjToIdTbl.insert(MapObjIDT::value_type(pObj, id));
|
||||
|
||||
return id;
|
||||
}
|
||||
|
@ -154,4 +154,3 @@ cSerRefCountTableMap::~cSerRefCountTableMap()
|
|||
}
|
||||
}
|
||||
*/
|
||||
|
||||
|
|
|
@ -3,29 +3,29 @@
|
|||
// Portions created by Tripwire, Inc. are copyright (C) 2000-2018 Tripwire,
|
||||
// Inc. Tripwire is a registered trademark of Tripwire, Inc. All rights
|
||||
// reserved.
|
||||
//
|
||||
//
|
||||
// This program is free software. The contents of this file are subject
|
||||
// to the terms of the GNU General Public License as published by the
|
||||
// Free Software Foundation; either version 2 of the License, or (at your
|
||||
// option) any later version. You may redistribute it and/or modify it
|
||||
// only in compliance with the GNU General Public License.
|
||||
//
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful.
|
||||
// However, this program is distributed AS-IS WITHOUT ANY
|
||||
// WARRANTY; INCLUDING THE IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS
|
||||
// FOR A PARTICULAR PURPOSE. Please see the GNU General Public License
|
||||
// for more details.
|
||||
//
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
|
||||
// USA.
|
||||
//
|
||||
//
|
||||
// Nothing in the GNU General Public License or any other license to use
|
||||
// the code or files shall permit you to use Tripwire's trademarks,
|
||||
// service marks, or other intellectual property without Tripwire's
|
||||
// prior written consent.
|
||||
//
|
||||
//
|
||||
// If you have any questions, please contact Tripwire, Inc. at either
|
||||
// info@tripwire.org or www.tripwire.org.
|
||||
//
|
||||
|
@ -51,16 +51,16 @@ public:
|
|||
// find object for specified id. returns NULL if not in table
|
||||
iSerRefCountObj* Lookup(int id);
|
||||
|
||||
// Add an object to the table, optionally specifying an ID. Returns a
|
||||
// unique ID for the object. ASSERTs and throws exception if object is
|
||||
// Add an object to the table, optionally specifying an ID. Returns a
|
||||
// unique ID for the object. ASSERTs and throws exception if object is
|
||||
// already in table or the ID is already taken.
|
||||
int Add( iSerRefCountObj* pObj, int id = 0);
|
||||
int Add(const iSerRefCountObj* pObj, int id = 0);
|
||||
// TODO -- Note that this class is not really const-correct in that the const version of
|
||||
// Add() just casts away the constness. The right thing to do is to make the serializer
|
||||
// use different versions of this class (const and non-const) depending on whether it is
|
||||
// reading or writing and (maybe?) make this class a template class so that it can map
|
||||
// to either const or non-const objects.
|
||||
int Add(iSerRefCountObj* pObj, int id = 0);
|
||||
int Add(const iSerRefCountObj* pObj, int id = 0);
|
||||
// TODO -- Note that this class is not really const-correct in that the const version of
|
||||
// Add() just casts away the constness. The right thing to do is to make the serializer
|
||||
// use different versions of this class (const and non-const) depending on whether it is
|
||||
// reading or writing and (maybe?) make this class a template class so that it can map
|
||||
// to either const or non-const objects.
|
||||
|
||||
|
||||
// clears out the table
|
||||
|
@ -89,4 +89,3 @@ public:
|
|||
};
|
||||
*/
|
||||
#endif
|
||||
|
||||
|
|
|
@ -3,29 +3,29 @@
|
|||
// Portions created by Tripwire, Inc. are copyright (C) 2000-2018 Tripwire,
|
||||
// Inc. Tripwire is a registered trademark of Tripwire, Inc. All rights
|
||||
// reserved.
|
||||
//
|
||||
//
|
||||
// This program is free software. The contents of this file are subject
|
||||
// to the terms of the GNU General Public License as published by the
|
||||
// Free Software Foundation; either version 2 of the License, or (at your
|
||||
// option) any later version. You may redistribute it and/or modify it
|
||||
// only in compliance with the GNU General Public License.
|
||||
//
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful.
|
||||
// However, this program is distributed AS-IS WITHOUT ANY
|
||||
// WARRANTY; INCLUDING THE IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS
|
||||
// FOR A PARTICULAR PURPOSE. Please see the GNU General Public License
|
||||
// for more details.
|
||||
//
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
|
||||
// USA.
|
||||
//
|
||||
//
|
||||
// Nothing in the GNU General Public License or any other license to use
|
||||
// the code or files shall permit you to use Tripwire's trademarks,
|
||||
// service marks, or other intellectual property without Tripwire's
|
||||
// prior written consent.
|
||||
//
|
||||
//
|
||||
// If you have any questions, please contact Tripwire, Inc. at either
|
||||
// info@tripwire.org or www.tripwire.org.
|
||||
//
|
||||
|
@ -36,5 +36,3 @@
|
|||
//
|
||||
|
||||
#include "stdcore.h"
|
||||
|
||||
|
||||
|
|
|
@ -3,29 +3,29 @@
|
|||
// Portions created by Tripwire, Inc. are copyright (C) 2000-2018 Tripwire,
|
||||
// Inc. Tripwire is a registered trademark of Tripwire, Inc. All rights
|
||||
// reserved.
|
||||
//
|
||||
//
|
||||
// This program is free software. The contents of this file are subject
|
||||
// to the terms of the GNU General Public License as published by the
|
||||
// Free Software Foundation; either version 2 of the License, or (at your
|
||||
// option) any later version. You may redistribute it and/or modify it
|
||||
// only in compliance with the GNU General Public License.
|
||||
//
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful.
|
||||
// However, this program is distributed AS-IS WITHOUT ANY
|
||||
// WARRANTY; INCLUDING THE IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS
|
||||
// FOR A PARTICULAR PURPOSE. Please see the GNU General Public License
|
||||
// for more details.
|
||||
//
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
|
||||
// USA.
|
||||
//
|
||||
//
|
||||
// Nothing in the GNU General Public License or any other license to use
|
||||
// the code or files shall permit you to use Tripwire's trademarks,
|
||||
// service marks, or other intellectual property without Tripwire's
|
||||
// prior written consent.
|
||||
//
|
||||
//
|
||||
// If you have any questions, please contact Tripwire, Inc. at either
|
||||
// info@tripwire.org or www.tripwire.org.
|
||||
//
|
||||
|
@ -48,43 +48,43 @@
|
|||
//--Disable some level 4 warnings
|
||||
|
||||
#if IS_MSVC
|
||||
|
||||
#define NOMINMAX //--Disable min/max macros
|
||||
|
||||
#include <xstddef> // ARGH!! This resumes certain warnings!
|
||||
# define NOMINMAX //--Disable min/max macros
|
||||
|
||||
#pragma warning( disable: 4786 ) // Token Name > 255
|
||||
#pragma warning( disable: 4127 ) // constant expression (e.g. ASSERT)
|
||||
#pragma warning( disable: 4291 ) // Incorrectly called when new(nothrow)!!!
|
||||
#pragma warning( disable: 4097 ) // Type synonyms are good!
|
||||
#pragma warning( disable: 4511 ) // Can't create copy ctor! (e.g.Private CTOR)
|
||||
#pragma warning( disable: 4512 ) // Can't create assignment!(e.g.Private CTOR)
|
||||
#pragma warning( disable: 4100 ) // Formal argument not used
|
||||
#pragma warning( disable: 4710 ) // Compiler did not inline function
|
||||
#include <xstddef> // ARGH!! This resumes certain warnings!
|
||||
|
||||
#ifndef DEBUG // ASSERT's are disabled give a lot of these
|
||||
#pragma warning( disable: 4702 ) // ---Unreachable Code
|
||||
#endif
|
||||
# pragma warning(disable : 4786) // Token Name > 255
|
||||
# pragma warning(disable : 4127) // constant expression (e.g. ASSERT)
|
||||
# pragma warning(disable : 4291) // Incorrectly called when new(nothrow)!!!
|
||||
# pragma warning(disable : 4097) // Type synonyms are good!
|
||||
# pragma warning(disable : 4511) // Can't create copy ctor! (e.g.Private CTOR)
|
||||
# pragma warning(disable : 4512) // Can't create assignment!(e.g.Private CTOR)
|
||||
# pragma warning(disable : 4100) // Formal argument not used
|
||||
# pragma warning(disable : 4710) // Compiler did not inline function
|
||||
|
||||
/* NOTE:RAD:05/09/1999 -- Plaguers STDCPP implementation is SOOO bad
|
||||
# ifndef DEBUG // ASSERT's are disabled give a lot of these
|
||||
# pragma warning(disable : 4702) // ---Unreachable Code
|
||||
# endif
|
||||
|
||||
/* NOTE:RAD:05/09/1999 -- Plaguers STDCPP implementation is SOOO bad
|
||||
it creates all these errors when compiling at W4. By doing a push
|
||||
before disabling them, we can still generate them for ourselves
|
||||
without a lot of noise. The warnings before this push, we want to
|
||||
always disable. */
|
||||
|
||||
#pragma warning( push )
|
||||
# pragma warning(push)
|
||||
|
||||
#pragma warning( disable: 4663 ) // Old template specialization syntax
|
||||
#pragma warning( disable: 4018 ) // Signed unsigned mismatch
|
||||
#pragma warning( disable: 4245 ) // Signed unsigned mismatch
|
||||
#pragma warning( disable: 4663 ) // Use new template specialization syntax: template<>
|
||||
#pragma warning( disable: 4701 ) // local variable 'X' may be used without having been initialized
|
||||
#pragma warning( disable: 4510 ) // 'X' : default constructor could not be generated
|
||||
#pragma warning( disable: 4610 ) // struct 'X' can never be instantiated - user defined constructor required
|
||||
#pragma warning( disable: 4146 ) // unary minus operator applied to unsigned type, result still unsigned
|
||||
#pragma warning( disable: 4244 ) // '=' : conversion from 'unsigned int' to 'char', possible loss of data
|
||||
#pragma warning( disable: 4511 )
|
||||
#pragma warning( disable: 4503 )
|
||||
# pragma warning(disable : 4663) // Old template specialization syntax
|
||||
# pragma warning(disable : 4018) // Signed unsigned mismatch
|
||||
# pragma warning(disable : 4245) // Signed unsigned mismatch
|
||||
# pragma warning(disable : 4663) // Use new template specialization syntax: template<>
|
||||
# pragma warning(disable : 4701) // local variable 'X' may be used without having been initialized
|
||||
# pragma warning(disable : 4510) // 'X' : default constructor could not be generated
|
||||
# pragma warning(disable : 4610) // struct 'X' can never be instantiated - user defined constructor required
|
||||
# pragma warning(disable : 4146) // unary minus operator applied to unsigned type, result still unsigned
|
||||
# pragma warning(disable : 4244) // '=' : conversion from 'unsigned int' to 'char', possible loss of data
|
||||
# pragma warning(disable : 4511)
|
||||
# pragma warning(disable : 4503)
|
||||
|
||||
#endif // #if IS_MSVC
|
||||
|
||||
|
@ -108,13 +108,12 @@
|
|||
#include <limits>
|
||||
|
||||
#if IS_MSVC
|
||||
#pragma warning( pop ) // Resume W4 msgs for TSS code
|
||||
# pragma warning(pop) // Resume W4 msgs for TSS code
|
||||
#endif
|
||||
|
||||
//--Include Platform Specific Declarations
|
||||
|
||||
|
||||
|
||||
//--Include Common Core Declarations
|
||||
|
||||
#include "./tchar.h"
|
||||
|
@ -123,5 +122,4 @@
|
|||
#include "./debug.h"
|
||||
|
||||
|
||||
#endif//__STDCORE_H
|
||||
|
||||
#endif //__STDCORE_H
|
||||
|
|
|
@ -3,29 +3,29 @@
|
|||
// Portions created by Tripwire, Inc. are copyright (C) 2000-2018 Tripwire,
|
||||
// Inc. Tripwire is a registered trademark of Tripwire, Inc. All rights
|
||||
// reserved.
|
||||
//
|
||||
//
|
||||
// This program is free software. The contents of this file are subject
|
||||
// to the terms of the GNU General Public License as published by the
|
||||
// Free Software Foundation; either version 2 of the License, or (at your
|
||||
// option) any later version. You may redistribute it and/or modify it
|
||||
// only in compliance with the GNU General Public License.
|
||||
//
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful.
|
||||
// However, this program is distributed AS-IS WITHOUT ANY
|
||||
// WARRANTY; INCLUDING THE IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS
|
||||
// FOR A PARTICULAR PURPOSE. Please see the GNU General Public License
|
||||
// for more details.
|
||||
//
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
|
||||
// USA.
|
||||
//
|
||||
//
|
||||
// Nothing in the GNU General Public License or any other license to use
|
||||
// the code or files shall permit you to use Tripwire's trademarks,
|
||||
// service marks, or other intellectual property without Tripwire's
|
||||
// prior written consent.
|
||||
//
|
||||
//
|
||||
// If you have any questions, please contact Tripwire, Inc. at either
|
||||
// info@tripwire.org or www.tripwire.org.
|
||||
//
|
||||
|
@ -66,16 +66,15 @@
|
|||
|
||||
/// Requirements
|
||||
|
||||
#include "stdcore.h" // for: pch
|
||||
#include "stdcore.h" // for: pch
|
||||
|
||||
#include "stringutil.h" // for: These Declarations
|
||||
#include "debug.h" // for: Debugging Interface
|
||||
#include "codeconvert.h" // for: iconv abstractions
|
||||
#include "ntmbs.h" // for: eCharacterEncoding
|
||||
#include "stringutil.h" // for: These Declarations
|
||||
#include "debug.h" // for: Debugging Interface
|
||||
#include "codeconvert.h" // for: iconv abstractions
|
||||
#include "ntmbs.h" // for: eCharacterEncoding
|
||||
#include "hashtable.h"
|
||||
|
||||
|
||||
|
||||
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
// String Cache
|
||||
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
|
@ -85,7 +84,7 @@
|
|||
class tss_hash_key_convert
|
||||
{
|
||||
public:
|
||||
const byte* operator()( const wc16_string& s, int* const pcbKeyLen )
|
||||
const byte* operator()(const wc16_string& s, int* const pcbKeyLen)
|
||||
{
|
||||
*pcbKeyLen = sizeof(WCHAR16) * s.length();
|
||||
return (byte*)s.c_str();
|
||||
|
@ -95,37 +94,32 @@ public:
|
|||
class tss_hash_key_compare
|
||||
{
|
||||
public:
|
||||
bool operator()( const wc16_string& lhs, const wc16_string& rhs )
|
||||
bool operator()(const wc16_string& lhs, const wc16_string& rhs)
|
||||
{
|
||||
return ( lhs.compare( rhs ) == 0 );
|
||||
return (lhs.compare(rhs) == 0);
|
||||
}
|
||||
};
|
||||
|
||||
namespace /* Module Local */
|
||||
{
|
||||
typedef
|
||||
cHashTable< wc16_string,
|
||||
TSTRING,
|
||||
tss_hash_key_compare,
|
||||
tss_hash_key_convert >
|
||||
hashtable_t;
|
||||
|
||||
hashtable_t& tss_GetHashTable()
|
||||
{
|
||||
static hashtable_t s_table;
|
||||
return s_table;
|
||||
}
|
||||
}//Anon.
|
||||
|
||||
typedef cHashTable<wc16_string, TSTRING, tss_hash_key_compare, tss_hash_key_convert> hashtable_t;
|
||||
|
||||
inline void tss_insert_in_hash( const wc16_string& lhs, const TSTRING& rhs )
|
||||
hashtable_t& tss_GetHashTable()
|
||||
{
|
||||
tss_GetHashTable().Insert( lhs, rhs );
|
||||
static hashtable_t s_table;
|
||||
return s_table;
|
||||
}
|
||||
} // namespace
|
||||
|
||||
|
||||
inline void tss_insert_in_hash(const wc16_string& lhs, const TSTRING& rhs)
|
||||
{
|
||||
tss_GetHashTable().Insert(lhs, rhs);
|
||||
}
|
||||
|
||||
inline bool tss_find_in_hash( const wc16_string& lhs, TSTRING& rhs )
|
||||
{
|
||||
return( tss_GetHashTable().Lookup( lhs, rhs ) );
|
||||
inline bool tss_find_in_hash(const wc16_string& lhs, TSTRING& rhs)
|
||||
{
|
||||
return (tss_GetHashTable().Lookup(lhs, rhs));
|
||||
}
|
||||
|
||||
|
||||
|
@ -134,30 +128,29 @@ inline bool tss_find_in_hash( const wc16_string& lhs, TSTRING& rhs )
|
|||
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
|
||||
/*static*/
|
||||
std::string::const_iterator
|
||||
cStringUtil::Convert( std::string& nbs, const wc16_string& dbs )
|
||||
std::string::const_iterator cStringUtil::Convert(std::string& nbs, const wc16_string& dbs)
|
||||
{
|
||||
#if IS_AROS
|
||||
nbs.resize(dbs.length());
|
||||
for (int x=0; x<dbs.length(); ++x)
|
||||
for (int x = 0; x < dbs.length(); ++x)
|
||||
nbs[x] = (unsigned char)dbs[x];
|
||||
#else
|
||||
cDebug d("cStringUtil::Convert( char, w16 )");
|
||||
|
||||
ASSERT( (void*)nbs.c_str() != (void*)dbs.c_str() );
|
||||
ASSERT((void*)nbs.c_str() != (void*)dbs.c_str());
|
||||
|
||||
if ( dbs.empty() )
|
||||
if (dbs.empty())
|
||||
nbs.erase();
|
||||
else
|
||||
{
|
||||
if( tss_find_in_hash( dbs, nbs ) )
|
||||
if (tss_find_in_hash(dbs, nbs))
|
||||
{
|
||||
d.TraceNever( _T("found string in hash table\n") );
|
||||
d.TraceNever(_T("found string in hash table\n"));
|
||||
return nbs.begin();
|
||||
}
|
||||
else
|
||||
{
|
||||
d.TraceNever( _T("didn't find string in hash table\n") );
|
||||
d.TraceNever(_T("didn't find string in hash table\n"));
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -167,21 +160,19 @@ cStringUtil::Convert( std::string& nbs, const wc16_string& dbs )
|
|||
d.TraceDebug( _T("----\n") );
|
||||
*/
|
||||
|
||||
nbs.resize( dbs.size() * MB_CUR_MAX );
|
||||
nbs.resize(dbs.size() * MB_CUR_MAX);
|
||||
|
||||
int nWrote =
|
||||
iCodeConverter::GetInstance()->Convert(
|
||||
(char*)nbs.c_str(), nbs.size(),
|
||||
dbs.c_str(), dbs.size() ); // c_str() because must be null terminated
|
||||
int nWrote = iCodeConverter::GetInstance()->Convert(
|
||||
(char*)nbs.c_str(), nbs.size(), dbs.c_str(), dbs.size()); // c_str() because must be null terminated
|
||||
|
||||
d.TraceDetail( _T("iCodeConverter returned %d\n"), nWrote );
|
||||
d.TraceDetail(_T("iCodeConverter returned %d\n"), nWrote);
|
||||
|
||||
if ( nWrote == -1 )
|
||||
throw eCharacterEncoding( TSS_GetString( cCore, core::STR_ERR_BADCHAR ) );
|
||||
if (nWrote == -1)
|
||||
throw eCharacterEncoding(TSS_GetString(cCore, core::STR_ERR_BADCHAR));
|
||||
|
||||
nbs.resize( nWrote );
|
||||
|
||||
tss_insert_in_hash( dbs, nbs );
|
||||
nbs.resize(nWrote);
|
||||
|
||||
tss_insert_in_hash(dbs, nbs);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -189,37 +180,34 @@ cStringUtil::Convert( std::string& nbs, const wc16_string& dbs )
|
|||
}
|
||||
|
||||
/*static*/
|
||||
wc16_string::const_iterator
|
||||
cStringUtil::Convert( wc16_string& dbs, const std::string& nbs )
|
||||
wc16_string::const_iterator cStringUtil::Convert(wc16_string& dbs, const std::string& nbs)
|
||||
{
|
||||
#if IS_AROS
|
||||
dbs.resize(nbs.length());
|
||||
for (int x=0; x<nbs.length(); x++)
|
||||
dbs[x] = (unsigned short)nbs[x];
|
||||
for (int x = 0; x < nbs.length(); x++)
|
||||
dbs[x] = (unsigned short)nbs[x];
|
||||
#else
|
||||
|
||||
cDebug d("cStringUtil::Convert( w16, char )");
|
||||
|
||||
if (nbs.size() != 0)
|
||||
{
|
||||
dbs.resize( nbs.size() );
|
||||
|
||||
dbs.resize(nbs.size());
|
||||
|
||||
// d.TraceDebug( "converting <%s>\n", nbs.c_str() );
|
||||
|
||||
int nWrote =
|
||||
iCodeConverter::GetInstance()->Convert(
|
||||
(WCHAR16*)dbs.c_str(), dbs.length(),
|
||||
nbs.c_str(), nbs.size() ); // c_str() because must be null terminated
|
||||
|
||||
d.TraceDetail( _T("iCodeConverter returned %d\n"), nWrote );
|
||||
|
||||
if ( nWrote == -1 )
|
||||
int nWrote = iCodeConverter::GetInstance()->Convert(
|
||||
(WCHAR16*)dbs.c_str(), dbs.length(), nbs.c_str(), nbs.size()); // c_str() because must be null terminated
|
||||
|
||||
d.TraceDetail(_T("iCodeConverter returned %d\n"), nWrote);
|
||||
|
||||
if (nWrote == -1)
|
||||
{
|
||||
throw eCharacterEncoding( TSS_GetString( cCore, core::STR_ERR_BADCHAR ) );
|
||||
throw eCharacterEncoding(TSS_GetString(cCore, core::STR_ERR_BADCHAR));
|
||||
}
|
||||
|
||||
dbs.resize( nWrote );
|
||||
|
||||
dbs.resize(nWrote);
|
||||
|
||||
/*
|
||||
d.TraceDebug( _T("converted to: \n") );
|
||||
for( int i = 0; i < dbs.size(); i++ )
|
||||
|
@ -237,18 +225,17 @@ cStringUtil::Convert( wc16_string& dbs, const std::string& nbs )
|
|||
#if SUPPORTS_WCHART && WCHAR_REP_IS_UCS2
|
||||
|
||||
/*static*/
|
||||
std::wstring::const_iterator
|
||||
cStringUtil::Convert( std::wstring& wcs, const wc16_string& dbs )
|
||||
std::wstring::const_iterator cStringUtil::Convert(std::wstring& wcs, const wc16_string& dbs)
|
||||
{
|
||||
if (dbs.size() != 0)
|
||||
{
|
||||
if( tss_find_in_hash( dbs, wcs ) )
|
||||
if (tss_find_in_hash(dbs, wcs))
|
||||
return wcs.begin();
|
||||
|
||||
wcs.resize( dbs.size() );
|
||||
std::copy( dbs.begin(), dbs.end(), wcs.begin() );
|
||||
|
||||
tss_insert_in_hash( dbs, wcs );
|
||||
wcs.resize(dbs.size());
|
||||
std::copy(dbs.begin(), dbs.end(), wcs.begin());
|
||||
|
||||
tss_insert_in_hash(dbs, wcs);
|
||||
}
|
||||
else
|
||||
wcs.erase();
|
||||
|
@ -257,13 +244,12 @@ cStringUtil::Convert( std::wstring& wcs, const wc16_string& dbs )
|
|||
}
|
||||
|
||||
/*static*/
|
||||
wc16_string::const_iterator
|
||||
cStringUtil::Convert( wc16_string& dbs, const std::wstring& wcs )
|
||||
wc16_string::const_iterator cStringUtil::Convert(wc16_string& dbs, const std::wstring& wcs)
|
||||
{
|
||||
if (wcs.size() != 0)
|
||||
{
|
||||
dbs.resize( wcs.size() );
|
||||
std::copy( wcs.begin(), wcs.end(), dbs.begin() );
|
||||
dbs.resize(wcs.size());
|
||||
std::copy(wcs.begin(), wcs.end(), dbs.begin());
|
||||
}
|
||||
else
|
||||
dbs.resize(0);
|
||||
|
@ -272,18 +258,17 @@ cStringUtil::Convert( wc16_string& dbs, const std::wstring& wcs )
|
|||
}
|
||||
|
||||
/*static*/
|
||||
std::wstring::const_iterator
|
||||
cStringUtil::Convert( std::wstring& wcs, const std::string& nbs )
|
||||
std::wstring::const_iterator cStringUtil::Convert(std::wstring& wcs, const std::string& nbs)
|
||||
{
|
||||
if (nbs.size() != 0)
|
||||
{
|
||||
wcs.resize( nbs.size() );
|
||||
|
||||
size_t nWrote = ::mbstowcs( (wchar_t*)wcs.c_str(), nbs.c_str(), wcs.size() + 1 );
|
||||
if ( nWrote == (size_t)-1 )
|
||||
throw eCharacterEncoding( TSS_GetString( cCore, core::STR_ERR_BADCHAR ) );
|
||||
|
||||
wcs.resize( nWrote );
|
||||
wcs.resize(nbs.size());
|
||||
|
||||
size_t nWrote = ::mbstowcs((wchar_t*)wcs.c_str(), nbs.c_str(), wcs.size() + 1);
|
||||
if (nWrote == (size_t)-1)
|
||||
throw eCharacterEncoding(TSS_GetString(cCore, core::STR_ERR_BADCHAR));
|
||||
|
||||
wcs.resize(nWrote);
|
||||
}
|
||||
else
|
||||
wcs.erase();
|
||||
|
@ -292,22 +277,21 @@ cStringUtil::Convert( std::wstring& wcs, const std::string& nbs )
|
|||
}
|
||||
|
||||
/*static*/
|
||||
std::string::const_iterator
|
||||
cStringUtil::Convert( std::string& nbs, const std::wstring& wcs )
|
||||
std::string::const_iterator cStringUtil::Convert(std::string& nbs, const std::wstring& wcs)
|
||||
{
|
||||
if (wcs.size() != 0)
|
||||
{
|
||||
if( tss_find_in_hash( wc16_string( wcs.c_str() ), nbs ) )
|
||||
if (tss_find_in_hash(wc16_string(wcs.c_str()), nbs))
|
||||
return nbs.begin();
|
||||
|
||||
nbs.resize( MB_CUR_MAX * wcs.size() );
|
||||
size_t nWrote = ::wcstombs( (char*)nbs.c_str(), wcs.c_str(), nbs.size() + 1 );
|
||||
if ( nWrote == (size_t)-1 )
|
||||
throw eCharacterEncoding( TSS_GetString( cCore, core::STR_ERR_BADCHAR ) );
|
||||
|
||||
nbs.resize( nWrote );
|
||||
|
||||
tss_insert_in_hash( wc16_string( wcs.c_str() ), nbs );
|
||||
nbs.resize(MB_CUR_MAX * wcs.size());
|
||||
size_t nWrote = ::wcstombs((char*)nbs.c_str(), wcs.c_str(), nbs.size() + 1);
|
||||
if (nWrote == (size_t)-1)
|
||||
throw eCharacterEncoding(TSS_GetString(cCore, core::STR_ERR_BADCHAR));
|
||||
|
||||
nbs.resize(nWrote);
|
||||
|
||||
tss_insert_in_hash(wc16_string(wcs.c_str()), nbs);
|
||||
}
|
||||
else
|
||||
nbs.erase();
|
||||
|
@ -324,40 +308,39 @@ cStringUtil::Convert( std::string& nbs, const std::wstring& wcs )
|
|||
// TstrToStr
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
std::string
|
||||
cStringUtil::TstrToStr( const TSTRING& tstr )
|
||||
std::string cStringUtil::TstrToStr(const TSTRING& tstr)
|
||||
{
|
||||
std::string s;
|
||||
cStringUtil::Convert( s, tstr );
|
||||
cStringUtil::Convert(s, tstr);
|
||||
return s;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// StrToTstr
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
TSTRING cStringUtil::StrToTstr( const std::string& rhs )
|
||||
TSTRING cStringUtil::StrToTstr(const std::string& rhs)
|
||||
{
|
||||
TSTRING lhs;
|
||||
cStringUtil::Convert( lhs, rhs );
|
||||
cStringUtil::Convert(lhs, rhs);
|
||||
return lhs;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// WstrToTstr
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
TSTRING cStringUtil::WstrToTstr(const wc16_string& rhs )
|
||||
{
|
||||
TSTRING cStringUtil::WstrToTstr(const wc16_string& rhs)
|
||||
{
|
||||
TSTRING lhs;
|
||||
cStringUtil::Convert( lhs, rhs );
|
||||
return lhs;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// TstrToWstr
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
wc16_string cStringUtil::TstrToWstr( const TSTRING& rhs )
|
||||
{
|
||||
wc16_string lhs;
|
||||
cStringUtil::Convert( lhs, rhs );
|
||||
cStringUtil::Convert(lhs, rhs);
|
||||
return lhs;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// TstrToWstr
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
wc16_string cStringUtil::TstrToWstr(const TSTRING& rhs)
|
||||
{
|
||||
wc16_string lhs;
|
||||
cStringUtil::Convert(lhs, rhs);
|
||||
return lhs;
|
||||
}
|
||||
|
|
|
@ -3,29 +3,29 @@
|
|||
// Portions created by Tripwire, Inc. are copyright (C) 2000-2018 Tripwire,
|
||||
// Inc. Tripwire is a registered trademark of Tripwire, Inc. All rights
|
||||
// reserved.
|
||||
//
|
||||
//
|
||||
// This program is free software. The contents of this file are subject
|
||||
// to the terms of the GNU General Public License as published by the
|
||||
// Free Software Foundation; either version 2 of the License, or (at your
|
||||
// option) any later version. You may redistribute it and/or modify it
|
||||
// only in compliance with the GNU General Public License.
|
||||
//
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful.
|
||||
// However, this program is distributed AS-IS WITHOUT ANY
|
||||
// WARRANTY; INCLUDING THE IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS
|
||||
// FOR A PARTICULAR PURPOSE. Please see the GNU General Public License
|
||||
// for more details.
|
||||
//
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
|
||||
// USA.
|
||||
//
|
||||
//
|
||||
// Nothing in the GNU General Public License or any other license to use
|
||||
// the code or files shall permit you to use Tripwire's trademarks,
|
||||
// service marks, or other intellectual property without Tripwire's
|
||||
// prior written consent.
|
||||
//
|
||||
//
|
||||
// If you have any questions, please contact Tripwire, Inc. at either
|
||||
// info@tripwire.org or www.tripwire.org.
|
||||
//
|
||||
|
@ -55,97 +55,83 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
namespace cStringUtil
|
||||
{
|
||||
//--Type Dispatched Conversion (Generalization away from TCHAR)
|
||||
//--Type Dispatched Conversion (Generalization away from TCHAR)
|
||||
|
||||
/// Handle Like-Types (xstring to xstring)
|
||||
/// Handle Like-Types (xstring to xstring)
|
||||
|
||||
inline
|
||||
const char *
|
||||
Convert( std::string& lhs, const std::string& rhs )
|
||||
{
|
||||
lhs = rhs;
|
||||
return lhs.c_str();
|
||||
}
|
||||
inline const char* Convert(std::string& lhs, const std::string& rhs)
|
||||
{
|
||||
lhs = rhs;
|
||||
return lhs.c_str();
|
||||
}
|
||||
|
||||
/// Specialize Everything Else
|
||||
/// Specialize Everything Else
|
||||
|
||||
std::string::const_iterator
|
||||
Convert( std::string&, const wc16_string& );
|
||||
std::string::const_iterator Convert(std::string&, const wc16_string&);
|
||||
|
||||
wc16_string::const_iterator
|
||||
Convert( wc16_string&, const std::string& );
|
||||
wc16_string::const_iterator Convert(wc16_string&, const std::string&);
|
||||
|
||||
#if SUPPORTS_WCHART && WCHAR_REP_IS_UCS2
|
||||
|
||||
inline
|
||||
std::wstring::const_iterator
|
||||
Convert( std::wstring& lhs, const std::wstring& rhs )
|
||||
{
|
||||
lhs = rhs;
|
||||
return lhs.c_str();
|
||||
}
|
||||
inline std::wstring::const_iterator Convert(std::wstring& lhs, const std::wstring& rhs)
|
||||
{
|
||||
lhs = rhs;
|
||||
return lhs.c_str();
|
||||
}
|
||||
|
||||
std::wstring::const_iterator
|
||||
Convert( std::wstring&, const wc16_string& );
|
||||
std::wstring::const_iterator Convert(std::wstring&, const wc16_string&);
|
||||
|
||||
std::wstring::const_iterator
|
||||
Convert( std::wstring&, const std::string& );
|
||||
std::wstring::const_iterator Convert(std::wstring&, const std::string&);
|
||||
|
||||
std::string::const_iterator
|
||||
Convert( std::string&, const std::wstring& );
|
||||
std::string::const_iterator Convert(std::string&, const std::wstring&);
|
||||
|
||||
wc16_string::const_iterator
|
||||
Convert( wc16_string&, const std::wstring& );
|
||||
wc16_string::const_iterator Convert(wc16_string&, const std::wstring&);
|
||||
|
||||
#endif//SUPPORTS_WCHART
|
||||
#endif //SUPPORTS_WCHART
|
||||
|
||||
|
||||
/// WARNING: These are deprecated, please use Convert()!
|
||||
/// WARNING: These are deprecated, please use Convert()!
|
||||
|
||||
std::string TstrToStr( const TSTRING& tstr );
|
||||
// converts a tstring to a narrow string; useful for passphrase input, which must always be
|
||||
// the same format, regardless of what TCHAR is defined to.
|
||||
std::string TstrToStr(const TSTRING& tstr);
|
||||
// converts a tstring to a narrow string; useful for passphrase input, which must always be
|
||||
// the same format, regardless of what TCHAR is defined to.
|
||||
|
||||
TSTRING StrToTstr( const std::string& str );
|
||||
// converts a narrow string to a TSTRING
|
||||
TSTRING StrToTstr(const std::string& str);
|
||||
// converts a narrow string to a TSTRING
|
||||
|
||||
TSTRING WstrToTstr( const wc16_string& src );
|
||||
// convert wc16_string to a TSTRING
|
||||
wc16_string TstrToWstr( const TSTRING& tstr );
|
||||
// convert a TSTRING to a wc16_string
|
||||
TSTRING WstrToTstr(const wc16_string& src);
|
||||
// convert wc16_string to a TSTRING
|
||||
wc16_string TstrToWstr(const TSTRING& tstr);
|
||||
// convert a TSTRING to a wc16_string
|
||||
|
||||
|
||||
template <class IterT>
|
||||
void splitstring(IterT& iter,
|
||||
const TSTRING& str,
|
||||
const TSTRING& delims) {
|
||||
template<class IterT> void splitstring(IterT& iter, const TSTRING& str, const TSTRING& delims)
|
||||
{
|
||||
|
||||
TSTRING::size_type where;
|
||||
TSTRING tmpStr;
|
||||
TSTRING workingString = str;
|
||||
TSTRING tmpStr;
|
||||
TSTRING workingString = str;
|
||||
|
||||
while (workingString.length() > 0) {
|
||||
while (workingString.length() > 0)
|
||||
{
|
||||
|
||||
where = workingString.find_first_of(delims, 0);
|
||||
where = workingString.find_first_of(delims, 0);
|
||||
|
||||
// in the case of no delimeters, setp to
|
||||
// grab the entire string.
|
||||
//
|
||||
if (where == TSTRING::npos)
|
||||
where = workingString.length();
|
||||
// in the case of no delimeters, setp to
|
||||
// grab the entire string.
|
||||
//
|
||||
if (where == TSTRING::npos)
|
||||
where = workingString.length();
|
||||
|
||||
tmpStr = workingString.substr(0, where);
|
||||
workingString.erase(0, where+1);
|
||||
|
||||
iter.push_back(tmpStr);
|
||||
tmpStr = workingString.substr(0, where);
|
||||
workingString.erase(0, where + 1);
|
||||
|
||||
iter.push_back(tmpStr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}//cStringUtil::
|
||||
} // namespace cStringUtil
|
||||
|
||||
/*
|
||||
//-----------------------------------------------------------------------------
|
||||
|
@ -202,5 +188,4 @@ namespace std
|
|||
}
|
||||
*/
|
||||
|
||||
#endif//__STRINGUTIL_H
|
||||
|
||||
#endif //__STRINGUTIL_H
|
||||
|
|
|
@ -3,29 +3,29 @@
|
|||
// Portions created by Tripwire, Inc. are copyright (C) 2000-2018 Tripwire,
|
||||
// Inc. Tripwire is a registered trademark of Tripwire, Inc. All rights
|
||||
// reserved.
|
||||
//
|
||||
//
|
||||
// This program is free software. The contents of this file are subject
|
||||
// to the terms of the GNU General Public License as published by the
|
||||
// Free Software Foundation; either version 2 of the License, or (at your
|
||||
// option) any later version. You may redistribute it and/or modify it
|
||||
// only in compliance with the GNU General Public License.
|
||||
//
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful.
|
||||
// However, this program is distributed AS-IS WITHOUT ANY
|
||||
// WARRANTY; INCLUDING THE IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS
|
||||
// FOR A PARTICULAR PURPOSE. Please see the GNU General Public License
|
||||
// for more details.
|
||||
//
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
|
||||
// USA.
|
||||
//
|
||||
//
|
||||
// Nothing in the GNU General Public License or any other license to use
|
||||
// the code or files shall permit you to use Tripwire's trademarks,
|
||||
// service marks, or other intellectual property without Tripwire's
|
||||
// prior written consent.
|
||||
//
|
||||
//
|
||||
// If you have any questions, please contact Tripwire, Inc. at either
|
||||
// info@tripwire.org or www.tripwire.org.
|
||||
//
|
||||
|
@ -33,7 +33,7 @@
|
|||
// tasktimer.h
|
||||
//
|
||||
// cTaskTimer -- a class that can be used to time a given task
|
||||
// TODO -- make this cross-platform -- maybe a template class with the time-reaping
|
||||
// TODO -- make this cross-platform -- maybe a template class with the time-reaping
|
||||
// function as a parameter
|
||||
#ifndef __TASKTIMER_H
|
||||
#define __TASKTIMER_H
|
||||
|
@ -50,19 +50,21 @@
|
|||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// cTaskTimer --
|
||||
// cTaskTimer --
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
class cTaskTimer
|
||||
{
|
||||
|
||||
|
||||
public:
|
||||
cTaskTimer(const TSTRING& name) : mName(name), mTotalTime(0), mStartTime(0), mNumStarts(0) {}
|
||||
cTaskTimer(const TSTRING& name) : mName(name), mTotalTime(0), mStartTime(0), mNumStarts(0)
|
||||
{
|
||||
}
|
||||
|
||||
inline ~cTaskTimer()
|
||||
{
|
||||
// stop the timer if it is currently running
|
||||
if(IsRunning())
|
||||
if (IsRunning())
|
||||
Stop();
|
||||
|
||||
// trace out the time contents...
|
||||
|
@ -72,34 +74,47 @@ public:
|
|||
|
||||
inline void Start()
|
||||
{
|
||||
ASSERT(! IsRunning());
|
||||
ASSERT(!IsRunning());
|
||||
time_t dummy;
|
||||
mStartTime = time(&dummy);
|
||||
mNumStarts++;
|
||||
}
|
||||
|
||||
void Stop()
|
||||
void Stop()
|
||||
{
|
||||
ASSERT(IsRunning());
|
||||
time_t dummy;
|
||||
mTotalTime += ( time(&dummy) - mStartTime );
|
||||
mTotalTime += (time(&dummy) - mStartTime);
|
||||
mStartTime = 0;
|
||||
}
|
||||
|
||||
bool IsRunning() { return (mStartTime != 0); }
|
||||
void Reset() { mNumStarts = mStartTime = mTotalTime = 0; }
|
||||
uint32 GetTotalTime() const { return mTotalTime; }
|
||||
uint32 GetNumTimesStarted() const { return mNumStarts; }
|
||||
const std::string& GetName() const { return mName; }
|
||||
bool IsRunning()
|
||||
{
|
||||
return (mStartTime != 0);
|
||||
}
|
||||
void Reset()
|
||||
{
|
||||
mNumStarts = mStartTime = mTotalTime = 0;
|
||||
}
|
||||
uint32 GetTotalTime() const
|
||||
{
|
||||
return mTotalTime;
|
||||
}
|
||||
uint32 GetNumTimesStarted() const
|
||||
{
|
||||
return mNumStarts;
|
||||
}
|
||||
const std::string& GetName() const
|
||||
{
|
||||
return mName;
|
||||
}
|
||||
|
||||
private:
|
||||
TSTRING mName;
|
||||
uint32 mTotalTime;
|
||||
uint32 mStartTime;
|
||||
uint32 mNumStarts;
|
||||
|
||||
TSTRING mName;
|
||||
uint32 mTotalTime;
|
||||
uint32 mStartTime;
|
||||
uint32 mNumStarts;
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
|
109
src/core/tchar.h
109
src/core/tchar.h
|
@ -3,36 +3,36 @@
|
|||
// Portions created by Tripwire, Inc. are copyright (C) 2000-2018 Tripwire,
|
||||
// Inc. Tripwire is a registered trademark of Tripwire, Inc. All rights
|
||||
// reserved.
|
||||
//
|
||||
//
|
||||
// This program is free software. The contents of this file are subject
|
||||
// to the terms of the GNU General Public License as published by the
|
||||
// Free Software Foundation; either version 2 of the License, or (at your
|
||||
// option) any later version. You may redistribute it and/or modify it
|
||||
// only in compliance with the GNU General Public License.
|
||||
//
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful.
|
||||
// However, this program is distributed AS-IS WITHOUT ANY
|
||||
// WARRANTY; INCLUDING THE IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS
|
||||
// FOR A PARTICULAR PURPOSE. Please see the GNU General Public License
|
||||
// for more details.
|
||||
//
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
|
||||
// USA.
|
||||
//
|
||||
//
|
||||
// Nothing in the GNU General Public License or any other license to use
|
||||
// the code or files shall permit you to use Tripwire's trademarks,
|
||||
// service marks, or other intellectual property without Tripwire's
|
||||
// prior written consent.
|
||||
//
|
||||
//
|
||||
// If you have any questions, please contact Tripwire, Inc. at either
|
||||
// info@tripwire.org or www.tripwire.org.
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// tchar.h
|
||||
// tchar.h
|
||||
//
|
||||
// VCC version of TCHAR.H that is cross platform compatible between UNIX and
|
||||
// VCC version of TCHAR.H that is cross platform compatible between UNIX and
|
||||
// Windows.
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
@ -58,7 +58,7 @@
|
|||
#define __TCHAR_H
|
||||
|
||||
// A little macro that's useful for finding the number of characters in a TCHAR ARRAY
|
||||
#define countof( x ) ( sizeof( x ) / sizeof( x[0] ) )
|
||||
#define countof(x) (sizeof(x) / sizeof(x[0]))
|
||||
|
||||
|
||||
#include <string.h>
|
||||
|
@ -66,64 +66,63 @@
|
|||
#include <sstream>
|
||||
#include <iostream>
|
||||
|
||||
#define TCHAR char
|
||||
#define TCHAR char
|
||||
#define _tmain main
|
||||
|
||||
typedef std::string TSTRING;
|
||||
typedef std::stringstream TSTRINGSTREAM;
|
||||
typedef std::ostringstream TOSTRINGSTREAM;
|
||||
typedef std::istringstream TISTRINGSTREAM;
|
||||
typedef std::ostream TOSTREAM;
|
||||
typedef std::istream TISTREAM;
|
||||
typedef std::ofstream TOFSTREAM;
|
||||
typedef std::ifstream TIFSTREAM;
|
||||
typedef std::string TSTRING;
|
||||
typedef std::stringstream TSTRINGSTREAM;
|
||||
typedef std::ostringstream TOSTRINGSTREAM;
|
||||
typedef std::istringstream TISTRINGSTREAM;
|
||||
typedef std::ostream TOSTREAM;
|
||||
typedef std::istream TISTREAM;
|
||||
typedef std::ofstream TOFSTREAM;
|
||||
typedef std::ifstream TIFSTREAM;
|
||||
|
||||
// iostream abstractions
|
||||
#define TCIN std::cin
|
||||
#define TCOUT std::cout
|
||||
#define TCERR std::cerr
|
||||
# define TCIN std::cin
|
||||
# define TCOUT std::cout
|
||||
# define TCERR std::cerr
|
||||
|
||||
// other functions
|
||||
#define _ftprintf fprintf
|
||||
#define _stprintf sprintf
|
||||
#define _itot itoa
|
||||
#define _ttoi atoi
|
||||
#define _istdigit isdigit
|
||||
#define _tcsftime strftime
|
||||
#define _vtprintf vprintf
|
||||
#define _vftprintf vfprintf
|
||||
#define _topen open
|
||||
#define _tfdopen fdopen
|
||||
#define _tfopen fopen
|
||||
#define _tmkdir mkdir
|
||||
#define _tcscpy strcpy
|
||||
#define _tgetenv getenv
|
||||
#define _taccess access
|
||||
#define _tcreat creat
|
||||
#define _tunlink unlink
|
||||
#define _tcscmp strcmp
|
||||
#define _tcsicmp strcasecmp
|
||||
#define _totlower tolower
|
||||
#define _totupper toupper
|
||||
#define _tcslen strlen
|
||||
#define _tcscat strcat
|
||||
#define _tcsncmp strncmp
|
||||
# define _ftprintf fprintf
|
||||
# define _stprintf sprintf
|
||||
# define _itot itoa
|
||||
# define _ttoi atoi
|
||||
# define _istdigit isdigit
|
||||
# define _tcsftime strftime
|
||||
# define _vtprintf vprintf
|
||||
# define _vftprintf vfprintf
|
||||
# define _topen open
|
||||
# define _tfdopen fdopen
|
||||
# define _tfopen fopen
|
||||
# define _tmkdir mkdir
|
||||
# define _tcscpy strcpy
|
||||
# define _tgetenv getenv
|
||||
# define _taccess access
|
||||
# define _tcreat creat
|
||||
# define _tunlink unlink
|
||||
# define _tcscmp strcmp
|
||||
# define _tcsicmp strcasecmp
|
||||
# define _totlower tolower
|
||||
# define _totupper toupper
|
||||
# define _tcslen strlen
|
||||
# define _tcscat strcat
|
||||
# define _tcsncmp strncmp
|
||||
|
||||
// other abstractions
|
||||
#define TUNLINK unlink
|
||||
# define TUNLINK unlink
|
||||
|
||||
// string representation
|
||||
#if defined(_T)
|
||||
// run it right over with a bulldozer, tripwire doesn't seem
|
||||
// to use ctype.h's _T -PH
|
||||
#undef _T
|
||||
#endif
|
||||
#define _T(x) x
|
||||
# if defined(_T)
|
||||
// run it right over with a bulldozer, tripwire doesn't seem
|
||||
// to use ctype.h's _T -PH
|
||||
# undef _T
|
||||
# endif
|
||||
# define _T(x) x
|
||||
|
||||
// misc...
|
||||
#ifndef __cdecl
|
||||
#define __cdecl
|
||||
#endif
|
||||
# ifndef __cdecl
|
||||
# define __cdecl
|
||||
# endif
|
||||
|
||||
#endif // __TCHAR_H
|
||||
|
||||
|
|
|
@ -3,29 +3,29 @@
|
|||
// Portions created by Tripwire, Inc. are copyright (C) 2000-2018 Tripwire,
|
||||
// Inc. Tripwire is a registered trademark of Tripwire, Inc. All rights
|
||||
// reserved.
|
||||
//
|
||||
//
|
||||
// This program is free software. The contents of this file are subject
|
||||
// to the terms of the GNU General Public License as published by the
|
||||
// Free Software Foundation; either version 2 of the License, or (at your
|
||||
// option) any later version. You may redistribute it and/or modify it
|
||||
// only in compliance with the GNU General Public License.
|
||||
//
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful.
|
||||
// However, this program is distributed AS-IS WITHOUT ANY
|
||||
// WARRANTY; INCLUDING THE IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS
|
||||
// FOR A PARTICULAR PURPOSE. Please see the GNU General Public License
|
||||
// for more details.
|
||||
//
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
|
||||
// USA.
|
||||
//
|
||||
//
|
||||
// Nothing in the GNU General Public License or any other license to use
|
||||
// the code or files shall permit you to use Tripwire's trademarks,
|
||||
// service marks, or other intellectual property without Tripwire's
|
||||
// prior written consent.
|
||||
//
|
||||
//
|
||||
// If you have any questions, please contact Tripwire, Inc. at either
|
||||
// info@tripwire.org or www.tripwire.org.
|
||||
//
|
||||
|
@ -52,36 +52,34 @@
|
|||
// METHOD CODE
|
||||
//=========================================================================
|
||||
|
||||
#define TIME_MAX 2147483647L // largest signed 32 bit number
|
||||
#define TIME_MAX 2147483647L // largest signed 32 bit number
|
||||
|
||||
#if IS_AROS
|
||||
#define tzset()
|
||||
# define tzset()
|
||||
#endif
|
||||
|
||||
struct tm* cTimeUtil::TimeToDateGMT( const int64& seconds )
|
||||
struct tm* cTimeUtil::TimeToDateGMT(const int64& seconds)
|
||||
{
|
||||
ASSERT( seconds < TIME_MAX );// this assumes time_t size is 32 bit. Yikes!
|
||||
ASSERT(seconds < TIME_MAX); // this assumes time_t size is 32 bit. Yikes!
|
||||
time_t t = static_cast<time_t>(seconds);
|
||||
return gmtime( &t );
|
||||
return gmtime(&t);
|
||||
}
|
||||
|
||||
struct tm* cTimeUtil::TimeToDateLocal( const int64& seconds )
|
||||
struct tm* cTimeUtil::TimeToDateLocal(const int64& seconds)
|
||||
{
|
||||
ASSERT( seconds < TIME_MAX );// this assumes time_t size is 32 bit. Yikes!
|
||||
ASSERT(seconds < TIME_MAX); // this assumes time_t size is 32 bit. Yikes!
|
||||
time_t t = static_cast<time_t>(seconds);
|
||||
tzset();
|
||||
return localtime( &t );
|
||||
return localtime(&t);
|
||||
}
|
||||
|
||||
int64 cTimeUtil::DateToTime( struct tm* ptm )
|
||||
int64 cTimeUtil::DateToTime(struct tm* ptm)
|
||||
{
|
||||
tzset();
|
||||
return mktime( ptm );
|
||||
return mktime(ptm);
|
||||
}
|
||||
|
||||
int64 cTimeUtil::GetTime()
|
||||
{
|
||||
return time( NULL );
|
||||
{
|
||||
return time(NULL);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -3,29 +3,29 @@
|
|||
// Portions created by Tripwire, Inc. are copyright (C) 2000-2018 Tripwire,
|
||||
// Inc. Tripwire is a registered trademark of Tripwire, Inc. All rights
|
||||
// reserved.
|
||||
//
|
||||
//
|
||||
// This program is free software. The contents of this file are subject
|
||||
// to the terms of the GNU General Public License as published by the
|
||||
// Free Software Foundation; either version 2 of the License, or (at your
|
||||
// option) any later version. You may redistribute it and/or modify it
|
||||
// only in compliance with the GNU General Public License.
|
||||
//
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful.
|
||||
// However, this program is distributed AS-IS WITHOUT ANY
|
||||
// WARRANTY; INCLUDING THE IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS
|
||||
// FOR A PARTICULAR PURPOSE. Please see the GNU General Public License
|
||||
// for more details.
|
||||
//
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
|
||||
// USA.
|
||||
//
|
||||
//
|
||||
// Nothing in the GNU General Public License or any other license to use
|
||||
// the code or files shall permit you to use Tripwire's trademarks,
|
||||
// service marks, or other intellectual property without Tripwire's
|
||||
// prior written consent.
|
||||
//
|
||||
//
|
||||
// If you have any questions, please contact Tripwire, Inc. at either
|
||||
// info@tripwire.org or www.tripwire.org.
|
||||
//
|
||||
|
@ -62,15 +62,14 @@
|
|||
class cTimeUtil
|
||||
{
|
||||
public:
|
||||
static int64 DateToTime( struct tm* ptm );
|
||||
// simple conversion. ptm is considered to be in localtime.
|
||||
static struct tm* TimeToDateGMT( const int64& seconds );
|
||||
// simple conversion
|
||||
static struct tm* TimeToDateLocal( const int64& seconds );
|
||||
// conversion with timezone and daylight
|
||||
static int64 GetTime();
|
||||
// returns current time in UTC
|
||||
static int64 DateToTime(struct tm* ptm);
|
||||
// simple conversion. ptm is considered to be in localtime.
|
||||
static struct tm* TimeToDateGMT(const int64& seconds);
|
||||
// simple conversion
|
||||
static struct tm* TimeToDateLocal(const int64& seconds);
|
||||
// conversion with timezone and daylight
|
||||
static int64 GetTime();
|
||||
// returns current time in UTC
|
||||
};
|
||||
|
||||
#endif//__TIMECONVERT_H
|
||||
|
||||
#endif //__TIMECONVERT_H
|
||||
|
|
|
@ -3,29 +3,29 @@
|
|||
// Portions created by Tripwire, Inc. are copyright (C) 2000-2018 Tripwire,
|
||||
// Inc. Tripwire is a registered trademark of Tripwire, Inc. All rights
|
||||
// reserved.
|
||||
//
|
||||
//
|
||||
// This program is free software. The contents of this file are subject
|
||||
// to the terms of the GNU General Public License as published by the
|
||||
// Free Software Foundation; either version 2 of the License, or (at your
|
||||
// option) any later version. You may redistribute it and/or modify it
|
||||
// only in compliance with the GNU General Public License.
|
||||
//
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful.
|
||||
// However, this program is distributed AS-IS WITHOUT ANY
|
||||
// WARRANTY; INCLUDING THE IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS
|
||||
// FOR A PARTICULAR PURPOSE. Please see the GNU General Public License
|
||||
// for more details.
|
||||
//
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
|
||||
// USA.
|
||||
//
|
||||
//
|
||||
// Nothing in the GNU General Public License or any other license to use
|
||||
// the code or files shall permit you to use Tripwire's trademarks,
|
||||
// service marks, or other intellectual property without Tripwire's
|
||||
// prior written consent.
|
||||
//
|
||||
//
|
||||
// If you have any questions, please contact Tripwire, Inc. at either
|
||||
// info@tripwire.org or www.tripwire.org.
|
||||
//
|
||||
|
@ -36,9 +36,9 @@
|
|||
#include <signal.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
static void util_SignalHandler( int sig );
|
||||
static void util_SignalHandler(int sig);
|
||||
|
||||
static void tw_psignal( int sig, const TCHAR* s );
|
||||
static void tw_psignal(int sig, const TCHAR* s);
|
||||
|
||||
tw_sighandler_t tw_signal(int sig, tw_sighandler_t pFunc)
|
||||
{
|
||||
|
@ -56,68 +56,64 @@ tw_sighandler_t tw_sigign(int sig)
|
|||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// tw_HandleSignal -- Take a given signal and install a handler for
|
||||
// tw_HandleSignal -- Take a given signal and install a handler for
|
||||
// it, which will then exit with the supplied exit value
|
||||
tw_sighandler_t tw_HandleSignal( int sig )
|
||||
tw_sighandler_t tw_HandleSignal(int sig)
|
||||
{
|
||||
return signal( sig, util_SignalHandler );
|
||||
return signal(sig, util_SignalHandler);
|
||||
}
|
||||
|
||||
void util_SignalHandler( int sig )
|
||||
void util_SignalHandler(int sig)
|
||||
{
|
||||
//If we're on unix, let's print out a nice error message telling
|
||||
//the user which signal we've recieved.
|
||||
tw_psignal( sig, (TSS_GetString( cCore, core::STR_SIGNAL).c_str() ) );
|
||||
exit( 8 );
|
||||
tw_psignal(sig, (TSS_GetString(cCore, core::STR_SIGNAL).c_str()));
|
||||
exit(8);
|
||||
}
|
||||
|
||||
/* For the morbidly curious, here's a thread where a POSIX standards committee
|
||||
wrings its hands about how to define NSIG: http://austingroupbugs.net/view.php?id=741#c1834 */
|
||||
wrings its hands about how to define NSIG: http://austingroupbugs.net/view.php?id=741#c1834 */
|
||||
#ifndef NSIG
|
||||
# ifdef SIGMAX
|
||||
# define NSIG (SIGMAX+1)
|
||||
# else
|
||||
# define NSIG 32
|
||||
# endif
|
||||
# ifdef SIGMAX
|
||||
# define NSIG (SIGMAX + 1)
|
||||
# else
|
||||
# define NSIG 32
|
||||
# endif
|
||||
#endif
|
||||
|
||||
void tw_psignal(int sig, const TCHAR *str)
|
||||
void tw_psignal(int sig, const TCHAR* str)
|
||||
{
|
||||
const TCHAR *siglist[NSIG] = {
|
||||
_T("Unknown Signal"),
|
||||
_T("Hangup"),
|
||||
_T("Interrupt"),
|
||||
_T("Quit"),
|
||||
_T("Illegal Instruction"),
|
||||
_T("Trace/Breakpoint Trap"),
|
||||
_T("Abort"),
|
||||
_T("Emulation Trap"),
|
||||
_T("Arithmetic Exception"),
|
||||
_T("Killed"),
|
||||
_T("Bus Error"),
|
||||
_T("Segmentation Fault"),
|
||||
_T("Bad System Call"),
|
||||
_T("Broken Pipe"),
|
||||
_T("Alarm Clock"),
|
||||
_T("Terminated"),
|
||||
_T("User Signal 1"),
|
||||
_T("User Signal 2"),
|
||||
_T("Child Status Changed"),
|
||||
_T("Power-Fail/Restart"),
|
||||
_T("Virtual Timer Expired"),
|
||||
_T("Profiling Timer Expired"),
|
||||
_T("Pollable Event"),
|
||||
_T("Window Size Change"),
|
||||
_T("Stopped (signal)"),
|
||||
_T("Stopped (user)"),
|
||||
_T("Continued"),
|
||||
_T("Stopped (tty input)"),
|
||||
_T("Stopped (tty output)"),
|
||||
_T("Urgent Socket Condition"),
|
||||
_T("File Lock Lost")
|
||||
};
|
||||
const TCHAR* siglist[NSIG] = {_T("Unknown Signal"),
|
||||
_T("Hangup"),
|
||||
_T("Interrupt"),
|
||||
_T("Quit"),
|
||||
_T("Illegal Instruction"),
|
||||
_T("Trace/Breakpoint Trap"),
|
||||
_T("Abort"),
|
||||
_T("Emulation Trap"),
|
||||
_T("Arithmetic Exception"),
|
||||
_T("Killed"),
|
||||
_T("Bus Error"),
|
||||
_T("Segmentation Fault"),
|
||||
_T("Bad System Call"),
|
||||
_T("Broken Pipe"),
|
||||
_T("Alarm Clock"),
|
||||
_T("Terminated"),
|
||||
_T("User Signal 1"),
|
||||
_T("User Signal 2"),
|
||||
_T("Child Status Changed"),
|
||||
_T("Power-Fail/Restart"),
|
||||
_T("Virtual Timer Expired"),
|
||||
_T("Profiling Timer Expired"),
|
||||
_T("Pollable Event"),
|
||||
_T("Window Size Change"),
|
||||
_T("Stopped (signal)"),
|
||||
_T("Stopped (user)"),
|
||||
_T("Continued"),
|
||||
_T("Stopped (tty input)"),
|
||||
_T("Stopped (tty output)"),
|
||||
_T("Urgent Socket Condition"),
|
||||
_T("File Lock Lost")};
|
||||
|
||||
_ftprintf(stderr, _T("%s %s\n"), str, sig < NSIG ? siglist[sig] : siglist[0]);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -3,34 +3,34 @@
|
|||
// Portions created by Tripwire, Inc. are copyright (C) 2000-2018 Tripwire,
|
||||
// Inc. Tripwire is a registered trademark of Tripwire, Inc. All rights
|
||||
// reserved.
|
||||
//
|
||||
//
|
||||
// This program is free software. The contents of this file are subject
|
||||
// to the terms of the GNU General Public License as published by the
|
||||
// Free Software Foundation; either version 2 of the License, or (at your
|
||||
// option) any later version. You may redistribute it and/or modify it
|
||||
// only in compliance with the GNU General Public License.
|
||||
//
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful.
|
||||
// However, this program is distributed AS-IS WITHOUT ANY
|
||||
// WARRANTY; INCLUDING THE IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS
|
||||
// FOR A PARTICULAR PURPOSE. Please see the GNU General Public License
|
||||
// for more details.
|
||||
//
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
|
||||
// USA.
|
||||
//
|
||||
//
|
||||
// Nothing in the GNU General Public License or any other license to use
|
||||
// the code or files shall permit you to use Tripwire's trademarks,
|
||||
// service marks, or other intellectual property without Tripwire's
|
||||
// prior written consent.
|
||||
//
|
||||
//
|
||||
// If you have any questions, please contact Tripwire, Inc. at either
|
||||
// info@tripwire.org or www.tripwire.org.
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// tw_signal.h -- a wrapper around signal(), needed because of linux
|
||||
// tw_signal.h -- a wrapper around signal(), needed because of linux
|
||||
// build issues
|
||||
//
|
||||
#ifndef __TW_SIGNAL_H
|
||||
|
@ -39,18 +39,19 @@
|
|||
#include <signal.h>
|
||||
|
||||
#ifdef HAVE_SIGNUM_H
|
||||
#include <signum.h> // the signal number constants
|
||||
#include <signum.h> // the signal number constants
|
||||
#endif
|
||||
#ifdef HAVE_BITS_SIGNUM_H
|
||||
#include <bits/signum.h>
|
||||
#endif
|
||||
|
||||
extern "C" {
|
||||
typedef void (*tw_sighandler_t)(int);
|
||||
extern "C"
|
||||
{
|
||||
typedef void (*tw_sighandler_t)(int);
|
||||
}
|
||||
|
||||
tw_sighandler_t tw_signal(int sig, tw_sighandler_t pFunc);
|
||||
int tw_raise (int sig);
|
||||
int tw_raise(int sig);
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// tw_sigign -- wrapper around tw_signal(XXX, SIG_IGN)
|
||||
|
@ -60,8 +61,7 @@ tw_sighandler_t tw_sigign(int sig);
|
|||
///////////////////////////////////////////////////////////////////////////////
|
||||
// tw_HandleSignal --wrapper around signal( XXX, <our handler function> )
|
||||
//
|
||||
tw_sighandler_t tw_HandleSignal( int sig );
|
||||
tw_sighandler_t tw_HandleSignal(int sig);
|
||||
|
||||
|
||||
#endif //__TW_SIGNAL_H
|
||||
|
||||
|
|
|
@ -3,29 +3,29 @@
|
|||
// Portions created by Tripwire, Inc. are copyright (C) 2000-2018 Tripwire,
|
||||
// Inc. Tripwire is a registered trademark of Tripwire, Inc. All rights
|
||||
// reserved.
|
||||
//
|
||||
//
|
||||
// This program is free software. The contents of this file are subject
|
||||
// to the terms of the GNU General Public License as published by the
|
||||
// Free Software Foundation; either version 2 of the License, or (at your
|
||||
// option) any later version. You may redistribute it and/or modify it
|
||||
// only in compliance with the GNU General Public License.
|
||||
//
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful.
|
||||
// However, this program is distributed AS-IS WITHOUT ANY
|
||||
// WARRANTY; INCLUDING THE IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS
|
||||
// FOR A PARTICULAR PURPOSE. Please see the GNU General Public License
|
||||
// for more details.
|
||||
//
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
|
||||
// USA.
|
||||
//
|
||||
//
|
||||
// Nothing in the GNU General Public License or any other license to use
|
||||
// the code or files shall permit you to use Tripwire's trademarks,
|
||||
// service marks, or other intellectual property without Tripwire's
|
||||
// prior written consent.
|
||||
//
|
||||
//
|
||||
// If you have any questions, please contact Tripwire, Inc. at either
|
||||
// info@tripwire.org or www.tripwire.org.
|
||||
//
|
||||
|
@ -44,9 +44,9 @@
|
|||
// METHOD CODE
|
||||
//=========================================================================
|
||||
|
||||
bool cInterpretInt::InterpretInt( const TSTRING& str, int* pi )
|
||||
bool cInterpretInt::InterpretInt(const TSTRING& str, int* pi)
|
||||
{
|
||||
ASSERT( pi != 0);
|
||||
ASSERT(pi != 0);
|
||||
|
||||
bool fFormatOK = true;
|
||||
|
||||
|
@ -55,21 +55,21 @@ bool cInterpretInt::InterpretInt( const TSTRING& str, int* pi )
|
|||
//
|
||||
TOSTRINGSTREAM sstr;
|
||||
sstr << cInterpretInt::LIMIT_MAX;
|
||||
if( str.length() > sstr.str().length() )
|
||||
if (str.length() > sstr.str().length())
|
||||
fFormatOK = false;
|
||||
|
||||
//
|
||||
// make sure string is not too short
|
||||
//
|
||||
if( fFormatOK && str.length() <= 0 )
|
||||
if (fFormatOK && str.length() <= 0)
|
||||
fFormatOK = false;
|
||||
|
||||
//
|
||||
// make sure first character is a digit or the minus sign
|
||||
//
|
||||
if( fFormatOK )
|
||||
if (fFormatOK)
|
||||
{
|
||||
if( ! ( _T('-') == str[0] || std::isdigit<TCHAR>( str[0], std::locale() ) ) )
|
||||
if (!(_T('-') == str[0] || std::isdigit<TCHAR>(str[0], std::locale())))
|
||||
fFormatOK = false;
|
||||
}
|
||||
|
||||
|
@ -77,23 +77,22 @@ bool cInterpretInt::InterpretInt( const TSTRING& str, int* pi )
|
|||
// make sure all other characters are digits
|
||||
// NOTE:BAM -- this assumes that all digits in all locales are SB characters.
|
||||
// TODO:BAM -- check this...
|
||||
for( TSTRING::size_type j = 1; fFormatOK && j < str.length(); j++ )
|
||||
for (TSTRING::size_type j = 1; fFormatOK && j < str.length(); j++)
|
||||
{
|
||||
if( ! std::isdigit<TCHAR>( str[j], std::locale() ) )
|
||||
if (!std::isdigit<TCHAR>(str[j], std::locale()))
|
||||
fFormatOK = false;
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// do _ttoi conversion and check that it is within allowable limits
|
||||
//
|
||||
if( fFormatOK )
|
||||
if (fFormatOK)
|
||||
{
|
||||
*pi = _ttoi( str.c_str() );
|
||||
*pi = _ttoi(str.c_str());
|
||||
|
||||
if( *pi < GetMin() || *pi > GetMax() )
|
||||
if (*pi < GetMin() || *pi > GetMax())
|
||||
fFormatOK = false;
|
||||
}
|
||||
|
||||
return fFormatOK;
|
||||
return fFormatOK;
|
||||
}
|
||||
|
||||
|
|
|
@ -3,29 +3,29 @@
|
|||
// Portions created by Tripwire, Inc. are copyright (C) 2000-2018 Tripwire,
|
||||
// Inc. Tripwire is a registered trademark of Tripwire, Inc. All rights
|
||||
// reserved.
|
||||
//
|
||||
//
|
||||
// This program is free software. The contents of this file are subject
|
||||
// to the terms of the GNU General Public License as published by the
|
||||
// Free Software Foundation; either version 2 of the License, or (at your
|
||||
// option) any later version. You may redistribute it and/or modify it
|
||||
// only in compliance with the GNU General Public License.
|
||||
//
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful.
|
||||
// However, this program is distributed AS-IS WITHOUT ANY
|
||||
// WARRANTY; INCLUDING THE IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS
|
||||
// FOR A PARTICULAR PURPOSE. Please see the GNU General Public License
|
||||
// for more details.
|
||||
//
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
|
||||
// USA.
|
||||
//
|
||||
//
|
||||
// Nothing in the GNU General Public License or any other license to use
|
||||
// the code or files shall permit you to use Tripwire's trademarks,
|
||||
// service marks, or other intellectual property without Tripwire's
|
||||
// prior written consent.
|
||||
//
|
||||
//
|
||||
// If you have any questions, please contact Tripwire, Inc. at either
|
||||
// info@tripwire.org or www.tripwire.org.
|
||||
//
|
||||
|
@ -33,9 +33,9 @@
|
|||
// twlimits.h
|
||||
//
|
||||
// this file contains classes that contain informations regarding
|
||||
// "limits" that need to be shared between files. The classes should only
|
||||
// "limits" that need to be shared between files. The classes should only
|
||||
// contain minimal functionality in support of these limits.
|
||||
//
|
||||
//
|
||||
//
|
||||
|
||||
#ifndef __TWLIMITS_H
|
||||
|
@ -68,15 +68,15 @@ public:
|
|||
//
|
||||
// basic functionality
|
||||
//
|
||||
bool InterpretInt( const TSTRING& str, int* pi );
|
||||
// converts the string into an int value, returned in *pi.
|
||||
// returns true if successfully converted value.
|
||||
// *pi is undefined if function returns false.
|
||||
bool InterpretInt(const TSTRING& str, int* pi);
|
||||
// converts the string into an int value, returned in *pi.
|
||||
// returns true if successfully converted value.
|
||||
// *pi is undefined if function returns false.
|
||||
|
||||
private:
|
||||
//
|
||||
// private enums
|
||||
//
|
||||
//
|
||||
enum Limits
|
||||
{
|
||||
LIMIT_MIN = INT_MIN,
|
||||
|
@ -86,11 +86,19 @@ private:
|
|||
//
|
||||
// private functionality
|
||||
//
|
||||
virtual int GetMax() { return LIMIT_MAX; };
|
||||
virtual int GetMin() { return LIMIT_MIN; };
|
||||
virtual int GetMax()
|
||||
{
|
||||
return LIMIT_MAX;
|
||||
};
|
||||
virtual int GetMin()
|
||||
{
|
||||
return LIMIT_MIN;
|
||||
};
|
||||
|
||||
public:
|
||||
virtual ~cInterpretInt() {}
|
||||
virtual ~cInterpretInt()
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////
|
||||
|
@ -105,11 +113,19 @@ private:
|
|||
LIMIT_MAX = 1000000
|
||||
};
|
||||
|
||||
virtual int GetMax() { return LIMIT_MAX; };
|
||||
virtual int GetMin() { return LIMIT_MIN; };
|
||||
virtual int GetMax()
|
||||
{
|
||||
return LIMIT_MAX;
|
||||
};
|
||||
virtual int GetMin()
|
||||
{
|
||||
return LIMIT_MIN;
|
||||
};
|
||||
|
||||
public:
|
||||
virtual ~cSeverityLimits() {}
|
||||
virtual ~cSeverityLimits()
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////
|
||||
|
@ -123,13 +139,20 @@ private:
|
|||
LIMIT_MIN = -1,
|
||||
LIMIT_MAX = 1000000
|
||||
};
|
||||
|
||||
virtual int GetMax() { return LIMIT_MAX; };
|
||||
virtual int GetMin() { return LIMIT_MIN; };
|
||||
|
||||
virtual int GetMax()
|
||||
{
|
||||
return LIMIT_MAX;
|
||||
};
|
||||
virtual int GetMin()
|
||||
{
|
||||
return LIMIT_MIN;
|
||||
};
|
||||
|
||||
public:
|
||||
virtual ~cRecurseDepthLimits() {}
|
||||
virtual ~cRecurseDepthLimits()
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
#endif //__TWLIMITS_H
|
||||
|
||||
|
|
|
@ -3,29 +3,29 @@
|
|||
// Portions created by Tripwire, Inc. are copyright (C) 2000-2018 Tripwire,
|
||||
// Inc. Tripwire is a registered trademark of Tripwire, Inc. All rights
|
||||
// reserved.
|
||||
//
|
||||
//
|
||||
// This program is free software. The contents of this file are subject
|
||||
// to the terms of the GNU General Public License as published by the
|
||||
// Free Software Foundation; either version 2 of the License, or (at your
|
||||
// option) any later version. You may redistribute it and/or modify it
|
||||
// only in compliance with the GNU General Public License.
|
||||
//
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful.
|
||||
// However, this program is distributed AS-IS WITHOUT ANY
|
||||
// WARRANTY; INCLUDING THE IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS
|
||||
// FOR A PARTICULAR PURPOSE. Please see the GNU General Public License
|
||||
// for more details.
|
||||
//
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
|
||||
// USA.
|
||||
//
|
||||
//
|
||||
// Nothing in the GNU General Public License or any other license to use
|
||||
// the code or files shall permit you to use Tripwire's trademarks,
|
||||
// service marks, or other intellectual property without Tripwire's
|
||||
// prior written consent.
|
||||
//
|
||||
//
|
||||
// If you have any questions, please contact Tripwire, Inc. at either
|
||||
// info@tripwire.org or www.tripwire.org.
|
||||
//
|
||||
|
@ -57,11 +57,11 @@
|
|||
//=========================================================================
|
||||
// UTIL FUNCTION PROTOTYPES
|
||||
//=========================================================================
|
||||
static TSTRING& util_FormatTimeC( struct tm* ptm, TSTRING& strBuf );
|
||||
static TSTRING& util_FormatTime( struct tm* ptm, TSTRING& strBuf );
|
||||
static TSTRING& util_FormatTimeC(struct tm* ptm, TSTRING& strBuf);
|
||||
static TSTRING& util_FormatTime(struct tm* ptm, TSTRING& strBuf);
|
||||
|
||||
#if !USES_CLIB_DATE_FUNCTION
|
||||
static TSTRING& util_FormatTimeCPlusPlus( struct tm* ptm, TSTRING& strBuf );
|
||||
static TSTRING& util_FormatTimeCPlusPlus(struct tm* ptm, TSTRING& strBuf);
|
||||
#endif
|
||||
|
||||
//=========================================================================
|
||||
|
@ -69,39 +69,38 @@ static TSTRING& util_FormatTimeCPlusPlus( struct tm* ptm, TSTRING& strBuf );
|
|||
//=========================================================================
|
||||
|
||||
#if IS_AROS
|
||||
#define tzset()
|
||||
# define tzset()
|
||||
#endif
|
||||
|
||||
void cTWLocale::InitGlobalLocale()
|
||||
{
|
||||
cDebug d("cTWLocale::InitGlobalLocale");
|
||||
|
||||
d.TraceDetail( "Attempting to set the program locale from the"
|
||||
"default \"C\" locale to the system-default locale." );
|
||||
d.TraceDetail("Attempting to set the program locale from the"
|
||||
"default \"C\" locale to the system-default locale.");
|
||||
|
||||
#if USE_CLIB_LOCALE
|
||||
char* pchLocale = setlocale( LC_ALL, "" );
|
||||
|
||||
d.TraceDetail( "C++ locale is incomplete or unavailable with this compiler, so"
|
||||
"only changing the C-language locale. Some C++ locale-specific functionality"
|
||||
"may not function properly." );
|
||||
char* pchLocale = setlocale(LC_ALL, "");
|
||||
|
||||
if( pchLocale )
|
||||
d.TraceDetail("C++ locale is incomplete or unavailable with this compiler, so"
|
||||
"only changing the C-language locale. Some C++ locale-specific functionality"
|
||||
"may not function properly.");
|
||||
|
||||
if (pchLocale)
|
||||
{
|
||||
d.TraceDebug( "locale changed to the system-default locale (non-C++): <%s>\n", pchLocale );
|
||||
d.TraceDebug("locale changed to the system-default locale (non-C++): <%s>\n", pchLocale);
|
||||
}
|
||||
else
|
||||
{
|
||||
d.TraceDebug( "Error: unable to change locale to the system-default.\n"
|
||||
"It is possible that there is no other locale than\n"
|
||||
"the \"C\" locale on this platform.\n" );
|
||||
d.TraceDebug("Error: unable to change locale to the system-default.\n"
|
||||
"It is possible that there is no other locale than\n"
|
||||
"the \"C\" locale on this platform.\n");
|
||||
}
|
||||
#else
|
||||
std::locale l("");
|
||||
std::locale::global( l );
|
||||
d.TraceDebug( "locale changed to the system default std::locale (C++): <%s>\n", l.name().c_str() );
|
||||
std::locale::global(l);
|
||||
d.TraceDebug("locale changed to the system default std::locale (C++): <%s>\n", l.name().c_str());
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -128,67 +127,56 @@ TSTRING cTWLocale::FormatNumberAsHex( int32 i )
|
|||
}
|
||||
*/
|
||||
|
||||
template< class numT, class CharT >
|
||||
class cFormatNumberUtil
|
||||
template<class numT, class CharT> class cFormatNumberUtil
|
||||
{
|
||||
public:
|
||||
|
||||
// TODO:BAM -- these functions should really maybe take a stringstream that has been
|
||||
// already set up for formatting (basefield, locale, etc.) that way we can merge
|
||||
//. the FormatNumberAsHex function as well
|
||||
//
|
||||
//=============================================================================
|
||||
// template< class numT, class CharT >
|
||||
// numT
|
||||
// numT
|
||||
// cFormatNumberUtil::FormatNumber( const std::basic_string< CharT >& s, bool fCStyleFormatting = false )
|
||||
//-----------------------------------------------------------------------------
|
||||
// EFFECTS: Does all actual formatting for FormatNumber methods
|
||||
static
|
||||
numT
|
||||
Format( const std::basic_string< CharT >& s, bool fCStyleFormatting )
|
||||
static numT Format(const std::basic_string<CharT>& s, bool fCStyleFormatting)
|
||||
{
|
||||
static const std::num_get< CharT >* png;
|
||||
std::basic_istringstream< CharT > ss( s );
|
||||
std::ios_base::iostate state;
|
||||
numT n;
|
||||
static const std::num_get<CharT>* png;
|
||||
std::basic_istringstream<CharT> ss(s);
|
||||
std::ios_base::iostate state;
|
||||
numT n;
|
||||
|
||||
if( fCStyleFormatting )
|
||||
ss.imbue( std::locale::classic() );
|
||||
if (fCStyleFormatting)
|
||||
ss.imbue(std::locale::classic());
|
||||
|
||||
tss::GetFacet( ss.getloc(), png ).get(
|
||||
ss,
|
||||
std::istreambuf_iterator< CharT >(),
|
||||
ss,
|
||||
state,
|
||||
n );
|
||||
tss::GetFacet(ss.getloc(), png).get(ss, std::istreambuf_iterator<CharT>(), ss, state, n);
|
||||
|
||||
|
||||
if( ( state & std::ios_base::failbit ) != 0 )
|
||||
if ((state & std::ios_base::failbit) != 0)
|
||||
throw eTWLocaleBadNumFormat();
|
||||
|
||||
return( n );
|
||||
return (n);
|
||||
}
|
||||
|
||||
//=============================================================================
|
||||
// std::basic_string< CharT >&
|
||||
// std::basic_string< CharT >&
|
||||
// Format( numT n, std::basic_string< CharT >& sBuf )
|
||||
//-----------------------------------------------------------------------------
|
||||
// EFFECTS: Does all actual formatting for FormatNumber methods
|
||||
//
|
||||
static
|
||||
std::basic_string< CharT >&
|
||||
Format( numT n, std::basic_string< CharT >& sBuf, bool fCStyleFormatting = false )
|
||||
//
|
||||
static std::basic_string<CharT>& Format(numT n, std::basic_string<CharT>& sBuf, bool fCStyleFormatting = false)
|
||||
{
|
||||
static const std::num_put< CharT >* pnp;
|
||||
std::basic_ostringstream< CharT > ss;
|
||||
static const std::num_put<CharT>* pnp;
|
||||
std::basic_ostringstream<CharT> ss;
|
||||
|
||||
if( fCStyleFormatting )
|
||||
ss.imbue( std::locale::classic() );
|
||||
if (fCStyleFormatting)
|
||||
ss.imbue(std::locale::classic());
|
||||
|
||||
tss::GetFacet( ss.getloc(), pnp ).put( ss, ss, ss.fill(), n );
|
||||
tss::GetFacet(ss.getloc(), pnp).put(ss, ss, ss.fill(), n);
|
||||
|
||||
sBuf = ss.str();
|
||||
return( sBuf );
|
||||
return (sBuf);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -205,102 +193,102 @@ int32 cTWLocale::FormatNumberClassic( const TSTRING& s )
|
|||
}
|
||||
*/
|
||||
|
||||
TSTRING& cTWLocale::FormatNumber( uint64 ui, TSTRING& strBuf )
|
||||
TSTRING& cTWLocale::FormatNumber(uint64 ui, TSTRING& strBuf)
|
||||
{
|
||||
// try to use the int64 version
|
||||
if( ui <= (uint64)TSS_INT64_MAX )
|
||||
return( FormatNumber( (int64)ui, strBuf ) );
|
||||
if (ui <= (uint64)TSS_INT64_MAX)
|
||||
return (FormatNumber((int64)ui, strBuf));
|
||||
else
|
||||
{
|
||||
#if IS_MSVC
|
||||
// MSVC can't convert from uint64 to a double for some reason
|
||||
strBuf = TSS_GetString( cCore, core::STR_NUMBER_TOO_BIG );
|
||||
return( strBuf );
|
||||
#else
|
||||
ASSERT( std::numeric_limits<double>::max() >= TSS_UINT64_MAX );
|
||||
return( cFormatNumberUtil< double, TCHAR >::Format( (double)ui, strBuf ) );
|
||||
#endif
|
||||
#if IS_MSVC
|
||||
// MSVC can't convert from uint64 to a double for some reason
|
||||
strBuf = TSS_GetString(cCore, core::STR_NUMBER_TOO_BIG);
|
||||
return (strBuf);
|
||||
#else
|
||||
ASSERT(std::numeric_limits<double>::max() >= TSS_UINT64_MAX);
|
||||
return (cFormatNumberUtil<double, TCHAR>::Format((double)ui, strBuf));
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
TSTRING& cTWLocale::FormatNumber( int64 i, TSTRING& strBuf )
|
||||
TSTRING& cTWLocale::FormatNumber(int64 i, TSTRING& strBuf)
|
||||
{
|
||||
// try to use the int32 version
|
||||
if( i <= (int64)TSS_INT32_MAX )
|
||||
return( FormatNumber( (int32)i, strBuf ) );
|
||||
if (i <= (int64)TSS_INT32_MAX)
|
||||
return (FormatNumber((int32)i, strBuf));
|
||||
else
|
||||
{
|
||||
ASSERT( std::numeric_limits<double>::max() >= TSS_INT64_MAX );
|
||||
return( cFormatNumberUtil< double, TCHAR >::Format( (double)i, strBuf ) );
|
||||
ASSERT(std::numeric_limits<double>::max() >= TSS_INT64_MAX);
|
||||
return (cFormatNumberUtil<double, TCHAR>::Format((double)i, strBuf));
|
||||
}
|
||||
}
|
||||
|
||||
TSTRING& cTWLocale::FormatNumber( uint32 ui, TSTRING& strBuf )
|
||||
{
|
||||
ASSERT( sizeof(unsigned long) >= sizeof(uint32) ); // must be able to cast to 'ulong'
|
||||
return( cFormatNumberUtil< unsigned long, TCHAR >::Format( (unsigned long)ui, strBuf ) );
|
||||
TSTRING& cTWLocale::FormatNumber(uint32 ui, TSTRING& strBuf)
|
||||
{
|
||||
ASSERT(sizeof(unsigned long) >= sizeof(uint32)); // must be able to cast to 'ulong'
|
||||
return (cFormatNumberUtil<unsigned long, TCHAR>::Format((unsigned long)ui, strBuf));
|
||||
}
|
||||
|
||||
TSTRING& cTWLocale::FormatNumber( int32 i, TSTRING& strBuf )
|
||||
{
|
||||
ASSERT( sizeof(long) >= sizeof(int32) ); // must be able to cast to 'long'
|
||||
return( cFormatNumberUtil< long, TCHAR >::Format( (long)i, strBuf ) );
|
||||
TSTRING& cTWLocale::FormatNumber(int32 i, TSTRING& strBuf)
|
||||
{
|
||||
ASSERT(sizeof(long) >= sizeof(int32)); // must be able to cast to 'long'
|
||||
return (cFormatNumberUtil<long, TCHAR>::Format((long)i, strBuf));
|
||||
}
|
||||
|
||||
TSTRING& cTWLocale::FormatTime( int64 t, TSTRING& strBuf )
|
||||
TSTRING& cTWLocale::FormatTime(int64 t, TSTRING& strBuf)
|
||||
{
|
||||
// clear return string
|
||||
strBuf.erase();
|
||||
tzset();
|
||||
time_t tmpTime = t;
|
||||
struct tm * ptm = localtime( &tmpTime );
|
||||
if( ptm )
|
||||
time_t tmpTime = t;
|
||||
struct tm* ptm = localtime(&tmpTime);
|
||||
if (ptm)
|
||||
{
|
||||
util_FormatTime( ptm, strBuf );
|
||||
util_FormatTime(ptm, strBuf);
|
||||
}
|
||||
else
|
||||
{
|
||||
strBuf = TSS_GetString( cCore, core::STR_UNKNOWN_TIME );
|
||||
strBuf = TSS_GetString(cCore, core::STR_UNKNOWN_TIME);
|
||||
}
|
||||
|
||||
return( strBuf );
|
||||
return (strBuf);
|
||||
}
|
||||
|
||||
//=========================================================================
|
||||
// UTIL FUNCTION IMPLEMENTATION
|
||||
//=========================================================================
|
||||
|
||||
TSTRING& util_FormatTime( struct tm* ptm, TSTRING& strBuf )
|
||||
TSTRING& util_FormatTime(struct tm* ptm, TSTRING& strBuf)
|
||||
{
|
||||
ASSERT( ptm );
|
||||
|
||||
#if USES_CLIB_DATE_FUNCTION
|
||||
ASSERT(ptm);
|
||||
|
||||
return util_FormatTimeC( ptm, strBuf );
|
||||
#if USES_CLIB_DATE_FUNCTION
|
||||
|
||||
#else
|
||||
return util_FormatTimeC(ptm, strBuf);
|
||||
|
||||
return util_FormatTimeCPlusPlus( ptm, strBuf );
|
||||
#else
|
||||
|
||||
#endif
|
||||
return util_FormatTimeCPlusPlus(ptm, strBuf);
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
#if !USES_CLIB_DATE_FUNCTION
|
||||
TSTRING& util_FormatTimeCPlusPlus( struct tm* ptm, TSTRING& strBuf )
|
||||
TSTRING& util_FormatTimeCPlusPlus(struct tm* ptm, TSTRING& strBuf)
|
||||
{
|
||||
ASSERT( ptm );
|
||||
TOSTRINGSTREAM sstr;
|
||||
ASSERT(ptm);
|
||||
TOSTRINGSTREAM sstr;
|
||||
static const std::time_put<TCHAR>* ptp;
|
||||
|
||||
|
||||
//
|
||||
// format date
|
||||
//
|
||||
#if IS_MSVC // MSVC uses old put() signature which didn't have the fill character, (and uses proprietary '#')
|
||||
tss::GetFacet( sstr.getloc(), ptp ).put( sstr, sstr, ptm, 'c', '#' );
|
||||
#else
|
||||
tss::GetFacet( sstr.getloc(), ptp ).put( sstr, sstr, sstr.fill(), ptm, 'c' );
|
||||
#endif
|
||||
# if IS_MSVC // MSVC uses old put() signature which didn't have the fill character, (and uses proprietary '#')
|
||||
tss::GetFacet(sstr.getloc(), ptp).put(sstr, sstr, ptm, 'c', '#');
|
||||
# else
|
||||
tss::GetFacet(sstr.getloc(), ptp).put(sstr, sstr, sstr.fill(), ptm, 'c');
|
||||
# endif
|
||||
|
||||
strBuf = sstr.str();
|
||||
return strBuf;
|
||||
|
@ -308,27 +296,27 @@ TSTRING& util_FormatTimeCPlusPlus( struct tm* ptm, TSTRING& strBuf )
|
|||
#endif
|
||||
|
||||
|
||||
TSTRING& util_FormatTimeC( struct tm* ptm, TSTRING& strBuf )
|
||||
TSTRING& util_FormatTimeC(struct tm* ptm, TSTRING& strBuf)
|
||||
{
|
||||
ASSERT( ptm );
|
||||
|
||||
ASSERT(ptm);
|
||||
|
||||
TCHAR achTimeBuf[256];
|
||||
|
||||
/* XXX: This should check (#ifdef) for strftime - PH */
|
||||
size_t nbWritten = _tcsftime( achTimeBuf, countof( achTimeBuf ),
|
||||
|
||||
#if IS_MSVC // MSVC uses proprietary '#'
|
||||
_T("%#c"),
|
||||
#else
|
||||
_T("%c"),
|
||||
#endif
|
||||
ptm );
|
||||
size_t nbWritten = _tcsftime(achTimeBuf,
|
||||
countof(achTimeBuf),
|
||||
|
||||
if( nbWritten )
|
||||
#if IS_MSVC // MSVC uses proprietary '#'
|
||||
_T("%#c"),
|
||||
#else
|
||||
_T("%c"),
|
||||
#endif
|
||||
ptm);
|
||||
|
||||
if (nbWritten)
|
||||
strBuf = achTimeBuf;
|
||||
else
|
||||
strBuf = TSS_GetString( cCore, core::STR_UNKNOWN_TIME );
|
||||
strBuf = TSS_GetString(cCore, core::STR_UNKNOWN_TIME);
|
||||
|
||||
return strBuf;
|
||||
}
|
||||
|
||||
|
|
|
@ -3,29 +3,29 @@
|
|||
// Portions created by Tripwire, Inc. are copyright (C) 2000-2018 Tripwire,
|
||||
// Inc. Tripwire is a registered trademark of Tripwire, Inc. All rights
|
||||
// reserved.
|
||||
//
|
||||
//
|
||||
// This program is free software. The contents of this file are subject
|
||||
// to the terms of the GNU General Public License as published by the
|
||||
// Free Software Foundation; either version 2 of the License, or (at your
|
||||
// option) any later version. You may redistribute it and/or modify it
|
||||
// only in compliance with the GNU General Public License.
|
||||
//
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful.
|
||||
// However, this program is distributed AS-IS WITHOUT ANY
|
||||
// WARRANTY; INCLUDING THE IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS
|
||||
// FOR A PARTICULAR PURPOSE. Please see the GNU General Public License
|
||||
// for more details.
|
||||
//
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
|
||||
// USA.
|
||||
//
|
||||
//
|
||||
// Nothing in the GNU General Public License or any other license to use
|
||||
// the code or files shall permit you to use Tripwire's trademarks,
|
||||
// service marks, or other intellectual property without Tripwire's
|
||||
// prior written consent.
|
||||
//
|
||||
//
|
||||
// If you have any questions, please contact Tripwire, Inc. at either
|
||||
// info@tripwire.org or www.tripwire.org.
|
||||
//
|
||||
|
@ -52,8 +52,8 @@
|
|||
// DECLARATION OF CLASSES
|
||||
//=========================================================================
|
||||
|
||||
TSS_EXCEPTION( eTWLocale, eError );
|
||||
TSS_EXCEPTION( eTWLocaleBadNumFormat, eError );
|
||||
TSS_EXCEPTION(eTWLocale, eError);
|
||||
TSS_EXCEPTION(eTWLocaleBadNumFormat, eError);
|
||||
|
||||
///////////////////////////////////////////////
|
||||
// cTWLocale
|
||||
|
@ -68,30 +68,30 @@ class cTWLocale
|
|||
{
|
||||
public:
|
||||
static void InitGlobalLocale();
|
||||
// initializes global locale to the default locale
|
||||
// initializes global locale to the default locale
|
||||
|
||||
//
|
||||
// basic functionality
|
||||
//
|
||||
static TSTRING& FormatNumber( int32 i, TSTRING& strBuf );
|
||||
static TSTRING& FormatNumber( int64 i, TSTRING& strBuf );
|
||||
static TSTRING& FormatNumber( uint32 ui, TSTRING& strBuf );
|
||||
static TSTRING& FormatNumber( uint64 ui, TSTRING& strBuf );
|
||||
static TSTRING& FormatNumber( double d, TSTRING& strBuf );
|
||||
// returns the locale-specific representation of the given cardinal number
|
||||
/*
|
||||
static TSTRING& FormatNumber(int32 i, TSTRING& strBuf);
|
||||
static TSTRING& FormatNumber(int64 i, TSTRING& strBuf);
|
||||
static TSTRING& FormatNumber(uint32 ui, TSTRING& strBuf);
|
||||
static TSTRING& FormatNumber(uint64 ui, TSTRING& strBuf);
|
||||
static TSTRING& FormatNumber(double d, TSTRING& strBuf);
|
||||
// returns the locale-specific representation of the given cardinal number
|
||||
/*
|
||||
static TSTRING FormatNumberClassic( int32 i );
|
||||
static int32 FormatNumberClassic( const TSTRING& s );
|
||||
// returns the C-locale representation of the given cardinal number
|
||||
*/
|
||||
// disabled this since nobody's using it
|
||||
// static TSTRING FormatNumberAsHex( int32 x );
|
||||
// locale-independant
|
||||
// disabled this since nobody's using it
|
||||
// static TSTRING FormatNumberAsHex( int32 x );
|
||||
// locale-independant
|
||||
|
||||
static TSTRING& FormatTime( int64 t, TSTRING& strBuf );
|
||||
// returns the local time and date formatted according to the current locale.
|
||||
// t is the number of seconds elapsed since midnight (00:00:00),
|
||||
// January 1, 1970, coordinated universal time
|
||||
static TSTRING& FormatTime(int64 t, TSTRING& strBuf);
|
||||
// returns the local time and date formatted according to the current locale.
|
||||
// t is the number of seconds elapsed since midnight (00:00:00),
|
||||
// January 1, 1970, coordinated universal time
|
||||
};
|
||||
|
||||
//=========================================================================
|
||||
|
@ -100,22 +100,21 @@ public:
|
|||
|
||||
namespace tss
|
||||
{
|
||||
////////////////////////////////////////////////
|
||||
// GetFacet
|
||||
//
|
||||
// Abstracts std::use_facet since Win32 and KAI
|
||||
// each implement it in a non-standard way.
|
||||
////////////////////////////////////////////////
|
||||
template< class FacetT > inline const FacetT& GetFacet( const std::locale& l, const FacetT* pf )
|
||||
{
|
||||
////////////////////////////////////////////////
|
||||
// GetFacet
|
||||
//
|
||||
// Abstracts std::use_facet since Win32 and KAI
|
||||
// each implement it in a non-standard way.
|
||||
////////////////////////////////////////////////
|
||||
template<class FacetT> inline const FacetT& GetFacet(const std::locale& l, const FacetT* pf)
|
||||
{
|
||||
#if USE_STD_CPP_LOCALE_WORKAROUND
|
||||
return std::use_facet( l, pf );
|
||||
return std::use_facet(l, pf);
|
||||
#else
|
||||
return std::use_facet< FacetT >( l ); (void)pf; // This is C++ standard
|
||||
return std::use_facet<FacetT>(l);
|
||||
(void)pf; // This is C++ standard
|
||||
#endif
|
||||
}
|
||||
}
|
||||
} // namespace tss
|
||||
|
||||
#endif //__TWLOCALE_H
|
||||
|
||||
|
||||
|
|
|
@ -3,29 +3,29 @@
|
|||
// Portions created by Tripwire, Inc. are copyright (C) 2000-2018 Tripwire,
|
||||
// Inc. Tripwire is a registered trademark of Tripwire, Inc. All rights
|
||||
// reserved.
|
||||
//
|
||||
//
|
||||
// This program is free software. The contents of this file are subject
|
||||
// to the terms of the GNU General Public License as published by the
|
||||
// Free Software Foundation; either version 2 of the License, or (at your
|
||||
// option) any later version. You may redistribute it and/or modify it
|
||||
// only in compliance with the GNU General Public License.
|
||||
//
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful.
|
||||
// However, this program is distributed AS-IS WITHOUT ANY
|
||||
// WARRANTY; INCLUDING THE IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS
|
||||
// FOR A PARTICULAR PURPOSE. Please see the GNU General Public License
|
||||
// for more details.
|
||||
//
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
|
||||
// USA.
|
||||
//
|
||||
//
|
||||
// Nothing in the GNU General Public License or any other license to use
|
||||
// the code or files shall permit you to use Tripwire's trademarks,
|
||||
// service marks, or other intellectual property without Tripwire's
|
||||
// prior written consent.
|
||||
//
|
||||
//
|
||||
// If you have any questions, please contact Tripwire, Inc. at either
|
||||
// info@tripwire.org or www.tripwire.org.
|
||||
//
|
||||
|
@ -36,10 +36,9 @@
|
|||
#ifndef __TWSTRINGSLANG_H
|
||||
#define __TWSTRINGSLANG_H
|
||||
|
||||
enum Languages
|
||||
enum Languages
|
||||
{
|
||||
LANG_USENGLISH = 1
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
@ -3,29 +3,29 @@
|
|||
// Portions created by Tripwire, Inc. are copyright (C) 2000-2018 Tripwire,
|
||||
// Inc. Tripwire is a registered trademark of Tripwire, Inc. All rights
|
||||
// reserved.
|
||||
//
|
||||
//
|
||||
// This program is free software. The contents of this file are subject
|
||||
// to the terms of the GNU General Public License as published by the
|
||||
// Free Software Foundation; either version 2 of the License, or (at your
|
||||
// option) any later version. You may redistribute it and/or modify it
|
||||
// only in compliance with the GNU General Public License.
|
||||
//
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful.
|
||||
// However, this program is distributed AS-IS WITHOUT ANY
|
||||
// WARRANTY; INCLUDING THE IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS
|
||||
// FOR A PARTICULAR PURPOSE. Please see the GNU General Public License
|
||||
// for more details.
|
||||
//
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
|
||||
// USA.
|
||||
//
|
||||
//
|
||||
// Nothing in the GNU General Public License or any other license to use
|
||||
// the code or files shall permit you to use Tripwire's trademarks,
|
||||
// service marks, or other intellectual property without Tripwire's
|
||||
// prior written consent.
|
||||
//
|
||||
//
|
||||
// If you have any questions, please contact Tripwire, Inc. at either
|
||||
// info@tripwire.org or www.tripwire.org.
|
||||
//
|
||||
|
@ -45,10 +45,11 @@ class cType
|
|||
{
|
||||
public:
|
||||
cType(const TCHAR* name);
|
||||
|
||||
|
||||
const TCHAR* AsString() const;
|
||||
bool operator==(const cType& rhs) const;
|
||||
bool operator!=(const cType& rhs) const;
|
||||
bool operator==(const cType& rhs) const;
|
||||
bool operator!=(const cType& rhs) const;
|
||||
|
||||
private:
|
||||
TSTRING mString;
|
||||
};
|
||||
|
@ -57,33 +58,35 @@ class iTyped
|
|||
{
|
||||
public:
|
||||
virtual const cType& GetType() const = 0;
|
||||
// the type of an FCO; classes that implement this interface need to
|
||||
// (a) declare a public static const cType member mType and
|
||||
// (b) returning that object in their implementation of GetType()
|
||||
// You can use the macros below to simplify the process
|
||||
// the type of an FCO; classes that implement this interface need to
|
||||
// (a) declare a public static const cType member mType and
|
||||
// (b) returning that object in their implementation of GetType()
|
||||
// You can use the macros below to simplify the process
|
||||
|
||||
virtual ~iTyped() {}
|
||||
virtual ~iTyped()
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
//////////////////////////////////////////////
|
||||
// convenience macros for implementing iTyped
|
||||
//////////////////////////////////////////////
|
||||
#define DECLARE_TYPED()\
|
||||
public:\
|
||||
static const cType mType;\
|
||||
virtual const cType& GetType() const;
|
||||
// put DECLARE_TYPED in the class definition
|
||||
#define DECLARE_TYPED() \
|
||||
public: \
|
||||
static const cType mType; \
|
||||
virtual const cType& GetType() const;
|
||||
// put DECLARE_TYPED in the class definition
|
||||
|
||||
#define IMPLEMENT_TYPED(CLASS, STRING)\
|
||||
const cType CLASS::mType(STRING);\
|
||||
const cType& CLASS::GetType() const\
|
||||
{\
|
||||
return mType;\
|
||||
}
|
||||
// put IMPLEMENT_TYPED in the .cpp file where the class is implemented
|
||||
#define IMPLEMENT_TYPED(CLASS, STRING) \
|
||||
const cType CLASS::mType(STRING); \
|
||||
const cType& CLASS::GetType() const \
|
||||
{ \
|
||||
return mType; \
|
||||
}
|
||||
// put IMPLEMENT_TYPED in the .cpp file where the class is implemented
|
||||
|
||||
#define CLASS_TYPE(CLASS) CLASS::mType
|
||||
// a convienent way to specify a class's type
|
||||
// a convienent way to specify a class's type
|
||||
|
||||
///////////////////////////////////////////////
|
||||
// iTyped Example
|
||||
|
@ -116,28 +119,26 @@ const cType& CLASS::GetType() const\
|
|||
///////////////////////////////////////////////////////////////////////////////
|
||||
// inline implementation
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
inline cType::cType(const TCHAR* name) :
|
||||
mString(name)
|
||||
inline cType::cType(const TCHAR* name) : mString(name)
|
||||
{
|
||||
ASSERT(!mString.empty());
|
||||
}
|
||||
|
||||
|
||||
inline const TCHAR* cType::AsString() const
|
||||
{
|
||||
return mString.c_str();
|
||||
inline const TCHAR* cType::AsString() const
|
||||
{
|
||||
return mString.c_str();
|
||||
}
|
||||
|
||||
inline bool cType::operator==(const cType& rhs) const
|
||||
{
|
||||
return (this == &rhs);
|
||||
inline bool cType::operator==(const cType& rhs) const
|
||||
{
|
||||
return (this == &rhs);
|
||||
}
|
||||
|
||||
inline bool cType::operator!=(const cType& rhs) const
|
||||
{
|
||||
return (this != &rhs);
|
||||
inline bool cType::operator!=(const cType& rhs) const
|
||||
{
|
||||
return (this != &rhs);
|
||||
}
|
||||
|
||||
|
||||
#endif //__TYPED_H
|
||||
|
||||
|
|
146
src/core/types.h
146
src/core/types.h
|
@ -3,29 +3,29 @@
|
|||
// Portions created by Tripwire, Inc. are copyright (C) 2000-2018 Tripwire,
|
||||
// Inc. Tripwire is a registered trademark of Tripwire, Inc. All rights
|
||||
// reserved.
|
||||
//
|
||||
//
|
||||
// This program is free software. The contents of this file are subject
|
||||
// to the terms of the GNU General Public License as published by the
|
||||
// Free Software Foundation; either version 2 of the License, or (at your
|
||||
// option) any later version. You may redistribute it and/or modify it
|
||||
// only in compliance with the GNU General Public License.
|
||||
//
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful.
|
||||
// However, this program is distributed AS-IS WITHOUT ANY
|
||||
// WARRANTY; INCLUDING THE IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS
|
||||
// FOR A PARTICULAR PURPOSE. Please see the GNU General Public License
|
||||
// for more details.
|
||||
//
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
|
||||
// USA.
|
||||
//
|
||||
//
|
||||
// Nothing in the GNU General Public License or any other license to use
|
||||
// the code or files shall permit you to use Tripwire's trademarks,
|
||||
// service marks, or other intellectual property without Tripwire's
|
||||
// prior written consent.
|
||||
//
|
||||
//
|
||||
// If you have any questions, please contact Tripwire, Inc. at either
|
||||
// info@tripwire.org or www.tripwire.org.
|
||||
//
|
||||
|
@ -41,46 +41,45 @@
|
|||
#endif
|
||||
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// standard TSS types
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
typedef unsigned char byte ; // platform-independent
|
||||
typedef unsigned char byte; // platform-independent
|
||||
|
||||
typedef signed char int8 ;
|
||||
typedef short int16 ;
|
||||
typedef float float32 ;
|
||||
typedef double float64 ;
|
||||
typedef unsigned char uint8 ;
|
||||
typedef unsigned short uint16 ;
|
||||
typedef signed char int8;
|
||||
typedef short int16;
|
||||
typedef float float32;
|
||||
typedef double float64;
|
||||
typedef unsigned char uint8;
|
||||
typedef unsigned short uint16;
|
||||
|
||||
#if HAVE_STDINT_H
|
||||
typedef int32_t int32 ;
|
||||
typedef uint32_t uint32 ;
|
||||
typedef int32_t int32;
|
||||
typedef uint32_t uint32;
|
||||
|
||||
#elif SIZEOF_INT == 4
|
||||
typedef int int32 ;
|
||||
typedef unsigned int uint32 ;
|
||||
typedef int int32;
|
||||
typedef unsigned int uint32;
|
||||
|
||||
#elif SIZEOF_LONG == 4
|
||||
typedef long int32 ;
|
||||
typedef unsigned long uint32 ;
|
||||
typedef long int32;
|
||||
typedef unsigned long uint32;
|
||||
#else
|
||||
# error "I don't seem to have a 32-bit integer type on this system."
|
||||
# error "I don't seem to have a 32-bit integer type on this system."
|
||||
#endif
|
||||
|
||||
#if HAVE_STDINT_H
|
||||
typedef int64_t int64 ;
|
||||
typedef uint64_t uint64 ;
|
||||
typedef int64_t int64;
|
||||
typedef uint64_t uint64;
|
||||
#elif SIZEOF_LONG == 8
|
||||
typedef long int64 ;
|
||||
typedef unsigned long uint64 ;
|
||||
typedef long int64;
|
||||
typedef unsigned long uint64;
|
||||
#elif SIZEOF_LONG_LONG == 8
|
||||
typedef long long int64 ;
|
||||
typedef unsigned long long uint64 ;
|
||||
typedef long long int64;
|
||||
typedef unsigned long long uint64;
|
||||
#else
|
||||
# error "I don't seem to have a 64-bit integer type on this system."
|
||||
# error "I don't seem to have a 64-bit integer type on this system."
|
||||
#endif
|
||||
|
||||
// other Win32 definitions
|
||||
|
@ -93,23 +92,23 @@ typedef unsigned long long uint64 ;
|
|||
|
||||
|
||||
#if (!(USES_2S_COMPLEMENT))
|
||||
#error limits.h depends on 2s complement integers. Check core/types.h
|
||||
# error limits.h depends on 2s complement integers. Check core/types.h
|
||||
#endif
|
||||
|
||||
#include <limits.h> // defines limits for built-in types
|
||||
|
||||
#define TSS_INT8_MIN (-127 - 1)
|
||||
#define TSS_INT8_MAX 127
|
||||
#define TSS_UINT8_MAX 0xFFU
|
||||
#define TSS_INT16_MIN (-32767 - 1)
|
||||
#define TSS_INT16_MAX 32767
|
||||
#define TSS_UINT16_MAX 0xFFFFU
|
||||
#define TSS_INT32_MIN (-2147483647 - 1)
|
||||
#define TSS_INT32_MAX 2147483647
|
||||
#define TSS_UINT32_MAX 0xFFFFFFFFU
|
||||
#define TSS_INT64_MIN (-9223372036854775807LL - 1)
|
||||
#define TSS_INT64_MAX 9223372036854775807LL
|
||||
#define TSS_UINT64_MAX 0xFFFFFFFFFFFFFFFFULL
|
||||
#define TSS_INT8_MIN (-127 - 1)
|
||||
#define TSS_INT8_MAX 127
|
||||
#define TSS_UINT8_MAX 0xFFU
|
||||
#define TSS_INT16_MIN (-32767 - 1)
|
||||
#define TSS_INT16_MAX 32767
|
||||
#define TSS_UINT16_MAX 0xFFFFU
|
||||
#define TSS_INT32_MIN (-2147483647 - 1)
|
||||
#define TSS_INT32_MAX 2147483647
|
||||
#define TSS_UINT32_MAX 0xFFFFFFFFU
|
||||
#define TSS_INT64_MIN (-9223372036854775807LL - 1)
|
||||
#define TSS_INT64_MAX 9223372036854775807LL
|
||||
#define TSS_UINT64_MAX 0xFFFFFFFFFFFFFFFFULL
|
||||
|
||||
/*
|
||||
//-----------------------------------------------------------------------------
|
||||
|
@ -153,64 +152,53 @@ namespace std
|
|||
// Byte Swapping
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
inline int16 SWAPBYTES16(int16 i)
|
||||
inline int16 SWAPBYTES16(int16 i)
|
||||
{
|
||||
|
||||
return ((uint16)i >> 8) | ((uint16)i << 8);
|
||||
|
||||
}
|
||||
|
||||
inline int32 SWAPBYTES32(int32 i)
|
||||
inline int32 SWAPBYTES32(int32 i)
|
||||
{
|
||||
return ((uint32)i >> 24) |
|
||||
(((uint32)i & 0x00ff0000) >> 8) |
|
||||
(((uint32)i & 0x0000ff00) << 8) |
|
||||
((uint32)i << 24);
|
||||
return ((uint32)i >> 24) | (((uint32)i & 0x00ff0000) >> 8) | (((uint32)i & 0x0000ff00) << 8) | ((uint32)i << 24);
|
||||
}
|
||||
|
||||
inline int64 SWAPBYTES64(int64 i)
|
||||
inline int64 SWAPBYTES64(int64 i)
|
||||
{
|
||||
return ((uint64)i >> 56) |
|
||||
(((uint64)i & 0x00ff000000000000ULL) >> 40) |
|
||||
(((uint64)i & 0x0000ff0000000000ULL) >> 24) |
|
||||
(((uint64)i & 0x000000ff00000000ULL) >> 8) |
|
||||
(((uint64)i & 0x00000000ff000000ULL) << 8) |
|
||||
(((uint64)i & 0x0000000000ff0000ULL) << 24) |
|
||||
(((uint64)i & 0x000000000000ff00ULL) << 40) |
|
||||
((uint64)i << 56);
|
||||
return ((uint64)i >> 56) | (((uint64)i & 0x00ff000000000000ULL) >> 40) |
|
||||
(((uint64)i & 0x0000ff0000000000ULL) >> 24) | (((uint64)i & 0x000000ff00000000ULL) >> 8) |
|
||||
(((uint64)i & 0x00000000ff000000ULL) << 8) | (((uint64)i & 0x0000000000ff0000ULL) << 24) |
|
||||
(((uint64)i & 0x000000000000ff00ULL) << 40) | ((uint64)i << 56);
|
||||
}
|
||||
|
||||
|
||||
#ifdef WORDS_BIGENDIAN
|
||||
# ifdef WORDS_BIGENDIAN
|
||||
|
||||
#define tw_htonl(x) (x)
|
||||
#define tw_ntohl(x) (x)
|
||||
#define tw_htons(x) (x)
|
||||
#define tw_ntohs(x) (x)
|
||||
#define tw_htonll(x) (x) // int64 versions
|
||||
#define tw_ntohll(x) (x)
|
||||
# define tw_htonl(x) (x)
|
||||
# define tw_ntohl(x) (x)
|
||||
# define tw_htons(x) (x)
|
||||
# define tw_ntohs(x) (x)
|
||||
# define tw_htonll(x) (x) // int64 versions
|
||||
# define tw_ntohll(x) (x)
|
||||
|
||||
#else //!WORDS_BIGENDIAN
|
||||
# else //!WORDS_BIGENDIAN
|
||||
|
||||
#define tw_htonl(x) SWAPBYTES32((x))
|
||||
#define tw_ntohl(x) SWAPBYTES32((x))
|
||||
#define tw_htons(x) SWAPBYTES16((x))
|
||||
#define tw_ntohs(x) SWAPBYTES16((x))
|
||||
#define tw_htonll(x) SWAPBYTES64((x)) // int64 versions
|
||||
#define tw_ntohll(x) SWAPBYTES64((x))
|
||||
# define tw_htonl(x) SWAPBYTES32((x))
|
||||
# define tw_ntohl(x) SWAPBYTES32((x))
|
||||
# define tw_htons(x) SWAPBYTES16((x))
|
||||
# define tw_ntohs(x) SWAPBYTES16((x))
|
||||
# define tw_htonll(x) SWAPBYTES64((x)) // int64 versions
|
||||
# define tw_ntohll(x) SWAPBYTES64((x))
|
||||
|
||||
#endif //WORDS_BIGENDIAN
|
||||
# endif //WORDS_BIGENDIAN
|
||||
|
||||
////////////////////////////////////////////
|
||||
|
||||
#if __cplusplus >= 201103L
|
||||
# define TW_UNIQUE_PTR std::unique_ptr
|
||||
#else
|
||||
# define TW_UNIQUE_PTR std::auto_ptr
|
||||
#endif
|
||||
|
||||
|
||||
# if __cplusplus >= 201103L
|
||||
# define TW_UNIQUE_PTR std::unique_ptr
|
||||
# else
|
||||
# define TW_UNIQUE_PTR std::auto_ptr
|
||||
# endif
|
||||
|
||||
|
||||
#endif // __TYPES_H
|
||||
|
||||
|
|
|
@ -3,29 +3,29 @@
|
|||
// Portions created by Tripwire, Inc. are copyright (C) 2000-2018 Tripwire,
|
||||
// Inc. Tripwire is a registered trademark of Tripwire, Inc. All rights
|
||||
// reserved.
|
||||
//
|
||||
//
|
||||
// This program is free software. The contents of this file are subject
|
||||
// to the terms of the GNU General Public License as published by the
|
||||
// Free Software Foundation; either version 2 of the License, or (at your
|
||||
// option) any later version. You may redistribute it and/or modify it
|
||||
// only in compliance with the GNU General Public License.
|
||||
//
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful.
|
||||
// However, this program is distributed AS-IS WITHOUT ANY
|
||||
// WARRANTY; INCLUDING THE IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS
|
||||
// FOR A PARTICULAR PURPOSE. Please see the GNU General Public License
|
||||
// for more details.
|
||||
//
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
|
||||
// USA.
|
||||
//
|
||||
//
|
||||
// Nothing in the GNU General Public License or any other license to use
|
||||
// the code or files shall permit you to use Tripwire's trademarks,
|
||||
// service marks, or other intellectual property without Tripwire's
|
||||
// prior written consent.
|
||||
//
|
||||
//
|
||||
// If you have any questions, please contact Tripwire, Inc. at either
|
||||
// info@tripwire.org or www.tripwire.org.
|
||||
//
|
||||
|
@ -38,27 +38,26 @@
|
|||
#include <errno.h>
|
||||
|
||||
// TODO: JEB: make this look like eFileError
|
||||
eUnix::eUnix( const TCHAR* szFunctionName, const TCHAR* szObjectName, bool fCallGetLastError)
|
||||
: eError( _T(""))
|
||||
eUnix::eUnix(const TCHAR* szFunctionName, const TCHAR* szObjectName, bool fCallGetLastError) : eError(_T(""))
|
||||
{
|
||||
ASSERT( szFunctionName || szObjectName || fCallGetLastError );
|
||||
ASSERT(szFunctionName || szObjectName || fCallGetLastError);
|
||||
//
|
||||
// construct the error message:
|
||||
//
|
||||
// it will be of the form: FuncName() failed for Object: <FormatMessage output>
|
||||
//
|
||||
if( szFunctionName )
|
||||
if (szFunctionName)
|
||||
{
|
||||
mMsg = szFunctionName;
|
||||
mMsg += _T(" failed");
|
||||
|
||||
if( szObjectName )
|
||||
if (szObjectName)
|
||||
{
|
||||
mMsg += _T(" for ");
|
||||
mMsg += szObjectName;
|
||||
}
|
||||
}
|
||||
else if( szObjectName )
|
||||
else if (szObjectName)
|
||||
{
|
||||
mMsg = szObjectName;
|
||||
}
|
||||
|
@ -67,11 +66,11 @@ eUnix::eUnix( const TCHAR* szFunctionName, const TCHAR* szObjectName, bool fCall
|
|||
mMsg = _T("Error");
|
||||
}
|
||||
|
||||
if( fCallGetLastError )
|
||||
if (fCallGetLastError)
|
||||
{
|
||||
TSTRING strErr = strerror(errno);
|
||||
|
||||
if( ! strErr.empty() )
|
||||
if (!strErr.empty())
|
||||
{
|
||||
mMsg += _T(": ");
|
||||
mMsg += strErr;
|
||||
|
|
|
@ -3,29 +3,29 @@
|
|||
// Portions created by Tripwire, Inc. are copyright (C) 2000-2018 Tripwire,
|
||||
// Inc. Tripwire is a registered trademark of Tripwire, Inc. All rights
|
||||
// reserved.
|
||||
//
|
||||
//
|
||||
// This program is free software. The contents of this file are subject
|
||||
// to the terms of the GNU General Public License as published by the
|
||||
// Free Software Foundation; either version 2 of the License, or (at your
|
||||
// option) any later version. You may redistribute it and/or modify it
|
||||
// only in compliance with the GNU General Public License.
|
||||
//
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful.
|
||||
// However, this program is distributed AS-IS WITHOUT ANY
|
||||
// WARRANTY; INCLUDING THE IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS
|
||||
// FOR A PARTICULAR PURPOSE. Please see the GNU General Public License
|
||||
// for more details.
|
||||
//
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
|
||||
// USA.
|
||||
//
|
||||
//
|
||||
// Nothing in the GNU General Public License or any other license to use
|
||||
// the code or files shall permit you to use Tripwire's trademarks,
|
||||
// service marks, or other intellectual property without Tripwire's
|
||||
// prior written consent.
|
||||
//
|
||||
//
|
||||
// If you have any questions, please contact Tripwire, Inc. at either
|
||||
// info@tripwire.org or www.tripwire.org.
|
||||
//
|
||||
|
@ -41,18 +41,16 @@
|
|||
#include "error.h"
|
||||
#endif
|
||||
|
||||
TSS_BEGIN_EXCEPTION( eUnix, eError )
|
||||
TSS_BEGIN_EXCEPTION(eUnix, eError)
|
||||
|
||||
eUnix(const TCHAR* functionName, const TCHAR* objectName, bool displayErrorNumber = true);
|
||||
// construct one of these to indicate a unix api failure. both functionName and
|
||||
// objectName can be NULL. This method will construct a string to pass to eError
|
||||
// that contains all of the above information plus whatever errno returns if the dusplayErrorNumber
|
||||
// parameter is true.
|
||||
|
||||
eUnix( const TCHAR* functionName, const TCHAR* objectName, bool displayErrorNumber = true );
|
||||
// construct one of these to indicate a unix api failure. both functionName and
|
||||
// objectName can be NULL. This method will construct a string to pass to eError
|
||||
// that contains all of the above information plus whatever errno returns if the dusplayErrorNumber
|
||||
// parameter is true.
|
||||
|
||||
|
||||
TSS_END_EXCEPTION()
|
||||
|
||||
|
||||
|
||||
#endif //__unixexcept_H
|
||||
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -3,36 +3,36 @@
|
|||
// Portions created by Tripwire, Inc. are copyright (C) 2000-2018 Tripwire,
|
||||
// Inc. Tripwire is a registered trademark of Tripwire, Inc. All rights
|
||||
// reserved.
|
||||
//
|
||||
//
|
||||
// This program is free software. The contents of this file are subject
|
||||
// to the terms of the GNU General Public License as published by the
|
||||
// Free Software Foundation; either version 2 of the License, or (at your
|
||||
// option) any later version. You may redistribute it and/or modify it
|
||||
// only in compliance with the GNU General Public License.
|
||||
//
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful.
|
||||
// However, this program is distributed AS-IS WITHOUT ANY
|
||||
// WARRANTY; INCLUDING THE IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS
|
||||
// FOR A PARTICULAR PURPOSE. Please see the GNU General Public License
|
||||
// for more details.
|
||||
//
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
|
||||
// USA.
|
||||
//
|
||||
//
|
||||
// Nothing in the GNU General Public License or any other license to use
|
||||
// the code or files shall permit you to use Tripwire's trademarks,
|
||||
// service marks, or other intellectual property without Tripwire's
|
||||
// prior written consent.
|
||||
//
|
||||
//
|
||||
// If you have any questions, please contact Tripwire, Inc. at either
|
||||
// info@tripwire.org or www.tripwire.org.
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// unixfsservices.h
|
||||
//
|
||||
// cUnixFSServices implements iFSServices, which abstacts out all
|
||||
// cUnixFSServices implements iFSServices, which abstacts out all
|
||||
// system dependent filesystem calls.
|
||||
|
||||
#ifndef __UNIXFSSERVICES_H
|
||||
|
@ -54,115 +54,113 @@
|
|||
// DECLARATION OF CLASSES
|
||||
//=========================================================================
|
||||
|
||||
class cUnixFSServices : public iFSServices
|
||||
class cUnixFSServices : public iFSServices
|
||||
{
|
||||
///////////////////////////////////////////////////////////////
|
||||
// MEMBER FUNCTIONS
|
||||
///////////////////////////////////////////////////////////////
|
||||
public:
|
||||
cUnixFSServices();
|
||||
virtual ~cUnixFSServices();
|
||||
|
||||
|
||||
////////////////////////////////////////
|
||||
// platform specific functions
|
||||
////////////////////////////////////////
|
||||
virtual bool IsCaseSensitive() const;
|
||||
// returns true if the file system is case sensitive
|
||||
virtual const TCHAR* GetStandardBackupExtension() const;
|
||||
// returns normal string to append to backup files for this os.
|
||||
// (e.g. "~" for unix and ".bak" for winos)
|
||||
virtual TCHAR GetPathSeparator() const;
|
||||
|
||||
////////////////////////////////////////
|
||||
// process functions
|
||||
////////////////////////////////////////
|
||||
virtual void Sleep( int nSeconds ) const;
|
||||
// makes the current process sleep for the specified number of seconds
|
||||
|
||||
////////////////////////////////////////
|
||||
// major filesystem functions
|
||||
////////////////////////////////////////
|
||||
virtual void Stat( const TSTRING& strFileName, cFSStatArgs& pStat ) const ;
|
||||
// fills out the cFSStatArgs structure with the stat info for the named file
|
||||
|
||||
virtual void GetTempDirName( TSTRING& strName ) const ;
|
||||
// makes directory if it doesn't exist already. Dirname will end with a delimiter ( '/' )
|
||||
|
||||
virtual void SetTempDirName(TSTRING& tmpName);
|
||||
// set the default dir name which GetTempDirName will use...
|
||||
|
||||
virtual TSTRING& MakeTempFilename( TSTRING& strName ) const ;
|
||||
// create temporary file
|
||||
// strName must have the form ("baseXXXXXX"), where the X's are replaced with
|
||||
// characters to make it a unique file. There must be at least 6 Xs.
|
||||
|
||||
|
||||
////////////////////////////////////////
|
||||
// minor filesystem functions
|
||||
////////////////////////////////////////
|
||||
virtual void GetHostID( TSTRING& name ) const;
|
||||
|
||||
virtual void GetMachineName( TSTRING& name) const;
|
||||
|
||||
virtual void GetMachineNameFullyQualified( TSTRING& name ) const;
|
||||
|
||||
virtual bool GetCurrentUserName( TSTRING& tstrName ) const;
|
||||
|
||||
virtual bool GetIPAddress( uint32& uiIPAddress );
|
||||
///////////////////////////////////////////////////////////////
|
||||
// MEMBER FUNCTIONS
|
||||
///////////////////////////////////////////////////////////////
|
||||
public:
|
||||
cUnixFSServices();
|
||||
virtual ~cUnixFSServices();
|
||||
|
||||
|
||||
////////////////////////////////////////
|
||||
// directory specific functions
|
||||
////////////////////////////////////////
|
||||
virtual void ReadDir( const TSTRING& strName, std::vector<TSTRING> &vDirContents, bool bFullPaths = true ) const;
|
||||
// puts the contents of the specified directory, except for . and .., into the supplied vector.
|
||||
virtual void GetCurrentDir( TSTRING& strCurDir ) const;
|
||||
// returns the current working directory
|
||||
////////////////////////////////////////
|
||||
// platform specific functions
|
||||
////////////////////////////////////////
|
||||
virtual bool IsCaseSensitive() const;
|
||||
// returns true if the file system is case sensitive
|
||||
virtual const TCHAR* GetStandardBackupExtension() const;
|
||||
// returns normal string to append to backup files for this os.
|
||||
// (e.g. "~" for unix and ".bak" for winos)
|
||||
virtual TCHAR GetPathSeparator() const;
|
||||
|
||||
|
||||
////////////////////////////////////////
|
||||
// file specific functions
|
||||
////////////////////////////////////////
|
||||
virtual bool FileDelete( const TSTRING& name ) const;
|
||||
|
||||
////////////////////////////////////////
|
||||
// directory and file functions
|
||||
////////////////////////////////////////
|
||||
virtual bool Rename( const TSTRING& strOldName, const TSTRING& strNewName, bool fOverWrite = true ) const;
|
||||
// rename a file
|
||||
|
||||
virtual bool GetUserName( uid_t user_id, TSTRING& tstrUser ) const;
|
||||
virtual bool GetGroupName( gid_t group_id, TSTRING& tstrGroup ) const;
|
||||
////////////////////////////////////////
|
||||
// process functions
|
||||
////////////////////////////////////////
|
||||
virtual void Sleep(int nSeconds) const;
|
||||
// makes the current process sleep for the specified number of seconds
|
||||
|
||||
//Set whether we try to resolve uid/gid to a name, since Linux static binaries can
|
||||
//have trouble (read: segfaulting) with name resolution given the right nsswitch.conf setup.
|
||||
//This defaults to true if not specified.
|
||||
virtual void SetResolveNames(bool resolve);
|
||||
|
||||
////////////////////////////////////////
|
||||
// miscellaneous utility functions
|
||||
////////////////////////////////////////
|
||||
virtual void ConvertModeToString( uint64 perm, TSTRING& tstrPerm ) const;
|
||||
// takes a int64 permission (from stat) and changes it to look like UNIX's 'ls -l' (e.g. drwxrwxrwx)
|
||||
virtual bool FullPath( TSTRING& fullPath, const TSTRING& relPath, const TSTRING& pathRelFrom = _T("") ) const;
|
||||
// converts relPath into a fully qualified path, storing it in FullPath. If this
|
||||
// fails, false is returned. if the path to which relPath is relative is not CWD, put it in pathRelFrom.
|
||||
virtual bool GetExecutableFilename( TSTRING& strFullPath, const TSTRING& strFilename ) const;
|
||||
// get the path to the current executable file
|
||||
virtual bool IsRoot( const TSTRING& strPath ) const;
|
||||
// returns true if strPath is all '/'s
|
||||
////////////////////////////////////////
|
||||
// major filesystem functions
|
||||
////////////////////////////////////////
|
||||
virtual void Stat(const TSTRING& strFileName, cFSStatArgs& pStat) const;
|
||||
// fills out the cFSStatArgs structure with the stat info for the named file
|
||||
|
||||
////////////////////////////////////////
|
||||
// error functions
|
||||
////////////////////////////////////////
|
||||
virtual TSTRING GetErrString() const;
|
||||
|
||||
private:
|
||||
virtual void GetTempDirName(TSTRING& strName) const;
|
||||
// makes directory if it doesn't exist already. Dirname will end with a delimiter ( '/' )
|
||||
|
||||
TSTRING mTempPath;
|
||||
bool mResolveNames;
|
||||
virtual void SetTempDirName(TSTRING& tmpName);
|
||||
// set the default dir name which GetTempDirName will use...
|
||||
|
||||
virtual TSTRING& MakeTempFilename(TSTRING& strName) const;
|
||||
// create temporary file
|
||||
// strName must have the form ("baseXXXXXX"), where the X's are replaced with
|
||||
// characters to make it a unique file. There must be at least 6 Xs.
|
||||
|
||||
|
||||
////////////////////////////////////////
|
||||
// minor filesystem functions
|
||||
////////////////////////////////////////
|
||||
virtual void GetHostID(TSTRING& name) const;
|
||||
|
||||
virtual void GetMachineName(TSTRING& name) const;
|
||||
|
||||
virtual void GetMachineNameFullyQualified(TSTRING& name) const;
|
||||
|
||||
virtual bool GetCurrentUserName(TSTRING& tstrName) const;
|
||||
|
||||
virtual bool GetIPAddress(uint32& uiIPAddress);
|
||||
|
||||
|
||||
////////////////////////////////////////
|
||||
// directory specific functions
|
||||
////////////////////////////////////////
|
||||
virtual void ReadDir(const TSTRING& strName, std::vector<TSTRING>& vDirContents, bool bFullPaths = true) const;
|
||||
// puts the contents of the specified directory, except for . and .., into the supplied vector.
|
||||
virtual void GetCurrentDir(TSTRING& strCurDir) const;
|
||||
// returns the current working directory
|
||||
|
||||
|
||||
////////////////////////////////////////
|
||||
// file specific functions
|
||||
////////////////////////////////////////
|
||||
virtual bool FileDelete(const TSTRING& name) const;
|
||||
|
||||
////////////////////////////////////////
|
||||
// directory and file functions
|
||||
////////////////////////////////////////
|
||||
virtual bool Rename(const TSTRING& strOldName, const TSTRING& strNewName, bool fOverWrite = true) const;
|
||||
// rename a file
|
||||
|
||||
virtual bool GetUserName(uid_t user_id, TSTRING& tstrUser) const;
|
||||
virtual bool GetGroupName(gid_t group_id, TSTRING& tstrGroup) const;
|
||||
|
||||
//Set whether we try to resolve uid/gid to a name, since Linux static binaries can
|
||||
//have trouble (read: segfaulting) with name resolution given the right nsswitch.conf setup.
|
||||
//This defaults to true if not specified.
|
||||
virtual void SetResolveNames(bool resolve);
|
||||
|
||||
////////////////////////////////////////
|
||||
// miscellaneous utility functions
|
||||
////////////////////////////////////////
|
||||
virtual void ConvertModeToString(uint64 perm, TSTRING& tstrPerm) const;
|
||||
// takes a int64 permission (from stat) and changes it to look like UNIX's 'ls -l' (e.g. drwxrwxrwx)
|
||||
virtual bool FullPath(TSTRING& fullPath, const TSTRING& relPath, const TSTRING& pathRelFrom = _T("")) const;
|
||||
// converts relPath into a fully qualified path, storing it in FullPath. If this
|
||||
// fails, false is returned. if the path to which relPath is relative is not CWD, put it in pathRelFrom.
|
||||
virtual bool GetExecutableFilename(TSTRING& strFullPath, const TSTRING& strFilename) const;
|
||||
// get the path to the current executable file
|
||||
virtual bool IsRoot(const TSTRING& strPath) const;
|
||||
// returns true if strPath is all '/'s
|
||||
|
||||
////////////////////////////////////////
|
||||
// error functions
|
||||
////////////////////////////////////////
|
||||
virtual TSTRING GetErrString() const;
|
||||
|
||||
private:
|
||||
TSTRING mTempPath;
|
||||
bool mResolveNames;
|
||||
};
|
||||
|
||||
#endif //__UNIXFSSERVICES_H
|
||||
|
||||
|
|
|
@ -3,29 +3,29 @@
|
|||
// Portions created by Tripwire, Inc. are copyright (C) 2000-2018 Tripwire,
|
||||
// Inc. Tripwire is a registered trademark of Tripwire, Inc. All rights
|
||||
// reserved.
|
||||
//
|
||||
//
|
||||
// This program is free software. The contents of this file are subject
|
||||
// to the terms of the GNU General Public License as published by the
|
||||
// Free Software Foundation; either version 2 of the License, or (at your
|
||||
// option) any later version. You may redistribute it and/or modify it
|
||||
// only in compliance with the GNU General Public License.
|
||||
//
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful.
|
||||
// However, this program is distributed AS-IS WITHOUT ANY
|
||||
// WARRANTY; INCLUDING THE IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS
|
||||
// FOR A PARTICULAR PURPOSE. Please see the GNU General Public License
|
||||
// for more details.
|
||||
//
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
|
||||
// USA.
|
||||
//
|
||||
//
|
||||
// Nothing in the GNU General Public License or any other license to use
|
||||
// the code or files shall permit you to use Tripwire's trademarks,
|
||||
// service marks, or other intellectual property without Tripwire's
|
||||
// prior written consent.
|
||||
//
|
||||
//
|
||||
// If you have any questions, please contact Tripwire, Inc. at either
|
||||
// info@tripwire.org or www.tripwire.org.
|
||||
//
|
||||
|
@ -37,15 +37,15 @@
|
|||
#define __UPPERBOUND_H
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Function name: template< class FwdIterT, class CmpObjT, class CmpFuncT >
|
||||
// Function name: template< class FwdIterT, class CmpObjT, class CmpFuncT >
|
||||
// UpperBound
|
||||
//
|
||||
// Description : same as std::upper_bound except it allows 'less' to take
|
||||
// Description : same as std::upper_bound except it allows 'less' to take
|
||||
// parameters of dissimilar types. Therefore, *FwdIter need not be
|
||||
// the same type as CmpObjT. Uses a binary search algorithm.
|
||||
//
|
||||
// Return type : FwdIterT : First element in the sequence [first, last)
|
||||
// that is equal to or greater than 'obj' or
|
||||
// Return type : FwdIterT : First element in the sequence [first, last)
|
||||
// that is equal to or greater than 'obj' or
|
||||
// 'last' if there is no such element.
|
||||
//
|
||||
// Argument : FwdIterT first : First element in sequence.
|
||||
|
@ -54,25 +54,26 @@
|
|||
// Argument : CmpFuncT less : Comparison function. Must return as 'std::less'.
|
||||
// Will be called as: 'bool less( *FwdIterT, CmpObjT )'.
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////
|
||||
template< class FwdIterT, class CmpObjT, class CmpFuncT > FwdIterT UpperBound( FwdIterT first, FwdIterT last, const CmpObjT& obj, CmpFuncT less )
|
||||
{
|
||||
template<class FwdIterT, class CmpObjT, class CmpFuncT>
|
||||
FwdIterT UpperBound(FwdIterT first, FwdIterT last, const CmpObjT& obj, CmpFuncT less)
|
||||
{
|
||||
// count elements in set
|
||||
int nElemsInSet = 0;
|
||||
FwdIterT iCur = first;
|
||||
for (; iCur != last; ++iCur )
|
||||
int nElemsInSet = 0;
|
||||
FwdIterT iCur = first;
|
||||
for (; iCur != last; ++iCur)
|
||||
++nElemsInSet;
|
||||
|
||||
iCur = first;
|
||||
|
||||
while( 0 < nElemsInSet )
|
||||
while (0 < nElemsInSet)
|
||||
{
|
||||
// go to halfway point
|
||||
int iHalfWay = nElemsInSet/2;
|
||||
FwdIterT iTemp = iCur;
|
||||
for( int j = 0; j < iHalfWay; j++ )
|
||||
int iHalfWay = nElemsInSet / 2;
|
||||
FwdIterT iTemp = iCur;
|
||||
for (int j = 0; j < iHalfWay; j++)
|
||||
iTemp++;
|
||||
|
||||
if( less( *iTemp, obj ) )
|
||||
if (less(*iTemp, obj))
|
||||
{
|
||||
// start next search set at next elem with half of the last search set's elements
|
||||
iCur = ++iTemp;
|
||||
|
@ -89,4 +90,3 @@ template< class FwdIterT, class CmpObjT, class CmpFuncT > FwdIterT UpperBound( F
|
|||
}
|
||||
|
||||
#endif // __UPPERBOUND_H
|
||||
|
||||
|
|
|
@ -3,29 +3,29 @@
|
|||
// Portions created by Tripwire, Inc. are copyright (C) 2000-2018 Tripwire,
|
||||
// Inc. Tripwire is a registered trademark of Tripwire, Inc. All rights
|
||||
// reserved.
|
||||
//
|
||||
//
|
||||
// This program is free software. The contents of this file are subject
|
||||
// to the terms of the GNU General Public License as published by the
|
||||
// Free Software Foundation; either version 2 of the License, or (at your
|
||||
// option) any later version. You may redistribute it and/or modify it
|
||||
// only in compliance with the GNU General Public License.
|
||||
//
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful.
|
||||
// However, this program is distributed AS-IS WITHOUT ANY
|
||||
// WARRANTY; INCLUDING THE IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS
|
||||
// FOR A PARTICULAR PURPOSE. Please see the GNU General Public License
|
||||
// for more details.
|
||||
//
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
|
||||
// USA.
|
||||
//
|
||||
//
|
||||
// Nothing in the GNU General Public License or any other license to use
|
||||
// the code or files shall permit you to use Tripwire's trademarks,
|
||||
// service marks, or other intellectual property without Tripwire's
|
||||
// prior written consent.
|
||||
//
|
||||
//
|
||||
// If you have any questions, please contact Tripwire, Inc. at either
|
||||
// info@tripwire.org or www.tripwire.org.
|
||||
//
|
||||
|
@ -36,20 +36,17 @@
|
|||
// There was a problem with varargs on some combo of old OpenBSD & old compiler.
|
||||
// Not needed with current, but it's here if you need it.
|
||||
#ifdef TW_OLD_OPENBSD_VARARGS
|
||||
# undef va_start
|
||||
# ifdef __GNUC__
|
||||
# define va_start(ap, last) \
|
||||
((ap) = (va_list)__builtin_next_arg(last))
|
||||
# else
|
||||
# define va_start(ap, last) \
|
||||
((ap) = (va_list)&(last) + __va_size(last))
|
||||
# endif
|
||||
# undef va_start
|
||||
# ifdef __GNUC__
|
||||
# define va_start(ap, last) ((ap) = (va_list)__builtin_next_arg(last))
|
||||
# else
|
||||
# define va_start(ap, last) ((ap) = (va_list) & (last) + __va_size(last))
|
||||
# endif
|
||||
#endif // TW_OLD_OPENBSD_VARARGS
|
||||
|
||||
iUserNotify* iUserNotify::mpInstance = 0;
|
||||
|
||||
iUserNotify::iUserNotify(int verboseLevel) :
|
||||
mVerboseLevel(verboseLevel)
|
||||
iUserNotify::iUserNotify(int verboseLevel) : mVerboseLevel(verboseLevel)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -70,33 +67,33 @@ int iUserNotify::GetVerboseLevel() const
|
|||
///////////////////////////////////////////////////////////////////////////////
|
||||
// NotifySilent
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
void iUserNotify::NotifySilent( const TCHAR* format, ... )
|
||||
void iUserNotify::NotifySilent(const TCHAR* format, ...)
|
||||
{
|
||||
va_list args;
|
||||
va_start(args, format);
|
||||
HandleNotify( V_SILENT, format, args );
|
||||
HandleNotify(V_SILENT, format, args);
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// NotifyNormal
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
void iUserNotify::NotifyNormal( const TCHAR* format, ... )
|
||||
void iUserNotify::NotifyNormal(const TCHAR* format, ...)
|
||||
{
|
||||
va_list args;
|
||||
va_start(args, format);
|
||||
HandleNotify( V_NORMAL, format, args );
|
||||
HandleNotify(V_NORMAL, format, args);
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// NotifyVerbose
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
void iUserNotify::NotifyVerbose( const TCHAR* format, ... )
|
||||
void iUserNotify::NotifyVerbose(const TCHAR* format, ...)
|
||||
{
|
||||
va_list args;
|
||||
va_start(args, format);
|
||||
HandleNotify( V_VERBOSE, format, args );
|
||||
HandleNotify(V_VERBOSE, format, args);
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
|
@ -107,8 +104,6 @@ void iUserNotify::Notify(int verboseLevel, const TCHAR* format, ...)
|
|||
{
|
||||
va_list args;
|
||||
va_start(args, format);
|
||||
HandleNotify( verboseLevel, format, args );
|
||||
HandleNotify(verboseLevel, format, args);
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -3,29 +3,29 @@
|
|||
// Portions created by Tripwire, Inc. are copyright (C) 2000-2018 Tripwire,
|
||||
// Inc. Tripwire is a registered trademark of Tripwire, Inc. All rights
|
||||
// reserved.
|
||||
//
|
||||
//
|
||||
// This program is free software. The contents of this file are subject
|
||||
// to the terms of the GNU General Public License as published by the
|
||||
// Free Software Foundation; either version 2 of the License, or (at your
|
||||
// option) any later version. You may redistribute it and/or modify it
|
||||
// only in compliance with the GNU General Public License.
|
||||
//
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful.
|
||||
// However, this program is distributed AS-IS WITHOUT ANY
|
||||
// WARRANTY; INCLUDING THE IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS
|
||||
// FOR A PARTICULAR PURPOSE. Please see the GNU General Public License
|
||||
// for more details.
|
||||
//
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
|
||||
// USA.
|
||||
//
|
||||
//
|
||||
// Nothing in the GNU General Public License or any other license to use
|
||||
// the code or files shall permit you to use Tripwire's trademarks,
|
||||
// service marks, or other intellectual property without Tripwire's
|
||||
// prior written consent.
|
||||
//
|
||||
//
|
||||
// If you have any questions, please contact Tripwire, Inc. at either
|
||||
// info@tripwire.org or www.tripwire.org.
|
||||
//
|
||||
|
@ -49,19 +49,19 @@ public:
|
|||
// singleton interface; caller is responsible for deleting pointer;
|
||||
static iUserNotify* GetInstance();
|
||||
static void SetInstance(iUserNotify* pInst);
|
||||
|
||||
virtual void Notify(int verboseLevel, const TCHAR* format, ...) ;
|
||||
// notify the user that an event has occured. The outcome of this operation is
|
||||
// dependant on the type of object that is implementing this interface (for example,
|
||||
// a console application would want an iUserNotify that prints things to stdout)
|
||||
// If the current verbosity level is less than verboseLevel, nothing will happen.
|
||||
// All output should be sent through the cDisplayEncoder beforehand
|
||||
// TODO:BAM -- enforce this somehow?
|
||||
|
||||
virtual void SetVerboseLevel(int level);
|
||||
virtual int GetVerboseLevel() const;
|
||||
// get/set the current verbosity level. Notify()s that occur whose verbosity level
|
||||
// is greater than the current level will not be processed.
|
||||
virtual void Notify(int verboseLevel, const TCHAR* format, ...);
|
||||
// notify the user that an event has occured. The outcome of this operation is
|
||||
// dependant on the type of object that is implementing this interface (for example,
|
||||
// a console application would want an iUserNotify that prints things to stdout)
|
||||
// If the current verbosity level is less than verboseLevel, nothing will happen.
|
||||
// All output should be sent through the cDisplayEncoder beforehand
|
||||
// TODO:BAM -- enforce this somehow?
|
||||
|
||||
virtual void SetVerboseLevel(int level);
|
||||
virtual int GetVerboseLevel() const;
|
||||
// get/set the current verbosity level. Notify()s that occur whose verbosity level
|
||||
// is greater than the current level will not be processed.
|
||||
|
||||
// a convenience enumeration; no one is bound by law to use these
|
||||
enum VerboseLevel
|
||||
|
@ -73,45 +73,47 @@ public:
|
|||
//
|
||||
// convenience methods for notifying at these three levels...
|
||||
//
|
||||
void NotifySilent ( const TCHAR* format, ... );
|
||||
void NotifyNormal ( const TCHAR* format, ... );
|
||||
void NotifyVerbose ( const TCHAR* format, ... );
|
||||
void NotifySilent(const TCHAR* format, ...);
|
||||
void NotifyNormal(const TCHAR* format, ...);
|
||||
void NotifyVerbose(const TCHAR* format, ...);
|
||||
|
||||
|
||||
iUserNotify(int verboseLevel = 0);
|
||||
virtual ~iUserNotify();
|
||||
|
||||
protected:
|
||||
virtual void HandleNotify( int level, const TCHAR* format, va_list& args ) = 0;
|
||||
// this is implemented in derived classes to implement the specific type of
|
||||
// notification desired
|
||||
|
||||
virtual void HandleNotify(int level, const TCHAR* format, va_list& args) = 0;
|
||||
// this is implemented in derived classes to implement the specific type of
|
||||
// notification desired
|
||||
|
||||
int mVerboseLevel;
|
||||
|
||||
private:
|
||||
static iUserNotify* mpInstance;
|
||||
};
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// notify macros
|
||||
// notify macros
|
||||
//
|
||||
// use these as an alternative to iUserNotify::GetInstance()->Notify( XXX )
|
||||
// use these as an alternative to iUserNotify::GetInstance()->Notify( XXX )
|
||||
// becuase the call will not be made if it is not the appropriate verbosity
|
||||
// level. This is useful when you don't want the "..." part of Notify() to be
|
||||
// evaluated (for example, if it is an expensive operation like cFCOName::AsString()
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#define TW_NOTIFY_SILENT\
|
||||
if( iUserNotify::GetInstance()->GetVerboseLevel() >= iUserNotify::V_SILENT )\
|
||||
iUserNotify::GetInstance()->NotifySilent
|
||||
#define TW_NOTIFY_SILENT \
|
||||
if (iUserNotify::GetInstance()->GetVerboseLevel() >= iUserNotify::V_SILENT) \
|
||||
iUserNotify::GetInstance()->NotifySilent
|
||||
|
||||
#define TW_NOTIFY_NORMAL\
|
||||
if( iUserNotify::GetInstance()->GetVerboseLevel() >= iUserNotify::V_NORMAL )\
|
||||
iUserNotify::GetInstance()->NotifyNormal
|
||||
#define TW_NOTIFY_NORMAL \
|
||||
if (iUserNotify::GetInstance()->GetVerboseLevel() >= iUserNotify::V_NORMAL) \
|
||||
iUserNotify::GetInstance()->NotifyNormal
|
||||
|
||||
#define TW_NOTIFY_VERBOSE\
|
||||
if( iUserNotify::GetInstance()->GetVerboseLevel() >= iUserNotify::V_VERBOSE )\
|
||||
iUserNotify::GetInstance()->NotifyVerbose
|
||||
#define TW_NOTIFY_VERBOSE \
|
||||
if (iUserNotify::GetInstance()->GetVerboseLevel() >= iUserNotify::V_VERBOSE) \
|
||||
iUserNotify::GetInstance()->NotifyVerbose
|
||||
|
||||
//#############################################################################
|
||||
// inline implementation
|
||||
|
@ -129,4 +131,3 @@ inline void iUserNotify::SetInstance(iUserNotify* pInst)
|
|||
|
||||
|
||||
#endif //__USERNOTIFY_H
|
||||
|
||||
|
|
|
@ -3,29 +3,29 @@
|
|||
// Portions created by Tripwire, Inc. are copyright (C) 2000-2018 Tripwire,
|
||||
// Inc. Tripwire is a registered trademark of Tripwire, Inc. All rights
|
||||
// reserved.
|
||||
//
|
||||
//
|
||||
// This program is free software. The contents of this file are subject
|
||||
// to the terms of the GNU General Public License as published by the
|
||||
// Free Software Foundation; either version 2 of the License, or (at your
|
||||
// option) any later version. You may redistribute it and/or modify it
|
||||
// only in compliance with the GNU General Public License.
|
||||
//
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful.
|
||||
// However, this program is distributed AS-IS WITHOUT ANY
|
||||
// WARRANTY; INCLUDING THE IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS
|
||||
// FOR A PARTICULAR PURPOSE. Please see the GNU General Public License
|
||||
// for more details.
|
||||
//
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
|
||||
// USA.
|
||||
//
|
||||
//
|
||||
// Nothing in the GNU General Public License or any other license to use
|
||||
// the code or files shall permit you to use Tripwire's trademarks,
|
||||
// service marks, or other intellectual property without Tripwire's
|
||||
// prior written consent.
|
||||
//
|
||||
//
|
||||
// If you have any questions, please contact Tripwire, Inc. at either
|
||||
// info@tripwire.org or www.tripwire.org.
|
||||
//
|
||||
|
@ -36,21 +36,20 @@
|
|||
///////////////////////////////////////////////////////////////////////////////
|
||||
// HandleNotify
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
void cUserNotifyStdout::HandleNotify( int level, const TCHAR* format, va_list& args )
|
||||
void cUserNotifyStdout::HandleNotify(int level, const TCHAR* format, va_list& args)
|
||||
{
|
||||
if(GetVerboseLevel() < level)
|
||||
if (GetVerboseLevel() < level)
|
||||
return;
|
||||
|
||||
// all verbose output now goes to stderr
|
||||
if(level < iUserNotify::V_VERBOSE)
|
||||
if (level < iUserNotify::V_VERBOSE)
|
||||
{
|
||||
_vtprintf(format, args);
|
||||
fflush( stdout );
|
||||
fflush(stdout);
|
||||
}
|
||||
else
|
||||
{
|
||||
_vftprintf(stderr, format, args);
|
||||
fflush( stderr );
|
||||
fflush(stderr);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -3,29 +3,29 @@
|
|||
// Portions created by Tripwire, Inc. are copyright (C) 2000-2018 Tripwire,
|
||||
// Inc. Tripwire is a registered trademark of Tripwire, Inc. All rights
|
||||
// reserved.
|
||||
//
|
||||
//
|
||||
// This program is free software. The contents of this file are subject
|
||||
// to the terms of the GNU General Public License as published by the
|
||||
// Free Software Foundation; either version 2 of the License, or (at your
|
||||
// option) any later version. You may redistribute it and/or modify it
|
||||
// only in compliance with the GNU General Public License.
|
||||
//
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful.
|
||||
// However, this program is distributed AS-IS WITHOUT ANY
|
||||
// WARRANTY; INCLUDING THE IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS
|
||||
// FOR A PARTICULAR PURPOSE. Please see the GNU General Public License
|
||||
// for more details.
|
||||
//
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
|
||||
// USA.
|
||||
//
|
||||
//
|
||||
// Nothing in the GNU General Public License or any other license to use
|
||||
// the code or files shall permit you to use Tripwire's trademarks,
|
||||
// service marks, or other intellectual property without Tripwire's
|
||||
// prior written consent.
|
||||
//
|
||||
//
|
||||
// If you have any questions, please contact Tripwire, Inc. at either
|
||||
// info@tripwire.org or www.tripwire.org.
|
||||
//
|
||||
|
@ -43,11 +43,10 @@
|
|||
class cUserNotifyStdout : public iUserNotify
|
||||
{
|
||||
public:
|
||||
virtual void HandleNotify( int level, const TCHAR* format, va_list& args ) ;
|
||||
// formats the string and sends it to stdout
|
||||
// NOTE -- a little tripwire specific hack has been applied that makes all output
|
||||
// at or above iUserNotify::V_VERBOSE go to stderr instead of stdout
|
||||
virtual void HandleNotify(int level, const TCHAR* format, va_list& args);
|
||||
// formats the string and sends it to stdout
|
||||
// NOTE -- a little tripwire specific hack has been applied that makes all output
|
||||
// at or above iUserNotify::V_VERBOSE go to stderr instead of stdout
|
||||
};
|
||||
|
||||
#endif /* __USERNOTIFYSTDOUT_H */
|
||||
|
||||
|
|
|
@ -3,29 +3,29 @@
|
|||
// Portions created by Tripwire, Inc. are copyright (C) 2000-2018 Tripwire,
|
||||
// Inc. Tripwire is a registered trademark of Tripwire, Inc. All rights
|
||||
// reserved.
|
||||
//
|
||||
//
|
||||
// This program is free software. The contents of this file are subject
|
||||
// to the terms of the GNU General Public License as published by the
|
||||
// Free Software Foundation; either version 2 of the License, or (at your
|
||||
// option) any later version. You may redistribute it and/or modify it
|
||||
// only in compliance with the GNU General Public License.
|
||||
//
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful.
|
||||
// However, this program is distributed AS-IS WITHOUT ANY
|
||||
// WARRANTY; INCLUDING THE IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS
|
||||
// FOR A PARTICULAR PURPOSE. Please see the GNU General Public License
|
||||
// for more details.
|
||||
//
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
|
||||
// USA.
|
||||
//
|
||||
//
|
||||
// Nothing in the GNU General Public License or any other license to use
|
||||
// the code or files shall permit you to use Tripwire's trademarks,
|
||||
// service marks, or other intellectual property without Tripwire's
|
||||
// prior written consent.
|
||||
//
|
||||
//
|
||||
// If you have any questions, please contact Tripwire, Inc. at either
|
||||
// info@tripwire.org or www.tripwire.org.
|
||||
//
|
||||
|
@ -72,7 +72,7 @@ const TCHAR* cUserStringMemBased::GetString(int stringID) const
|
|||
if (setItr == mStringSets.end())
|
||||
{
|
||||
// mCurrentStringSet is invallid
|
||||
ASSERT(false);
|
||||
ASSERT(false);
|
||||
return _T("<Bad String Set>");
|
||||
}
|
||||
|
||||
|
@ -106,10 +106,10 @@ void cUserStringMemBased::ClearStringSet(int id)
|
|||
}
|
||||
|
||||
// Add an array of string pairs to a string set. The pair array passed in
|
||||
// should terminate with an id of -1. If this string set contains string IDs
|
||||
// should terminate with an id of -1. If this string set contains string IDs
|
||||
// that already exist in the string set, they will "overwrite" the
|
||||
// the previous strings.
|
||||
// Note: We store only pointers to the string pairs so they must remain
|
||||
// the previous strings.
|
||||
// Note: We store only pointers to the string pairs so they must remain
|
||||
// around for as long as this class uses them. A static array defined at
|
||||
// compile time is perfect for this.
|
||||
void cUserStringMemBased::AddStringSet(int setID, const iUserString::tStringPair* pPairArray)
|
||||
|
@ -167,4 +167,3 @@ void cUserStringMemBased::AddString(int setID, int stringID, TCHAR* string)
|
|||
|
||||
setItr->second->insert(std::pair<int, TCHAR*>(stringID, string));
|
||||
}
|
||||
|
||||
|
|
|
@ -3,29 +3,29 @@
|
|||
// Portions created by Tripwire, Inc. are copyright (C) 2000-2018 Tripwire,
|
||||
// Inc. Tripwire is a registered trademark of Tripwire, Inc. All rights
|
||||
// reserved.
|
||||
//
|
||||
//
|
||||
// This program is free software. The contents of this file are subject
|
||||
// to the terms of the GNU General Public License as published by the
|
||||
// Free Software Foundation; either version 2 of the License, or (at your
|
||||
// option) any later version. You may redistribute it and/or modify it
|
||||
// only in compliance with the GNU General Public License.
|
||||
//
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful.
|
||||
// However, this program is distributed AS-IS WITHOUT ANY
|
||||
// WARRANTY; INCLUDING THE IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS
|
||||
// FOR A PARTICULAR PURPOSE. Please see the GNU General Public License
|
||||
// for more details.
|
||||
//
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
|
||||
// USA.
|
||||
//
|
||||
//
|
||||
// Nothing in the GNU General Public License or any other license to use
|
||||
// the code or files shall permit you to use Tripwire's trademarks,
|
||||
// service marks, or other intellectual property without Tripwire's
|
||||
// prior written consent.
|
||||
//
|
||||
//
|
||||
// If you have any questions, please contact Tripwire, Inc. at either
|
||||
// info@tripwire.org or www.tripwire.org.
|
||||
//
|
||||
|
@ -40,16 +40,16 @@
|
|||
#endif
|
||||
|
||||
#ifndef __USERSTRINGMEM_H
|
||||
#define __USERSTRINGMEM_H
|
||||
# define __USERSTRINGMEM_H
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning(disable:4786) /* disable unwanted C++ /W4 warning */
|
||||
/* #pragma warning(default:4786) */ /* use this to reenable, if necessary */
|
||||
#endif /* _MSC_VER */
|
||||
# ifdef _MSC_VER
|
||||
# pragma warning(disable : 4786) /* disable unwanted C++ /W4 warning */
|
||||
/* #pragma warning(default:4786) */ /* use this to reenable, if necessary */
|
||||
# endif /* _MSC_VER */
|
||||
|
||||
#ifndef __USERSTRING_H
|
||||
#include "userstring.h"
|
||||
#endif
|
||||
# ifndef __USERSTRING_H
|
||||
# include "userstring.h"
|
||||
# endif
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// class cUserStringMemBased -- A implementation where the various string
|
||||
|
@ -69,23 +69,22 @@ public:
|
|||
~cUserStringMemBased();
|
||||
|
||||
// the abstract interface
|
||||
virtual bool SelectStringSet (int setID);
|
||||
virtual const TCHAR* GetString (int stringID) const;
|
||||
virtual void ClearStringSet (int id);
|
||||
virtual void AddStringSet (int setID, const iUserString::tStringPair* pPairArray);
|
||||
virtual void AddString (int setID, int stringID, TCHAR* string);
|
||||
virtual bool SelectStringSet(int setID);
|
||||
virtual const TCHAR* GetString(int stringID) const;
|
||||
virtual void ClearStringSet(int id);
|
||||
virtual void AddStringSet(int setID, const iUserString::tStringPair* pPairArray);
|
||||
virtual void AddString(int setID, int stringID, TCHAR* string);
|
||||
|
||||
private:
|
||||
typedef std::map<int, TCHAR*> StringSet;
|
||||
|
||||
int mCurrentStringSet;
|
||||
std::map<int, StringSet*> mStringSets;
|
||||
int mCurrentStringSet;
|
||||
std::map<int, StringSet*> mStringSets;
|
||||
};
|
||||
|
||||
|
||||
#ifdef _MSC_VER
|
||||
# ifdef _MSC_VER
|
||||
//#pragma warning(default:4786)
|
||||
#endif /* _MSC_VER */
|
||||
# endif /* _MSC_VER */
|
||||
|
||||
#endif // __USERSTRINGMEM_H
|
||||
|
||||
|
|
|
@ -3,29 +3,29 @@
|
|||
// Portions created by Tripwire, Inc. are copyright (C) 2000-2018 Tripwire,
|
||||
// Inc. Tripwire is a registered trademark of Tripwire, Inc. All rights
|
||||
// reserved.
|
||||
//
|
||||
//
|
||||
// This program is free software. The contents of this file are subject
|
||||
// to the terms of the GNU General Public License as published by the
|
||||
// Free Software Foundation; either version 2 of the License, or (at your
|
||||
// option) any later version. You may redistribute it and/or modify it
|
||||
// only in compliance with the GNU General Public License.
|
||||
//
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful.
|
||||
// However, this program is distributed AS-IS WITHOUT ANY
|
||||
// WARRANTY; INCLUDING THE IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS
|
||||
// FOR A PARTICULAR PURPOSE. Please see the GNU General Public License
|
||||
// for more details.
|
||||
//
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
|
||||
// USA.
|
||||
//
|
||||
//
|
||||
// Nothing in the GNU General Public License or any other license to use
|
||||
// the code or files shall permit you to use Tripwire's trademarks,
|
||||
// service marks, or other intellectual property without Tripwire's
|
||||
// prior written consent.
|
||||
//
|
||||
//
|
||||
// If you have any questions, please contact Tripwire, Inc. at either
|
||||
// info@tripwire.org or www.tripwire.org.
|
||||
//
|
||||
|
@ -40,7 +40,7 @@
|
|||
#include "debug.h"
|
||||
#include <stdexcept> // for stl::out_of_range
|
||||
#ifdef HAVE_MEMORY_H
|
||||
# include <memory.h>
|
||||
#include <memory.h>
|
||||
#endif
|
||||
|
||||
int wchar16len(const WCHAR16* s)
|
||||
|
@ -55,8 +55,8 @@ int wchar16len(const WCHAR16* s)
|
|||
//=============================================================================
|
||||
// class wc16_string
|
||||
//
|
||||
// This clas implements enough of the std::basic_string interface so we
|
||||
// can use it like an STL string.
|
||||
// This clas implements enough of the std::basic_string interface so we
|
||||
// can use it like an STL string.
|
||||
//
|
||||
// In an ideal world we this would be a std::basic_string instantiation, but
|
||||
// UNIX doesn't seem to dealing 16 bit wide chars, it uses 32 bit chars.
|
||||
|
@ -76,17 +76,19 @@ public:
|
|||
void Release();
|
||||
void Resize(int newlen);
|
||||
void CopyString(const wc16_string_impl& rhs);
|
||||
// note: does not alter this->referenceCount, and ASSERTs that refcount == 1
|
||||
// note: does not alter this->referenceCount, and ASSERTs that refcount == 1
|
||||
|
||||
~wc16_string_impl(); // call Release() to delete
|
||||
~wc16_string_impl(); // call Release() to delete
|
||||
private:
|
||||
void operator = (const wc16_string_impl& rhs) { return; } // don't call
|
||||
void operator=(const wc16_string_impl& rhs)
|
||||
{
|
||||
return;
|
||||
} // don't call
|
||||
};
|
||||
|
||||
static WCHAR16 NULL_WCHAR16 = 0;
|
||||
|
||||
wc16_string::wc16_string()
|
||||
: mpData(0)
|
||||
wc16_string::wc16_string() : mpData(0)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -112,42 +114,39 @@ wc16_string::~wc16_string()
|
|||
mpData->Release();
|
||||
}
|
||||
|
||||
void wc16_string::operator = (const wc16_string& rhs)
|
||||
void wc16_string::operator=(const wc16_string& rhs)
|
||||
{
|
||||
if (mpData)
|
||||
mpData->Release();
|
||||
|
||||
mpData = rhs.mpData;
|
||||
|
||||
if( mpData )
|
||||
if (mpData)
|
||||
mpData->AddRef();
|
||||
}
|
||||
|
||||
|
||||
int wc16_string::compare(const wc16_string& rhs) const
|
||||
{
|
||||
if( length() > rhs.length() )
|
||||
if (length() > rhs.length())
|
||||
return 1;
|
||||
else if ( length() < rhs.length() )
|
||||
else if (length() < rhs.length())
|
||||
return -1;
|
||||
else
|
||||
return memcmp( c_str(), rhs.c_str(), length()*sizeof( WCHAR16 ) );
|
||||
return memcmp(c_str(), rhs.c_str(), length() * sizeof(WCHAR16));
|
||||
}
|
||||
|
||||
wc16_string::size_type
|
||||
wc16_string::length() const
|
||||
wc16_string::size_type wc16_string::length() const
|
||||
{
|
||||
return mpData ? mpData->length : 0;
|
||||
}
|
||||
|
||||
wc16_string::size_type
|
||||
wc16_string::size() const
|
||||
wc16_string::size_type wc16_string::size() const
|
||||
{
|
||||
return mpData ? mpData->length : 0;
|
||||
}
|
||||
|
||||
wc16_string::const_iterator
|
||||
wc16_string::c_str() const
|
||||
wc16_string::const_iterator wc16_string::c_str() const
|
||||
{
|
||||
if (mpData == 0)
|
||||
return &NULL_WCHAR16;
|
||||
|
@ -157,35 +156,24 @@ wc16_string::c_str() const
|
|||
return mpData->pString;
|
||||
}
|
||||
|
||||
wc16_string::const_iterator
|
||||
wc16_string::begin() const
|
||||
wc16_string::const_iterator wc16_string::begin() const
|
||||
{
|
||||
return (const_cast<wc16_string*>(this))->begin();
|
||||
}
|
||||
|
||||
wc16_string::iterator
|
||||
wc16_string::begin()
|
||||
wc16_string::iterator wc16_string::begin()
|
||||
{
|
||||
return mpData ? mpData->pString : &NULL_WCHAR16;
|
||||
}
|
||||
|
||||
wc16_string::const_iterator
|
||||
wc16_string::end() const
|
||||
wc16_string::const_iterator wc16_string::end() const
|
||||
{
|
||||
return
|
||||
const_cast< iterator >(
|
||||
mpData
|
||||
? mpData->pString + mpData->length
|
||||
: &NULL_WCHAR16 );
|
||||
return const_cast<iterator>(mpData ? mpData->pString + mpData->length : &NULL_WCHAR16);
|
||||
}
|
||||
|
||||
wc16_string::iterator
|
||||
wc16_string::end()
|
||||
wc16_string::iterator wc16_string::end()
|
||||
{
|
||||
return
|
||||
mpData
|
||||
? mpData->pString + mpData->length
|
||||
: &NULL_WCHAR16;
|
||||
return mpData ? mpData->pString + mpData->length : &NULL_WCHAR16;
|
||||
}
|
||||
|
||||
wc16_string::const_iterator wc16_string::data() const
|
||||
|
@ -193,7 +181,7 @@ wc16_string::const_iterator wc16_string::data() const
|
|||
return begin();
|
||||
}
|
||||
|
||||
const wc16_string::value_type& wc16_string::operator [] (int i) const
|
||||
const wc16_string::value_type& wc16_string::operator[](int i) const
|
||||
{
|
||||
ASSERT(i >= 0);
|
||||
|
||||
|
@ -206,7 +194,7 @@ const wc16_string::value_type& wc16_string::operator [] (int i) const
|
|||
return mpData->pString[i];
|
||||
}
|
||||
|
||||
wc16_string::value_type& wc16_string::operator [] (int i)
|
||||
wc16_string::value_type& wc16_string::operator[](int i)
|
||||
{
|
||||
ASSERT(i >= 0);
|
||||
|
||||
|
@ -222,24 +210,24 @@ wc16_string::value_type& wc16_string::operator [] (int i)
|
|||
mpData->Release();
|
||||
mpData = newImpl;
|
||||
}
|
||||
|
||||
|
||||
return mpData->pString[i];
|
||||
}
|
||||
|
||||
void wc16_string::resize( size_type nCount )
|
||||
void wc16_string::resize(size_type nCount)
|
||||
{
|
||||
if ( mpData == 0 )
|
||||
if (mpData == 0)
|
||||
{
|
||||
mpData = new wc16_string_impl;
|
||||
}
|
||||
else if ( mpData->refCount > 1 )
|
||||
else if (mpData->refCount > 1)
|
||||
{
|
||||
wc16_string_impl* newImpl = new wc16_string_impl( *mpData );
|
||||
wc16_string_impl* newImpl = new wc16_string_impl(*mpData);
|
||||
mpData->Release();
|
||||
mpData = newImpl;
|
||||
}
|
||||
|
||||
mpData->Resize( nCount );
|
||||
mpData->Resize(nCount);
|
||||
}
|
||||
|
||||
// useful to convert to network byte order
|
||||
|
@ -264,17 +252,17 @@ void wc16_string::swapbytes()
|
|||
|
||||
wc16_string_impl::wc16_string_impl()
|
||||
{
|
||||
length = 0;
|
||||
pString = new WCHAR16[1];
|
||||
length = 0;
|
||||
pString = new WCHAR16[1];
|
||||
refCount = 1;
|
||||
}
|
||||
|
||||
wc16_string_impl::wc16_string_impl(const wc16_string_impl& rhs)
|
||||
{
|
||||
int newlen = rhs.length;
|
||||
pString = new WCHAR16[newlen + 1];
|
||||
length = newlen;
|
||||
refCount = 1;
|
||||
pString = new WCHAR16[newlen + 1];
|
||||
length = newlen;
|
||||
refCount = 1;
|
||||
|
||||
memcpy(pString, rhs.pString, newlen * sizeof(WCHAR16));
|
||||
}
|
||||
|
@ -306,13 +294,13 @@ void wc16_string_impl::Resize(int newlen)
|
|||
return;
|
||||
|
||||
WCHAR16* newString = new WCHAR16[newlen + 1];
|
||||
|
||||
|
||||
if (newlen < length)
|
||||
{
|
||||
memcpy(newString, pString, newlen * sizeof(WCHAR16));
|
||||
delete [] pString;
|
||||
pString = newString;
|
||||
length = newlen;
|
||||
length = newlen;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -320,7 +308,7 @@ void wc16_string_impl::Resize(int newlen)
|
|||
memset(newString + length, 0, (newlen - length) * sizeof(WCHAR16));
|
||||
delete [] pString;
|
||||
pString = newString;
|
||||
length = newlen;
|
||||
length = newlen;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -333,10 +321,9 @@ void wc16_string_impl::CopyString(const wc16_string_impl& rhs)
|
|||
if (rhs.length != this->length)
|
||||
{
|
||||
delete [] pString;
|
||||
pString = new WCHAR16[newlen + 1];
|
||||
pString = new WCHAR16[newlen + 1];
|
||||
this->length = newlen;
|
||||
}
|
||||
|
||||
memcpy(this->pString, rhs.pString, newlen * sizeof(WCHAR16));
|
||||
}
|
||||
|
||||
|
|
|
@ -3,29 +3,29 @@
|
|||
// Portions created by Tripwire, Inc. are copyright (C) 2000-2018 Tripwire,
|
||||
// Inc. Tripwire is a registered trademark of Tripwire, Inc. All rights
|
||||
// reserved.
|
||||
//
|
||||
//
|
||||
// This program is free software. The contents of this file are subject
|
||||
// to the terms of the GNU General Public License as published by the
|
||||
// Free Software Foundation; either version 2 of the License, or (at your
|
||||
// option) any later version. You may redistribute it and/or modify it
|
||||
// only in compliance with the GNU General Public License.
|
||||
//
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful.
|
||||
// However, this program is distributed AS-IS WITHOUT ANY
|
||||
// WARRANTY; INCLUDING THE IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS
|
||||
// FOR A PARTICULAR PURPOSE. Please see the GNU General Public License
|
||||
// for more details.
|
||||
//
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
|
||||
// USA.
|
||||
//
|
||||
//
|
||||
// Nothing in the GNU General Public License or any other license to use
|
||||
// the code or files shall permit you to use Tripwire's trademarks,
|
||||
// service marks, or other intellectual property without Tripwire's
|
||||
// prior written consent.
|
||||
//
|
||||
//
|
||||
// If you have any questions, please contact Tripwire, Inc. at either
|
||||
// info@tripwire.org or www.tripwire.org.
|
||||
//
|
||||
|
@ -44,16 +44,16 @@
|
|||
#endif
|
||||
|
||||
#if WCHAR_IS_16_BITS
|
||||
typedef unsigned short WCHAR16;
|
||||
typedef unsigned short WCHAR16;
|
||||
#else
|
||||
typedef uint16 WCHAR16; // unix has 4 byte wchar_t, but we want to standardize on 16 bit wide chars
|
||||
typedef uint16 WCHAR16; // unix has 4 byte wchar_t, but we want to standardize on 16 bit wide chars
|
||||
#endif
|
||||
|
||||
//=============================================================================
|
||||
// class wc16_string
|
||||
//
|
||||
// This clas implements enough of the std::basic_string interface so we
|
||||
// can use it like an STL string.
|
||||
// This clas implements enough of the std::basic_string interface so we
|
||||
// can use it like an STL string.
|
||||
//
|
||||
// In an ideal world we this would be a std::basic_string instantiation, but
|
||||
// UNIX doesn't seem to dealing 16 bit wide chars, it uses 32 bit chars.
|
||||
|
@ -70,49 +70,46 @@ class wc16_string_impl;
|
|||
class wc16_string
|
||||
{
|
||||
public:
|
||||
|
||||
typedef WCHAR16 value_type;
|
||||
typedef value_type* iterator;
|
||||
typedef const value_type* const_iterator;
|
||||
typedef size_t size_type;
|
||||
typedef WCHAR16 value_type;
|
||||
typedef value_type* iterator;
|
||||
typedef const value_type* const_iterator;
|
||||
typedef size_t size_type;
|
||||
|
||||
|
||||
wc16_string();
|
||||
wc16_string( const wc16_string& rhs);
|
||||
wc16_string( const_iterator pStr);
|
||||
wc16_string(const wc16_string& rhs);
|
||||
wc16_string(const_iterator pStr);
|
||||
|
||||
~wc16_string();
|
||||
|
||||
void operator=( const wc16_string& rhs );
|
||||
int compare( const wc16_string& rhs ) const;
|
||||
void operator=(const wc16_string& rhs);
|
||||
int compare(const wc16_string& rhs) const;
|
||||
|
||||
size_type length() const;
|
||||
size_type size() const;
|
||||
|
||||
const_iterator begin() const;
|
||||
iterator begin();
|
||||
size_type length() const;
|
||||
size_type size() const;
|
||||
|
||||
const_iterator end() const;
|
||||
iterator end();
|
||||
const_iterator begin() const;
|
||||
iterator begin();
|
||||
|
||||
const_iterator end() const;
|
||||
iterator end();
|
||||
|
||||
const_iterator c_str() const;
|
||||
const_iterator data() const;
|
||||
|
||||
const_iterator c_str() const;
|
||||
const_iterator data() const;
|
||||
|
||||
bool empty() const
|
||||
{
|
||||
{
|
||||
return length() == 0;
|
||||
}
|
||||
|
||||
const value_type& operator[]( int i ) const; // throw std::out_of_range
|
||||
value_type& operator[]( int i ); // throw std::out_of_range
|
||||
const value_type& operator[](int i) const; // throw std::out_of_range
|
||||
value_type& operator[](int i); // throw std::out_of_range
|
||||
|
||||
void resize( size_type );
|
||||
void swapbytes(); // useful to convert to network byte order
|
||||
void resize(size_type);
|
||||
void swapbytes(); // useful to convert to network byte order
|
||||
|
||||
private:
|
||||
|
||||
wc16_string_impl* mpData;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
|
|
165
src/db/block.h
165
src/db/block.h
|
@ -3,29 +3,29 @@
|
|||
// Portions created by Tripwire, Inc. are copyright (C) 2000-2018 Tripwire,
|
||||
// Inc. Tripwire is a registered trademark of Tripwire, Inc. All rights
|
||||
// reserved.
|
||||
//
|
||||
//
|
||||
// This program is free software. The contents of this file are subject
|
||||
// to the terms of the GNU General Public License as published by the
|
||||
// Free Software Foundation; either version 2 of the License, or (at your
|
||||
// option) any later version. You may redistribute it and/or modify it
|
||||
// only in compliance with the GNU General Public License.
|
||||
//
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful.
|
||||
// However, this program is distributed AS-IS WITHOUT ANY
|
||||
// WARRANTY; INCLUDING THE IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS
|
||||
// FOR A PARTICULAR PURPOSE. Please see the GNU General Public License
|
||||
// for more details.
|
||||
//
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
|
||||
// USA.
|
||||
//
|
||||
//
|
||||
// Nothing in the GNU General Public License or any other license to use
|
||||
// the code or files shall permit you to use Tripwire's trademarks,
|
||||
// service marks, or other intellectual property without Tripwire's
|
||||
// prior written consent.
|
||||
//
|
||||
//
|
||||
// If you have any questions, please contact Tripwire, Inc. at either
|
||||
// info@tripwire.org or www.tripwire.org.
|
||||
//
|
||||
|
@ -45,78 +45,87 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// cBlock
|
||||
//-----------------------------------------------------------------------------
|
||||
template <int SIZE>
|
||||
class cBlock
|
||||
template<int SIZE> class cBlock
|
||||
{
|
||||
public:
|
||||
enum { INVALID_NUM = -1 };
|
||||
enum
|
||||
{
|
||||
INVALID_NUM = -1
|
||||
};
|
||||
|
||||
cBlock();
|
||||
|
||||
void SetDirty () { mbDirty = true; }
|
||||
bool IsDirty () const { return mbDirty; }
|
||||
int GetBlockNum () const { return mBlockNum; }
|
||||
int8* GetData() { return mpData; }
|
||||
|
||||
bool AssertValid() const;
|
||||
// this asserts and returns false if the guard bytes have been corrupted
|
||||
bool IsValidAddr(int8* pAddr) const;
|
||||
// returns true if pAddr falls within mpData
|
||||
void SetDirty()
|
||||
{
|
||||
mbDirty = true;
|
||||
}
|
||||
bool IsDirty() const
|
||||
{
|
||||
return mbDirty;
|
||||
}
|
||||
int GetBlockNum() const
|
||||
{
|
||||
return mBlockNum;
|
||||
}
|
||||
int8* GetData()
|
||||
{
|
||||
return mpData;
|
||||
}
|
||||
|
||||
bool AssertValid() const;
|
||||
// this asserts and returns false if the guard bytes have been corrupted
|
||||
bool IsValidAddr(int8* pAddr) const;
|
||||
// returns true if pAddr falls within mpData
|
||||
protected:
|
||||
enum { NUM_GUARD_BLOCKS = 8, // associated with BYTE_ALIGN: see ctor for info
|
||||
GUARD_BLOCK_VAL = 0xAB }; // odd, non-zero value for debugging
|
||||
enum
|
||||
{
|
||||
NUM_GUARD_BLOCKS = 8, // associated with BYTE_ALIGN: see ctor for info
|
||||
GUARD_BLOCK_VAL = 0xAB
|
||||
}; // odd, non-zero value for debugging
|
||||
|
||||
// guardMin and guardMax are used to detect bad writes
|
||||
uint8 mGuardMin[NUM_GUARD_BLOCKS];
|
||||
int8 mpData[SIZE];
|
||||
uint8 mGuardMax[NUM_GUARD_BLOCKS];
|
||||
bool mbDirty;
|
||||
int mBlockNum;
|
||||
uint8 mGuardMin[NUM_GUARD_BLOCKS];
|
||||
int8 mpData[SIZE];
|
||||
uint8 mGuardMax[NUM_GUARD_BLOCKS];
|
||||
bool mbDirty;
|
||||
int mBlockNum;
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// ctor
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
template <int SIZE>
|
||||
inline cBlock<SIZE>::cBlock()
|
||||
: mbDirty (false),
|
||||
mBlockNum (cBlock::INVALID_NUM)
|
||||
template<int SIZE> inline cBlock<SIZE>::cBlock() : mbDirty(false), mBlockNum(cBlock::INVALID_NUM)
|
||||
{
|
||||
// To prevent misaligned memory access, the size of the data and the
|
||||
// number of guard blocks must be a multiple of the byte alignment
|
||||
// To prevent misaligned memory access, the size of the data and the
|
||||
// number of guard blocks must be a multiple of the byte alignment
|
||||
// and they both must be at least as large as the byte alignment
|
||||
ASSERT( 0 == ( SIZE % BYTE_ALIGN ) );
|
||||
ASSERT( 0 == ( NUM_GUARD_BLOCKS % BYTE_ALIGN ) );
|
||||
ASSERT( SIZE >= BYTE_ALIGN );
|
||||
ASSERT( NUM_GUARD_BLOCKS >= BYTE_ALIGN );
|
||||
|
||||
ASSERT(0 == (SIZE % BYTE_ALIGN));
|
||||
ASSERT(0 == (NUM_GUARD_BLOCKS % BYTE_ALIGN));
|
||||
ASSERT(SIZE >= BYTE_ALIGN);
|
||||
ASSERT(NUM_GUARD_BLOCKS >= BYTE_ALIGN);
|
||||
|
||||
// init guard blocks to dummy value
|
||||
for( int i = 0; i < NUM_GUARD_BLOCKS; i++ )
|
||||
for (int i = 0; i < NUM_GUARD_BLOCKS; i++)
|
||||
{
|
||||
mGuardMin[i] = (uint8)GUARD_BLOCK_VAL;
|
||||
mGuardMax[i] = (uint8)GUARD_BLOCK_VAL;
|
||||
}
|
||||
|
||||
// zero out memory
|
||||
memset( mpData, 0, SIZE );
|
||||
memset(mpData, 0, SIZE);
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// ctor
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
template <int SIZE>
|
||||
inline bool cBlock<SIZE>::AssertValid() const
|
||||
template<int SIZE> inline bool cBlock<SIZE>::AssertValid() const
|
||||
{
|
||||
// determine if guard bites have been accidentally overwritten
|
||||
for( int i = 0; i < NUM_GUARD_BLOCKS; i++ )
|
||||
for (int i = 0; i < NUM_GUARD_BLOCKS; i++)
|
||||
{
|
||||
if(
|
||||
( mGuardMin[i] != (uint8) GUARD_BLOCK_VAL )
|
||||
||
|
||||
( mGuardMax[i] != (uint8) GUARD_BLOCK_VAL )
|
||||
)
|
||||
if ((mGuardMin[i] != (uint8)GUARD_BLOCK_VAL) || (mGuardMax[i] != (uint8)GUARD_BLOCK_VAL))
|
||||
{
|
||||
ASSERT( false );
|
||||
ASSERT(false);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -124,56 +133,62 @@ inline bool cBlock<SIZE>::AssertValid() const
|
|||
return true;
|
||||
}
|
||||
|
||||
template <int SIZE>
|
||||
inline bool cBlock<SIZE>::IsValidAddr(int8* pAddr) const
|
||||
template<int SIZE> inline bool cBlock<SIZE>::IsValidAddr(int8* pAddr) const
|
||||
{
|
||||
return ( (pAddr >= &mpData[0]) && (pAddr <= &mpData[SIZE-1]) );
|
||||
return ((pAddr >= &mpData[0]) && (pAddr <= &mpData[SIZE - 1]));
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// cBlockImpl
|
||||
//-----------------------------------------------------------------------------
|
||||
template <int SIZE>
|
||||
class cBlockImpl : public cBlock<SIZE>
|
||||
template<int SIZE> class cBlockImpl : public cBlock<SIZE>
|
||||
{
|
||||
public:
|
||||
enum { INVALID_NUM = -1 };
|
||||
enum
|
||||
{
|
||||
INVALID_NUM = -1
|
||||
};
|
||||
|
||||
cBlockImpl();
|
||||
|
||||
void SetBlockNum ( int blockNum ) { cBlock<SIZE>::mBlockNum = blockNum; }
|
||||
void SetTimestamp( uint32 timestamp ) { mTimestamp = timestamp; }
|
||||
uint32 GetTimestamp() const { return mTimestamp; }
|
||||
void SetBlockNum(int blockNum)
|
||||
{
|
||||
cBlock<SIZE>::mBlockNum = blockNum;
|
||||
}
|
||||
void SetTimestamp(uint32 timestamp)
|
||||
{
|
||||
mTimestamp = timestamp;
|
||||
}
|
||||
uint32 GetTimestamp() const
|
||||
{
|
||||
return mTimestamp;
|
||||
}
|
||||
|
||||
void Write ( cBidirArchive& arch ); //throw( eArchive )
|
||||
void Read ( cBidirArchive& arch, int blockNum = INVALID_NUM ); //throw( eArchive )
|
||||
void Write(cBidirArchive& arch); //throw( eArchive )
|
||||
void Read(cBidirArchive& arch, int blockNum = INVALID_NUM); //throw( eArchive )
|
||||
// if blockNum is INVALID_NUM, then it reads in the current block number
|
||||
protected:
|
||||
uint32 mTimestamp;
|
||||
uint32 mTimestamp;
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// ctor
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
template <int SIZE>
|
||||
inline cBlockImpl<SIZE>::cBlockImpl()
|
||||
: cBlock<SIZE> ( ),
|
||||
mTimestamp (0)
|
||||
template<int SIZE> inline cBlockImpl<SIZE>::cBlockImpl() : cBlock<SIZE>(), mTimestamp(0)
|
||||
{
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Write
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
template <int SIZE>
|
||||
inline void cBlockImpl<SIZE>::Write( cBidirArchive& arch ) //throw( eArchive )
|
||||
template<int SIZE> inline void cBlockImpl<SIZE>::Write(cBidirArchive& arch) //throw( eArchive )
|
||||
{
|
||||
ASSERT( mbDirty );
|
||||
ASSERT( (mBlockNum >= 0) && (((mBlockNum + 1) * SIZE) <= arch.Length()) );
|
||||
ASSERT(mbDirty);
|
||||
ASSERT((mBlockNum >= 0) && (((mBlockNum + 1) * SIZE) <= arch.Length()));
|
||||
|
||||
arch.Seek ( (cBlock<SIZE>::mBlockNum * SIZE), cBidirArchive::BEGINNING );
|
||||
arch.WriteBlob ( cBlock<SIZE>::mpData, SIZE );
|
||||
arch.Seek((cBlock<SIZE>::mBlockNum * SIZE), cBidirArchive::BEGINNING);
|
||||
arch.WriteBlob(cBlock<SIZE>::mpData, SIZE);
|
||||
|
||||
cBlock<SIZE>::mbDirty = false;
|
||||
}
|
||||
|
@ -181,21 +196,19 @@ inline void cBlockImpl<SIZE>::Write( cBidirArchive& arch ) //throw( eArchive )
|
|||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Read
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
template <int SIZE>
|
||||
inline void cBlockImpl<SIZE>::Read( cBidirArchive& arch, int blockNum ) //throw( eArchive )
|
||||
template<int SIZE> inline void cBlockImpl<SIZE>::Read(cBidirArchive& arch, int blockNum) //throw( eArchive )
|
||||
{
|
||||
if( blockNum != INVALID_NUM )
|
||||
if (blockNum != INVALID_NUM)
|
||||
cBlock<SIZE>::mBlockNum = blockNum;
|
||||
|
||||
ASSERT( (mBlockNum >= 0) && (((mBlockNum + 1) * SIZE) <= arch.Length()) );
|
||||
ASSERT((mBlockNum >= 0) && (((mBlockNum + 1) * SIZE) <= arch.Length()));
|
||||
|
||||
// std::cout << "cBlockImpl<SIZE>::Read() mBlockNum = " << mBlockNum << " arch.Length() = " << arch.Length() << std::endl;
|
||||
// std::cout << "cBlockImpl<SIZE>::Read() mBlockNum = " << mBlockNum << " arch.Length() = " << arch.Length() << std::endl;
|
||||
|
||||
arch.Seek ( (cBlock<SIZE>::mBlockNum * SIZE), cBidirArchive::BEGINNING );
|
||||
arch.ReadBlob ( cBlock<SIZE>::mpData, SIZE );
|
||||
arch.Seek((cBlock<SIZE>::mBlockNum * SIZE), cBidirArchive::BEGINNING);
|
||||
arch.ReadBlob(cBlock<SIZE>::mpData, SIZE);
|
||||
|
||||
cBlock<SIZE>::mbDirty = false;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue