diff options
author | Kartik K. Agaram <vc@akkartik.com> | 2015-05-05 21:17:24 -0700 |
---|---|---|
committer | Kartik K. Agaram <vc@akkartik.com> | 2015-05-05 21:17:24 -0700 |
commit | b96af395b9af2ff9df94b3e82213171f30827c8d (patch) | |
tree | 17c8c12648ccc25625e2534ec8d74fbe8f1542cc /enumerate | |
parent | 2e3b597fe85b654e82b891c22d50754fa5a26156 (diff) | |
download | mu-b96af395b9af2ff9df94b3e82213171f30827c8d.tar.gz |
1276 - make C++ version the default
I've tried to update the Readme, but there are at least a couple of issues.
Diffstat (limited to 'enumerate')
-rw-r--r-- | enumerate/enumerate.cc | 35 | ||||
-rw-r--r-- | enumerate/makefile | 5 |
2 files changed, 40 insertions, 0 deletions
diff --git a/enumerate/enumerate.cc b/enumerate/enumerate.cc new file mode 100644 index 00000000..02349213 --- /dev/null +++ b/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/enumerate/makefile b/enumerate/makefile new file mode 100644 index 00000000..f2d0e460 --- /dev/null +++ b/enumerate/makefile @@ -0,0 +1,5 @@ +tangle: makefile + g++ -O3 -Wall -Wextra -fno-strict-aliasing enumerate.cc -o enumerate + +clean: + -rm enumerate |