summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.travis/calcrom/calcrom.cpp50
1 files changed, 31 insertions, 19 deletions
diff --git a/.travis/calcrom/calcrom.cpp b/.travis/calcrom/calcrom.cpp
index fd0ac79..c16a958 100644
--- a/.travis/calcrom/calcrom.cpp
+++ b/.travis/calcrom/calcrom.cpp
@@ -23,6 +23,8 @@
* Account for diamond/pearl split
* - 0.1.4 (19 Sep 2020):
* Modify for PowerPC development
+ * - 0.1.5 (20 Sep 2020):
+ * Use nftw instead of glob to recursively search directory trees
*/
#include <iostream>
@@ -30,29 +32,27 @@
#include <sstream>
#include <regex>
#include <elf.h>
-#include <glob.h>
+#include <ftw.h>
#include <string.h>
#include <vector>
#include <string>
using namespace std;
-struct Glob : public vector<char const *> {
- glob_t glob_result;
-public:
- Glob(string const & pattern) {
- int result = glob(pattern.c_str(), GLOB_TILDE | GLOB_BRACE, NULL, &glob_result);
- if (result) {
- stringstream ss;
- ss << "Glob(" << pattern << ") failed with error " << result << endl;
- throw runtime_error(ss.str());
- }
- assign(glob_result.gl_pathv, glob_result.gl_pathv + glob_result.gl_pathc);
- };
- void operator~() {
- globfree(&glob_result);
+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)
{
@@ -115,10 +115,22 @@ 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()))
+
+ // Recursively search the /src and /asm directories for
+ // .c, .cpp, and .s files, accumulating them all into the files vector
+ 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);