String handling tweaks (string <--> dbchar) so AROS build works properly.

This commit is contained in:
Brian Cox 2016-04-02 10:38:21 -07:00
parent e71023730e
commit f666409d8f
5 changed files with 34 additions and 432 deletions

View File

@ -150,6 +150,11 @@ inline void tss_insert_in_hash( const wc16_string& lhs, const std::string& rhs )
std::string::const_iterator
cStringUtil::Convert( std::string& nbs, const wc16_string& dbs )
{
#ifdef __AROS__
nbs.resize(dbs.length());
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() );
@ -192,7 +197,7 @@ cStringUtil::Convert( std::string& nbs, const wc16_string& dbs )
tss_insert_in_hash( dbs, nbs );
}
#endif
return nbs.begin();
}
@ -200,6 +205,12 @@ cStringUtil::Convert( std::string& nbs, const wc16_string& dbs )
wc16_string::const_iterator
cStringUtil::Convert( wc16_string& dbs, const std::string& nbs )
{
#ifdef __AROS__
dbs.resize(nbs.length());
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)
@ -231,6 +242,7 @@ cStringUtil::Convert( wc16_string& dbs, const std::string& nbs )
}
else
dbs.resize(0);
#endif
return dbs.begin();
}

View File

@ -143,7 +143,7 @@ public:
class cHierRoot : public cHierNode
{
public:
cHierRoot() : cHierNode( TYPE_ROOT ) {}
cHierRoot() : cHierNode( TYPE_ROOT ), mbCaseSensitive(true), mDelimitingChar('/') {}
cHierAddr mChild; // points to a cHierArray or an invalid address
bool mbCaseSensitive; // determines the case-sensitiveness of lookups, ordering, etc.
@ -177,10 +177,11 @@ public:
}
mChild.Read ( arch );
int32 cs;
arch.ReadInt32 ( cs );
arch.ReadInt32(cs);
mbCaseSensitive = cs ? true : false;
TSTRING dc;
arch.ReadString ( dc );
arch.ReadString(dc);
if( dc.length() != 1 )
{
ASSERT( false );

View File

@ -93,7 +93,7 @@ void cFCOName::ClearNameTable()
// ctor, dtor
///////////////////////////////////////////////////////////////////////////////
cFCOName::cFCOName(iFCONameInfo* pNI) :
mpPathName(0)
mpPathName(0), mDelimiter('/')
{
SetNameInfo(pNI);
mpPathName = new cFCOName_i;
@ -118,7 +118,7 @@ cFCOName::cFCOName(const cFCOName& rhs) :
}
cFCOName::cFCOName(const TSTRING& rhs, iFCONameInfo* pNI) :
mpPathName(0)
mpPathName(0), mDelimiter('/')
{
SetNameInfo(pNI);
mpPathName = new cFCOName_i;
@ -132,7 +132,7 @@ cFCOName::cFCOName(const TSTRING& rhs, iFCONameInfo* pNI) :
}
cFCOName::cFCOName(const TCHAR* rhs, iFCONameInfo* pNI) :
mpPathName(0)
mpPathName(0), mDelimiter('/')
{
SetNameInfo(pNI);
mpPathName = new cFCOName_i;
@ -211,58 +211,6 @@ void cFCOName::operator = (const TCHAR* rhs)
#endif
}
///////////////////////////////////////////////////////////////////////////////
// ParseString
// here is how the string is broken down: between every item in
// mpPathName.mNames, there is assumed to be a delimiter. It is assumed there
// is no delimiter at the beginning of the path. If there is, or if
// double delimiters appear anywhere, that is signified by putting an empty
// string into the list. Any delimiter that appears at the end of the string
// is removed (so that /etc/ becomes /etc)
///////////////////////////////////////////////////////////////////////////////
#define RADS_NTMBS_VER // Try it out first
#ifndef RADS_NTMBS_VER
void cFCOName::ParseString(const TCHAR* str)
{
ASSERT(mpPathName);
mpPathName->ClearList();
int len = _tcslen(str);
TSTRING name;
const TCHAR* pEnd = str + len;
const TCHAR* pChar = str;
// break off the next word to add..
const TCHAR* pBegin = pChar;
while(pChar < pEnd)
{
while((*pChar != mDelimiter) && (pChar < pEnd))
pChar++;
// if pChar == pBegin, then we have an extra delimiter; add it.
// TODO -- right now, I will suppress the final delimiter; I don't know if this is the
// right thing to do
if(pChar == pBegin)
{
// NOTE -- there is a special case here -- "/" (the root directory); it will be represented
// as a single empty node. This is handled by the (pChar != str) below.
if((pChar + 1 >= pEnd) && (pChar != str))
// don't add the trailing slash
break;
name = _T("");
}
else
name.assign(pBegin, (pChar - pBegin));
cFCONameTblNode* pNode = cFCOName_i::msNameTbl.CreateNode(name);
mpPathName->mNames.push_back(pNode);
pBegin = ++pChar;
}
}
#else//RADS_NTMBS_VER
void cFCOName::ParseString( const TCHAR* pszin )
{
ASSERT(mpPathName != 0);
@ -280,10 +228,11 @@ void cFCOName::ParseString( const TCHAR* pszin )
while (at < end)
{
while (!(*at == mDelimiter) && (at < end))
while (*at && !(*at == mDelimiter) && (at < end))
at++;
TSTRING name(begin, at);
if (name.length() > 0 || components == 0)
{
cFCONameTblNode* pNode =
@ -292,12 +241,13 @@ void cFCOName::ParseString( const TCHAR* pszin )
mpPathName->mNames.push_back(pNode);
}
components++;
begin = (at = tss::strinc(at));
components++;
at++;
begin=at;
//begin = (at = tss::strinc(at));
}
}
#endif//RADS_NTMBS_VER
///////////////////////////////////////////////////////////////////////////////
// AsString
@ -322,14 +272,15 @@ TSTRING cFCOName::AsString() const
return str;
}
// end ugly root dir hacks ...
ListType::iterator i = mpPathName->mNames.begin();
while(i != mpPathName->mNames.end())
{
TSTRING current = (*i)->GetString();
// the loop is constructed in this odd fashion because I don't want a trailing mDelimiter
str += (*i)->GetString();
str += current;
i++;
if(i != mpPathName->mNames.end())
if(i != mpPathName->mNames.end() && current != "/")
str += mDelimiter;
}
@ -416,17 +367,15 @@ void cFCOName::Read(iSerializer* pSerializer, int32 version)
TSTRING str;
pSerializer->ReadString(str);
int16 dummy = 0;
// serialize the delimiter
#ifdef _UNICODE
pSerializer->ReadInt16( (int16&)mDelimiter );
#else
pSerializer->ReadInt16( dummy );
const wchar_t wc = dummy;
size_t N = ::wcstombs( &mDelimiter, &wc, 1 );
if ( N == (size_t)-1 )
throw eCharacterEncoding();
pSerializer->ReadInt16( dummy ); // delimiter, but it's always '/' anyway in OST.
mDelimiter = '/';
#endif
// read the case-sensitiveness
@ -455,8 +404,7 @@ void cFCOName::Write(iSerializer* pSerializer) const
#ifdef _UNICODE
pSerializer->WriteInt16(mDelimiter);
#else
wchar_t wc;
mbtowc(&wc, &mDelimiter, 1);
unsigned short wc = (unsigned short)'/';
pSerializer->WriteInt16(wc);
#endif

View File

@ -1,231 +0,0 @@
//
// The developer of the original code and/or files is Tripwire, Inc.
// Portions created by Tripwire, Inc. are copyright (C) 2000 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.
//
///////////////////////////////////////////////////////////////////////////////
// fconame.h
//
// cFCOName -- represents the name of an FCO
#ifndef __FCONAME_H
#define __FCONAME_H
#ifndef __SERIALIZABLE_H
#include "core/serializable.h"
#endif
#ifndef __FCONAMEINFO_H
#include "fconameinfo.h"
#endif
///////////////////////////////////////////////////////////////////////////////
// class cFCOName -- How we name a FCO. The implementation has ended up being
// a wrapper around a standard string.
///////////////////////////////////////////////////////////////////////////////
class cFCONameTblNode;
class cFCONameIter;
class cFCOName : public iTypedSerializable
{
DECLARE_TYPEDSERIALIZABLE()
public:
typedef cFCONameIter iterator;
cFCOName(iFCONameInfo* iNI = NULL);
cFCOName(const cFCOName& rhs);
explicit cFCOName(const TSTRING& rhs, iFCONameInfo* iNI = NULL);
explicit cFCOName(const TCHAR* rhs, iFCONameInfo* iNI = NULL);
// these ctors are explicit because it is expensive to create these things, so we don't want to
// do it unexpectedly
virtual ~cFCOName();
void operator = (const cFCOName& rhs);
void operator = (const TSTRING& rhs);
void operator = (const TCHAR* rhs);
bool operator < (const cFCOName& rhs) const;
// defines an arbitrary order for cFCONames. This is so that names can
// be stored in trees and other ordered data structures in order to facilitate
// fast lookups.
bool operator == (const cFCOName& rhs) const;
bool operator != (const cFCOName& rhs) const;
bool IsEqual (const cFCOName& rhs) const;
// both of these are synonyms for (GetRelationship(rhs) == REL_EQUAL)
TSTRING AsString() const;
// return a string representation of the string
bool IsCaseSensitive() const;
void SetCaseSensitive(bool val);
// determines how name comparisons are done. If two cFCONames are compared who are
// both case insensitive, a case insensitive compare is done. If both are case sensitive,
// a case sensitive compare is done. If one is and one isn't case sensitive (? TODO: what
// is the right thing to do in this case? ASSERT(0)? do a case sensitive compare??)
TCHAR GetDelimiter() const;
void SetDelimiter(TCHAR delimiter);
// defines what the path-delimiting character is
void Push(const TSTRING& str);
// pushes the named string onto the end of the path. A delimiter is implicitely placed between the old end
// and the new string. if debug is defined, it is asserted that the new string does not contain the
// delimiting character
const TCHAR* Pop();
// removes the last part of the path from the name and returns it. ASSERTS and returns an undefined value if
// the path is empty
const TCHAR* PopFront();
// removes the first part of the path from the name and returns it. ASSERTS and returns an undefined value if
// the path is empty
void Clear();
// removes all elements from the name; after this, GetSize() == 0.
const TCHAR* GetShortName() const;
// this will return the final string in the vector. It will assert that the name is not empty.
int GetSize() const;
// returns the number of path items (strings between delimiters) that are in the fco name. It is always equal
// to the number of delimiters in the path plus one.
enum Relationship
{
REL_BELOW, // an fco is below another (/etc/passwd is below /etc)
REL_ABOVE, // an fco is above another (/etc is above /etc/passwd)
REL_EQUAL, // the fcos are equal (/etc/passwd is equal to /etc/passwd)
REL_UNRELATED // the fcos are unrelated (/var/spool/mail is unrelated to /var/log/pig.log)
};
Relationship GetRelationship(const cFCOName& rhs) const;
// returns the relationship of _this_ name to the one passed in (ie -- if REL_BELOW is returned,
// this fco name is below the one passed in)
virtual void Read (iSerializer* pSerializer, int32 version = 0); // throw (eSerializer, eArchive)
virtual void Write(iSerializer* pSerializer) const; // throw (eSerializer, eArchive)
//////////////////////////////////
// Debugging method
//////////////////////////////////
static void ClearNameTable();
// this method should _only_ be called when the program is exiting, and you are positively sure you
// will not be using or creating any more cFCONames. Violating this rule will result in unpredictable
// results. This clears out the cFCOName internal name table, making memory leaks easier to find.
protected:
friend class cFCOName_i;
friend class cFCONameIter;
void ParseString(const TCHAR* str);
// helper function that takes the pathname pointer to by str and fills out mpPathName
void CopyOnModify();
// if the fconame is modified and mpPathName is shared by more than one object, this will
// release mpPathName and create a new one, so we don't change any other object's data
void SetNameInfo(iFCONameInfo* pNI);
// sets the delimiter and case sensitiveness to the name info's
cFCOName_i* mpPathName;
TCHAR mDelimiter; // the delimiting character in names (ie -- in file systems, it is '/')
bool mbCaseSensitive; // determines whether name compares are case sensitive of not
// this is what type of structure holds the elements of the name
//
typedef std::vector<cFCONameTblNode*> ListType;
#ifdef _DEBUG
TSTRING mDebugStrName; // so we can see this guy's value in the debug window
#endif
};
//-----------------------------------------------------------------------------
// cFCONameIter
//-----------------------------------------------------------------------------
class cFCONameIter_i;
class cFCONameIter
{
public:
cFCONameIter(const cFCOName& name);
~cFCONameIter();
int GetSize() const; // returns the number of entries in the fco name
void SeekBegin();
void Next();
void Prev();
bool Done() const;
int Index() const;
// return the current offset from the beginning of the short name list
void SeekTo( int index );
// seeks to the given index. asserts that the index is appropriate for the
// current fco name.
const TCHAR* GetName() const;
private:
void operator=(const cFCONameIter& rhs); // not impl
cFCONameIter(const cFCONameIter& rhs); // not impl
// the data...
//
const cFCOName& mName;
cFCOName::ListType::const_iterator mIter;
};
//#############################################################################
// inline implementation
inline bool cFCOName::IsCaseSensitive() const
{
return mbCaseSensitive;
}
inline void cFCOName::SetCaseSensitive(bool val)
{
mbCaseSensitive = val;
}
inline TCHAR cFCOName::GetDelimiter() const
{
return mDelimiter;
}
inline void cFCOName::SetDelimiter(TCHAR delimiter)
{
mDelimiter = delimiter;
}
///////////////////////////////////////////////////////////////////////////////
// IsEqual
///////////////////////////////////////////////////////////////////////////////
inline bool cFCOName::IsEqual(const cFCOName& rhs) const
{
return (GetRelationship(rhs) == cFCOName::REL_EQUAL);
}
inline bool cFCOName::operator==(const cFCOName& rhs) const
{
return IsEqual(rhs);
}
inline bool cFCOName::operator!=(const cFCOName& rhs) const
{
return (! IsEqual(rhs));
}
#endif //__FCONAME_H

