diff --git a/Userland/Utilities/CMakeLists.txt b/Userland/Utilities/CMakeLists.txt index c28308ee3e6..fcc396826c4 100644 --- a/Userland/Utilities/CMakeLists.txt +++ b/Userland/Utilities/CMakeLists.txt @@ -71,7 +71,7 @@ target_link_libraries(gunzip LibCompress) target_link_libraries(gzip LibCompress) target_link_libraries(id LibMain) target_link_libraries(js LibJS LibLine LibMain) -target_link_libraries(keymap LibKeyboard) +target_link_libraries(keymap LibKeyboard LibMain) target_link_libraries(lspci LibPCIDB) target_link_libraries(lsusb LibUSBDB) target_link_libraries(man LibMarkdown) diff --git a/Userland/Utilities/keymap.cpp b/Userland/Utilities/keymap.cpp index 693a0448051..24974009e36 100644 --- a/Userland/Utilities/keymap.cpp +++ b/Userland/Utilities/keymap.cpp @@ -6,52 +6,30 @@ #include #include +#include #include +#include #include -#include -int main(int argc, char** argv) +ErrorOr serenity_main(Main::Arguments arguments) { - if (pledge("stdio setkeymap getkeymap rpath wpath cpath", nullptr) < 0) { - perror("pledge"); - return 1; - } - - if (unveil("/res/keymaps", "r") < 0) { - perror("unveil"); - return 1; - } - - if (unveil("/etc/Keyboard.ini", "rwc") < 0) { - perror("unveil /etc/Keyboard.ini"); - return 1; - } + TRY(Core::System::pledge("stdio setkeymap getkeymap rpath wpath cpath", nullptr)); + TRY(Core::System::unveil("/res/keymaps", "r")); + TRY(Core::System::unveil("/etc/Keyboard.ini", "rwc")); const char* path = nullptr; Core::ArgsParser args_parser; args_parser.add_positional_argument(path, "The mapping file to be used", "file", Core::ArgsParser::Required::No); - args_parser.parse(argc, argv); + args_parser.parse(arguments); - if (path && path[0] == '/') { - if (unveil(path, "r") < 0) { - perror("unveil path"); - return 1; - } - } + if (path && path[0] == '/') + TRY(Core::System::unveil(path, "r")); - if (unveil(nullptr, nullptr) < 0) { - perror("unveil"); - return 1; - } + TRY(Core::System::unveil(nullptr, nullptr)); if (!path) { - auto keymap = Keyboard::CharacterMap::fetch_system_map(); - if (keymap.is_error()) { - warnln("getkeymap: {}", keymap.error()); - return 1; - } - - outln("{}", keymap.value().character_map_name()); + auto keymap = TRY(Keyboard::CharacterMap::fetch_system_map()); + outln("{}", keymap.character_map_name()); return 0; }