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 .
38 #include <rsctools.hxx>
41 #include <rtl/strbuf.hxx>
44 static bool CallPrePro( const OString
& rInput
,
45 const OString
& rOutput
, RscPtrPtr
* pCmdLine
,
48 RscPtrPtr aNewCmdL
; // Kommandozeile
49 RscPtrPtr aRespCmdL
; // Kommandozeile
50 RscPtrPtr
* pCmdL
= &aNewCmdL
;
52 FILE* fRspFile
= NULL
;
57 aRspFileName
= ::GetTmpFileName();
58 fRspFile
= fopen( aRspFileName
.getStr(), "w" );
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" ) )
72 if (strcmp(static_cast<char *>(pCmdLine
->GetEntry(i
)), "-isystem") == 0)
74 // ignore "-isystem" and following arg
75 if (i
< int(pCmdLine
->GetCount()) - 1)
82 static_cast<char *>(pCmdLine
->GetEntry(i
)), "-isystem",
86 // ignore args starting with "-isystem"
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 );
103 printf( "Preprocessor commandline: " );
104 for( i
= 0; i
< (int)(pCmdL
->GetCount() -1); i
++ )
107 printf( "%s", static_cast<const char *>(pCmdL
->GetEntry( i
)) );
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 );
121 for( i
= 0; i
< (int)(aNewCmdL
.GetCount() -1); i
++ )
123 fprintf( fRspFile
, "%s ", static_cast<const char *>(aNewCmdL
.GetEntry( i
)) );
129 printf( "Preprocessor startline: " );
130 for( i
= 0; i
< (int)(pCmdL
->GetCount() -1); i
++ )
133 printf( "%s", static_cast<const char *>(pCmdL
->GetEntry( i
)) );
139 nRet
= rscpp_main( pCmdL
->GetCount()-1, reinterpret_cast<char**>(pCmdL
->GetBlock()) );
143 #if OSL_DEBUG_LEVEL > 5
144 fprintf( stderr
, "leaving response file %s\n", aRspFileName
.getStr() );
146 unlink( aRspFileName
.getStr() );
156 static bool CallRsc2( RscStrList
* pInputList
,
157 const OString
&rSrsName
, RscPtrPtr
* pCmdLine
)
160 RscVerbosity eVerbosity
= RscVerbosityNormal
;
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
;
172 if ( !rsc_stricmp( static_cast<char *>(pCmdLine
->GetEntry( i
)), "-quiet" ) )
174 eVerbosity
= RscVerbositySilent
;
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
)) ) )
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
)) );
212 nRet
= rsc2_main( aNewCmdL
.GetCount(), reinterpret_cast<char**>(aNewCmdL
.GetBlock()) );
219 SAL_IMPLEMENT_MAIN_WITH_ARGS(argc
, argv
)
224 bool bResponse
= false;
227 RscStrList aInputList
;
231 RscPtrPtr aCmdLine
; // Kommandozeile
234 pStr
= ::ResponseFile( &aCmdLine
, argv
, argc
);
237 printf( "Cannot open response file <%s>\n", pStr
);
241 ppStr
= reinterpret_cast<char **>(aCmdLine
.GetBlock());
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)
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
267 else if( !rsc_stricmp( (*ppStr
) + 1, "h" ) )
271 else if( !rsc_strnicmp( (*ppStr
) + 1, "presponse", 9 ) )
272 { // whether to use response file when parameterising preprocessor
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
288 aInputList
.push_back( new OString(*ppStr
) );
294 if( !aInputList
.empty() )
296 /* build the output file names */
297 if (!aResName
.getLength())
298 aResName
= OutputFile( *aInputList
[ 0 ], "res" );
301 aSrsName
= OStringBuffer("-fp=").append(OutputFile(*aInputList
[0], "srs")).
302 makeStringAndClear();
309 if( bPrePro
&& !aInputList
.empty() )
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" );
323 aTmpList
.push_back( new OString(aTmpName
) );
329 if( !CallRsc2( bPrePro
? &aTmpList
: &aInputList
, aSrsName
, &aCmdLine
) )
333 printf( "Error starting rsc2 compiler\n" );
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
)
348 printf( "Program exit is %d\n", (int)nExit
);
352 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */