TDME2  1.9.200
generatelicenses-main.cpp
Go to the documentation of this file.
1 #include <string>
2 #include <vector>
3 
4 #include <tdme/tdme.h>
6 #include <tdme/engine/Version.h>
10 #include <tdme/utilities/Console.h>
14 
15 using std::string;
16 using std::to_string;
17 using std::vector;
18 
28 
29 void scanDir(const string& folder, vector<string>& totalFiles) {
30  class ListFilter : public virtual FileNameFilter {
31  public:
32  virtual ~ListFilter() {}
33 
34  bool accept(const string& pathName, const string& fileName) override {
35  if (fileName == ".") return false;
36  if (fileName == "..") return false;
37  if (FileSystem::getInstance()->isPath(pathName + "/" + fileName) == true) return true;
38  if (fileName == "LICENSE") return true;
39  return false;
40  }
41  };
42 
43  ListFilter listFilter;
44  vector<string> files;
45 
46  FileSystem::getInstance()->list(folder, files, &listFilter);
47 
48  for (const auto& fileName: files) {
49  if (fileName == "LICENSE") {
50  totalFiles.push_back(folder + "/" + fileName);
51  } else {
52  scanDir(folder + "/" + fileName, totalFiles);
53  }
54  }
55 }
56 
57 void processFile(const string& indent, const string& fileName) {
58  auto _fileName = StringTools::startsWith(fileName, "./") == true?StringTools::substring(fileName, 2, fileName.size()):fileName;
59  vector<string> lines;
60  FileSystem::getInstance()->getContentAsStringArray(".", fileName, lines);
61  Console::println(indent + _fileName);
62  Console::print(indent);
63  for (auto i = 0; i < _fileName.size() + 2; i++) Console::print("-");
64  Console::println();
65  Console::println();
66  for (const auto& line: lines) {
67  if (StringTools::trim(line).size() == 0) {
68  Console::println();
69  } else {
70  Console::println(indent + "\t" + line);
71  }
72  }
73  Console::println();
74  Console::println();
75 }
76 
77 int main(int argc, char** argv)
78 {
79  Console::println(string("generatelicenses ") + Version::getVersion());
80  Console::println(Version::getCopyright());
81  Console::println();
82 
83  auto pathToHeaders = "."; // we do search in pwd
84  auto indent = argc > 1?string(argv[1]):string();
85 
86  if (argc > 2 || (argc == 2 && indent.empty() == false && indent != "--indent")) {
87  Console::println("Usage: generatelicenses [--indent]");
88  Application::exit(1);
89  }
90 
91  if (indent == "--indent") indent = "\t";
92 
93  Console::println("Scanning files");
94  vector<string> files;
95  scanDir(pathToHeaders, files);
96 
97  Console::println("Processing files");
98  Console::println("------------------");
99  Console::println();
100  for (const auto& fileName: files) {
101  if (fileName == "./LICENSE") continue; // ignore own project license
102  processFile(indent, fileName);
103  }
104 
105  //
106  Application::exit(Application::EXITCODE_SUCCESS);
107 }
Application base class, please make sure to allocate application on heap to have correct application ...
Definition: Application.h:41
File system singleton class.
Definition: FileSystem.h:17
Console class.
Definition: Console.h:29
String tokenizer class.
String tools class.
Definition: StringTools.h:22
int main(int argc, char **argv)
void scanDir(const string &folder, vector< string > &totalFiles)
void processFile(const string &indent, const string &fileName)
std::exception Exception
Exception base class.
Definition: Exception.h:18
File system file name filter interface.
virtual bool accept(const string &path, const string &file)=0
Accept a file.