fdo#74697 Add Bluez 5 support for impress remote.
[LibreOffice.git] / rsc / source / prj / start.cxx
blobf15472cff14835ac1bbb19da3480c93ac64aa39a
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
36 #include <rsctools.hxx>
37 #include <rscerror.h>
38 #include <sal/main.h>
39 #include <rtl/strbuf.hxx>
42 // Entry point declaration for modules rscpp and rsc2
43 extern "C"
45 int rscpp_main(int, char**);
47 int rsc2_main(int, char**);
49 static sal_Bool CallPrePro( const OString& rInput,
50 const OString& rOutput, RscPtrPtr * pCmdLine,
51 sal_Bool bResponse )
53 RscPtrPtr aNewCmdL; // Kommandozeile
54 RscPtrPtr aRespCmdL; // Kommandozeile
55 RscPtrPtr * pCmdL = &aNewCmdL;
56 int i, nRet;
57 FILE* fRspFile = NULL;
58 OString aRspFileName;
60 if( bResponse )
62 aRspFileName = ::GetTmpFileName();
63 fRspFile = fopen( aRspFileName.getStr(), "w" );
66 if( !fRspFile )
67 aNewCmdL.Append( rsc_strdup( "rscpp" ) );
69 bool bVerbose = false;
70 for( i = 1; i < int(pCmdLine->GetCount() -1); i++ )
72 if ( 0 == rsc_stricmp( (char *)pCmdLine->GetEntry( i ), "-verbose" ) )
74 bVerbose = true;
75 continue;
77 if ( !rsc_strnicmp( (char *)pCmdLine->GetEntry( i ), "-u", 2 )
78 || !rsc_strnicmp( (char *)pCmdLine->GetEntry( i ), "-i", 2 )
79 || !rsc_strnicmp( (char *)pCmdLine->GetEntry( i ), "-d", 2 )
82 aNewCmdL.Append( rsc_strdup( (char *)pCmdLine->GetEntry( i ) ) );
86 aNewCmdL.Append( rsc_strdup( rInput.getStr() ) );
87 aNewCmdL.Append( rsc_strdup( rOutput.getStr() ) );
88 aNewCmdL.Append( (void *)0 );
90 if ( bVerbose )
92 printf( "Preprocessor commandline: " );
93 for( i = 0; i < (int)(pCmdL->GetCount() -1); i++ )
95 printf( " " );
96 printf( "%s", (const char *)pCmdL->GetEntry( i ) );
98 printf( "\n" );
101 if( fRspFile )
103 aRespCmdL.Append( rsc_strdup( "rscpp" ) );
104 OStringBuffer aTmpStr;
105 aTmpStr.append('@').append(aRspFileName);
106 aRespCmdL.Append( rsc_strdup( aTmpStr.getStr() ) );
107 aRespCmdL.Append( (void *)0 );
109 pCmdL = &aRespCmdL;
110 for( i = 0; i < (int)(aNewCmdL.GetCount() -1); i++ )
112 fprintf( fRspFile, "%s ", (const char *)aNewCmdL.GetEntry( i ) );
114 fclose( fRspFile );
116 if ( bVerbose )
118 printf( "Preprocessor startline: " );
119 for( i = 0; i < (int)(pCmdL->GetCount() -1); i++ )
121 printf( " " );
122 printf( "%s", (const char *)pCmdL->GetEntry( i ) );
124 printf( "\n" );
128 nRet = rscpp_main( pCmdL->GetCount()-1, (char**)pCmdL->GetBlock() );
130 if ( fRspFile )
132 #if OSL_DEBUG_LEVEL > 5
133 fprintf( stderr, "leaving response file %s\n", aRspFileName.getStr() );
134 #else
135 unlink( aRspFileName.getStr() );
136 #endif
138 if ( nRet )
139 return sal_False;
141 return sal_True;
145 static sal_Bool CallRsc2( RscStrList * pInputList,
146 const OString &rSrsName, RscPtrPtr * pCmdLine )
148 int nRet;
149 OString* pString;
150 RscVerbosity eVerbosity = RscVerbosityNormal;
152 RscPtrPtr aNewCmdL;
153 aNewCmdL.Append( rsc_strdup( "rsc2" ) );
155 for (int i = 1; i < (int)(pCmdLine->GetCount() -1); ++i)
157 if ( !rsc_stricmp( (char *)pCmdLine->GetEntry( i ), "-verbose" ) )
159 eVerbosity = RscVerbosityVerbose;
160 continue;
162 if ( !rsc_stricmp( (char *)pCmdLine->GetEntry( i ), "-quiet" ) )
164 eVerbosity = RscVerbositySilent;
165 continue;
167 if( !rsc_strnicmp( (char *)pCmdLine->GetEntry( i ), "-fp=", 4 )
168 || !rsc_strnicmp( (char *)pCmdLine->GetEntry( i ), "-fo=", 4 )
169 || !rsc_strnicmp( (char *)pCmdLine->GetEntry( i ), "-presponse", 9 )
170 || !rsc_strnicmp( (char *)pCmdLine->GetEntry( i ), "-rc", 3 )
171 || !rsc_stricmp( (char *)pCmdLine->GetEntry( i ), "-+" )
172 || !rsc_stricmp( (char *)pCmdLine->GetEntry( i ), "-br" )
173 || !rsc_stricmp( (char *)pCmdLine->GetEntry( i ), "-bz" )
174 || !rsc_stricmp( (char *)pCmdLine->GetEntry( i ), "-r" )
175 || ( '-' != *(char *)pCmdLine->GetEntry( i ) ) )
178 else
179 aNewCmdL.Append( rsc_strdup( (char *)pCmdLine->GetEntry( i ) ) );
182 aNewCmdL.Append( rsc_strdup( rSrsName.getStr() ) );
184 for ( size_t i = 0, n = pInputList->size(); i < n; ++i )
186 pString = (*pInputList)[ i ];
187 aNewCmdL.Append( rsc_strdup( pString->getStr() ) );
190 if ( eVerbosity >= RscVerbosityVerbose )
192 printf( "Rsc2 commandline: " );
193 for( size_t i = 0; i < (unsigned int)(aNewCmdL.GetCount() -1); i++ )
195 printf( " %s", (const char *)aNewCmdL.GetEntry( i ) );
197 printf( "\n" );
200 nRet = rsc2_main( aNewCmdL.GetCount(), (char**)aNewCmdL.GetBlock() );
202 if( nRet )
203 return( sal_False );
204 return( sal_True );
207 SAL_IMPLEMENT_MAIN_WITH_ARGS(argc, argv)
209 sal_Bool bPrePro = sal_True;
210 sal_Bool bHelp = sal_False;
211 sal_Bool bError = sal_False;
212 sal_Bool bResponse = sal_False;
213 OString aSrsName;
214 OString aResName;
215 RscStrList aInputList;
216 RscStrList aTmpList;
217 char * pStr;
218 char ** ppStr;
219 RscPtrPtr aCmdLine; // Kommandozeile
220 sal_uInt32 i;
221 OString* pString;
223 pStr = ::ResponseFile( &aCmdLine, argv, argc );
224 if( pStr )
226 printf( "Cannot open response file <%s>\n", pStr );
227 return( 1 );
230 ppStr = (char **)aCmdLine.GetBlock();
231 ppStr++;
232 i = 1;
233 sal_Bool bSetSrs = sal_False;
234 while( ppStr && i < (aCmdLine.GetCount() -1) )
236 if( '-' == **ppStr )
238 if( !rsc_stricmp( (*ppStr) + 1, "p" )
239 || !rsc_stricmp( (*ppStr) + 1, "l" ) )
240 { // kein Preprozessor
241 bPrePro = sal_False;
243 else if( !rsc_stricmp( (*ppStr) + 1, "h" ) )
244 { // Hilfe anzeigen
245 bHelp = sal_True;
247 else if( !rsc_strnicmp( (*ppStr) + 1, "presponse", 9 ) )
248 { // whether to use response file when parameterising preprocessor
249 bResponse = sal_True;
251 else if( !rsc_strnicmp( (*ppStr) + 1, "fo=", 3 ) )
252 { // anderer Name fuer .res-file
253 aResName = (*ppStr) + 4;
255 else if( !rsc_strnicmp( (*ppStr) + 1, "fp=", 3 ) )
256 { // anderer Name fuer .srs-file
257 bSetSrs = sal_True;
258 aSrsName = (*ppStr);
261 else
263 // Eingabedatei
264 aInputList.push_back( new OString(*ppStr) );
266 ppStr++;
267 i++;
270 if( !aInputList.empty() )
272 /* build the output file names */
273 if (!aResName.getLength())
274 aResName = OutputFile( *aInputList[ 0 ], "res" );
275 if( ! bSetSrs )
277 aSrsName = OStringBuffer("-fp=").append(OutputFile(*aInputList[0], "srs")).
278 makeStringAndClear();
282 if( bHelp )
283 bPrePro = sal_False;
284 if( bPrePro && !aInputList.empty() )
286 OString aTmpName;
288 for ( size_t k = 0, n = aInputList.size(); k < n; ++k )
290 pString = aInputList[ k ];
291 aTmpName = ::GetTmpFileName();
292 if( !CallPrePro( *pString, aTmpName, &aCmdLine, bResponse ) )
294 printf( "Error starting preprocessor\n" );
295 bError = sal_True;
296 break;
298 aTmpList.push_back( new OString(aTmpName) );
302 if( !bError )
304 if( !CallRsc2( bPrePro ? &aTmpList : &aInputList, aSrsName, &aCmdLine ) )
306 if( !bHelp )
308 printf( "Error starting rsc2 compiler\n" );
309 bError = sal_True;
314 for ( size_t k = 0, n = aTmpList.size(); k < n; ++k )
315 unlink( aTmpList[ k ]->getStr() );
317 return( bError );
320 void RscExit( sal_uInt32 nExit )
322 if( nExit )
323 printf( "Program exit is %d\n", (int)nExit );
324 exit( nExit );
327 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */