Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 :
21 : #include <stdlib.h>
22 : #include <stdio.h>
23 : #include <database.hxx>
24 : #include <globals.hxx>
25 : #include <command.hxx>
26 : #include <tools/fsys.hxx>
27 : #include <tools/string.hxx>
28 :
29 : #define BR 0x8000
30 40 : sal_Bool FileMove_Impl( const String & rFile1, const String & rFile2, sal_Bool bImmerVerschieben )
31 : {
32 : //printf( "Move from %s to %s\n", rFile2.GetStr(), rFile1.GetStr() );
33 40 : sal_uLong nC1 = 0;
34 40 : sal_uLong nC2 = 1;
35 40 : if( !bImmerVerschieben )
36 : {
37 40 : SvFileStream aOutStm1( rFile1, STREAM_STD_READ );
38 40 : SvFileStream aOutStm2( rFile2, STREAM_STD_READ );
39 40 : if( aOutStm1.GetError() == SVSTREAM_OK )
40 : {
41 8 : sal_uInt8 * pBuf1 = new sal_uInt8[ BR ];
42 8 : sal_uInt8 * pBuf2 = new sal_uInt8[ BR ];
43 8 : nC1 = aOutStm1.Read( pBuf1, BR );
44 8 : nC2 = aOutStm2.Read( pBuf2, BR );
45 16 : while( nC1 == nC2 )
46 : {
47 0 : if( memcmp( pBuf1, pBuf2, nC1 ) )
48 : {
49 0 : nC1++;
50 0 : break;
51 : }
52 : else
53 : {
54 0 : if( 0x8000 != nC1 )
55 0 : break;
56 0 : nC1 = aOutStm1.Read( pBuf1, BR );
57 0 : nC2 = aOutStm2.Read( pBuf2, BR );
58 : }
59 : }
60 8 : delete[] pBuf1;
61 8 : delete[] pBuf2;
62 40 : }
63 : }
64 40 : DirEntry aF2( rFile2 );
65 40 : if( nC1 != nC2 )
66 : {// something has changed
67 40 : DirEntry aF1( rFile1 );
68 40 : aF1.Kill();
69 : // move file
70 40 : if( aF2.MoveTo( aF1 ) )
71 : {
72 : // delete both files
73 0 : aF1.Kill();
74 0 : aF2.Kill();
75 0 : return sal_False;
76 : }
77 40 : return sal_True;
78 : }
79 0 : return 0 == aF2.Kill();
80 : }
81 :
82 : #if defined( UNX ) || defined (__MINGW32__)
83 8 : int main ( int argc, char ** argv)
84 : {
85 : #else
86 : int cdecl main ( int argc, char ** argv)
87 : {
88 : #endif
89 :
90 8 : String aTmpListFile;
91 8 : String aTmpSlotMapFile;
92 8 : String aTmpSfxItemFile;
93 8 : String aTmpDataBaseFile;
94 8 : String aTmpCallingFile;
95 8 : String aTmpSrcFile;
96 8 : String aTmpCxxFile;
97 8 : String aTmpHxxFile;
98 8 : String aTmpHelpIdFile;
99 8 : String aTmpCSVFile;
100 8 : String aTmpDocuFile;
101 8 : String aTmpDepFile;
102 :
103 8 : SvCommand aCommand( argc, argv );
104 :
105 8 : if( aCommand.nVerbosity != 0 )
106 0 : printf( "StarView Interface Definition Language (IDL) Compiler 3.0\n" );
107 :
108 8 : Init();
109 8 : SvIdlWorkingBase * pDataBase = new SvIdlWorkingBase(aCommand);
110 :
111 8 : int nExit = 0;
112 8 : if( aCommand.aExportFile.Len() )
113 : {
114 8 : DirEntry aDE( aCommand.aExportFile );
115 8 : pDataBase->SetExportFile( aDE.GetName() );
116 : }
117 :
118 8 : if( ReadIdl( pDataBase, aCommand ) )
119 : {
120 8 : if( nExit == 0 && aCommand.aDocuFile.Len() )
121 : {
122 0 : DirEntry aDE( aCommand.aDocuFile );
123 0 : aDE.ToAbs();
124 0 : aTmpDocuFile = aDE.GetPath().TempName().GetFull();
125 0 : SvFileStream aOutStm( aTmpDocuFile, STREAM_READWRITE | STREAM_TRUNC );
126 0 : if( !pDataBase->WriteDocumentation( aOutStm ) )
127 : {
128 0 : nExit = -1;
129 0 : rtl::OStringBuffer aStr("cannot write documentation file: ");
130 : aStr.append(rtl::OUStringToOString(aCommand.aDocuFile,
131 0 : RTL_TEXTENCODING_UTF8));
132 0 : fprintf(stderr, "%s\n", aStr.getStr());
133 0 : }
134 : }
135 8 : if( nExit == 0 && aCommand.aListFile.Len() )
136 : {
137 8 : DirEntry aDE( aCommand.aListFile );
138 8 : aDE.ToAbs();
139 8 : aTmpListFile = aDE.GetPath().TempName().GetFull();
140 8 : SvFileStream aOutStm( aTmpListFile, STREAM_READWRITE | STREAM_TRUNC );
141 8 : if( !pDataBase->WriteSvIdl( aOutStm ) )
142 : {
143 0 : nExit = -1;
144 0 : rtl::OStringBuffer aStr("cannot write list file: ");
145 : aStr.append(rtl::OUStringToOString(aCommand.aListFile,
146 0 : RTL_TEXTENCODING_UTF8));
147 0 : fprintf(stderr, "%s\n", aStr.getStr());
148 8 : }
149 : }
150 8 : if( nExit == 0 && aCommand.aSlotMapFile.Len() )
151 : {
152 8 : DirEntry aDE( aCommand.aSlotMapFile );
153 8 : aDE.ToAbs();
154 8 : aTmpSlotMapFile = aDE.GetPath().TempName().GetFull();
155 8 : SvFileStream aOutStm( aTmpSlotMapFile, STREAM_READWRITE | STREAM_TRUNC );
156 8 : if( !pDataBase->WriteSfx( aOutStm ) )
157 : {
158 0 : nExit = -1;
159 0 : rtl::OStringBuffer aStr("cannot write slotmap file: ");
160 : aStr.append(rtl::OUStringToOString(aCommand.aSlotMapFile,
161 0 : RTL_TEXTENCODING_UTF8));
162 0 : fprintf(stderr, "%s\n", aStr.getStr());
163 8 : }
164 : }
165 8 : if( nExit == 0 && aCommand.aHelpIdFile.Len() )
166 : {
167 8 : DirEntry aDE( aCommand.aHelpIdFile );
168 8 : aDE.ToAbs();
169 8 : aTmpHelpIdFile = aDE.GetPath().TempName().GetFull();
170 8 : SvFileStream aStm( aTmpHelpIdFile, STREAM_READWRITE | STREAM_TRUNC );
171 8 : if (!pDataBase->WriteHelpIds( aStm ) )
172 : {
173 0 : nExit = -1;
174 0 : rtl::OStringBuffer aStr("cannot write help ID file: ");
175 : aStr.append(rtl::OUStringToOString(aCommand.aHelpIdFile,
176 0 : RTL_TEXTENCODING_UTF8));
177 0 : fprintf(stderr, "%s\n", aStr.getStr());
178 8 : }
179 : }
180 8 : if( nExit == 0 && aCommand.aCSVFile.Len() )
181 : {
182 0 : DirEntry aDE( aCommand.aCSVFile );
183 0 : aDE.ToAbs();
184 0 : aTmpCSVFile = aDE.GetPath().TempName().GetFull();
185 0 : SvFileStream aStm( aTmpCSVFile, STREAM_READWRITE | STREAM_TRUNC );
186 0 : if (!pDataBase->WriteCSV( aStm ) )
187 : {
188 0 : nExit = -1;
189 0 : rtl::OStringBuffer aStr("cannot write CSV file: ");
190 : aStr.append(rtl::OUStringToOString(aCommand.aCSVFile,
191 0 : RTL_TEXTENCODING_UTF8));
192 0 : fprintf(stderr, "%s\n", aStr.getStr());
193 0 : }
194 : }
195 8 : if( nExit == 0 && aCommand.aSfxItemFile.Len() )
196 : {
197 0 : DirEntry aDE( aCommand.aSfxItemFile );
198 0 : aDE.ToAbs();
199 0 : aTmpSfxItemFile = aDE.GetPath().TempName().GetFull();
200 0 : SvFileStream aOutStm( aTmpSfxItemFile, STREAM_READWRITE | STREAM_TRUNC );
201 0 : if( !pDataBase->WriteSfxItem( aOutStm ) )
202 : {
203 0 : nExit = -1;
204 0 : rtl::OStringBuffer aStr("cannot write item file: ");
205 : aStr.append(rtl::OUStringToOString(aCommand.aSfxItemFile,
206 0 : RTL_TEXTENCODING_UTF8));
207 0 : fprintf(stderr, "%s\n", aStr.getStr());
208 0 : }
209 : }
210 8 : if( nExit == 0 && aCommand.aDataBaseFile.Len() )
211 : {
212 8 : DirEntry aDE( aCommand.aDataBaseFile );
213 8 : aDE.ToAbs();
214 8 : aTmpDataBaseFile = aDE.GetPath().TempName().GetFull();
215 8 : SvFileStream aOutStm( aTmpDataBaseFile, STREAM_READWRITE | STREAM_TRUNC );
216 8 : pDataBase->Save( aOutStm, aCommand.nFlags );
217 8 : if( aOutStm.GetError() != SVSTREAM_OK )
218 : {
219 0 : nExit = -1;
220 0 : rtl::OStringBuffer aStr("cannot write database file: ");
221 : aStr.append(rtl::OUStringToOString(aCommand.aDataBaseFile,
222 0 : RTL_TEXTENCODING_UTF8));
223 0 : fprintf(stderr, "%s\n", aStr.getStr());
224 8 : }
225 : }
226 8 : if (nExit == 0 && !aCommand.m_DepFile.isEmpty())
227 : {
228 8 : DirEntry aDE(aCommand.m_DepFile);
229 8 : aDE.ToAbs();
230 8 : aTmpDepFile = aDE.GetPath().TempName().GetFull();
231 8 : SvFileStream aOutStm( aTmpDepFile, STREAM_READWRITE | STREAM_TRUNC );
232 8 : pDataBase->WriteDepFile(aOutStm, aCommand.aTargetFile);
233 8 : if( aOutStm.GetError() != SVSTREAM_OK )
234 : {
235 0 : nExit = -1;
236 : fprintf( stderr, "cannot write dependency file: %s\n",
237 : ::rtl::OUStringToOString( aCommand.m_DepFile,
238 0 : RTL_TEXTENCODING_UTF8 ).getStr() );
239 8 : }
240 : }
241 : }
242 : else
243 0 : nExit = -1;
244 :
245 8 : if( nExit == 0 )
246 : {
247 8 : sal_Bool bErr = sal_False;
248 8 : sal_Bool bDoMove = aCommand.aTargetFile.Len() == 0;
249 8 : String aErrFile, aErrFile2;
250 8 : if( !bErr && aCommand.aListFile.Len() )
251 : {
252 8 : bErr |= !FileMove_Impl( aCommand.aListFile, aTmpListFile, bDoMove );
253 8 : if( bErr ) {
254 0 : aErrFile = aCommand.aListFile;
255 0 : aErrFile2 = aTmpListFile;
256 : }
257 : }
258 8 : if( !bErr && aCommand.aSlotMapFile.Len() )
259 : {
260 8 : bErr |= !FileMove_Impl( aCommand.aSlotMapFile, aTmpSlotMapFile, bDoMove );
261 8 : if( bErr ) {
262 0 : aErrFile = aCommand.aSlotMapFile;
263 0 : aErrFile2 = aTmpSlotMapFile;
264 : }
265 : }
266 8 : if( !bErr && aCommand.aSfxItemFile.Len() )
267 : {
268 0 : bErr |= !FileMove_Impl( aCommand.aSfxItemFile, aTmpSfxItemFile, bDoMove );
269 0 : if( bErr ) {
270 0 : aErrFile = aCommand.aSfxItemFile;
271 0 : aErrFile2 = aTmpSfxItemFile;
272 : }
273 : }
274 8 : if( !bErr && aCommand.aDataBaseFile.Len() )
275 : {
276 8 : bErr |= !FileMove_Impl( aCommand.aDataBaseFile, aTmpDataBaseFile, bDoMove );
277 8 : if( bErr ) {
278 0 : aErrFile = aCommand.aDataBaseFile;
279 0 : aErrFile2 = aTmpDataBaseFile;
280 : }
281 : }
282 8 : if( !bErr && aCommand.aCallingFile.Len() )
283 : {
284 0 : bErr |= !FileMove_Impl( aCommand.aCallingFile, aTmpCallingFile, bDoMove );
285 0 : if( bErr ) {
286 0 : aErrFile = aCommand.aCallingFile;
287 0 : aErrFile2 = aTmpCallingFile;
288 : }
289 : }
290 8 : if( !bErr && aCommand.aCxxFile.Len() )
291 : {
292 0 : bErr |= !FileMove_Impl( aCommand.aCxxFile, aTmpCxxFile, bDoMove );
293 0 : if( bErr ) {
294 0 : aErrFile = aCommand.aCxxFile;
295 0 : aErrFile2 = aTmpCxxFile;
296 : }
297 : }
298 8 : if( !bErr && aCommand.aHxxFile.Len() )
299 : {
300 0 : bErr |= !FileMove_Impl( aCommand.aHxxFile, aTmpHxxFile, bDoMove );
301 0 : if( bErr ) {
302 0 : aErrFile = aCommand.aHxxFile;
303 0 : aErrFile2 = aTmpHxxFile;
304 : }
305 : }
306 8 : if( !bErr && aCommand.aHelpIdFile.Len() )
307 : {
308 8 : bErr |= !FileMove_Impl( aCommand.aHelpIdFile, aTmpHelpIdFile, bDoMove );
309 8 : if( bErr ) {
310 0 : aErrFile = aCommand.aHelpIdFile;
311 0 : aErrFile2 = aTmpHelpIdFile;
312 : }
313 : }
314 8 : if( !bErr && aCommand.aCSVFile.Len() )
315 : {
316 0 : bErr |= !FileMove_Impl( aCommand.aCSVFile, aTmpCSVFile, bDoMove );
317 0 : if( bErr ) {
318 0 : aErrFile = aCommand.aCSVFile;
319 0 : aErrFile2 = aTmpCSVFile;
320 : }
321 : }
322 8 : if( !bErr && aCommand.aDocuFile.Len() )
323 : {
324 0 : bErr |= !FileMove_Impl( aCommand.aDocuFile, aTmpDocuFile, bDoMove );
325 0 : if( bErr ) {
326 0 : aErrFile = aCommand.aDocuFile;
327 0 : aErrFile2 = aTmpDocuFile;
328 : }
329 : }
330 8 : if (!bErr && !aCommand.m_DepFile.isEmpty())
331 : {
332 8 : bErr |= !FileMove_Impl( aCommand.m_DepFile, aTmpDepFile, bDoMove );
333 8 : if (bErr) {
334 0 : aErrFile = aCommand.m_DepFile;
335 0 : aErrFile2 = aTmpDepFile;
336 : }
337 : }
338 :
339 8 : if( bErr )
340 : {
341 0 : nExit = -1;
342 0 : rtl::OStringBuffer aStr("cannot move file from: ");
343 : aStr.append(rtl::OUStringToOString(aErrFile2,
344 0 : RTL_TEXTENCODING_UTF8));
345 0 : aStr.append("\n to file: ");
346 : aStr.append(rtl::OUStringToOString(aErrFile,
347 0 : RTL_TEXTENCODING_UTF8));
348 0 : fprintf( stderr, "%s\n", aStr.getStr() );
349 : }
350 : else
351 : {
352 8 : if( aCommand.aTargetFile.Len() )
353 : {
354 : #ifdef ICC
355 : DirEntry aT(aCommand.aTargetFile);
356 : aT.Kill();
357 : #endif
358 : // stamp file, because idl passed through correctly
359 : SvFileStream aOutStm( aCommand.aTargetFile,
360 8 : STREAM_READWRITE | STREAM_TRUNC );
361 : }
362 8 : }
363 : }
364 :
365 8 : if( nExit != 0 )
366 : {
367 0 : if( aCommand.aListFile.Len() )
368 0 : DirEntry( aTmpListFile ).Kill();
369 0 : if( aCommand.aSlotMapFile.Len() )
370 0 : DirEntry( aTmpSlotMapFile ).Kill();
371 0 : if( aCommand.aSfxItemFile.Len() )
372 0 : DirEntry( aTmpSfxItemFile ).Kill();
373 0 : if( aCommand.aDataBaseFile.Len() )
374 0 : DirEntry( aTmpDataBaseFile ).Kill();
375 0 : if( aCommand.aCallingFile.Len() )
376 0 : DirEntry( aTmpCallingFile ).Kill();
377 0 : if( aCommand.aCxxFile.Len() )
378 0 : DirEntry( aTmpCxxFile ).Kill();
379 0 : if( aCommand.aHxxFile.Len() )
380 0 : DirEntry( aTmpHxxFile ).Kill();
381 : }
382 :
383 8 : delete pDataBase;
384 8 : DeInit();
385 8 : if( nExit != 0 )
386 0 : fprintf( stderr, "svidl terminated with errors\n" );
387 8 : return nExit;
388 : }
389 :
390 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|