about summary refs log tree commit diff stats
path: root/020run.cc
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2018-02-15 20:36:16 -0800
committerKartik K. Agaram <vc@akkartik.com>2018-02-15 20:36:16 -0800
commit745a6dee7875154e3512bed5d2c73869dddef13e (patch)
treef3a9e5ff020205f0b592df51cc11807058370b29 /020run.cc
parent6086465de72dc1b194a8b3b465fe72788a1d6a7c (diff)
downloadmu-745a6dee7875154e3512bed5d2c73869dddef13e.tar.gz
4204
Diffstat (limited to '020run.cc')
-rw-r--r--020run.cc11
1 files changed, 10 insertions, 1 deletions
diff --git a/020run.cc b/020run.cc
index e82c07e7..d171f112 100644
--- a/020run.cc
+++ b/020run.cc
@@ -273,13 +273,22 @@ void load_all(string dir) {
   int num_files = scandir(dir.c_str(), &files, NULL, alphasort);
   for (int i = 0;  i < num_files;  ++i) {
     string curr_file = files[i]->d_name;
-    if (isdigit(curr_file.at(0)))
+    if (isdigit(curr_file.at(0)) && ends_with(curr_file, ".mu"))
       load_file_or_directory(dir+'/'+curr_file);
     free(files[i]);
     files[i] = NULL;
   }
   free(files);
 }
+
+bool ends_with(const string& s, const string& pat) {
+  for (string::const_reverse_iterator p = s.rbegin(), q = pat.rbegin();  q != pat.rend();  ++p, ++q) {
+    if (p == s.rend()) return false;  // pat too long
+    if (*p != *q) return false;
+  }
+  return true;
+}
+
 :(before "End Includes")
 #include <dirent.h>
 #include <sys/stat.h>