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 ************************************************************************/
32 #include <database.hxx>
33 #include <globals.hxx>
34 #include <command.hxx>
35 #include <tools/fsys.hxx>
36 #include <tools/string.hxx>
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() );
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
);
56 if( memcmp( pBuf1
, pBuf2
, nC1
) )
65 nC1
= aOutStm1
.Read( pBuf1
, BR
);
66 nC2
= aOutStm2
.Read( pBuf2
, BR
);
73 DirEntry
aF2( rFile2
);
75 {// something has changed
76 DirEntry
aF1( rFile1
);
79 if( aF2
.MoveTo( aF1
) )
88 return 0 == aF2
.Kill();
91 #if defined( UNX ) || defined (__MINGW32__)
92 int main ( int argc
, char ** argv
)
95 int cdecl main ( int argc
, char ** argv
)
100 String aTmpSlotMapFile
;
101 String aTmpSfxItemFile
;
102 String aTmpDataBaseFile
;
103 String aTmpCallingFile
;
107 String aTmpHelpIdFile
;
112 SvCommand
aCommand( argc
, argv
);
114 if( aCommand
.nVerbosity
!= 0 )
115 printf( "StarView Interface Definition Language (IDL) Compiler 3.0\n" );
118 SvIdlWorkingBase
* pDataBase
= new SvIdlWorkingBase(aCommand
);
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
);
133 aTmpDocuFile
= aDE
.GetPath().TempName().GetFull();
134 SvFileStream
aOutStm( aTmpDocuFile
, STREAM_READWRITE
| STREAM_TRUNC
);
135 if( !pDataBase
->WriteDocumentation( aOutStm
) )
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
);
148 aTmpListFile
= aDE
.GetPath().TempName().GetFull();
149 SvFileStream
aOutStm( aTmpListFile
, STREAM_READWRITE
| STREAM_TRUNC
);
150 if( !pDataBase
->WriteSvIdl( aOutStm
) )
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
);
163 aTmpSlotMapFile
= aDE
.GetPath().TempName().GetFull();
164 SvFileStream
aOutStm( aTmpSlotMapFile
, STREAM_READWRITE
| STREAM_TRUNC
);
165 if( !pDataBase
->WriteSfx( aOutStm
) )
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
);
178 aTmpHelpIdFile
= aDE
.GetPath().TempName().GetFull();
179 SvFileStream
aStm( aTmpHelpIdFile
, STREAM_READWRITE
| STREAM_TRUNC
);
180 if (!pDataBase
->WriteHelpIds( aStm
) )
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
);
193 aTmpCSVFile
= aDE
.GetPath().TempName().GetFull();
194 SvFileStream
aStm( aTmpCSVFile
, STREAM_READWRITE
| STREAM_TRUNC
);
195 if (!pDataBase
->WriteCSV( aStm
) )
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
);
208 aTmpSfxItemFile
= aDE
.GetPath().TempName().GetFull();
209 SvFileStream
aOutStm( aTmpSfxItemFile
, STREAM_READWRITE
| STREAM_TRUNC
);
210 if( !pDataBase
->WriteSfxItem( aOutStm
) )
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
);
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
)
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
);
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
)
245 fprintf( stderr
, "cannot write dependency file: %s\n",
246 ::rtl::OUStringToOString( aCommand
.m_DepFile
,
247 RTL_TEXTENCODING_UTF8
).getStr() );
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
);
263 aErrFile
= aCommand
.aListFile
;
264 aErrFile2
= aTmpListFile
;
267 if( !bErr
&& aCommand
.aSlotMapFile
.Len() )
269 bErr
|= !FileMove_Impl( aCommand
.aSlotMapFile
, aTmpSlotMapFile
, bDoMove
);
271 aErrFile
= aCommand
.aSlotMapFile
;
272 aErrFile2
= aTmpSlotMapFile
;
275 if( !bErr
&& aCommand
.aSfxItemFile
.Len() )
277 bErr
|= !FileMove_Impl( aCommand
.aSfxItemFile
, aTmpSfxItemFile
, bDoMove
);
279 aErrFile
= aCommand
.aSfxItemFile
;
280 aErrFile2
= aTmpSfxItemFile
;
283 if( !bErr
&& aCommand
.aDataBaseFile
.Len() )
285 bErr
|= !FileMove_Impl( aCommand
.aDataBaseFile
, aTmpDataBaseFile
, bDoMove
);
287 aErrFile
= aCommand
.aDataBaseFile
;
288 aErrFile2
= aTmpDataBaseFile
;
291 if( !bErr
&& aCommand
.aCallingFile
.Len() )
293 bErr
|= !FileMove_Impl( aCommand
.aCallingFile
, aTmpCallingFile
, bDoMove
);
295 aErrFile
= aCommand
.aCallingFile
;
296 aErrFile2
= aTmpCallingFile
;
299 if( !bErr
&& aCommand
.aCxxFile
.Len() )
301 bErr
|= !FileMove_Impl( aCommand
.aCxxFile
, aTmpCxxFile
, bDoMove
);
303 aErrFile
= aCommand
.aCxxFile
;
304 aErrFile2
= aTmpCxxFile
;
307 if( !bErr
&& aCommand
.aHxxFile
.Len() )
309 bErr
|= !FileMove_Impl( aCommand
.aHxxFile
, aTmpHxxFile
, bDoMove
);
311 aErrFile
= aCommand
.aHxxFile
;
312 aErrFile2
= aTmpHxxFile
;
315 if( !bErr
&& aCommand
.aHelpIdFile
.Len() )
317 bErr
|= !FileMove_Impl( aCommand
.aHelpIdFile
, aTmpHelpIdFile
, bDoMove
);
319 aErrFile
= aCommand
.aHelpIdFile
;
320 aErrFile2
= aTmpHelpIdFile
;
323 if( !bErr
&& aCommand
.aCSVFile
.Len() )
325 bErr
|= !FileMove_Impl( aCommand
.aCSVFile
, aTmpCSVFile
, bDoMove
);
327 aErrFile
= aCommand
.aCSVFile
;
328 aErrFile2
= aTmpCSVFile
;
331 if( !bErr
&& aCommand
.aDocuFile
.Len() )
333 bErr
|= !FileMove_Impl( aCommand
.aDocuFile
, aTmpDocuFile
, bDoMove
);
335 aErrFile
= aCommand
.aDocuFile
;
336 aErrFile2
= aTmpDocuFile
;
339 if (!bErr
&& !aCommand
.m_DepFile
.isEmpty())
341 bErr
|= !FileMove_Impl( aCommand
.m_DepFile
, aTmpDepFile
, bDoMove
);
343 aErrFile
= aCommand
.m_DepFile
;
344 aErrFile2
= aTmpDepFile
;
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() );
361 if( aCommand
.aTargetFile
.Len() )
364 DirEntry
aT(aCommand
.aTargetFile
);
367 // stamp file, because idl passed through correctly
368 SvFileStream
aOutStm( aCommand
.aTargetFile
,
369 STREAM_READWRITE
| STREAM_TRUNC
);
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();
395 fprintf( stderr
, "svidl terminated with errors\n" );
399 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */