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