summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMax <mparisi@stevens.edu>2020-09-20 23:09:47 -0400
committerMax <mparisi@stevens.edu>2020-09-20 23:09:47 -0400
commit3caf86eee2da7bf65a4ce785e79bc872cf2a5955 (patch)
treedc4818db2caf045af318216c0df9f805985a9ac3
parent12d1063966f54ec53f86ca9e8414250b9e886343 (diff)
calcrom bugfix: use nftw() instead of glob() to recursively search both the asm/ and src/ directory trees for .s/.c/.cpp files
-rw-r--r--.travis/calcrom/calcrom.cpp35
1 files changed, 32 insertions, 3 deletions
diff --git a/.travis/calcrom/calcrom.cpp b/.travis/calcrom/calcrom.cpp
index fd0ac79..9b429b2 100644
--- a/.travis/calcrom/calcrom.cpp
+++ b/.travis/calcrom/calcrom.cpp
@@ -31,6 +31,7 @@
#include <regex>
#include <elf.h>
#include <glob.h>
+#include <ftw.h>
#include <string.h>
#include <vector>
#include <string>
@@ -54,6 +55,21 @@ public:
}
};
+static vector<string> files;
+
+static int
+get_files(const char *fpath, const struct stat *sb,
+ int tflag, struct FTW *ftwbuf)
+{
+ if (tflag == FTW_F) {
+ string fpath_s(fpath);
+ string ext = fpath_s.substr(fpath_s.rfind('.'), 4);
+ if (ext == ".c" || ext == ".cpp" || ".s")
+ files.push_back(fpath_s);
+ }
+ return 0;
+}
+
static inline Elf32_Half ElfHalfEndianAdjust(Elf32_Half val)
{
return (Elf32_Half)__builtin_bswap16((uint16_t)val);
@@ -115,10 +131,23 @@ void analyze(string basedir, string version) {
builddir << "/build/" << version;
stringstream basebuilddir;
basebuilddir << basedir << builddir.str();
- pattern << basedir << "/{src,asm}/*.{c,s,cpp}";
- for (char const * & fname : Glob(pattern.str()))
+ pattern << basedir << "/{src,asm}/**/*.{c,s,cpp}";
+
+ // Recursively search the src/ and asm/ directories for
+ // .c, .cpp, and .s files, accumulating them all into files
+ string srcdir = basedir + "/src";
+ string asmdir = basedir + "/asm";
+ if (nftw(srcdir.c_str(), get_files, 20, 0) == -1) {
+ perror("nftw");
+ exit(EXIT_FAILURE);
+ }
+ if (nftw(asmdir.c_str(), get_files, 20, 0) == -1) {
+ perror("nftw");
+ exit(EXIT_FAILURE);
+ }
+
+ for (auto fname_s : files)
{
- string fname_s(fname);
string ext = fname_s.substr(fname_s.rfind('.'), 4);
bool is_asm = ext == ".s";
string fileroot = fname_s.substr(fname_s.rfind('/') + 1);