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()) {
59 if ( !options
.quiet() )
61 stdout
, "%s: Compiling stdin\n",
62 options
.getProgramName().getStr());
63 nErrors
= compileFile(0);
64 if ( ( idlc()->getWarningCount() > 0 ) && !options
.quiet() ) {
66 stdout
, "%s: detected %lu warnings compiling stdin\n",
67 options
.getProgramName().getStr(),
68 sal::static_int_cast
< unsigned long >(
69 idlc()->getWarningCount()));
72 if (options
.isValid("-O")) {
73 outputUrl
= convertToFileUrl(options
.getOption("-O"));
74 if (outputUrl
[outputUrl
.getLength() - 1] != '/') {
77 outputUrl
+= "stdin.urd";
79 outputUrl
= convertToFileUrl("stdin.urd");
82 removeIfExists(outputUrl
);
84 nErrors
= produceFile(outputUrl
);
88 StringVector
const & files
= options
.getInputFiles();
89 if ( options
.verbose() )
91 fprintf( stdout
, "%s: compiling %i source files ... \n",
92 options
.getProgramName().getStr(), (int)files
.size() );
95 for (StringVector::const_iterator
i(files
.begin());
96 i
!= files
.end() && nErrors
== 0; ++i
)
98 OString
sysFileName( convertToAbsoluteSystemPath(*i
) );
100 if ( !options
.quiet() )
101 fprintf(stdout
, "Compiling: %s\n",
103 nErrors
= compileFile(&sysFileName
);
105 if ( idlc()->getWarningCount() && !options
.quiet() )
106 fprintf(stdout
, "%s: detected %lu warnings compiling file '%s'\n",
107 options
.getProgramName().getStr(),
108 sal::static_int_cast
< unsigned long >(
109 idlc()->getWarningCount()),
112 // prepare output file name
113 OString outputFileUrl
;
114 if ( options
.isValid("-O") )
116 OString
strippedFileName(sysFileName
.copy(sysFileName
.lastIndexOf(SEPARATOR
) + 1));
117 outputFileUrl
= convertToFileUrl(options
.getOption("-O"));
118 sal_Char c
= outputFileUrl
.getStr()[outputFileUrl
.getLength()-1];
121 outputFileUrl
+= OString::valueOf('/');
123 outputFileUrl
+= strippedFileName
.replaceAt(strippedFileName
.getLength() -3 , 3, "urd");
126 outputFileUrl
= convertToFileUrl(sysFileName
.replaceAt(sysFileName
.getLength() -3 , 3, "urd"));
130 removeIfExists(outputFileUrl
);
132 nErrors
= produceFile(outputFileUrl
);
139 fprintf(stderr
, "%s: detected %ld errors%s",
140 options
.getProgramName().getStr(),
141 sal::static_int_cast
< long >(nErrors
),
142 options
.prepareVersion().getStr());
145 if ( options
.verbose() )
146 fprintf(stdout
, "%s: returned successful%s",
147 options
.getProgramName().getStr(),
148 options
.prepareVersion().getStr());