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