Remove UCS2-related dead code, in the name of clarity

This commit is contained in:
Brian Cox 2016-06-13 20:11:13 -07:00
parent 9a3183a76c
commit 7ad2b52d14
19 changed files with 12 additions and 367 deletions

View File

@ -447,19 +447,6 @@ void cDebug::DebugOut( const char* lpOutputString, ... )
vsprintf(buf, lpOutputString, args);
va_end(args);
#ifdef _UNICODE
wchar_t wbuf[2048];
if (mbstowcs(wbuf, buf, strlen(buf)+1) == -1)
wcscpy(wbuf, _T("XXX Unconvertable mb character detected in cDebug::DebugOut()\n") );
#if !USE_OUTPUT_DEBUG_STRING
#ifdef _DEBUG
TCERR << wbuf;
#endif //_DEBUG
#else // USE_OUTPUT_DEBUG_STRING
::OutputDebugString(wbuf);
#endif // USE_OUTPUT_DEBUG_STRING
#else // _UNICODE
#if !USE_OUTPUT_DEBUG_STRING
#ifdef _DEBUG
TCERR << buf;
@ -467,7 +454,6 @@ void cDebug::DebugOut( const char* lpOutputString, ... )
#else // USE_OUTPUT_DEBUG_STRING
::OutputDebugString(buf);
#endif // USE_OUTPUT_DEBUG_STRING
#endif // _UNICODE
TCOUT.flush();
}
@ -491,22 +477,12 @@ void cDebug::DebugOut( const wchar_t* lpOutputString, ... )
#endif
va_end(args);
#ifdef _UNICODE
#if !USE_OUTPUT_DEBUG_STRING
#ifdef _DEBUG
TCERR << buf;
#endif //_DEBUG
#else // USE_OUTPUT_DEBUG_STRING
::OutputDebugString(buf);
#endif // USE_OUTPUT_DEBUG_STRING
#else
char nbuf[1024];
#if IS_UNIX
strcpy(nbuf, buf);
#else
if (wcstombs(nbuf, buf, wcslen(buf)+1) == -1)
strcpy(nbuf, "XXX Unconvertable wide char detected in cDebug::DebugOut()\n");
#endif
#if !USE_OUTPUT_DEBUG_STRING
#ifdef _DEBUG

View File

@ -235,32 +235,7 @@ bool cNonNarrowableCharEncoder::NeedsEncoding(
TSTRING::const_iterator first,
TSTRING::const_iterator last ) const
{
#ifdef _UNICODE
ASSERT( IsSingleTCHAR( first, last ) );
char amb[ MB_LEN_MAX ];
TCHAR awch[] = { *first, 0 };
// TODO:BAM -- this is not really correct! Convert will not honor nSource!!
// it looks for the first null char!
try
{
int ret = iCodeConverter::GetInstance()->Convert( amb, sizeof( amb ), awch, 1 );
return( -1 == ret );
}
catch( eError& )
{
return true;
}
#else
return false; // all chars are narrow
#endif
}

View File

@ -61,30 +61,6 @@ void cFileHeaderID::operator=( const TCHAR* pszId )
// mIDLen = 0;
// return;
//}
#ifdef _UNICODE
size_t N = (::wcslen( pszId ) * MB_CUR_MAX); // Try the easy way!
if ( !(N < cFileHeaderID::MAXBYTES) )
{
N = ::wcstombs( 0, pszId, (size_t)-1 ); // Try again!
if ( N == (size_t)-1 )
{
throw
eCharacterEncoding(
TSS_GetString( cCore, core::STR_ERR_BADCHAR ) );
}
else if ( !(N < cFileHeaderID::MAXBYTES) )
{
throw
eCharacter(
TSS_GetString( cCore, core::STR_ERR_OVERFLOW ) );
}
}
mIDLen = (int16)(::wcstombs( mID, pszId, N )); // Do it
#else
size_t N = ::strlen( pszId );
if ( !(N < cFileHeaderID::MAXBYTES) )
@ -92,8 +68,6 @@ void cFileHeaderID::operator=( const TCHAR* pszId )
mIDLen = static_cast<int16>( N ); // know len is less than MAXBYTES
::memcpy( mID, pszId, N * sizeof(char) );
#endif
}
void cFileHeaderID::operator=( const cFileHeaderID& rhs )

