xref: /aoo41x/main/rsc/inc/rsctools.hxx (revision f7c60c9c)
1*f7c60c9cSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*f7c60c9cSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*f7c60c9cSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*f7c60c9cSAndrew Rist  * distributed with this work for additional information
6*f7c60c9cSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*f7c60c9cSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*f7c60c9cSAndrew Rist  * "License"); you may not use this file except in compliance
9*f7c60c9cSAndrew Rist  * with the License.  You may obtain a copy of the License at
10*f7c60c9cSAndrew Rist  *
11*f7c60c9cSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*f7c60c9cSAndrew Rist  *
13*f7c60c9cSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*f7c60c9cSAndrew Rist  * software distributed under the License is distributed on an
15*f7c60c9cSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*f7c60c9cSAndrew Rist  * KIND, either express or implied.  See the License for the
17*f7c60c9cSAndrew Rist  * specific language governing permissions and limitations
18*f7c60c9cSAndrew Rist  * under the License.
19*f7c60c9cSAndrew Rist  *
20*f7c60c9cSAndrew Rist  *************************************************************/
21*f7c60c9cSAndrew Rist 
22*f7c60c9cSAndrew Rist 
23cdf0e10cSrcweir struct RSHEADER_TYPE;
24cdf0e10cSrcweir class  RscPtrPtr;
25cdf0e10cSrcweir 
26cdf0e10cSrcweir #ifndef _RSCTOOLS_HXX
27cdf0e10cSrcweir #define _RSCTOOLS_HXX
28cdf0e10cSrcweir 
29cdf0e10cSrcweir #ifdef UNX
30cdf0e10cSrcweir #include <stdlib.h>
31cdf0e10cSrcweir #endif
32cdf0e10cSrcweir #include <stdio.h>
33cdf0e10cSrcweir #include <tools/string.hxx>
34cdf0e10cSrcweir #include <tools/list.hxx>
35cdf0e10cSrcweir 
36cdf0e10cSrcweir /******************* T y p e s *******************************************/
37cdf0e10cSrcweir // Zeichensatz
38cdf0e10cSrcweir enum COMPARE { LESS = -1, EQUAL = 0, GREATER = 1 };
39cdf0e10cSrcweir 
40cdf0e10cSrcweir enum RSCBYTEORDER_TYPE { RSC_BIGENDIAN, RSC_LITTLEENDIAN, RSC_SYSTEMENDIAN };
41cdf0e10cSrcweir 
42cdf0e10cSrcweir /******************* M A K R O S *****************************************/
43cdf0e10cSrcweir #define ALIGNED_SIZE( nSize )								\
44cdf0e10cSrcweir 			(nSize + sizeof( void * ) -1) / sizeof( void * ) * sizeof( void * )
45cdf0e10cSrcweir /******************* F u n c t i o n   F o r w a r d s *******************/
46cdf0e10cSrcweir ByteString GetTmpFileName();
47cdf0e10cSrcweir sal_Bool Append( ByteString aDestFile, ByteString aSourceFile );
48cdf0e10cSrcweir sal_Bool Append( FILE * fDest, ByteString aSourceFile );
49cdf0e10cSrcweir ByteString InputFile ( const char * pInput, const char * pExt );
50cdf0e10cSrcweir ByteString OutputFile( ByteString aInput, const char * ext );
51cdf0e10cSrcweir char * ResponseFile( RscPtrPtr * ppCmd, char ** ppArgv,
52cdf0e10cSrcweir 					 sal_uInt32 nArgc );
53cdf0e10cSrcweir void RscExit( sal_uInt32 nExit );
54cdf0e10cSrcweir 
55cdf0e10cSrcweir /********* A n s i - F u n c t i o n   F o r w a r d s *******************/
56cdf0e10cSrcweir int rsc_strnicmp( const char *string1, const char *string2, size_t count );
57cdf0e10cSrcweir int rsc_stricmp( const char *string1, const char *string2 );
58cdf0e10cSrcweir char* rsc_strdup( const char* );
59cdf0e10cSrcweir 
60cdf0e10cSrcweir /****************** C L A S S E S ****************************************/
61cdf0e10cSrcweir DECLARE_LIST( RscStrList, ByteString * )
62cdf0e10cSrcweir /*********** R s c C h a r ***********************************************/
63cdf0e10cSrcweir class RscChar
64cdf0e10cSrcweir {
65cdf0e10cSrcweir public:
66cdf0e10cSrcweir 	static char * MakeUTF8( char * pStr, sal_uInt16 nTextEncoding );
67cdf0e10cSrcweir };
68cdf0e10cSrcweir 
69cdf0e10cSrcweir /****************** R s c P t r P t r ************************************/
70cdf0e10cSrcweir class RscPtrPtr
71cdf0e10cSrcweir {
72cdf0e10cSrcweir 	sal_uInt32	nCount;
73cdf0e10cSrcweir 	void ** 		pMem;
74cdf0e10cSrcweir public:
75cdf0e10cSrcweir 					RscPtrPtr();
76cdf0e10cSrcweir 					~RscPtrPtr();
77cdf0e10cSrcweir 	void			Reset();
78cdf0e10cSrcweir 	sal_uInt32	Append( void * );
Append(char * pStr)79cdf0e10cSrcweir 	sal_uInt32	Append( char * pStr ){
80cdf0e10cSrcweir 						return( Append( (void *)pStr ) );
81cdf0e10cSrcweir 					};
GetCount()82cdf0e10cSrcweir 	sal_uInt32	GetCount(){ return( nCount ); };
83cdf0e10cSrcweir 	void *			GetEntry( sal_uInt32 nEle );
GetBlock()84cdf0e10cSrcweir 	void ** 		GetBlock(){ return( pMem ); };
85cdf0e10cSrcweir };
86cdf0e10cSrcweir 
87cdf0e10cSrcweir /****************** R s c W r i t e R c **********************************/
88cdf0e10cSrcweir class RscWriteRc
89cdf0e10cSrcweir {
90cdf0e10cSrcweir 	sal_uInt32				nLen;
91cdf0e10cSrcweir 	sal_Bool				bSwap;
92cdf0e10cSrcweir 	RSCBYTEORDER_TYPE	nByteOrder;
93cdf0e10cSrcweir 	char *				pMem;
94cdf0e10cSrcweir 	char *				GetPointer( sal_uInt32 nSize );
95cdf0e10cSrcweir public:
96cdf0e10cSrcweir 				RscWriteRc( RSCBYTEORDER_TYPE nOrder = RSC_SYSTEMENDIAN );
97cdf0e10cSrcweir 				~RscWriteRc();
98cdf0e10cSrcweir 	sal_uInt32		IncSize( sal_uInt32 nSize );// gibt die vorherige Groesse
GetBuffer()99cdf0e10cSrcweir 	void *		GetBuffer()
100cdf0e10cSrcweir 				{
101cdf0e10cSrcweir 					return GetPointer( 0 );
102cdf0e10cSrcweir 				}
GetShort(sal_uInt32 nPos)103cdf0e10cSrcweir 	sal_uInt16	GetShort( sal_uInt32 nPos )
104cdf0e10cSrcweir 				{
105cdf0e10cSrcweir                     sal_uInt16 nVal = 0;
106cdf0e10cSrcweir                     char* pFrom = GetPointer(nPos);
107cdf0e10cSrcweir                     char* pTo = (char*)&nVal;
108cdf0e10cSrcweir                     *pTo++ = *pFrom++;
109cdf0e10cSrcweir                     *pTo++ = *pFrom++;
110cdf0e10cSrcweir 					return bSwap ? SWAPSHORT( nVal ) : nVal;
111cdf0e10cSrcweir 				}
GetLong(sal_uInt32 nPos)112cdf0e10cSrcweir 	sal_uInt32	GetLong( sal_uInt32 nPos )
113cdf0e10cSrcweir 				{
114cdf0e10cSrcweir                     sal_uInt32 nVal = 0;
115cdf0e10cSrcweir                     char* pFrom = GetPointer(nPos);
116cdf0e10cSrcweir                     char* pTo = (char*)&nVal;
117cdf0e10cSrcweir                     *pTo++ = *pFrom++;
118cdf0e10cSrcweir                     *pTo++ = *pFrom++;
119cdf0e10cSrcweir                     *pTo++ = *pFrom++;
120cdf0e10cSrcweir                     *pTo++ = *pFrom++;
121cdf0e10cSrcweir 					return bSwap ? SWAPLONG( nVal ) : nVal;
122cdf0e10cSrcweir 				}
GetUTF8(sal_uInt32 nPos)123cdf0e10cSrcweir 	char *		GetUTF8( sal_uInt32 nPos )
124cdf0e10cSrcweir 				{
125cdf0e10cSrcweir 					return GetPointer( nPos );
126cdf0e10cSrcweir 				}
127cdf0e10cSrcweir 
128cdf0e10cSrcweir 
GetByteOrder() const129cdf0e10cSrcweir 	RSCBYTEORDER_TYPE GetByteOrder() const { return nByteOrder; }
Size()130cdf0e10cSrcweir 	sal_uInt32		Size(){ return( nLen ); };
Put(sal_uInt64 lVal)131cdf0e10cSrcweir     void        Put( sal_uInt64 lVal )
132cdf0e10cSrcweir                 {
133cdf0e10cSrcweir                     union
134cdf0e10cSrcweir                     {
135cdf0e10cSrcweir                         sal_uInt64 lVal64;
136cdf0e10cSrcweir                         sal_uInt32 aVal32[2];
137cdf0e10cSrcweir                     };
138cdf0e10cSrcweir                     lVal64 = lVal;
139cdf0e10cSrcweir                     if( bSwap )
140cdf0e10cSrcweir                     {
141cdf0e10cSrcweir                         Put( aVal32[1] );
142cdf0e10cSrcweir                         Put( aVal32[0] );
143cdf0e10cSrcweir                     }
144cdf0e10cSrcweir                     else
145cdf0e10cSrcweir                     {
146cdf0e10cSrcweir                         Put( aVal32[0] );
147cdf0e10cSrcweir                         Put( aVal32[1] );
148cdf0e10cSrcweir                     }
149cdf0e10cSrcweir                 }
Put(sal_Int32 lVal)150cdf0e10cSrcweir 	void		Put( sal_Int32 lVal )
151cdf0e10cSrcweir 				{
152cdf0e10cSrcweir                     union
153cdf0e10cSrcweir                     {
154cdf0e10cSrcweir                         sal_uInt32 lVal32;
155cdf0e10cSrcweir                         sal_uInt16 aVal16[2];
156cdf0e10cSrcweir                     };
157cdf0e10cSrcweir                     lVal32 = lVal;
158cdf0e10cSrcweir 
159cdf0e10cSrcweir 					if( bSwap )
160cdf0e10cSrcweir 					{
161cdf0e10cSrcweir 						Put( aVal16[1] );
162cdf0e10cSrcweir 						Put( aVal16[0] );
163cdf0e10cSrcweir 					}
164cdf0e10cSrcweir 					else
165cdf0e10cSrcweir 					{
166cdf0e10cSrcweir 						Put( aVal16[0] );
167cdf0e10cSrcweir 						Put( aVal16[1] );
168cdf0e10cSrcweir 					}
169cdf0e10cSrcweir 				}
Put(sal_uInt32 nValue)170cdf0e10cSrcweir 	void		Put( sal_uInt32 nValue )
171cdf0e10cSrcweir 				{ Put( (sal_Int32)nValue ); }
172cdf0e10cSrcweir 	void		Put( sal_uInt16 nValue );
Put(sal_Int16 nValue)173cdf0e10cSrcweir 	void		Put( sal_Int16 nValue )
174cdf0e10cSrcweir 				{ Put( (sal_uInt16)nValue ); }
175cdf0e10cSrcweir 	void		PutUTF8( char * pData );
176cdf0e10cSrcweir 
PutAt(sal_uInt32 nPos,sal_Int32 lVal)177cdf0e10cSrcweir 	void		PutAt( sal_uInt32 nPos, sal_Int32 lVal )
178cdf0e10cSrcweir 				{
179cdf0e10cSrcweir                     union
180cdf0e10cSrcweir                     {
181cdf0e10cSrcweir                         sal_uInt32 lVal32;
182cdf0e10cSrcweir                         sal_uInt16 aVal16[2];
183cdf0e10cSrcweir                     };
184cdf0e10cSrcweir                     lVal32 = lVal;
185cdf0e10cSrcweir 
186cdf0e10cSrcweir 					if( bSwap )
187cdf0e10cSrcweir 					{
188cdf0e10cSrcweir 						PutAt( nPos, aVal16[1] );
189cdf0e10cSrcweir 						PutAt( nPos + 2, aVal16[0] );
190cdf0e10cSrcweir 					}
191cdf0e10cSrcweir 					else
192cdf0e10cSrcweir 					{
193cdf0e10cSrcweir 						PutAt( nPos, aVal16[0] );
194cdf0e10cSrcweir 						PutAt( nPos + 2, aVal16[1] );
195cdf0e10cSrcweir 					}
196cdf0e10cSrcweir 				}
PutAt(sal_uInt32 nPos,sal_uInt32 lVal)197cdf0e10cSrcweir     void        PutAt( sal_uInt32 nPos, sal_uInt32 lVal )
198cdf0e10cSrcweir                 {
199cdf0e10cSrcweir                     PutAt( nPos, (sal_Int32)lVal);
200cdf0e10cSrcweir                 }
PutAt(sal_uInt32 nPos,short nVal)201cdf0e10cSrcweir 	void		PutAt( sal_uInt32 nPos, short nVal )
202cdf0e10cSrcweir 				{
203cdf0e10cSrcweir 					PutAt( nPos, (sal_uInt16)nVal );
204cdf0e10cSrcweir 				}
PutAt(sal_uInt32 nPos,sal_uInt16 nVal)205cdf0e10cSrcweir 	void		PutAt( sal_uInt32 nPos, sal_uInt16 nVal )
206cdf0e10cSrcweir 				{
207cdf0e10cSrcweir                     if( bSwap )
208cdf0e10cSrcweir                         nVal = SWAPSHORT( nVal );
209cdf0e10cSrcweir                     char* pTo = GetPointer( nPos );
210cdf0e10cSrcweir                     char* pFrom = (char*)&nVal;
211cdf0e10cSrcweir                     *pTo++ = *pFrom++;
212cdf0e10cSrcweir                     *pTo++ = *pFrom++;
213cdf0e10cSrcweir 				}
214cdf0e10cSrcweir };
215cdf0e10cSrcweir 
216cdf0e10cSrcweir #endif // _RSCTOOLS_HXX
217