update dev300-m57
[ooovba.git] / idlc / source / idlcmain.cxx
blobaa53b08b4a5ab2b822866c06cc4d9faa26034d82
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: idlcmain.cxx,v $
10 * $Revision: 1.17 $
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>
34 #include "sal/main.h"
36 using namespace ::rtl;
38 SAL_IMPLEMENT_MAIN_WITH_ARGS(argc, argv)
40 Options options;
42 try
44 if (!options.initOptions(argc, argv))
45 exit(1);
47 catch( IllegalArgument& e)
49 fprintf(stderr, "Illegal argument: %s\n%s",
50 e.m_message.getStr(),
51 options.prepareVersion().getStr());
52 exit(99);
55 setIdlc(&options);
57 sal_Int32 nErrors = 0;
58 if (options.readStdin()) {
59 fprintf(
60 stdout, "%s: compile stdin...\n",
61 options.getProgramName().getStr());
62 nErrors = compileFile(0);
63 if (idlc()->getWarningCount() > 0) {
64 fprintf(
65 stdout, "%s: detected %lu warnings compiling stdin\n",
66 options.getProgramName().getStr(),
67 sal::static_int_cast< unsigned long >(
68 idlc()->getWarningCount()));
70 OString outputUrl;
71 if (options.isValid("-O")) {
72 outputUrl = convertToFileUrl(options.getOption("-O"));
73 if (outputUrl[outputUrl.getLength() - 1] != '/') {
74 outputUrl += "/";
76 outputUrl += "stdin.urd";
77 } else {
78 outputUrl = convertToFileUrl("stdin.urd");
80 if (nErrors > 0) {
81 removeIfExists(outputUrl);
82 } else {
83 nErrors = produceFile(outputUrl);
85 idlc()->reset();
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()),
102 (*i).getStr());
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];
112 if ( c != '/' )
113 outputFileUrl += OString::valueOf('/');
115 outputFileUrl += strippedFileName.replaceAt(strippedFileName.getLength() -3 , 3, "urd");
116 } else
118 outputFileUrl = convertToFileUrl(sysFileName.replaceAt(sysFileName.getLength() -3 , 3, "urd"));
121 if ( nErrors )
122 removeIfExists(outputFileUrl);
123 else
124 nErrors = produceFile(outputFileUrl);
126 idlc()->reset();
129 if ( nErrors > 0 )
131 fprintf(stdout, "%s: detected %ld errors%s",
132 options.getProgramName().getStr(),
133 sal::static_int_cast< long >(nErrors),
134 options.prepareVersion().getStr());
136 return nErrors;