merge the formfield patch from ooo-build
[ooovba.git] / idl / source / prj / svidl.cxx
blob6dbd39ef9a49a4a7fc4e5d3be03d83170018421e
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: svidl.cxx,v $
10 * $Revision: 1.10 $
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"
34 #include <stdlib.h>
35 #include <stdio.h>
36 #include <database.hxx>
37 #include <globals.hxx>
38 #include <command.hxx>
39 #include <tools/fsys.hxx>
40 #include <tools/string.hxx>
42 #define BR 0x8000
43 BOOL FileMove_Impl( const String & rFile1, const String & rFile2, BOOL bImmerVerschieben )
45 //printf( "Move from %s to %s\n", rFile2.GetStr(), rFile1.GetStr() );
46 ULONG nC1 = 0;
47 ULONG nC2 = 1;
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 );
58 while( nC1 == nC2 )
60 if( memcmp( pBuf1, pBuf2, nC1 ) )
62 nC1++;
63 break;
65 else
67 if( 0x8000 != nC1 )
68 break;
69 nC1 = aOutStm1.Read( pBuf1, BR );
70 nC2 = aOutStm2.Read( pBuf2, BR );
73 delete[] pBuf1;
74 delete[] pBuf2;
77 DirEntry aF2( rFile2 );
78 if( nC1 != nC2 )
79 {// es hat sich etwas geaendert
80 DirEntry aF1( rFile1 );
81 aF1.Kill();
82 // Datei verschieben
83 if( aF2.MoveTo( aF1 ) )
85 // Beide Dateien loeschen
86 aF1.Kill();
87 aF2.Kill();
88 return FALSE;
91 else
93 printf( "%s to %s moved\n",
94 rFile2.GetStr(), rFile1.GetStr() );
97 return TRUE;
99 return 0 == aF2.Kill();
102 /*************************************************************************
103 |* main()
105 |* Beschreibung
106 *************************************************************************/
107 #if defined( UNX ) || (defined( PM2 ) && defined( CSET )) || defined (WTC) || defined (MTW) || defined (__MINGW32__) || defined( OS2 )
108 int main ( int argc, char ** argv)
110 #else
111 int cdecl main ( int argc, char ** argv)
113 #endif
116 pStr = ::ResponseFile( &aCmdLine, argv, argc );
117 if( pStr )
119 printf( "Cannot open response file <%s>\n", pStr );
120 return( 1 );
124 String aTmpListFile;
125 String aTmpSlotMapFile;
126 String aTmpSfxItemFile;
127 String aTmpDataBaseFile;
128 String aTmpCallingFile;
129 String aTmpSrcFile;
130 String aTmpCxxFile;
131 String aTmpHxxFile;
132 String aTmpHelpIdFile;
133 String aTmpCSVFile;
134 String aTmpDocuFile;
136 SvCommand aCommand( argc, argv );
138 if( aCommand.nVerbosity != 0 )
139 printf( "StarView Interface Definition Language (IDL) Compiler 3.0\n" );
141 Init();
142 SvIdlWorkingBase * pDataBase = new SvIdlWorkingBase(aCommand);
144 int nExit = 0;
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 );
156 aDE.ToAbs();
157 aTmpDocuFile = aDE.GetPath().TempName().GetFull();
158 SvFileStream aOutStm( aTmpDocuFile, STREAM_READWRITE | STREAM_TRUNC );
159 if( !pDataBase->WriteDocumentation( aOutStm ) )
161 nExit = -1;
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 );
170 aDE.ToAbs();
171 aTmpListFile = aDE.GetPath().TempName().GetFull();
172 SvFileStream aOutStm( aTmpListFile, STREAM_READWRITE | STREAM_TRUNC );
173 if( !pDataBase->WriteSvIdl( aOutStm ) )
175 nExit = -1;
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 );
184 aDE.ToAbs();
185 aTmpSlotMapFile = aDE.GetPath().TempName().GetFull();
186 SvFileStream aOutStm( aTmpSlotMapFile, STREAM_READWRITE | STREAM_TRUNC );
187 if( !pDataBase->WriteSfx( aOutStm ) )
189 nExit = -1;
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 );
198 aDE.ToAbs();
199 aTmpHelpIdFile = aDE.GetPath().TempName().GetFull();
200 SvFileStream aStm( aTmpHelpIdFile, STREAM_READWRITE | STREAM_TRUNC );
201 if (!pDataBase->WriteHelpIds( aStm ) )
203 nExit = -1;
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 );
212 aDE.ToAbs();
213 aTmpCSVFile = aDE.GetPath().TempName().GetFull();
214 SvFileStream aStm( aTmpCSVFile, STREAM_READWRITE | STREAM_TRUNC );
215 if (!pDataBase->WriteCSV( aStm ) )
217 nExit = -1;
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 );
226 aDE.ToAbs();
227 aTmpSfxItemFile = aDE.GetPath().TempName().GetFull();
228 SvFileStream aOutStm( aTmpSfxItemFile, STREAM_READWRITE | STREAM_TRUNC );
229 if( !pDataBase->WriteSfxItem( aOutStm ) )
231 nExit = -1;
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 );
240 aDE.ToAbs();
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 )
246 nExit = -1;
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 );
256 aDE.ToAbs();
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 )
263 nExit = -1;
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 );
272 aDE.ToAbs();
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();
280 else
282 DirEntry aDE( aCommand.aCxxFile );
283 aDE.SetExtension( "hxx" );
284 aOutStm << aDE.GetName().GetBuffer);
286 aOutStm << '>' << endl;
287 if( !pDataBase->WriteCxx( aOutStm ) )
289 nExit = -1;
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 );
298 aDE.ToAbs();
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 ) )
305 nExit = -1;
306 ByteString aStr = "cannot write cxx file: ";
307 aStr += ByteString( aCommand.aHxxFile, RTL_TEXTENCODING_UTF8 );
308 fprintf( stderr, "%s\n", aStr.GetBuffer() );
313 else
314 nExit = -1;
316 if( nExit == 0 )
318 BOOL bErr = FALSE;
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 );
324 if( bErr ) {
325 aErrFile = aCommand.aListFile;
326 aErrFile2 = aTmpListFile;
329 if( !bErr && aCommand.aSlotMapFile.Len() )
331 bErr |= !FileMove_Impl( aCommand.aSlotMapFile, aTmpSlotMapFile, bDoMove );
332 if( bErr ) {
333 aErrFile = aCommand.aSlotMapFile;
334 aErrFile2 = aTmpSlotMapFile;
337 if( !bErr && aCommand.aSfxItemFile.Len() )
339 bErr |= !FileMove_Impl( aCommand.aSfxItemFile, aTmpSfxItemFile, bDoMove );
340 if( bErr ) {
341 aErrFile = aCommand.aSfxItemFile;
342 aErrFile2 = aTmpSfxItemFile;
345 if( !bErr && aCommand.aDataBaseFile.Len() )
347 bErr |= !FileMove_Impl( aCommand.aDataBaseFile, aTmpDataBaseFile, bDoMove );
348 if( bErr ) {
349 aErrFile = aCommand.aDataBaseFile;
350 aErrFile2 = aTmpDataBaseFile;
353 if( !bErr && aCommand.aCallingFile.Len() )
355 bErr |= !FileMove_Impl( aCommand.aCallingFile, aTmpCallingFile, bDoMove );
356 if( bErr ) {
357 aErrFile = aCommand.aCallingFile;
358 aErrFile2 = aTmpCallingFile;
361 if( !bErr && aCommand.aCxxFile.Len() )
363 bErr |= !FileMove_Impl( aCommand.aCxxFile, aTmpCxxFile, bDoMove );
364 if( bErr ) {
365 aErrFile = aCommand.aCxxFile;
366 aErrFile2 = aTmpCxxFile;
369 if( !bErr && aCommand.aHxxFile.Len() )
371 bErr |= !FileMove_Impl( aCommand.aHxxFile, aTmpHxxFile, bDoMove );
372 if( bErr ) {
373 aErrFile = aCommand.aHxxFile;
374 aErrFile2 = aTmpHxxFile;
377 if( !bErr && aCommand.aHelpIdFile.Len() )
379 bErr |= !FileMove_Impl( aCommand.aHelpIdFile, aTmpHelpIdFile, bDoMove );
380 if( bErr ) {
381 aErrFile = aCommand.aHelpIdFile;
382 aErrFile2 = aTmpHelpIdFile;
385 if( !bErr && aCommand.aCSVFile.Len() )
387 bErr |= !FileMove_Impl( aCommand.aCSVFile, aTmpCSVFile, bDoMove );
388 if( bErr ) {
389 aErrFile = aCommand.aCSVFile;
390 aErrFile2 = aTmpCSVFile;
393 if( !bErr && aCommand.aDocuFile.Len() )
395 bErr |= !FileMove_Impl( aCommand.aDocuFile, aTmpDocuFile, bDoMove );
396 if( bErr ) {
397 aErrFile = aCommand.aDocuFile;
398 aErrFile2 = aTmpDocuFile;
402 if( bErr )
404 nExit = -1;
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() );
411 else
413 if( aCommand.aTargetFile.Len() )
415 #ifdef ICC
416 DirEntry aT(aCommand.aTargetFile);
417 aT.Kill();
418 #endif
419 // Datei stempeln, da idl korrekt durchlaufen wurde
420 SvFileStream aOutStm( aCommand.aTargetFile,
421 STREAM_READWRITE | STREAM_TRUNC );
426 if( nExit != 0 )
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();
444 delete pDataBase;
445 DeInit();
446 if( nExit != 0 )
447 fprintf( stderr, "svidl terminated with errors\n" );
448 return nExit;