update dev300-m58
[ooovba.git] / autodoc / source / tools / filecoll.cxx
blob502d7dad720c3333e97a0c841049189441503930
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: filecoll.cxx,v $
10 * $Revision: 1.12 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #include <precomp.h>
32 #include <tools/filecoll.hxx>
35 // NOT FULLY DEFINED SERVICES
36 #include <cosv/ploc_dir.hxx>
38 #include <stdio.h>
41 FileCollector::FileCollector( uintt i_nRoughNrOfFiles )
42 // : aFoundFiles
44 if (i_nRoughNrOfFiles > 0)
45 aFoundFiles.reserve(i_nRoughNrOfFiles);
48 uintt
49 FileCollector::AddFilesFrom( const char * i_sRootDir,
50 const char * i_sFilter,
51 E_SearchMode i_eSearchMode )
53 uintt nSizeAtStart = aFoundFiles.size();
55 if (csv::no_str(i_sFilter) OR csv::no_str(i_sRootDir))
57 Cout() << "Warning: The filter contains no files." << Endl();
58 return 0;
61 csv::ploc::Directory aDir(i_sRootDir);
62 if (NOT aDir.Exists())
64 Cerr() << "Warning: The path for the files to be parsed could not be found:\n"
65 << i_sRootDir
66 << Endl();
67 return 0;
70 Cout() << "." << Flush();
71 aDir.GetContainedFiles(aFoundFiles, i_sFilter);
73 if (i_eSearchMode == recursive)
75 StreamStr aPath(1020);
76 aPath << i_sRootDir << csv::ploc::Delimiter();
77 uintt nSubDirStart = aPath.tellp();
79 StringVector aSubDirs;
80 aDir.GetContainedDirectories(aSubDirs);
82 for ( const_iterator iter = aSubDirs.begin();
83 iter != aSubDirs.end();
84 ++iter )
86 aPath.seekp(nSubDirStart);
87 aPath << (*iter);
88 AddFilesFrom( aPath.c_str(), i_sFilter, i_eSearchMode );
92 return aFoundFiles.size() - nSizeAtStart;
95 uintt
96 FileCollector::AddFile( const char * i_sFilePath )
98 FILE * pFile = fopen( i_sFilePath, "r" );
99 if ( pFile == 0 )
101 Cerr() << "Warning: The path for the file to be parsed could not be found:\n"
102 << i_sFilePath
103 << Endl();
104 return 0;
107 fclose(pFile);
108 aFoundFiles.push_back(i_sFilePath);
109 return 1;
112 void
113 FileCollector::EraseAll()
115 csv::erase_container(aFoundFiles);
118 FileCollector::const_iterator
119 FileCollector::Begin() const
121 return aFoundFiles.begin();
124 FileCollector::const_iterator
125 FileCollector::End() const
127 return aFoundFiles.end();
130 uintt
131 FileCollector::Size() const
133 return aFoundFiles.size();