View File

@ -1,128 +0,0 @@
//
// The developer of the original code and/or files is Tripwire, Inc.
// Portions created by Tripwire, Inc. are copyright (C) 2000 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.
//
///////////////////////////////////////////////////////////////////////////////
// fcosetimpl.h
//
// class cFCOSetImpl -- concrete implementation of an FCO set
// class cFCOIterImpl -- the iterator over the set
#ifndef __FCOSETIMPL_H
#define __FCOSETIMPL_H
#ifndef __FCO_H
#include "fco.h"
#endif
#include "fconame.h"
#ifndef __FCONAME_H
#include "fconame.h"
#endif
class cFCOSetImpl : public iFCOSet
{
friend class cFCOIterImpl;
DECLARE_TYPEDSERIALIZABLE()
public:
cFCOSetImpl();
cFCOSetImpl(const cFCOSetImpl& rhs);
virtual ~cFCOSetImpl();
void operator=(const cFCOSetImpl& rhs);
virtual const iFCOIter* Lookup(const cFCOName& name) const;
virtual iFCOIter* Lookup(const cFCOName& name);
virtual const iFCOIter* GetIter() const;
virtual iFCOIter* GetIter();
virtual void Insert(iFCO* pFCO);
virtual void Clear();
virtual bool IsEmpty() const;
virtual int Size() const { return mFCOSet.size(); };
virtual void TraceContents(int dl = -1) const;
// iSerializable interface
virtual void Read (iSerializer* pSerializer, int32 version = 0); // throw (eSerializer, eArchive)
virtual void Write(iSerializer* pSerializer) const; // throw (eSerializer, eArchive)
private:
void ReturnIter(const cFCOIterImpl* pIter) const;
// returns the iterator to its owner; the reciprocal action
// to Lookup() or GetIter(); called by the iterator when it is destroyed
// class we store in the set below; it is a hack that allows us to
// look up iFCOs using cFCONames in a std::set
class cFCONode
{
public:
iFCO* mpFCO;
const cFCOName* mpFCOName;
cFCONode() : mpFCO(0), mpFCOName(0) {}
cFCONode(iFCO* pFCO) : mpFCO(pFCO), mpFCOName(&pFCO->GetName()) {}
cFCONode(const cFCOName& name) : mpFCO(0), mpFCOName(&name) {}
cFCONode(const cFCONode& rhs) : mpFCO(rhs.mpFCO), mpFCOName(rhs.mpFCOName) {}
bool operator < (const cFCONode& rhs) const { if(mpFCOName) return (*mpFCOName < *rhs.mpFCOName); else return false; }
bool operator ==(const cFCONode& rhs) const { if(mpFCOName) return (*mpFCOName == *rhs.mpFCOName); else return false; }
};
std::set<cFCONode> mFCOSet;
// this is what actually stores the iFCOs.
};
class cFCOIterImpl : public iFCOIter
{
friend class cFCOSetImpl;
public:
cFCOIterImpl(cFCOSetImpl* pSet);
cFCOIterImpl(const cFCOSetImpl* pSet);
virtual void SeekBegin() const;
virtual bool Done() const;
virtual bool IsEmpty() const;
virtual void Next() const;
virtual const iFCO* FCO() const;
virtual iFCO* FCO();
virtual bool SeekToFCO(const cFCOName& name) const;
virtual void Remove();
virtual void Remove() const;
virtual void DestroyIter() const;
private:
virtual ~cFCOIterImpl() ;
cFCOSetImpl* mpSet;
mutable std::set<cFCOSetImpl::cFCONode>::iterator mIter;
// the definition of a const iterator is not that its position cannot change,
// but that it cannot modify the set it is iterating over, hence the "mutable"
};
#endif //__FCOSETIMPL_H