merge the formfield patch from ooo-build
[ooovba.git] / idlc / source / idlcmain.cxx
blobf9937070a173eb12897604f9f32736021626702a
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 if ( !options.quiet() )
60 fprintf(
61 stdout, "%s: Compiling stdin\n",
62 options.getProgramName().getStr());
63 nErrors = compileFile(0);
64 if ( ( idlc()->getWarningCount() > 0 ) && !options.quiet() ) {
65 fprintf(
66 stdout, "%s: detected %lu warnings compiling stdin\n",
67 options.getProgramName().getStr(),
68 sal::static_int_cast< unsigned long >(
69 idlc()->getWarningCount()));
71 OString outputUrl;
72 if (options.isValid("-O")) {
73 outputUrl = convertToFileUrl(options.getOption("-O"));
74 if (outputUrl[outputUrl.getLength() - 1] != '/') {
75 outputUrl += "/";
77 outputUrl += "stdin.urd";
78 } else {
79 outputUrl = convertToFileUrl("stdin.urd");
81 if (nErrors > 0) {
82 removeIfExists(outputUrl);
83 } else {
84 nErrors = produceFile(outputUrl);
86 idlc()->reset();
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() );
93 fflush( stdout );
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",
102 (*i).getStr());
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()),
110 (*i).getStr());
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];
120 if ( c != '/' )
121 outputFileUrl += OString::valueOf('/');
123 outputFileUrl += strippedFileName.replaceAt(strippedFileName.getLength() -3 , 3, "urd");
124 } else
126 outputFileUrl = convertToFileUrl(sysFileName.replaceAt(sysFileName.getLength() -3 , 3, "urd"));
129 if ( nErrors )
130 removeIfExists(outputFileUrl);
131 else
132 nErrors = produceFile(outputFileUrl);
134 idlc()->reset();
137 if ( nErrors > 0 )
139 fprintf(stderr, "%s: detected %ld errors%s",
140 options.getProgramName().getStr(),
141 sal::static_int_cast< long >(nErrors),
142 options.prepareVersion().getStr());
143 } else
145 if ( options.verbose() )
146 fprintf(stdout, "%s: returned successful%s",
147 options.getProgramName().getStr(),
148 options.prepareVersion().getStr());
150 return nErrors;