diff options
Diffstat (limited to 'rsc/source/tools')
-rw-r--r-- | rsc/source/tools/makefile.mk | 86 | ||||
-rw-r--r-- | rsc/source/tools/rscchar.cxx | 411 | ||||
-rw-r--r-- | rsc/source/tools/rscdef.cxx | 1456 | ||||
-rw-r--r-- | rsc/source/tools/rschash.cxx | 440 | ||||
-rw-r--r-- | rsc/source/tools/rsctools.cxx | 656 | ||||
-rw-r--r-- | rsc/source/tools/rsctree.cxx | 604 |
6 files changed, 3653 insertions, 0 deletions
diff --git a/rsc/source/tools/makefile.mk b/rsc/source/tools/makefile.mk new file mode 100644 index 000000000000..3ac670ed2827 --- /dev/null +++ b/rsc/source/tools/makefile.mk @@ -0,0 +1,86 @@ +#************************************************************************* +# +# $RCSfile: makefile.mk,v $ +# +# $Revision: 1.1.1.1 $ +# +# last change: $Author: hr $ $Date: 2000-09-18 16:42:56 $ +# +# The Contents of this file are made available subject to the terms of +# either of the following licenses +# +# - GNU Lesser General Public License Version 2.1 +# - Sun Industry Standards Source License Version 1.1 +# +# Sun Microsystems Inc., October, 2000 +# +# GNU Lesser General Public License Version 2.1 +# ============================================= +# Copyright 2000 by Sun Microsystems, Inc. +# 901 San Antonio Road, Palo Alto, CA 94303, USA +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License version 2.1, as published by the Free Software Foundation. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, +# MA 02111-1307 USA +# +# +# Sun Industry Standards Source License Version 1.1 +# ================================================= +# The contents of this file are subject to the Sun Industry Standards +# Source License Version 1.1 (the "License"); You may not use this file +# except in compliance with the License. You may obtain a copy of the +# License at http://www.openoffice.org/license.html. +# +# Software provided under this License is provided on an "AS IS" basis, +# WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, +# WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, +# MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. +# See the License for the specific provisions governing your rights and +# obligations concerning the Software. +# +# The Initial Developer of the Original Code is: Sun Microsystems, Inc. +# +# Copyright: 2000 by Sun Microsystems, Inc. +# +# All Rights Reserved. +# +# Contributor(s): _______________________________________ +# +# +# +#************************************************************************* + +PRJ=..$/.. + +PRJNAME=rsc +TARGET=rsctoo + +# --- Settings ------------------------------------------------------ + +.INCLUDE : svpre.mk +.INCLUDE : settings.mk +.INCLUDE : sv.mk + +OBJFILES= $(OBJ)$/rschash.obj \ + $(OBJ)$/rsctree.obj \ + $(OBJ)$/rsctools.obj \ + $(OBJ)$/rscchar.obj \ + $(OBJ)$/rscdef.obj + +CXXFILES= rschash.cxx \ + rsctree.cxx \ + rsctools.cxx \ + rscchar.cxx \ + rscdef.cxx + +.INCLUDE : target.mk diff --git a/rsc/source/tools/rscchar.cxx b/rsc/source/tools/rscchar.cxx new file mode 100644 index 000000000000..2ab9badbcd74 --- /dev/null +++ b/rsc/source/tools/rscchar.cxx @@ -0,0 +1,411 @@ +/************************************************************************* + * + * $RCSfile: rscchar.cxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 16:42:56 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ +/************************************************************************ + + Source Code Control System - Header + + $Header: /zpool/svn/migration/cvs_rep_09_09_08/code/rsc/source/tools/rscchar.cxx,v 1.1.1.1 2000-09-18 16:42:56 hr Exp $ + + Source Code Control System - Update + + $Log: not supported by cvs2svn $ + Revision 1.14 2000/09/17 12:51:12 willem.vandorp + OpenOffice header added. + + Revision 1.13 2000/07/26 17:13:23 willem.vandorp + Headers/footers replaced + + Revision 1.12 1999/09/20 16:12:22 mm + \X is possible in the character converter + + Revision 1.11 1999/09/09 13:10:53 mm + UTF8 corrected + + Revision 1.10 1999/09/07 13:30:06 mm + UniCode + + Revision 1.9 1998/01/08 13:20:56 MM + includes angepasst + + + Rev 1.8 08 Jan 1998 13:20:56 MM + includes angepasst + + Rev 1.7 07 Aug 1997 15:47:20 TJ + include + + Rev 1.6 21 Nov 1995 19:50:52 TLX + Neuer Link + + Rev 1.5 25 Aug 1993 15:31:38 mm + Zeichensaetze aus den tools + + Rev 1.4 06 Aug 1993 13:14:56 TH + Equal-Tablle zwischen 200-209 jetzt richtig + + Rev 1.3 19 Jul 1993 19:21:42 mm + \ verbessert + + Rev 1.2 19 Jul 1993 16:29:46 mm + + Rev 1.1 20 Aug 1992 18:18:20 mm + +**************************************************************************/ +/****************** I N C L U D E S **************************************/ +#include <stdio.h> +#include <string.h> +#include <ctype.h> + +#ifndef _TABLE_HXX //autogen +#include <tools/table.hxx> +#endif + +// Solar Definitionen +#include <tools/solar.h> +#ifndef _RSCTOOLS_HXX +#include <rsctools.hxx> +#endif + +#include <rtl/textcvt.h> +#include <rtl/textenc.h> + +/************************************************************************* +|* +|* RscChar::MakeChar() +|* +|* Beschreibung Der String wird nach C-Konvention umgesetzt +|* Ersterstellung MM 20.03.91 +|* Letzte Aenderung MM 20.03.91 +|* +*************************************************************************/ +char * RscChar::MakeUTF8( char * pStr, UINT16 nTextEncoding ) +{ + sal_Size nMaxUniCodeBuf = strlen( pStr ) + 1; + char * pOrgStr = new char[ nMaxUniCodeBuf ]; + USHORT nOrgLen = 0; + + if( nMaxUniCodeBuf * 6 > 0xFFFF ) + RscExit( 10 ); + + char cOld = '1'; + while( cOld != 0 ) + { + char c; + + if( *pStr == '\\' ) + { + ++pStr; + switch( *pStr ) + { + case 'a': + c = '\a'; + break; + case 'b': + c = '\b'; + break; + case 'f': + c = '\f'; + break; + case 'n': + c = '\n'; + break; + case 'r': + c = '\r'; + break; + case 't': + c = '\t'; + break; + case 'v': + c = '\v'; + break; + case '\\': + c = '\\'; + break; + case '?': + c = '\?'; + break; + case '\'': + c = '\''; + break; + case '\"': + c = '\"'; + break; + default: + { + if( '0' <= *pStr && '7' >= *pStr ) + { + USHORT nChar = 0; + USHORT i = 0; + while( '0' <= *pStr && '7' >= *pStr && i != 3 ) + { + nChar = nChar * 8 + (BYTE)*pStr - (BYTE)'0'; + ++pStr; + i++; + } + if( nChar > 255 ) + { + RscMem::Free( pOrgStr ); + + // Wert zu gross, oder kein 3 Ziffern + return( NULL ); + } + c = (char)nChar; + pStr--; + } + else if( 'x' == *pStr ) + { + USHORT nChar = 0; + USHORT i = 0; + ++pStr; + while( isxdigit( *pStr ) && i != 2 ) + { + if( isdigit( *pStr ) ) + nChar = nChar * 16 + (BYTE)*pStr - (BYTE)'0'; + else if( isupper( *pStr ) ) + nChar = nChar * 16 + (BYTE)*pStr - (BYTE)'A' +10; + else + nChar = nChar * 16 + (BYTE)*pStr - (BYTE)'a' +10; + ++pStr; + i++; + } + c = (char)nChar; + pStr--; + } + else + c = *pStr; + }; + } + } + else + c = *pStr; + pOrgStr[ nOrgLen++ ] = c; + cOld = *pStr; + pStr++; + } + + sal_Unicode * pUniCode = new sal_Unicode[ nMaxUniCodeBuf ]; + rtl_TextToUnicodeConverter hConv = rtl_createTextToUnicodeConverter( nTextEncoding ); + + sal_uInt32 nInfo; + sal_Size nSrcCvtBytes; + sal_Size nUniSize = rtl_convertTextToUnicode( hConv, 0, + pOrgStr, nOrgLen, + pUniCode, nMaxUniCodeBuf, + RTL_TEXTTOUNICODE_FLAGS_UNDEFINED_DEFAULT + | RTL_TEXTTOUNICODE_FLAGS_MBUNDEFINED_DEFAULT + | RTL_TEXTTOUNICODE_FLAGS_INVALID_DEFAULT + | RTL_TEXTTOUNICODE_FLAGS_FLUSH, + &nInfo, + &nSrcCvtBytes ); + + rtl_destroyTextToUnicodeConverter( hConv ); + + hConv = rtl_createUnicodeToTextConverter( RTL_TEXTENCODING_UTF8 ); + // factor fo 6 is the maximum size of an UNICODE character as utf8 + char * pUtf8 = (char *)RscMem::Malloc( (USHORT)(nMaxUniCodeBuf * 6) ); + UINT16 nUtf8Len = 0; + + rtl_convertUnicodeToText( hConv, 0, + pUniCode, nUniSize, + pUtf8, nMaxUniCodeBuf * 6, + RTL_UNICODETOTEXT_FLAGS_UNDEFINED_DEFAULT + | RTL_UNICODETOTEXT_FLAGS_INVALID_DEFAULT + | RTL_UNICODETOTEXT_FLAGS_FLUSH, + &nInfo, + &nSrcCvtBytes ); + + rtl_destroyTextToUnicodeConverter( hConv ); + + delete pUniCode; + delete pOrgStr; + return pUtf8; +}; + +/************************************************************************* +|* +|* RscChar::MakeChar() +|* +|* Beschreibung Der String wird nach C-Konvention umgesetzt +|* Ersterstellung MM 20.03.91 +|* Letzte Aenderung MM 20.03.91 +|* +*************************************************************************/ +char * RscChar::MakeUTF8FromL( char * pStr ) +{ + sal_Size nUniPos = 0; + sal_Unicode * pUniCode = new sal_Unicode[ strlen( pStr ) + 1 ]; + + char cOld = '1'; + while( cOld != 0 ) + { + sal_Unicode c; + if( *pStr == '\\' ) + { + ++pStr; + switch( *pStr ) + { + case 'a': + c = '\a'; + break; + case 'b': + c = '\b'; + break; + case 'f': + c = '\f'; + break; + case 'n': + c = '\n'; + break; + case 'r': + c = '\r'; + break; + case 't': + c = '\t'; + break; + case 'v': + c = '\v'; + break; + case '\\': + c = '\\'; + break; + case '?': + c = '\?'; + break; + case '\'': + c = '\''; + break; + case '\"': + c = '\"'; + break; + default: + { + if( '0' <= *pStr && '7' >= *pStr ) + { + UINT32 nChar = 0; + USHORT i = 0; + while( '0' <= *pStr && '7' >= *pStr && i != 6 ) + { + nChar = nChar * 8 + (BYTE)*pStr - (BYTE)'0'; + ++pStr; + i++; + } + if( nChar > 0xFFFF ) + // Wert zu gross, oder kein 3 Ziffern + return( FALSE ); + c = (UINT16)nChar; + pStr--; + } + else if( 'x' == *pStr || 'X' == *pStr ) + { + UINT32 nChar = 0; + USHORT i = 0; + ++pStr; + while( isxdigit( *pStr ) && i != 4 ) + { + if( isdigit( *pStr ) ) + nChar = nChar * 16 + (BYTE)*pStr - (BYTE)'0'; + else if( isupper( *pStr ) ) + nChar = nChar * 16 + (BYTE)*pStr - (BYTE)'A' +10; + else + nChar = nChar * 16 + (BYTE)*pStr - (BYTE)'a' +10; + ++pStr; + i++; + } + c = (UINT16)nChar; + pStr--; + } + else + c = *pStr; + }; + } + } + else + c = *pStr; + + pUniCode[ nUniPos++ ] = c; + cOld = *pStr; + pStr++; + } + + // factor fo 6 is the maximum size of an UNICODE character as utf8 + sal_Size nMaxUtf8Len = nUniPos * 6; + if( nUniPos * 6 > 0xFFFF ) + RscExit( 10 ); + char * pUtf8 = (char *)RscMem::Malloc( (USHORT)nMaxUtf8Len ); + rtl_TextToUnicodeConverter hConv = rtl_createUnicodeToTextConverter( RTL_TEXTENCODING_UTF8 ); + + sal_uInt32 nInfo; + sal_Size nSrcCvtBytes; + sal_Size nSize = rtl_convertUnicodeToText( hConv, 0, + pUniCode, nUniPos, + pUtf8, nMaxUtf8Len, + RTL_UNICODETOTEXT_FLAGS_UNDEFINED_DEFAULT + | RTL_UNICODETOTEXT_FLAGS_INVALID_DEFAULT + | RTL_UNICODETOTEXT_FLAGS_FLUSH, + &nInfo, + &nSrcCvtBytes ); + + rtl_destroyUnicodeToTextConverter( hConv ); + + delete pUniCode; + return pUtf8; +}; + diff --git a/rsc/source/tools/rscdef.cxx b/rsc/source/tools/rscdef.cxx new file mode 100644 index 000000000000..13b82098a823 --- /dev/null +++ b/rsc/source/tools/rscdef.cxx @@ -0,0 +1,1456 @@ +/************************************************************************* + * + * $RCSfile: rscdef.cxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 16:42:56 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ +/************************************************************************ + + Source Code Control System - Header + + $Header: /zpool/svn/migration/cvs_rep_09_09_08/code/rsc/source/tools/rscdef.cxx,v 1.1.1.1 2000-09-18 16:42:56 hr Exp $ + + Source Code Control System - Update + + $Log: not supported by cvs2svn $ + Revision 1.13 2000/09/17 12:51:12 willem.vandorp + OpenOffice header added. + + Revision 1.12 2000/07/26 17:13:24 willem.vandorp + Headers/footers replaced + + Revision 1.11 2000/07/11 17:17:36 th + Unicode + + Revision 1.10 1997/08/27 18:17:52 MM + neue Headerstruktur + +**************************************************************************/ +/****************** I N C L U D E S **************************************/ + +// Programmuebergreifende Includes. +#ifndef _RSCDEF_HXX +#include <rscdef.hxx> +#endif + +/****************** C o d e **********************************************/ +/****************** R s c I d ********************************************/ +BOOL RscId::bNames = TRUE; + +/************************************************************************* +|* +|* static RscId::SetNames +|* static RscId::SetNoNames +|* +|* Beschreibung +|* Ersterstellung MM 26.06.91 +|* Letzte Aenderung MM 26.06.91 +|* +*************************************************************************/ +void RscId::SetNames( BOOL bSet ) { bNames = bSet; } +BOOL RscId::IsSetNames() { return bNames; } + +/************************************************************************* +|* +|* RscId::GetNumber +|* +|* Beschreibung +|* Ersterstellung MM 17.05.91 +|* Letzte Aenderung MM 17.05.91 +|* +*************************************************************************/ +long RscId::GetNumber() const{ + long lVal; + aExp.Evaluate( &lVal ); + return lVal; +} + +/************************************************************************* +|* +|* RscId::Create() +|* +|* Beschreibung +|* Ersterstellung MM 01.11.91 +|* Letzte Aenderung MM 01.11.91 +|* +*************************************************************************/ +void RscId::Create( const RscExpType & rExpType ) +{ + aExp = rExpType; + if( aExp.IsDefinition() ) + aExp.aExp.pDef->IncRef(); + else if( aExp.IsExpression() ){ + long lValue; + + aExp.Evaluate( &lValue ); + aExp.SetLong( lValue ); + } +} + +/************************************************************************* +|* +|* RscId::Destroy() +|* +|* Beschreibung +|* Ersterstellung MM 01.11.91 +|* Letzte Aenderung MM 01.11.91 +|* +*************************************************************************/ +void RscId::Destroy(){ + if( aExp.IsDefinition() ) + aExp.aExp.pDef->DecRef(); + aExp.cType = RSCEXP_NOTHING; +} + +/************************************************************************* +|* +|* RscId::RscId() +|* +|* Beschreibung +|* Ersterstellung MM 01.11.91 +|* Letzte Aenderung MM 01.11.91 +|* +*************************************************************************/ +RscId::RscId( const RscId& rRscId ){ + aExp = rRscId.aExp; + if( aExp.IsDefinition() ) + aExp.aExp.pDef->IncRef(); +} + +/************************************************************************* +|* +|* RscId::RscId() +|* +|* Beschreibung +|* Ersterstellung MM 01.11.91 +|* Letzte Aenderung MM 25.11.91 +|* +*************************************************************************/ +RscId::RscId( RscDefine * pDef ){ + RscExpType aExpType; + + aExpType.aExp.pDef = pDef; + aExpType.cType = RSCEXP_DEF; + Create( aExpType ); +} + +/************************************************************************* +|* +|* RscId:: = +|* +|* Beschreibung +|* Ersterstellung MM 01.11.91 +|* Letzte Aenderung MM 01.11.91 +|* +*************************************************************************/ +RscId& RscId::operator = ( const RscId& rRscId ){ + if( rRscId.aExp.IsDefinition() ) + rRscId.aExp.aExp.pDef->IncRef(); + Destroy(); + aExp = rRscId.aExp; + return *this; +} + +/************************************************************************* +|* +|* RscId::operator == +|* +|* Beschreibung +|* Ersterstellung MM 16.05.91 +|* Letzte Aenderung MM 16.05.91 +|* +*************************************************************************/ +BOOL RscId::operator == ( const RscId& rRscId ) const +{ + return( GetNumber() == rRscId.GetNumber() ); +} + +/************************************************************************* +|* +|* RscId::operator < +|* +|* Beschreibung +|* Ersterstellung MM 16.05.91 +|* Letzte Aenderung MM 16.05.91 +|* +*************************************************************************/ +BOOL RscId::operator < ( const RscId& rRscId ) const +{ + return( GetNumber() < rRscId.GetNumber() ); +} + +/************************************************************************* +|* +|* RscId::operator > +|* +|* Beschreibung +|* Ersterstellung MM 16.05.91 +|* Letzte Aenderung MM 16.05.91 +|* +*************************************************************************/ +BOOL RscId::operator > ( const RscId& rRscId ) const +{ + return( GetNumber() > rRscId.GetNumber() ); +} + +/************************************************************************* +|* +|* RscId::long() +|* +|* Beschreibung +|* Ersterstellung MM 16.05.91 +|* Letzte Aenderung MM 16.05.91 +|* +*************************************************************************/ +RscId::operator long() const +{ + return( GetNumber() ); +} + +/************************************************************************* +|* +|* RscId::GetNames() +|* +|* Beschreibung +|* Ersterstellung MM 16.05.91 +|* Letzte Aenderung MM 25.11.91 +|* +*************************************************************************/ +ByteString RscId::GetName() const +{ + ByteString aStr; + + if ( !aExp.IsNothing() ) + { + if( bNames ) + aExp.GetMacro( aStr ); + else + aStr = ByteString::CreateFromInt32( GetNumber() ); + } + + return aStr; +} + +/************************************************************************* +|* +|* RscId::GetMacro() +|* +|* Beschreibung +|* Ersterstellung MM 01.11.91 +|* Letzte Aenderung MM 25.11.91 +|* +*************************************************************************/ +ByteString RscId::GetMacro() const +{ + ByteString aStr; + + if ( aExp.IsDefinition() ) + aStr = aExp.aExp.pDef->GetMacro(); + else + aExp.GetMacro( aStr ); + + return aStr; +} + +/****************** R s c D e f i n e ************************************/ +/************************************************************************* +|* +|* RscDefine::RscDefine() +|* +|* Beschreibung +|* Ersterstellung MM 01.11.91 +|* Letzte Aenderung MM 01.11.91 +|* +*************************************************************************/ +RscDefine::RscDefine( ULONG lKey, const ByteString & rDefName, long lDefId ) + : StringNode( rDefName ) +{ + nRefCount = 0; + lFileKey = lKey; + lId = lDefId; + pExp = NULL; +} + +RscDefine::RscDefine( ULONG lKey, const ByteString & rDefName, + RscExpression * pExpression ) + : StringNode( rDefName ) +{ + nRefCount = 0; + lFileKey = lKey; + pExpression->Evaluate( &lId ); + pExp = pExpression; +} + +/************************************************************************* +|* +|* RscDefine::~RscDefine() +|* +|* Beschreibung +|* Ersterstellung MM 01.11.91 +|* Letzte Aenderung MM 01.11.91 +|* +*************************************************************************/ +RscDefine::~RscDefine(){ + if( pExp ) + delete pExp; + if( nRefCount ) + RscExit( 14 ); +} + +/************************************************************************* +|* +|* RscDefine::DecRef() +|* +|* Beschreibung +|* Ersterstellung MM 01.11.91 +|* Letzte Aenderung MM 01.11.91 +|* +*************************************************************************/ +void RscDefine::DecRef(){ + nRefCount--; + if( 0 == nRefCount ){ + delete this; + } +} + +/************************************************************************* +|* +|* RscDefine::DefineToNumber() +|* +|* Beschreibung +|* Ersterstellung MM 07.11.91 +|* Letzte Aenderung MM 07.11.91 +|* +*************************************************************************/ +void RscDefine::DefineToNumber() +{ + if( pExp ) + delete pExp; + pExp = NULL; + SetName( ByteString::CreateFromInt32( lId ) ); +} + +/************************************************************************* +|* +|* RscDefine::ChangeMacro() +|* +|* Beschreibung +|* Ersterstellung MM 04.11.91 +|* Letzte Aenderung MM 04.11.91 +|* +*************************************************************************/ +void RscDefine::ChangeMacro( RscExpression * pExpression ){ + if( pExp ) + delete pExp; + pExp = pExpression; + pExp->Evaluate( &lId ); +} + +void RscDefine::ChangeMacro( long lIdentifier ){ + if( pExp ){ + delete pExp; + pExp = NULL; + } + lId = lIdentifier; +} + +/************************************************************************* +|* +|* RscDefine::Evaluate() +|* +|* Beschreibung +|* Ersterstellung MM 01.11.91 +|* Letzte Aenderung MM 01.11.91 +|* +*************************************************************************/ +BOOL RscDefine::Evaluate(){ + BOOL bRet = TRUE; + + if( pExp ) + bRet = !pExp->Evaluate( &lId ); + + return bRet; +} + +/************************************************************************* +|* +|* RscDefine::Search() +|* +|* Beschreibung +|* Ersterstellung MM 11.11.91 +|* Letzte Aenderung MM 11.11.91 +|* +*************************************************************************/ +RscDefine * RscDefine::Search( const char * pStr ){ + return (RscDefine *)StringNode::Search( pStr ); +} + +/************************************************************************* +|* +|* RscDefine::GetMacro() +|* +|* Beschreibung +|* Ersterstellung MM 01.11.91 +|* Letzte Aenderung MM 01.11.91 +|* +*************************************************************************/ +ByteString RscDefine::GetMacro() +{ + if( pExp ) + return pExp->GetMacro(); + return ByteString::CreateFromInt32( lId ); +} + +/****************** R s c D e f i n e L i s t ****************************/ +/************************************************************************* +|* +|* RscDefineList::New() +|* +|* Beschreibung +|* Ersterstellung MM 04.11.91 +|* Letzte Aenderung MM 04.11.91 +|* +*************************************************************************/ +RscDefine * RscDefineList::New( ULONG lFileKey, const ByteString & rDefName, + long lDefId, ULONG lPos ) +{ + RscDefine * pDef; + + pDef = new RscDefine( lFileKey, rDefName, lDefId ); + pDef->IncRef(); + Insert( pDef, lPos ); + return pDef; +} + +RscDefine * RscDefineList::New( ULONG lFileKey, const ByteString & rDefName, + RscExpression * pExpression, ULONG lPos ) +{ + RscDefine * pDef; + + pDef = new RscDefine( lFileKey, rDefName, pExpression ); + pDef->IncRef(); + Insert( pDef, lPos ); + + return pDef; +} + +/************************************************************************* +|* +|* RscDefineList::Remove() +|* +|* Beschreibung +|* Ersterstellung MM 04.11.91 +|* Letzte Aenderung MM 04.11.91 +|* +*************************************************************************/ +BOOL RscDefineList::Remove( RscDefine * pDef ){ + pDef = RscSubDefList::Remove( pDef ); + if( pDef ){ + pDef->DefineToNumber(); + pDef->DecRef(); + } + + return( NULL != pDef ); +} + +BOOL RscDefineList::Remove( ULONG lIndex ){ + RscDefine * pDef = RscSubDefList::Remove( lIndex ); + if( pDef ){ + pDef->DefineToNumber(); + pDef->DecRef(); + } + + return( NULL != pDef ); +} + +BOOL RscDefineList::Remove(){ + RscDefine * pDef; + + pDef = RscSubDefList::Remove( (ULONG)0 ); + + if( pDef ){ + pDef->DefineToNumber(); + pDef->DecRef(); + } + return( NULL != pDef ); +} + +/************************************************************************* +|* +|* RscDefineList::Befor() +|* +|* Beschreibung +|* Ersterstellung MM 12.11.91 +|* Letzte Aenderung MM 12.11.91 +|* +*************************************************************************/ +BOOL RscDefineList::Befor( const RscDefine * pFree, + const RscDefine * pDepend ) +{ + RscDefine * pDef; + + pDef = First(); + while( pDef ){ + if( pDef == pFree ){ + pDef = Next(); + while( pDef ){ + if( pDef == pDepend ) + return TRUE; + pDef = Next(); + } + } + pDef = Next(); + }; + return FALSE; +} + +/************************************************************************* +|* +|* RscDefineList::WriteAll() +|* +|* Beschreibung +|* Ersterstellung MM 28.10.91 +|* Letzte Aenderung MM 28.10.91 +|* +*************************************************************************/ +void RscDefineList::WriteAll( FILE * fOutput ) +{ + RscDefine * pDefEle = First(); + + while( pDefEle ) + { + fprintf( fOutput, "#define %s %s\n", + pDefEle->GetName().GetBuffer(), + pDefEle->GetMacro().GetBuffer() ); + pDefEle = Next(); + }; +} + +/****************** R s c E x p T y p e **********************************/ +/************************************************************************* +|* +|* RscExpType::Evaluate() +|* +|* Beschreibung +|* Ersterstellung MM 01.11.91 +|* Letzte Aenderung MM 01.11.91 +|* +*************************************************************************/ +BOOL RscExpType::Evaluate( long * plValue ) const{ + if( IsDefinition() ){ + aExp.pDef->Evaluate(); + // Eventuellen Fehler ignorieren + *plValue = aExp.pDef->GetNumber(); + } + else if( IsExpression() ) + return( aExp.pExp->Evaluate( plValue ) ); + else if( IsNothing() ) + *plValue = 0; + else + *plValue = GetLong(); + + return TRUE; +} + +/************************************************************************* +|* +|* RscExpType::GetMacro() +|* +|* Beschreibung +|* Ersterstellung MM 01.11.91 +|* Letzte Aenderung MM 01.11.91 +|* +*************************************************************************/ +void RscExpType::GetMacro( ByteString & rStr ) const +{ + ByteString aStr; + + if( IsDefinition() ) + { + rStr += aExp.pDef->GetName(); + } + else if( IsExpression() ) + rStr += aExp.pExp->GetMacro(); + else if( IsNumber() ) + rStr += ByteString::CreateFromInt32( GetLong() ); +} + + +/****************** R s c E x p r e s s i o n ****************************/ +/************************************************************************* +|* +|* RscExpression::RscExpression() +|* +|* Beschreibung +|* Ersterstellung MM 01.11.91 +|* Letzte Aenderung MM 01.11.91 +|* +*************************************************************************/ +RscExpression::RscExpression( RscExpType aLE, char cOp, RscExpType aRE ) +{ + aLeftExp = aLE; + cOperation = cOp; + aRightExp = aRE; + if( aLeftExp.IsDefinition() ) + aLeftExp.aExp.pDef->IncRef(); + if( aRightExp.IsDefinition() ) + aRightExp.aExp.pDef->IncRef(); +} + +/************************************************************************* +|* +|* RscExpression::~RscExpression() +|* +|* Beschreibung +|* Ersterstellung MM 01.11.91 +|* Letzte Aenderung MM 01.11.91 +|* +*************************************************************************/ +RscExpression::~RscExpression(){ + if( aLeftExp.IsDefinition() ) + aLeftExp.aExp.pDef->DecRef(); + else if( aLeftExp.IsExpression() ) + delete aLeftExp.aExp.pExp; + + if( aRightExp.IsDefinition() ) + aRightExp.aExp.pDef->DecRef(); + else if( aRightExp.IsExpression() ) + delete aRightExp.aExp.pExp; +} + +/************************************************************************* +|* +|* RscExpression::Evaluate() +|* +|* Beschreibung +|* Ersterstellung MM 01.11.91 +|* Letzte Aenderung MM 01.11.91 +|* +*************************************************************************/ +BOOL RscExpression::Evaluate( long * plValue ){ + long lLeft; + long lRight; + + // linken und rechten Zweig auswerten + if( aLeftExp.Evaluate( &lLeft ) && aRightExp.Evaluate( &lRight ) ){ + if( cOperation == '&' ) + *plValue = lLeft & lRight; + else if( cOperation == '|' ) + *plValue = lLeft | lRight; + else if( cOperation == '+' ) + *plValue = lLeft + lRight; + else if( cOperation == '-' ) + *plValue = lLeft - lRight; + else if( cOperation == '*' ) + *plValue = lLeft * lRight; + else if( cOperation == 'r' ) + *plValue = lLeft >> lRight; + else if( cOperation == 'l' ) + *plValue = lLeft << lRight; + else{ + if( 0L == lRight ) + return FALSE; + *plValue = lLeft / lRight; + }; + return TRUE; + } + return FALSE; +} + +/************************************************************************* +|* +|* RscExpression::GetMacro() +|* +|* Beschreibung +|* Ersterstellung MM 01.11.91 +|* Letzte Aenderung MM 01.11.91 +|* +*************************************************************************/ +ByteString RscExpression::GetMacro() +{ + ByteString aLeft; + + // Ausgabeoptimierung + if( aLeftExp.IsNothing() ) + { + if ( '-' == cOperation ) + { + aLeft += '('; + aLeft += '-'; + } + aRightExp.GetMacro( aLeft ); + if( '-' == cOperation ) + aLeft += ')'; + } + else if( aRightExp.IsNothing() ) + aLeftExp.GetMacro( aLeft ); + else{ + aLeft += '('; + // linken Zweig auswerten + aLeftExp.GetMacro( aLeft ); + + aLeft += cOperation; + + aLeft += '('; + // rechten Zweig auswerten + aRightExp.GetMacro( aLeft ); + aLeft += ')'; + + aLeft += ')'; + } + + return aLeft; +} + +/****************** R s c F i l e ****************************************/ +/************************************************************************* +|* +|* RscFile::RscFile() +|* +|* Beschreibung +|* Ersterstellung MM 04.11.91 +|* Letzte Aenderung MM 04.11.91 +|* +*************************************************************************/ +RscFile :: RscFile(){ + bLoaded = FALSE; + bIncFile = FALSE; + bDirty = FALSE; + bScanned = FALSE; +} + +/************************************************************************* +|* +|* RscFile::~RscFile() +|* +|* Beschreibung +|* Ersterstellung MM 04.11.91 +|* Letzte Aenderung MM 04.11.91 +|* +*************************************************************************/ +RscFile :: ~RscFile(){ + RscDepend * pDep = Remove( (ULONG)0 ); + + while( pDep ){ + delete pDep; + pDep = Remove( (ULONG)0 ); + } + + //von hinten nach vorne ist besser wegen der Abhaengigkeiten + //Objekte zerstoeren sich, wenn Referenzzaehler NULL + aDefLst.Last(); + while( aDefLst.Remove() ); +} + +/************************************************************************* +|* +|* RscFile::Depend() +|* +|* Beschreibung Diese Methode gibt TRUE zurueck, wenn lDepend +|* existiert und hinter lFree steht, oder wenn +|* lDepend nicht existiert. +|* Ersterstellung MM 12.11.91 +|* Letzte Aenderung MM 12.11.91 +|* +*************************************************************************/ +BOOL RscFile::Depend( ULONG lDepend, ULONG lFree ){ + RscDepend * pDep; + + pDep = Last(); + while( pDep ){ + if( pDep->GetFileKey() == lDepend ){ + while( pDep ){ + if( pDep->GetFileKey() == lFree ) + return TRUE; + pDep = Prev(); + } + return FALSE; + } + pDep = Prev(); + }; + + return TRUE; +} + +/************************************************************************* +|* +|* RscFile::InsertDependFile() +|* +|* Beschreibung +|* Ersterstellung MM 06.01.92 +|* Letzte Aenderung MM 06.01.92 +|* +*************************************************************************/ +BOOL RscFile :: InsertDependFile( ULONG lIncFile, ULONG lPos ) +{ + RscDepend * pDep; + + pDep = First(); + while( pDep ){ + if( pDep->GetFileKey() == lIncFile ) + return TRUE; + pDep = Next(); + } + + // Current-Zeiger steht auf letztem Element + if( lPos >= Count() ){ //letztes Element muss immer letztes bleiben + // Abhaengigkeit vor der letzten Position eintragen + Insert( new RscDepend( lIncFile ) ); + } + else + Insert( new RscDepend( lIncFile ), lPos ); + + return TRUE; +} + +/************************************************************************* +|* +|* RscFile::RemoveDependFile() +|* +|* Beschreibung +|* Ersterstellung MM 18.11.91 +|* Letzte Aenderung MM 18.11.91 +|* +*************************************************************************/ +void RscFile :: RemoveDependFile( ULONG lDepFile ) +{ + + RscDepend * pDep = Last(); + + while( pDep ){ + if( pDep->GetFileKey() == lDepFile ){ + Remove( pDep ); + delete pDep; + } + pDep = Prev(); + } +} + +/****************** R s c D e f T r e e **********************************/ +/************************************************************************* +|* +|* RscDefTree::~RscDefTree() +|* +|* Beschreibung +|* Ersterstellung MM 12.11.91 +|* Letzte Aenderung MM 12.11.91 +|* +*************************************************************************/ +RscDefTree::~RscDefTree(){ + Remove(); +} + +/************************************************************************* +|* +|* RscDefTree::Remove() +|* +|* Beschreibung +|* Ersterstellung MM 12.11.91 +|* Letzte Aenderung MM 12.11.91 +|* +*************************************************************************/ +void RscDefTree::Remove(){ + RscDefine * pDef; + while( pDefRoot ){ + pDef = pDefRoot; + pDefRoot = (RscDefine *)pDefRoot->Remove( pDefRoot ); + pDef->DecRef(); + } +} + +/************************************************************************* +|* +|* RscDefTree::~Search() +|* +|* Beschreibung +|* Ersterstellung MM 12.11.91 +|* Letzte Aenderung MM 12.11.91 +|* +*************************************************************************/ +RscDefine * RscDefTree::Search( const char * pName ){ + if( pDefRoot ) + return pDefRoot->Search( pName ); + return NULL; +} + +/************************************************************************* +|* +|* RscDefTree::Insert() +|* +|* Beschreibung +|* Ersterstellung MM 12.11.91 +|* Letzte Aenderung MM 12.11.91 +|* +*************************************************************************/ +void RscDefTree::Insert( RscDefine * pDef ){ + if( pDefRoot ) + pDefRoot->Insert( pDef ); + else + pDefRoot = pDef; + pDef->IncRef(); +} + +/************************************************************************* +|* +|* RscDefTree::Remove() +|* +|* Beschreibung +|* Ersterstellung MM 12.11.91 +|* Letzte Aenderung MM 12.11.91 +|* +*************************************************************************/ +void RscDefTree::Remove( RscDefine * pDef ){ + if( pDefRoot ){ + //falls pDef == pDefRoot + pDefRoot = (RscDefine *)pDefRoot->Remove( pDef ); + } + pDef->DecRef(); +} + +/************************************************************************* +|* +|* RscDefTree::Evaluate() +|* +|* Beschreibung +|* Ersterstellung MM 12.11.91 +|* Letzte Aenderung MM 12.11.91 +|* +*************************************************************************/ +BOOL RscDefTree::Evaluate( RscDefine * pDef ){ + if( pDef ){ + if( !Evaluate( (RscDefine *)pDef->Left() ) ) + return FALSE; + if( !Evaluate( (RscDefine *)pDef->Right() ) ) + return FALSE; + }; + return TRUE; +} + +BOOL RscDefTree::Evaluate(){ + return Evaluate( pDefRoot ); +} + +/****************** R s c F i l e T a b **********************************/ +/************************************************************************* +|* +|* RscFileTab::RscFileTab() +|* +|* Beschreibung +|* Ersterstellung MM 07.11.91 +|* Letzte Aenderung MM 07.11.91 +|* +*************************************************************************/ +RscFileTab::RscFileTab(){ +} + +/************************************************************************* +|* +|* RscFileTab::~RscFileTab() +|* +|* Beschreibung +|* Ersterstellung MM 04.11.91 +|* Letzte Aenderung MM 04.11.91 +|* +*************************************************************************/ +RscFileTab :: ~RscFileTab(){ + RscFile * pFile; + + aDefTree.Remove(); + + pFile = Last(); + while( pFile ){ + Remove( GetIndex( pFile ) ); + delete pFile; + pFile = Prev(); + }; +} + +/************************************************************************* +|* +|* RscFileTab::Find() +|* +|* Beschreibung +|* Ersterstellung MM 16.05.91 +|* Letzte Aenderung MM 16.05.91 +|* +*************************************************************************/ +ULONG RscFileTab :: Find( const ByteString & rName ) +{ + RscFile * pFName; + + pFName = First(); + while( pFName && (pFName->aFileName != rName) ) + pFName = Next(); + + if( pFName ) + return( GetIndex( pFName ) ); + else + return( NOFILE_INDEX ); +} + +/************************************************************************* +|* +|* RscFileTab::FindDef() +|* +|* Beschreibung +|* Ersterstellung MM 30.10.91 +|* Letzte Aenderung MM 01.11.91 +|* +*************************************************************************/ +RscDefine * RscFileTab::FindDef( const char * pName ){ + return aDefTree.Search( pName ); +} + +/************************************************************************* +|* +|* RscFileTab::FindDef() +|* +|* Beschreibung +|* Ersterstellung MM 30.10.91 +|* Letzte Aenderung MM 01.11.91 +|* +*************************************************************************/ +RscDefine * RscFileTab::FindDef( ULONG lFileKey, const ByteString & rName ) +{ + RscDefine * pDef = FindDef( rName ); + + if( pDef ) + //befindet sich das DEFINE in einer Include-Datei in der + //Datei lFileKey + if( Depend( lFileKey, pDef->GetFileKey() ) ) + return pDef; + return NULL; +} + +/************************************************************************* +|* +|* RscFileTab::Depend() +|* +|* Beschreibung +|* Ersterstellung MM 08.11.91 +|* Letzte Aenderung MM 08.11.91 +|* +*************************************************************************/ +BOOL RscFileTab::Depend( ULONG lDepend, ULONG lFree ){ + if( lDepend == lFree ) + return TRUE; + + RscFile * pFile = First(); + while( pFile ){ + if( !pFile->IsIncFile() ){ + if( !pFile->Depend( lDepend, lFree ) ) + return FALSE; + }; + pFile = Next(); + }; + + return TRUE; +} + +/************************************************************************* +|* +|* RscFileTab::TestDef() +|* +|* Beschreibung +|* Ersterstellung MM 14.01.92 +|* Letzte Aenderung MM 14.01.92 +|* +*************************************************************************/ +BOOL RscFileTab::TestDef( ULONG lFileKey, ULONG lPos, + const RscDefine * pDefDec ) +{ + if( lFileKey == pDefDec->GetFileKey() ){ + RscFile * pFile = GetFile( pDefDec->GetFileKey() ); + if( pFile && (lPos <= pFile->aDefLst.GetPos( (RscDefine *)pDefDec )) + && (lPos != LIST_APPEND) ) + return FALSE; + } + else if( !Depend( lFileKey, pDefDec->GetFileKey() ) ) + return FALSE; + + return TestDef( lFileKey, lPos, pDefDec->pExp ); +} + +/************************************************************************* +|* +|* RscFileTab::TestDef() +|* +|* Beschreibung +|* Ersterstellung MM 14.01.92 +|* Letzte Aenderung MM 14.01.92 +|* +*************************************************************************/ +BOOL RscFileTab::TestDef( ULONG lFileKey, ULONG lPos, + const RscExpression * pExpDec ) +{ + if( !pExpDec ) + return TRUE; + + if( pExpDec->aLeftExp.IsExpression() ) + if( !TestDef( lFileKey, lPos, pExpDec->aLeftExp.aExp.pExp ) ) + return FALSE; + + if( pExpDec->aLeftExp.IsDefinition() ) + if( !TestDef( lFileKey, lPos, pExpDec->aLeftExp.aExp.pDef ) ) + return FALSE; + + if( pExpDec->aRightExp.IsExpression() ) + if( !TestDef( lFileKey, lPos, pExpDec->aRightExp.aExp.pExp ) ) + return FALSE; + + if( pExpDec->aRightExp.IsDefinition() ) + if( !TestDef( lFileKey, lPos, pExpDec->aRightExp.aExp.pDef ) ) + return FALSE; + + return TRUE; +} + +/************************************************************************* +|* +|* RscFileTab::NewDef() +|* +|* Beschreibung +|* Ersterstellung MM 04.11.91 +|* Letzte Aenderung MM 04.11.91 +|* +*************************************************************************/ +RscDefine * RscFileTab::NewDef( ULONG lFileKey, const ByteString & rDefName, + long lId, ULONG lPos ) +{ + RscDefine * pDef = FindDef( rDefName ); + + if( !pDef ){ + RscFile * pFile = GetFile( lFileKey ); + + if( pFile ){ + pDef = pFile->aDefLst.New( lFileKey, rDefName, lId, lPos ); + aDefTree.Insert( pDef ); + } + } + else + pDef = NULL; + + return( pDef ); +} + +/************************************************************************* +|* +|* RscFileTab::NewDef() +|* +|* Beschreibung +|* Ersterstellung MM 04.11.91 +|* Letzte Aenderung MM 04.11.91 +|* +*************************************************************************/ +RscDefine * RscFileTab::NewDef( ULONG lFileKey, const ByteString & rDefName, + RscExpression * pExp, ULONG lPos ) +{ + RscDefine * pDef = FindDef( rDefName ); + + if( !pDef ){ + //Macros in den Expressions sind definiert ? + if( TestDef( lFileKey, lPos, pExp ) ){ + RscFile * pFile = GetFile( lFileKey ); + + if( pFile ){ + pDef = pFile->aDefLst.New( lFileKey, rDefName, pExp, lPos ); + aDefTree.Insert( pDef ); + } + } + } + else + pDef = NULL; + + if( !pDef ){ + // pExp wird immer Eigentum und muss, wenn es nicht benoetigt wird + // geloescht werden + delete pExp; + } + return( pDef ); +} + +/************************************************************************* +|* +|* RscFileTab::IsDefUsed() +|* +|* Beschreibung +|* Ersterstellung MM 22.11.91 +|* Letzte Aenderung MM 22.11.91 +|* +*************************************************************************/ +BOOL RscFileTab::IsDefUsed( const ByteString & rDefName ) +{ + RscDefine * pDef = FindDef( rDefName ); + + if( pDef ) + return( pDef->GetRefCount() != 2 ); + + return FALSE; +} + +/************************************************************************* +|* +|* RscFileTab::DeleteDef() +|* +|* Beschreibung +|* Ersterstellung MM 11.11.91 +|* Letzte Aenderung MM 11.11.91 +|* +*************************************************************************/ +void RscFileTab::DeleteDef( const ByteString & rDefName ) +{ + RscDefine * pDef = FindDef( rDefName ); + RscFile * pFile; + + if( pDef ){ + pFile = GetFile( pDef->GetFileKey() ); + if( pFile ){ + aDefTree.Remove( pDef ); + pFile->aDefLst.Remove( pDef ); + } + }; +} + +/************************************************************************* +|* +|* RscFileTab::ChangeDef() +|* +|* Beschreibung +|* Ersterstellung MM 04.11.91 +|* Letzte Aenderung MM 11.11.91 +|* +*************************************************************************/ +BOOL RscFileTab::ChangeDef( const ByteString & rDefName, long lId ) +{ + RscDefine * pDef = FindDef( rDefName ); + + if( pDef ){ + pDef->ChangeMacro( lId ); + //alle Macros neu bewerten + return aDefTree.Evaluate(); + }; + return( FALSE ); +} + +/************************************************************************* +|* +|* RscFileTab::ChangeDef() +|* +|* Beschreibung +|* Ersterstellung MM 04.11.91 +|* Letzte Aenderung MM 11.11.91 +|* +*************************************************************************/ +BOOL RscFileTab::ChangeDef( const ByteString & rDefName, + RscExpression * pExp ) +{ + RscDefine * pDef = FindDef( rDefName ); + RscFile * pFile; + ULONG lPos; + + if( pDef ){ + pFile = GetFile( pDef->GetFileKey() ); + if( pFile ) + lPos = pFile->aDefLst.GetPos( pDef ); + //Macros in den Expressions sind definiert ? + if( TestDef( pDef->GetFileKey(), lPos, pExp ) ){ + pDef->ChangeMacro( pExp ); + //alle Macros neu bewerten + return aDefTree.Evaluate(); + } + }; + + // pExp wird immer Eigentum und muss, wenn es nicht benoetigt wird + // geloescht werden + delete pExp; + + return( FALSE ); +} + +/************************************************************************* +|* +|* RscFileTab::ChangeDefName() +|* +|* Beschreibung +|* Ersterstellung MM 04.11.91 +|* Letzte Aenderung MM 04.11.91 +|* +*************************************************************************/ +BOOL RscFileTab::ChangeDefName( const ByteString & rDefName, + const ByteString & rNewName ) +{ + RscDefine * pDef = FindDef( rDefName ); + + //Name gefunden ? + if( pDef ){ + // und neuer Name noch nicht bekannt ? + if( !FindDef( pDef->GetFileKey(), rNewName ) ){ + aDefTree.Remove( pDef ); + pDef->SetName( rNewName ); + aDefTree.Insert( pDef ); + return( TRUE ); + } + }; + + return( FALSE ); +} + +/************************************************************************* +|* +|* RscFileTab::DeleteFileContext() +|* +|* Beschreibung +|* Ersterstellung MM 09.12.91 +|* Letzte Aenderung MM 09.12.91 +|* +*************************************************************************/ +void RscFileTab :: DeleteFileContext( ULONG lFileKey ){ + RscFile * pFName; + + pFName = GetFile( lFileKey ); + if( pFName ){ + RscDefine * pDef; + + pDef = pFName->aDefLst.First(); + while( pDef ){ + aDefTree.Remove( pDef ); + pDef = pFName->aDefLst.Next(); + }; + while( pFName->aDefLst.Remove( (ULONG)0 ) ); + } +} + +/************************************************************************* +|* +|* RscFileTab::DeleteFile() +|* +|* Beschreibung +|* Ersterstellung MM 16.05.91 +|* Letzte Aenderung MM 16.05.91 +|* +*************************************************************************/ +void RscFileTab :: DeleteFile( ULONG lFileKey ){ + RscFile * pFName; + + //Defines freigeben + DeleteFileContext( lFileKey ); + + //Schleife ueber alle Abhaengigkeiten + pFName = First(); + while( pFName ){ + pFName->RemoveDependFile( lFileKey ); + pFName = Next(); + }; + + pFName = Remove( lFileKey ); + if( pFName ) + delete pFName; +} + +/************************************************************************* +|* +|* RscFileTab::NewCodeFile() +|* +|* Beschreibung +|* Ersterstellung MM 16.05.91 +|* Letzte Aenderung MM 16.05.91 +|* +*************************************************************************/ +ULONG RscFileTab :: NewCodeFile( const ByteString & rName ) +{ + ULONG lKey; + RscFile * pFName; + + lKey = Find( rName ); + if( UNIQUEINDEX_ENTRY_NOTFOUND == lKey ) + { + pFName = new RscFile(); + pFName->aFileName = rName; + pFName->aPathName = rName; + lKey = Insert( pFName ); + pFName->InsertDependFile( lKey, LIST_APPEND ); + } + return lKey; +} + +/************************************************************************* +|* +|* RscFileTab::NewIncFile() +|* +|* Beschreibung +|* Ersterstellung MM 16.05.91 +|* Letzte Aenderung MM 16.05.91 +|* +*************************************************************************/ +ULONG RscFileTab :: NewIncFile( const ByteString & rName, + const ByteString & rPath ) +{ + ULONG lKey; + RscFile * pFName; + + lKey = Find( rName ); + if( UNIQUEINDEX_ENTRY_NOTFOUND == lKey ) + { + pFName = new RscFile(); + pFName->aFileName = rName; + pFName->aPathName = rPath; + pFName->SetIncFlag(); + lKey = Insert( pFName ); + pFName->InsertDependFile( lKey, LIST_APPEND ); + } + return lKey; +} diff --git a/rsc/source/tools/rschash.cxx b/rsc/source/tools/rschash.cxx new file mode 100644 index 000000000000..c47b078db082 --- /dev/null +++ b/rsc/source/tools/rschash.cxx @@ -0,0 +1,440 @@ +/************************************************************************* + * + * $RCSfile: rschash.cxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 16:42:56 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ +/************************************************************************ + + Source Code Control System - Header + + $Header: /zpool/svn/migration/cvs_rep_09_09_08/code/rsc/source/tools/rschash.cxx,v 1.1.1.1 2000-09-18 16:42:56 hr Exp $ + + Source Code Control System - Update + + $Log: not supported by cvs2svn $ + Revision 1.7 2000/09/17 12:51:12 willem.vandorp + OpenOffice header added. + + Revision 1.6 2000/07/26 17:13:24 willem.vandorp + Headers/footers replaced + + Revision 1.5 1997/08/27 18:17:52 MM + neue Headerstruktur + + + Rev 1.4 27 Aug 1997 18:17:52 MM + neue Headerstruktur + + Rev 1.3 21 Nov 1995 19:50:48 TLX + Neuer Link + + Rev 1.2 25 Aug 1993 15:31:02 mm + Fehler und Warnings beseitigt + + Rev 1.1 03 Jun 1993 15:45:48 mm + Fehler in Test_HashId verbessert + + Rev 1.0 10 Aug 1992 07:18:56 MM + Initial revision. + + Rev 1.6 23 Mar 1992 15:25:54 MM + + Rev 1.5 26 Nov 1991 08:42:22 MM + Methode Test mit char* und void* Argument + + Rev 1.4 11 Sep 1991 12:40:52 MM + + Rev 1.3 31 Jul 1991 15:37:10 MM + + Rev 1.2 24 Jul 1991 10:10:52 MM + Ausgabe auskommentiert + + Rev 1.1 18 Jul 1991 12:55:24 MM + Fehler mit (BOOL) beseitigt + + Rev 1.0 14 Jun 1991 16:20:56 MM + Initial revision. + + Rev 1.2 22 Mar 1991 11:41:44 MM + + Rev 1.1 25 Feb 1991 13:47:12 MM + + Rev 1.0 08 Feb 1991 13:12:06 MM + Initial revision. + +**************************************************************************/ +/****************** I N C L U D E S **************************************/ +// C and C++ Includes. +#include <stdlib.h> +#include <stdio.h> +#include <string.h> +#include <ctype.h> + +// Programmabh„ngige Includes. +#ifndef _RSCHASH_HXX +#include <rschash.hxx> +#endif + +/****************** C O D E **********************************************/ +/************************************************************************* +|* +|* HashTabel::HashTabel() +|* +|* Beschreibung HASHTAB.DOC +|* Ersterstellung MM 20.03.90 +|* Letzte Aenderung MM 27.06.90 +|* +*************************************************************************/ +HashTabel :: HashTabel( USHORT nMaxEntries ){ + nMax = nMaxEntries; // set max entries + nFill = 0; // no entries + lTry = 0; + lAsk = 0; +} + +/************************************************************************* +|* +|* HashTabel::~HashTabel() +|* +|* Beschreibung +|* Ersterstellung MM 17.07.91 +|* Letzte Aenderung MM 17.07.91 +|* +*************************************************************************/ +HashTabel :: ~HashTabel(){ +#ifdef DOS +/* + printf( "Maximum: %d, Fuellung: %d\n", nMax, nFill ); + printf( "Anfragen: %ld, Versuche: %ld", lAsk, lTry ); + if( lTry != 0 ) + printf( ", V/E = %ld\n", lTry / lAsk ); +*/ +#endif +} + +/************************************************************************* +|* +|* HashTabel::Test_Insert() +|* +|* Beschreibung HASHTAB.DOC +|* Ersterstellung MM 20.03.90 +|* Letzte Aenderung MM 27.06.90 +|* +*************************************************************************/ +HASHID HashTabel::Test_Insert( const void * pElement, BOOL bInsert ) +{ + USHORT nHash; + USHORT nIndex; + USHORT nLoop; + + lAsk++; + lTry++; + + nHash = HashFunc( pElement ); + nIndex = nHash % nMax; + + nLoop = 0; // divide to range + while( (nMax != nLoop) && IsEntry( nIndex ) ) + { // is place occupied + if( EQUAL == Compare( pElement, nIndex ) ) // is element in tabel + return( nIndex ); // place of Element + nLoop++; + lTry++; + nIndex = (USHORT)(nIndex + nHash + 7) % nMax; + } + + if( bInsert ) + { + if( nMax == nLoop ) // is tabel full + RscExit( 11 ); + nFill++; + return( nIndex ); // return free place + } + return( HASH_NONAME ); +} + +/************************************************************************* +|* +|* HashTabel::Test() +|* +|* Beschreibung HASHTAB.DOC +|* Ersterstellung MM 15.05.91 +|* Letzte Aenderung MM 15.05.91 +|* +*************************************************************************/ +HASHID HashTabel::Test( const void * pElement ){ + return( Test_Insert( pElement, FALSE ) ); +} + +/************************************************************************* +|* +|* HashTabel::Insert() +|* +|* Beschreibung HASHTAB.DOC +|* Ersterstellung MM 20.03.90 +|* Letzte Aenderung MM 27.06.90 +|* +*************************************************************************/ +HASHID HashTabel::Insert( const void * pElement ){ +// return free place in Tabel or the place, if Element is in the tabel + return( Test_Insert( pElement, TRUE ) ); +} + +/************************************************************************* +|* +|* HashString::HashString() +|* +|* Beschreibung HASHTAB.DOC +|* Ersterstellung MM 20.03.90 +|* Letzte Aenderung MM 27.06.90 +|* +*************************************************************************/ +HashString::HashString( USHORT nMaxEntries ) : HashTabel( nMaxEntries ){ + if( (long)nMaxEntries * sizeof( char * ) >= 0x10000 ){ + // can't allocate more then 64k - 1 Bytes + RscExit( 12 ); + } + // allocate + + ppStr = (char **)RscMem::Malloc( nMaxEntries * sizeof( char * ) ); + + memset( ppStr, 0, nMaxEntries * sizeof( char * ) ); + paSC = new StringCon( (USHORT)40000 ); +} + +/************************************************************************* +|* +|* ~HashString::HashString() +|* +|* Beschreibung HASHTAB.DOC +|* Ersterstellung MM 02.06.91 +|* Letzte Aenderung MM 02.06.91 +|* +*************************************************************************/ +HashString::~HashString(){ + delete paSC; + RscMem::Free( (void *)ppStr ); +} + +/************************************************************************* +|* +|* HashString::HashFunc() +|* +|* Beschreibung HASHTAB.DOC +|* Ersterstellung MM 20.03.90 +|* Letzte Aenderung MM 27.06.90 +|* +*************************************************************************/ +USHORT HashString :: HashFunc( const void * pElement ){ + const char *pStr; + USHORT nHash = 0; // hash value + + pStr = (const char *)pElement; + while( *pStr ){ + nHash ^= toupper( *pStr ) - 'A'; + if( *++pStr ){ + nHash ^= (toupper( *pStr ) - 'A') << 4; + if( *++pStr ) + nHash ^= (toupper( *pStr ) - 'A') << 8; + } + } + return( nHash ); +} + +/************************************************************************* +|* +|* HashString::IsEntry() +|* +|* Beschreibung HASHTAB.DOC +|* Ersterstellung MM 20.03.90 +|* Letzte Aenderung MM 27.06.90 +|* +*************************************************************************/ +BOOL HashString :: IsEntry( HASHID nIndex ){ +// return TRUE if place is occupied +// return FALSE if place is FREE + // ppStr[ nIndex ] == pointer to stringtabel + return( NULL != ppStr[ nIndex ] ); +} + +/************************************************************************* +|* +|* HashString::Insert() +|* +|* Beschreibung HASHTAB.DOC +|* Ersterstellung MM 20.03.90 +|* Letzte Aenderung MM 27.06.90 +|* +*************************************************************************/ +HASHID HashString :: Insert( const char * pElement ){ + HASHID nIndex; + + nIndex = HashTabel::Insert( (const void *)pElement ); + if( !IsEntry( nIndex ) )// is place not occupied ? + // put string in the string tabel + ppStr[ nIndex ] = paSC->Put( pElement ); + return( nIndex ); +} + +/************************************************************************* +|* +|* HashString::Test() +|* +|* Beschreibung +|* Ersterstellung MM 05.11.91 +|* Letzte Aenderung MM 05.11.91 +|* +*************************************************************************/ +HASHID HashString :: Test( const char * pElement ){ + return HashTabel::Test( (const void *)pElement ); +} + +/************************************************************************* +|* +|* HashString::Get() +|* +|* Beschreibung HASHTAB.DOC +|* Ersterstellung MM 20.03.90 +|* Letzte Aenderung MM 27.06.90 +|* +*************************************************************************/ +char * HashString :: Get( HASHID nIndex ){ +// return pointer to string + if( nIndex != HASH_NONAME ) + return( ppStr[ nIndex ] ); + else + return( NULL ); +} + +/************************************************************************* +|* +|* HashString::Get() +|* +|* Beschreibung HASHTAB.DOC +|* Ersterstellung MM 20.03.90 +|* Letzte Aenderung MM 27.06.90 +|* +*************************************************************************/ +COMPARE HashString :: Compare( const void * pElement, HASHID nIndex ){ + short nCmp; // Vergleichsresultat + + nCmp = rsc_stricmp( (const char *)pElement, ppStr[ nIndex ] ); + + if( 0 < nCmp ) + return( GREATER ); + else if( 0 == nCmp ) + return( EQUAL ); + else + return( LESS ); +} + +/************************************************************************* +|* +|* StringCon::StringCon() +|* +|* Beschreibung HASHTAB.DOC +|* Ersterstellung MM 20.03.90 +|* Letzte Aenderung MM 27.06.90 +|* +*************************************************************************/ +StringCon::StringCon( USHORT nMaxEntries ){ + // allocate character field + pField = (char * )RscMem::Malloc( nMaxEntries ); + + nMax = nMaxEntries; // set maximum of characters + nFill = 0; // no character in tabel +} + +/************************************************************************* +|* +|* StringCon::~StringCon() +|* +|* Beschreibung HASHTAB.DOC +|* Ersterstellung MM 02.06.91 +|* Letzte Aenderung MM 02.06.91 +|* +*************************************************************************/ +StringCon::~StringCon(){ + // free character field + RscMem::Free( pField ); +} + +/************************************************************************* +|* +|* StringCon::Put() +|* +|* Beschreibung HASHTAB.DOC +|* Ersterstellung MM 20.03.90 +|* Letzte Aenderung MM 27.06.90 +|* +*************************************************************************/ +char * StringCon :: Put( const char * pStr ) +{ +// put string into the tabel + char * pReturn = pField + nFill; // set return value + + while( nMax > (USHORT)(nFill +1) && *pStr ) // strcpy in tabel + pField[ nFill++ ] = *pStr++; + if( nMax == nFill +1 ){ // buffer overflow ? + RscExit( 13 ); + } + else + pField[ nFill++ ] = '\0'; // terminate with zero. + + return( pReturn ); // return pointer to string +} diff --git a/rsc/source/tools/rsctools.cxx b/rsc/source/tools/rsctools.cxx new file mode 100644 index 000000000000..dd8b545442df --- /dev/null +++ b/rsc/source/tools/rsctools.cxx @@ -0,0 +1,656 @@ +/************************************************************************* + * + * $RCSfile: rsctools.cxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 16:42:56 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ +/************************************************************************ + + Source Code Control System - Header + + $Header: /zpool/svn/migration/cvs_rep_09_09_08/code/rsc/source/tools/rsctools.cxx,v 1.1.1.1 2000-09-18 16:42:56 hr Exp $ + + Source Code Control System - Update + + $Log: not supported by cvs2svn $ + Revision 1.32 2000/09/17 12:51:12 willem.vandorp + OpenOffice header added. + + Revision 1.31 2000/09/07 04:30:57 patrick.luby + Replaced tempnam() with tmpnam() as tempnam() keeps returning the same file name on Mac OS X. + + Revision 1.30 2000/07/26 17:13:24 willem.vandorp + Headers/footers replaced + + Revision 1.29 2000/07/11 17:17:46 th + Unicode + + Revision 1.28 1999/12/08 15:33:51 mh + tmp file not in actual directory + + Revision 1.27 1999/09/21 17:08:45 mm + Bigendian correct + +**************************************************************************/ +/****************** I N C L U D E S **************************************/ + +// C and C++ Includes. +#include <stdlib.h> +#include <stdio.h> +#if defined ( DOS ) || defined ( WIN ) || defined (WNT ) +#include <direct.h> +#endif +#if defined ( OS2 ) && !defined ( GCC ) +#include <direct.h> +#endif +#include <string.h> +#include <ctype.h> +#ifdef MAC +#include <cursorctl.h> +#endif + +#include <tools/fsys.hxx> + +// Include +#ifndef _RSCDEF_HXX +#include <rscdef.hxx> +#endif +#ifndef _RSCTOOLS_HXX +#include <rsctools.hxx> +#endif + +#if defined (WIN) || defined (MAC) +#define ONLY_NEW +#endif + +/****************** C o d e **********************************************/ +/************************************************************************* +|* +|* rsc_strnicmp() +|* +|* Beschreibung Vergleicht zwei Strings Case-Unabhaengig bis zu +|* einer bestimmten Laenge +|* Ersterstellung MM 13.02.91 +|* Letzte Aenderung MM 13.02.91 +|* +*************************************************************************/ +int rsc_strnicmp( const char *string1, const char *string2, size_t count ) +{ + size_t i; + + for( i = 0; ( i < count ) && string1[ i ] && string2[ i ] ; i++ ) + { + if( tolower( string1[ i ] ) < tolower( string2[ i ] ) ) + return( -1 ); + else if( tolower( string1[ i ] ) > tolower( string2[ i ] ) ) + return( 1 ); + } + if( i == count ) + return( 0 ); + else if( tolower( string1[ i ] ) < tolower( string2[ i ] ) ) + return( -1 ); + else if( tolower( string1[ i ] ) > tolower( string2[ i ] ) ) + return( 1 ); + return( 0 ); +} + +/************************************************************************* +|* +|* rsc_strnicmp() +|* +|* Beschreibung Vergleicht zwei Strings Case-Unabhaengig +|* Ersterstellung MM 13.02.91 +|* Letzte Aenderung MM 13.02.91 +|* +*************************************************************************/ +int rsc_stricmp( const char *string1, const char *string2 ){ + int i; + + for( i = 0; string1[ i ] && string2[ i ]; i++ ){ + if( tolower( string1[ i ] ) < tolower( string2[ i ] ) ) + return( -1 ); + else if( tolower( string1[ i ] ) > tolower( string2[ i ] ) ) + return( 1 ); + } + if( tolower( string1[ i ] ) < tolower( string2[ i ] ) ) + return( -1 ); + else if( tolower( string1[ i ] ) > tolower( string2[ i ] ) ) + return( 1 ); + return( 0 ); +} + +/************************************************************************* +|* +|* GetTmpFileName() +|* +|* Beschreibung Gibt einen String eines eindeutigen Dateinamens +|* zurueck. Der Speicher fuer den String wird mit +|* malloc allokiert +|* Ersterstellung MM 13.02.91 +|* Letzte Aenderung MH 13.10.97 +|* +*************************************************************************/ +ByteString GetTmpFileName() +{ + // Use tmpnam instead of tempnam as tempnam has some bugs in Mac OS X + return ByteString( tmpnam( NULL ) ); +} + +/********************************************************************/ +/* */ +/* Function : Append( ) */ +/* */ +/* Parameters : psw - pointer to a preprocessor switch */ +/* */ +/* Description : appends text files */ +/********************************************************************/ +BOOL Append( FILE * fDest, ByteString aTmpFile ) +{ +#define MAX_BUF 1000 + char szBuf[ MAX_BUF ]; + short nItems; + FILE *fSource; + + fSource = fopen( aTmpFile.GetBuffer(), "rb" ); + if( !fDest || !fSource ){ + if( fSource ) + fclose( fSource ); + return FALSE; + } + else{ + do{ // append + nItems = fread( szBuf, sizeof( char ), MAX_BUF, fSource ); + fwrite( szBuf, sizeof( char ), nItems, fDest ); + } while( MAX_BUF == nItems ); + + fclose( fSource ); + }; + return TRUE; +} + +BOOL Append( ByteString aOutputSrs, ByteString aTmpFile ) +{ + FILE * fDest = fopen( aOutputSrs.GetBuffer(), "ab" ); + + BOOL bRet = Append( fDest, aTmpFile ); + + if( fDest ) + fclose( fDest ); + + return bRet; +} + +/************************************************************************* +|* +|* InputFile +|* +|* Beschreibung Haengt Extension an, wenn keine da ist +|* Parameter: pInput, der Input-Dateiname. +|* pExt, die Extension des Ausgabenamens +|* Ersterstellung MM 13.02.91 +|* Letzte Aenderung MM 28.06.91 +|* +*************************************************************************/ +ByteString InputFile ( char * pInput, char * pExt ) +{ + UniString aUniInput( pInput, RTL_TEXTENCODING_ASCII_US ); + DirEntry aFileName( aUniInput ); + + if ( 0 == aFileName.GetExtension().Len() ) + { + UniString aExt( pExt, RTL_TEXTENCODING_ASCII_US ); + aFileName.SetExtension( aExt ); + } + + return ByteString( aFileName.GetFull(), RTL_TEXTENCODING_ASCII_US ); +} + +/************************************************************************* +|* +|* OutputFile +|* +|* Beschreibung Ersetzt Extension durch eine andere +|* Parameter: input, der Input-Dateiname. +|* pExt, die Extension des Ausgabenamens +|* Ersterstellung MM 13.02.91 +|* Letzte Aenderung MM 28.06.91 +|* +*************************************************************************/ +ByteString OutputFile ( ByteString aInput, char * pExt ) +{ + UniString aUniInput( aInput, RTL_TEXTENCODING_ASCII_US ); + DirEntry aFileName( aUniInput ); + + UniString aExt( pExt, RTL_TEXTENCODING_ASCII_US ); + aFileName.SetExtension( aExt ); + + return ByteString( aFileName.GetFull(), RTL_TEXTENCODING_ASCII_US ); +} + +/************************************************************************* +|* +|* ::ResonseFile() +|* +|* Beschreibung Kommandozeile aufbereiten +|* Ersterstellung MM 05.09.91 +|* Letzte Aenderung MM 05.09.91 +|* +*************************************************************************/ +char * ResponseFile( RscPtrPtr * ppCmd, char ** ppArgv, + USHORT nArgc ) +{ + FILE *fFile; + int nItems; + char szBuffer[4096]; // file buffer + USHORT i; + + // Programmname + ppCmd->Append( ((RscMem *)0)->Assignsw( *ppArgv, 0 ) ); + for( i = 1; i < nArgc; i++ ) + { + if( '@' == **(ppArgv +i) ){ // wenn @, dann Response-Datei + if( NULL == (fFile = fopen( (*(ppArgv +i)) +1, "r" )) ) + return( (*(ppArgv +i)) ); + + nItems = fread( &szBuffer[ 0 ], 1, sizeof( char ), fFile ); + while( nItems ) + { + if( !isspace( szBuffer[ 0 ] ) ) + { + USHORT n = 0; + while( nItems && !isspace( szBuffer[ n ] ) && + n +1 < sizeof( szBuffer ) ) + { + n++; + nItems = fread( &szBuffer[ n ], 1, + sizeof( char ), fFile ); + } + szBuffer[ n ] = '\0'; + ppCmd->Append( ((RscMem *)0)->Assignsw( szBuffer, 0 ) ); + } + nItems = fread( &szBuffer[ 0 ], 1, sizeof( char ), fFile ); + }; + + fclose( fFile ); + } + else + ppCmd->Append( ((RscMem *)0)->Assignsw( *(ppArgv +i), 0 ) ); + }; + ppCmd->Append( (void *)0 ); + return( NULL ); +} + + +/*************** R s c M e m ********************************************/ + +#ifdef DOS +class RscCount { +public: + long nCount; + RscCount(){ nCount = 0; } +// ~RscCount(){ printf( "\nMalloczaehler: %ld\n", nCount ); } +}; +RscCount aRscCount; +#endif +/************************************************************************* +|* +|* RscMem :: Malloc() +|* +|* Beschreibung Speicher allokieren +|* Ersterstellung MM 13.02.91 +|* Letzte Aenderung MM 13.02.91 +|* +*************************************************************************/ +void * RscMem :: Malloc( USHORT nSize ){ + char * pMem; + +#ifdef MAC + SpinCursor( 1 ); +#endif +#ifdef DOS + aRscCount.nCount++; +#endif +#ifdef ONLY_NEW + pMem = new char[ nSize + sizeof( USHORT ) ]; + *(USHORT *)pMem = nSize; + pMem += sizeof( USHORT ); +#else + if( NULL == (pMem = (char *)malloc( nSize )) ) + RscExit( 10 ); +#endif + return( pMem ); +} + +/************************************************************************* +|* +|* RscMem :: Realloc() +|* +|* Beschreibung Speicher zusaetzlich allokieren +|* Ersterstellung MM 13.02.91 +|* Letzte Aenderung MM 13.02.91 +|* +*************************************************************************/ +void * RscMem :: Realloc( void * pMem, USHORT nSize ){ +#ifdef MAC + SpinCursor( 1 ); +#endif +#ifdef ONLY_NEW + char * pTmp = (char *)pMem; + USHORT nMin, nOldSize; + + pMem = Malloc( nSize ); + nOldSize = *(USHORT *)(pTmp - sizeof( USHORT ) ); + nMin = (nSize < nOldSize) ? nSize : nOldSize; + memcpy( pMem, pTmp, nMin ); + delete (pTmp - sizeof( USHORT )); +#else +#ifdef UNX + if( NULL == (pMem = realloc( (char*)pMem, nSize )) ) +#else + if( NULL == (pMem = realloc( pMem, nSize )) ) +#endif + RscExit( 10 ); +#endif + return( pMem ); +} + +/************************************************************************* +|* +|* RscMem :: Free() +|* +|* Beschreibung Speicher freigeben +|* Ersterstellung MM 13.02.91 +|* Letzte Aenderung MM 13.02.91 +|* +*************************************************************************/ +void RscMem :: Free( void * pMem ){ +#ifdef DOS + aRscCount.nCount--; +#endif +#ifdef ONLY_NEW + delete ((char *)pMem - sizeof( USHORT )); +#else +#ifdef UNX + free( (char *)pMem ); +#else + free( pMem ); +#endif +#endif +} + +/************************************************************************* +|* +|* RscMem :: Assignsw +|* +|* Beschreibung Allokiert speicher fuer String und kopiert ihn +|* Parameter: psw, der String. +|* nExtraSpace, weiterer Speicher hinter dem String +|* Ersterstellung MM 13.02.91 +|* Letzte Aenderung MM 13.02.91 +|* +*************************************************************************/ +char * RscMem :: Assignsw( const char *psw, short nExtraSpace ) +{ + char * pTmp; + + if( !psw ) + psw = ""; + /* allocate memory */ + pTmp = (char *)Malloc( strlen( psw ) + 1 + nExtraSpace ); + /* copy string into allocated memory*/ + strcpy( pTmp, psw ); + return( pTmp ); +} + +/*************** R s c P t r P t r **************************************/ +/************************************************************************* +|* +|* RscPtrPtr :: RscPtrPtr() +|* +|* Beschreibung Eine Tabelle mit Zeigern +|* Ersterstellung MM 13.02.91 +|* Letzte Aenderung MM 13.02.91 +|* +*************************************************************************/ +RscPtrPtr :: RscPtrPtr(){ + nCount = 0; + pMem = NULL; +} + +/************************************************************************* +|* +|* RscPtrPtr :: ~RscPtrPtr() +|* +|* Beschreibung Zerst”rt eine Tabelle mit Zeigern, die Zeiger werde +|* ebenfalls freigegebn +|* Ersterstellung MM 13.02.91 +|* Letzte Aenderung MM 13.02.91 +|* +*************************************************************************/ +RscPtrPtr :: ~RscPtrPtr(){ + Reset(); +} + +/************************************************************************* +|* +|* RscPtrPtr :: Reset() +|* +|* Beschreibung +|* Ersterstellung MM 03.05.91 +|* Letzte Aenderung MM 03.05.91 +|* +*************************************************************************/ +void RscPtrPtr :: Reset(){ + USHORT i; + + if( pMem ){ + for( i = 0; i < nCount; i++ ){ + if( pMem[ i ] ) + RscMem::Free( pMem[ i ] ); + } + RscMem::Free( (void *)pMem ); + }; + nCount = 0; + pMem = NULL; +} + +/************************************************************************* +|* +|* RscPtrPtr :: Append() +|* +|* Beschreibung Haengt einen Eintrag an. +|* Ersterstellung MM 13.02.91 +|* Letzte Aenderung MM 13.02.91 +|* +*************************************************************************/ +USHORT RscPtrPtr :: Append( void * pBuffer ){ + if( !pMem ) + pMem = (void **)RscMem::Malloc( (nCount +1) * sizeof( void * ) ); + else + pMem = (void **)RscMem::Realloc( (void *)pMem, + (USHORT)((nCount +1) * sizeof( void * ) + ) ); + pMem[ nCount ] = pBuffer; + return( nCount++ ); +} + +/************************************************************************* +|* +|* RscPtrPtr :: GetEntry() +|* +|* Beschreibung Liefert einen Eintrag, NULL wenn nicht vorhanden. +|* Ersterstellung MM 13.02.91 +|* Letzte Aenderung MM 13.02.91 +|* +*************************************************************************/ +void * RscPtrPtr :: GetEntry( USHORT nEntry ){ + if( nEntry < nCount ) + return( pMem[ nEntry ] ); + return( NULL ); +} + +/****************** R S C W R I T E R C **********************************/ +/************************************************************************* +|* +|* RscWriteRc :: RscWriteRc() +|* +|* Beschreibung +|* Ersterstellung MM 15.04.91 +|* Letzte Aenderung MM 15.04.91 +|* +*************************************************************************/ +RscWriteRc::RscWriteRc( RSCBYTEORDER_TYPE nOrder ) +{ + short nSwapTest = 1; + RSCBYTEORDER_TYPE nMachineOrder; + + bSwap = FALSE; + if( nOrder != RSC_SYSTEMENDIAN ) + { + if( (BYTE)*(BYTE *)&nSwapTest ) + nMachineOrder = RSC_LITTLEENDIAN; + else + nMachineOrder = RSC_BIGENDIAN; + bSwap = nOrder != nMachineOrder; + } + nByteOrder = nOrder; + nLen = 0; + pMem = NULL; +} + +/************************************************************************* +|* +|* RscWriteRc :: ~RscWriteRc() +|* +|* Beschreibung +|* Ersterstellung MM 15.04.91 +|* Letzte Aenderung MM 15.04.91 +|* +*************************************************************************/ +RscWriteRc :: ~RscWriteRc() +{ + if( pMem ) + RscMem::Free( pMem ); +} + +/************************************************************************* +|* +|* RscWriteRc :: IncSize() +|* +|* Beschreibung +|* Ersterstellung MM 15.04.91 +|* Letzte Aenderung MM 15.04.91 +|* +*************************************************************************/ +USHORT RscWriteRc :: IncSize( USHORT nSize ) +{ + nLen += nSize; + if( pMem ) + pMem = RscMem::Realloc( pMem, nLen ); + return( nLen - nSize ); +} + +/************************************************************************* +|* +|* RscWriteRc :: GetPointer() +|* +|* Beschreibung +|* Ersterstellung MM 15.04.91 +|* Letzte Aenderung MM 15.04.91 +|* +*************************************************************************/ +char * RscWriteRc :: GetPointer( USHORT nSize ) +{ + if( !pMem ) + pMem = (char *)RscMem::Malloc( nLen ); + return( pMem + nSize ); +} + + +/************************************************************************* +|* +|* RscWriteRc :: Put() +|* +|* Beschreibung +|* Ersterstellung MM 15.04.91 +|* Letzte Aenderung MM 15.04.91 +|* +*************************************************************************/ +void RscWriteRc :: Put( USHORT nVal ) +{ + USHORT nOldLen; + + nOldLen = IncSize( sizeof( nVal ) ); + PutAt( nOldLen, nVal ); +} + +void RscWriteRc :: PutUTF8( char * pStr ) +{ + USHORT nStrLen = 0; + if( pStr ) + nStrLen = strlen( pStr ); + + USHORT n = nStrLen +1; + if( n % 2 ) + // align to 2 + n++; + + USHORT nOldLen = IncSize( n ); + memcpy( GetPointer( nOldLen ), pStr, nStrLen ); + // 0 terminated + pMem[ nOldLen + nStrLen ] = '\0'; +} diff --git a/rsc/source/tools/rsctree.cxx b/rsc/source/tools/rsctree.cxx new file mode 100644 index 000000000000..bc7ea5194a3c --- /dev/null +++ b/rsc/source/tools/rsctree.cxx @@ -0,0 +1,604 @@ +/************************************************************************* + * + * $RCSfile: rsctree.cxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 16:42:56 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ +/************************************************************************ + + Source Code Control System - Header + + $Header: /zpool/svn/migration/cvs_rep_09_09_08/code/rsc/source/tools/rsctree.cxx,v 1.1.1.1 2000-09-18 16:42:56 hr Exp $ + + Source Code Control System - Update + + $Log: not supported by cvs2svn $ + Revision 1.11 2000/09/17 12:51:12 willem.vandorp + OpenOffice header added. + + Revision 1.10 2000/07/26 17:13:24 willem.vandorp + Headers/footers replaced + + Revision 1.9 2000/07/11 17:17:55 th + Unicode + + Revision 1.8 1997/08/27 18:17:52 MM + neue Headerstruktur + +**************************************************************************/ +/****************** I N C L U D E S **************************************/ + +// C and C++ Includes. +#include <stdlib.h> +#include <stdio.h> +#include <string.h> + +// Programmabh„ngige Includes. +#ifndef _LINK_HXX //autogen +#include <tools/link.hxx> +#endif + +#ifndef _RSCTREE_HXX +#include <rsctree.hxx> +#endif + +/****************** C O D E **********************************************/ + +/****************** B i N o d e ******************************************/ +/************************************************************************* +|* +|* BiNode::BiNode() +|* +|* Beschreibung NAME.DOC +|* Ersterstellung MM 07.02.91 +|* Letzte Aenderung MM 07.02.91 +|* +*************************************************************************/ +BiNode::BiNode(){ + pLeft = pRight = NULL; +} + +/************************************************************************* +|* +|* BiNode::~BiNode() +|* +|* Beschreibung +|* Ersterstellung MM 07.02.91 +|* Letzte Aenderung MM 07.02.91 +|* +*************************************************************************/ +BiNode::~BiNode(){ +} + +/************************************************************************* +|* +|* BiNode::EnumNodes() +|* +|* Beschreibung +|* Ersterstellung MM 07.02.91 +|* Letzte Aenderung MM 07.02.91 +|* +*************************************************************************/ +void BiNode::EnumNodes( Link aLink ) const{ + if( Left() ) + Left()->EnumNodes( aLink ); + aLink.Call( (BiNode *)this ); + if( Right() ) + Right()->EnumNodes( aLink ); +} + +/************************************************************************* +|* +|* BiNode::ChangeDLListBTree() +|* +|* Beschreibung +|* Ersterstellung MM 11.01.91 +|* Letzte Aenderung MM 11.01.91 +|* +*************************************************************************/ +BiNode * BiNode::ChangeDLListBTree( BiNode * pList ){ + BiNode * pRightNode; + BiNode * pMiddle; + BiNode * pTmp; + USHORT nEle, i; + + if( pList ){ + while( pList->Left() ) + pList = pList->Left(); + pTmp = pList; + for( nEle = 0; pTmp->Right(); nEle++ ) + pTmp = pTmp->Right(); + pMiddle = pList; + if( nEle / 2 ) + for( i = 0; i < (USHORT)(nEle / 2); i++ ) + pMiddle = pMiddle->Right(); + else + pList = (BiNode *)0; + + if( NULL != (pTmp = pMiddle->Left()) ) // rechten Zeiger auf Null + pTmp->pRight = (BiNode *)0; + + // linken Zeiger auf Null + if( NULL != (pRightNode = pMiddle->Right()) ) + pRightNode->pLeft = (BiNode *)0; + + pMiddle->pLeft = ChangeDLListBTree( pList ); + pMiddle->pRight = ChangeDLListBTree( pRightNode ); + + return( pMiddle ); + } + return( pList ); +} + +/************************************************************************* +|* +|* BiNode::ChangeBTreeDLList() +|* +|* Beschreibung +|* Ersterstellung MM 11.01.91 +|* Letzte Aenderung MM 11.01.91 +|* +*************************************************************************/ +BiNode * BiNode::ChangeBTreeDLList(){ + BiNode * pList; + BiNode * pLL_RN; // linke Liste rechter Knoten + + if( Right() ){ + pList = Right()->ChangeBTreeDLList(); + pRight = pList; + pList->pLeft = this; + } + pList = this; + if( Left() ){ + pLL_RN = pList = Left()->ChangeBTreeDLList(); + while( pLL_RN->Right() ) + pLL_RN = pLL_RN->Right(); + pLeft = pLL_RN; + pLL_RN->pRight = this; + } + return( pList ); +} + +/****************** N a m e N o d e **************************************/ +/************************************************************************* +|* +|* NameNode::Remove() +|* +|* Beschreibung +|* Ersterstellung MM 10.07.91 +|* Letzte Aenderung MM 10.07.91 +|* +*************************************************************************/ +NameNode * NameNode::Remove( NameNode * pRemove ){ + NameNode * pRoot = this; + NameNode * pParent = SearchParent( pRemove ); + + if( pParent ){ + if( pParent->Left() + && (EQUAL == pRemove->Compare( pParent->Left() ) ) ){ + pParent->pLeft = pRemove->Left(); + if( pRemove->Right() ) + pParent->Insert( pRemove->Right() ); + } + else if( pParent->Right() + && (EQUAL == pRemove->Compare( pParent->Right() ) ) ){ + pParent->pRight = pRemove->Right(); + if( pRemove->Left() ) + pParent->Insert( pRemove->Left() ); + } + } + else if( EQUAL == this->Compare( pRemove ) ){ + if( Right() ){ + pRoot = Right(); + if( Left() ) + Right()->Insert( Left() ); + } + else{ + pRoot = Left(); + } + } + pRemove->pLeft = pRemove->pRight = NULL; + + return pRoot; +} + + +/************************************************************************* +|* +|* NameNode::Compare +|* +|* Beschreibung +|* Ersterstellung MM 10.07.91 +|* Letzte Aenderung MM 13.07.91 +|* +*************************************************************************/ +COMPARE NameNode::Compare( const NameNode * pCompare ) const{ + if( (long)this < (long)pCompare ) + return LESS; + else if( (long)this > (long)pCompare ) + return GREATER; + else + return EQUAL; +} + +COMPARE NameNode::Compare( const void * pCompare ) const{ + if( (long)this < (long)pCompare ) + return LESS; + else if( (long)this > (long)pCompare ) + return GREATER; + else + return EQUAL; +} + +/************************************************************************* +|* +|* NameNode::SearchParent +|* +|* Beschreibung +|* Ersterstellung MM 10.07.91 +|* Letzte Aenderung MM 10.07.91 +|* +*************************************************************************/ +NameNode* NameNode::SearchParent( const NameNode * pSearch ) const{ +// search for a parent node. +// return a pointer to the parent node if found. +// otherwise return 0. + short nCmp = Compare( pSearch ); + + if( nCmp == GREATER ){ + if( Left() ){ + if( ((NameNode *)Left())->Compare( pSearch ) == EQUAL ) + return (NameNode *)this; + return ((NameNode *)Left())->SearchParent( pSearch ); + }; + } + else if( nCmp == LESS ){ + if( Right() ){ + if( ((NameNode *)Right())->Compare( pSearch ) == EQUAL ) + return (NameNode *)this; + return ((NameNode *)Right())->SearchParent( pSearch ); + } + }; + return( (NameNode *)NULL ); +} + +/************************************************************************* +|* +|* NameNode::Search +|* +|* Beschreibung +|* Ersterstellung MM 21.03.90 +|* Letzte Aenderung MM 27.06.90 +|* +*************************************************************************/ +NameNode* NameNode::Search( const NameNode * pSearch ) const{ +// search for a node. +// return a pointer to the node if found. +// otherwise return 0. + short nCmp = Compare( pSearch ); + + if( nCmp == GREATER ){ + if( Left() ) + return ((NameNode *)Left())->Search( pSearch ); + } + else if( nCmp == LESS ){ + if( Right() ) + return ((NameNode *)Right())->Search( pSearch ); + } + else + return( (NameNode *)this ); + + return( NULL ); +} + +NameNode* NameNode::Search( const void * pSearch ) const{ +// search for a node. +// return a pointer to the node if found. +// otherwise return 0. + short nCmp = Compare( pSearch ); + + if( nCmp == GREATER ){ + if( Left() ) + return ((NameNode *)Left())->Search( pSearch ); + } + else if( nCmp == LESS ){ + if( Right() ) + return ((NameNode *)Right())->Search( pSearch ); + } + else + return( (NameNode *)this ); + + return( NULL ); +} + +/************************************************************************* +|* +|* NameNode::Insert() +|* +|* Beschreibung NAME.DOC +|* Ersterstellung MM 11.01.91 +|* Letzte Aenderung MM 11.01.91 +|* +*************************************************************************/ +BOOL NameNode::Insert( NameNode * pTN, USHORT * pnDepth ){ +// Ein Knoten wird in den Baum eingefuegt +// Gibt es einen Knoten mit dem gleichen Namen, dann return FALSE +// sonst return TRUE. Der Knoten wird auf jeden Fall eingefuegt. + + BOOL bRet = TRUE; + short nCmp = Compare( pTN ); + + *pnDepth += 1; + if( nCmp == GREATER ){ + if( Left() ) + bRet = ((NameNode *)Left())->Insert( pTN, pnDepth ); + else + pLeft = pTN; + } + else{ + if( Right() ) + bRet = ((NameNode *)Right())->Insert( pTN, pnDepth ); + else + pRight = pTN; + if( nCmp == EQUAL ) + bRet = FALSE; + }; + return( bRet ); +} + +/************************************************************************* +|* +|* NameNode::Insert() +|* +|* Beschreibung NAME.DOC +|* Ersterstellung MM 21.03.90 +|* Letzte Aenderung MM 11.01.91 +|* +*************************************************************************/ +BOOL NameNode::Insert( NameNode * pTN ){ +// insert a node in the tree. +// if the node with the same name is in, return FALSE and no insert. +// if not return true. + USHORT nDepth = 0; + BOOL bRet; + + bRet = Insert( pTN, &nDepth ); + if( bRet ){ + if( nDepth > 20 ){ + if( Left() ) + pLeft = ChangeDLListBTree( Left()->ChangeBTreeDLList() ); + if( Right() ) + pRight = ChangeDLListBTree( Right()->ChangeBTreeDLList() ); + } + } + + return( bRet ); +} + +/************************************************************************* +|* +|* NameNode::OrderTree() +|* +|* Beschreibung +|* Ersterstellung MM 23.09.91 +|* Letzte Aenderung MM 23.09.91 +|* +*************************************************************************/ +void NameNode::OrderTree(){ + NameNode * pTmpLeft = (NameNode *)Left(); + NameNode * pTmpRight = (NameNode *)Right(); + + pLeft = NULL; + pRight = NULL; + SubOrderTree( pTmpLeft ); + SubOrderTree( pTmpRight ); +} + +void NameNode::SubOrderTree( NameNode * pOrderNode ){ + if( pOrderNode ){ + NameNode * pTmpLeft = (NameNode *)pOrderNode->Left(); + NameNode * pTmpRight = (NameNode *)pOrderNode->Right(); + pOrderNode->pLeft = NULL; + pOrderNode->pRight = NULL; + Insert( pOrderNode ); + SubOrderTree( pTmpLeft ); + SubOrderTree( pTmpRight ); + } +} + +/************************************************************************* +|* +|* NameNode::IdOrderTree() +|* +|* Beschreibung +|* Ersterstellung MM 15.11.91 +|* Letzte Aenderung MM 15.11.91 +|* +*************************************************************************/ +class OrderCtrl { + BOOL bOrder; + NameNode * pName; + DECL_LINK( CallBackFunc, NameNode * ); +public: + OrderCtrl() { bOrder = FALSE; pName = NULL; } + BOOL IsOrder( const NameNode * pRoot ) + { + bOrder = TRUE; + pName = NULL; + pRoot->EnumNodes( LINK( this, OrderCtrl, CallBackFunc ) ); + return bOrder; + }; +}; +IMPL_LINK_INLINE_START( OrderCtrl, CallBackFunc, NameNode *, pNext ) +{ + if( pName && pName->Compare( pNext ) != LESS ) + bOrder = FALSE; + pName = pNext; + return 0; +} +IMPL_LINK_INLINE_END( OrderCtrl, CallBackFunc, NameNode *, pNext ) + +BOOL NameNode::IsOrderTree() const{ + OrderCtrl aOrder; + + return aOrder.IsOrder( this ); +} + +/****************** I d N o d e ******************************************/ +/************************************************************************* +|* +|* IdNode::Search() +|* +|* Beschreibung +|* Ersterstellung MM 06.11.91 +|* Letzte Aenderung MM 06.11.91 +|* +*************************************************************************/ +IdNode * IdNode::Search( USHORT nTypeName ) const{ + return( (IdNode *)NameNode::Search( (const void *)&nTypeName ) ); +} + +/************************************************************************* +|* +|* IdNode::Compare() +|* +|* Beschreibung +|* Ersterstellung MM 06.11.91 +|* Letzte Aenderung MM 06.11.91 +|* +*************************************************************************/ +COMPARE IdNode::Compare( const NameNode * pSearch ) const +{ + if( GetId() < (USHORT)(((const IdNode *)pSearch)->GetId()) ) + return LESS; + else if( GetId() > (USHORT)(((const IdNode *)pSearch)->GetId()) ) + return GREATER; + else + return EQUAL; +} + +COMPARE IdNode::Compare( const void * pSearch ) const{ +// pSearch ist ein Zeiger auf USHORT + + if( GetId() < *((const USHORT *)pSearch) ) + return LESS; + else if( GetId() > *((const USHORT *)pSearch) ) + return GREATER; + else + return EQUAL; +} + +/************************************************************************* +|* +|* IdNode::GetId() +|* +|* Beschreibung +|* Ersterstellung MM 23.09.91 +|* Letzte Aenderung MM 23.09.91 +|* +*************************************************************************/ +USHORT IdNode::GetId() const +{ + return( 0xFFFF ); +} + +/************************************************************************* +|* +|* StringNode::Search() +|* +|* Beschreibung +|* Ersterstellung MM 06.11.91 +|* Letzte Aenderung MM 06.11.91 +|* +*************************************************************************/ +StringNode * StringNode::Search( const char * pSearch ) const{ + return (StringNode *)NameNode::Search( (const void *)pSearch ); +} + +/************************************************************************* +|* +|* StringNode::Compare() +|* +|* Beschreibung +|* Ersterstellung MM 06.11.91 +|* Letzte Aenderung MM 06.11.91 +|* +*************************************************************************/ +COMPARE StringNode::Compare( const NameNode * pSearch ) const +{ + short nCmp = strcmp( aName.GetBuffer(), + ((const StringNode *)pSearch)->aName.GetBuffer() ); + if( nCmp < 0 ) + return LESS; + else if( nCmp > 0 ) + return GREATER; + else + return EQUAL; +} + +COMPARE StringNode::Compare( const void * pSearch ) const +{ +// pSearch ist ein Zeiger auf const char * + short nCmp = strcmp( aName.GetBuffer(), (const char *)pSearch ); + + if( nCmp < 0 ) + return LESS; + else if( nCmp > 0 ) + return GREATER; + else + return EQUAL; +} |