Update ooo320-m1
[ooovba.git] / rsc / source / prj / start.cxx
blob4b8dcc3ac6f823811452639ecbf49257555917f3
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: start.cxx,v $
10 * $Revision: 1.13 $
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"
34 #include <stdlib.h>
35 #include <stdio.h>
36 #include <fcntl.h>
37 #include <string.h>
38 #if defined (WNT) && defined (tcpp)
39 #define _spawnvp spawnvp
40 #define _P_WAIT P_WAIT
41 #endif
43 #ifdef UNX
44 #include <unistd.h>
45 #include <sys/wait.h>
46 #else // UNX
48 #include <io.h>
49 #include <process.h>
50 #if defined ( OS2 ) && !defined ( GCC )
51 #include <direct.h>
52 #endif
53 #if !defined ( CSET ) && !defined ( OS2 )
54 #include <dos.h>
55 #endif
57 #endif // UNX
58 #include <rsctools.hxx>
59 #include <rscerror.h>
60 #include <tools/fsys.hxx>
62 /*************** C O D E ************************************************/
63 /****************************************************************/
64 /* */
65 /* Function : fuer Ansi kompatibilitaet */
66 /* */
67 /****************************************************************/
68 #ifdef UNX
69 #define P_WAIT 0
70 int spawnvp( int, const char * cmdname, char *const* argv ){
71 int rc(0);
73 switch( fork() ){
74 case -1:
75 return( -1 );
76 case 0:
77 if( execvp( cmdname, argv ) == -1 )
78 // an error occurs
79 return( -1 );
80 break;
81 default:
82 if( -1 == wait( &rc ) )
83 return( -1 );
85 return( WEXITSTATUS( rc ) );
87 #endif
89 /*************************************************************************
90 |* CallPrePro()
92 |* Beschreibung
93 *************************************************************************/
94 static BOOL CallPrePro( const ByteString& rPrePro,
95 const ByteString& rInput,
96 const ByteString& rOutput,
97 RscPtrPtr * pCmdLine,
98 BOOL bResponse )
100 RscPtrPtr aNewCmdL; // Kommandozeile
101 RscPtrPtr aRespCmdL; // Kommandozeile
102 RscPtrPtr * pCmdL = &aNewCmdL;
103 int i, nExit;
104 FILE* fRspFile = NULL;
105 ByteString aRspFileName;
107 if( bResponse )
109 aRspFileName = ::GetTmpFileName();
110 fRspFile = fopen( aRspFileName.GetBuffer(), "w" );
113 if( !fRspFile )
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" ) )
121 bVerbose = true;
122 continue;
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 );
137 if ( bVerbose )
139 printf( "Preprocessor commandline: " );
140 for( i = 0; i < (int)(pCmdL->GetCount() -1); i++ )
142 printf( " " );
143 printf( "%s", (const char *)pCmdL->GetEntry( i ) );
145 printf( "\n" );
148 if( fRspFile )
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 );
156 pCmdL = &aRespCmdL;
157 for( i = 0; i < (int)(aNewCmdL.GetCount() -1); i++ )
159 #ifdef OS2
160 fprintf( fRspFile, "%s\n", (const char *)aNewCmdL.GetEntry( i ) );
161 #else
162 fprintf( fRspFile, "%s ", (const char *)aNewCmdL.GetEntry( i ) );
163 #endif
165 fclose( fRspFile );
167 if ( bVerbose )
169 printf( "Preprocessor startline: " );
170 for( i = 0; i < (int)(pCmdL->GetCount() -1); i++ )
172 printf( " " );
173 printf( "%s", (const char *)pCmdL->GetEntry( i ) );
175 printf( "\n" );
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() );
181 #elif defined CSET
182 nExit = spawnvp( P_WAIT, (char*)rPrePro.GetBuffer(), char **) (const char**)pCmdL->GetBlock() );
183 #elif defined WTC
184 nExit = spawnvp( P_WAIT, (char*)rPrePro.GetBuffer(), (const char* const*)pCmdL->GetBlock() );
185 #elif defined MTW
186 nExit = spawnvp( P_WAIT, (char*)rPrePro.GetBuffer(), (char**)pCmdL->GetBlock() );
187 #else
188 nExit = spawnvp( P_WAIT, (char*)rPrePro.GetBuffer(), (const char**)pCmdL->GetBlock() );
189 #endif
191 if ( fRspFile )
192 #if OSL_DEBUG_LEVEL > 5
193 fprintf( stderr, "leaving response file %s\n", aRspFileName.GetBuffer() );
194 #else
195 unlink( aRspFileName.GetBuffer() );
196 #endif
197 if ( nExit )
198 return FALSE;
200 return TRUE;
204 /*************************************************************************
205 |* CallRsc2
207 |* Beschreibung
208 *************************************************************************/
209 static BOOL CallRsc2( ByteString aRsc2Name,
210 RscStrList * pInputList,
211 ByteString aSrsName,
212 RscPtrPtr * pCmdLine )
214 int i, nExit;
215 ByteString* pString;
216 ByteString aRspFileName; // Response-Datei
217 FILE * fRspFile; // Response-Datei
219 aRspFileName = ::GetTmpFileName();
220 fRspFile = fopen( aRspFileName.GetBuffer(), "w" );
222 RscVerbosity eVerbosity = RscVerbosityNormal;
223 if( fRspFile )
225 for( i = 1; i < (int)(pCmdLine->GetCount() -1); i++ )
227 if ( !rsc_stricmp( (char *)pCmdLine->GetEntry( i ), "-verbose" ) )
229 eVerbosity = RscVerbosityVerbose;
230 continue;
232 if ( !rsc_stricmp( (char *)pCmdLine->GetEntry( i ), "-quiet" ) )
234 eVerbosity = RscVerbositySilent;
235 continue;
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 ) ) )
251 else
252 #ifdef OS2
253 fprintf( fRspFile, "%s\n",
254 #else
255 fprintf( fRspFile, "%s ",
256 #endif
257 (const char *)pCmdLine->GetEntry( i ) );
260 #ifdef OS2
261 fprintf( fRspFile, "%s\n", aSrsName.GetBuffer() );
262 #else
263 fprintf( fRspFile, "%s", aSrsName.GetBuffer() );
264 #endif
266 pString = pInputList->First();
267 while( pString )
269 #ifdef OS2
270 fprintf( fRspFile, "%s\n", pString->GetBuffer() );
271 #else
272 fprintf( fRspFile, " %s", pString->GetBuffer() );
273 #endif
274 pString = pInputList->Next();
277 fclose( fRspFile );
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 ) );
291 printf( " " );
292 printf( "%s", (const char *)aNewCmdL.GetEntry( 1 ) );
293 printf( "\n" );
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() );
298 #elif defined CSET
299 nExit = spawnvp( P_WAIT, (char*)aRsc2Name.GetBuffer(), (char **)(const char**)aNewCmdL.GetBlock() );
300 #elif defined WTC
301 nExit = spawnvp( P_WAIT, (char*)aRsc2Name.GetBuffer(), (const char* const*)aNewCmdL.GetBlock() );
302 #elif defined MTW
303 nExit = spawnvp( P_WAIT, (char*)aRsc2Name.GetBuffer(), (char**)aNewCmdL.GetBlock() );
304 #else
305 nExit = spawnvp( P_WAIT, (char*)aRsc2Name.GetBuffer(), (const char**)aNewCmdL.GetBlock() );
306 #endif
308 if( fRspFile )
309 #if OSL_DEBUG_LEVEL > 5
310 fprintf( stderr, "leaving response file %s\n", aRspFileName.GetBuffer() );
311 #else
312 unlink( aRspFileName.GetBuffer() );
313 #endif
314 if( nExit )
315 return( FALSE );
316 return( TRUE );
319 /*************************************************************************
321 |* main()
323 |* Beschreibung
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)
331 #else
332 int cdecl main ( int argc, char ** argv)
334 #endif
336 BOOL bPrePro = TRUE;
337 BOOL bResFile = TRUE;
338 BOOL bHelp = FALSE;
339 BOOL bError = FALSE;
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"));
345 ByteString aSrsName;
346 ByteString aResName;
347 RscStrList aInputList;
348 RscStrList aTmpList;
349 char * pStr;
350 char ** ppStr;
351 RscPtrPtr aCmdLine; // Kommandozeile
352 sal_uInt32 i;
353 ByteString* pString;
355 aPrePro = aSolarbin;
356 aPrePro += aDelim;
357 aPrePro += ByteString("rscpp");
359 aRsc2Name = aSolarbin;
360 aRsc2Name += aDelim;
361 aRsc2Name += ByteString("rsc2");
363 pStr = ::ResponseFile( &aCmdLine, argv, argc );
364 if( pStr )
366 printf( "Cannot open response file <%s>\n", pStr );
367 return( 1 );
370 ppStr = (char **)aCmdLine.GetBlock();
371 ppStr++;
372 i = 1;
373 BOOL bSetSrs = FALSE;
374 while( ppStr && i < (aCmdLine.GetCount() -1) )
376 if( '-' == **ppStr )
378 if( !rsc_stricmp( (*ppStr) + 1, "p" )
379 || !rsc_stricmp( (*ppStr) + 1, "l" ) )
380 { // kein Preprozessor
381 bPrePro = FALSE;
383 else if( !rsc_stricmp( (*ppStr) + 1, "r" )
384 || !rsc_stricmp( (*ppStr) + 1, "s" ) )
385 { // erzeugt kein .res-file
386 bResFile = FALSE;
388 else if( !rsc_stricmp( (*ppStr) + 1, "h" ) )
389 { // Hilfe anzeigen
390 bHelp = TRUE;
392 else if( !rsc_strnicmp( (*ppStr) + 1, "presponse", 9 ) )
393 { // anderer Name fuer den Preprozessor
394 bResponse = TRUE;
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
410 bSetSrs = TRUE;
411 aSrsName = (*ppStr);
414 else
416 // Eingabedatei
417 aInputList.Insert( new ByteString( *ppStr ), CONTAINER_APPEND );
419 ppStr++;
420 i++;
423 if( aInputList.Count() )
425 /* build the output file names */
426 if( ! aResName.Len() )
427 aResName = OutputFile( *aInputList.First(), "res" );
428 if( ! bSetSrs )
430 aSrsName = "-fp=";
431 aSrsName += OutputFile( *aInputList.First(), "srs" );
435 if( bHelp )
437 bPrePro = FALSE;
438 bResFile = FALSE;
440 if( bPrePro && aInputList.Count() )
442 ByteString aTmpName;
444 pString = aInputList.First();
445 while( pString )
447 aTmpName = ::GetTmpFileName();
448 if( !CallPrePro( aPrePro, *pString, aTmpName, &aCmdLine, bResponse ) )
450 printf( "Error starting preprocessor\n" );
451 bError = TRUE;
452 break;
454 aTmpList.Insert( new ByteString( aTmpName ), CONTAINER_APPEND );
455 pString = aInputList.Next();
459 if( !bError )
461 if( !CallRsc2( aRsc2Name, bPrePro ? &aTmpList : &aInputList,
462 aSrsName, &aCmdLine ) )
464 if( !bHelp )
466 printf( "Error starting rsc2 compiler\n" );
467 bError = TRUE;
472 pString = aTmpList.First();
473 while( pString )
475 #if OSL_DEBUG_LEVEL > 5
476 fprintf( stderr, "leaving temp file %s\n", pString->GetBuffer() );
477 #else
478 unlink( pString->GetBuffer() );
479 #endif
480 pString = aTmpList.Next();
483 return( bError );
486 void RscExit( sal_uInt32 nExit )
488 if( nExit )
489 printf( "Program exit is %d\n", (int)nExit );
490 exit( nExit );