View File

@ -41,24 +41,6 @@
cSerializerImpl::SerMap cSerializerImpl::mSerCreateMap ;
cSerializerImpl::SerRefCountMap cSerializerImpl::mSerRefCountCreateMap ;
// RAD:09/01/99 -- No longer needed!
///////////////////////////////////////////////////////////////////////////////
// util_TstrToStr -- converts the passed in tstring into a narrow string. maxSize
// indicates the size of the narrow buffer
///////////////////////////////////////////////////////////////////////////////
// static inline void util_TstrToStr(char* pStr, const TCHAR* pTstr, int maxSize)
// {
// #ifdef _UNICODE
// ASSERT( maxSize >= wcstombs( 0, pTstr
// wcstombs(pStr, pTstr, maxSize);
// #else
// strncpy( pStr, pTstr, maxSize );
// #endif
// }
//
///////////////////////////////////////////////////////////////////////////////
// util_GetCrc -- calculates the crc for the narrow version of the type's AsString()
///////////////////////////////////////////////////////////////////////////////
@ -74,30 +56,12 @@ static uint32 util_GetCRC( const cType& type )
// - Increased performance by removing superflous conversion
// when type.AsString() is already narrow.
//
#ifdef _UNICODE
char sz[256];
const uint8* pszType = (const uint8*)(&sz[0]);
const wchar_t* wsz = type.AsString();
ASSERT( countof(sz) >= ::wcstombs( 0, wsz, size_t(-1) ) );
int nBytes = (int)::wcstombs( (char*)pszType, wsz, countof(sz) );
if ( nBytes == -1 ) // Bad character conversion!
{
throw eCharacterEncoding(
TSS_GetString( cCore, core::STR_ERR_BADCHAR ) );
}
#else//!_UNICODE
// 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 );
#endif//_UNICODE
ASSERT( sizeof(uint8) == sizeof(byte) );
ASSERT( pszType && *pszType );

View File

@ -78,11 +78,7 @@ public:
DECLARE_TYPEDSERIALIZABLE()
};
#ifdef _UNICODE
typedef cSerializableWString cSerializableTSTRING;
#else
typedef cSerializableNString cSerializableTSTRING;
#endif
#endif

View File

@ -128,19 +128,6 @@ inline bool tss_find_in_hash( const wc16_string& lhs, TSTRING& rhs )
return( tss_GetHashTable().Lookup( lhs, rhs ) );
}
#ifdef _UNICODE
inline bool tss_find_in_hash( const wc16_string& lhs, std::string& rhs )
{
return false; // don't have a hash table for this!
}
inline void tss_insert_in_hash( const wc16_string& lhs, const std::string& rhs )
{
return; // don't have a hash table for this!
}
#endif
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// Type Dispatched Conversions

View File

