From 0faa6c9c93804c4ce0e6fc8e5a6d5cfbc85f01da Mon Sep 17 00:00:00 2001 From: yenatch Date: Sat, 22 Jul 2017 18:49:38 -0400 Subject: scaninc: read c includes Now editing .h files triggers a rebuild. Also allow .h and .inc files to be passed as a main argument. src/ and include/ are temporarily hardcoded. --- tools/scaninc/scaninc.cpp | 41 +++++++++++++++++++++++++++++++++++------ 1 file changed, 35 insertions(+), 6 deletions(-) (limited to 'tools/scaninc/scaninc.cpp') diff --git a/tools/scaninc/scaninc.cpp b/tools/scaninc/scaninc.cpp index b6f7ba767..10cb06eee 100644 --- a/tools/scaninc/scaninc.cpp +++ b/tools/scaninc/scaninc.cpp @@ -55,16 +55,45 @@ int main(int argc, char **argv) std::string extension = initialPath.substr(pos + 1); - if (extension == "c") + std::string srcDir("src/"); + std::string includeDir("include/"); + + if (extension == "c" || extension == "h") { - CFile file(initialPath); + filesToProcess.push(initialPath); + + while (!filesToProcess.empty()) + { + CFile file(filesToProcess.top()); + filesToProcess.pop(); - file.FindIncbins(); - dependencies = file.GetIncbins(); + file.FindIncbins(); + for (auto incbin : file.GetIncbins()) + { + dependencies.insert(incbin); + } + for (auto include : file.GetIncludes()) + { + std::string path(srcDir + include); + if (!CanOpenFile(path)) + { + path = includeDir + include; + } + + if (CanOpenFile(path)) + { + bool inserted = dependencies.insert(path).second; + if (inserted) + { + filesToProcess.push(path); + } + } + } + } } - else if (extension == "s") + else if (extension == "s" || extension == "inc") { - filesToProcess.push(std::string(argv[1])); + filesToProcess.push(initialPath); while (!filesToProcess.empty()) { -- cgit v1.2.3 From 7451ea31c62604cc3a96fa9c4123aea3cc5b5cb6 Mon Sep 17 00:00:00 2001 From: yenatch Date: Sun, 23 Jul 2017 21:44:37 -0400 Subject: scaninc: add -I and stop hardcoding include paths --- tools/scaninc/scaninc.cpp | 49 +++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 43 insertions(+), 6 deletions(-) (limited to 'tools/scaninc/scaninc.cpp') diff --git a/tools/scaninc/scaninc.cpp b/tools/scaninc/scaninc.cpp index 10cb06eee..2d91db646 100644 --- a/tools/scaninc/scaninc.cpp +++ b/tools/scaninc/scaninc.cpp @@ -38,15 +38,48 @@ bool CanOpenFile(std::string path) return true; } +const char *const USAGE = "Usage: scaninc [-I INCLUDE_PATH] FILE_PATH\n"; + int main(int argc, char **argv) { - if (argc < 2) - FATAL_ERROR("Usage: scaninc FILE_PATH\n"); - std::stack filesToProcess; std::set dependencies; - std::string initialPath(argv[1]); + std::string includeDir(""); + + argc--; + argv++; + + while (argc > 1) + { + std::string arg(argv[0]); + if (arg.substr(0, 2) == "-I") + { + includeDir = arg.substr(2); + if (includeDir.empty()) + { + argc--; + argv++; + includeDir = std::string(argv[0]); + } + if (includeDir.back() != '/') + { + includeDir += '/'; + } + } + else + { + FATAL_ERROR(USAGE); + } + argc--; + argv++; + } + + if (argc != 1) { + FATAL_ERROR(USAGE); + } + + std::string initialPath(argv[0]); std::size_t pos = initialPath.find_last_of('.'); @@ -55,8 +88,12 @@ int main(int argc, char **argv) std::string extension = initialPath.substr(pos + 1); - std::string srcDir("src/"); - std::string includeDir("include/"); + std::string srcDir(""); + std::size_t slash = initialPath.rfind('/'); + if (slash != std::string::npos) + { + srcDir = initialPath.substr(0, slash + 1); + } if (extension == "c" || extension == "h") { -- cgit v1.2.3 From e98e074138c9a8083a812760d71144f7174b34d8 Mon Sep 17 00:00:00 2001 From: yenatch Date: Sun, 23 Jul 2017 23:11:26 -0400 Subject: scaninc: allow multiple include paths also use a queue instead of a stack for filesToProcess --- tools/scaninc/scaninc.cpp | 42 ++++++++++++++++++++++-------------------- 1 file changed, 22 insertions(+), 20 deletions(-) (limited to 'tools/scaninc/scaninc.cpp') diff --git a/tools/scaninc/scaninc.cpp b/tools/scaninc/scaninc.cpp index 2d91db646..3dc221479 100644 --- a/tools/scaninc/scaninc.cpp +++ b/tools/scaninc/scaninc.cpp @@ -20,7 +20,8 @@ #include #include -#include +#include +#include #include #include #include "scaninc.h" @@ -42,10 +43,10 @@ const char *const USAGE = "Usage: scaninc [-I INCLUDE_PATH] FILE_PATH\n"; int main(int argc, char **argv) { - std::stack filesToProcess; + std::queue filesToProcess; std::set dependencies; - std::string includeDir(""); + std::list includeDirs; argc--; argv++; @@ -55,22 +56,23 @@ int main(int argc, char **argv) std::string arg(argv[0]); if (arg.substr(0, 2) == "-I") { - includeDir = arg.substr(2); + std::string includeDir = arg.substr(2); if (includeDir.empty()) - { + { argc--; argv++; - includeDir = std::string(argv[0]); + includeDir = std::string(argv[0]); } if (includeDir.back() != '/') { includeDir += '/'; } - } + includeDirs.push_back(includeDir); + } else { FATAL_ERROR(USAGE); - } + } argc--; argv++; } @@ -94,6 +96,7 @@ int main(int argc, char **argv) { srcDir = initialPath.substr(0, slash + 1); } + includeDirs.push_back(srcDir); if (extension == "c" || extension == "h") { @@ -101,7 +104,7 @@ int main(int argc, char **argv) while (!filesToProcess.empty()) { - CFile file(filesToProcess.top()); + CFile file(filesToProcess.front()); filesToProcess.pop(); file.FindIncbins(); @@ -111,18 +114,17 @@ int main(int argc, char **argv) } for (auto include : file.GetIncludes()) { - std::string path(srcDir + include); - if (!CanOpenFile(path)) - { - path = includeDir + include; - } - - if (CanOpenFile(path)) + for (auto includeDir : includeDirs) { - bool inserted = dependencies.insert(path).second; - if (inserted) + std::string path(includeDir + include); + if (CanOpenFile(path)) { - filesToProcess.push(path); + bool inserted = dependencies.insert(path).second; + if (inserted) + { + filesToProcess.push(path); + } + break; } } } @@ -134,7 +136,7 @@ int main(int argc, char **argv) while (!filesToProcess.empty()) { - AsmFile file(filesToProcess.top()); + AsmFile file(filesToProcess.front()); filesToProcess.pop(); -- cgit v1.2.3