1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
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.
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).
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.
26 ************************************************************************/
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_rsc.hxx"
30 /****************** I N C L U D E S **************************************/
32 // C and C++ Includes.
38 #if defined ( OS2 ) && !defined ( GCC )
44 #include <tools/fsys.hxx>
48 #include <rsctools.hxx>
51 #include <rtl/alloc.h>
52 #include <rtl/memory.h>
56 /****************** C o d e **********************************************/
57 /*************************************************************************
61 |* Beschreibung Vergleicht zwei Strings Case-Unabhaengig bis zu
62 |* einer bestimmten Laenge
63 |* Ersterstellung MM 13.02.91
64 |* Letzte Aenderung MM 13.02.91
66 *************************************************************************/
67 int rsc_strnicmp( const char *string1
, const char *string2
, size_t count
)
71 for( i
= 0; ( i
< count
) && string1
[ i
] && string2
[ i
] ; i
++ )
73 if( tolower( string1
[ i
] ) < tolower( string2
[ i
] ) )
75 else if( tolower( string1
[ i
] ) > tolower( string2
[ i
] ) )
80 else if( tolower( string1
[ i
] ) < tolower( string2
[ i
] ) )
82 else if( tolower( string1
[ i
] ) > tolower( string2
[ i
] ) )
87 /*************************************************************************
91 |* Beschreibung Vergleicht zwei Strings Case-Unabhaengig
92 |* Ersterstellung MM 13.02.91
93 |* Letzte Aenderung MM 13.02.91
95 *************************************************************************/
96 int rsc_stricmp( const char *string1
, const char *string2
){
99 for( i
= 0; string1
[ i
] && string2
[ i
]; i
++ ){
100 if( tolower( string1
[ i
] ) < tolower( string2
[ i
] ) )
102 else if( tolower( string1
[ i
] ) > tolower( string2
[ i
] ) )
105 if( tolower( string1
[ i
] ) < tolower( string2
[ i
] ) )
107 else if( tolower( string1
[ i
] ) > tolower( string2
[ i
] ) )
112 char* rsc_strdup( const char* pStr
)
114 int nLen
= strlen( pStr
);
115 char* pBuffer
= (char*)rtl_allocateMemory( nLen
+1 );
116 rtl_copyMemory( pBuffer
, pStr
, nLen
+1 );
120 /*************************************************************************
124 |* Beschreibung Gibt einen String eines eindeutigen Dateinamens
125 |* zurueck. Der Speicher fuer den String wird mit
127 |* Ersterstellung MM 13.02.91
128 |* Letzte Aenderung MH 13.10.97
130 *************************************************************************/
131 ByteString
GetTmpFileName()
133 OUString aTmpURL
, aTmpFile
;
134 osl_createTempFile( NULL
, NULL
, &aTmpURL
.pData
);
135 osl_getSystemPathFromFileURL( aTmpURL
.pData
, &aTmpFile
.pData
);
136 return OUStringToOString( aTmpFile
, RTL_TEXTENCODING_MS_1252
);
139 /********************************************************************/
141 /* Function : Append( ) */
143 /* Parameters : psw - pointer to a preprocessor switch */
145 /* Description : appends text files */
146 /********************************************************************/
147 sal_Bool
Append( FILE * fDest
, ByteString aTmpFile
)
150 char szBuf
[ MAX_BUF
];
154 fSource
= fopen( aTmpFile
.GetBuffer(), "rb" );
155 if( !fDest
|| !fSource
){
162 nItems
= fread( szBuf
, sizeof( char ), MAX_BUF
, fSource
);
163 fwrite( szBuf
, sizeof( char ), nItems
, fDest
);
164 } while( MAX_BUF
== nItems
);
171 sal_Bool
Append( ByteString aOutputSrs
, ByteString aTmpFile
)
173 FILE * fDest
= fopen( aOutputSrs
.GetBuffer(), "ab" );
175 sal_Bool bRet
= Append( fDest
, aTmpFile
);
183 /*************************************************************************
187 |* Beschreibung Haengt Extension an, wenn keine da ist
188 |* Parameter: pInput, der Input-Dateiname.
189 |* pExt, die Extension des Ausgabenamens
190 |* Ersterstellung MM 13.02.91
191 |* Letzte Aenderung MM 28.06.91
193 *************************************************************************/
194 ByteString
InputFile ( const char * pInput
, const char * pExt
)
196 UniString
aUniInput( pInput
, RTL_TEXTENCODING_ASCII_US
);
197 DirEntry
aFileName( aUniInput
);
199 if ( 0 == aFileName
.GetExtension().Len() )
201 UniString
aExt( pExt
, RTL_TEXTENCODING_ASCII_US
);
202 aFileName
.SetExtension( aExt
);
205 return ByteString( aFileName
.GetFull(), RTL_TEXTENCODING_ASCII_US
);
208 /*************************************************************************
212 |* Beschreibung Ersetzt Extension durch eine andere
213 |* Parameter: input, der Input-Dateiname.
214 |* pExt, die Extension des Ausgabenamens
215 |* Ersterstellung MM 13.02.91
216 |* Letzte Aenderung MM 28.06.91
218 *************************************************************************/
219 ByteString
OutputFile ( ByteString aInput
, const char * pExt
)
221 UniString
aUniInput( aInput
, RTL_TEXTENCODING_ASCII_US
);
222 DirEntry
aFileName( aUniInput
);
224 UniString
aExt( pExt
, RTL_TEXTENCODING_ASCII_US
);
225 aFileName
.SetExtension( aExt
);
227 return ByteString( aFileName
.GetFull(), RTL_TEXTENCODING_ASCII_US
);
230 /*************************************************************************
234 |* Beschreibung Kommandozeile aufbereiten
235 |* Ersterstellung MM 05.09.91
236 |* Letzte Aenderung MM 05.09.91
238 *************************************************************************/
239 char * ResponseFile( RscPtrPtr
* ppCmd
, char ** ppArgv
, sal_uInt32 nArgc
)
243 char szBuffer
[4096]; // file buffer
245 bool bInQuotes
= false;
248 ppCmd
->Append( rsc_strdup( *ppArgv
) );
249 for( i
= 1; i
< nArgc
; i
++ )
251 if( '@' == **(ppArgv
+i
) ){ // wenn @, dann Response-Datei
252 if( NULL
== (fFile
= fopen( (*(ppArgv
+i
)) +1, "r" )) )
253 return( (*(ppArgv
+i
)) );
254 nItems
= fread( &szBuffer
[ 0 ], 1, sizeof( char ), fFile
);
257 if( !isspace( szBuffer
[ 0 ] ) )
260 * #i27914# double ticks '"' now have a duplicate function:
261 * 1. they define a string ( e.g. -DFOO="baz" )
262 * 2. a string can contain spaces, so -DFOO="baz zum" defines one
266 while( nItems
&& (!isspace( szBuffer
[ n
] ) || bInQuotes
) &&
267 n
+1 < sizeof( szBuffer
) )
270 nItems
= fread( &szBuffer
[ n
], 1,
271 sizeof( char ), fFile
);
272 if( szBuffer
[n
] == '"' )
273 bInQuotes
= !bInQuotes
;
275 szBuffer
[ n
] = '\0';
276 ppCmd
->Append( rsc_strdup( szBuffer
) );
278 nItems
= fread( &szBuffer
[ 0 ], 1, sizeof( char ), fFile
);
284 ppCmd
->Append( rsc_strdup( *(ppArgv
+i
) ) );
286 ppCmd
->Append( (void *)0 );
291 /*************** R s c P t r P t r **************************************/
292 /*************************************************************************
294 |* RscPtrPtr :: RscPtrPtr()
296 |* Beschreibung Eine Tabelle mit Zeigern
297 |* Ersterstellung MM 13.02.91
298 |* Letzte Aenderung MM 13.02.91
300 *************************************************************************/
301 RscPtrPtr :: RscPtrPtr(){
306 /*************************************************************************
308 |* RscPtrPtr :: ~RscPtrPtr()
310 |* Beschreibung Zerst�rt eine Tabelle mit Zeigern, die Zeiger werde
311 |* ebenfalls freigegebn
312 |* Ersterstellung MM 13.02.91
313 |* Letzte Aenderung MM 13.02.91
315 *************************************************************************/
316 RscPtrPtr :: ~RscPtrPtr(){
320 /*************************************************************************
322 |* RscPtrPtr :: Reset()
325 |* Ersterstellung MM 03.05.91
326 |* Letzte Aenderung MM 03.05.91
328 *************************************************************************/
329 void RscPtrPtr :: Reset(){
333 for( i
= 0; i
< nCount
; i
++ ){
335 rtl_freeMemory( pMem
[ i
] );
337 rtl_freeMemory( (void *)pMem
);
343 /*************************************************************************
345 |* RscPtrPtr :: Append()
347 |* Beschreibung Haengt einen Eintrag an.
348 |* Ersterstellung MM 13.02.91
349 |* Letzte Aenderung MM 13.02.91
351 *************************************************************************/
352 sal_uInt32
RscPtrPtr :: Append( void * pBuffer
){
354 pMem
= (void **)rtl_allocateMemory( (nCount
+1) * sizeof( void * ) );
356 pMem
= (void **)rtl_reallocateMemory( (void *)pMem
,
357 ((nCount
+1) * sizeof( void * )
359 pMem
[ nCount
] = pBuffer
;
363 /*************************************************************************
365 |* RscPtrPtr :: GetEntry()
367 |* Beschreibung Liefert einen Eintrag, NULL wenn nicht vorhanden.
368 |* Ersterstellung MM 13.02.91
369 |* Letzte Aenderung MM 13.02.91
371 *************************************************************************/
372 void * RscPtrPtr :: GetEntry( sal_uInt32 nEntry
){
373 if( nEntry
< nCount
)
374 return( pMem
[ nEntry
] );
378 /****************** R S C W R I T E R C **********************************/
379 /*************************************************************************
381 |* RscWriteRc :: RscWriteRc()
384 |* Ersterstellung MM 15.04.91
385 |* Letzte Aenderung MM 15.04.91
387 *************************************************************************/
388 RscWriteRc::RscWriteRc( RSCBYTEORDER_TYPE nOrder
)
391 RSCBYTEORDER_TYPE nMachineOrder
;
394 if( nOrder
!= RSC_SYSTEMENDIAN
)
396 if( (sal_uInt8
)*(sal_uInt8
*)&nSwapTest
)
397 nMachineOrder
= RSC_LITTLEENDIAN
;
399 nMachineOrder
= RSC_BIGENDIAN
;
400 bSwap
= nOrder
!= nMachineOrder
;
407 /*************************************************************************
409 |* RscWriteRc :: ~RscWriteRc()
412 |* Ersterstellung MM 15.04.91
413 |* Letzte Aenderung MM 15.04.91
415 *************************************************************************/
416 RscWriteRc :: ~RscWriteRc()
419 rtl_freeMemory( pMem
);
422 /*************************************************************************
424 |* RscWriteRc :: IncSize()
427 |* Ersterstellung MM 15.04.91
428 |* Letzte Aenderung MM 15.04.91
430 *************************************************************************/
431 sal_uInt32
RscWriteRc :: IncSize( sal_uInt32 nSize
)
435 pMem
= (char*)rtl_reallocateMemory( pMem
, nLen
);
436 return( nLen
- nSize
);
439 /*************************************************************************
441 |* RscWriteRc :: GetPointer()
444 |* Ersterstellung MM 15.04.91
445 |* Letzte Aenderung MM 15.04.91
447 *************************************************************************/
448 char * RscWriteRc :: GetPointer( sal_uInt32 nSize
)
451 pMem
= (char *)rtl_allocateMemory( nLen
);
452 return( pMem
+ nSize
);
456 /*************************************************************************
458 |* RscWriteRc :: Put()
461 |* Ersterstellung MM 15.04.91
462 |* Letzte Aenderung MM 15.04.91
464 *************************************************************************/
465 void RscWriteRc :: Put( sal_uInt16 nVal
)
469 nOldLen
= IncSize( sizeof( nVal
) );
470 PutAt( nOldLen
, nVal
);
473 void RscWriteRc :: PutUTF8( char * pStr
)
475 sal_uInt32 nStrLen
= 0;
477 nStrLen
= strlen( pStr
);
479 sal_uInt32 n
= nStrLen
+1;
484 sal_uInt32 nOldLen
= IncSize( n
);
485 rtl_copyMemory( GetPointer( nOldLen
), pStr
, nStrLen
);
487 pMem
[ nOldLen
+ nStrLen
] = '\0';