1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: svidl.cxx,v $
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_idl.hxx"
36 #include <database.hxx>
37 #include <globals.hxx>
38 #include <command.hxx>
39 #include <tools/fsys.hxx>
40 #include <tools/string.hxx>
43 BOOL
FileMove_Impl( const String
& rFile1
, const String
& rFile2
, BOOL bImmerVerschieben
)
45 //printf( "Move from %s to %s\n", rFile2.GetStr(), rFile1.GetStr() );
48 if( !bImmerVerschieben
)
50 SvFileStream
aOutStm1( rFile1
, STREAM_STD_READ
);
51 SvFileStream
aOutStm2( rFile2
, STREAM_STD_READ
);
52 if( aOutStm1
.GetError() == SVSTREAM_OK
)
54 BYTE
* pBuf1
= new BYTE
[ BR
];
55 BYTE
* pBuf2
= new BYTE
[ BR
];
56 nC1
= aOutStm1
.Read( pBuf1
, BR
);
57 nC2
= aOutStm2
.Read( pBuf2
, BR
);
60 if( memcmp( pBuf1
, pBuf2
, nC1
) )
69 nC1
= aOutStm1
.Read( pBuf1
, BR
);
70 nC2
= aOutStm2
.Read( pBuf2
, BR
);
77 DirEntry
aF2( rFile2
);
79 {// es hat sich etwas geaendert
80 DirEntry
aF1( rFile1
);
83 if( aF2
.MoveTo( aF1
) )
85 // Beide Dateien loeschen
93 printf( "%s to %s moved\n",
94 rFile2.GetStr(), rFile1.GetStr() );
99 return 0 == aF2
.Kill();
102 /*************************************************************************
106 *************************************************************************/
107 #if defined( UNX ) || (defined( PM2 ) && defined( CSET )) || defined (WTC) || defined (MTW) || defined (__MINGW32__) || defined( OS2 )
108 int main ( int argc
, char ** argv
)
111 int cdecl main ( int argc
, char ** argv
)
116 pStr = ::ResponseFile( &aCmdLine, argv, argc );
119 printf( "Cannot open response file <%s>\n", pStr );
125 String aTmpSlotMapFile
;
126 String aTmpSfxItemFile
;
127 String aTmpDataBaseFile
;
128 String aTmpCallingFile
;
132 String aTmpHelpIdFile
;
136 SvCommand
aCommand( argc
, argv
);
138 if( aCommand
.nVerbosity
!= 0 )
139 printf( "StarView Interface Definition Language (IDL) Compiler 3.0\n" );
142 SvIdlWorkingBase
* pDataBase
= new SvIdlWorkingBase(aCommand
);
145 if( aCommand
.aExportFile
.Len() )
147 DirEntry
aDE( aCommand
.aExportFile
);
148 pDataBase
->SetExportFile( aDE
.GetName() );
151 if( ReadIdl( pDataBase
, aCommand
) )
153 if( nExit
== 0 && aCommand
.aDocuFile
.Len() )
155 DirEntry
aDE( aCommand
.aDocuFile
);
157 aTmpDocuFile
= aDE
.GetPath().TempName().GetFull();
158 SvFileStream
aOutStm( aTmpDocuFile
, STREAM_READWRITE
| STREAM_TRUNC
);
159 if( !pDataBase
->WriteDocumentation( aOutStm
) )
162 ByteString aStr
= "cannot write documentation file: ";
163 aStr
+= ByteString( aCommand
.aDocuFile
, RTL_TEXTENCODING_UTF8
);
164 fprintf( stderr
, "%s\n", aStr
.GetBuffer() );
167 if( nExit
== 0 && aCommand
.aListFile
.Len() )
169 DirEntry
aDE( aCommand
.aListFile
);
171 aTmpListFile
= aDE
.GetPath().TempName().GetFull();
172 SvFileStream
aOutStm( aTmpListFile
, STREAM_READWRITE
| STREAM_TRUNC
);
173 if( !pDataBase
->WriteSvIdl( aOutStm
) )
176 ByteString aStr
= "cannot write list file: ";
177 aStr
+= ByteString( aCommand
.aListFile
, RTL_TEXTENCODING_UTF8
);
178 fprintf( stderr
, "%s\n", aStr
.GetBuffer() );
181 if( nExit
== 0 && aCommand
.aSlotMapFile
.Len() )
183 DirEntry
aDE( aCommand
.aSlotMapFile
);
185 aTmpSlotMapFile
= aDE
.GetPath().TempName().GetFull();
186 SvFileStream
aOutStm( aTmpSlotMapFile
, STREAM_READWRITE
| STREAM_TRUNC
);
187 if( !pDataBase
->WriteSfx( aOutStm
) )
190 ByteString aStr
= "cannot write slotmap file: ";
191 aStr
+= ByteString( aCommand
.aSlotMapFile
, RTL_TEXTENCODING_UTF8
);
192 fprintf( stderr
, "%s\n", aStr
.GetBuffer() );
195 if( nExit
== 0 && aCommand
.aHelpIdFile
.Len() )
197 DirEntry
aDE( aCommand
.aHelpIdFile
);
199 aTmpHelpIdFile
= aDE
.GetPath().TempName().GetFull();
200 SvFileStream
aStm( aTmpHelpIdFile
, STREAM_READWRITE
| STREAM_TRUNC
);
201 if (!pDataBase
->WriteHelpIds( aStm
) )
204 ByteString aStr
= "cannot write help ID file: ";
205 aStr
+= ByteString( aCommand
.aHelpIdFile
, RTL_TEXTENCODING_UTF8
);
206 fprintf( stderr
, "%s\n", aStr
.GetBuffer() );
209 if( nExit
== 0 && aCommand
.aCSVFile
.Len() )
211 DirEntry
aDE( aCommand
.aCSVFile
);
213 aTmpCSVFile
= aDE
.GetPath().TempName().GetFull();
214 SvFileStream
aStm( aTmpCSVFile
, STREAM_READWRITE
| STREAM_TRUNC
);
215 if (!pDataBase
->WriteCSV( aStm
) )
218 ByteString aStr
= "cannot write CSV file: ";
219 aStr
+= ByteString( aCommand
.aCSVFile
, RTL_TEXTENCODING_UTF8
);
220 fprintf( stderr
, "%s\n", aStr
.GetBuffer() );
223 if( nExit
== 0 && aCommand
.aSfxItemFile
.Len() )
225 DirEntry
aDE( aCommand
.aSfxItemFile
);
227 aTmpSfxItemFile
= aDE
.GetPath().TempName().GetFull();
228 SvFileStream
aOutStm( aTmpSfxItemFile
, STREAM_READWRITE
| STREAM_TRUNC
);
229 if( !pDataBase
->WriteSfxItem( aOutStm
) )
232 ByteString aStr
= "cannot write item file: ";
233 aStr
+= ByteString( aCommand
.aSfxItemFile
, RTL_TEXTENCODING_UTF8
);
234 fprintf( stderr
, "%s\n", aStr
.GetBuffer() );
237 if( nExit
== 0 && aCommand
.aDataBaseFile
.Len() )
239 DirEntry
aDE( aCommand
.aDataBaseFile
);
241 aTmpDataBaseFile
= aDE
.GetPath().TempName().GetFull();
242 SvFileStream
aOutStm( aTmpDataBaseFile
, STREAM_READWRITE
| STREAM_TRUNC
);
243 pDataBase
->Save( aOutStm
, aCommand
.nFlags
);
244 if( aOutStm
.GetError() != SVSTREAM_OK
)
247 ByteString aStr
= "cannot write database file: ";
248 aStr
+= ByteString( aCommand
.aDataBaseFile
, RTL_TEXTENCODING_UTF8
);
249 fprintf( stderr
, "%s\n", aStr
.GetBuffer() );
253 if( nExit == 0 && aCommand.aCallingFile.Len() )
255 DirEntry aDE( aCommand.aCallingFile );
257 aTmpCallingFile = aDE.GetPath().TempName().GetFull();
258 SvFileStream aOutStm( aTmpCallingFile, STREAM_READWRITE | STREAM_TRUNC );
259 pDataBase->WriteSbx( aOutStm );
260 //pDataBase->Save( aOutStm, aCommand.nFlags | IDL_WRITE_CALLING );
261 if( aOutStm.GetError() != SVSTREAM_OK )
264 ByteString aStr = "cannot write calling file: ";
265 aStr += aCommand.aCallingFile;
266 fprintf( stderr, "%s\n", aStr.GetStr() );
269 if( nExit == 0 && aCommand.aCxxFile.Len() )
271 DirEntry aDE( aCommand.aCxxFile );
273 aTmpCxxFile = aDE.GetPath().TempName().GetFull();
274 SvFileStream aOutStm( aTmpCxxFile, STREAM_READWRITE | STREAM_TRUNC );
276 aOutStm << "#pragma hdrstop" << endl;
277 aOutStm << "#include <";
278 if( aCommand.aHxxFile.Len() )
279 aOutStm << DirEntry(aCommand.aHxxFile).GetName().GetBuffer();
282 DirEntry aDE( aCommand.aCxxFile );
283 aDE.SetExtension( "hxx" );
284 aOutStm << aDE.GetName().GetBuffer);
286 aOutStm << '>' << endl;
287 if( !pDataBase->WriteCxx( aOutStm ) )
290 ByteString aStr = "cannot write cxx file: ";
291 aStr += ByteString( aCommand.aCxxFile, RTL_TEXTENCODING_UTF8 );
292 fprintf( stderr, "%s\n", aStr.GetBuffer() );
295 if( nExit == 0 && aCommand.aHxxFile.Len() )
297 DirEntry aDE( aCommand.aHxxFile );
299 aTmpHxxFile = aDE.GetPath().TempName().GetFull();
300 SvFileStream aOutStm( aTmpHxxFile, STREAM_READWRITE | STREAM_TRUNC );
302 aOutStm << "#include <somisc.hxx>" << endl;
303 if( !pDataBase->WriteHxx( aOutStm ) )
306 ByteString aStr = "cannot write cxx file: ";
307 aStr += ByteString( aCommand.aHxxFile, RTL_TEXTENCODING_UTF8 );
308 fprintf( stderr, "%s\n", aStr.GetBuffer() );
319 BOOL bDoMove
= aCommand
.aTargetFile
.Len() == 0;
320 String aErrFile
, aErrFile2
;
321 if( !bErr
&& aCommand
.aListFile
.Len() )
323 bErr
|= !FileMove_Impl( aCommand
.aListFile
, aTmpListFile
, bDoMove
);
325 aErrFile
= aCommand
.aListFile
;
326 aErrFile2
= aTmpListFile
;
329 if( !bErr
&& aCommand
.aSlotMapFile
.Len() )
331 bErr
|= !FileMove_Impl( aCommand
.aSlotMapFile
, aTmpSlotMapFile
, bDoMove
);
333 aErrFile
= aCommand
.aSlotMapFile
;
334 aErrFile2
= aTmpSlotMapFile
;
337 if( !bErr
&& aCommand
.aSfxItemFile
.Len() )
339 bErr
|= !FileMove_Impl( aCommand
.aSfxItemFile
, aTmpSfxItemFile
, bDoMove
);
341 aErrFile
= aCommand
.aSfxItemFile
;
342 aErrFile2
= aTmpSfxItemFile
;
345 if( !bErr
&& aCommand
.aDataBaseFile
.Len() )
347 bErr
|= !FileMove_Impl( aCommand
.aDataBaseFile
, aTmpDataBaseFile
, bDoMove
);
349 aErrFile
= aCommand
.aDataBaseFile
;
350 aErrFile2
= aTmpDataBaseFile
;
353 if( !bErr
&& aCommand
.aCallingFile
.Len() )
355 bErr
|= !FileMove_Impl( aCommand
.aCallingFile
, aTmpCallingFile
, bDoMove
);
357 aErrFile
= aCommand
.aCallingFile
;
358 aErrFile2
= aTmpCallingFile
;
361 if( !bErr
&& aCommand
.aCxxFile
.Len() )
363 bErr
|= !FileMove_Impl( aCommand
.aCxxFile
, aTmpCxxFile
, bDoMove
);
365 aErrFile
= aCommand
.aCxxFile
;
366 aErrFile2
= aTmpCxxFile
;
369 if( !bErr
&& aCommand
.aHxxFile
.Len() )
371 bErr
|= !FileMove_Impl( aCommand
.aHxxFile
, aTmpHxxFile
, bDoMove
);
373 aErrFile
= aCommand
.aHxxFile
;
374 aErrFile2
= aTmpHxxFile
;
377 if( !bErr
&& aCommand
.aHelpIdFile
.Len() )
379 bErr
|= !FileMove_Impl( aCommand
.aHelpIdFile
, aTmpHelpIdFile
, bDoMove
);
381 aErrFile
= aCommand
.aHelpIdFile
;
382 aErrFile2
= aTmpHelpIdFile
;
385 if( !bErr
&& aCommand
.aCSVFile
.Len() )
387 bErr
|= !FileMove_Impl( aCommand
.aCSVFile
, aTmpCSVFile
, bDoMove
);
389 aErrFile
= aCommand
.aCSVFile
;
390 aErrFile2
= aTmpCSVFile
;
393 if( !bErr
&& aCommand
.aDocuFile
.Len() )
395 bErr
|= !FileMove_Impl( aCommand
.aDocuFile
, aTmpDocuFile
, bDoMove
);
397 aErrFile
= aCommand
.aDocuFile
;
398 aErrFile2
= aTmpDocuFile
;
405 ByteString aStr
= "cannot move file from: ";
406 aStr
+= ByteString( aErrFile2
, RTL_TEXTENCODING_UTF8
);
407 aStr
+= "\n to file: ";
408 aStr
+= ByteString( aErrFile
, RTL_TEXTENCODING_UTF8
);
409 fprintf( stderr
, "%s\n", aStr
.GetBuffer() );
413 if( aCommand
.aTargetFile
.Len() )
416 DirEntry
aT(aCommand
.aTargetFile
);
419 // Datei stempeln, da idl korrekt durchlaufen wurde
420 SvFileStream
aOutStm( aCommand
.aTargetFile
,
421 STREAM_READWRITE
| STREAM_TRUNC
);
428 if( aCommand
.aListFile
.Len() )
429 DirEntry( aTmpListFile
).Kill();
430 if( aCommand
.aSlotMapFile
.Len() )
431 DirEntry( aTmpSlotMapFile
).Kill();
432 if( aCommand
.aSfxItemFile
.Len() )
433 DirEntry( aTmpSfxItemFile
).Kill();
434 if( aCommand
.aDataBaseFile
.Len() )
435 DirEntry( aTmpDataBaseFile
).Kill();
436 if( aCommand
.aCallingFile
.Len() )
437 DirEntry( aTmpCallingFile
).Kill();
438 if( aCommand
.aCxxFile
.Len() )
439 DirEntry( aTmpCxxFile
).Kill();
440 if( aCommand
.aHxxFile
.Len() )
441 DirEntry( aTmpHxxFile
).Kill();
447 fprintf( stderr
, "svidl terminated with errors\n" );