1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: rsctools.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_rsc.hxx"
33 /****************** I N C L U D E S **************************************/
35 // C and C++ Includes.
38 #if defined ( DOS ) || defined ( WIN ) || defined (WNT )
41 #if defined ( OS2 ) && !defined ( GCC )
47 #include <tools/fsys.hxx>
51 #include <rsctools.hxx>
54 #include <rtl/alloc.h>
55 #include <rtl/memory.h>
63 /****************** C o d e **********************************************/
64 /*************************************************************************
68 |* Beschreibung Vergleicht zwei Strings Case-Unabhaengig bis zu
69 |* einer bestimmten Laenge
70 |* Ersterstellung MM 13.02.91
71 |* Letzte Aenderung MM 13.02.91
73 *************************************************************************/
74 int rsc_strnicmp( const char *string1
, const char *string2
, size_t count
)
78 for( i
= 0; ( i
< count
) && string1
[ i
] && string2
[ i
] ; i
++ )
80 if( tolower( string1
[ i
] ) < tolower( string2
[ i
] ) )
82 else if( tolower( string1
[ i
] ) > tolower( string2
[ i
] ) )
87 else if( tolower( string1
[ i
] ) < tolower( string2
[ i
] ) )
89 else if( tolower( string1
[ i
] ) > tolower( string2
[ i
] ) )
94 /*************************************************************************
98 |* Beschreibung Vergleicht zwei Strings Case-Unabhaengig
99 |* Ersterstellung MM 13.02.91
100 |* Letzte Aenderung MM 13.02.91
102 *************************************************************************/
103 int rsc_stricmp( const char *string1
, const char *string2
){
106 for( i
= 0; string1
[ i
] && string2
[ i
]; i
++ ){
107 if( tolower( string1
[ i
] ) < tolower( string2
[ i
] ) )
109 else if( tolower( string1
[ i
] ) > tolower( string2
[ i
] ) )
112 if( tolower( string1
[ i
] ) < tolower( string2
[ i
] ) )
114 else if( tolower( string1
[ i
] ) > tolower( string2
[ i
] ) )
119 char* rsc_strdup( const char* pStr
)
121 int nLen
= strlen( pStr
);
122 char* pBuffer
= (char*)rtl_allocateMemory( nLen
+1 );
123 rtl_copyMemory( pBuffer
, pStr
, nLen
+1 );
127 /*************************************************************************
131 |* Beschreibung Gibt einen String eines eindeutigen Dateinamens
132 |* zurueck. Der Speicher fuer den String wird mit
134 |* Ersterstellung MM 13.02.91
135 |* Letzte Aenderung MH 13.10.97
137 *************************************************************************/
138 ByteString
GetTmpFileName()
140 OUString aTmpURL
, aTmpFile
;
141 osl_createTempFile( NULL
, NULL
, &aTmpURL
.pData
);
142 osl_getSystemPathFromFileURL( aTmpURL
.pData
, &aTmpFile
.pData
);
143 return OUStringToOString( aTmpFile
, RTL_TEXTENCODING_MS_1252
);
146 /********************************************************************/
148 /* Function : Append( ) */
150 /* Parameters : psw - pointer to a preprocessor switch */
152 /* Description : appends text files */
153 /********************************************************************/
154 BOOL
Append( FILE * fDest
, ByteString aTmpFile
)
157 char szBuf
[ MAX_BUF
];
161 fSource
= fopen( aTmpFile
.GetBuffer(), "rb" );
162 if( !fDest
|| !fSource
){
169 nItems
= fread( szBuf
, sizeof( char ), MAX_BUF
, fSource
);
170 fwrite( szBuf
, sizeof( char ), nItems
, fDest
);
171 } while( MAX_BUF
== nItems
);
178 BOOL
Append( ByteString aOutputSrs
, ByteString aTmpFile
)
180 FILE * fDest
= fopen( aOutputSrs
.GetBuffer(), "ab" );
182 BOOL bRet
= Append( fDest
, aTmpFile
);
190 /*************************************************************************
194 |* Beschreibung Haengt Extension an, wenn keine da ist
195 |* Parameter: pInput, der Input-Dateiname.
196 |* pExt, die Extension des Ausgabenamens
197 |* Ersterstellung MM 13.02.91
198 |* Letzte Aenderung MM 28.06.91
200 *************************************************************************/
201 ByteString
InputFile ( const char * pInput
, const char * pExt
)
203 UniString
aUniInput( pInput
, RTL_TEXTENCODING_ASCII_US
);
204 DirEntry
aFileName( aUniInput
);
206 if ( 0 == aFileName
.GetExtension().Len() )
208 UniString
aExt( pExt
, RTL_TEXTENCODING_ASCII_US
);
209 aFileName
.SetExtension( aExt
);
212 return ByteString( aFileName
.GetFull(), RTL_TEXTENCODING_ASCII_US
);
215 /*************************************************************************
219 |* Beschreibung Ersetzt Extension durch eine andere
220 |* Parameter: input, der Input-Dateiname.
221 |* pExt, die Extension des Ausgabenamens
222 |* Ersterstellung MM 13.02.91
223 |* Letzte Aenderung MM 28.06.91
225 *************************************************************************/
226 ByteString
OutputFile ( ByteString aInput
, const char * pExt
)
228 UniString
aUniInput( aInput
, RTL_TEXTENCODING_ASCII_US
);
229 DirEntry
aFileName( aUniInput
);
231 UniString
aExt( pExt
, RTL_TEXTENCODING_ASCII_US
);
232 aFileName
.SetExtension( aExt
);
234 return ByteString( aFileName
.GetFull(), RTL_TEXTENCODING_ASCII_US
);
237 /*************************************************************************
241 |* Beschreibung Kommandozeile aufbereiten
242 |* Ersterstellung MM 05.09.91
243 |* Letzte Aenderung MM 05.09.91
245 *************************************************************************/
246 char * ResponseFile( RscPtrPtr
* ppCmd
, char ** ppArgv
, sal_uInt32 nArgc
)
250 char szBuffer
[4096]; // file buffer
252 bool bInQuotes
= false;
255 ppCmd
->Append( rsc_strdup( *ppArgv
) );
256 for( i
= 1; i
< nArgc
; i
++ )
258 if( '@' == **(ppArgv
+i
) ){ // wenn @, dann Response-Datei
259 if( NULL
== (fFile
= fopen( (*(ppArgv
+i
)) +1, "r" )) )
260 return( (*(ppArgv
+i
)) );
261 nItems
= fread( &szBuffer
[ 0 ], 1, sizeof( char ), fFile
);
264 if( !isspace( szBuffer
[ 0 ] ) )
267 * #i27914# double ticks '"' now have a duplicate function:
268 * 1. they define a string ( e.g. -DFOO="baz" )
269 * 2. a string can contain spaces, so -DFOO="baz zum" defines one
273 while( nItems
&& (!isspace( szBuffer
[ n
] ) || bInQuotes
) &&
274 n
+1 < sizeof( szBuffer
) )
277 nItems
= fread( &szBuffer
[ n
], 1,
278 sizeof( char ), fFile
);
279 if( szBuffer
[n
] == '"' )
280 bInQuotes
= !bInQuotes
;
282 szBuffer
[ n
] = '\0';
283 ppCmd
->Append( rsc_strdup( szBuffer
) );
285 nItems
= fread( &szBuffer
[ 0 ], 1, sizeof( char ), fFile
);
291 ppCmd
->Append( rsc_strdup( *(ppArgv
+i
) ) );
293 ppCmd
->Append( (void *)0 );
298 /*************** R s c P t r P t r **************************************/
299 /*************************************************************************
301 |* RscPtrPtr :: RscPtrPtr()
303 |* Beschreibung Eine Tabelle mit Zeigern
304 |* Ersterstellung MM 13.02.91
305 |* Letzte Aenderung MM 13.02.91
307 *************************************************************************/
308 RscPtrPtr :: RscPtrPtr(){
313 /*************************************************************************
315 |* RscPtrPtr :: ~RscPtrPtr()
317 |* Beschreibung Zerst�rt eine Tabelle mit Zeigern, die Zeiger werde
318 |* ebenfalls freigegebn
319 |* Ersterstellung MM 13.02.91
320 |* Letzte Aenderung MM 13.02.91
322 *************************************************************************/
323 RscPtrPtr :: ~RscPtrPtr(){
327 /*************************************************************************
329 |* RscPtrPtr :: Reset()
332 |* Ersterstellung MM 03.05.91
333 |* Letzte Aenderung MM 03.05.91
335 *************************************************************************/
336 void RscPtrPtr :: Reset(){
340 for( i
= 0; i
< nCount
; i
++ ){
342 rtl_freeMemory( pMem
[ i
] );
344 rtl_freeMemory( (void *)pMem
);
350 /*************************************************************************
352 |* RscPtrPtr :: Append()
354 |* Beschreibung Haengt einen Eintrag an.
355 |* Ersterstellung MM 13.02.91
356 |* Letzte Aenderung MM 13.02.91
358 *************************************************************************/
359 sal_uInt32
RscPtrPtr :: Append( void * pBuffer
){
361 pMem
= (void **)rtl_allocateMemory( (nCount
+1) * sizeof( void * ) );
363 pMem
= (void **)rtl_reallocateMemory( (void *)pMem
,
364 ((nCount
+1) * sizeof( void * )
366 pMem
[ nCount
] = pBuffer
;
370 /*************************************************************************
372 |* RscPtrPtr :: GetEntry()
374 |* Beschreibung Liefert einen Eintrag, NULL wenn nicht vorhanden.
375 |* Ersterstellung MM 13.02.91
376 |* Letzte Aenderung MM 13.02.91
378 *************************************************************************/
379 void * RscPtrPtr :: GetEntry( sal_uInt32 nEntry
){
380 if( nEntry
< nCount
)
381 return( pMem
[ nEntry
] );
385 /****************** R S C W R I T E R C **********************************/
386 /*************************************************************************
388 |* RscWriteRc :: RscWriteRc()
391 |* Ersterstellung MM 15.04.91
392 |* Letzte Aenderung MM 15.04.91
394 *************************************************************************/
395 RscWriteRc::RscWriteRc( RSCBYTEORDER_TYPE nOrder
)
398 RSCBYTEORDER_TYPE nMachineOrder
;
401 if( nOrder
!= RSC_SYSTEMENDIAN
)
403 if( (BYTE
)*(BYTE
*)&nSwapTest
)
404 nMachineOrder
= RSC_LITTLEENDIAN
;
406 nMachineOrder
= RSC_BIGENDIAN
;
407 bSwap
= nOrder
!= nMachineOrder
;
414 /*************************************************************************
416 |* RscWriteRc :: ~RscWriteRc()
419 |* Ersterstellung MM 15.04.91
420 |* Letzte Aenderung MM 15.04.91
422 *************************************************************************/
423 RscWriteRc :: ~RscWriteRc()
426 rtl_freeMemory( pMem
);
429 /*************************************************************************
431 |* RscWriteRc :: IncSize()
434 |* Ersterstellung MM 15.04.91
435 |* Letzte Aenderung MM 15.04.91
437 *************************************************************************/
438 sal_uInt32
RscWriteRc :: IncSize( sal_uInt32 nSize
)
442 pMem
= (char*)rtl_reallocateMemory( pMem
, nLen
);
443 return( nLen
- nSize
);
446 /*************************************************************************
448 |* RscWriteRc :: GetPointer()
451 |* Ersterstellung MM 15.04.91
452 |* Letzte Aenderung MM 15.04.91
454 *************************************************************************/
455 char * RscWriteRc :: GetPointer( sal_uInt32 nSize
)
458 pMem
= (char *)rtl_allocateMemory( nLen
);
459 return( pMem
+ nSize
);
463 /*************************************************************************
465 |* RscWriteRc :: Put()
468 |* Ersterstellung MM 15.04.91
469 |* Letzte Aenderung MM 15.04.91
471 *************************************************************************/
472 void RscWriteRc :: Put( sal_uInt16 nVal
)
476 nOldLen
= IncSize( sizeof( nVal
) );
477 PutAt( nOldLen
, nVal
);
480 void RscWriteRc :: PutUTF8( char * pStr
)
482 sal_uInt32 nStrLen
= 0;
484 nStrLen
= strlen( pStr
);
486 sal_uInt32 n
= nStrLen
+1;
491 sal_uInt32 nOldLen
= IncSize( n
);
492 rtl_copyMemory( GetPointer( nOldLen
), pStr
, nStrLen
);
494 pMem
[ nOldLen
+ nStrLen
] = '\0';