@ -147,13 +147,7 @@ TSTRING cUnixFSServices::GetErrString() const
{
TSTRING ret;
char* pErrorStr = strerror(errno);
#ifdef _UNICODE
wchar_t pBuf[1024];
mbstowcs(pBuf, pErrorStr, 1024);
ret = pBuf;
#else
ret = pErrorStr;
#endif
return ret;
}
@ -268,14 +262,7 @@ TSTRING& cUnixFSServices::MakeTempFilename( TSTRING& strName ) const throw(eFSSe
char szTemplate[iFSServices::TW_MAX_PATH];
int fd;
#ifdef _UNICODE
// convert template from wide character to multi-byte string
char mbBuf[iFSServices::TW_MAX_PATH];
wcstombs( mbBuf, strName.c_str(), strName.length() + 1 );
strcpy( szTemplate, mbBuf );
#else
strcpy( szTemplate, strName.c_str() );
#endif
#ifdef HAVE_MKSTEMP
// create temp filename and check to see if mkstemp failed
@ -297,15 +284,7 @@ TSTRING& cUnixFSServices::MakeTempFilename( TSTRING& strName ) const throw(eFSSe
#endif
// change name so that it has the XXXXXX part filled in
#ifdef _UNICODE
// convert name from multi-byte to wide character string
wchar_t wcsbuf[1024];
mbstowcs( wcsbuf, pchTempFileName, strlen( pchTempFileName ) + 1 ));
strName = wcsbuf;
#else
strName = pchTempFileName;
#endif
// Linux creates the file!! Doh!
// So I'll always attempt to delete it -bam

View File

@ -372,12 +372,8 @@ void cFCOName::Read(iSerializer* pSerializer, int32 version)
int16 dummy = 0;
// serialize the delimiter
#ifdef _UNICODE
pSerializer->ReadInt16( (int16&)mDelimiter );
#else
pSerializer->ReadInt16( dummy ); // delimiter, but it's always '/' anyway in OST.
mDelimiter = '/';
#endif
mDelimiter = '/';
// read the case-sensitiveness
pSerializer->ReadInt16(dummy);
@ -402,13 +398,8 @@ void cFCOName::Write(iSerializer* pSerializer) const
pSerializer->WriteString(AsString());
// serialize the delimiter
#ifdef _UNICODE
pSerializer->WriteInt16(mDelimiter);
#else
unsigned short wc = (unsigned short)'/';
unsigned short wc = (unsigned short)'/';
pSerializer->WriteInt16(wc);
#endif
pSerializer->WriteInt16( mbCaseSensitive ? (int16)1 : (int16)0);
}

View File

@ -342,12 +342,9 @@ TSTRING cChecksumSignature::AsString() const
ps_signature = pltob64(local, buf, 2);
//ps_signature holds base64 representation of mCRC
#ifdef _UNICODE
ret.resize(strlen(ps_signature));
mbstowcs((TCHAR*)ret.data(), ps_signature, strlen(ps_signature));
#else
ret.append(ps_signature);
#endif
return ret;
}
@ -436,12 +433,7 @@ TSTRING cCRC32Signature::AsString() const
ps_signature = pltob64(&local, buf, 1);
//ps_signature holds base64 representation of mCRCInfo.crc
#ifdef _UNICODE
ret.resize(strlen(ps_signature));
mbstowcs((TCHAR*)ret.data(), ps_signature, strlen(ps_signature));
#else
ret.append(ps_signature);
#endif
return ret;
}
@ -555,14 +547,7 @@ TSTRING cMD5Signature::AsString() const
btob64((byte*)md5_digest, buf, SIG_BYTE_SIZE*8);
//converting to base64 representation.
#ifdef _UNICODE //making it TSTRING sensitive
int length;
length = strlen(buf);
ret.resize(length);
mbstowcs((TCHAR*) ret.data(), buf, length);
#else
ret.append(buf);
#endif
return ret;
}
@ -686,14 +671,7 @@ TSTRING cSHASignature::AsString(void) const
ps_signature = btob64((uint8*)sha_digest, buf, SIG_UINT32_SIZE*sizeof(uint32)*8);
//converting to base64 representation.
#ifdef _UNICODE //making it TSTRING sensitive
int length;
length = strlen(ps_signature);
ret.resize(length);
mbstowcs((TCHAR*) ret.data(), ps_signature, length);
#else
ret.append(ps_signature);
#endif
return ret;
}
@ -768,13 +746,7 @@ TSTRING cSHASignature::AsString(void) const
ps_signature = pltob64((uint32*)mSHAInfo.digest, buf, SIG_UINT32_SIZE);
//converting to base64 representation.
#ifdef _UNICODE //making it TSTRING sensitive
int length = strlen(ps_signature);
ret.resize(length);
mbstowcs((TCHAR*) ret.data(), ps_signature, length);
#else
ret.append(ps_signature);
#endif
return ret;
//return ret;
}
@ -877,15 +849,7 @@ TSTRING cHAVALSignature::AsString() const
btob64((byte*)mSignature, buf, 128);
//converting to base64 representation.
#ifdef _UNICODE //making it TSTRING sensitive
int length;
length = strlen(buf);
ret.resize(length);
mbstowcs((TCHAR*) ret.data(), buf, length);
#else
ret.append(buf);
#endif
return ret;
}

