mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 19:57:35 +00:00
keymap: Port to LibMain :^)
This commit is contained in:
parent
8b5c0e8e71
commit
120168203e
2 changed files with 13 additions and 35 deletions
|
@ -71,7 +71,7 @@ target_link_libraries(gunzip LibCompress)
|
||||||
target_link_libraries(gzip LibCompress)
|
target_link_libraries(gzip LibCompress)
|
||||||
target_link_libraries(id LibMain)
|
target_link_libraries(id LibMain)
|
||||||
target_link_libraries(js LibJS LibLine 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(lspci LibPCIDB)
|
||||||
target_link_libraries(lsusb LibUSBDB)
|
target_link_libraries(lsusb LibUSBDB)
|
||||||
target_link_libraries(man LibMarkdown)
|
target_link_libraries(man LibMarkdown)
|
||||||
|
|
|
@ -6,52 +6,30 @@
|
||||||
|
|
||||||
#include <LibCore/ArgsParser.h>
|
#include <LibCore/ArgsParser.h>
|
||||||
#include <LibCore/ConfigFile.h>
|
#include <LibCore/ConfigFile.h>
|
||||||
|
#include <LibCore/System.h>
|
||||||
#include <LibKeyboard/CharacterMap.h>
|
#include <LibKeyboard/CharacterMap.h>
|
||||||
|
#include <LibMain/Main.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <unistd.h>
|
|
||||||
|
|
||||||
int main(int argc, char** argv)
|
ErrorOr<int> serenity_main(Main::Arguments arguments)
|
||||||
{
|
{
|
||||||
if (pledge("stdio setkeymap getkeymap rpath wpath cpath", nullptr) < 0) {
|
TRY(Core::System::pledge("stdio setkeymap getkeymap rpath wpath cpath", nullptr));
|
||||||
perror("pledge");
|
TRY(Core::System::unveil("/res/keymaps", "r"));
|
||||||
return 1;
|
TRY(Core::System::unveil("/etc/Keyboard.ini", "rwc"));
|
||||||
}
|
|
||||||
|
|
||||||
if (unveil("/res/keymaps", "r") < 0) {
|
|
||||||
perror("unveil");
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (unveil("/etc/Keyboard.ini", "rwc") < 0) {
|
|
||||||
perror("unveil /etc/Keyboard.ini");
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
const char* path = nullptr;
|
const char* path = nullptr;
|
||||||
Core::ArgsParser args_parser;
|
Core::ArgsParser args_parser;
|
||||||
args_parser.add_positional_argument(path, "The mapping file to be used", "file", Core::ArgsParser::Required::No);
|
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 (path && path[0] == '/')
|
||||||
if (unveil(path, "r") < 0) {
|
TRY(Core::System::unveil(path, "r"));
|
||||||
perror("unveil path");
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (unveil(nullptr, nullptr) < 0) {
|
TRY(Core::System::unveil(nullptr, nullptr));
|
||||||
perror("unveil");
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!path) {
|
if (!path) {
|
||||||
auto keymap = Keyboard::CharacterMap::fetch_system_map();
|
auto keymap = TRY(Keyboard::CharacterMap::fetch_system_map());
|
||||||
if (keymap.is_error()) {
|
outln("{}", keymap.character_map_name());
|
||||||
warnln("getkeymap: {}", keymap.error());
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
outln("{}", keymap.value().character_map_name());
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue