Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
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.
15 : : *
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).
21 : : *
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.
26 : : *
27 : : ************************************************************************/
28 : :
29 : :
30 : : #include <stdio.h>
31 : : #include <sal/main.h>
32 : : #include <osl/file.h>
33 : : #include <osl/thread.h>
34 : : #include <rtl/alloc.h>
35 : : #include <rtl/ustring.hxx>
36 : : #include <rtl/strbuf.hxx>
37 : :
38 : : #include "pdfparse.hxx"
39 : :
40 : : using namespace pdfparse;
41 : :
42 : : using ::rtl::OUString;
43 : : using ::rtl::OString;
44 : : using ::rtl::OStringBuffer;
45 : : using ::rtl::OStringToOUString;
46 : :
47 : 0 : void printHelp( const char* pExe )
48 : : {
49 : : fprintf( stdout,
50 : : "USAGE: %s [-h,--help]\n"
51 : : " %s [-pw, --password <password>] <inputfile> [<outputfile>]\n"
52 : : " %s <-a, --extract-add-streams> [-pw, --password <password>] <inputfile> [<outputfile>]\n"
53 : : " %s <-f, --extract-fonts> [-pw, --password <password>] <inputfile> [<outputfile>]\n"
54 : : " %s <-o, --extract-objects> <o0>[:<g0>][,<o1>[:g1][,...]] [-pw, --password <password>] <inputfile> [<outputfile>]\n"
55 : : " -h, --help: show help\n"
56 : : " -a, --extract-add-streams: extracts additional streams to outputfile_object\n"
57 : : " and prints the mimetype found to stdout\n"
58 : : " -f, --extract-fonts: extracts fonts (currently only type1 and truetype are supported\n"
59 : : " -o, --extract-objects: extracts object streams, the syntax of the argument is comma separated\n"
60 : : " object numbers, where object number and generation number are separated by \':\'\n"
61 : : " an omitted generation number defaults to 0\n"
62 : : " -pw, --password: use password for decryption\n"
63 : : "\n"
64 : : "note: -f, -a, -o and normal unzip operation are mutually exclusive\n"
65 : 0 : , pExe, pExe, pExe, pExe, pExe );
66 : 0 : }
67 : :
68 : : class FileEmitContext : public EmitContext
69 : : {
70 : : oslFileHandle m_aHandle;
71 : : oslFileHandle m_aReadHandle;
72 : : unsigned int m_nReadLen;
73 : :
74 : : void openReadFile( const char* pOrigName );
75 : :
76 : : public:
77 : : FileEmitContext( const char* pFileName, const char* pOrigName, const PDFContainer* pTop );
78 : : virtual ~FileEmitContext();
79 : :
80 : : virtual bool write( const void* pBuf, unsigned int nLen ) throw();
81 : : virtual unsigned int getCurPos() throw();
82 : : virtual bool copyOrigBytes( unsigned int nOrigOffset, unsigned int nLen ) throw();
83 : : virtual unsigned int readOrigBytes( unsigned int nOrigOffset, unsigned int nLen, void* pBuf ) throw();
84 : : };
85 : :
86 : 0 : FileEmitContext::FileEmitContext( const char* pFileName, const char* pOrigName, const PDFContainer* pTop )
87 : : : EmitContext( pTop ),
88 : : m_aHandle( NULL ),
89 : : m_aReadHandle( NULL ),
90 : 0 : m_nReadLen( 0 )
91 : : {
92 : 0 : OUString aSysFile( OStringToOUString( OString( pFileName ), osl_getThreadTextEncoding() ) );
93 : 0 : OUString aURL;
94 : 0 : if( osl_getFileURLFromSystemPath( aSysFile.pData, &aURL.pData ) != osl_File_E_None )
95 : : {
96 : 0 : fprintf( stderr, "filename conversion \"%s\" failed\n", pFileName );
97 : : return;
98 : : }
99 : :
100 : 0 : if( osl_openFile( aURL.pData, &m_aHandle, osl_File_OpenFlag_Write ) == osl_File_E_None )
101 : : {
102 : 0 : if( osl_setFileSize( m_aHandle, 0 ) != osl_File_E_None )
103 : : {
104 : 0 : fprintf( stderr, "could not truncate %s\n", pFileName );
105 : 0 : osl_closeFile( m_aHandle );
106 : 0 : m_aHandle = NULL;
107 : : }
108 : : }
109 : 0 : else if( osl_openFile( aURL.pData, &m_aHandle,
110 : 0 : osl_File_OpenFlag_Write |osl_File_OpenFlag_Create ) != osl_File_E_None )
111 : : {
112 : 0 : fprintf( stderr, "could not open %s\n", pFileName );
113 : : return;
114 : : }
115 : 0 : m_bDeflate = true;
116 : :
117 : 0 : openReadFile( pOrigName );
118 : : }
119 : :
120 : 0 : FileEmitContext::~FileEmitContext()
121 : : {
122 : 0 : if( m_aHandle )
123 : 0 : osl_closeFile( m_aHandle );
124 : 0 : if( m_aReadHandle )
125 : 0 : osl_closeFile( m_aReadHandle );
126 : 0 : }
127 : :
128 : 0 : void FileEmitContext::openReadFile( const char* pInFile )
129 : : {
130 : 0 : OUString aSysFile( OStringToOUString( OString( pInFile ), osl_getThreadTextEncoding() ) );
131 : 0 : OUString aURL;
132 : 0 : if( osl_getFileURLFromSystemPath( aSysFile.pData, &aURL.pData ) != osl_File_E_None )
133 : : {
134 : 0 : fprintf( stderr, "filename conversion \"%s\" failed\n", pInFile );
135 : : return;
136 : : }
137 : :
138 : 0 : if( osl_openFile( aURL.pData, &m_aReadHandle, osl_File_OpenFlag_Read ) != osl_File_E_None )
139 : : {
140 : 0 : fprintf( stderr, "could not open %s\n", pInFile );
141 : : return;
142 : : }
143 : :
144 : 0 : if( osl_setFilePos( m_aReadHandle, osl_Pos_End, 0 ) != osl_File_E_None )
145 : : {
146 : 0 : fprintf( stderr, "could not seek to end of %s\n", pInFile );
147 : 0 : osl_closeFile( m_aReadHandle );
148 : : return;
149 : : }
150 : :
151 : 0 : sal_uInt64 nFileSize = 0;
152 : 0 : if( osl_getFilePos( m_aReadHandle, &nFileSize ) != osl_File_E_None )
153 : : {
154 : 0 : fprintf( stderr, "could not get end pos of %s\n", pInFile );
155 : 0 : osl_closeFile( m_aReadHandle );
156 : : return;
157 : : }
158 : :
159 : 0 : m_nReadLen = static_cast<unsigned int>(nFileSize);
160 : : }
161 : :
162 : 0 : bool FileEmitContext::write( const void* pBuf, unsigned int nLen ) throw()
163 : : {
164 : 0 : if( ! m_aHandle )
165 : 0 : return false;
166 : :
167 : 0 : sal_uInt64 nWrite = static_cast<sal_uInt64>(nLen);
168 : 0 : sal_uInt64 nWritten = 0;
169 : 0 : return (osl_writeFile( m_aHandle, pBuf, nWrite, &nWritten ) == osl_File_E_None)
170 : 0 : && nWrite == nWritten;
171 : : }
172 : :
173 : 0 : unsigned int FileEmitContext::getCurPos() throw()
174 : : {
175 : 0 : sal_uInt64 nFileSize = 0;
176 : 0 : if( m_aHandle )
177 : : {
178 : 0 : if( osl_getFilePos( m_aHandle, &nFileSize ) != osl_File_E_None )
179 : 0 : nFileSize = 0;
180 : : }
181 : 0 : return static_cast<unsigned int>(nFileSize);
182 : : }
183 : :
184 : 0 : bool FileEmitContext::copyOrigBytes( unsigned int nOrigOffset, unsigned int nLen ) throw()
185 : : {
186 : 0 : if( nOrigOffset + nLen > m_nReadLen )
187 : 0 : return false;
188 : :
189 : 0 : if( osl_setFilePos( m_aReadHandle, osl_Pos_Absolut, nOrigOffset ) != osl_File_E_None )
190 : : {
191 : 0 : fprintf( stderr, "could not seek to offset %u\n", nOrigOffset );
192 : 0 : return false;
193 : : }
194 : 0 : void* pBuf = rtl_allocateMemory( nLen );
195 : 0 : if( ! pBuf )
196 : 0 : return false;
197 : 0 : sal_uInt64 nBytesRead = 0;
198 : 0 : if( osl_readFile( m_aReadHandle, pBuf, nLen, &nBytesRead ) != osl_File_E_None
199 : : || nBytesRead != static_cast<sal_uInt64>(nLen) )
200 : : {
201 : 0 : fprintf( stderr, "could not read %u bytes\n", nLen );
202 : 0 : rtl_freeMemory( pBuf );
203 : 0 : return false;
204 : : }
205 : 0 : bool bRet = write( pBuf, nLen );
206 : 0 : rtl_freeMemory( pBuf );
207 : 0 : return bRet;
208 : : }
209 : :
210 : 0 : unsigned int FileEmitContext::readOrigBytes( unsigned int nOrigOffset, unsigned int nLen, void* pBuf ) throw()
211 : : {
212 : 0 : if( nOrigOffset + nLen > m_nReadLen )
213 : 0 : return 0;
214 : :
215 : 0 : if( osl_setFilePos( m_aReadHandle, osl_Pos_Absolut, nOrigOffset ) != osl_File_E_None )
216 : : {
217 : 0 : fprintf( stderr, "could not seek to offset %u\n", nOrigOffset );
218 : 0 : return 0;
219 : : }
220 : 0 : sal_uInt64 nBytesRead = 0;
221 : 0 : if( osl_readFile( m_aReadHandle, pBuf, nLen, &nBytesRead ) != osl_File_E_None )
222 : 0 : return 0;
223 : 0 : return static_cast<unsigned int>(nBytesRead);
224 : : }
225 : :
226 : : typedef int(*PDFFileHdl)(const char*, const char*, PDFFile*);
227 : :
228 : 0 : int handleFile( const char* pInFile, const char* pOutFile, const char* pPassword, PDFFileHdl pHdl )
229 : : {
230 : :
231 : 0 : PDFReader aParser;
232 : 0 : int nRet = 0;
233 : 0 : PDFEntry* pEntry = aParser.read( pInFile );
234 : 0 : if( pEntry )
235 : : {
236 : 0 : PDFFile* pPDFFile = dynamic_cast<PDFFile*>(pEntry);
237 : 0 : if( pPDFFile )
238 : : {
239 : 0 : fprintf( stdout, "have a %s PDF file\n", pPDFFile->isEncrypted() ? "encrypted" : "unencrypted" );
240 : 0 : if( pPassword )
241 : : fprintf( stdout, "password %s\n",
242 : 0 : pPDFFile->setupDecryptionData( pPassword ) ? "matches" : "does not match" );
243 : 0 : nRet = pHdl( pInFile, pOutFile, pPDFFile );
244 : : }
245 : : else
246 : 0 : nRet = 20;
247 : 0 : delete pEntry;
248 : : }
249 : 0 : return nRet;
250 : : }
251 : :
252 : 0 : int write_unzipFile( const char* pInFile, const char* pOutFile, PDFFile* pPDFFile )
253 : : {
254 : 0 : FileEmitContext aContext( pOutFile, pInFile, pPDFFile );
255 : 0 : aContext.m_bDecrypt = pPDFFile->isEncrypted();
256 : 0 : pPDFFile->emit(aContext);
257 : 0 : return 0;
258 : : }
259 : :
260 : 0 : int write_addStreamArray( const char* pOutFile, PDFArray* pStreams, PDFFile* pPDFFile, const char* pInFile )
261 : : {
262 : 0 : int nRet = 0;
263 : 0 : unsigned int nArrayElements = pStreams->m_aSubElements.size();
264 : 0 : for( unsigned int i = 0; i < nArrayElements-1 && nRet == 0; i++ )
265 : : {
266 : 0 : PDFName* pMimeType = dynamic_cast<PDFName*>(pStreams->m_aSubElements[i]);
267 : 0 : PDFObjectRef* pStreamRef = dynamic_cast<PDFObjectRef*>(pStreams->m_aSubElements[i+1]);
268 : 0 : if( ! pMimeType )
269 : 0 : fprintf( stderr, "error: no mimetype element\n" );
270 : 0 : if( ! pStreamRef )
271 : 0 : fprintf( stderr, "error: no stream ref element\n" );
272 : 0 : if( pMimeType && pStreamRef )
273 : : {
274 : : fprintf( stdout, "found stream %d %d with mimetype %s\n",
275 : : pStreamRef->m_nNumber, pStreamRef->m_nGeneration,
276 : 0 : pMimeType->m_aName.getStr() );
277 : 0 : PDFObject* pObject = pPDFFile->findObject( pStreamRef->m_nNumber, pStreamRef->m_nGeneration );
278 : 0 : if( pObject )
279 : : {
280 : 0 : rtl::OStringBuffer aOutStream( pOutFile );
281 : 0 : aOutStream.append( "_stream_" );
282 : 0 : aOutStream.append( sal_Int32(pStreamRef->m_nNumber) );
283 : 0 : aOutStream.append( "_" );
284 : 0 : aOutStream.append( sal_Int32(pStreamRef->m_nGeneration) );
285 : 0 : FileEmitContext aContext( aOutStream.getStr(), pInFile, pPDFFile );
286 : 0 : aContext.m_bDecrypt = pPDFFile->isEncrypted();
287 : 0 : pObject->writeStream( aContext, pPDFFile );
288 : : }
289 : : else
290 : : {
291 : 0 : fprintf( stderr, "object not found\n" );
292 : 0 : nRet = 121;
293 : 0 : }
294 : : }
295 : : else
296 : 0 : nRet = 120;
297 : : }
298 : 0 : return nRet;
299 : : }
300 : :
301 : 0 : int write_addStreams( const char* pInFile, const char* pOutFile, PDFFile* pPDFFile )
302 : : {
303 : : // find all trailers
304 : 0 : int nRet = 0;
305 : 0 : unsigned int nElements = pPDFFile->m_aSubElements.size();
306 : 0 : for( unsigned i = 0; i < nElements && nRet == 0; i++ )
307 : : {
308 : 0 : PDFTrailer* pTrailer = dynamic_cast<PDFTrailer*>(pPDFFile->m_aSubElements[i]);
309 : 0 : if( pTrailer && pTrailer->m_pDict )
310 : : {
311 : : // search for AdditionalStreams entry
312 : 0 : boost::unordered_map<rtl::OString,PDFEntry*,rtl::OStringHash>::iterator add_stream;
313 : 0 : add_stream = pTrailer->m_pDict->m_aMap.find( "AdditionalStreams" );
314 : 0 : if( add_stream != pTrailer->m_pDict->m_aMap.end() )
315 : : {
316 : 0 : PDFArray* pStreams = dynamic_cast<PDFArray*>(add_stream->second);
317 : 0 : if( pStreams )
318 : 0 : nRet = write_addStreamArray( pOutFile, pStreams, pPDFFile, pInFile );
319 : : }
320 : : }
321 : : }
322 : 0 : return nRet;
323 : : }
324 : :
325 : 0 : int write_fonts( const char* i_pInFile, const char* i_pOutFile, PDFFile* i_pPDFFile )
326 : : {
327 : 0 : int nRet = 0;
328 : 0 : unsigned int nElements = i_pPDFFile->m_aSubElements.size();
329 : 0 : for( unsigned i = 0; i < nElements && nRet == 0; i++ )
330 : : {
331 : : // search FontDescriptors
332 : 0 : PDFObject* pObj = dynamic_cast<PDFObject*>(i_pPDFFile->m_aSubElements[i]);
333 : 0 : if( ! pObj )
334 : 0 : continue;
335 : 0 : PDFDict* pDict = dynamic_cast<PDFDict*>(pObj->m_pObject);
336 : 0 : if( ! pDict )
337 : 0 : continue;
338 : :
339 : : boost::unordered_map<rtl::OString,PDFEntry*,rtl::OStringHash>::iterator map_it =
340 : 0 : pDict->m_aMap.find( "Type" );
341 : 0 : if( map_it == pDict->m_aMap.end() )
342 : 0 : continue;
343 : :
344 : 0 : PDFName* pName = dynamic_cast<PDFName*>(map_it->second);
345 : 0 : if( ! pName )
346 : 0 : continue;
347 : 0 : if( ! pName->m_aName.equals( "FontDescriptor" ) )
348 : 0 : continue;
349 : :
350 : : // the font name will be helpful, also there must be one in
351 : : // a font descriptor
352 : 0 : map_it = pDict->m_aMap.find( "FontName" );
353 : 0 : if( map_it == pDict->m_aMap.end() )
354 : 0 : continue;
355 : 0 : pName = dynamic_cast<PDFName*>(map_it->second);
356 : 0 : if( ! pName )
357 : 0 : continue;
358 : 0 : rtl::OString aFontName( pName->m_aName );
359 : :
360 : 0 : PDFObjectRef* pStreamRef = 0;
361 : 0 : const char* pFileType = NULL;
362 : : // we have a font descriptor, try for a type 1 font
363 : 0 : map_it = pDict->m_aMap.find( "FontFile" );
364 : 0 : if( map_it != pDict->m_aMap.end() )
365 : : {
366 : 0 : pStreamRef = dynamic_cast<PDFObjectRef*>(map_it->second);
367 : 0 : if( pStreamRef )
368 : 0 : pFileType = "pfa";
369 : : }
370 : :
371 : : // perhaps it's a truetype file ?
372 : 0 : if( ! pStreamRef )
373 : : {
374 : 0 : map_it = pDict->m_aMap.find( "FontFile2" );
375 : 0 : if( map_it != pDict->m_aMap.end() )
376 : : {
377 : 0 : pStreamRef = dynamic_cast<PDFObjectRef*>(map_it->second);
378 : 0 : if( pStreamRef )
379 : 0 : pFileType = "ttf";
380 : : }
381 : : }
382 : :
383 : 0 : if( ! pStreamRef )
384 : 0 : continue;
385 : :
386 : 0 : PDFObject* pStream = i_pPDFFile->findObject( pStreamRef );
387 : 0 : if( ! pStream )
388 : 0 : continue;
389 : :
390 : 0 : rtl::OStringBuffer aOutStream( i_pOutFile );
391 : 0 : aOutStream.append( "_font_" );
392 : 0 : aOutStream.append( sal_Int32(pStreamRef->m_nNumber) );
393 : 0 : aOutStream.append( "_" );
394 : 0 : aOutStream.append( sal_Int32(pStreamRef->m_nGeneration) );
395 : 0 : aOutStream.append( "_" );
396 : 0 : aOutStream.append( aFontName );
397 : 0 : if( pFileType )
398 : : {
399 : 0 : aOutStream.append( "." );
400 : 0 : aOutStream.append( pFileType );
401 : : }
402 : 0 : FileEmitContext aContext( aOutStream.getStr(), i_pInFile, i_pPDFFile );
403 : 0 : aContext.m_bDecrypt = i_pPDFFile->isEncrypted();
404 : 0 : pStream->writeStream( aContext, i_pPDFFile );
405 : 0 : }
406 : 0 : return nRet;
407 : : }
408 : :
409 : 0 : std::vector< std::pair< sal_Int32, sal_Int32 > > s_aEmitObjects;
410 : :
411 : 0 : int write_objects( const char* i_pInFile, const char* i_pOutFile, PDFFile* i_pPDFFile )
412 : : {
413 : 0 : int nRet = 0;
414 : 0 : unsigned int nElements = s_aEmitObjects.size();
415 : 0 : for( unsigned i = 0; i < nElements && nRet == 0; i++ )
416 : : {
417 : 0 : sal_Int32 nObject = s_aEmitObjects[i].first;
418 : 0 : sal_Int32 nGeneration = s_aEmitObjects[i].second;
419 : 0 : PDFObject* pStream = i_pPDFFile->findObject( nObject, nGeneration );
420 : 0 : if( ! pStream )
421 : : {
422 : 0 : fprintf( stderr, "object %d %d not found !\n", (int)nObject, (int)nGeneration );
423 : 0 : continue;
424 : : }
425 : :
426 : 0 : rtl::OStringBuffer aOutStream( i_pOutFile );
427 : 0 : aOutStream.append( "_stream_" );
428 : 0 : aOutStream.append( nObject );
429 : 0 : aOutStream.append( "_" );
430 : 0 : aOutStream.append( nGeneration );
431 : 0 : FileEmitContext aContext( aOutStream.getStr(), i_pInFile, i_pPDFFile );
432 : 0 : aContext.m_bDecrypt = i_pPDFFile->isEncrypted();
433 : 0 : pStream->writeStream( aContext, i_pPDFFile );
434 : 0 : }
435 : 0 : return nRet;
436 : : }
437 : :
438 : 0 : SAL_IMPLEMENT_MAIN_WITH_ARGS( argc, argv )
439 : : {
440 : 0 : const char* pInFile = NULL;
441 : 0 : const char* pOutFile = NULL;
442 : 0 : const char* pPassword = NULL;
443 : 0 : OStringBuffer aOutFile( 256 );
444 : 0 : PDFFileHdl aHdl = write_unzipFile;
445 : :
446 : 0 : for( int nArg = 1; nArg < argc; nArg++ )
447 : : {
448 : 0 : if( argv[nArg][0] == '-' )
449 : : {
450 : 0 : if( ! rtl_str_compare( "-pw", argv[nArg] ) ||
451 : 0 : ! rtl_str_compare( "--password" , argv[nArg] ) )
452 : : {
453 : 0 : if( nArg == argc-1 )
454 : : {
455 : 0 : fprintf( stderr, "no password given\n" );
456 : 0 : return 1;
457 : : }
458 : 0 : nArg++;
459 : 0 : pPassword = argv[nArg];
460 : : }
461 : 0 : else if( ! rtl_str_compare( "-h", argv[nArg] ) ||
462 : 0 : ! rtl_str_compare( "--help", argv[nArg] ) )
463 : : {
464 : 0 : printHelp( argv[0] );
465 : 0 : return 0;
466 : : }
467 : 0 : else if( ! rtl_str_compare( "-a", argv[nArg] ) ||
468 : 0 : ! rtl_str_compare( "--extract-add-streams", argv[nArg] ) )
469 : : {
470 : 0 : aHdl = write_addStreams;
471 : : }
472 : 0 : else if( ! rtl_str_compare( "-f", argv[nArg] ) ||
473 : 0 : ! rtl_str_compare( "--extract-fonts", argv[nArg] ) )
474 : : {
475 : 0 : aHdl = write_fonts;
476 : : }
477 : 0 : else if( ! rtl_str_compare( "-o", argv[nArg] ) ||
478 : 0 : ! rtl_str_compare( "--extract-objects", argv[nArg] ) )
479 : : {
480 : 0 : aHdl = write_objects;
481 : 0 : nArg++;
482 : 0 : if( nArg < argc )
483 : : {
484 : 0 : rtl::OString aObjs( argv[nArg] );
485 : 0 : sal_Int32 nIndex = 0;
486 : 0 : while( nIndex != -1 )
487 : : {
488 : 0 : rtl::OString aToken( aObjs.getToken( 0, ',', nIndex ) );
489 : 0 : sal_Int32 nObject = 0;
490 : 0 : sal_Int32 nGeneration = 0;
491 : 0 : sal_Int32 nGenIndex = 0;
492 : 0 : nObject = aToken.getToken( 0, ':', nGenIndex ).toInt32();
493 : 0 : if( nGenIndex != -1 )
494 : 0 : nGeneration = aToken.getToken( 0, ':', nGenIndex ).toInt32();
495 : 0 : s_aEmitObjects.push_back( std::pair<sal_Int32,sal_Int32>(nObject,nGeneration) );
496 : 0 : }
497 : : }
498 : : }
499 : : else
500 : : {
501 : : fprintf( stderr, "unrecognized option \"%s\"\n",
502 : 0 : argv[nArg] );
503 : 0 : printHelp( argv[0] );
504 : 0 : return 1;
505 : : }
506 : : }
507 : 0 : else if( pInFile == NULL )
508 : 0 : pInFile = argv[nArg];
509 : 0 : else if( pOutFile == NULL )
510 : 0 : pOutFile = argv[nArg];
511 : : }
512 : 0 : if( ! pInFile )
513 : : {
514 : 0 : fprintf( stderr, "no input file given\n" );
515 : 0 : return 10;
516 : : }
517 : 0 : if( ! pOutFile )
518 : : {
519 : 0 : OString aFile( pInFile );
520 : 0 : if( aFile.getLength() > 0 )
521 : : {
522 : 0 : if( aFile.getLength() > 4 )
523 : : {
524 : 0 : if( aFile.matchIgnoreAsciiCase( OString( ".pdf" ), aFile.getLength()-4 ) )
525 : 0 : aOutFile.append( pInFile, aFile.getLength() - 4 );
526 : : else
527 : 0 : aOutFile.append( aFile );
528 : : }
529 : 0 : aOutFile.append( "_unzip.pdf" );
530 : 0 : pOutFile = aOutFile.getStr();
531 : : }
532 : : else
533 : : {
534 : 0 : fprintf( stderr, "no output file given\n" );
535 : 0 : return 11;
536 : 0 : }
537 : : }
538 : :
539 : 0 : return handleFile( pInFile, pOutFile, pPassword, aHdl );
540 : 0 : }
541 : :
542 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|