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