Bump version to 4.3-4
[LibreOffice.git] / idlc / source / idlcmain.cxx
blob52e05f0eb24720bfe701a6642950790995b498a7
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 "idlc/idlc.hxx"
22 #include <sal/main.h>
24 #include <string.h>
26 using namespace ::rtl;
28 SAL_IMPLEMENT_MAIN_WITH_ARGS(argc, argv)
30 std::vector< std::string > args;
31 for (int i = 1; i < argc; i++)
33 if (!Options::checkArgument (args, argv[i], strlen(argv[i])))
34 return (1);
37 Options options(argv[0]);
38 try
40 if (!options.initOptions(args))
41 return (0);
43 catch(const IllegalArgument& e)
45 fprintf(stderr, "Illegal argument: %s\n%s",
46 e.m_message.getStr(),
47 options.prepareVersion().getStr());
48 return (99);
51 setIdlc(&options);
53 sal_Int32 nErrors = 0;
54 if (options.readStdin()) {
55 if ( !options.quiet() )
56 fprintf(
57 stdout, "%s: Compiling stdin\n",
58 options.getProgramName().getStr());
59 nErrors = compileFile(0);
60 if ( ( idlc()->getWarningCount() > 0 ) && !options.quiet() ) {
61 fprintf(
62 stdout, "%s: detected %lu warnings compiling stdin\n",
63 options.getProgramName().getStr(),
64 sal::static_int_cast< unsigned long >(
65 idlc()->getWarningCount()));
67 OString outputUrl;
68 if (options.isValid("-O")) {
69 outputUrl = convertToFileUrl(options.getOption("-O"));
70 if (!outputUrl.endsWith("/")) {
71 outputUrl += "/";
73 outputUrl += "stdin.urd";
74 } else {
75 outputUrl = convertToFileUrl("stdin.urd");
77 if (nErrors > 0) {
78 removeIfExists(outputUrl);
79 } else {
80 nErrors = produceFile(outputUrl, 0);
82 idlc()->reset();
84 StringVector const & files = options.getInputFiles();
85 if ( options.verbose() )
87 fprintf( stdout, "%s: compiling %i source files ... \n",
88 options.getProgramName().getStr(), (int)files.size() );
89 fflush( stdout );
91 for (StringVector::const_iterator i(files.begin());
92 i != files.end() && nErrors == 0; ++i)
94 OString sysFileName( convertToAbsoluteSystemPath(*i) );
96 if ( !options.quiet() )
97 fprintf(stdout, "Compiling: %s\n",
98 (*i).getStr());
99 nErrors = compileFile(&sysFileName);
101 if ( idlc()->getWarningCount() && !options.quiet() )
102 fprintf(stdout, "%s: detected %lu warnings compiling file '%s'\n",
103 options.getProgramName().getStr(),
104 sal::static_int_cast< unsigned long >(
105 idlc()->getWarningCount()),
106 (*i).getStr());
108 // prepare output file name
109 OString const strippedFileName(
110 sysFileName.copy(sysFileName.lastIndexOf(SEPARATOR) + 1));
111 OString outputFile;
112 if ( options.isValid("-O") )
114 outputFile = (options.getOption("-O"));
115 if (!outputFile.endsWith("/")) {
116 outputFile += OString('/');
118 outputFile += strippedFileName.replaceAt(
119 strippedFileName.getLength() -3 , 3, "urd");
120 } else {
121 outputFile =
122 sysFileName.replaceAt(sysFileName.getLength() -3 , 3, "urd");
124 OString const outputFileUrl = convertToFileUrl(outputFile);
126 OString depFileUrl;
127 if (options.isValid("-M")) {
128 depFileUrl = convertToFileUrl(options.getOption("-M"));
129 if (!depFileUrl.endsWith("/")) {
130 depFileUrl += "/";
132 depFileUrl += strippedFileName.replaceAt(
133 strippedFileName.getLength() -3 , 3, "d");
136 if ( nErrors ) {
137 if (options.isValid("-M")) {
138 removeIfExists(depFileUrl);
140 removeIfExists(outputFileUrl);
141 } else {
142 sPair_t const pair(depFileUrl, outputFile);
143 nErrors = produceFile(outputFileUrl,
144 (options.isValid("-M")) ? &pair : 0);
147 idlc()->reset();
150 if ( nErrors > 0 )
152 fprintf(stderr, "%s: detected %ld errors%s",
153 options.getProgramName().getStr(),
154 sal::static_int_cast< long >(nErrors),
155 options.prepareVersion().getStr());
156 } else
158 if ( options.verbose() )
159 fprintf(stdout, "%s: returned successful%s",
160 options.getProgramName().getStr(),
161 options.prepareVersion().getStr());
163 return nErrors;
166 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */