xref: /trunk/main/rsc/source/prj/start.cxx (revision cf6516809c57e1bb0a940545cca99cdad54d4ce2)
1477794c1SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3477794c1SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4477794c1SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5477794c1SAndrew Rist  * distributed with this work for additional information
6477794c1SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7477794c1SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8477794c1SAndrew Rist  * "License"); you may not use this file except in compliance
9477794c1SAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
11477794c1SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
13477794c1SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14477794c1SAndrew Rist  * software distributed under the License is distributed on an
15477794c1SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16477794c1SAndrew Rist  * KIND, either express or implied.  See the License for the
17477794c1SAndrew Rist  * specific language governing permissions and limitations
18477794c1SAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
20477794c1SAndrew Rist  *************************************************************/
21477794c1SAndrew Rist 
22477794c1SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_rsc.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include <stdlib.h>
28cdf0e10cSrcweir #include <stdio.h>
29cdf0e10cSrcweir #include <fcntl.h>
30cdf0e10cSrcweir #include <string.h>
31cdf0e10cSrcweir #if defined (WNT) && defined (tcpp)
32cdf0e10cSrcweir #define _spawnvp spawnvp
33cdf0e10cSrcweir #define _P_WAIT P_WAIT
34cdf0e10cSrcweir #endif
35cdf0e10cSrcweir 
36cdf0e10cSrcweir #ifdef UNX
37cdf0e10cSrcweir #include <unistd.h>
38cdf0e10cSrcweir #include <sys/wait.h>
39cdf0e10cSrcweir #else // UNX
40cdf0e10cSrcweir 
41cdf0e10cSrcweir #include <io.h>
42cdf0e10cSrcweir #include <process.h>
43cdf0e10cSrcweir #if defined ( OS2 ) && !defined ( GCC )
44cdf0e10cSrcweir #include <direct.h>
45cdf0e10cSrcweir #endif
46cdf0e10cSrcweir #if !defined ( CSET ) && !defined ( OS2 )
47cdf0e10cSrcweir #include <dos.h>
48cdf0e10cSrcweir #endif
49cdf0e10cSrcweir 
50cdf0e10cSrcweir #endif // UNX
51cdf0e10cSrcweir #include <rsctools.hxx>
52cdf0e10cSrcweir #include <rscerror.h>
53cdf0e10cSrcweir #include <sal/main.h>
54cdf0e10cSrcweir #include <tools/fsys.hxx>
55cdf0e10cSrcweir 
56cdf0e10cSrcweir /*************** C O D E ************************************************/
57cdf0e10cSrcweir /****************************************************************/
58cdf0e10cSrcweir /*                                                              */
59cdf0e10cSrcweir /*  Function    :   fuer Ansi kompatibilitaet                   */
60cdf0e10cSrcweir /*                                                              */
61cdf0e10cSrcweir /****************************************************************/
62cdf0e10cSrcweir #ifdef UNX
63cdf0e10cSrcweir #define P_WAIT 0
spawnvp(int,const char * cmdname,char * const * argv)64cdf0e10cSrcweir     int spawnvp( int, const char * cmdname, char *const*  argv ){
65cdf0e10cSrcweir         int rc(0);
66cdf0e10cSrcweir 
67cdf0e10cSrcweir         switch( fork() ){
68cdf0e10cSrcweir             case -1:
69cdf0e10cSrcweir                 return( -1 );
70cdf0e10cSrcweir             case 0:
71cdf0e10cSrcweir                 if( execvp( cmdname, argv ) == -1 )
72cdf0e10cSrcweir                     // an error occurs
73cdf0e10cSrcweir                     return( -1 );
74cdf0e10cSrcweir                 break;
75cdf0e10cSrcweir             default:
76cdf0e10cSrcweir                 if( -1 == wait( &rc ) )
77cdf0e10cSrcweir                     return( -1 );
78cdf0e10cSrcweir         }
79cdf0e10cSrcweir         return( WEXITSTATUS( rc ) );
80cdf0e10cSrcweir     }
81cdf0e10cSrcweir #endif
82cdf0e10cSrcweir 
83cdf0e10cSrcweir /*************************************************************************
84cdf0e10cSrcweir |*    CallPrePro()
85cdf0e10cSrcweir |*
86cdf0e10cSrcweir |*    Beschreibung
87cdf0e10cSrcweir *************************************************************************/
CallPrePro(const ByteString & rPrePro,const ByteString & rInput,const ByteString & rOutput,RscPtrPtr * pCmdLine,sal_Bool bResponse)88cdf0e10cSrcweir static sal_Bool CallPrePro( const ByteString& rPrePro,
89cdf0e10cSrcweir                         const ByteString& rInput,
90cdf0e10cSrcweir                         const ByteString& rOutput,
91cdf0e10cSrcweir                         RscPtrPtr * pCmdLine,
92cdf0e10cSrcweir                         sal_Bool bResponse )
93cdf0e10cSrcweir {
94cdf0e10cSrcweir     RscPtrPtr       aNewCmdL;   // Kommandozeile
95cdf0e10cSrcweir     RscPtrPtr       aRespCmdL;   // Kommandozeile
96cdf0e10cSrcweir     RscPtrPtr *     pCmdL = &aNewCmdL;
97cdf0e10cSrcweir     int             i, nExit;
98cdf0e10cSrcweir     FILE*           fRspFile = NULL;
99cdf0e10cSrcweir     ByteString      aRspFileName;
100cdf0e10cSrcweir 
101cdf0e10cSrcweir     if( bResponse )
102cdf0e10cSrcweir     {
103cdf0e10cSrcweir         aRspFileName = ::GetTmpFileName();
104cdf0e10cSrcweir         fRspFile = fopen( aRspFileName.GetBuffer(), "w" );
105cdf0e10cSrcweir     }
106cdf0e10cSrcweir 
107cdf0e10cSrcweir     if( !fRspFile )
108cdf0e10cSrcweir         aNewCmdL.Append( rsc_strdup( rPrePro.GetBuffer() ) );
109cdf0e10cSrcweir 
110cdf0e10cSrcweir     bool bVerbose = false;
111cdf0e10cSrcweir     for( i = 1; i < int(pCmdLine->GetCount() -1); i++ )
112cdf0e10cSrcweir     {
113cdf0e10cSrcweir         if ( 0 == rsc_stricmp( (char *)pCmdLine->GetEntry( i ), "-verbose" ) )
114cdf0e10cSrcweir         {
115cdf0e10cSrcweir             bVerbose = true;
116cdf0e10cSrcweir             continue;
117cdf0e10cSrcweir         }
118cdf0e10cSrcweir         if  (   !rsc_strnicmp( (char *)pCmdLine->GetEntry( i ), "-u", 2 )
119cdf0e10cSrcweir             ||  !rsc_strnicmp( (char *)pCmdLine->GetEntry( i ), "-i", 2 )
120cdf0e10cSrcweir             ||  !rsc_strnicmp( (char *)pCmdLine->GetEntry( i ), "-d", 2 )
121cdf0e10cSrcweir             )
122cdf0e10cSrcweir         {
123cdf0e10cSrcweir             aNewCmdL.Append( rsc_strdup( (char *)pCmdLine->GetEntry( i ) ) );
124cdf0e10cSrcweir         }
125cdf0e10cSrcweir     }
126cdf0e10cSrcweir 
127cdf0e10cSrcweir     aNewCmdL.Append( rsc_strdup( rInput.GetBuffer() ) );
128cdf0e10cSrcweir     aNewCmdL.Append( rsc_strdup( rOutput.GetBuffer() ) );
129cdf0e10cSrcweir     aNewCmdL.Append( (void *)0 );
130cdf0e10cSrcweir 
131cdf0e10cSrcweir     if ( bVerbose )
132cdf0e10cSrcweir     {
133cdf0e10cSrcweir         printf( "Preprocessor commandline: " );
134cdf0e10cSrcweir         for( i = 0; i < (int)(pCmdL->GetCount() -1); i++ )
135cdf0e10cSrcweir         {
136cdf0e10cSrcweir             printf( " " );
137cdf0e10cSrcweir             printf( "%s", (const char *)pCmdL->GetEntry( i ) );
138cdf0e10cSrcweir         }
139cdf0e10cSrcweir         printf( "\n" );
140cdf0e10cSrcweir     }
141cdf0e10cSrcweir 
142cdf0e10cSrcweir     if( fRspFile )
143cdf0e10cSrcweir     {
144cdf0e10cSrcweir         aRespCmdL.Append( rsc_strdup( rPrePro.GetBuffer() ) );
145cdf0e10cSrcweir         ByteString aTmpStr( '@' );
146cdf0e10cSrcweir         aTmpStr += aRspFileName;
147cdf0e10cSrcweir         aRespCmdL.Append( rsc_strdup( aTmpStr.GetBuffer() ) );
148cdf0e10cSrcweir         aRespCmdL.Append( (void *)0 );
149cdf0e10cSrcweir 
150cdf0e10cSrcweir         pCmdL = &aRespCmdL;
151cdf0e10cSrcweir         for( i = 0; i < (int)(aNewCmdL.GetCount() -1); i++ )
152cdf0e10cSrcweir         {
153cdf0e10cSrcweir #ifdef OS2
154cdf0e10cSrcweir             fprintf( fRspFile, "%s\n", (const char *)aNewCmdL.GetEntry( i ) );
155cdf0e10cSrcweir #else
156cdf0e10cSrcweir             fprintf( fRspFile, "%s ", (const char *)aNewCmdL.GetEntry( i ) );
157cdf0e10cSrcweir #endif
158cdf0e10cSrcweir         }
159cdf0e10cSrcweir         fclose( fRspFile );
160cdf0e10cSrcweir 
161cdf0e10cSrcweir         if ( bVerbose )
162cdf0e10cSrcweir         {
163cdf0e10cSrcweir             printf( "Preprocessor startline: " );
164cdf0e10cSrcweir             for( i = 0; i < (int)(pCmdL->GetCount() -1); i++ )
165cdf0e10cSrcweir             {
166cdf0e10cSrcweir                 printf( " " );
167cdf0e10cSrcweir                 printf( "%s", (const char *)pCmdL->GetEntry( i ) );
168cdf0e10cSrcweir             }
169cdf0e10cSrcweir             printf( "\n" );
170cdf0e10cSrcweir         }
171cdf0e10cSrcweir     }
172cdf0e10cSrcweir 
173cdf0e10cSrcweir #if ((defined OS2 || defined WNT) && (defined TCPP || defined tcpp)) || defined UNX || defined OS2
174cdf0e10cSrcweir     nExit = spawnvp( P_WAIT, rPrePro.GetBuffer(), (char* const*)pCmdL->GetBlock() );
175cdf0e10cSrcweir #elif defined CSET
176cdf0e10cSrcweir     nExit = spawnvp( P_WAIT, (char*)rPrePro.GetBuffer(), (const char**)pCmdL->GetBlock() );
177cdf0e10cSrcweir #elif defined WTC
178cdf0e10cSrcweir     nExit = spawnvp( P_WAIT, (char*)rPrePro.GetBuffer(), (const char* const*)pCmdL->GetBlock() );
179cdf0e10cSrcweir #elif defined MTW
180cdf0e10cSrcweir     nExit = spawnvp( P_WAIT, (char*)rPrePro.GetBuffer(), (char**)pCmdL->GetBlock() );
181cdf0e10cSrcweir #else
182cdf0e10cSrcweir     nExit = spawnvp( P_WAIT, (char*)rPrePro.GetBuffer(), (const char**)pCmdL->GetBlock() );
183cdf0e10cSrcweir #endif
184cdf0e10cSrcweir 
185cdf0e10cSrcweir     if ( fRspFile )
186cdf0e10cSrcweir         #if OSL_DEBUG_LEVEL > 5
187cdf0e10cSrcweir         fprintf( stderr, "leaving response file %s\n", aRspFileName.GetBuffer() );
188cdf0e10cSrcweir         #else
189cdf0e10cSrcweir         unlink( aRspFileName.GetBuffer() );
190cdf0e10cSrcweir         #endif
191cdf0e10cSrcweir     if ( nExit )
192cdf0e10cSrcweir         return sal_False;
193cdf0e10cSrcweir 
194cdf0e10cSrcweir     return sal_True;
195cdf0e10cSrcweir }
196cdf0e10cSrcweir 
197cdf0e10cSrcweir 
198cdf0e10cSrcweir /*************************************************************************
199cdf0e10cSrcweir |*    CallRsc2
200cdf0e10cSrcweir |*
201cdf0e10cSrcweir |*    Beschreibung
202cdf0e10cSrcweir *************************************************************************/
CallRsc2(ByteString aRsc2Name,RscStrList * pInputList,ByteString aSrsName,RscPtrPtr * pCmdLine)203cdf0e10cSrcweir static sal_Bool CallRsc2( ByteString aRsc2Name,
204cdf0e10cSrcweir                       RscStrList * pInputList,
205cdf0e10cSrcweir                       ByteString aSrsName,
206cdf0e10cSrcweir                       RscPtrPtr * pCmdLine )
207cdf0e10cSrcweir {
208cdf0e10cSrcweir     int             i, nExit;
209cdf0e10cSrcweir     ByteString*     pString;
210cdf0e10cSrcweir     ByteString      aRspFileName;   // Response-Datei
211cdf0e10cSrcweir     FILE *          fRspFile;       // Response-Datei
212cdf0e10cSrcweir 
213cdf0e10cSrcweir     aRspFileName = ::GetTmpFileName();
214cdf0e10cSrcweir     fRspFile = fopen( aRspFileName.GetBuffer(), "w" );
215cdf0e10cSrcweir 
216cdf0e10cSrcweir     RscVerbosity eVerbosity = RscVerbosityNormal;
217cdf0e10cSrcweir     if( fRspFile )
218cdf0e10cSrcweir     {
219cdf0e10cSrcweir         for( i = 1; i < (int)(pCmdLine->GetCount() -1); i++ )
220cdf0e10cSrcweir         {
221cdf0e10cSrcweir             if ( !rsc_stricmp( (char *)pCmdLine->GetEntry( i ), "-verbose" ) )
222cdf0e10cSrcweir             {
223cdf0e10cSrcweir                 eVerbosity = RscVerbosityVerbose;
224cdf0e10cSrcweir                 continue;
225cdf0e10cSrcweir             }
226cdf0e10cSrcweir             if ( !rsc_stricmp( (char *)pCmdLine->GetEntry( i ), "-quiet" ) )
227cdf0e10cSrcweir             {
228cdf0e10cSrcweir                 eVerbosity = RscVerbositySilent;
229cdf0e10cSrcweir                 continue;
230cdf0e10cSrcweir             }
231cdf0e10cSrcweir             if( !rsc_strnicmp( (char *)pCmdLine->GetEntry( i ),  "-fp=", 4 )
232cdf0e10cSrcweir               || !rsc_strnicmp( (char *)pCmdLine->GetEntry( i ), "-fo=", 4 )
233cdf0e10cSrcweir               || !rsc_strnicmp( (char *)pCmdLine->GetEntry( i ), "-pp=", 4 )
234cdf0e10cSrcweir               || !rsc_strnicmp( (char *)pCmdLine->GetEntry( i ), "-rsc2=", 6 )
235cdf0e10cSrcweir               || !rsc_strnicmp( (char *)pCmdLine->GetEntry( i ), "-presponse", 9 )
236cdf0e10cSrcweir               || !rsc_strnicmp( (char *)pCmdLine->GetEntry( i ), "-rc", 3 )
237cdf0e10cSrcweir               || !rsc_stricmp( (char *)pCmdLine->GetEntry( i ), "-+" )
238cdf0e10cSrcweir               || !rsc_stricmp( (char *)pCmdLine->GetEntry( i ), "-br" )
239cdf0e10cSrcweir               || !rsc_stricmp( (char *)pCmdLine->GetEntry( i ), "-bz" )
240cdf0e10cSrcweir               || !rsc_stricmp( (char *)pCmdLine->GetEntry( i ), "-r" )
241cdf0e10cSrcweir               // Am I the only one that thinks the following line inludes all the tests before?
242cdf0e10cSrcweir               || ( '-' != *(char *)pCmdLine->GetEntry( i ) ) )
243cdf0e10cSrcweir             {
244cdf0e10cSrcweir             }
245cdf0e10cSrcweir             else
246cdf0e10cSrcweir #ifdef OS2
247cdf0e10cSrcweir                 fprintf( fRspFile, "%s\n",
248cdf0e10cSrcweir #else
249cdf0e10cSrcweir                 fprintf( fRspFile, "%s ",
250cdf0e10cSrcweir #endif
251cdf0e10cSrcweir                          (const char *)pCmdLine->GetEntry( i ) );
252cdf0e10cSrcweir         };
253cdf0e10cSrcweir 
254cdf0e10cSrcweir #ifdef OS2
255cdf0e10cSrcweir         fprintf( fRspFile, "%s\n", aSrsName.GetBuffer() );
256cdf0e10cSrcweir #else
257*851abcd9Struckman         fprintf( fRspFile, "%s", aSrsName.GetBuffer() );
258cdf0e10cSrcweir #endif
259cdf0e10cSrcweir 
260cdf0e10cSrcweir         pString = pInputList->First();
261cdf0e10cSrcweir         while( pString )
262cdf0e10cSrcweir         {
263cdf0e10cSrcweir #ifdef OS2
264cdf0e10cSrcweir             fprintf( fRspFile, "%s\n", pString->GetBuffer() );
265cdf0e10cSrcweir #else
266cdf0e10cSrcweir             fprintf( fRspFile, " %s", pString->GetBuffer() );
267cdf0e10cSrcweir #endif
268cdf0e10cSrcweir             pString = pInputList->Next();
269cdf0e10cSrcweir         };
270cdf0e10cSrcweir 
271cdf0e10cSrcweir         fclose( fRspFile );
272cdf0e10cSrcweir     };
273cdf0e10cSrcweir 
274cdf0e10cSrcweir     RscPtrPtr       aNewCmdL;       // Kommandozeile
275cdf0e10cSrcweir     aNewCmdL.Append( rsc_strdup( aRsc2Name.GetBuffer() ) );
276cdf0e10cSrcweir     ByteString aTmpStr( '@' );
277cdf0e10cSrcweir     aTmpStr += aRspFileName;
278cdf0e10cSrcweir     aNewCmdL.Append( rsc_strdup( aTmpStr.GetBuffer() ) );
279cdf0e10cSrcweir     aNewCmdL.Append( (void *)0 );
280cdf0e10cSrcweir 
281cdf0e10cSrcweir     if ( eVerbosity >= RscVerbosityVerbose )
282cdf0e10cSrcweir     {
283cdf0e10cSrcweir         printf( "Rsc2 commandline: " );
284cdf0e10cSrcweir         printf( "%s", (const char *)aNewCmdL.GetEntry( 0 ) );
285cdf0e10cSrcweir         printf( " " );
286cdf0e10cSrcweir         printf( "%s", (const char *)aNewCmdL.GetEntry( 1 ) );
287cdf0e10cSrcweir         printf( "\n" );
288cdf0e10cSrcweir     }
289cdf0e10cSrcweir 
290cdf0e10cSrcweir #if ((defined OS2 || defined WNT) && (defined TCPP || defined tcpp)) || defined UNX || defined OS2
291cdf0e10cSrcweir     nExit = spawnvp( P_WAIT, aRsc2Name.GetBuffer(), (char* const*)aNewCmdL.GetBlock() );
292cdf0e10cSrcweir #elif defined CSET
293cdf0e10cSrcweir     nExit = spawnvp( P_WAIT, (char*)aRsc2Name.GetBuffer(), (char **)(const char**)aNewCmdL.GetBlock() );
294cdf0e10cSrcweir #elif defined WTC
295cdf0e10cSrcweir     nExit = spawnvp( P_WAIT, (char*)aRsc2Name.GetBuffer(), (const char* const*)aNewCmdL.GetBlock() );
296cdf0e10cSrcweir #elif defined MTW
297cdf0e10cSrcweir     nExit = spawnvp( P_WAIT, (char*)aRsc2Name.GetBuffer(), (char**)aNewCmdL.GetBlock() );
298cdf0e10cSrcweir #else
299cdf0e10cSrcweir     nExit = spawnvp( P_WAIT, (char*)aRsc2Name.GetBuffer(), (const char**)aNewCmdL.GetBlock() );
300cdf0e10cSrcweir #endif
301cdf0e10cSrcweir 
302cdf0e10cSrcweir     if( fRspFile )
303cdf0e10cSrcweir         #if OSL_DEBUG_LEVEL > 5
304cdf0e10cSrcweir         fprintf( stderr, "leaving response file %s\n", aRspFileName.GetBuffer() );
305cdf0e10cSrcweir         #else
306cdf0e10cSrcweir         unlink( aRspFileName.GetBuffer() );
307cdf0e10cSrcweir         #endif
308cdf0e10cSrcweir     if( nExit )
309cdf0e10cSrcweir         return( sal_False );
310cdf0e10cSrcweir     return( sal_True );
311cdf0e10cSrcweir }
312cdf0e10cSrcweir 
313cdf0e10cSrcweir /*************************************************************************
314cdf0e10cSrcweir |*
315cdf0e10cSrcweir |*    main()
316cdf0e10cSrcweir |*
317cdf0e10cSrcweir |*    Beschreibung
318cdf0e10cSrcweir |*    Ersterstellung    MM 05.09.91
319cdf0e10cSrcweir |*    Letzte Aenderung  MM 05.09.91
320cdf0e10cSrcweir |*
321cdf0e10cSrcweir *************************************************************************/
SAL_IMPLEMENT_MAIN_WITH_ARGS(argc,argv)322cdf0e10cSrcweir SAL_IMPLEMENT_MAIN_WITH_ARGS(argc, argv)
323cdf0e10cSrcweir {
324cdf0e10cSrcweir     sal_Bool            bPrePro  = sal_True;
325cdf0e10cSrcweir     sal_Bool            bResFile = sal_True;
326cdf0e10cSrcweir     sal_Bool            bHelp    = sal_False;
327cdf0e10cSrcweir     sal_Bool            bError   = sal_False;
328cdf0e10cSrcweir     sal_Bool            bResponse = sal_False;
329cdf0e10cSrcweir     ByteString      aSolarbin(getenv("SOLARBINDIR"));
330cdf0e10cSrcweir     ByteString      aDelim("/");
331cdf0e10cSrcweir     ByteString      aPrePro; //( aSolarbin + aDelim + ByteString("rscpp"));
332cdf0e10cSrcweir     ByteString      aRsc2Name; //(  aSolarbin + aDelim + ByteString("rsc2"));
333cdf0e10cSrcweir     ByteString      aSrsName;
334cdf0e10cSrcweir     ByteString      aResName;
335cdf0e10cSrcweir     RscStrList      aInputList;
336cdf0e10cSrcweir     RscStrList      aTmpList;
337cdf0e10cSrcweir     char *          pStr;
338cdf0e10cSrcweir     char **         ppStr;
339cdf0e10cSrcweir     RscPtrPtr       aCmdLine;       // Kommandozeile
340cdf0e10cSrcweir     sal_uInt32      i;
341cdf0e10cSrcweir     ByteString*     pString;
342cdf0e10cSrcweir 
343cdf0e10cSrcweir     aPrePro = aSolarbin;
344cdf0e10cSrcweir     aPrePro += aDelim;
345cdf0e10cSrcweir     aPrePro += ByteString("rscpp");
346cdf0e10cSrcweir 
347cdf0e10cSrcweir     aRsc2Name = aSolarbin;
348cdf0e10cSrcweir     aRsc2Name += aDelim;
349cdf0e10cSrcweir     aRsc2Name += ByteString("rsc2");
350cdf0e10cSrcweir 
351cdf0e10cSrcweir     pStr = ::ResponseFile( &aCmdLine, argv, argc );
352cdf0e10cSrcweir     if( pStr )
353cdf0e10cSrcweir     {
354cdf0e10cSrcweir         printf( "Cannot open response file <%s>\n", pStr );
355cdf0e10cSrcweir         return( 1 );
356cdf0e10cSrcweir     };
357cdf0e10cSrcweir 
358cdf0e10cSrcweir     ppStr  = (char **)aCmdLine.GetBlock();
359cdf0e10cSrcweir     ppStr++;
360cdf0e10cSrcweir     i = 1;
361cdf0e10cSrcweir     sal_Bool bSetSrs = sal_False;
362cdf0e10cSrcweir     while( ppStr && i < (aCmdLine.GetCount() -1) )
363cdf0e10cSrcweir     {
364cdf0e10cSrcweir         if( '-' == **ppStr )
365cdf0e10cSrcweir         {
366cdf0e10cSrcweir             if( !rsc_stricmp( (*ppStr) + 1, "p" )
367cdf0e10cSrcweir               || !rsc_stricmp( (*ppStr) + 1, "l" ) )
368cdf0e10cSrcweir             { // kein Preprozessor
369cdf0e10cSrcweir                 bPrePro = sal_False;
370cdf0e10cSrcweir             }
371cdf0e10cSrcweir             else if( !rsc_stricmp( (*ppStr) + 1, "r" )
372cdf0e10cSrcweir               || !rsc_stricmp( (*ppStr) + 1, "s" ) )
373cdf0e10cSrcweir             { // erzeugt kein .res-file
374cdf0e10cSrcweir                 bResFile = sal_False;
375cdf0e10cSrcweir             }
376cdf0e10cSrcweir             else if( !rsc_stricmp( (*ppStr) + 1, "h" ) )
377cdf0e10cSrcweir             { // Hilfe anzeigen
378cdf0e10cSrcweir                 bHelp = sal_True;
379cdf0e10cSrcweir             }
380cdf0e10cSrcweir             else if( !rsc_strnicmp( (*ppStr) + 1, "presponse", 9 ) )
381cdf0e10cSrcweir             { // anderer Name fuer den Preprozessor
382cdf0e10cSrcweir                 bResponse = sal_True;
383cdf0e10cSrcweir             }
384cdf0e10cSrcweir             else if( !rsc_strnicmp( (*ppStr) + 1, "pp=", 3 ) )
385cdf0e10cSrcweir             { // anderer Name fuer den Preprozessor
386cdf0e10cSrcweir                 aPrePro = (*ppStr) + 4;
387cdf0e10cSrcweir             }
388cdf0e10cSrcweir             else if( !rsc_strnicmp( (*ppStr) + 1, "rsc2=", 5 ) )
389cdf0e10cSrcweir             { // Accept alternate name for the rsc2 compiler
390cdf0e10cSrcweir                 aRsc2Name = (*ppStr) + 6;
391cdf0e10cSrcweir             }
392cdf0e10cSrcweir             else if( !rsc_strnicmp( (*ppStr) + 1, "fo=", 3 ) )
393cdf0e10cSrcweir             { // anderer Name fuer .res-file
394cdf0e10cSrcweir                 aResName = (*ppStr) + 4;
395cdf0e10cSrcweir             }
396cdf0e10cSrcweir             else if( !rsc_strnicmp( (*ppStr) + 1, "fp=", 3 ) )
397cdf0e10cSrcweir             { // anderer Name fuer .srs-file
398cdf0e10cSrcweir                 bSetSrs  = sal_True;
399cdf0e10cSrcweir                 aSrsName = (*ppStr);
400cdf0e10cSrcweir             }
401cdf0e10cSrcweir         }
402cdf0e10cSrcweir         else
403cdf0e10cSrcweir         {
404cdf0e10cSrcweir             // Eingabedatei
405cdf0e10cSrcweir             aInputList.Insert( new ByteString( *ppStr ), CONTAINER_APPEND );
406cdf0e10cSrcweir         }
407cdf0e10cSrcweir         ppStr++;
408cdf0e10cSrcweir         i++;
409cdf0e10cSrcweir     }
410cdf0e10cSrcweir 
411cdf0e10cSrcweir     if( aInputList.Count() )
412cdf0e10cSrcweir     {
413cdf0e10cSrcweir         /* build the output file names          */
414cdf0e10cSrcweir         if( ! aResName.Len() )
415cdf0e10cSrcweir             aResName = OutputFile( *aInputList.First(), "res" );
416cdf0e10cSrcweir         if( ! bSetSrs )
417cdf0e10cSrcweir         {
418cdf0e10cSrcweir             aSrsName = "-fp=";
419cdf0e10cSrcweir             aSrsName += OutputFile( *aInputList.First(), "srs" );
420cdf0e10cSrcweir         }
421cdf0e10cSrcweir     };
422cdf0e10cSrcweir 
423cdf0e10cSrcweir     if( bHelp )
424cdf0e10cSrcweir     {
425cdf0e10cSrcweir         bPrePro = sal_False;
426cdf0e10cSrcweir         bResFile = sal_False;
427cdf0e10cSrcweir     };
428cdf0e10cSrcweir     if( bPrePro && aInputList.Count() )
429cdf0e10cSrcweir     {
430cdf0e10cSrcweir         ByteString aTmpName;
431cdf0e10cSrcweir 
432cdf0e10cSrcweir         pString = aInputList.First();
433cdf0e10cSrcweir         while( pString )
434cdf0e10cSrcweir         {
435cdf0e10cSrcweir             aTmpName = ::GetTmpFileName();
436cdf0e10cSrcweir             if( !CallPrePro( aPrePro, *pString, aTmpName, &aCmdLine, bResponse ) )
437cdf0e10cSrcweir             {
438cdf0e10cSrcweir                 printf( "Error starting preprocessor\n" );
439cdf0e10cSrcweir                 bError = sal_True;
440cdf0e10cSrcweir                 break;
441cdf0e10cSrcweir             }
442cdf0e10cSrcweir             aTmpList.Insert( new ByteString( aTmpName ), CONTAINER_APPEND );
443cdf0e10cSrcweir             pString = aInputList.Next();
444cdf0e10cSrcweir         };
445cdf0e10cSrcweir     };
446cdf0e10cSrcweir 
447cdf0e10cSrcweir     if( !bError )
448cdf0e10cSrcweir     {
449cdf0e10cSrcweir         if( !CallRsc2( aRsc2Name, bPrePro ? &aTmpList : &aInputList,
450cdf0e10cSrcweir                        aSrsName, &aCmdLine ) )
451cdf0e10cSrcweir         {
452cdf0e10cSrcweir             if( !bHelp )
453cdf0e10cSrcweir             {
454cdf0e10cSrcweir                 printf( "Error starting rsc2 compiler\n" );
455cdf0e10cSrcweir                 bError = sal_True;
456cdf0e10cSrcweir             }
457cdf0e10cSrcweir         };
458cdf0e10cSrcweir     };
459cdf0e10cSrcweir 
460cdf0e10cSrcweir     pString = aTmpList.First();
461cdf0e10cSrcweir     while( pString )
462cdf0e10cSrcweir     {
463cdf0e10cSrcweir         #if OSL_DEBUG_LEVEL > 5
464cdf0e10cSrcweir         fprintf( stderr, "leaving temp file %s\n", pString->GetBuffer() );
465cdf0e10cSrcweir         #else
466cdf0e10cSrcweir         unlink( pString->GetBuffer() );
467cdf0e10cSrcweir         #endif
468cdf0e10cSrcweir         pString = aTmpList.Next();
469cdf0e10cSrcweir     };
470cdf0e10cSrcweir 
471cdf0e10cSrcweir     return( bError );
472cdf0e10cSrcweir }
473cdf0e10cSrcweir 
RscExit(sal_uInt32 nExit)474cdf0e10cSrcweir void RscExit( sal_uInt32 nExit )
475cdf0e10cSrcweir {
476cdf0e10cSrcweir     if( nExit )
477cdf0e10cSrcweir         printf( "Program exit is %d\n", (int)nExit );
478cdf0e10cSrcweir     exit( nExit );
479cdf0e10cSrcweir }
480