summaryrefslogtreecommitdiff
path: root/Userland
diff options
context:
space:
mode:
authorKenneth Myhra <kennethmyhra@gmail.com>2021-12-07 20:30:37 +0100
committerBrian Gianforcaro <b.gianfo@gmail.com>2021-12-16 02:10:47 -0800
commit4726532735dd4ef0a02a37f01c22c34809bce6d1 (patch)
treed63f33a2fa19f5b04de1cfd09d91e590fa642a0a /Userland
parentcd8bd27835f52a82308e5f894c89a11f39818fe2 (diff)
downloadserenity-4726532735dd4ef0a02a37f01c22c34809bce6d1.zip
diff: Port to LibMain
Diffstat (limited to 'Userland')
-rw-r--r--Userland/Utilities/CMakeLists.txt2
-rw-r--r--Userland/Utilities/diff.cpp27
2 files changed, 10 insertions, 19 deletions
diff --git a/Userland/Utilities/CMakeLists.txt b/Userland/Utilities/CMakeLists.txt
index 29eb8f07c6..eb1c787311 100644
--- a/Userland/Utilities/CMakeLists.txt
+++ b/Userland/Utilities/CMakeLists.txt
@@ -81,7 +81,7 @@ target_link_libraries(date LibMain)
target_link_libraries(dd LibMain)
target_link_libraries(ddate LibMain)
target_link_libraries(df LibMain)
-target_link_libraries(diff LibDiff)
+target_link_libraries(diff LibDiff LibMain)
target_link_libraries(disasm LibX86)
target_link_libraries(dmesg LibMain)
target_link_libraries(echo LibMain)
diff --git a/Userland/Utilities/diff.cpp b/Userland/Utilities/diff.cpp
index cfbaf02d49..51b785fa49 100644
--- a/Userland/Utilities/diff.cpp
+++ b/Userland/Utilities/diff.cpp
@@ -6,34 +6,25 @@
#include <LibCore/ArgsParser.h>
#include <LibCore/File.h>
+#include <LibCore/System.h>
#include <LibDiff/Generator.h>
+#include <LibMain/Main.h>
#include <unistd.h>
-int main(int argc, char** argv)
+ErrorOr<int> serenity_main(Main::Arguments arguments)
{
- if (pledge("stdio rpath", nullptr) < 0) {
- perror("pledge");
- return 1;
- }
+ TRY(Core::System::pledge("stdio rpath"));
Core::ArgsParser parser;
- char const* filename1;
- char const* filename2;
+ String filename1;
+ String filename2;
parser.add_positional_argument(filename1, "First file to compare", "file1", Core::ArgsParser::Required::Yes);
parser.add_positional_argument(filename2, "Second file to compare", "file2", Core::ArgsParser::Required::Yes);
- parser.parse(argc, argv, Core::ArgsParser::FailureBehavior::PrintUsageAndExit);
+ parser.parse(arguments);
- auto file1 = Core::File::construct(filename1);
- if (!file1->open(Core::OpenMode::ReadOnly)) {
- warnln("Error: Cannot open {}: {}", filename1, file1->error_string());
- return 1;
- }
- auto file2 = Core::File::construct(filename2);
- if (!file2->open(Core::OpenMode::ReadOnly)) {
- warnln("Error: Cannot open {}: {}", filename2, file2->error_string());
- return 1;
- }
+ auto file1 = TRY(Core::File::open(filename1, Core::OpenMode::ReadOnly));
+ auto file2 = TRY(Core::File::open(filename2, Core::OpenMode::ReadOnly));
auto hunks = Diff::from_text(file1->read_all(), file2->read_all());
for (const auto& hunk : hunks) {