Commit b1df4800 authored by Pádraig Ó Conbhuí's avatar Pádraig Ó Conbhuí
Browse files

Added .clang-format and ran the formatter over the project.

parent 65e99a07
Language: Cpp
BasedOnStyle: LLVM
#ifndef MEGADEP_COMMON_TYPES_HPP
#define MEGADEP_COMMON_TYPES_HPP
#include <string>
#include <cstdint>
#include <string>
namespace megadep {
......@@ -11,6 +11,6 @@ using DirectoryName = std::string;
using FileHash = uint32_t;
}
} // namespace megadep
#endif // MEGADEP_COMMON_TYPES_HPP
#include <megadep/megadep.hpp>
#include <megadep/common_types.hpp>
#include <megadep/megadep.hpp>
#include <dirent.h>
#include <cstring>
#include <dirent.h>
namespace megadep {
std::vector<FileName> list_files(const DirectoryName& directory) {
namespace fs = std::filesystem;
std::vector<FileName> list_files(const DirectoryName &directory) {
namespace fs = std::filesystem;
std::vector<FileName> file_names;
std::vector<FileName> file_names;
DIR* dir_ptr;
dirent *entity_ptr;
DIR *dir_ptr;
dirent *entity_ptr;
dir_ptr = opendir(directory.c_str());
dir_ptr = opendir(directory.c_str());
// Directory is a file, return the directory name
if(dir_ptr == NULL) {
if(errno == ENOTDIR || errno == ENOENT) {
return {directory};
}
return {};
// Directory is a file, return the directory name
if (dir_ptr == NULL) {
if (errno == ENOTDIR || errno == ENOENT) {
return {directory};
}
while(entity_ptr = readdir(dir_ptr)) {
const char* entity_name = entity_ptr->d_name;
return {};
}
while (entity_ptr = readdir(dir_ptr)) {
const char *entity_name = entity_ptr->d_name;
// Skip . and ..
if(strcmp(entity_name, ".") == 0) continue;
if(strcmp(entity_name, "..") == 0) continue;
// Skip . and ..
if (strcmp(entity_name, ".") == 0)
continue;
if (strcmp(entity_name, "..") == 0)
continue;
// Try recursing
auto sub_files = list_files(directory + '/' + entity_ptr->d_name);
// Try recursing
auto sub_files = list_files(directory + '/' + entity_ptr->d_name);
for(auto& sub_file: sub_files) {
file_names.emplace_back(std::move(sub_file));
}
for (auto &sub_file : sub_files) {
file_names.emplace_back(std::move(sub_file));
}
}
closedir(dir_ptr);
closedir(dir_ptr);
return file_names;
return file_names;
}
}
} // namespace megadep
......@@ -3,12 +3,12 @@
#include <megadep/common_types.hpp>
#include <vector>
#include <string>
#include <vector>
namespace megadep {
std::vector<FileName> list_files(const DirectoryName& directories);
std::vector<FileName> list_files(const DirectoryName &directories);
}
......
......@@ -4,10 +4,10 @@
using namespace megadep;
int main(int argc, char* argv[]) {
auto files = list_files(argv[1]);
for(const auto& file: files) {
std::cout << file << '\n';
}
return 0;
int main(int argc, char *argv[]) {
auto files = list_files(argv[1]);
for (const auto &file : files) {
std::cout << file << '\n';
}
return 0;
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment