about summary refs log tree commit diff stats
path: root/tools
diff options
context:
space:
mode:
authorKartik Agaram <vc@akkartik.com>2019-12-07 15:26:05 -0800
committerKartik Agaram <vc@akkartik.com>2019-12-07 18:06:16 -0800
commit72f278ae6bb52e17dbdeac0fce41a794e8dfd0d1 (patch)
tree37a9447622b24894ccb2006b027b61b3b8b8fab8 /tools
parentc1d596f56a6f2198ea8ea1b0a90c613e919d891b (diff)
downloadmu-72f278ae6bb52e17dbdeac0fce41a794e8dfd0d1.tar.gz
5797 - move `enumerate/` to `tools/` directory
Diffstat (limited to 'tools')
-rw-r--r--tools/Readme.md8
-rw-r--r--tools/enumerate.cc26
2 files changed, 34 insertions, 0 deletions
diff --git a/tools/Readme.md b/tools/Readme.md
index 3a24955b..2649ef72 100644
--- a/tools/Readme.md
+++ b/tools/Readme.md
@@ -1,5 +1,13 @@
 Run all these from the top-level `mu/` directory.
 
+### Some tools for Mu's build process
+
+These are built automatically.
+
+* `enumerate`: list numeric files in current directory, optionally `--until`
+  some prefix.
+
+
 ### Miscellaneous odds and ends
 
 These are built lazily.
diff --git a/tools/enumerate.cc b/tools/enumerate.cc
new file mode 100644
index 00000000..2777c407
--- /dev/null
+++ b/tools/enumerate.cc
@@ -0,0 +1,26 @@
+#include<assert.h>
+#include<cstdlib>
+#include<dirent.h>
+#include<vector>
+using std::vector;
+#include<string>
+using std::string;
+#include<iostream>
+using std::cout;
+
+int main(int argc, const char* argv[]) {
+  assert(argc == 3);
+  assert(string(argv[1]) == "--until");
+  string last_file(argv[2]);
+
+  dirent** files;
+  int num_files = scandir(".", &files, NULL, alphasort);
+  for (int i = 0; i < num_files; ++i) {
+    string curr_file = files[i]->d_name;
+    if (!isdigit(curr_file.at(0))) continue;
+    if (!last_file.empty() && curr_file > last_file) break;
+    cout << curr_file << '\n';
+  }
+  // don't bother freeing files
+  return 0;
+}