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 .
26 SAL_IMPLEMENT_MAIN_WITH_ARGS(argc
, argv
)
28 std::vector
< std::string
> args
;
29 for (int i
= 1; i
< argc
; i
++)
31 if (!Options::checkArgument (args
, argv
[i
], strlen(argv
[i
])))
35 Options
options(argv
[0]);
36 sal_Int32 nErrors
= 0;
40 if (!options
.initOptions(args
))
45 if (options
.readStdin()) {
46 if ( !options
.quiet() )
48 stdout
, "%s: Compiling stdin\n",
49 options
.getProgramName().getStr());
50 nErrors
= compileFile(nullptr);
51 if ( ( idlc()->getWarningCount() > 0 ) && !options
.quiet() ) {
53 stdout
, "%s: detected %lu warnings compiling stdin\n",
54 options
.getProgramName().getStr(),
55 sal::static_int_cast
< unsigned long >(
56 idlc()->getWarningCount()));
59 if (options
.isValid("-O")) {
60 outputUrl
= convertToFileUrl(options
.getOption("-O"));
61 if (!outputUrl
.endsWith("/")) {
64 outputUrl
+= "stdin.urd";
66 outputUrl
= convertToFileUrl("stdin.urd");
69 removeIfExists(outputUrl
);
71 nErrors
= produceFile(outputUrl
, nullptr);
75 std::vector
< OString
> const & files
= options
.getInputFiles();
76 if ( options
.verbose() )
78 fprintf( stdout
, "%s: compiling %i source files ... \n",
79 options
.getProgramName().getStr(), static_cast<int>(files
.size()) );
82 for (auto const& elem
: files
)
86 OString
sysFileName( convertToAbsoluteSystemPath(elem
) );
88 if ( !options
.quiet() )
89 fprintf(stdout
, "Compiling: %s\n", elem
.getStr());
90 nErrors
= compileFile(&sysFileName
);
92 if ( idlc()->getWarningCount() && !options
.quiet() )
93 fprintf(stdout
, "%s: detected %" SAL_PRIdINT64
" warnings compiling file '%s'\n",
94 options
.getProgramName().getStr(),
95 sal_Int64(idlc()->getWarningCount()),
98 // prepare output file name
99 OString
const strippedFileName(
100 sysFileName
.copy(sysFileName
.lastIndexOf(SEPARATOR
) + 1));
102 if ( options
.isValid("-O") )
104 outputFile
= options
.getOption("-O");
105 if (!outputFile
.endsWith("/")) {
108 outputFile
+= strippedFileName
.replaceAt(
109 strippedFileName
.getLength() -3 , 3, "urd");
112 sysFileName
.replaceAt(sysFileName
.getLength() -3 , 3, "urd");
114 OString
const outputFileUrl
= convertToFileUrl(outputFile
);
117 if (options
.isValid("-M")) {
118 depFileUrl
= convertToFileUrl(options
.getOption("-M"));
119 if (!depFileUrl
.endsWith("/")) {
122 depFileUrl
+= strippedFileName
.replaceAt(
123 strippedFileName
.getLength() -3 , 3, "d");
127 if (options
.isValid("-M")) {
128 removeIfExists(depFileUrl
);
130 removeIfExists(outputFileUrl
);
132 sPair_t
const pair(depFileUrl
, outputFile
);
133 nErrors
= produceFile(outputFileUrl
,
134 (options
.isValid("-M")) ? &pair
: nullptr);
142 fprintf(stderr
, "%s: detected %" SAL_PRIdINT64
" errors%s",
143 options
.getProgramName().getStr(),
145 options
.prepareVersion().getStr());
148 if ( options
.verbose() )
149 fprintf(stdout
, "%s: returned successful%s",
150 options
.getProgramName().getStr(),
151 options
.prepareVersion().getStr());
153 } catch(const IllegalArgument
& e
)
155 fprintf(stderr
, "Illegal argument: %s\n%s",
156 e
.m_message
.getStr(),
157 options
.prepareVersion().getStr());
164 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */