summaryrefslogtreecommitdiff
path: root/Userland
diff options
context:
space:
mode:
authorFabian INGREMEAU <fabian.ingremeau@outlook.com>2022-01-23 18:10:52 +0100
committerBrian Gianforcaro <b.gianfo@gmail.com>2022-01-25 00:11:14 +0000
commit5f602e39e9b3a16e89d8ca4bba19494df39e0d54 (patch)
tree03ffefef88bbf24c6c290e816cf349dd493545a4 /Userland
parentdff64603730a65c31e2e104a9852a8ed9401d3a1 (diff)
downloadserenity-5f602e39e9b3a16e89d8ca4bba19494df39e0d54.zip
md: Port to LibMain
Diffstat (limited to 'Userland')
-rw-r--r--Userland/Utilities/CMakeLists.txt2
-rw-r--r--Userland/Utilities/md.cpp18
2 files changed, 8 insertions, 12 deletions
diff --git a/Userland/Utilities/CMakeLists.txt b/Userland/Utilities/CMakeLists.txt
index de947882b2..4547c166a5 100644
--- a/Userland/Utilities/CMakeLists.txt
+++ b/Userland/Utilities/CMakeLists.txt
@@ -127,7 +127,7 @@ target_link_libraries(lsusb LibUSBDB LibMain)
target_link_libraries(man LibMarkdown LibMain)
target_link_libraries(markdown-check LibMarkdown)
target_link_libraries(matroska LibVideo)
-target_link_libraries(md LibMarkdown)
+target_link_libraries(md LibMarkdown LibMain)
target_link_libraries(mkdir LibMain)
target_link_libraries(mkfifo LibMain)
target_link_libraries(mknod LibMain)
diff --git a/Userland/Utilities/md.cpp b/Userland/Utilities/md.cpp
index 0b927d2d6a..b40c6d88f8 100644
--- a/Userland/Utilities/md.cpp
+++ b/Userland/Utilities/md.cpp
@@ -7,17 +7,15 @@
#include <AK/String.h>
#include <LibCore/ArgsParser.h>
#include <LibCore/File.h>
+#include <LibCore/System.h>
+#include <LibMain/Main.h>
#include <LibMarkdown/Document.h>
-#include <stdio.h>
#include <sys/ioctl.h>
#include <unistd.h>
-int main(int argc, char* argv[])
+ErrorOr<int> serenity_main(Main::Arguments arguments)
{
- if (pledge("stdio rpath tty", nullptr) < 0) {
- perror("pledge");
- return 1;
- }
+ TRY(Core::System::pledge("stdio rpath tty"));
const char* filename = nullptr;
bool html = false;
@@ -28,7 +26,7 @@ int main(int argc, char* argv[])
args_parser.add_option(html, "Render to HTML rather than for the terminal", "html", 'H');
args_parser.add_option(view_width, "Viewport width for the terminal (defaults to current terminal width)", "view-width", 0, "width");
args_parser.add_positional_argument(filename, "Path to Markdown file", "path", Core::ArgsParser::Required::No);
- args_parser.parse(argc, argv);
+ args_parser.parse(arguments);
if (!html && view_width == 0) {
if (isatty(STDOUT_FILENO)) {
@@ -55,10 +53,7 @@ int main(int argc, char* argv[])
return 1;
}
- if (pledge("stdio", nullptr) < 0) {
- perror("pledge");
- return 1;
- }
+ TRY(Core::System::pledge("stdio"));
auto buffer = file->read_all();
dbgln("Read size {}", buffer.size());
@@ -73,4 +68,5 @@ int main(int argc, char* argv[])
String res = html ? document->render_to_html() : document->render_for_terminal(view_width);
out("{}", res);
+ return 0;
}