fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / rsc / source / prj / start.cxx
blob181b9f58fb416ffe215f94f6a43b99d4701623d6
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #include <stdlib.h>
22 #include <stdio.h>
23 #include <fcntl.h>
24 #include <string.h>
26 #ifdef UNX
27 #include <unistd.h>
28 #include <sys/wait.h>
29 #else // UNX
31 #include <io.h>
32 #include <process.h>
33 #include <dos.h>
35 #endif // UNX
37 #include <gui.hxx>
38 #include <rsctools.hxx>
39 #include <rscerror.h>
40 #include <sal/main.h>
41 #include <rtl/strbuf.hxx>
44 static bool CallPrePro( const OString& rInput,
45 const OString& rOutput, RscPtrPtr * pCmdLine,
46 bool bResponse )
48 RscPtrPtr aNewCmdL; // Kommandozeile
49 RscPtrPtr aRespCmdL; // Kommandozeile
50 RscPtrPtr * pCmdL = &aNewCmdL;
51 int i, nRet;
52 FILE* fRspFile = NULL;
53 OString aRspFileName;
55 if( bResponse )
57 aRspFileName = ::GetTmpFileName();
58 fRspFile = fopen( aRspFileName.getStr(), "w" );
61 if( !fRspFile )
62 aNewCmdL.Append( rsc_strdup( "rscpp" ) );
64 bool bVerbose = false;
65 for( i = 1; i < int(pCmdLine->GetCount() -1); i++ )
67 if ( 0 == rsc_stricmp( static_cast<char *>(pCmdLine->GetEntry( i )), "-verbose" ) )
69 bVerbose = true;
70 continue;
72 if (strcmp(static_cast<char *>(pCmdLine->GetEntry(i)), "-isystem") == 0)
74 // ignore "-isystem" and following arg
75 if (i < int(pCmdLine->GetCount()) - 1)
77 ++i;
79 continue;
81 if (strncmp(
82 static_cast<char *>(pCmdLine->GetEntry(i)), "-isystem",
83 strlen("-isystem"))
84 == 0)
86 // ignore args starting with "-isystem"
87 continue;
89 if ( !rsc_strnicmp( static_cast<char *>(pCmdLine->GetEntry( i )), "-u", 2 ) ||
90 !rsc_strnicmp( static_cast<char *>(pCmdLine->GetEntry( i )), "-i", 2 ) ||
91 !rsc_strnicmp( static_cast<char *>(pCmdLine->GetEntry( i )), "-d", 2 ))
93 aNewCmdL.Append( rsc_strdup( static_cast<char *>(pCmdLine->GetEntry( i )) ) );
97 aNewCmdL.Append( rsc_strdup( rInput.getStr() ) );
98 aNewCmdL.Append( rsc_strdup( rOutput.getStr() ) );
99 aNewCmdL.Append( (void *)0 );
101 if ( bVerbose )
103 printf( "Preprocessor commandline: " );
104 for( i = 0; i < (int)(pCmdL->GetCount() -1); i++ )
106 printf( " " );
107 printf( "%s", static_cast<const char *>(pCmdL->GetEntry( i )) );
109 printf( "\n" );
112 if( fRspFile )
114 aRespCmdL.Append( rsc_strdup( "rscpp" ) );
115 OStringBuffer aTmpStr;
116 aTmpStr.append('@').append(aRspFileName);
117 aRespCmdL.Append( rsc_strdup( aTmpStr.getStr() ) );
118 aRespCmdL.Append( (void *)0 );
120 pCmdL = &aRespCmdL;
121 for( i = 0; i < (int)(aNewCmdL.GetCount() -1); i++ )
123 fprintf( fRspFile, "%s ", static_cast<const char *>(aNewCmdL.GetEntry( i )) );
125 fclose( fRspFile );
127 if ( bVerbose )
129 printf( "Preprocessor startline: " );
130 for( i = 0; i < (int)(pCmdL->GetCount() -1); i++ )
132 printf( " " );
133 printf( "%s", static_cast<const char *>(pCmdL->GetEntry( i )) );
135 printf( "\n" );
139 nRet = rscpp_main( pCmdL->GetCount()-1, reinterpret_cast<char**>(pCmdL->GetBlock()) );
141 if ( fRspFile )
143 #if OSL_DEBUG_LEVEL > 5
144 fprintf( stderr, "leaving response file %s\n", aRspFileName.getStr() );
145 #else
146 unlink( aRspFileName.getStr() );
147 #endif
149 if ( nRet )
150 return false;
152 return true;
156 static bool CallRsc2( RscStrList * pInputList,
157 const OString &rSrsName, RscPtrPtr * pCmdLine )
159 int nRet;
160 RscVerbosity eVerbosity = RscVerbosityNormal;
162 RscPtrPtr aNewCmdL;
163 aNewCmdL.Append( rsc_strdup( "rsc2" ) );
165 for (int i = 1; i < (int)(pCmdLine->GetCount() -1); ++i)
167 if ( !rsc_stricmp( static_cast<char *>(pCmdLine->GetEntry( i )), "-verbose" ) )
169 eVerbosity = RscVerbosityVerbose;
170 continue;
172 if ( !rsc_stricmp( static_cast<char *>(pCmdLine->GetEntry( i )), "-quiet" ) )
174 eVerbosity = RscVerbositySilent;
175 continue;
177 if( !rsc_strnicmp( static_cast<char *>(pCmdLine->GetEntry( i )), "-fp=", 4 ) ||
178 !rsc_strnicmp( static_cast<char *>(pCmdLine->GetEntry( i )), "-fo=", 4 ) ||
179 !rsc_strnicmp( static_cast<char *>(pCmdLine->GetEntry( i )), "-presponse", 10 ) ||
180 !rsc_strnicmp( static_cast<char *>(pCmdLine->GetEntry( i )), "-rc", 3 ) ||
181 !rsc_stricmp( static_cast<char *>(pCmdLine->GetEntry( i )), "-+" ) ||
182 !rsc_stricmp( static_cast<char *>(pCmdLine->GetEntry( i )), "-br" ) ||
183 !rsc_stricmp( static_cast<char *>(pCmdLine->GetEntry( i )), "-bz" ) ||
184 !rsc_stricmp( static_cast<char *>(pCmdLine->GetEntry( i )), "-r" ) ||
185 ( '-' != *static_cast<char *>(pCmdLine->GetEntry( i )) ) )
188 else
190 aNewCmdL.Append( rsc_strdup( static_cast<char *>(pCmdLine->GetEntry( i )) ) );
194 aNewCmdL.Append( rsc_strdup( rSrsName.getStr() ) );
196 for ( size_t i = 0, n = pInputList->size(); i < n; ++i )
198 OString* pString = (*pInputList)[ i ];
199 aNewCmdL.Append( rsc_strdup( pString->getStr() ) );
202 if ( eVerbosity >= RscVerbosityVerbose )
204 printf( "Rsc2 commandline: " );
205 for( size_t i = 0; i < (unsigned int)(aNewCmdL.GetCount() -1); i++ )
207 printf( " %s", static_cast<const char *>(aNewCmdL.GetEntry( i )) );
209 printf( "\n" );
212 nRet = rsc2_main( aNewCmdL.GetCount(), reinterpret_cast<char**>(aNewCmdL.GetBlock()) );
214 if( nRet )
215 return false;
216 return true;
219 SAL_IMPLEMENT_MAIN_WITH_ARGS(argc, argv)
221 bool bPrePro = true;
222 bool bHelp = false;
223 bool bError = false;
224 bool bResponse = false;
225 OString aSrsName;
226 OString aResName;
227 RscStrList aInputList;
228 RscStrList aTmpList;
229 char * pStr;
230 char ** ppStr;
231 RscPtrPtr aCmdLine; // Kommandozeile
232 sal_uInt32 i;
234 pStr = ::ResponseFile( &aCmdLine, argv, argc );
235 if( pStr )
237 printf( "Cannot open response file <%s>\n", pStr );
238 return 1;
241 ppStr = reinterpret_cast<char **>(aCmdLine.GetBlock());
242 ppStr++;
243 i = 1;
244 bool bSetSrs = false;
245 while( ppStr && i < (aCmdLine.GetCount() -1) )
247 if (strcmp(*ppStr, "-isystem") == 0)
249 // ignore "-isystem" and following arg
250 if (i < aCmdLine.GetCount() - 1)
252 ++ppStr;
253 ++i;
256 else if (strncmp(*ppStr, "-isystem", strlen("-isystem")) == 0)
258 // ignore args starting with "-isystem"
260 else if( '-' == **ppStr )
262 if( !rsc_stricmp( (*ppStr) + 1, "p" )
263 || !rsc_stricmp( (*ppStr) + 1, "l" ) )
264 { // kein Preprozessor
265 bPrePro = false;
267 else if( !rsc_stricmp( (*ppStr) + 1, "h" ) )
268 { // Hilfe anzeigen
269 bHelp = true;
271 else if( !rsc_strnicmp( (*ppStr) + 1, "presponse", 9 ) )
272 { // whether to use response file when parameterising preprocessor
273 bResponse = true;
275 else if( !rsc_strnicmp( (*ppStr) + 1, "fo=", 3 ) )
276 { // anderer Name fuer .res-file
277 aResName = (*ppStr) + 4;
279 else if( !rsc_strnicmp( (*ppStr) + 1, "fp=", 3 ) )
280 { // anderer Name fuer .srs-file
281 bSetSrs = true;
282 aSrsName = (*ppStr);
285 else
287 // Eingabedatei
288 aInputList.push_back( new OString(*ppStr) );
290 ppStr++;
291 i++;
294 if( !aInputList.empty() )
296 /* build the output file names */
297 if (!aResName.getLength())
298 aResName = OutputFile( *aInputList[ 0 ], "res" );
299 if( ! bSetSrs )
301 aSrsName = OStringBuffer("-fp=").append(OutputFile(*aInputList[0], "srs")).
302 makeStringAndClear();
306 if( bHelp )
307 bPrePro = false;
309 if( bPrePro && !aInputList.empty() )
311 OString aTmpName;
313 for ( size_t k = 0, n = aInputList.size(); k < n; ++k )
315 OString* pString = aInputList[ k ];
316 aTmpName = ::GetTmpFileName();
317 if( !CallPrePro( *pString, aTmpName, &aCmdLine, bResponse ) )
319 printf( "Error starting preprocessor\n" );
320 bError = true;
321 break;
323 aTmpList.push_back( new OString(aTmpName) );
327 if( !bError )
329 if( !CallRsc2( bPrePro ? &aTmpList : &aInputList, aSrsName, &aCmdLine ) )
331 if( !bHelp )
333 printf( "Error starting rsc2 compiler\n" );
334 bError = true;
339 for ( size_t k = 0, n = aTmpList.size(); k < n; ++k )
340 unlink( aTmpList[ k ]->getStr() );
342 return bError ? EXIT_FAILURE : EXIT_SUCCESS;
345 void RscExit( sal_uInt32 nExit )
347 if( nExit )
348 printf( "Program exit is %d\n", (int)nExit );
349 exit( nExit );
352 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */