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: start.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"
38 #if defined (WNT) && defined (tcpp)
39 #define _spawnvp spawnvp
40 #define _P_WAIT P_WAIT
50 #if defined ( OS2 ) && !defined ( GCC )
53 #if !defined ( CSET ) && !defined ( OS2 )
58 #include <rsctools.hxx>
60 #include <tools/fsys.hxx>
62 /*************** C O D E ************************************************/
63 /****************************************************************/
65 /* Function : fuer Ansi kompatibilitaet */
67 /****************************************************************/
70 int spawnvp( int, const char * cmdname
, char *const* argv
){
77 if( execvp( cmdname
, argv
) == -1 )
82 if( -1 == wait( &rc
) )
85 return( WEXITSTATUS( rc
) );
89 /*************************************************************************
93 *************************************************************************/
94 static BOOL
CallPrePro( const ByteString
& rPrePro
,
95 const ByteString
& rInput
,
96 const ByteString
& rOutput
,
100 RscPtrPtr aNewCmdL
; // Kommandozeile
101 RscPtrPtr aRespCmdL
; // Kommandozeile
102 RscPtrPtr
* pCmdL
= &aNewCmdL
;
104 FILE* fRspFile
= NULL
;
105 ByteString aRspFileName
;
109 aRspFileName
= ::GetTmpFileName();
110 fRspFile
= fopen( aRspFileName
.GetBuffer(), "w" );
114 aNewCmdL
.Append( rsc_strdup( rPrePro
.GetBuffer() ) );
116 bool bVerbose
= false;
117 for( i
= 1; i
< int(pCmdLine
->GetCount() -1); i
++ )
119 if ( 0 == rsc_stricmp( (char *)pCmdLine
->GetEntry( i
), "-verbose" ) )
124 if ( !rsc_strnicmp( (char *)pCmdLine
->GetEntry( i
), "-u", 2 )
125 || !rsc_strnicmp( (char *)pCmdLine
->GetEntry( i
), "-i", 2 )
126 || !rsc_strnicmp( (char *)pCmdLine
->GetEntry( i
), "-d", 2 )
129 aNewCmdL
.Append( rsc_strdup( (char *)pCmdLine
->GetEntry( i
) ) );
133 aNewCmdL
.Append( rsc_strdup( rInput
.GetBuffer() ) );
134 aNewCmdL
.Append( rsc_strdup( rOutput
.GetBuffer() ) );
135 aNewCmdL
.Append( (void *)0 );
139 printf( "Preprocessor commandline: " );
140 for( i
= 0; i
< (int)(pCmdL
->GetCount() -1); i
++ )
143 printf( "%s", (const char *)pCmdL
->GetEntry( i
) );
150 aRespCmdL
.Append( rsc_strdup( rPrePro
.GetBuffer() ) );
151 ByteString
aTmpStr( '@' );
152 aTmpStr
+= aRspFileName
;
153 aRespCmdL
.Append( rsc_strdup( aTmpStr
.GetBuffer() ) );
154 aRespCmdL
.Append( (void *)0 );
157 for( i
= 0; i
< (int)(aNewCmdL
.GetCount() -1); i
++ )
160 fprintf( fRspFile
, "%s\n", (const char *)aNewCmdL
.GetEntry( i
) );
162 fprintf( fRspFile
, "%s ", (const char *)aNewCmdL
.GetEntry( i
) );
169 printf( "Preprocessor startline: " );
170 for( i
= 0; i
< (int)(pCmdL
->GetCount() -1); i
++ )
173 printf( "%s", (const char *)pCmdL
->GetEntry( i
) );
179 #if ((defined OS2 || defined WNT) && (defined TCPP || defined tcpp)) || defined UNX || defined OS2
180 nExit
= spawnvp( P_WAIT
, rPrePro
.GetBuffer(), (char* const*)pCmdL
->GetBlock() );
182 nExit
= spawnvp( P_WAIT
, (char*)rPrePro
.GetBuffer(), char **) (const char**)pCmdL
->GetBlock() );
184 nExit
= spawnvp( P_WAIT
, (char*)rPrePro
.GetBuffer(), (const char* const*)pCmdL
->GetBlock() );
186 nExit
= spawnvp( P_WAIT
, (char*)rPrePro
.GetBuffer(), (char**)pCmdL
->GetBlock() );
188 nExit
= spawnvp( P_WAIT
, (char*)rPrePro
.GetBuffer(), (const char**)pCmdL
->GetBlock() );
192 #if OSL_DEBUG_LEVEL > 5
193 fprintf( stderr
, "leaving response file %s\n", aRspFileName
.GetBuffer() );
195 unlink( aRspFileName
.GetBuffer() );
204 /*************************************************************************
208 *************************************************************************/
209 static BOOL
CallRsc2( ByteString aRsc2Name
,
210 RscStrList
* pInputList
,
212 RscPtrPtr
* pCmdLine
)
216 ByteString aRspFileName
; // Response-Datei
217 FILE * fRspFile
; // Response-Datei
219 aRspFileName
= ::GetTmpFileName();
220 fRspFile
= fopen( aRspFileName
.GetBuffer(), "w" );
222 RscVerbosity eVerbosity
= RscVerbosityNormal
;
225 for( i
= 1; i
< (int)(pCmdLine
->GetCount() -1); i
++ )
227 if ( !rsc_stricmp( (char *)pCmdLine
->GetEntry( i
), "-verbose" ) )
229 eVerbosity
= RscVerbosityVerbose
;
232 if ( !rsc_stricmp( (char *)pCmdLine
->GetEntry( i
), "-quiet" ) )
234 eVerbosity
= RscVerbositySilent
;
237 if( !rsc_strnicmp( (char *)pCmdLine
->GetEntry( i
), "-fp=", 4 )
238 || !rsc_strnicmp( (char *)pCmdLine
->GetEntry( i
), "-fo=", 4 )
239 || !rsc_strnicmp( (char *)pCmdLine
->GetEntry( i
), "-pp=", 4 )
240 || !rsc_strnicmp( (char *)pCmdLine
->GetEntry( i
), "-rsc2=", 6 )
241 || !rsc_strnicmp( (char *)pCmdLine
->GetEntry( i
), "-presponse", 9 )
242 || !rsc_strnicmp( (char *)pCmdLine
->GetEntry( i
), "-rc", 3 )
243 || !rsc_stricmp( (char *)pCmdLine
->GetEntry( i
), "-+" )
244 || !rsc_stricmp( (char *)pCmdLine
->GetEntry( i
), "-br" )
245 || !rsc_stricmp( (char *)pCmdLine
->GetEntry( i
), "-bz" )
246 || !rsc_stricmp( (char *)pCmdLine
->GetEntry( i
), "-r" )
247 // Am I the only one that thinks the following line inludes all the tests before?
248 || ( '-' != *(char *)pCmdLine
->GetEntry( i
) ) )
253 fprintf( fRspFile
, "%s\n",
255 fprintf( fRspFile
, "%s ",
257 (const char *)pCmdLine
->GetEntry( i
) );
261 fprintf( fRspFile
, "%s\n", aSrsName
.GetBuffer() );
263 fprintf( fRspFile
, "%s", aSrsName
.GetBuffer() );
266 pString
= pInputList
->First();
270 fprintf( fRspFile
, "%s\n", pString
->GetBuffer() );
272 fprintf( fRspFile
, " %s", pString
->GetBuffer() );
274 pString
= pInputList
->Next();
280 RscPtrPtr aNewCmdL
; // Kommandozeile
281 aNewCmdL
.Append( rsc_strdup( aRsc2Name
.GetBuffer() ) );
282 ByteString
aTmpStr( '@' );
283 aTmpStr
+= aRspFileName
;
284 aNewCmdL
.Append( rsc_strdup( aTmpStr
.GetBuffer() ) );
285 aNewCmdL
.Append( (void *)0 );
287 if ( eVerbosity
>= RscVerbosityVerbose
)
289 printf( "Rsc2 commandline: " );
290 printf( "%s", (const char *)aNewCmdL
.GetEntry( 0 ) );
292 printf( "%s", (const char *)aNewCmdL
.GetEntry( 1 ) );
296 #if ((defined OS2 || defined WNT) && (defined TCPP || defined tcpp)) || defined UNX || defined OS2
297 nExit
= spawnvp( P_WAIT
, aRsc2Name
.GetBuffer(), (char* const*)aNewCmdL
.GetBlock() );
299 nExit
= spawnvp( P_WAIT
, (char*)aRsc2Name
.GetBuffer(), (char **)(const char**)aNewCmdL
.GetBlock() );
301 nExit
= spawnvp( P_WAIT
, (char*)aRsc2Name
.GetBuffer(), (const char* const*)aNewCmdL
.GetBlock() );
303 nExit
= spawnvp( P_WAIT
, (char*)aRsc2Name
.GetBuffer(), (char**)aNewCmdL
.GetBlock() );
305 nExit
= spawnvp( P_WAIT
, (char*)aRsc2Name
.GetBuffer(), (const char**)aNewCmdL
.GetBlock() );
309 #if OSL_DEBUG_LEVEL > 5
310 fprintf( stderr
, "leaving response file %s\n", aRspFileName
.GetBuffer() );
312 unlink( aRspFileName
.GetBuffer() );
319 /*************************************************************************
324 |* Ersterstellung MM 05.09.91
325 |* Letzte Aenderung MM 05.09.91
327 *************************************************************************/
328 #if defined UNX || (defined OS2 && (defined CSET || defined GCC )) || defined WTC || defined MTW || defined ICC || defined(__MINGW32__)
329 int main ( int argc
, char ** argv
)
332 int cdecl main ( int argc
, char ** argv
)
337 BOOL bResFile
= TRUE
;
340 BOOL bResponse
= FALSE
;
341 ByteString
aSolarbin(getenv("SOLARBINDIR"));
342 ByteString
aDelim("/");
343 ByteString aPrePro
; //( aSolarbin + aDelim + ByteString("rscpp"));
344 ByteString aRsc2Name
; //( aSolarbin + aDelim + ByteString("rsc2"));
347 RscStrList aInputList
;
351 RscPtrPtr aCmdLine
; // Kommandozeile
357 aPrePro
+= ByteString("rscpp");
359 aRsc2Name
= aSolarbin
;
361 aRsc2Name
+= ByteString("rsc2");
363 pStr
= ::ResponseFile( &aCmdLine
, argv
, argc
);
366 printf( "Cannot open response file <%s>\n", pStr
);
370 ppStr
= (char **)aCmdLine
.GetBlock();
373 BOOL bSetSrs
= FALSE
;
374 while( ppStr
&& i
< (aCmdLine
.GetCount() -1) )
378 if( !rsc_stricmp( (*ppStr
) + 1, "p" )
379 || !rsc_stricmp( (*ppStr
) + 1, "l" ) )
380 { // kein Preprozessor
383 else if( !rsc_stricmp( (*ppStr
) + 1, "r" )
384 || !rsc_stricmp( (*ppStr
) + 1, "s" ) )
385 { // erzeugt kein .res-file
388 else if( !rsc_stricmp( (*ppStr
) + 1, "h" ) )
392 else if( !rsc_strnicmp( (*ppStr
) + 1, "presponse", 9 ) )
393 { // anderer Name fuer den Preprozessor
396 else if( !rsc_strnicmp( (*ppStr
) + 1, "pp=", 3 ) )
397 { // anderer Name fuer den Preprozessor
398 aPrePro
= (*ppStr
) + 4;
400 else if( !rsc_strnicmp( (*ppStr
) + 1, "rsc2=", 5 ) )
401 { // Accept alternate name for the rsc2 compiler
402 aRsc2Name
= (*ppStr
) + 6;
404 else if( !rsc_strnicmp( (*ppStr
) + 1, "fo=", 3 ) )
405 { // anderer Name fuer .res-file
406 aResName
= (*ppStr
) + 4;
408 else if( !rsc_strnicmp( (*ppStr
) + 1, "fp=", 3 ) )
409 { // anderer Name fuer .srs-file
417 aInputList
.Insert( new ByteString( *ppStr
), CONTAINER_APPEND
);
423 if( aInputList
.Count() )
425 /* build the output file names */
426 if( ! aResName
.Len() )
427 aResName
= OutputFile( *aInputList
.First(), "res" );
431 aSrsName
+= OutputFile( *aInputList
.First(), "srs" );
440 if( bPrePro
&& aInputList
.Count() )
444 pString
= aInputList
.First();
447 aTmpName
= ::GetTmpFileName();
448 if( !CallPrePro( aPrePro
, *pString
, aTmpName
, &aCmdLine
, bResponse
) )
450 printf( "Error starting preprocessor\n" );
454 aTmpList
.Insert( new ByteString( aTmpName
), CONTAINER_APPEND
);
455 pString
= aInputList
.Next();
461 if( !CallRsc2( aRsc2Name
, bPrePro
? &aTmpList
: &aInputList
,
462 aSrsName
, &aCmdLine
) )
466 printf( "Error starting rsc2 compiler\n" );
472 pString
= aTmpList
.First();
475 #if OSL_DEBUG_LEVEL > 5
476 fprintf( stderr
, "leaving temp file %s\n", pString
->GetBuffer() );
478 unlink( pString
->GetBuffer() );
480 pString
= aTmpList
.Next();
486 void RscExit( sal_uInt32 nExit
)
489 printf( "Program exit is %d\n", (int)nExit
);