update dev300-m58
[ooovba.git] / rsc / source / prj / start.cxx
blob42ff95c2ab7ee396c9dbe7e8c212ec8a1fe76c06
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 <tools/fsys.hxx>
61 /*************** C O D E ************************************************/
62 /****************************************************************/
63 /* */
64 /* Function : fuer Ansi kompatibilitaet */
65 /* */
66 /****************************************************************/
67 #ifdef UNX
68 #define P_WAIT 0
69 int spawnvp( int, const char * cmdname, char *const* argv ){
70 int rc(0);
72 switch( fork() ){
73 case -1:
74 return( -1 );
75 case 0:
76 if( execvp( cmdname, argv ) == -1 )
77 // an error occurs
78 return( -1 );
79 break;
80 default:
81 if( -1 == wait( &rc ) )
82 return( -1 );
84 return( WEXITSTATUS( rc ) );
86 #endif
88 /*************************************************************************
89 |* CallPrePro()
91 |* Beschreibung
92 *************************************************************************/
93 static BOOL CallPrePro( const ByteString& rPrePro,
94 const ByteString& rInput,
95 const ByteString& rOutput,
96 RscPtrPtr * pCmdLine,
97 BOOL bResponse )
99 RscPtrPtr aNewCmdL; // Kommandozeile
100 RscPtrPtr aRespCmdL; // Kommandozeile
101 RscPtrPtr * pCmdL = &aNewCmdL;
102 int i, nExit;
103 FILE* fRspFile = NULL;
104 ByteString aRspFileName;
106 if( bResponse )
108 aRspFileName = ::GetTmpFileName();
109 fRspFile = fopen( aRspFileName.GetBuffer(), "w" );
112 if( !fRspFile )
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++ )
129 printf( " " );
130 printf( "%s", (const char *)pCmdL->GetEntry( i ) );
132 printf( "\n" );
134 if( fRspFile )
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 );
142 pCmdL = &aRespCmdL;
143 for( i = 0; i < (int)(aNewCmdL.GetCount() -1); i++ )
145 #ifdef OS2
146 fprintf( fRspFile, "%s\n", (const char *)aNewCmdL.GetEntry( i ) );
147 #else
148 fprintf( fRspFile, "%s ", (const char *)aNewCmdL.GetEntry( i ) );
149 #endif
151 fclose( fRspFile );
153 printf( "Preprocessor startline: " );
154 for( i = 0; i < (int)(pCmdL->GetCount() -1); i++ )
156 printf( " " );
157 printf( "%s", (const char *)pCmdL->GetEntry( i ) );
159 printf( "\n" );
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() );
164 #elif defined CSET
165 nExit = spawnvp( P_WAIT, (char*)rPrePro.GetBuffer(), char **) (const char**)pCmdL->GetBlock() );
166 #elif defined WTC
167 nExit = spawnvp( P_WAIT, (char*)rPrePro.GetBuffer(), (const char* const*)pCmdL->GetBlock() );
168 #elif defined MTW
169 nExit = spawnvp( P_WAIT, (char*)rPrePro.GetBuffer(), (char**)pCmdL->GetBlock() );
170 #else
171 nExit = spawnvp( P_WAIT, (char*)rPrePro.GetBuffer(), (const char**)pCmdL->GetBlock() );
172 #endif
174 if ( fRspFile )
175 #if OSL_DEBUG_LEVEL > 5
176 fprintf( stderr, "leaving response file %s\n", aRspFileName.GetBuffer() );
177 #else
178 unlink( aRspFileName.GetBuffer() );
179 #endif
180 if ( nExit )
181 return FALSE;
183 return TRUE;
187 /*************************************************************************
188 |* CallRsc2
190 |* Beschreibung
191 *************************************************************************/
192 static BOOL CallRsc2( ByteString aRsc2Name,
193 RscStrList * pInputList,
194 ByteString aSrsName,
195 RscPtrPtr * pCmdLine )
197 RscPtrPtr aNewCmdL; // Kommandozeile
198 int i, nExit;
199 ByteString* pString;
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 ) );
209 printf( " " );
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 );
215 printf( "\n" );
217 if( fRspFile )
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 ) ) )
235 else
236 #ifdef OS2
237 fprintf( fRspFile, "%s\n",
238 #else
239 fprintf( fRspFile, "%s ",
240 #endif
241 (const char *)pCmdLine->GetEntry( i ) );
244 #ifdef OS2
245 fprintf( fRspFile, "%s\n", aSrsName.GetBuffer() );
246 #else
247 fprintf( fRspFile, "%s", aSrsName.GetBuffer() );
248 #endif
250 pString = pInputList->First();
251 while( pString )
253 #ifdef OS2
254 fprintf( fRspFile, "%s\n", pString->GetBuffer() );
255 #else
256 fprintf( fRspFile, " %s", pString->GetBuffer() );
257 #endif
258 pString = pInputList->Next();
261 fclose( fRspFile );
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() );
266 #elif defined CSET
267 nExit = spawnvp( P_WAIT, (char*)aRsc2Name.GetBuffer(), (char **)(const char**)aNewCmdL.GetBlock() );
268 #elif defined WTC
269 nExit = spawnvp( P_WAIT, (char*)aRsc2Name.GetBuffer(), (const char* const*)aNewCmdL.GetBlock() );
270 #elif defined MTW
271 nExit = spawnvp( P_WAIT, (char*)aRsc2Name.GetBuffer(), (char**)aNewCmdL.GetBlock() );
272 #else
273 nExit = spawnvp( P_WAIT, (char*)aRsc2Name.GetBuffer(), (const char**)aNewCmdL.GetBlock() );
274 #endif
276 if( fRspFile )
277 #if OSL_DEBUG_LEVEL > 5
278 fprintf( stderr, "leaving response file %s\n", aRspFileName.GetBuffer() );
279 #else
280 unlink( aRspFileName.GetBuffer() );
281 #endif
282 if( nExit )
283 return( FALSE );
284 return( TRUE );
287 /*************************************************************************
289 |* main()
291 |* Beschreibung
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)
299 #else
300 int cdecl main ( int argc, char ** argv)
302 #endif
304 BOOL bPrePro = TRUE;
305 BOOL bResFile = TRUE;
306 BOOL bHelp = FALSE;
307 BOOL bError = FALSE;
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"));
313 ByteString aSrsName;
314 ByteString aResName;
315 RscStrList aInputList;
316 RscStrList aTmpList;
317 char * pStr;
318 char ** ppStr;
319 RscPtrPtr aCmdLine; // Kommandozeile
320 sal_uInt32 i;
321 ByteString* pString;
323 aPrePro = aSolarbin;
324 aPrePro += aDelim;
325 aPrePro += ByteString("rscpp");
327 aRsc2Name = aSolarbin;
328 aRsc2Name += aDelim;
329 aRsc2Name += ByteString("rsc2");
331 printf( "VCL Resource Compiler 3.0\n" );
333 pStr = ::ResponseFile( &aCmdLine, argv, argc );
334 if( pStr )
336 printf( "Cannot open response file <%s>\n", pStr );
337 return( 1 );
340 ppStr = (char **)aCmdLine.GetBlock();
341 ppStr++;
342 i = 1;
343 BOOL bSetSrs = FALSE;
344 while( ppStr && i < (aCmdLine.GetCount() -1) )
346 if( '-' == **ppStr )
348 if( !rsc_stricmp( (*ppStr) + 1, "p" )
349 || !rsc_stricmp( (*ppStr) + 1, "l" ) )
350 { // kein Preprozessor
351 bPrePro = FALSE;
353 else if( !rsc_stricmp( (*ppStr) + 1, "r" )
354 || !rsc_stricmp( (*ppStr) + 1, "s" ) )
355 { // erzeugt kein .res-file
356 bResFile = FALSE;
358 else if( !rsc_stricmp( (*ppStr) + 1, "h" ) )
359 { // Hilfe anzeigen
360 bHelp = TRUE;
362 else if( !rsc_strnicmp( (*ppStr) + 1, "presponse", 9 ) )
363 { // anderer Name fuer den Preprozessor
364 bResponse = TRUE;
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
380 bSetSrs = TRUE;
381 aSrsName = (*ppStr);
384 else
386 // Eingabedatei
387 aInputList.Insert( new ByteString( *ppStr ), CONTAINER_APPEND );
389 ppStr++;
390 i++;
393 if( aInputList.Count() )
395 /* build the output file names */
396 if( ! aResName.Len() )
397 aResName = OutputFile( *aInputList.First(), "res" );
398 if( ! bSetSrs )
400 aSrsName = "-fp=";
401 aSrsName += OutputFile( *aInputList.First(), "srs" );
405 if( bHelp )
407 bPrePro = FALSE;
408 bResFile = FALSE;
410 if( bPrePro && aInputList.Count() )
412 ByteString aTmpName;
414 pString = aInputList.First();
415 while( pString )
417 aTmpName = ::GetTmpFileName();
418 if( !CallPrePro( aPrePro, *pString, aTmpName, &aCmdLine, bResponse ) )
420 printf( "Error starting preprocessor\n" );
421 bError = TRUE;
422 break;
424 aTmpList.Insert( new ByteString( aTmpName ), CONTAINER_APPEND );
425 pString = aInputList.Next();
429 if( !bError )
431 if( !CallRsc2( aRsc2Name, bPrePro ? &aTmpList : &aInputList,
432 aSrsName, &aCmdLine ) )
434 if( !bHelp )
436 printf( "Error starting rsc2 compiler\n" );
437 bError = TRUE;
442 pString = aTmpList.First();
443 while( pString )
445 #if OSL_DEBUG_LEVEL > 5
446 fprintf( stderr, "leaving temp file %s\n", pString->GetBuffer() );
447 #else
448 unlink( pString->GetBuffer() );
449 #endif
450 pString = aTmpList.Next();
453 return( bError );
456 void RscExit( sal_uInt32 nExit )
458 if( nExit )
459 printf( "Program exit is %d\n", (int)nExit );
460 exit( nExit );