1d291ea28SAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3d291ea28SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4d291ea28SAndrew Rist * or more contributor license agreements. See the NOTICE file
5d291ea28SAndrew Rist * distributed with this work for additional information
6d291ea28SAndrew Rist * regarding copyright ownership. The ASF licenses this file
7d291ea28SAndrew Rist * to you under the Apache License, Version 2.0 (the
8d291ea28SAndrew Rist * "License"); you may not use this file except in compliance
9d291ea28SAndrew Rist * with the License. You may obtain a copy of the License at
10cdf0e10cSrcweir *
11d291ea28SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir *
13d291ea28SAndrew Rist * Unless required by applicable law or agreed to in writing,
14d291ea28SAndrew Rist * software distributed under the License is distributed on an
15d291ea28SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16d291ea28SAndrew Rist * KIND, either express or implied. See the License for the
17d291ea28SAndrew Rist * specific language governing permissions and limitations
18d291ea28SAndrew Rist * under the License.
19cdf0e10cSrcweir *
20d291ea28SAndrew Rist *************************************************************/
21cdf0e10cSrcweir
22cdf0e10cSrcweir #include <precomp.h>
23cdf0e10cSrcweir #include <tools/filecoll.hxx>
24cdf0e10cSrcweir
25cdf0e10cSrcweir // NOT FULLY DEFINED SERVICES
26cdf0e10cSrcweir #include <cosv/ploc_dir.hxx>
27cdf0e10cSrcweir
28cdf0e10cSrcweir #include <stdio.h>
29cdf0e10cSrcweir
FileCollector(uintt i_nRoughNrOfFiles)30cdf0e10cSrcweir FileCollector::FileCollector( uintt i_nRoughNrOfFiles )
31cdf0e10cSrcweir // : aFoundFiles
32cdf0e10cSrcweir {
33cdf0e10cSrcweir if (i_nRoughNrOfFiles > 0)
34cdf0e10cSrcweir aFoundFiles.reserve(i_nRoughNrOfFiles);
35cdf0e10cSrcweir }
36cdf0e10cSrcweir
37cdf0e10cSrcweir uintt
AddFilesFrom(const char * i_sRootDir,const char * i_sFilter,E_SearchMode i_eSearchMode)38cdf0e10cSrcweir FileCollector::AddFilesFrom( const char * i_sRootDir,
39cdf0e10cSrcweir const char * i_sFilter,
40cdf0e10cSrcweir E_SearchMode i_eSearchMode )
41cdf0e10cSrcweir {
42cdf0e10cSrcweir uintt nSizeAtStart = aFoundFiles.size();
43cdf0e10cSrcweir
44cdf0e10cSrcweir if (csv::no_str(i_sFilter) OR csv::no_str(i_sRootDir))
45cdf0e10cSrcweir {
46cdf0e10cSrcweir Cout() << "Warning: The filter contains no files." << Endl();
47cdf0e10cSrcweir return 0;
48cdf0e10cSrcweir }
49cdf0e10cSrcweir
50cdf0e10cSrcweir csv::ploc::Directory aDir(i_sRootDir);
51cdf0e10cSrcweir if (NOT aDir.Exists())
52cdf0e10cSrcweir {
53cdf0e10cSrcweir Cerr() << "Warning: The path for the files to be parsed could not be found:\n"
54cdf0e10cSrcweir << i_sRootDir
55cdf0e10cSrcweir << Endl();
56cdf0e10cSrcweir return 0;
57cdf0e10cSrcweir }
58cdf0e10cSrcweir
59cdf0e10cSrcweir Cout() << "." << Flush();
60cdf0e10cSrcweir aDir.GetContainedFiles(aFoundFiles, i_sFilter);
61cdf0e10cSrcweir
62cdf0e10cSrcweir if (i_eSearchMode == recursive)
63cdf0e10cSrcweir {
64cdf0e10cSrcweir StreamStr aPath(1020);
65cdf0e10cSrcweir aPath << i_sRootDir << csv::ploc::Delimiter();
66cdf0e10cSrcweir uintt nSubDirStart = aPath.tellp();
67cdf0e10cSrcweir
68cdf0e10cSrcweir StringVector aSubDirs;
69cdf0e10cSrcweir aDir.GetContainedDirectories(aSubDirs);
70cdf0e10cSrcweir
71cdf0e10cSrcweir for ( const_iterator iter = aSubDirs.begin();
72cdf0e10cSrcweir iter != aSubDirs.end();
73cdf0e10cSrcweir ++iter )
74cdf0e10cSrcweir {
75cdf0e10cSrcweir aPath.seekp(nSubDirStart);
76cdf0e10cSrcweir aPath << (*iter);
77cdf0e10cSrcweir AddFilesFrom( aPath.c_str(), i_sFilter, i_eSearchMode );
78cdf0e10cSrcweir }
79cdf0e10cSrcweir }
80cdf0e10cSrcweir
81cdf0e10cSrcweir return aFoundFiles.size() - nSizeAtStart;
82cdf0e10cSrcweir }
83cdf0e10cSrcweir
84cdf0e10cSrcweir uintt
AddFile(const char * i_sFilePath)85cdf0e10cSrcweir FileCollector::AddFile( const char * i_sFilePath )
86cdf0e10cSrcweir {
87cdf0e10cSrcweir FILE * pFile = fopen( i_sFilePath, "r" );
88cdf0e10cSrcweir if ( pFile == 0 )
89cdf0e10cSrcweir {
90cdf0e10cSrcweir Cerr() << "Warning: The path for the file to be parsed could not be found:\n"
91cdf0e10cSrcweir << i_sFilePath
92cdf0e10cSrcweir << Endl();
93cdf0e10cSrcweir return 0;
94cdf0e10cSrcweir }
95cdf0e10cSrcweir
96cdf0e10cSrcweir fclose(pFile);
97cdf0e10cSrcweir aFoundFiles.push_back(i_sFilePath);
98cdf0e10cSrcweir return 1;
99cdf0e10cSrcweir }
100cdf0e10cSrcweir
101cdf0e10cSrcweir void
EraseAll()102cdf0e10cSrcweir FileCollector::EraseAll()
103cdf0e10cSrcweir {
104cdf0e10cSrcweir csv::erase_container(aFoundFiles);
105cdf0e10cSrcweir }
106cdf0e10cSrcweir
107cdf0e10cSrcweir FileCollector::const_iterator
Begin() const108cdf0e10cSrcweir FileCollector::Begin() const
109cdf0e10cSrcweir {
110cdf0e10cSrcweir return aFoundFiles.begin();
111cdf0e10cSrcweir }
112cdf0e10cSrcweir
113cdf0e10cSrcweir FileCollector::const_iterator
End() const114cdf0e10cSrcweir FileCollector::End() const
115cdf0e10cSrcweir {
116cdf0e10cSrcweir return aFoundFiles.end();
117cdf0e10cSrcweir }
118cdf0e10cSrcweir
119cdf0e10cSrcweir uintt
Size() const120cdf0e10cSrcweir FileCollector::Size() const
121cdf0e10cSrcweir {
122cdf0e10cSrcweir return aFoundFiles.size();
123cdf0e10cSrcweir }
124*1fd21976Smseidel
125*1fd21976Smseidel /* vim: set noet sw=4 ts=4: */
126