#include #include #include #include #include #include #include #include #include namespace fs = std::filesystem; int main(int argc, char* argv[]) try { std::vector args(argv + 1, argv + argc); const std::regex link_regex{R"(\[[^\]]*\]\(([^)]*)\))"}; if (args.size() != 1) { std::cerr << "only one argument expected\n"; return 1; } for (const auto& entry : fs::recursive_directory_iterator(args[0])) { if (entry.is_regular_file()) { const auto entry_path = entry.path(); if (entry_path.extension() == ".md") { std::ifstream document(entry_path); if (!document.good()) { std::cerr << "something bad happened" << std::endl; } std::string line; while (std::getline(document, line)) { const auto links = std::sregex_iterator(line.begin(), line.end(), link_regex); const auto end = std::sregex_iterator(); for (auto it = links; it != end; ++it) { const auto link = it->str(1); // TODO } } } } } } catch (std::exception& e) { std::cerr << e.what() << std::endl; return 1; } catch (...) { std::cerr << "unexpected exception" << std::endl; return 1; }