From 8fc1a923a8621e48d4229d88a05daf2b1d675ab0 Mon Sep 17 00:00:00 2001
From: Florian Schmaus <flow@cs.fau.de>
Date: Mon, 21 Mar 2022 15:06:58 +0100
Subject: [PATCH] Add apps/dirwalk

---
 apps/Dirwalk.cpp | 49 ++++++++++++++++++++++++++++++++++++++++++++++++
 apps/meson.build |  6 ++++++
 2 files changed, 55 insertions(+)
 create mode 100644 apps/Dirwalk.cpp

diff --git a/apps/Dirwalk.cpp b/apps/Dirwalk.cpp
new file mode 100644
index 00000000..42eb5a27
--- /dev/null
+++ b/apps/Dirwalk.cpp
@@ -0,0 +1,49 @@
+// SPDX-License-Identifier: LGPL-3.0-or-later
+// Copyright © 2022 Florian Schmaus
+#include <cstdlib>
+#include <filesystem>
+#include <iostream>
+#include <sstream>
+#include <string>
+#include <vector>
+
+#include "Fiber.hpp"
+#include "Fibril.hpp"
+#include "Runtime.hpp"
+#include "emper-common.h"
+
+namespace fs = std::filesystem;
+
+// NOLINTNEXTLINE(clang-diagnostic-unknown-attributes)
+emper_fibril void fibril_recursive_directory_print_walk(const fs::path* dirpath) {
+	std::cout << "DIR: " << *dirpath << std::endl;
+
+	std::vector<fs::path> subdirs;
+	for (const auto& path : fs::directory_iterator(*dirpath)) {
+		if (path.is_directory()) {
+			subdirs.push_back(path);
+			continue;
+		}
+
+		std::cout << path << std::endl;
+	}
+
+	Fibril fibril;
+	for (const auto& subdir : subdirs) {
+		fibril.spawn(fibril_recursive_directory_print_walk, &subdir);
+	}
+}
+
+auto main(UNUSED_ARG int argc, UNUSED_ARG char* argv[]) -> int {
+	Runtime runtime;
+
+	auto* fiber = Fiber::from([] {
+		auto cwd = fs::current_path();
+		fibril_recursive_directory_print_walk(&cwd);
+		Runtime::getRuntime()->initiateTermination();
+	});
+	runtime.scheduleFromAnywhere(*fiber);
+
+	runtime.waitUntilFinished();
+	return EXIT_SUCCESS;
+}
diff --git a/apps/meson.build b/apps/meson.build
index 1ab32678..959cf569 100644
--- a/apps/meson.build
+++ b/apps/meson.build
@@ -40,6 +40,12 @@ qsort = executable(
   dependencies: emper_dep,
 )
 
+qsort = executable(
+  'dirwalk',
+  'Dirwalk.cpp',
+  dependencies: emper_dep,
+)
+
 boost_program_options_dep = dependency('boost', modules: ['program_options'])
 
 boost_program_options_code = '''
-- 
GitLab