xref: /trunk/main/idl/source/prj/svidl.cxx (revision 1ecadb572e7010ff3b3382ad9bf179dbc6efadbb)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_idl.hxx"
30 
31 #include <stdlib.h>
32 #include <stdio.h>
33 #include <database.hxx>
34 #include <globals.hxx>
35 #include <command.hxx>
36 #include <tools/fsys.hxx>
37 #include <tools/string.hxx>
38 
39 #define BR 0x8000
40 sal_Bool FileMove_Impl( const String & rFile1, const String & rFile2, sal_Bool bImmerVerschieben )
41 {
42     //printf( "Move from %s to %s\n", rFile2.GetStr(), rFile1.GetStr() );
43     sal_uLong nC1 = 0;
44     sal_uLong nC2 = 1;
45     if( !bImmerVerschieben )
46     {
47         SvFileStream aOutStm1( rFile1, STREAM_STD_READ );
48         SvFileStream aOutStm2( rFile2, STREAM_STD_READ );
49         if( aOutStm1.GetError() == SVSTREAM_OK )
50         {
51             sal_uInt8 * pBuf1 = new sal_uInt8[ BR ];
52             sal_uInt8 * pBuf2 = new sal_uInt8[ BR ];
53             nC1 = aOutStm1.Read( pBuf1, BR );
54             nC2 = aOutStm2.Read( pBuf2, BR );
55             while( nC1 == nC2 )
56             {
57                 if( memcmp( pBuf1, pBuf2, nC1 ) )
58                 {
59                     nC1++;
60                     break;
61                 }
62                 else
63                 {
64                     if( 0x8000 != nC1 )
65                         break;
66                     nC1 = aOutStm1.Read( pBuf1, BR );
67                     nC2 = aOutStm2.Read( pBuf2, BR );
68                 }
69             }
70             delete[] pBuf1;
71             delete[] pBuf2;
72         }
73     }
74     DirEntry aF2( rFile2 );
75     if( nC1 != nC2 )
76     {// es hat sich etwas geaendert
77         DirEntry aF1( rFile1 );
78         aF1.Kill();
79         // Datei verschieben
80         if( aF2.MoveTo( aF1 ) )
81         {
82             // Beide Dateien loeschen
83             aF1.Kill();
84             aF2.Kill();
85             return sal_False;
86         }
87 /*
88         else
89         {
90             printf( "%s to %s moved\n",
91                      rFile2.GetStr(), rFile1.GetStr() );
92         }
93 */
94         return sal_True;
95     }
96     return 0 == aF2.Kill();
97 }
98 
99 /*************************************************************************
100 |*    main()
101 |*
102 |*    Beschreibung
103 *************************************************************************/
104 #if defined( UNX ) || (defined( PM2 ) && defined( CSET )) || defined (WTC) || defined (MTW) || defined (__MINGW32__) || defined( OS2 )
105 int main ( int argc, char ** argv)
106 {
107 #else
108 int cdecl main ( int argc, char ** argv)
109 {
110 #endif
111 
112 /*
113     pStr = ::ResponseFile( &aCmdLine, argv, argc );
114     if( pStr )
115     {
116         printf( "Cannot open response file <%s>\n", pStr );
117         return( 1 );
118     };
119 */
120 
121     String aTmpListFile;
122     String aTmpSlotMapFile;
123     String aTmpSfxItemFile;
124     String aTmpDataBaseFile;
125     String aTmpCallingFile;
126     String aTmpSrcFile;
127     String aTmpCxxFile;
128     String aTmpHxxFile;
129     String aTmpHelpIdFile;
130     String aTmpCSVFile;
131     String aTmpDocuFile;
132 
133     SvCommand aCommand( argc, argv );
134 
135     if( aCommand.nVerbosity != 0 )
136         printf( "StarView Interface Definition Language (IDL) Compiler 3.0\n" );
137 
138     Init();
139     SvIdlWorkingBase * pDataBase = new SvIdlWorkingBase(aCommand);
140 
141     int nExit = 0;
142     if( aCommand.aExportFile.Len() )
143     {
144         DirEntry aDE( aCommand.aExportFile );
145         pDataBase->SetExportFile( aDE.GetName() );
146     }
147 
148     if( ReadIdl( pDataBase, aCommand ) )
149     {
150         if( nExit == 0 && aCommand.aDocuFile.Len() )
151         {
152             DirEntry aDE( aCommand.aDocuFile );
153             aDE.ToAbs();
154             aTmpDocuFile = aDE.GetPath().TempName().GetFull();
155             SvFileStream aOutStm( aTmpDocuFile, STREAM_READWRITE | STREAM_TRUNC );
156             if( !pDataBase->WriteDocumentation( aOutStm ) )
157             {
158                 nExit = -1;
159                 ByteString aStr = "cannot write documentation file: ";
160                 aStr += ByteString( aCommand.aDocuFile, RTL_TEXTENCODING_UTF8 );
161                 fprintf( stderr, "%s\n", aStr.GetBuffer() );
162             }
163         }
164         if( nExit == 0 && aCommand.aListFile.Len() )
165         {
166             DirEntry aDE( aCommand.aListFile );
167             aDE.ToAbs();
168             aTmpListFile = aDE.GetPath().TempName().GetFull();
169             SvFileStream aOutStm( aTmpListFile, STREAM_READWRITE | STREAM_TRUNC );
170             if( !pDataBase->WriteSvIdl( aOutStm ) )
171             {
172                 nExit = -1;
173                 ByteString aStr = "cannot write list file: ";
174                 aStr += ByteString( aCommand.aListFile, RTL_TEXTENCODING_UTF8 );
175                 fprintf( stderr, "%s\n", aStr.GetBuffer() );
176             }
177         }
178         if( nExit == 0 && aCommand.aSlotMapFile.Len() )
179         {
180             DirEntry aDE( aCommand.aSlotMapFile );
181             aDE.ToAbs();
182             aTmpSlotMapFile = aDE.GetPath().TempName().GetFull();
183             SvFileStream aOutStm( aTmpSlotMapFile, STREAM_READWRITE | STREAM_TRUNC );
184             if( !pDataBase->WriteSfx( aOutStm ) )
185             {
186                 nExit = -1;
187                 ByteString aStr = "cannot write slotmap file: ";
188                 aStr += ByteString( aCommand.aSlotMapFile, RTL_TEXTENCODING_UTF8 );
189                 fprintf( stderr, "%s\n", aStr.GetBuffer() );
190             }
191         }
192         if( nExit == 0 && aCommand.aHelpIdFile.Len() )
193         {
194             DirEntry aDE( aCommand.aHelpIdFile );
195             aDE.ToAbs();
196             aTmpHelpIdFile = aDE.GetPath().TempName().GetFull();
197             SvFileStream aStm( aTmpHelpIdFile, STREAM_READWRITE | STREAM_TRUNC );
198             if (!pDataBase->WriteHelpIds( aStm ) )
199             {
200                 nExit = -1;
201                 ByteString aStr = "cannot write help ID file: ";
202                 aStr += ByteString( aCommand.aHelpIdFile, RTL_TEXTENCODING_UTF8 );
203                 fprintf( stderr, "%s\n", aStr.GetBuffer() );
204             }
205         }
206         if( nExit == 0 && aCommand.aCSVFile.Len() )
207         {
208             DirEntry aDE( aCommand.aCSVFile );
209             aDE.ToAbs();
210             aTmpCSVFile = aDE.GetPath().TempName().GetFull();
211             SvFileStream aStm( aTmpCSVFile, STREAM_READWRITE | STREAM_TRUNC );
212             if (!pDataBase->WriteCSV( aStm ) )
213             {
214                 nExit = -1;
215                 ByteString aStr = "cannot write CSV file: ";
216                 aStr += ByteString( aCommand.aCSVFile, RTL_TEXTENCODING_UTF8 );
217                 fprintf( stderr, "%s\n", aStr.GetBuffer() );
218             }
219         }
220         if( nExit == 0 && aCommand.aSfxItemFile.Len() )
221         {
222             DirEntry aDE( aCommand.aSfxItemFile );
223             aDE.ToAbs();
224             aTmpSfxItemFile = aDE.GetPath().TempName().GetFull();
225             SvFileStream aOutStm( aTmpSfxItemFile, STREAM_READWRITE | STREAM_TRUNC );
226             if( !pDataBase->WriteSfxItem( aOutStm ) )
227             {
228                 nExit = -1;
229                 ByteString aStr = "cannot write item file: ";
230                 aStr += ByteString( aCommand.aSfxItemFile, RTL_TEXTENCODING_UTF8 );
231                 fprintf( stderr, "%s\n", aStr.GetBuffer() );
232             }
233         }
234         if( nExit == 0 && aCommand.aDataBaseFile.Len() )
235         {
236             DirEntry aDE( aCommand.aDataBaseFile );
237             aDE.ToAbs();
238             aTmpDataBaseFile = aDE.GetPath().TempName().GetFull();
239             SvFileStream aOutStm( aTmpDataBaseFile, STREAM_READWRITE | STREAM_TRUNC );
240             pDataBase->Save( aOutStm, aCommand.nFlags );
241             if( aOutStm.GetError() != SVSTREAM_OK )
242             {
243                 nExit = -1;
244                 ByteString aStr = "cannot write database file: ";
245                 aStr += ByteString( aCommand.aDataBaseFile, RTL_TEXTENCODING_UTF8 );
246                 fprintf( stderr, "%s\n", aStr.GetBuffer() );
247             }
248         }
249 /*
250         if( nExit == 0 && aCommand.aCallingFile.Len() )
251         {
252             DirEntry aDE( aCommand.aCallingFile );
253             aDE.ToAbs();
254             aTmpCallingFile = aDE.GetPath().TempName().GetFull();
255             SvFileStream aOutStm( aTmpCallingFile, STREAM_READWRITE | STREAM_TRUNC );
256             pDataBase->WriteSbx( aOutStm );
257             //pDataBase->Save( aOutStm, aCommand.nFlags | IDL_WRITE_CALLING );
258             if( aOutStm.GetError() != SVSTREAM_OK )
259             {
260                 nExit = -1;
261                 ByteString aStr = "cannot write calling file: ";
262                 aStr += aCommand.aCallingFile;
263                 fprintf( stderr, "%s\n", aStr.GetStr() );
264             }
265         }
266         if( nExit == 0 && aCommand.aCxxFile.Len() )
267         {
268             DirEntry aDE( aCommand.aCxxFile );
269             aDE.ToAbs();
270             aTmpCxxFile = aDE.GetPath().TempName().GetFull();
271             SvFileStream aOutStm( aTmpCxxFile, STREAM_READWRITE | STREAM_TRUNC );
272 
273             aOutStm << "#pragma hdrstop" << endl;
274             aOutStm << "#include <";
275             if( aCommand.aHxxFile.Len() )
276                 aOutStm << DirEntry(aCommand.aHxxFile).GetName().GetBuffer();
277             else
278             {
279                 DirEntry aDE( aCommand.aCxxFile );
280                 aDE.SetExtension( "hxx" );
281                 aOutStm << aDE.GetName().GetBuffer);
282             }
283             aOutStm << '>' << endl;
284             if( !pDataBase->WriteCxx( aOutStm ) )
285             {
286                 nExit = -1;
287                 ByteString aStr = "cannot write cxx file: ";
288                 aStr += ByteString( aCommand.aCxxFile, RTL_TEXTENCODING_UTF8 );
289                 fprintf( stderr, "%s\n", aStr.GetBuffer() );
290             }
291         }
292         if( nExit == 0 && aCommand.aHxxFile.Len() )
293         {
294             DirEntry aDE( aCommand.aHxxFile );
295             aDE.ToAbs();
296             aTmpHxxFile = aDE.GetPath().TempName().GetFull();
297             SvFileStream aOutStm( aTmpHxxFile, STREAM_READWRITE | STREAM_TRUNC );
298 
299             aOutStm << "#include <somisc.hxx>" << endl;
300             if( !pDataBase->WriteHxx( aOutStm ) )
301             {
302                 nExit = -1;
303                 ByteString aStr = "cannot write cxx file: ";
304                 aStr += ByteString( aCommand.aHxxFile, RTL_TEXTENCODING_UTF8 );
305                 fprintf( stderr, "%s\n", aStr.GetBuffer() );
306             }
307         }
308  */
309     }
310     else
311         nExit = -1;
312 
313     if( nExit == 0 )
314     {
315         sal_Bool bErr = sal_False;
316         sal_Bool bDoMove = aCommand.aTargetFile.Len() == 0;
317         String aErrFile, aErrFile2;
318         if( !bErr && aCommand.aListFile.Len() )
319         {
320             bErr |= !FileMove_Impl( aCommand.aListFile, aTmpListFile, bDoMove );
321             if( bErr ) {
322                 aErrFile = aCommand.aListFile;
323                 aErrFile2 = aTmpListFile;
324             }
325         }
326         if( !bErr && aCommand.aSlotMapFile.Len() )
327         {
328             bErr |= !FileMove_Impl( aCommand.aSlotMapFile, aTmpSlotMapFile, bDoMove );
329             if( bErr ) {
330                 aErrFile = aCommand.aSlotMapFile;
331                 aErrFile2 = aTmpSlotMapFile;
332             }
333         }
334         if( !bErr && aCommand.aSfxItemFile.Len() )
335         {
336             bErr |= !FileMove_Impl( aCommand.aSfxItemFile, aTmpSfxItemFile, bDoMove );
337             if( bErr ) {
338                 aErrFile = aCommand.aSfxItemFile;
339                 aErrFile2 = aTmpSfxItemFile;
340             }
341         }
342         if( !bErr && aCommand.aDataBaseFile.Len() )
343         {
344             bErr |= !FileMove_Impl( aCommand.aDataBaseFile, aTmpDataBaseFile, bDoMove );
345             if( bErr ) {
346                 aErrFile = aCommand.aDataBaseFile;
347                 aErrFile2 = aTmpDataBaseFile;
348             }
349         }
350         if( !bErr && aCommand.aCallingFile.Len() )
351         {
352             bErr |= !FileMove_Impl( aCommand.aCallingFile, aTmpCallingFile, bDoMove );
353             if( bErr ) {
354                 aErrFile = aCommand.aCallingFile;
355                 aErrFile2 = aTmpCallingFile;
356             }
357         }
358         if( !bErr && aCommand.aCxxFile.Len() )
359         {
360             bErr |= !FileMove_Impl( aCommand.aCxxFile, aTmpCxxFile, bDoMove );
361             if( bErr ) {
362                 aErrFile = aCommand.aCxxFile;
363                 aErrFile2 = aTmpCxxFile;
364             }
365         }
366         if( !bErr && aCommand.aHxxFile.Len() )
367         {
368             bErr |= !FileMove_Impl( aCommand.aHxxFile, aTmpHxxFile, bDoMove );
369             if( bErr ) {
370                 aErrFile = aCommand.aHxxFile;
371                 aErrFile2 = aTmpHxxFile;
372             }
373         }
374         if( !bErr && aCommand.aHelpIdFile.Len() )
375         {
376             bErr |= !FileMove_Impl( aCommand.aHelpIdFile, aTmpHelpIdFile, bDoMove );
377             if( bErr ) {
378                 aErrFile = aCommand.aHelpIdFile;
379                 aErrFile2 = aTmpHelpIdFile;
380             }
381         }
382         if( !bErr && aCommand.aCSVFile.Len() )
383         {
384             bErr |= !FileMove_Impl( aCommand.aCSVFile, aTmpCSVFile, bDoMove );
385             if( bErr ) {
386                 aErrFile = aCommand.aCSVFile;
387                 aErrFile2 = aTmpCSVFile;
388             }
389         }
390         if( !bErr && aCommand.aDocuFile.Len() )
391         {
392             bErr |= !FileMove_Impl( aCommand.aDocuFile, aTmpDocuFile, bDoMove );
393             if( bErr ) {
394                 aErrFile = aCommand.aDocuFile;
395                 aErrFile2 = aTmpDocuFile;
396             }
397         }
398 
399         if( bErr )
400         {
401             nExit = -1;
402             ByteString aStr = "cannot move file from: ";
403             aStr += ByteString( aErrFile2, RTL_TEXTENCODING_UTF8 );
404             aStr += "\n              to file: ";
405             aStr += ByteString( aErrFile, RTL_TEXTENCODING_UTF8 );
406             fprintf( stderr, "%s\n", aStr.GetBuffer() );
407         }
408         else
409         {
410             if( aCommand.aTargetFile.Len() )
411             {
412 #ifdef ICC
413                 DirEntry aT(aCommand.aTargetFile);
414                 aT.Kill();
415 #endif
416                 // Datei stempeln, da idl korrekt durchlaufen wurde
417                 SvFileStream aOutStm( aCommand.aTargetFile,
418                                 STREAM_READWRITE | STREAM_TRUNC );
419             }
420         }
421     }
422 
423     if( nExit != 0 )
424     {
425         if( aCommand.aListFile.Len() )
426             DirEntry( aTmpListFile ).Kill();
427         if( aCommand.aSlotMapFile.Len() )
428             DirEntry( aTmpSlotMapFile ).Kill();
429         if( aCommand.aSfxItemFile.Len() )
430             DirEntry( aTmpSfxItemFile ).Kill();
431         if( aCommand.aDataBaseFile.Len() )
432             DirEntry( aTmpDataBaseFile ).Kill();
433         if( aCommand.aCallingFile.Len() )
434             DirEntry( aTmpCallingFile ).Kill();
435         if( aCommand.aCxxFile.Len() )
436             DirEntry( aTmpCxxFile ).Kill();
437         if( aCommand.aHxxFile.Len() )
438             DirEntry( aTmpHxxFile ).Kill();
439     }
440 
441     delete pDataBase;
442     DeInit();
443     if( nExit != 0 )
444         fprintf( stderr, "svidl terminated with errors\n" );
445     return nExit;
446 }
447 
448