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/enumerate | |
parent | 844697c2ab154509cb8fa876bf6094c948caf817 (diff) | |
download | mu-6d943605ad7c5989716a3f9c05392f1394980a05.tar.gz |
1014 - reorganize build system to prepare for .mu layers
Diffstat (limited to 'cpp/enumerate')
-rw-r--r-- | cpp/enumerate/enumerate.cc | 35 | ||||
-rw-r--r-- | cpp/enumerate/makefile | 5 |
2 files changed, 40 insertions, 0 deletions
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 |