Refactorization: Removed lengthy comment and actually check std::ifstream::operator bool().

This commit is contained in:
PKEuS 2015-11-15 11:16:12 +01:00
parent b788d96bb9
commit 4e5b9dc692
1 changed files with 4 additions and 13 deletions

View File

@ -34,21 +34,13 @@
#include <cstdlib> // EXIT_FAILURE #include <cstdlib> // EXIT_FAILURE
#ifdef HAVE_RULES #ifdef HAVE_RULES
// xml is used in rules // xml is used for rules
#include <tinyxml2.h> #include <tinyxml2.h>
#endif #endif
static void AddFilesToList(const std::string& FileList, std::vector<std::string>& PathNames) static void AddFilesToList(const std::string& FileList, std::vector<std::string>& PathNames)
{ {
// to keep things initially simple, if the file can't be opened, just be // To keep things initially simple, if the file can't be opened, just be silent and move on.
// silent and move on
// ideas : we could also require this should be an xml file, with the filenames
// specified in an xml structure
// we could elaborate this then, to also include the I-paths, ...
// basically for everything that makes the command line very long
// xml is a bonus then, since we can easily extend it
// we need a good parser then -> suggestion : TinyXml
// drawback : creates a dependency
std::istream *Files; std::istream *Files;
std::ifstream Infile; std::ifstream Infile;
if (FileList.compare("-") == 0) { // read from stdin if (FileList.compare("-") == 0) { // read from stdin
@ -57,7 +49,7 @@ static void AddFilesToList(const std::string& FileList, std::vector<std::string>
Infile.open(FileList.c_str()); Infile.open(FileList.c_str());
Files = &Infile; Files = &Infile;
} }
if (Files) { if (Files && *Files) {
std::string FileName; std::string FileName;
while (std::getline(*Files, FileName)) { // next line while (std::getline(*Files, FileName)) { // next line
if (!FileName.empty()) { if (!FileName.empty()) {
@ -69,8 +61,7 @@ static void AddFilesToList(const std::string& FileList, std::vector<std::string>
static void AddInclPathsToList(const std::string& FileList, std::list<std::string>* PathNames) static void AddInclPathsToList(const std::string& FileList, std::list<std::string>* PathNames)
{ {
// to keep things initially simple, if the file can't be opened, just be // To keep things initially simple, if the file can't be opened, just be silent and move on.
// silent and move on
std::ifstream Files(FileList.c_str()); std::ifstream Files(FileList.c_str());
if (Files) { if (Files) {
std::string PathName; std::string PathName;