1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: idlcmain.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_idlc.hxx"
33 #include <idlc/idlc.hxx>
36 using namespace ::rtl
;
38 SAL_IMPLEMENT_MAIN_WITH_ARGS(argc
, argv
)
44 if (!options
.initOptions(argc
, argv
))
47 catch( IllegalArgument
& e
)
49 fprintf(stderr
, "Illegal argument: %s\n%s",
51 options
.prepareVersion().getStr());
57 sal_Int32 nErrors
= 0;
58 if (options
.readStdin()) {
60 stdout
, "%s: compile stdin...\n",
61 options
.getProgramName().getStr());
62 nErrors
= compileFile(0);
63 if (idlc()->getWarningCount() > 0) {
65 stdout
, "%s: detected %lu warnings compiling stdin\n",
66 options
.getProgramName().getStr(),
67 sal::static_int_cast
< unsigned long >(
68 idlc()->getWarningCount()));
71 if (options
.isValid("-O")) {
72 outputUrl
= convertToFileUrl(options
.getOption("-O"));
73 if (outputUrl
[outputUrl
.getLength() - 1] != '/') {
76 outputUrl
+= "stdin.urd";
78 outputUrl
= convertToFileUrl("stdin.urd");
81 removeIfExists(outputUrl
);
83 nErrors
= produceFile(outputUrl
);
87 StringVector
const & files
= options
.getInputFiles();
88 for (StringVector::const_iterator
i(files
.begin());
89 i
!= files
.end() && nErrors
== 0; ++i
)
91 OString
sysFileName( convertToAbsoluteSystemPath(*i
) );
93 fprintf(stdout
, "%s: compile '%s' ... \n",
94 options
.getProgramName().getStr(), (*i
).getStr());
95 nErrors
= compileFile(&sysFileName
);
97 if ( idlc()->getWarningCount() )
98 fprintf(stdout
, "%s: detected %lu warnings compiling file '%s'\n",
99 options
.getProgramName().getStr(),
100 sal::static_int_cast
< unsigned long >(
101 idlc()->getWarningCount()),
104 // prepare output file name
105 OString outputFileUrl
;
106 if ( options
.isValid("-O") )
108 OString
strippedFileName(sysFileName
.copy(sysFileName
.lastIndexOf(SEPARATOR
) + 1));
109 outputFileUrl
= convertToFileUrl(options
.getOption("-O"));
110 sal_Char c
= outputFileUrl
.getStr()[outputFileUrl
.getLength()-1];
113 outputFileUrl
+= OString::valueOf('/');
115 outputFileUrl
+= strippedFileName
.replaceAt(strippedFileName
.getLength() -3 , 3, "urd");
118 outputFileUrl
= convertToFileUrl(sysFileName
.replaceAt(sysFileName
.getLength() -3 , 3, "urd"));
122 removeIfExists(outputFileUrl
);
124 nErrors
= produceFile(outputFileUrl
);
131 fprintf(stdout
, "%s: detected %ld errors%s",
132 options
.getProgramName().getStr(),
133 sal::static_int_cast
< long >(nErrors
),
134 options
.prepareVersion().getStr());