From 4726532735dd4ef0a02a37f01c22c34809bce6d1 Mon Sep 17 00:00:00 2001 From: Kenneth Myhra Date: Tue, 7 Dec 2021 20:30:37 +0100 Subject: diff: Port to LibMain --- Userland/Utilities/CMakeLists.txt | 2 +- Userland/Utilities/diff.cpp | 27 +++++++++------------------ 2 files changed, 10 insertions(+), 19 deletions(-) (limited to 'Userland') 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 #include +#include #include +#include #include -int main(int argc, char** argv) +ErrorOr 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) { -- cgit v1.2.3