View File

@ -74,28 +74,9 @@ void cSyslog::Log(const TCHAR* programName, cSyslog::LogType logType, const TCHA
(void)logType; // logType is not used for Unix syslog
#ifdef _UNICODE
std::basic_string identString;
std::basic_string msgString;
int count;
count = sizeof(char) * MB_CUR_MAX * _tcslen(programName); // note we use sizeof(char) * 2 because mb chars can be two bytes long
identString.resize(count);
count = wcstombs((char*)identString.data(), programName, count);
identString.resize(count); // count will be set to number of bytes written
count = sizeof(char) * MB_CUR_MAX * _tcslen(message);
msgString.resize(count);
count = wcstombs((char*)msgString.data(), message, count);
msgString.resize(count);
const char* ident = programName.data();
const char* msg = message.data();
#else
ASSERT(sizeof(TCHAR) == sizeof(char));
const char* ident = programName;
const char* msg = message;
#endif
#ifndef SKYOS // Handle an oddball OS that has syslog.h but doesn't implement the calls.
openlog(ident, LOG_PID, LOG_USER);

View File

@ -135,13 +135,7 @@ void cTextDBViewer::PrintDB( cFCODatabaseFile& rd, const TSTRING& strFilename )
else
{
//Gonna have to insert a lame hack here, since ostr.open DEMANDS a const char*!!
#ifdef _UNICODE
char ncBuf[ iFSServices::TW_MAX_PATH ];
wcstombs( ncBuf, strFilename.c_str(), sizeof(char));
fileOut.open( ncBuf );
#else //narrow character mode
fileOut.open( strFilename.c_str() );
#endif
if( fileOut.is_open() )
{

View File

@ -40,15 +40,7 @@
#include "twstrings.h"
#include "buildnum.h"
#ifdef _UNICODE
# ifdef _DEBUG // lets leave out the "u" for non-debug
# define UNICODE_STR _T("u")
# else
# define UNICODE_STR _T("")
# endif
#else
# define UNICODE_STR _T("")
#endif
#define UNICODE_STR _T("")
#ifdef _DEBUG
# define DEBUG_STR _T("d")
@ -115,7 +107,6 @@ TSS_BeginStringtable( cTW )
TSS_StringEntry( tw::STR_DEF_CFG_FILENAME, _T("/etc/tw.cfg")),
#endif
TSS_StringEntry( tw::STR_WIN_NT_ONLY, _T("Open Source Tripwire(R) runs only on Windows NT.")),
TSS_StringEntry( tw::STR_GET_HELP, _T("Use --help to get help.")),
TSS_StringEntry( tw::STR_NEWLINE, _T("\n")),
TSS_StringEntry( tw::STR_ERR_TWCFG_CANT_READ, _T("Configuration file could not be read.")),

View File

@ -52,7 +52,6 @@ TSS_BeginStringIds( tw )
STR_ERR_WRONG_PASSPHRASE_LOCAL,
STR_ERR_WRONG_PASSPHRASE_SITE,
STR_DEF_CFG_FILENAME,
STR_WIN_NT_ONLY,
STR_GET_HELP,
STR_VERSION,
STR_VERSION_LONG,

View File

@ -80,9 +80,6 @@
int _getch(void);
#endif
#ifdef _UNICODE // right now we only need this for unicode
#include <mbstring.h>
#endif
// constants
static const char* POLICY_FILE_MAGIC_8BYTE = "#POLTXT\n";

View File

@ -430,18 +430,11 @@ void cParserUtil::InterpretEscapedString( const std::string& strEscapedString, T
// leaves it alone. After we have the wide string, we convert these encoded Unicode chars into true 16 bit
// Unicode chars.
#ifdef _UNICODE
typedef char INTERCHAR;
const char unicodeEscape = '\x01'; // This value must be chosen carefully so not to conflict with escape chars or mb chars
const char unicodeBase = 'A'; // This value must not fool the convertion from single to multibyte
bool unicodeWasEscaped = false;
std::string strIntermediateString;
#else
// for unix we cheat a bit and do the initial interpretation
// directly to the final string.
typedef TCHAR INTERCHAR;
TSTRING& strIntermediateString = strInterpretedString;
#endif
const char* pchCur = strEscapedString.c_str();
@ -451,15 +444,6 @@ void cParserUtil::InterpretEscapedString( const std::string& strEscapedString, T
{
if( *pchCur != '\\' ) // just regular char
{
#ifdef _UNICODE
// check for our special unicode escape char, and escape it if necessary
if ( *pchCur == unicodeEscape )
{
strIntermediateString += unicodeEscape;
unicodeWasEscaped = true;
}
#endif
strIntermediateString += *pchCur;
}
else // deal with escaped character sequence
@ -497,10 +481,6 @@ void cParserUtil::InterpretEscapedString( const std::string& strEscapedString, T
{
throw eParserBadHex( cStringUtil::StrToTstr( pchCur - (( nCharsRead == 0 ) ? 0 : nCharsRead - 1) ) );
}
// For non-unicode Unix, we don't support > 0xff characters.
// Unicode Windows supports it just fine.
#ifndef _UNICODE
else if (wcEscapedChar > 0xff)
{
throw eParserBadHex( cStringUtil::StrToTstr( pchCur - (( nCharsRead == 0 ) ? 0 : nCharsRead - 1) ) );
@ -509,21 +489,6 @@ void cParserUtil::InterpretEscapedString( const std::string& strEscapedString, T
{
strIntermediateString += static_cast<INTERCHAR>(wcEscapedChar);
}
#else
else if (wcEscapedChar <= 0xff)
{
strIntermediateString += static_cast<INTERCHAR>(wcEscapedChar);
}
else
{
strIntermediateString += unicodeEscape;
strIntermediateString += static_cast<INTERCHAR>((wcEscapedChar >> 12 & 0xf) + unicodeBase);
strIntermediateString += static_cast<INTERCHAR>((wcEscapedChar >> 8 & 0xf) + unicodeBase);
strIntermediateString += static_cast<INTERCHAR>((wcEscapedChar >> 4 & 0xf) + unicodeBase);
strIntermediateString += static_cast<INTERCHAR>((wcEscapedChar & 0xf) + unicodeBase);
unicodeWasEscaped = true;
}
#endif
}
else if( util_IsOctal( *pchCur ) ) // deal with \xxx where 'x' is an octal digit
{
@ -538,48 +503,6 @@ void cParserUtil::InterpretEscapedString( const std::string& strEscapedString, T
}
}
#ifdef _UNICODE
// now convert to the wide vertion
strInterpretedString = cStringUtil::StrToTstr(strIntermediateString);
// search for unicode escapes
if (unicodeWasEscaped)
{
TSTRING::iterator i;
for (i = strInterpretedString.begin(); i != strInterpretedString.end(); ++i)
{
if (*i == static_cast<TCHAR>(unicodeEscape))
{
i = strInterpretedString.erase(i);
ASSERT(i != strInterpretedString.end()); // This would indicate a logic error above
if (*i != static_cast<TCHAR>(unicodeEscape)) // check that this is escaped unicode
{
wchar_t wc;
TSTRING::iterator j = i;
ASSERT(*j >= unicodeBase && *j < unicodeBase + 16);
wc = static_cast<wchar_t>((*j++ - unicodeBase) << 12);
ASSERT(j != strInterpretedString.end());
ASSERT(*j >= unicodeBase && *j < unicodeBase + 16);
wc |= static_cast<wchar_t>((*j++ - unicodeBase) << 8);
ASSERT(j != strInterpretedString.end());
ASSERT(*j >= unicodeBase && *j < unicodeBase + 16);
wc |= static_cast<wchar_t>((*j++ - unicodeBase) << 4);
ASSERT(j != strInterpretedString.end());
ASSERT(*j >= unicodeBase && *j < unicodeBase + 16);
wc |= static_cast<wchar_t>((*j++ - unicodeBase));
i = strInterpretedString.erase(i, j);
i = strInterpretedString.insert(i, wc);
}
}
}
}
#endif
#ifdef _DEBUG
std::string str;

View File

@ -139,17 +139,7 @@ void cPolicyParser::Execute( cGenreSpecListVector& policy, cErrorBucket* pError
void tw_yy_scan::yyerror( const char* pszErr, ... ) //throw( eParserHelper )
{
TOSTRINGSTREAM ssError; // final error string
#ifdef _UNICODE
// passed in strings are narrow so we need to convert them to wide
wchar_t szErrorW[1024];
size_t nWrote = ::mbstowcs( szErrorW, pszErr, strlen( pszErr ) + 1 );
if ( nWrote == (size_t)-1 )
throw eCharacterEncoding( TSS_GetString( cCore, core::STR_ERR_BADCHAR ) );
ssError << szErrorW;
#else
ssError << pszErr;
#endif
throw eParseFailed( ssError.str() );
}

View File

@ -288,14 +288,7 @@ static void FillOutCmdLineInfo(cTWPrintModeCommon* pModeInfo, const cCmdLinePars
{
// this bites! I have to make sure it is a narrow char string
ASSERT(iter.NumParams() > 0); // should be caught by cmd line parser
#ifdef _UNICODE
char* buf = new char[2*(wcslen(iter.ParamAt(0).c_str()) + 1)];
wcstombs(buf, iter.ParamAt(0).c_str(), sizeof(buf));
pModeInfo->mPassPhrase = buf;
delete [] buf;
#else
pModeInfo->mPassPhrase = iter.ParamAt(0);
#endif
}
break;
case cTWPrintCmdLine::REPORTLEVEL:

View File

@ -50,13 +50,9 @@
// UTIL
///////////////////////////////////////////////////////////////////////////////
#ifdef _UNICODE
#define TSS_TCHAR_MIN WCHAR_MIN
#define TSS_TCHAR_MAX WCHAR_MAX
#else
#define TSS_TCHAR_MIN CHAR_MIN
#define TSS_TCHAR_MAX CHAR_MAX
#endif
#define TSS_TCHAR_MIN CHAR_MIN
#define TSS_TCHAR_MAX CHAR_MAX
template< class CharT > bool IsPrintable( const std::basic_string< CharT >& str )
{
@ -288,12 +284,8 @@ public:
//=============================================================
TSTRING strMessWithMe = _T("Mess with me...");
for( size_t c = TSS_TCHAR_MIN;
c < TSS_TCHAR_MAX;
#ifdef _UNICODE
c += ( TSS_TCHAR_MAX / 150 ) )
#else
c < TSS_TCHAR_MAX;
c++ )
#endif
{
if( ( c != '\0' ) )
{
@ -322,12 +314,8 @@ public:
//=============================================================
TSTRING strMessWithMe2 = _T("Mess with me...");
for( size_t ch = TSS_TCHAR_MIN;
ch < TSS_TCHAR_MAX;
#ifdef _UNICODE
ch += ( TSS_TCHAR_MAX / 150 ) )
#else
ch < TSS_TCHAR_MAX;
ch++ )
#endif
{
if( ( ch != '\0' ) )
{

View File

@ -116,23 +116,6 @@ void TestTWUtil()
std::string WideToNarrow( const TSTRING& strWide )
{
#ifdef _UNICODE
std::string strA;
for( TSTRING::const_iterator i = strWide.begin(); i != strWide.end(); i++ )
{
char ach[6];
ASSERT( MB_CUR_MAX <= 6 );
int n = wctomb( ach, *i );
ASSERT( n != -1 );
for( int j = 0; j < n; j++ )
strA += ach[j];
}
return strA;
#else
return strWide;
#endif
return strWide;
}