From b96af395b9af2ff9df94b3e82213171f30827c8d Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Tue, 5 May 2015 21:17:24 -0700 Subject: 1276 - make C++ version the default I've tried to update the Readme, but there are at least a couple of issues. --- enumerate/enumerate.cc | 35 +++++++++++++++++++++++++++++++++++ enumerate/makefile | 5 +++++ 2 files changed, 40 insertions(+) create mode 100644 enumerate/enumerate.cc create mode 100644 enumerate/makefile (limited to 'enumerate') 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 +#include +#include +using std::vector; +#include +using std::string; +#include +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 -- cgit 1.4.1-2-gfad0