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

Initial Commit.

parents
cmake_minimum_required(VERSION 3.14)
project(
magedep
VERSION 0.0.1
DESCRIPTION "Fast C/C++ dependency generation"
LANGUAGES CXX
)
add_library(
libmegadep
src/megadep/megadep.cpp
)
set_target_properties(
libmegadep
PROPERTIES
OUTPUT_NAME "megadep"
)
target_compile_features(libmegadep PUBLIC cxx_std_17)
target_include_directories(libmegadep PRIVATE src)
enable_testing()
add_executable(
libmegadep.test
src/megadep/megadep.test.cpp
)
target_link_libraries(libmegadep.test libmegadep)
target_include_directories(libmegadep.test PRIVATE src)
add_test(
NAME libmegadep.test
COMMAND libmegadep.test ${CMAKE_CURRENT_SOURCE_DIR}
)
#ifndef MEGADEP_COMMON_TYPES_HPP
#define MEGADEP_COMMON_TYPES_HPP
#include <string>
#include <cstdint>
namespace megadep {
using FileName = std::string;
using DirectoryName = std::string;
using FileHash = uint32_t;
}
#endif // MEGADEP_COMMON_TYPES_HPP
#include <megadep/megadep.hpp>
#include <megadep/common_types.hpp>
#include <dirent.h>
#include <cstring>
namespace megadep {
std::vector<FileName> list_files(const DirectoryName& directory) {
namespace fs = std::filesystem;
std::vector<FileName> file_names;
DIR* dir_ptr;
dirent *entity_ptr;
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 {};
}
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;
// 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));
}
}
closedir(dir_ptr);
return file_names;
}
}
#ifndef MEGADEP_MEGADEP_HPP
#define MEGADEP_MEGADEP_HPP
#include <megadep/common_types.hpp>
#include <vector>
#include <string>
namespace megadep {
std::vector<FileName> list_files(const DirectoryName& directories);
}
#endif // MEGADEP_MEGADEP_HPP
#include <iostream>
#include <megadep/megadep.hpp>
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;
}
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