summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoryenatch <yenatch@gmail.com>2017-07-23 21:44:37 -0400
committeryenatch <yenatch@gmail.com>2017-07-23 21:44:37 -0400
commit7451ea31c62604cc3a96fa9c4123aea3cc5b5cb6 (patch)
treec6c1ba9701ce66f1b62285afeefc9498c17dee8c
parent0faa6c9c93804c4ce0e6fc8e5a6d5cfbc85f01da (diff)
scaninc: add -I and stop hardcoding include paths
-rw-r--r--tools/scaninc/scaninc.cpp49
1 files changed, 43 insertions, 6 deletions
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<std::string> filesToProcess;
std::set<std::string> 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")
{