From f666409d8f8e0ca8280b2bacdd687227bc201b17 Mon Sep 17 00:00:00 2001 From: Brian Cox Date: Sat, 2 Apr 2016 10:38:21 -0700 Subject: [PATCH] String handling tweaks (string <--> dbchar) so AROS build works properly. --- src/core/stringutil.cpp | 14 ++- src/db/hierdbnode.h | 7 +- src/fco/fconame.cpp | 86 +++------------ src/fco/fconame.h~ | 231 ---------------------------------------- src/fco/fcosetimpl.h~ | 128 ---------------------- 5 files changed, 34 insertions(+), 432 deletions(-) delete mode 100644 src/fco/fconame.h~ delete mode 100644 src/fco/fcosetimpl.h~ diff --git a/src/core/stringutil.cpp b/src/core/stringutil.cpp index 5d8a0c5..8c10b3e 100644 --- a/src/core/stringutil.cpp +++ b/src/core/stringutil.cpp @@ -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; xClearList(); - 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 diff --git a/src/fco/fconame.h~ b/src/fco/fconame.h~ deleted file mode 100644 index 3e07ad0..0000000 --- a/src/fco/fconame.h~ +++ /dev/null @@ -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 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 - diff --git a/src/fco/fcosetimpl.h~ b/src/fco/fcosetimpl.h~ deleted file mode 100644 index 90d7c19..0000000 --- a/src/fco/fcosetimpl.h~ +++ /dev/null @@ -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 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::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 -