From 02af7e788f3fef0dbba0ba49442054fb451f5bdc Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Thu, 9 Jul 2015 12:25:47 +0200 Subject: Implement directory iteration support --- tests/buildfile | 2 +- tests/dir-iterator/buildfile | 7 ++++++ tests/dir-iterator/driver.cxx | 55 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 63 insertions(+), 1 deletion(-) create mode 100644 tests/dir-iterator/buildfile create mode 100644 tests/dir-iterator/driver.cxx (limited to 'tests') diff --git a/tests/buildfile b/tests/buildfile index ae4bbb3..684221b 100644 --- a/tests/buildfile +++ b/tests/buildfile @@ -2,6 +2,6 @@ # copyright : Copyright (c) 2014-2015 Code Synthesis Ltd # license : MIT; see accompanying LICENSE file -d = path/ prefix-map/ +d = dir-iterator/ path/ prefix-map/ .: $d include $d diff --git a/tests/dir-iterator/buildfile b/tests/dir-iterator/buildfile new file mode 100644 index 0000000..fabea4d --- /dev/null +++ b/tests/dir-iterator/buildfile @@ -0,0 +1,7 @@ +# file : tests/dir-iterator/buildfile +# copyright : Copyright (c) 2014-2015 Code Synthesis Ltd +# license : MIT; see accompanying LICENSE file + +exe{driver}: cxx{driver} ../../butl/lib{butl} + +include ../../butl/ diff --git a/tests/dir-iterator/driver.cxx b/tests/dir-iterator/driver.cxx new file mode 100644 index 0000000..09a259f --- /dev/null +++ b/tests/dir-iterator/driver.cxx @@ -0,0 +1,55 @@ +// file : tests/dir-iterator/driver.cxx -*- C++ -*- +// copyright : Copyright (c) 2014-2015 Code Synthesis Ltd +// license : MIT; see accompanying LICENSE file + +#include // size_t +#include +#include + +#include +#include +#include + +using namespace std; +using namespace butl; + +static const char* entry_type_string[] = +{ + "unk", "reg", "dir", "sym", "oth" +}; + +inline ostream& +operator<< (ostream& os, entry_type e) +{ + return os << entry_type_string[static_cast (e)]; +} + +int +main (int argc, const char* argv[]) +{ + if (argc != 2) + { + cerr << "usage: " << argv[0] << " " << endl; + return 1; + } + + try + { + for (const dir_entry& de: dir_iterator (dir_path (argv[1]))) + { + cerr << de.type () << " "; + + if (de.type () == entry_type::symlink) + cerr << de.ltype (); + else + cerr << " "; + + cerr << " " << de.path () << endl; + } + } + catch (const exception& e) + { + cerr << argv[1] << ": " << e.what () << endl; + return 1; + } +} -- cgit v1.1