mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 21:07:35 +00:00
markdown-check: Port to LibMain
This commit is contained in:
parent
6437f5da36
commit
de7d333d43
3 changed files with 9 additions and 10 deletions
|
@ -513,7 +513,7 @@ if (BUILD_LAGOM)
|
||||||
|
|
||||||
add_executable(markdown-check_lagom ../../Userland/Utilities/markdown-check.cpp)
|
add_executable(markdown-check_lagom ../../Userland/Utilities/markdown-check.cpp)
|
||||||
set_target_properties(markdown-check_lagom PROPERTIES OUTPUT_NAME markdown-check)
|
set_target_properties(markdown-check_lagom PROPERTIES OUTPUT_NAME markdown-check)
|
||||||
target_link_libraries(markdown-check_lagom LagomMarkdown)
|
target_link_libraries(markdown-check_lagom LagomMarkdown LagomMain)
|
||||||
|
|
||||||
add_executable(ntpquery_lagom ../../Userland/Utilities/ntpquery.cpp)
|
add_executable(ntpquery_lagom ../../Userland/Utilities/ntpquery.cpp)
|
||||||
set_target_properties(ntpquery_lagom PROPERTIES OUTPUT_NAME ntpquery)
|
set_target_properties(ntpquery_lagom PROPERTIES OUTPUT_NAME ntpquery)
|
||||||
|
|
|
@ -137,7 +137,7 @@ target_link_libraries(lsof LibMain)
|
||||||
target_link_libraries(lspci LibPCIDB LibMain)
|
target_link_libraries(lspci LibPCIDB LibMain)
|
||||||
target_link_libraries(lsusb LibUSBDB LibMain)
|
target_link_libraries(lsusb LibUSBDB LibMain)
|
||||||
target_link_libraries(man LibMarkdown LibMain)
|
target_link_libraries(man LibMarkdown LibMain)
|
||||||
target_link_libraries(markdown-check LibMarkdown)
|
target_link_libraries(markdown-check LibMarkdown LibMain)
|
||||||
target_link_libraries(matroska LibMain LibVideo)
|
target_link_libraries(matroska LibMain LibVideo)
|
||||||
target_link_libraries(md LibMarkdown LibMain)
|
target_link_libraries(md LibMarkdown LibMain)
|
||||||
target_link_libraries(mkdir LibMain)
|
target_link_libraries(mkdir LibMain)
|
||||||
|
|
|
@ -15,12 +15,11 @@
|
||||||
#include <AK/HashMap.h>
|
#include <AK/HashMap.h>
|
||||||
#include <AK/HashTable.h>
|
#include <AK/HashTable.h>
|
||||||
#include <AK/LexicalPath.h>
|
#include <AK/LexicalPath.h>
|
||||||
#include <AK/OwnPtr.h>
|
|
||||||
#include <AK/RecursionDecision.h>
|
#include <AK/RecursionDecision.h>
|
||||||
#include <AK/StdLibExtras.h>
|
|
||||||
#include <AK/URL.h>
|
#include <AK/URL.h>
|
||||||
#include <AK/Vector.h>
|
#include <AK/Vector.h>
|
||||||
#include <LibCore/File.h>
|
#include <LibCore/File.h>
|
||||||
|
#include <LibMain/Main.h>
|
||||||
#include <LibMarkdown/Document.h>
|
#include <LibMarkdown/Document.h>
|
||||||
#include <LibMarkdown/Visitor.h>
|
#include <LibMarkdown/Visitor.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
@ -223,25 +222,25 @@ RecursionDecision MarkdownLinkage::visit(Markdown::Text::LinkNode const& link_no
|
||||||
return RecursionDecision::Recurse;
|
return RecursionDecision::Recurse;
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char** argv)
|
ErrorOr<int> serenity_main(Main::Arguments arguments)
|
||||||
{
|
{
|
||||||
if (argc < 2) {
|
if (arguments.strings.size() < 2) {
|
||||||
// Technically it is valid to call this program with zero markdown files: When there are
|
// Technically it is valid to call this program with zero markdown files: When there are
|
||||||
// no files, there are no dead links. However, any such usage is probably erroneous.
|
// no files, there are no dead links. However, any such usage is probably erroneous.
|
||||||
warnln("Usage: {} Foo.md Bar.md ...", argv[0]);
|
warnln("Usage: {} Foo.md Bar.md ...", arguments.strings[0]);
|
||||||
// E.g.: find AK/ Base/ Documentation/ Kernel/ Meta/ Ports/ Tests/ Userland/ -name '*.md' -print0 | xargs -0 ./MarkdownCheck
|
// E.g.: find AK/ Base/ Documentation/ Kernel/ Meta/ Ports/ Tests/ Userland/ -name '*.md' -print0 | xargs -0 ./MarkdownCheck
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
outln("Reading and parsing Markdown files ...");
|
outln("Reading and parsing Markdown files ...");
|
||||||
HashMap<String, MarkdownLinkage> files;
|
HashMap<String, MarkdownLinkage> files;
|
||||||
for (int i = 1; i < argc; ++i) {
|
for (size_t i = 1; i < arguments.strings.size(); ++i) {
|
||||||
auto path = argv[i];
|
auto path = arguments.strings[i];
|
||||||
auto file_or_error = Core::File::open(path, Core::OpenMode::ReadOnly);
|
auto file_or_error = Core::File::open(path, Core::OpenMode::ReadOnly);
|
||||||
if (file_or_error.is_error()) {
|
if (file_or_error.is_error()) {
|
||||||
warnln("Failed to read {}: {}", path, file_or_error.error());
|
warnln("Failed to read {}: {}", path, file_or_error.error());
|
||||||
// Since this should never happen anyway, fail early.
|
// Since this should never happen anyway, fail early.
|
||||||
return 1;
|
return file_or_error.release_error();
|
||||||
}
|
}
|
||||||
auto file = file_or_error.release_value();
|
auto file = file_or_error.release_value();
|
||||||
auto content_buffer = file->read_all();
|
auto content_buffer = file->read_all();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue