xref: /aoo41x/main/rsc/inc/rsctools.hxx (revision cdf0e10c)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir struct RSHEADER_TYPE;
28*cdf0e10cSrcweir class  RscPtrPtr;
29*cdf0e10cSrcweir 
30*cdf0e10cSrcweir #ifndef _RSCTOOLS_HXX
31*cdf0e10cSrcweir #define _RSCTOOLS_HXX
32*cdf0e10cSrcweir 
33*cdf0e10cSrcweir #ifdef UNX
34*cdf0e10cSrcweir #include <stdlib.h>
35*cdf0e10cSrcweir #endif
36*cdf0e10cSrcweir #include <stdio.h>
37*cdf0e10cSrcweir #include <tools/string.hxx>
38*cdf0e10cSrcweir #include <tools/list.hxx>
39*cdf0e10cSrcweir 
40*cdf0e10cSrcweir /******************* T y p e s *******************************************/
41*cdf0e10cSrcweir // Zeichensatz
42*cdf0e10cSrcweir enum COMPARE { LESS = -1, EQUAL = 0, GREATER = 1 };
43*cdf0e10cSrcweir 
44*cdf0e10cSrcweir enum RSCBYTEORDER_TYPE { RSC_BIGENDIAN, RSC_LITTLEENDIAN, RSC_SYSTEMENDIAN };
45*cdf0e10cSrcweir 
46*cdf0e10cSrcweir /******************* M A K R O S *****************************************/
47*cdf0e10cSrcweir #define ALIGNED_SIZE( nSize )								\
48*cdf0e10cSrcweir 			(nSize + sizeof( void * ) -1) / sizeof( void * ) * sizeof( void * )
49*cdf0e10cSrcweir /******************* F u n c t i o n   F o r w a r d s *******************/
50*cdf0e10cSrcweir ByteString GetTmpFileName();
51*cdf0e10cSrcweir sal_Bool Append( ByteString aDestFile, ByteString aSourceFile );
52*cdf0e10cSrcweir sal_Bool Append( FILE * fDest, ByteString aSourceFile );
53*cdf0e10cSrcweir ByteString InputFile ( const char * pInput, const char * pExt );
54*cdf0e10cSrcweir ByteString OutputFile( ByteString aInput, const char * ext );
55*cdf0e10cSrcweir char * ResponseFile( RscPtrPtr * ppCmd, char ** ppArgv,
56*cdf0e10cSrcweir 					 sal_uInt32 nArgc );
57*cdf0e10cSrcweir void RscExit( sal_uInt32 nExit );
58*cdf0e10cSrcweir 
59*cdf0e10cSrcweir /********* A n s i - F u n c t i o n   F o r w a r d s *******************/
60*cdf0e10cSrcweir int rsc_strnicmp( const char *string1, const char *string2, size_t count );
61*cdf0e10cSrcweir int rsc_stricmp( const char *string1, const char *string2 );
62*cdf0e10cSrcweir char* rsc_strdup( const char* );
63*cdf0e10cSrcweir 
64*cdf0e10cSrcweir /****************** C L A S S E S ****************************************/
65*cdf0e10cSrcweir DECLARE_LIST( RscStrList, ByteString * )
66*cdf0e10cSrcweir /*********** R s c C h a r ***********************************************/
67*cdf0e10cSrcweir class RscChar
68*cdf0e10cSrcweir {
69*cdf0e10cSrcweir public:
70*cdf0e10cSrcweir 	static char * MakeUTF8( char * pStr, sal_uInt16 nTextEncoding );
71*cdf0e10cSrcweir };
72*cdf0e10cSrcweir 
73*cdf0e10cSrcweir /****************** R s c P t r P t r ************************************/
74*cdf0e10cSrcweir class RscPtrPtr
75*cdf0e10cSrcweir {
76*cdf0e10cSrcweir 	sal_uInt32	nCount;
77*cdf0e10cSrcweir 	void ** 		pMem;
78*cdf0e10cSrcweir public:
79*cdf0e10cSrcweir 					RscPtrPtr();
80*cdf0e10cSrcweir 					~RscPtrPtr();
81*cdf0e10cSrcweir 	void			Reset();
82*cdf0e10cSrcweir 	sal_uInt32	Append( void * );
83*cdf0e10cSrcweir 	sal_uInt32	Append( char * pStr ){
84*cdf0e10cSrcweir 						return( Append( (void *)pStr ) );
85*cdf0e10cSrcweir 					};
86*cdf0e10cSrcweir 	sal_uInt32	GetCount(){ return( nCount ); };
87*cdf0e10cSrcweir 	void *			GetEntry( sal_uInt32 nEle );
88*cdf0e10cSrcweir 	void ** 		GetBlock(){ return( pMem ); };
89*cdf0e10cSrcweir };
90*cdf0e10cSrcweir 
91*cdf0e10cSrcweir /****************** R s c W r i t e R c **********************************/
92*cdf0e10cSrcweir class RscWriteRc
93*cdf0e10cSrcweir {
94*cdf0e10cSrcweir 	sal_uInt32				nLen;
95*cdf0e10cSrcweir 	sal_Bool				bSwap;
96*cdf0e10cSrcweir 	RSCBYTEORDER_TYPE	nByteOrder;
97*cdf0e10cSrcweir 	char *				pMem;
98*cdf0e10cSrcweir 	char *				GetPointer( sal_uInt32 nSize );
99*cdf0e10cSrcweir public:
100*cdf0e10cSrcweir 				RscWriteRc( RSCBYTEORDER_TYPE nOrder = RSC_SYSTEMENDIAN );
101*cdf0e10cSrcweir 				~RscWriteRc();
102*cdf0e10cSrcweir 	sal_uInt32		IncSize( sal_uInt32 nSize );// gibt die vorherige Groesse
103*cdf0e10cSrcweir 	void *		GetBuffer()
104*cdf0e10cSrcweir 				{
105*cdf0e10cSrcweir 					return GetPointer( 0 );
106*cdf0e10cSrcweir 				}
107*cdf0e10cSrcweir 	sal_uInt16	GetShort( sal_uInt32 nPos )
108*cdf0e10cSrcweir 				{
109*cdf0e10cSrcweir                     sal_uInt16 nVal = 0;
110*cdf0e10cSrcweir                     char* pFrom = GetPointer(nPos);
111*cdf0e10cSrcweir                     char* pTo = (char*)&nVal;
112*cdf0e10cSrcweir                     *pTo++ = *pFrom++;
113*cdf0e10cSrcweir                     *pTo++ = *pFrom++;
114*cdf0e10cSrcweir 					return bSwap ? SWAPSHORT( nVal ) : nVal;
115*cdf0e10cSrcweir 				}
116*cdf0e10cSrcweir 	sal_uInt32	GetLong( sal_uInt32 nPos )
117*cdf0e10cSrcweir 				{
118*cdf0e10cSrcweir                     sal_uInt32 nVal = 0;
119*cdf0e10cSrcweir                     char* pFrom = GetPointer(nPos);
120*cdf0e10cSrcweir                     char* pTo = (char*)&nVal;
121*cdf0e10cSrcweir                     *pTo++ = *pFrom++;
122*cdf0e10cSrcweir                     *pTo++ = *pFrom++;
123*cdf0e10cSrcweir                     *pTo++ = *pFrom++;
124*cdf0e10cSrcweir                     *pTo++ = *pFrom++;
125*cdf0e10cSrcweir 					return bSwap ? SWAPLONG( nVal ) : nVal;
126*cdf0e10cSrcweir 				}
127*cdf0e10cSrcweir 	char *		GetUTF8( sal_uInt32 nPos )
128*cdf0e10cSrcweir 				{
129*cdf0e10cSrcweir 					return GetPointer( nPos );
130*cdf0e10cSrcweir 				}
131*cdf0e10cSrcweir 
132*cdf0e10cSrcweir 
133*cdf0e10cSrcweir 	RSCBYTEORDER_TYPE GetByteOrder() const { return nByteOrder; }
134*cdf0e10cSrcweir 	sal_uInt32		Size(){ return( nLen ); };
135*cdf0e10cSrcweir     void        Put( sal_uInt64 lVal )
136*cdf0e10cSrcweir                 {
137*cdf0e10cSrcweir                     union
138*cdf0e10cSrcweir                     {
139*cdf0e10cSrcweir                         sal_uInt64 lVal64;
140*cdf0e10cSrcweir                         sal_uInt32 aVal32[2];
141*cdf0e10cSrcweir                     };
142*cdf0e10cSrcweir                     lVal64 = lVal;
143*cdf0e10cSrcweir                     if( bSwap )
144*cdf0e10cSrcweir                     {
145*cdf0e10cSrcweir                         Put( aVal32[1] );
146*cdf0e10cSrcweir                         Put( aVal32[0] );
147*cdf0e10cSrcweir                     }
148*cdf0e10cSrcweir                     else
149*cdf0e10cSrcweir                     {
150*cdf0e10cSrcweir                         Put( aVal32[0] );
151*cdf0e10cSrcweir                         Put( aVal32[1] );
152*cdf0e10cSrcweir                     }
153*cdf0e10cSrcweir                 }
154*cdf0e10cSrcweir 	void		Put( sal_Int32 lVal )
155*cdf0e10cSrcweir 				{
156*cdf0e10cSrcweir                     union
157*cdf0e10cSrcweir                     {
158*cdf0e10cSrcweir                         sal_uInt32 lVal32;
159*cdf0e10cSrcweir                         sal_uInt16 aVal16[2];
160*cdf0e10cSrcweir                     };
161*cdf0e10cSrcweir                     lVal32 = lVal;
162*cdf0e10cSrcweir 
163*cdf0e10cSrcweir 					if( bSwap )
164*cdf0e10cSrcweir 					{
165*cdf0e10cSrcweir 						Put( aVal16[1] );
166*cdf0e10cSrcweir 						Put( aVal16[0] );
167*cdf0e10cSrcweir 					}
168*cdf0e10cSrcweir 					else
169*cdf0e10cSrcweir 					{
170*cdf0e10cSrcweir 						Put( aVal16[0] );
171*cdf0e10cSrcweir 						Put( aVal16[1] );
172*cdf0e10cSrcweir 					}
173*cdf0e10cSrcweir 				}
174*cdf0e10cSrcweir 	void		Put( sal_uInt32 nValue )
175*cdf0e10cSrcweir 				{ Put( (sal_Int32)nValue ); }
176*cdf0e10cSrcweir 	void		Put( sal_uInt16 nValue );
177*cdf0e10cSrcweir 	void		Put( sal_Int16 nValue )
178*cdf0e10cSrcweir 				{ Put( (sal_uInt16)nValue ); }
179*cdf0e10cSrcweir 	void		PutUTF8( char * pData );
180*cdf0e10cSrcweir 
181*cdf0e10cSrcweir 	void		PutAt( sal_uInt32 nPos, sal_Int32 lVal )
182*cdf0e10cSrcweir 				{
183*cdf0e10cSrcweir                     union
184*cdf0e10cSrcweir                     {
185*cdf0e10cSrcweir                         sal_uInt32 lVal32;
186*cdf0e10cSrcweir                         sal_uInt16 aVal16[2];
187*cdf0e10cSrcweir                     };
188*cdf0e10cSrcweir                     lVal32 = lVal;
189*cdf0e10cSrcweir 
190*cdf0e10cSrcweir 					if( bSwap )
191*cdf0e10cSrcweir 					{
192*cdf0e10cSrcweir 						PutAt( nPos, aVal16[1] );
193*cdf0e10cSrcweir 						PutAt( nPos + 2, aVal16[0] );
194*cdf0e10cSrcweir 					}
195*cdf0e10cSrcweir 					else
196*cdf0e10cSrcweir 					{
197*cdf0e10cSrcweir 						PutAt( nPos, aVal16[0] );
198*cdf0e10cSrcweir 						PutAt( nPos + 2, aVal16[1] );
199*cdf0e10cSrcweir 					}
200*cdf0e10cSrcweir 				}
201*cdf0e10cSrcweir     void        PutAt( sal_uInt32 nPos, sal_uInt32 lVal )
202*cdf0e10cSrcweir                 {
203*cdf0e10cSrcweir                     PutAt( nPos, (sal_Int32)lVal);
204*cdf0e10cSrcweir                 }
205*cdf0e10cSrcweir 	void		PutAt( sal_uInt32 nPos, short nVal )
206*cdf0e10cSrcweir 				{
207*cdf0e10cSrcweir 					PutAt( nPos, (sal_uInt16)nVal );
208*cdf0e10cSrcweir 				}
209*cdf0e10cSrcweir 	void		PutAt( sal_uInt32 nPos, sal_uInt16 nVal )
210*cdf0e10cSrcweir 				{
211*cdf0e10cSrcweir                     if( bSwap )
212*cdf0e10cSrcweir                         nVal = SWAPSHORT( nVal );
213*cdf0e10cSrcweir                     char* pTo = GetPointer( nPos );
214*cdf0e10cSrcweir                     char* pFrom = (char*)&nVal;
215*cdf0e10cSrcweir                     *pTo++ = *pFrom++;
216*cdf0e10cSrcweir                     *pTo++ = *pFrom++;
217*cdf0e10cSrcweir 				}
218*cdf0e10cSrcweir };
219*cdf0e10cSrcweir 
220*cdf0e10cSrcweir #endif // _RSCTOOLS_HXX
221