1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 .
36 #include <rsctools.hxx>
39 #include <rtl/strbuf.hxx>
42 // Entry point declaration for modules rscpp and rsc2
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
,
53 RscPtrPtr aNewCmdL
; // Kommandozeile
54 RscPtrPtr aRespCmdL
; // Kommandozeile
55 RscPtrPtr
* pCmdL
= &aNewCmdL
;
57 FILE* fRspFile
= NULL
;
62 aRspFileName
= ::GetTmpFileName();
63 fRspFile
= fopen( aRspFileName
.getStr(), "w" );
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" ) )
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 );
92 printf( "Preprocessor commandline: " );
93 for( i
= 0; i
< (int)(pCmdL
->GetCount() -1); i
++ )
96 printf( "%s", (const char *)pCmdL
->GetEntry( i
) );
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 );
110 for( i
= 0; i
< (int)(aNewCmdL
.GetCount() -1); i
++ )
112 fprintf( fRspFile
, "%s ", (const char *)aNewCmdL
.GetEntry( i
) );
118 printf( "Preprocessor startline: " );
119 for( i
= 0; i
< (int)(pCmdL
->GetCount() -1); i
++ )
122 printf( "%s", (const char *)pCmdL
->GetEntry( i
) );
128 nRet
= rscpp_main( pCmdL
->GetCount()-1, (char**)pCmdL
->GetBlock() );
132 #if OSL_DEBUG_LEVEL > 5
133 fprintf( stderr
, "leaving response file %s\n", aRspFileName
.getStr() );
135 unlink( aRspFileName
.getStr() );
145 static sal_Bool
CallRsc2( RscStrList
* pInputList
,
146 const OString
&rSrsName
, RscPtrPtr
* pCmdLine
)
150 RscVerbosity eVerbosity
= RscVerbosityNormal
;
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
;
162 if ( !rsc_stricmp( (char *)pCmdLine
->GetEntry( i
), "-quiet" ) )
164 eVerbosity
= RscVerbositySilent
;
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
) ) )
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
) );
200 nRet
= rsc2_main( aNewCmdL
.GetCount(), (char**)aNewCmdL
.GetBlock() );
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
;
215 RscStrList aInputList
;
219 RscPtrPtr aCmdLine
; // Kommandozeile
223 pStr
= ::ResponseFile( &aCmdLine
, argv
, argc
);
226 printf( "Cannot open response file <%s>\n", pStr
);
230 ppStr
= (char **)aCmdLine
.GetBlock();
233 sal_Bool bSetSrs
= sal_False
;
234 while( ppStr
&& i
< (aCmdLine
.GetCount() -1) )
238 if( !rsc_stricmp( (*ppStr
) + 1, "p" )
239 || !rsc_stricmp( (*ppStr
) + 1, "l" ) )
240 { // kein Preprozessor
243 else if( !rsc_stricmp( (*ppStr
) + 1, "h" ) )
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
264 aInputList
.push_back( new OString(*ppStr
) );
270 if( !aInputList
.empty() )
272 /* build the output file names */
273 if (!aResName
.getLength())
274 aResName
= OutputFile( *aInputList
[ 0 ], "res" );
277 aSrsName
= OStringBuffer("-fp=").append(OutputFile(*aInputList
[0], "srs")).
278 makeStringAndClear();
284 if( bPrePro
&& !aInputList
.empty() )
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" );
298 aTmpList
.push_back( new OString(aTmpName
) );
304 if( !CallRsc2( bPrePro
? &aTmpList
: &aInputList
, aSrsName
, &aCmdLine
) )
308 printf( "Error starting rsc2 compiler\n" );
314 for ( size_t k
= 0, n
= aTmpList
.size(); k
< n
; ++k
)
315 unlink( aTmpList
[ k
]->getStr() );
320 void RscExit( sal_uInt32 nExit
)
323 printf( "Program exit is %d\n", (int)nExit
);
327 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */