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>
59 #include <tools/fsys.hxx>
61 /*************** C O D E ************************************************/
62 /****************************************************************/
64 /* Function : fuer Ansi kompatibilitaet */
66 /****************************************************************/
69 int spawnvp( int, const char * cmdname
, char *const* argv
){
76 if( execvp( cmdname
, argv
) == -1 )
81 if( -1 == wait( &rc
) )
84 return( WEXITSTATUS( rc
) );
88 /*************************************************************************
92 *************************************************************************/
93 static BOOL
CallPrePro( const ByteString
& rPrePro
,
94 const ByteString
& rInput
,
95 const ByteString
& rOutput
,
99 RscPtrPtr aNewCmdL
; // Kommandozeile
100 RscPtrPtr aRespCmdL
; // Kommandozeile
101 RscPtrPtr
* pCmdL
= &aNewCmdL
;
103 FILE* fRspFile
= NULL
;
104 ByteString aRspFileName
;
108 aRspFileName
= ::GetTmpFileName();
109 fRspFile
= fopen( aRspFileName
.GetBuffer(), "w" );
113 aNewCmdL
.Append( rsc_strdup( rPrePro
.GetBuffer() ) );
114 for( i
= 1; i
< int(pCmdLine
->GetCount() -1); i
++ ){
115 if( !rsc_strnicmp( (char *)pCmdLine
->GetEntry( i
), "-u", 2 )
116 || !rsc_strnicmp( (char *)pCmdLine
->GetEntry( i
), "-i", 2 )
117 || !rsc_strnicmp( (char *)pCmdLine
->GetEntry( i
), "-d", 2 ) )
119 aNewCmdL
.Append( rsc_strdup( (char *)pCmdLine
->GetEntry( i
) ) );
122 aNewCmdL
.Append( rsc_strdup( rInput
.GetBuffer() ) );
123 aNewCmdL
.Append( rsc_strdup( rOutput
.GetBuffer() ) );
124 aNewCmdL
.Append( (void *)0 );
126 printf( "Preprocessor commandline: " );
127 for( i
= 0; i
< (int)(pCmdL
->GetCount() -1); i
++ )
130 printf( "%s", (const char *)pCmdL
->GetEntry( i
) );
136 aRespCmdL
.Append( rsc_strdup( rPrePro
.GetBuffer() ) );
137 ByteString
aTmpStr( '@' );
138 aTmpStr
+= aRspFileName
;
139 aRespCmdL
.Append( rsc_strdup( aTmpStr
.GetBuffer() ) );
140 aRespCmdL
.Append( (void *)0 );
143 for( i
= 0; i
< (int)(aNewCmdL
.GetCount() -1); i
++ )
146 fprintf( fRspFile
, "%s\n", (const char *)aNewCmdL
.GetEntry( i
) );
148 fprintf( fRspFile
, "%s ", (const char *)aNewCmdL
.GetEntry( i
) );
153 printf( "Preprocessor startline: " );
154 for( i
= 0; i
< (int)(pCmdL
->GetCount() -1); i
++ )
157 printf( "%s", (const char *)pCmdL
->GetEntry( i
) );
162 #if ((defined OS2 || defined WNT) && (defined TCPP || defined tcpp)) || defined UNX || defined OS2
163 nExit
= spawnvp( P_WAIT
, rPrePro
.GetBuffer(), (char* const*)pCmdL
->GetBlock() );
165 nExit
= spawnvp( P_WAIT
, (char*)rPrePro
.GetBuffer(), char **) (const char**)pCmdL
->GetBlock() );
167 nExit
= spawnvp( P_WAIT
, (char*)rPrePro
.GetBuffer(), (const char* const*)pCmdL
->GetBlock() );
169 nExit
= spawnvp( P_WAIT
, (char*)rPrePro
.GetBuffer(), (char**)pCmdL
->GetBlock() );
171 nExit
= spawnvp( P_WAIT
, (char*)rPrePro
.GetBuffer(), (const char**)pCmdL
->GetBlock() );
175 #if OSL_DEBUG_LEVEL > 5
176 fprintf( stderr
, "leaving response file %s\n", aRspFileName
.GetBuffer() );
178 unlink( aRspFileName
.GetBuffer() );
187 /*************************************************************************
191 *************************************************************************/
192 static BOOL
CallRsc2( ByteString aRsc2Name
,
193 RscStrList
* pInputList
,
195 RscPtrPtr
* pCmdLine
)
197 RscPtrPtr aNewCmdL
; // Kommandozeile
200 ByteString aRspFileName
; // Response-Datei
201 FILE * fRspFile
; // Response-Datei
203 aRspFileName
= ::GetTmpFileName();
204 fRspFile
= fopen( aRspFileName
.GetBuffer(), "w" );
206 printf( "Rsc2 commandline: " );
207 aNewCmdL
.Append( rsc_strdup( aRsc2Name
.GetBuffer() ) );
208 printf( "%s", (const char *)aNewCmdL
.GetEntry( aNewCmdL
.GetCount() -1 ) );
210 ByteString
aTmpStr( '@' );
211 aTmpStr
+= aRspFileName
;
212 aNewCmdL
.Append( rsc_strdup( aTmpStr
.GetBuffer() ) );
213 printf( "%s", (const char *)aNewCmdL
.GetEntry( aNewCmdL
.GetCount() -1 ) );
214 aNewCmdL
.Append( (void *)0 );
219 for( i
= 1; i
< (int)(pCmdLine
->GetCount() -1); i
++ )
221 if( !rsc_strnicmp( (char *)pCmdLine
->GetEntry( i
), "-fp=", 4 )
222 || !rsc_strnicmp( (char *)pCmdLine
->GetEntry( i
), "-fo=", 4 )
223 || !rsc_strnicmp( (char *)pCmdLine
->GetEntry( i
), "-pp=", 4 )
224 || !rsc_strnicmp( (char *)pCmdLine
->GetEntry( i
), "-rsc2=", 6 )
225 || !rsc_strnicmp( (char *)pCmdLine
->GetEntry( i
), "-presponse", 9 )
226 || !rsc_strnicmp( (char *)pCmdLine
->GetEntry( i
), "-rc", 3 )
227 || !rsc_stricmp( (char *)pCmdLine
->GetEntry( i
), "-+" )
228 || !rsc_stricmp( (char *)pCmdLine
->GetEntry( i
), "-br" )
229 || !rsc_stricmp( (char *)pCmdLine
->GetEntry( i
), "-bz" )
230 || !rsc_stricmp( (char *)pCmdLine
->GetEntry( i
), "-r" )
231 // Am I the only one that thinks the following line inludes all the tests before?
232 || ( '-' != *(char *)pCmdLine
->GetEntry( i
) ) )
237 fprintf( fRspFile
, "%s\n",
239 fprintf( fRspFile
, "%s ",
241 (const char *)pCmdLine
->GetEntry( i
) );
245 fprintf( fRspFile
, "%s\n", aSrsName
.GetBuffer() );
247 fprintf( fRspFile
, "%s", aSrsName
.GetBuffer() );
250 pString
= pInputList
->First();
254 fprintf( fRspFile
, "%s\n", pString
->GetBuffer() );
256 fprintf( fRspFile
, " %s", pString
->GetBuffer() );
258 pString
= pInputList
->Next();
264 #if ((defined OS2 || defined WNT) && (defined TCPP || defined tcpp)) || defined UNX || defined OS2
265 nExit
= spawnvp( P_WAIT
, aRsc2Name
.GetBuffer(), (char* const*)aNewCmdL
.GetBlock() );
267 nExit
= spawnvp( P_WAIT
, (char*)aRsc2Name
.GetBuffer(), (char **)(const char**)aNewCmdL
.GetBlock() );
269 nExit
= spawnvp( P_WAIT
, (char*)aRsc2Name
.GetBuffer(), (const char* const*)aNewCmdL
.GetBlock() );
271 nExit
= spawnvp( P_WAIT
, (char*)aRsc2Name
.GetBuffer(), (char**)aNewCmdL
.GetBlock() );
273 nExit
= spawnvp( P_WAIT
, (char*)aRsc2Name
.GetBuffer(), (const char**)aNewCmdL
.GetBlock() );
277 #if OSL_DEBUG_LEVEL > 5
278 fprintf( stderr
, "leaving response file %s\n", aRspFileName
.GetBuffer() );
280 unlink( aRspFileName
.GetBuffer() );
287 /*************************************************************************
292 |* Ersterstellung MM 05.09.91
293 |* Letzte Aenderung MM 05.09.91
295 *************************************************************************/
296 #if defined UNX || (defined OS2 && (defined CSET || defined GCC )) || defined WTC || defined MTW || defined ICC || defined(__MINGW32__)
297 int main ( int argc
, char ** argv
)
300 int cdecl main ( int argc
, char ** argv
)
305 BOOL bResFile
= TRUE
;
308 BOOL bResponse
= FALSE
;
309 ByteString
aSolarbin(getenv("SOLARBINDIR"));
310 ByteString
aDelim("/");
311 ByteString aPrePro
; //( aSolarbin + aDelim + ByteString("rscpp"));
312 ByteString aRsc2Name
; //( aSolarbin + aDelim + ByteString("rsc2"));
315 RscStrList aInputList
;
319 RscPtrPtr aCmdLine
; // Kommandozeile
325 aPrePro
+= ByteString("rscpp");
327 aRsc2Name
= aSolarbin
;
329 aRsc2Name
+= ByteString("rsc2");
331 printf( "VCL Resource Compiler 3.0\n" );
333 pStr
= ::ResponseFile( &aCmdLine
, argv
, argc
);
336 printf( "Cannot open response file <%s>\n", pStr
);
340 ppStr
= (char **)aCmdLine
.GetBlock();
343 BOOL bSetSrs
= FALSE
;
344 while( ppStr
&& i
< (aCmdLine
.GetCount() -1) )
348 if( !rsc_stricmp( (*ppStr
) + 1, "p" )
349 || !rsc_stricmp( (*ppStr
) + 1, "l" ) )
350 { // kein Preprozessor
353 else if( !rsc_stricmp( (*ppStr
) + 1, "r" )
354 || !rsc_stricmp( (*ppStr
) + 1, "s" ) )
355 { // erzeugt kein .res-file
358 else if( !rsc_stricmp( (*ppStr
) + 1, "h" ) )
362 else if( !rsc_strnicmp( (*ppStr
) + 1, "presponse", 9 ) )
363 { // anderer Name fuer den Preprozessor
366 else if( !rsc_strnicmp( (*ppStr
) + 1, "pp=", 3 ) )
367 { // anderer Name fuer den Preprozessor
368 aPrePro
= (*ppStr
) + 4;
370 else if( !rsc_strnicmp( (*ppStr
) + 1, "rsc2=", 5 ) )
371 { // Accept alternate name for the rsc2 compiler
372 aRsc2Name
= (*ppStr
) + 6;
374 else if( !rsc_strnicmp( (*ppStr
) + 1, "fo=", 3 ) )
375 { // anderer Name fuer .res-file
376 aResName
= (*ppStr
) + 4;
378 else if( !rsc_strnicmp( (*ppStr
) + 1, "fp=", 3 ) )
379 { // anderer Name fuer .srs-file
387 aInputList
.Insert( new ByteString( *ppStr
), CONTAINER_APPEND
);
393 if( aInputList
.Count() )
395 /* build the output file names */
396 if( ! aResName
.Len() )
397 aResName
= OutputFile( *aInputList
.First(), "res" );
401 aSrsName
+= OutputFile( *aInputList
.First(), "srs" );
410 if( bPrePro
&& aInputList
.Count() )
414 pString
= aInputList
.First();
417 aTmpName
= ::GetTmpFileName();
418 if( !CallPrePro( aPrePro
, *pString
, aTmpName
, &aCmdLine
, bResponse
) )
420 printf( "Error starting preprocessor\n" );
424 aTmpList
.Insert( new ByteString( aTmpName
), CONTAINER_APPEND
);
425 pString
= aInputList
.Next();
431 if( !CallRsc2( aRsc2Name
, bPrePro
? &aTmpList
: &aInputList
,
432 aSrsName
, &aCmdLine
) )
436 printf( "Error starting rsc2 compiler\n" );
442 pString
= aTmpList
.First();
445 #if OSL_DEBUG_LEVEL > 5
446 fprintf( stderr
, "leaving temp file %s\n", pString
->GetBuffer() );
448 unlink( pString
->GetBuffer() );
450 pString
= aTmpList
.Next();
456 void RscExit( sal_uInt32 nExit
)
459 printf( "Program exit is %d\n", (int)nExit
);