Version 3.6.0.4, tag libreoffice-3.6.0.4
[LibreOffice.git] / idl / source / prj / svidl.cxx
blobc250f35bcf96c46660df14b68a20c61b41124944
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
30 #include <stdlib.h>
31 #include <stdio.h>
32 #include <database.hxx>
33 #include <globals.hxx>
34 #include <command.hxx>
35 #include <tools/fsys.hxx>
36 #include <tools/string.hxx>
38 #define BR 0x8000
39 sal_Bool FileMove_Impl( const String & rFile1, const String & rFile2, sal_Bool bImmerVerschieben )
41 //printf( "Move from %s to %s\n", rFile2.GetStr(), rFile1.GetStr() );
42 sal_uLong nC1 = 0;
43 sal_uLong nC2 = 1;
44 if( !bImmerVerschieben )
46 SvFileStream aOutStm1( rFile1, STREAM_STD_READ );
47 SvFileStream aOutStm2( rFile2, STREAM_STD_READ );
48 if( aOutStm1.GetError() == SVSTREAM_OK )
50 sal_uInt8 * pBuf1 = new sal_uInt8[ BR ];
51 sal_uInt8 * pBuf2 = new sal_uInt8[ BR ];
52 nC1 = aOutStm1.Read( pBuf1, BR );
53 nC2 = aOutStm2.Read( pBuf2, BR );
54 while( nC1 == nC2 )
56 if( memcmp( pBuf1, pBuf2, nC1 ) )
58 nC1++;
59 break;
61 else
63 if( 0x8000 != nC1 )
64 break;
65 nC1 = aOutStm1.Read( pBuf1, BR );
66 nC2 = aOutStm2.Read( pBuf2, BR );
69 delete[] pBuf1;
70 delete[] pBuf2;
73 DirEntry aF2( rFile2 );
74 if( nC1 != nC2 )
75 {// something has changed
76 DirEntry aF1( rFile1 );
77 aF1.Kill();
78 // move file
79 if( aF2.MoveTo( aF1 ) )
81 // delete both files
82 aF1.Kill();
83 aF2.Kill();
84 return sal_False;
86 return sal_True;
88 return 0 == aF2.Kill();
91 #if defined( UNX ) || defined (__MINGW32__)
92 int main ( int argc, char ** argv)
94 #else
95 int cdecl main ( int argc, char ** argv)
97 #endif
99 String aTmpListFile;
100 String aTmpSlotMapFile;
101 String aTmpSfxItemFile;
102 String aTmpDataBaseFile;
103 String aTmpCallingFile;
104 String aTmpSrcFile;
105 String aTmpCxxFile;
106 String aTmpHxxFile;
107 String aTmpHelpIdFile;
108 String aTmpCSVFile;
109 String aTmpDocuFile;
110 String aTmpDepFile;
112 SvCommand aCommand( argc, argv );
114 if( aCommand.nVerbosity != 0 )
115 printf( "StarView Interface Definition Language (IDL) Compiler 3.0\n" );
117 Init();
118 SvIdlWorkingBase * pDataBase = new SvIdlWorkingBase(aCommand);
120 int nExit = 0;
121 if( aCommand.aExportFile.Len() )
123 DirEntry aDE( aCommand.aExportFile );
124 pDataBase->SetExportFile( aDE.GetName() );
127 if( ReadIdl( pDataBase, aCommand ) )
129 if( nExit == 0 && aCommand.aDocuFile.Len() )
131 DirEntry aDE( aCommand.aDocuFile );
132 aDE.ToAbs();
133 aTmpDocuFile = aDE.GetPath().TempName().GetFull();
134 SvFileStream aOutStm( aTmpDocuFile, STREAM_READWRITE | STREAM_TRUNC );
135 if( !pDataBase->WriteDocumentation( aOutStm ) )
137 nExit = -1;
138 rtl::OStringBuffer aStr("cannot write documentation file: ");
139 aStr.append(rtl::OUStringToOString(aCommand.aDocuFile,
140 RTL_TEXTENCODING_UTF8));
141 fprintf(stderr, "%s\n", aStr.getStr());
144 if( nExit == 0 && aCommand.aListFile.Len() )
146 DirEntry aDE( aCommand.aListFile );
147 aDE.ToAbs();
148 aTmpListFile = aDE.GetPath().TempName().GetFull();
149 SvFileStream aOutStm( aTmpListFile, STREAM_READWRITE | STREAM_TRUNC );
150 if( !pDataBase->WriteSvIdl( aOutStm ) )
152 nExit = -1;
153 rtl::OStringBuffer aStr("cannot write list file: ");
154 aStr.append(rtl::OUStringToOString(aCommand.aListFile,
155 RTL_TEXTENCODING_UTF8));
156 fprintf(stderr, "%s\n", aStr.getStr());
159 if( nExit == 0 && aCommand.aSlotMapFile.Len() )
161 DirEntry aDE( aCommand.aSlotMapFile );
162 aDE.ToAbs();
163 aTmpSlotMapFile = aDE.GetPath().TempName().GetFull();
164 SvFileStream aOutStm( aTmpSlotMapFile, STREAM_READWRITE | STREAM_TRUNC );
165 if( !pDataBase->WriteSfx( aOutStm ) )
167 nExit = -1;
168 rtl::OStringBuffer aStr("cannot write slotmap file: ");
169 aStr.append(rtl::OUStringToOString(aCommand.aSlotMapFile,
170 RTL_TEXTENCODING_UTF8));
171 fprintf(stderr, "%s\n", aStr.getStr());
174 if( nExit == 0 && aCommand.aHelpIdFile.Len() )
176 DirEntry aDE( aCommand.aHelpIdFile );
177 aDE.ToAbs();
178 aTmpHelpIdFile = aDE.GetPath().TempName().GetFull();
179 SvFileStream aStm( aTmpHelpIdFile, STREAM_READWRITE | STREAM_TRUNC );
180 if (!pDataBase->WriteHelpIds( aStm ) )
182 nExit = -1;
183 rtl::OStringBuffer aStr("cannot write help ID file: ");
184 aStr.append(rtl::OUStringToOString(aCommand.aHelpIdFile,
185 RTL_TEXTENCODING_UTF8));
186 fprintf(stderr, "%s\n", aStr.getStr());
189 if( nExit == 0 && aCommand.aCSVFile.Len() )
191 DirEntry aDE( aCommand.aCSVFile );
192 aDE.ToAbs();
193 aTmpCSVFile = aDE.GetPath().TempName().GetFull();
194 SvFileStream aStm( aTmpCSVFile, STREAM_READWRITE | STREAM_TRUNC );
195 if (!pDataBase->WriteCSV( aStm ) )
197 nExit = -1;
198 rtl::OStringBuffer aStr("cannot write CSV file: ");
199 aStr.append(rtl::OUStringToOString(aCommand.aCSVFile,
200 RTL_TEXTENCODING_UTF8));
201 fprintf(stderr, "%s\n", aStr.getStr());
204 if( nExit == 0 && aCommand.aSfxItemFile.Len() )
206 DirEntry aDE( aCommand.aSfxItemFile );
207 aDE.ToAbs();
208 aTmpSfxItemFile = aDE.GetPath().TempName().GetFull();
209 SvFileStream aOutStm( aTmpSfxItemFile, STREAM_READWRITE | STREAM_TRUNC );
210 if( !pDataBase->WriteSfxItem( aOutStm ) )
212 nExit = -1;
213 rtl::OStringBuffer aStr("cannot write item file: ");
214 aStr.append(rtl::OUStringToOString(aCommand.aSfxItemFile,
215 RTL_TEXTENCODING_UTF8));
216 fprintf(stderr, "%s\n", aStr.getStr());
219 if( nExit == 0 && aCommand.aDataBaseFile.Len() )
221 DirEntry aDE( aCommand.aDataBaseFile );
222 aDE.ToAbs();
223 aTmpDataBaseFile = aDE.GetPath().TempName().GetFull();
224 SvFileStream aOutStm( aTmpDataBaseFile, STREAM_READWRITE | STREAM_TRUNC );
225 pDataBase->Save( aOutStm, aCommand.nFlags );
226 if( aOutStm.GetError() != SVSTREAM_OK )
228 nExit = -1;
229 rtl::OStringBuffer aStr("cannot write database file: ");
230 aStr.append(rtl::OUStringToOString(aCommand.aDataBaseFile,
231 RTL_TEXTENCODING_UTF8));
232 fprintf(stderr, "%s\n", aStr.getStr());
235 if (nExit == 0 && !aCommand.m_DepFile.isEmpty())
237 DirEntry aDE(aCommand.m_DepFile);
238 aDE.ToAbs();
239 aTmpDepFile = aDE.GetPath().TempName().GetFull();
240 SvFileStream aOutStm( aTmpDepFile, STREAM_READWRITE | STREAM_TRUNC );
241 pDataBase->WriteDepFile(aOutStm, aCommand.aTargetFile);
242 if( aOutStm.GetError() != SVSTREAM_OK )
244 nExit = -1;
245 fprintf( stderr, "cannot write dependency file: %s\n",
246 ::rtl::OUStringToOString( aCommand.m_DepFile,
247 RTL_TEXTENCODING_UTF8 ).getStr() );
251 else
252 nExit = -1;
254 if( nExit == 0 )
256 sal_Bool bErr = sal_False;
257 sal_Bool bDoMove = aCommand.aTargetFile.Len() == 0;
258 String aErrFile, aErrFile2;
259 if( !bErr && aCommand.aListFile.Len() )
261 bErr |= !FileMove_Impl( aCommand.aListFile, aTmpListFile, bDoMove );
262 if( bErr ) {
263 aErrFile = aCommand.aListFile;
264 aErrFile2 = aTmpListFile;
267 if( !bErr && aCommand.aSlotMapFile.Len() )
269 bErr |= !FileMove_Impl( aCommand.aSlotMapFile, aTmpSlotMapFile, bDoMove );
270 if( bErr ) {
271 aErrFile = aCommand.aSlotMapFile;
272 aErrFile2 = aTmpSlotMapFile;
275 if( !bErr && aCommand.aSfxItemFile.Len() )
277 bErr |= !FileMove_Impl( aCommand.aSfxItemFile, aTmpSfxItemFile, bDoMove );
278 if( bErr ) {
279 aErrFile = aCommand.aSfxItemFile;
280 aErrFile2 = aTmpSfxItemFile;
283 if( !bErr && aCommand.aDataBaseFile.Len() )
285 bErr |= !FileMove_Impl( aCommand.aDataBaseFile, aTmpDataBaseFile, bDoMove );
286 if( bErr ) {
287 aErrFile = aCommand.aDataBaseFile;
288 aErrFile2 = aTmpDataBaseFile;
291 if( !bErr && aCommand.aCallingFile.Len() )
293 bErr |= !FileMove_Impl( aCommand.aCallingFile, aTmpCallingFile, bDoMove );
294 if( bErr ) {
295 aErrFile = aCommand.aCallingFile;
296 aErrFile2 = aTmpCallingFile;
299 if( !bErr && aCommand.aCxxFile.Len() )
301 bErr |= !FileMove_Impl( aCommand.aCxxFile, aTmpCxxFile, bDoMove );
302 if( bErr ) {
303 aErrFile = aCommand.aCxxFile;
304 aErrFile2 = aTmpCxxFile;
307 if( !bErr && aCommand.aHxxFile.Len() )
309 bErr |= !FileMove_Impl( aCommand.aHxxFile, aTmpHxxFile, bDoMove );
310 if( bErr ) {
311 aErrFile = aCommand.aHxxFile;
312 aErrFile2 = aTmpHxxFile;
315 if( !bErr && aCommand.aHelpIdFile.Len() )
317 bErr |= !FileMove_Impl( aCommand.aHelpIdFile, aTmpHelpIdFile, bDoMove );
318 if( bErr ) {
319 aErrFile = aCommand.aHelpIdFile;
320 aErrFile2 = aTmpHelpIdFile;
323 if( !bErr && aCommand.aCSVFile.Len() )
325 bErr |= !FileMove_Impl( aCommand.aCSVFile, aTmpCSVFile, bDoMove );
326 if( bErr ) {
327 aErrFile = aCommand.aCSVFile;
328 aErrFile2 = aTmpCSVFile;
331 if( !bErr && aCommand.aDocuFile.Len() )
333 bErr |= !FileMove_Impl( aCommand.aDocuFile, aTmpDocuFile, bDoMove );
334 if( bErr ) {
335 aErrFile = aCommand.aDocuFile;
336 aErrFile2 = aTmpDocuFile;
339 if (!bErr && !aCommand.m_DepFile.isEmpty())
341 bErr |= !FileMove_Impl( aCommand.m_DepFile, aTmpDepFile, bDoMove );
342 if (bErr) {
343 aErrFile = aCommand.m_DepFile;
344 aErrFile2 = aTmpDepFile;
348 if( bErr )
350 nExit = -1;
351 rtl::OStringBuffer aStr("cannot move file from: ");
352 aStr.append(rtl::OUStringToOString(aErrFile2,
353 RTL_TEXTENCODING_UTF8));
354 aStr.append("\n to file: ");
355 aStr.append(rtl::OUStringToOString(aErrFile,
356 RTL_TEXTENCODING_UTF8));
357 fprintf( stderr, "%s\n", aStr.getStr() );
359 else
361 if( aCommand.aTargetFile.Len() )
363 #ifdef ICC
364 DirEntry aT(aCommand.aTargetFile);
365 aT.Kill();
366 #endif
367 // stamp file, because idl passed through correctly
368 SvFileStream aOutStm( aCommand.aTargetFile,
369 STREAM_READWRITE | STREAM_TRUNC );
374 if( nExit != 0 )
376 if( aCommand.aListFile.Len() )
377 DirEntry( aTmpListFile ).Kill();
378 if( aCommand.aSlotMapFile.Len() )
379 DirEntry( aTmpSlotMapFile ).Kill();
380 if( aCommand.aSfxItemFile.Len() )
381 DirEntry( aTmpSfxItemFile ).Kill();
382 if( aCommand.aDataBaseFile.Len() )
383 DirEntry( aTmpDataBaseFile ).Kill();
384 if( aCommand.aCallingFile.Len() )
385 DirEntry( aTmpCallingFile ).Kill();
386 if( aCommand.aCxxFile.Len() )
387 DirEntry( aTmpCxxFile ).Kill();
388 if( aCommand.aHxxFile.Len() )
389 DirEntry( aTmpHxxFile ).Kill();
392 delete pDataBase;
393 DeInit();
394 if( nExit != 0 )
395 fprintf( stderr, "svidl terminated with errors\n" );
396 return nExit;
399 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */