diff options
author | Kartik K. Agaram <vc@akkartik.com> | 2015-04-03 20:45:03 -0700 |
---|---|---|
committer | Kartik K. Agaram <vc@akkartik.com> | 2015-04-03 20:45:14 -0700 |
commit | 6d943605ad7c5989716a3f9c05392f1394980a05 (patch) | |
tree | 20be4a7ca60de0e9fb6d30d492d56be25165ec4b /cpp | |
parent | 844697c2ab154509cb8fa876bf6094c948caf817 (diff) | |
download | mu-6d943605ad7c5989716a3f9c05392f1394980a05.tar.gz |
1014 - reorganize build system to prepare for .mu layers
Diffstat (limited to 'cpp')
-rwxr-xr-x | cpp/build_and_test_until | 3 | ||||
-rw-r--r-- | cpp/enumerate/enumerate.cc | 35 | ||||
-rw-r--r-- | cpp/enumerate/makefile | 5 | ||||
-rw-r--r-- | cpp/makefile | 10 | ||||
-rw-r--r-- | cpp/tangle/002main.cc | 9 | ||||
-rw-r--r-- | cpp/tangle/030tangle.cc | 29 |
6 files changed, 53 insertions, 38 deletions
diff --git a/cpp/build_and_test_until b/cpp/build_and_test_until index d23de2e1..cd0db64b 100755 --- a/cpp/build_and_test_until +++ b/cpp/build_and_test_until @@ -5,7 +5,8 @@ set -e set -v make tangle/tangle -./tangle/tangle --until $* |grep -v "^\s*//:" > mu.cc +make enumerate/enumerate +./tangle/tangle $(./enumerate/enumerate --until $* |grep -v '.mu$') |grep -v "^\s*//:" > mu.cc make autogenerated_lists g++ -g -Wall -Wextra -fno-strict-aliasing mu.cc -o mu ./mu test diff --git a/cpp/enumerate/enumerate.cc b/cpp/enumerate/enumerate.cc new file mode 100644 index 00000000..02349213 --- /dev/null +++ b/cpp/enumerate/enumerate.cc @@ -0,0 +1,35 @@ +#include<cstdlib> +#include<dirent.h> +#include<vector> +using std::vector; +#include<string> +using std::string; +#include<iostream> +using std::cout; + +int enumerate_files_in_cwd_until(string last_file); +string flag_value(const string& flag, int argc, const char* argv[]); + +int main(int argc, const char* argv[]) { + return enumerate_files_in_cwd_until(flag_value("--until", argc, argv)); +} + +int enumerate_files_in_cwd_until(string last_file) { + 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[0])) continue; + if (!last_file.empty() && curr_file > last_file) break; + cout << curr_file << '\n'; + } + // don't bother freeing files + return 0; +} + +string flag_value(const string& flag, int argc, const char* argv[]) { + for (int i = 1; i < argc-1; ++i) + if (string(argv[i]) == flag) + return argv[i+1]; + return ""; +} diff --git a/cpp/enumerate/makefile b/cpp/enumerate/makefile new file mode 100644 index 00000000..2c685cd4 --- /dev/null +++ b/cpp/enumerate/makefile @@ -0,0 +1,5 @@ +tangle: makefile + g++ -O3 -Wall -Wextra -fno-strict-aliasing enumerate.cc -o enumerate + +clean: + rm -rf enumerate diff --git a/cpp/makefile b/cpp/makefile index d49d8887..a42667c9 100644 --- a/cpp/makefile +++ b/cpp/makefile @@ -1,14 +1,17 @@ -mu: makefile tangle/tangle mu.cc +mu: makefile enumerate/enumerate tangle/tangle mu.cc g++ -g -Wall -Wextra -fno-strict-aliasing mu.cc -o mu # To see what the program looks like after all layers have been applied, read # mu.cc mu.cc: 0* - ./tangle/tangle --until 999 |grep -v "^\s*//:" > mu.cc + ./tangle/tangle $$(./enumerate/enumerate --until 999 |grep -v '.mu$$') |grep -v "^\s*//:" > mu.cc @make autogenerated_lists >/dev/null +enumerate/enumerate: + cd enumerate && make && ./enumerate test + tangle/tangle: - cd tangle && make && tangle test + cd tangle && make && ./tangle test # auto-generated files; by convention they end in '_list'. .PHONY: autogenerated_lists test clena @@ -27,5 +30,6 @@ test_list: mu.cc clena: clean clean: + cd enumerate && make clean cd tangle && make clean rm -rf mu.cc mu *_list diff --git a/cpp/tangle/002main.cc b/cpp/tangle/002main.cc index 04d10c8d..aaa91e6f 100644 --- a/cpp/tangle/002main.cc +++ b/cpp/tangle/002main.cc @@ -1,14 +1,7 @@ -string Last_file = ""; int main(int argc, const char* argv[]) { - Last_file = flag_value("--until", argc, argv); if (flag("test", argc, argv)) return run_tests(); - return tangle_files_in_cwd(); -} - -bool eof(istream& in) { - in.peek(); - return in.eof(); + return tangle(argc, argv); } bool flag(const string& flag, int argc, const char* argv[]) { diff --git a/cpp/tangle/030tangle.cc b/cpp/tangle/030tangle.cc index 52bf4c61..ec34c944 100644 --- a/cpp/tangle/030tangle.cc +++ b/cpp/tangle/030tangle.cc @@ -1,12 +1,9 @@ #include<sys/param.h> -int tangle_files_in_cwd() { +int tangle(int argc, const char* argv[]) { list<string> result; - vector<char*> files = sorted_files(".", /*no extension*/ ""); - for (vector<char*>::iterator p = files.begin(); p != files.end(); ++p) { - if ((*p)[0] < '0' || (*p)[0] > '9') continue; - if (!Last_file.empty() && *p > Last_file) break; - ifstream in(*p); + for (int i = 1; i < argc; ++i) { + ifstream in(argv[i]); tangle(in, result); } for (list<string>::iterator p = result.begin(); p != result.end(); ++p) @@ -367,23 +364,3 @@ string trim(const string& s) { ++last; return string(first, last); } - -#include<dirent.h> - -vector<char*> sorted_files(const char* dirname, const char* ext) { - vector<char*> result; - dirent** files; - int num_files = scandir(dirname, &files, NULL, alphasort); - for (int i = 0; i < num_files; ++i) { - unsigned long n = strlen(files[i]->d_name), extn = strlen(ext); - if (n < extn) continue; - if (strncmp(&files[i]->d_name[n-extn], ext, extn)) continue; - if (!isdigit(files[i]->d_name[0])) continue; - char* s = new char[n+1]; - strncpy(s, files[i]->d_name, n+1); - result.push_back(s); - free(files[i]); - } - free(files); - return result; -} |