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