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