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 #include <precomp.h> 29 #include <tools/filecoll.hxx> 30 31 32 // NOT FULLY DEFINED SERVICES 33 #include <cosv/ploc_dir.hxx> 34 35 #include <stdio.h> 36 37 38 FileCollector::FileCollector( uintt i_nRoughNrOfFiles ) 39 // : aFoundFiles 40 { 41 if (i_nRoughNrOfFiles > 0) 42 aFoundFiles.reserve(i_nRoughNrOfFiles); 43 } 44 45 uintt 46 FileCollector::AddFilesFrom( const char * i_sRootDir, 47 const char * i_sFilter, 48 E_SearchMode i_eSearchMode ) 49 { 50 uintt nSizeAtStart = aFoundFiles.size(); 51 52 if (csv::no_str(i_sFilter) OR csv::no_str(i_sRootDir)) 53 { 54 Cout() << "Warning: The filter contains no files." << Endl(); 55 return 0; 56 } 57 58 csv::ploc::Directory aDir(i_sRootDir); 59 if (NOT aDir.Exists()) 60 { 61 Cerr() << "Warning: The path for the files to be parsed could not be found:\n" 62 << i_sRootDir 63 << Endl(); 64 return 0; 65 } 66 67 Cout() << "." << Flush(); 68 aDir.GetContainedFiles(aFoundFiles, i_sFilter); 69 70 if (i_eSearchMode == recursive) 71 { 72 StreamStr aPath(1020); 73 aPath << i_sRootDir << csv::ploc::Delimiter(); 74 uintt nSubDirStart = aPath.tellp(); 75 76 StringVector aSubDirs; 77 aDir.GetContainedDirectories(aSubDirs); 78 79 for ( const_iterator iter = aSubDirs.begin(); 80 iter != aSubDirs.end(); 81 ++iter ) 82 { 83 aPath.seekp(nSubDirStart); 84 aPath << (*iter); 85 AddFilesFrom( aPath.c_str(), i_sFilter, i_eSearchMode ); 86 } 87 } 88 89 return aFoundFiles.size() - nSizeAtStart; 90 } 91 92 uintt 93 FileCollector::AddFile( const char * i_sFilePath ) 94 { 95 FILE * pFile = fopen( i_sFilePath, "r" ); 96 if ( pFile == 0 ) 97 { 98 Cerr() << "Warning: The path for the file to be parsed could not be found:\n" 99 << i_sFilePath 100 << Endl(); 101 return 0; 102 } 103 104 fclose(pFile); 105 aFoundFiles.push_back(i_sFilePath); 106 return 1; 107 } 108 109 void 110 FileCollector::EraseAll() 111 { 112 csv::erase_container(aFoundFiles); 113 } 114 115 FileCollector::const_iterator 116 FileCollector::Begin() const 117 { 118 return aFoundFiles.begin(); 119 } 120 121 FileCollector::const_iterator 122 FileCollector::End() const 123 { 124 return aFoundFiles.end(); 125 } 126 127 uintt 128 FileCollector::Size() const 129 { 130 return aFoundFiles.size(); 131 } 132 133