Teach symstore more duplicated DLLs
[LibreOffice.git] / idl / source / prj / svidl.cxx
blob91ad73d193369f28cb58c3c72a4778924023ebd9
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #include <stdlib.h>
22 #include <stdio.h>
23 #include <database.hxx>
24 #include <globals.hxx>
25 #include <command.hxx>
26 #include <rtl/ustring.hxx>
27 #include <osl/file.hxx>
28 #include <memory>
30 #define BR 0x8000
31 static bool FileMove_Impl( const OUString & rFile1, const OUString & rFile2, bool bMoveAlways )
33 //printf( "Move from %s to %s\n", rFile2.GetStr(), rFile1.GetStr() );
34 sal_uLong nC1 = 0;
35 sal_uLong nC2 = 1;
36 if( !bMoveAlways )
38 SvFileStream aOutStm1( rFile1, StreamMode::STD_READ );
39 SvFileStream aOutStm2( rFile2, StreamMode::STD_READ );
40 if( aOutStm1.GetError() == ERRCODE_NONE )
42 std::unique_ptr<sal_uInt8[]> pBuf1(new sal_uInt8[ BR ]);
43 std::unique_ptr<sal_uInt8[]> pBuf2(new sal_uInt8[ BR ]);
44 nC1 = aOutStm1.ReadBytes(pBuf1.get(), BR);
45 nC2 = aOutStm2.ReadBytes(pBuf2.get(), BR);
46 while( nC1 == nC2 )
48 if( memcmp( pBuf1.get(), pBuf2.get(), nC1 ) )
50 nC1++;
51 break;
53 else
55 if( 0x8000 != nC1 )
56 break;
57 nC1 = aOutStm1.ReadBytes(pBuf1.get(), BR);
58 nC2 = aOutStm2.ReadBytes(pBuf2.get(), BR);
63 OUString fileURL2;
64 osl::FileBase::getFileURLFromSystemPath( rFile2, fileURL2 );
65 if( nC1 != nC2 )
66 {// something has changed
67 OUString fileURL1;
68 osl::FileBase::getFileURLFromSystemPath( rFile1, fileURL1 );
69 // move file
70 if( osl::FileBase::E_None != osl::File::move( fileURL2, fileURL1 ) )
72 // delete both files
73 osl::File::remove( fileURL1 );
74 osl::File::remove( fileURL2 );
75 return false;
77 return true;
79 return osl::FileBase::E_None == osl::File::remove( fileURL2 );
82 //This function gets a system path to a file [fname], creates a temp file in
83 //the same folder as [fname] and returns the system path of the temp file.
84 static OUString tempFileHelper(OUString const & fname)
86 OUString aTmpFile;
88 sal_Int32 delimIndex = fname.lastIndexOf( '/' );
89 if( delimIndex > 0 )
91 OUString aTmpDir( fname.copy( 0, delimIndex ) );
92 osl::FileBase::getFileURLFromSystemPath( aTmpDir, aTmpDir );
93 osl::FileBase::createTempFile( &aTmpDir, nullptr, &aTmpFile );
94 osl::FileBase::getSystemPathFromFileURL( aTmpFile, aTmpFile );
96 else
98 OString aStr = "invalid filename: " +
99 OUStringToOString(fname, RTL_TEXTENCODING_UTF8);
100 fprintf(stderr, "%s\n", aStr.getStr());
102 return aTmpFile;
105 int main ( int argc, char ** argv)
107 OUString aTmpSlotMapFile;
108 OUString aTmpDepFile;
110 SvCommand aCommand( argc, argv );
112 if( aCommand.nVerbosity != 0 )
113 printf( "StarView Interface Definition Language (IDL) Compiler 3.0\n" );
115 Init();
116 std::unique_ptr<SvIdlWorkingBase> pDataBase( new SvIdlWorkingBase(aCommand));
118 int nExit = 0;
119 if( !aCommand.aExportFile.isEmpty() )
121 osl::DirectoryItem aDI;
122 osl::FileStatus fileStatus( osl_FileStatus_Mask_FileName );
123 (void)osl::DirectoryItem::get( aCommand.aExportFile, aDI );
124 (void)aDI.getFileStatus(fileStatus);
125 pDataBase->SetExportFile( fileStatus.getFileName() );
128 if( ReadIdl( pDataBase.get(), aCommand ) )
130 if( nExit == 0 && !aCommand.aSlotMapFile.isEmpty() )
132 aTmpSlotMapFile = tempFileHelper(aCommand.aSlotMapFile);
133 SvFileStream aOutStm( aTmpSlotMapFile, StreamMode::READWRITE | StreamMode::TRUNC );
134 if( !pDataBase->WriteSfx( aOutStm ) )
136 nExit = -1;
137 OString aStr = "cannot write slotmap file: " +
138 OUStringToOString(aCommand.aSlotMapFile, RTL_TEXTENCODING_UTF8);
139 fprintf(stderr, "%s\n", aStr.getStr());
142 if (nExit == 0 && !aCommand.m_DepFile.isEmpty())
144 aTmpDepFile = tempFileHelper(aCommand.m_DepFile);
145 SvFileStream aOutStm( aTmpDepFile, StreamMode::READWRITE | StreamMode::TRUNC );
146 pDataBase->WriteDepFile(aOutStm, aCommand.aTargetFile);
147 if( aOutStm.GetError() != ERRCODE_NONE )
149 nExit = -1;
150 fprintf( stderr, "cannot write dependency file: %s\n",
151 OUStringToOString( aCommand.m_DepFile,
152 RTL_TEXTENCODING_UTF8 ).getStr() );
156 else
157 nExit = -1;
159 if( nExit == 0 )
161 bool bErr = false;
162 bool bDoMove = aCommand.aTargetFile.isEmpty();
163 OUString aErrFile, aErrFile2;
164 if (!aCommand.aSlotMapFile.isEmpty())
166 bErr = !FileMove_Impl( aCommand.aSlotMapFile, aTmpSlotMapFile, bDoMove );
167 if( bErr ) {
168 aErrFile = aCommand.aSlotMapFile;
169 aErrFile2 = aTmpSlotMapFile;
172 if (!bErr && !aCommand.m_DepFile.isEmpty())
174 bErr |= !FileMove_Impl( aCommand.m_DepFile, aTmpDepFile, bDoMove );
175 if (bErr) {
176 aErrFile = aCommand.m_DepFile;
177 aErrFile2 = aTmpDepFile;
181 if( bErr )
183 nExit = -1;
184 OString aStr = "cannot move file from: " +
185 OUStringToOString(aErrFile2, RTL_TEXTENCODING_UTF8) +
186 "\n to file: " +
187 OUStringToOString(aErrFile, RTL_TEXTENCODING_UTF8);
188 fprintf( stderr, "%s\n", aStr.getStr() );
190 else
192 if( !aCommand.aTargetFile.isEmpty() )
194 // stamp file, because idl passed through correctly
195 SvFileStream aOutStm( aCommand.aTargetFile,
196 StreamMode::READWRITE | StreamMode::TRUNC );
201 if( nExit != 0 )
203 if( !aCommand.aSlotMapFile.isEmpty() )
205 osl::FileBase::getSystemPathFromFileURL( aTmpSlotMapFile, aTmpSlotMapFile );
206 osl::File::remove( aTmpSlotMapFile );
210 if( nExit != 0 )
211 fprintf( stderr, "svidl terminated with errors\n" );
212 return nExit;
215 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */