Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*
3 : : * This file is part of the LibreOffice project.
4 : : *
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/.
8 : : *
9 : : * This file incorporates work covered by the following license notice:
10 : : *
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 .
18 : : */
19 : :
20 : :
21 : : #include <stdlib.h>
22 : : #include <stdio.h>
23 : : #include <fcntl.h>
24 : : #include <string.h>
25 : :
26 : : #ifdef UNX
27 : : #include <unistd.h>
28 : : #include <sys/wait.h>
29 : : #else // UNX
30 : :
31 : : #include <io.h>
32 : : #include <process.h>
33 : : #include <dos.h>
34 : :
35 : : #endif // UNX
36 : : #include <rsctools.hxx>
37 : : #include <rscerror.h>
38 : : #include <sal/main.h>
39 : : #include <rtl/strbuf.hxx>
40 : : #include <tools/fsys.hxx>
41 : :
42 : : /*************** C O D E ************************************************/
43 : :
44 : : // Entry point declaration for modules rscpp and rsc2
45 : : extern "C"
46 : : {
47 : : int rscpp_main(int, char**);
48 : : }
49 : : int rsc2_main(int, char**);
50 : :
51 : : /*************************************************************************
52 : : |* CallPrePro()
53 : : |*
54 : : |* Beschreibung
55 : : *************************************************************************/
56 : 1320 : static sal_Bool CallPrePro( const rtl::OString& rInput,
57 : : const rtl::OString& rOutput, RscPtrPtr * pCmdLine,
58 : : sal_Bool bResponse )
59 : : {
60 [ + - ]: 1320 : RscPtrPtr aNewCmdL; // Kommandozeile
61 [ + - ]: 1320 : RscPtrPtr aRespCmdL; // Kommandozeile
62 : 1320 : RscPtrPtr * pCmdL = &aNewCmdL;
63 : : int i, nRet;
64 : 1320 : FILE* fRspFile = NULL;
65 : 1320 : rtl::OString aRspFileName;
66 : :
67 [ + - ]: 1320 : if( bResponse )
68 : : {
69 [ + - ]: 1320 : aRspFileName = ::GetTmpFileName();
70 [ + - ]: 1320 : fRspFile = fopen( aRspFileName.getStr(), "w" );
71 : : }
72 : :
73 [ - + ]: 1320 : if( !fRspFile )
74 [ # # ][ # # ]: 0 : aNewCmdL.Append( rsc_strdup( "rscpp" ) );
75 : :
76 : 1320 : bool bVerbose = false;
77 [ + + ]: 51680 : for( i = 1; i < int(pCmdLine->GetCount() -1); i++ )
78 : : {
79 [ + - ][ + - ]: 50360 : if ( 0 == rsc_stricmp( (char *)pCmdLine->GetEntry( i ), "-verbose" ) )
[ - + ]
80 : : {
81 : 0 : bVerbose = true;
82 : 0 : continue;
83 : : }
84 [ + - ][ + - ]: 131080 : if ( !rsc_strnicmp( (char *)pCmdLine->GetEntry( i ), "-u", 2 )
[ + - ][ + + ]
[ + + ][ + + ]
85 [ + - ][ + - ]: 50360 : || !rsc_strnicmp( (char *)pCmdLine->GetEntry( i ), "-i", 2 )
86 [ + - ][ + - ]: 30360 : || !rsc_strnicmp( (char *)pCmdLine->GetEntry( i ), "-d", 2 )
87 : : )
88 : : {
89 [ + - ][ + - ]: 45080 : aNewCmdL.Append( rsc_strdup( (char *)pCmdLine->GetEntry( i ) ) );
[ + - ]
90 : : }
91 : : }
92 : :
93 [ + - ][ + - ]: 1320 : aNewCmdL.Append( rsc_strdup( rInput.getStr() ) );
94 [ + - ][ + - ]: 1320 : aNewCmdL.Append( rsc_strdup( rOutput.getStr() ) );
95 [ + - ]: 1320 : aNewCmdL.Append( (void *)0 );
96 : :
97 [ - + ]: 1320 : if ( bVerbose )
98 : : {
99 [ # # ]: 0 : printf( "Preprocessor commandline: " );
100 [ # # ]: 0 : for( i = 0; i < (int)(pCmdL->GetCount() -1); i++ )
101 : : {
102 [ # # ]: 0 : printf( " " );
103 [ # # ][ # # ]: 0 : printf( "%s", (const char *)pCmdL->GetEntry( i ) );
104 : : }
105 [ # # ]: 0 : printf( "\n" );
106 : : }
107 : :
108 [ + - ]: 1320 : if( fRspFile )
109 : : {
110 [ + - ][ + - ]: 1320 : aRespCmdL.Append( rsc_strdup( "rscpp" ) );
111 : 1320 : rtl::OStringBuffer aTmpStr;
112 [ + - ][ + - ]: 1320 : aTmpStr.append('@').append(aRspFileName);
113 [ + - ][ + - ]: 1320 : aRespCmdL.Append( rsc_strdup( aTmpStr.getStr() ) );
114 [ + - ]: 1320 : aRespCmdL.Append( (void *)0 );
115 : :
116 : 1320 : pCmdL = &aRespCmdL;
117 [ + + ]: 49040 : for( i = 0; i < (int)(aNewCmdL.GetCount() -1); i++ )
118 : : {
119 [ + - ][ + - ]: 47720 : fprintf( fRspFile, "%s ", (const char *)aNewCmdL.GetEntry( i ) );
120 : : }
121 [ + - ]: 1320 : fclose( fRspFile );
122 : :
123 [ - + ]: 1320 : if ( bVerbose )
124 : : {
125 [ # # ]: 0 : printf( "Preprocessor startline: " );
126 [ # # ]: 0 : for( i = 0; i < (int)(pCmdL->GetCount() -1); i++ )
127 : : {
128 [ # # ]: 0 : printf( " " );
129 [ # # ][ # # ]: 0 : printf( "%s", (const char *)pCmdL->GetEntry( i ) );
130 : : }
131 [ # # ]: 0 : printf( "\n" );
132 : 1320 : }
133 : : }
134 : :
135 [ + - ]: 1320 : nRet = rscpp_main( pCmdL->GetCount()-1, (char**)pCmdL->GetBlock() );
136 : :
137 [ + - ]: 1320 : if ( fRspFile )
138 : : {
139 : : #if OSL_DEBUG_LEVEL > 5
140 : : fprintf( stderr, "leaving response file %s\n", aRspFileName.getStr() );
141 : : #else
142 : 1320 : unlink( aRspFileName.getStr() );
143 : : #endif
144 : : }
145 [ - + ]: 1320 : if ( nRet )
146 : 0 : return sal_False;
147 : :
148 [ + - ][ + - ]: 1320 : return sal_True;
149 : : }
150 : :
151 : :
152 : : /*************************************************************************
153 : : |* CallRsc2
154 : : |*
155 : : |* Beschreibung
156 : : *************************************************************************/
157 : 1440 : static sal_Bool CallRsc2( RscStrList * pInputList,
158 : : const rtl::OString &rSrsName, RscPtrPtr * pCmdLine )
159 : : {
160 : : int nRet;
161 : : rtl::OString* pString;
162 : 1440 : RscVerbosity eVerbosity = RscVerbosityNormal;
163 : :
164 [ + - ]: 1440 : RscPtrPtr aNewCmdL;
165 [ + - ][ + - ]: 1440 : aNewCmdL.Append( rsc_strdup( "rsc2" ) );
166 : :
167 [ + + ]: 53722 : for (int i = 1; i < (int)(pCmdLine->GetCount() -1); ++i)
168 : : {
169 [ + - ][ + - ]: 52282 : if ( !rsc_stricmp( (char *)pCmdLine->GetEntry( i ), "-verbose" ) )
[ - + ]
170 : : {
171 : 0 : eVerbosity = RscVerbosityVerbose;
172 : 0 : continue;
173 : : }
174 [ + - ][ + - ]: 52282 : if ( !rsc_stricmp( (char *)pCmdLine->GetEntry( i ), "-quiet" ) )
[ - + ]
175 : : {
176 : 0 : eVerbosity = RscVerbositySilent;
177 : 0 : continue;
178 : : }
179 [ + - ][ + - ]: 451938 : if( !rsc_strnicmp( (char *)pCmdLine->GetEntry( i ), "-fp=", 4 )
[ + + ][ + - ]
[ + + ][ + - ]
[ + - ][ + - ]
[ + - ][ + + ]
[ + + ][ + + ]
180 [ + - ][ + - ]: 50962 : || !rsc_strnicmp( (char *)pCmdLine->GetEntry( i ), "-fo=", 4 )
181 [ + - ][ + - ]: 50962 : || !rsc_strnicmp( (char *)pCmdLine->GetEntry( i ), "-presponse", 9 )
182 [ + - ][ + - ]: 49642 : || !rsc_strnicmp( (char *)pCmdLine->GetEntry( i ), "-rc", 3 )
183 [ + - ][ + - ]: 49642 : || !rsc_stricmp( (char *)pCmdLine->GetEntry( i ), "-+" )
184 [ + - ][ + - ]: 49642 : || !rsc_stricmp( (char *)pCmdLine->GetEntry( i ), "-br" )
185 [ + - ][ + - ]: 49642 : || !rsc_stricmp( (char *)pCmdLine->GetEntry( i ), "-bz" )
186 [ + - ][ + - ]: 49642 : || !rsc_stricmp( (char *)pCmdLine->GetEntry( i ), "-r" )
187 [ + - ]: 49522 : || ( '-' != *(char *)pCmdLine->GetEntry( i ) ) )
188 : : {
189 : : }
190 : : else
191 [ + - ][ + - ]: 48080 : aNewCmdL.Append( rsc_strdup( (char *)pCmdLine->GetEntry( i ) ) );
[ + - ]
192 : : };
193 : :
194 [ + - ][ + - ]: 1440 : aNewCmdL.Append( rsc_strdup( rSrsName.getStr() ) );
195 : :
196 [ + + ]: 2882 : for ( size_t i = 0, n = pInputList->size(); i < n; ++i )
197 : : {
198 : 1442 : pString = (*pInputList)[ i ];
199 [ + - ][ + - ]: 1442 : aNewCmdL.Append( rsc_strdup( pString->getStr() ) );
200 : : };
201 : :
202 [ - + ]: 1440 : if ( eVerbosity >= RscVerbosityVerbose )
203 : : {
204 [ # # ]: 0 : printf( "Rsc2 commandline: " );
205 [ # # ]: 0 : for( size_t i = 0; i < (unsigned int)(aNewCmdL.GetCount() -1); i++ )
206 : : {
207 [ # # ][ # # ]: 0 : printf( " %s", (const char *)aNewCmdL.GetEntry( i ) );
208 : : }
209 [ # # ]: 0 : printf( "\n" );
210 : : }
211 : :
212 [ + - ]: 1440 : nRet = rsc2_main( aNewCmdL.GetCount(), (char**)aNewCmdL.GetBlock() );
213 : :
214 [ - + ]: 1440 : if( nRet )
215 : 0 : return( sal_False );
216 [ + - ]: 1440 : return( sal_True );
217 : : }
218 : :
219 : : /*************************************************************************
220 : : |*
221 : : |* main()
222 : : |*
223 : : *************************************************************************/
224 : 1440 : SAL_IMPLEMENT_MAIN_WITH_ARGS(argc, argv)
225 : : {
226 : 1440 : sal_Bool bPrePro = sal_True;
227 : 1440 : sal_Bool bHelp = sal_False;
228 : 1440 : sal_Bool bError = sal_False;
229 : 1440 : sal_Bool bResponse = sal_False;
230 : 1440 : rtl::OString aSrsName;
231 : 1440 : rtl::OString aResName;
232 [ + - ]: 1440 : RscStrList aInputList;
233 [ + - ]: 1440 : RscStrList aTmpList;
234 : : char * pStr;
235 : : char ** ppStr;
236 [ + - ]: 1440 : RscPtrPtr aCmdLine; // Kommandozeile
237 : : sal_uInt32 i;
238 : : rtl::OString* pString;
239 : :
240 [ + - ]: 1440 : pStr = ::ResponseFile( &aCmdLine, argv, argc );
241 [ - + ]: 1440 : if( pStr )
242 : : {
243 [ # # ]: 0 : printf( "Cannot open response file <%s>\n", pStr );
244 : 0 : return( 1 );
245 : : };
246 : :
247 : 1440 : ppStr = (char **)aCmdLine.GetBlock();
248 : 1440 : ppStr++;
249 : 1440 : i = 1;
250 : 1440 : sal_Bool bSetSrs = sal_False;
251 [ + - ][ + + ]: 53722 : while( ppStr && i < (aCmdLine.GetCount() -1) )
[ + + ]
252 : : {
253 [ + + ]: 52282 : if( '-' == **ppStr )
254 : : {
255 [ + - ][ + + ]: 101560 : if( !rsc_stricmp( (*ppStr) + 1, "p" )
[ - + ][ + + ]
256 [ + - ]: 50720 : || !rsc_stricmp( (*ppStr) + 1, "l" ) )
257 : : { // kein Preprozessor
258 : 120 : bPrePro = sal_False;
259 : : }
260 [ + - ][ - + ]: 50720 : else if( !rsc_stricmp( (*ppStr) + 1, "h" ) )
261 : : { // Hilfe anzeigen
262 : 0 : bHelp = sal_True;
263 : : }
264 [ + - ][ + + ]: 50720 : else if( !rsc_strnicmp( (*ppStr) + 1, "presponse", 9 ) )
265 : : { // whether to use response file when parameterising preprocessor
266 : 1320 : bResponse = sal_True;
267 : : }
268 [ + - ][ - + ]: 49400 : else if( !rsc_strnicmp( (*ppStr) + 1, "fo=", 3 ) )
269 : : { // anderer Name fuer .res-file
270 : 0 : aResName = (*ppStr) + 4;
271 : : }
272 [ + - ][ + + ]: 49400 : else if( !rsc_strnicmp( (*ppStr) + 1, "fp=", 3 ) )
273 : : { // anderer Name fuer .srs-file
274 : 1320 : bSetSrs = sal_True;
275 : 1320 : aSrsName = (*ppStr);
276 : : }
277 : : }
278 : : else
279 : : {
280 : : // Eingabedatei
281 [ + - ][ + - ]: 1442 : aInputList.push_back( new rtl::OString(*ppStr) );
282 : : }
283 : 52282 : ppStr++;
284 : 52282 : i++;
285 : : }
286 : :
287 [ + - ]: 1440 : if( !aInputList.empty() )
288 : : {
289 : : /* build the output file names */
290 [ + - ]: 1440 : if (!aResName.getLength())
291 [ + - ]: 1440 : aResName = OutputFile( *aInputList[ 0 ], "res" );
292 [ + + ]: 1440 : if( ! bSetSrs )
293 : : {
294 [ + - ][ + - ]: 240 : aSrsName = rtl::OStringBuffer("-fp=").append(OutputFile(*aInputList[0], "srs")).
295 : 120 : makeStringAndClear();
296 : : }
297 : : };
298 : :
299 [ - + ]: 1440 : if( bHelp )
300 : 0 : bPrePro = sal_False;
301 [ + + ][ + - ]: 1440 : if( bPrePro && !aInputList.empty() )
[ + + ]
302 : : {
303 : 1320 : rtl::OString aTmpName;
304 : :
305 [ + + ]: 2640 : for ( size_t k = 0, n = aInputList.size(); k < n; ++k )
306 : : {
307 : 1320 : pString = aInputList[ k ];
308 [ + - ]: 1320 : aTmpName = ::GetTmpFileName();
309 [ - + ][ + - ]: 1320 : if( !CallPrePro( *pString, aTmpName, &aCmdLine, bResponse ) )
310 : : {
311 [ # # ]: 0 : printf( "Error starting preprocessor\n" );
312 : 0 : bError = sal_True;
313 : 0 : break;
314 : : }
315 [ + - ][ + - ]: 1320 : aTmpList.push_back( new rtl::OString(aTmpName) );
316 : 1320 : };
317 : : };
318 : :
319 [ + - ]: 1440 : if( !bError )
320 : : {
321 [ + + ][ + - ]: 1440 : if( !CallRsc2( bPrePro ? &aTmpList : &aInputList, aSrsName, &aCmdLine ) )
[ - + ]
322 : : {
323 [ # # ]: 0 : if( !bHelp )
324 : : {
325 [ # # ]: 0 : printf( "Error starting rsc2 compiler\n" );
326 : 0 : bError = sal_True;
327 : : }
328 : : };
329 : : };
330 : :
331 [ + + ]: 2760 : for ( size_t k = 0, n = aTmpList.size(); k < n; ++k )
332 : 1320 : unlink( aTmpList[ k ]->getStr() );
333 : :
334 [ + - ]: 1440 : return( bError );
335 : : }
336 : :
337 : 0 : void RscExit( sal_uInt32 nExit )
338 : : {
339 [ # # ]: 0 : if( nExit )
340 : 0 : printf( "Program exit is %d\n", (int)nExit );
341 : 0 : exit( nExit );
342 : : }
343 : :
344 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|