xref: /aoo41x/main/idlc/source/idlcmain.cxx (revision 2fe1ca3d)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_idlc.hxx"
26 
27 #include "idlc/idlc.hxx"
28 #include "sal/main.h"
29 
30 #include <string.h>
31 
32 using namespace ::rtl;
33 
SAL_IMPLEMENT_MAIN_WITH_ARGS(argc,argv)34 SAL_IMPLEMENT_MAIN_WITH_ARGS(argc, argv)
35 {
36     std::vector< std::string > args;
37     for (int i = 1; i < argc; i++)
38     {
39         if (!Options::checkArgument (args, argv[i], strlen(argv[i])))
40             return (1);
41     }
42 
43     Options options(argv[0]);
44     try
45     {
46         if (!options.initOptions(args))
47            return (0);
48     }
49     catch( IllegalArgument& e)
50     {
51         fprintf(stderr, "Illegal argument: %s\n%s",
52             e.m_message.getStr(),
53             options.prepareVersion().getStr());
54         return (99);
55     }
56 
57     setIdlc(&options);
58 
59     sal_Int32 nErrors = 0;
60     if (options.readStdin()) {
61         if ( !options.quiet() )
62             fprintf(
63                 stdout, "%s: Compiling stdin\n",
64                 options.getProgramName().getStr());
65         nErrors = compileFile(0);
66         if ( ( idlc()->getWarningCount() > 0 ) && !options.quiet() ) {
67             fprintf(
68                 stdout, "%s: detected %lu warnings compiling stdin\n",
69                 options.getProgramName().getStr(),
70                 sal::static_int_cast< unsigned long >(
71                     idlc()->getWarningCount()));
72         }
73         OString outputUrl;
74         if (options.isValid("-O")) {
75             outputUrl = convertToFileUrl(options.getOption("-O"));
76             if (outputUrl[outputUrl.getLength() - 1] != '/') {
77                 outputUrl += "/";
78             }
79             outputUrl += "stdin.urd";
80         } else {
81             outputUrl = convertToFileUrl("stdin.urd");
82         }
83         if (nErrors > 0) {
84             removeIfExists(outputUrl);
85         } else {
86             nErrors = produceFile(outputUrl);
87         }
88         idlc()->reset();
89     }
90     StringVector const & files = options.getInputFiles();
91     if ( options.verbose() )
92     {
93         fprintf( stdout, "%s: compiling %i source files ... \n",
94             options.getProgramName().getStr(), (int)files.size() );
95         fflush( stdout );
96     }
97     for (StringVector::const_iterator i(files.begin());
98          i != files.end() && nErrors == 0; ++i)
99     {
100         OString sysFileName( convertToAbsoluteSystemPath(*i) );
101 
102         if ( !options.quiet() )
103             fprintf(stdout, "Compiling: %s\n",
104                 (*i).getStr());
105         nErrors = compileFile(&sysFileName);
106 
107         if ( idlc()->getWarningCount() && !options.quiet() )
108             fprintf(stdout, "%s: detected %lu warnings compiling file '%s'\n",
109                     options.getProgramName().getStr(),
110                     sal::static_int_cast< unsigned long >(
111                         idlc()->getWarningCount()),
112                     (*i).getStr());
113 
114         // prepare output file name
115         OString outputFileUrl;
116         if ( options.isValid("-O") )
117         {
118             OString strippedFileName(sysFileName.copy(sysFileName.lastIndexOf(SEPARATOR) + 1));
119             outputFileUrl = convertToFileUrl(options.getOption("-O"));
120             sal_Char c = outputFileUrl.getStr()[outputFileUrl.getLength()-1];
121 
122             if ( c != '/' )
123                 outputFileUrl += OString::valueOf('/');
124 
125             outputFileUrl += strippedFileName.replaceAt(strippedFileName.getLength() -3 , 3, "urd");
126         } else
127         {
128             outputFileUrl = convertToFileUrl(sysFileName.replaceAt(sysFileName.getLength() -3 , 3, "urd"));
129         }
130 
131         if ( nErrors )
132             removeIfExists(outputFileUrl);
133         else
134             nErrors = produceFile(outputFileUrl);
135 
136         idlc()->reset();
137     }
138 
139     if ( nErrors > 0 )
140     {
141         fprintf(stderr, "%s: detected %ld errors%s",
142             options.getProgramName().getStr(),
143             sal::static_int_cast< long >(nErrors),
144             options.prepareVersion().getStr());
145     } else
146     {
147         if ( options.verbose() )
148             fprintf(stdout, "%s: returned successful%s",
149                 options.getProgramName().getStr(),
150                 options.prepareVersion().getStr());
151     }
152     return nErrors;
153 }
154