diff options
author | Kenneth Myhra <kennethmyhra@gmail.com> | 2022-03-29 22:24:00 +0200 |
---|---|---|
committer | Brian Gianforcaro <b.gianfo@gmail.com> | 2022-03-29 21:28:29 -0700 |
commit | c843f2e3a50e03504ff56186deb09bbfdb2e2dbd (patch) | |
tree | 0360dc2f4952d2b33ae46f15c8bfba87427ed43d | |
parent | 1ee93e0fe76348899a438dc01e8a007db9e2fdc0 (diff) | |
download | serenity-c843f2e3a50e03504ff56186deb09bbfdb2e2dbd.zip |
seq: Port to LibMain
-rw-r--r-- | Userland/Utilities/CMakeLists.txt | 1 | ||||
-rw-r--r-- | Userland/Utilities/seq.cpp | 40 |
2 files changed, 19 insertions, 22 deletions
diff --git a/Userland/Utilities/CMakeLists.txt b/Userland/Utilities/CMakeLists.txt index 66d033bb90..8d62b432f4 100644 --- a/Userland/Utilities/CMakeLists.txt +++ b/Userland/Utilities/CMakeLists.txt @@ -178,6 +178,7 @@ target_link_libraries(rev LibMain) target_link_libraries(rm LibMain) target_link_libraries(rmdir LibMain) target_link_libraries(run-tests LibRegex LibCoredump LibMain) +target_link_libraries(seq LibMain) target_link_libraries(shot LibGUI LibMain) target_link_libraries(shuf LibMain) target_link_libraries(shutdown LibMain) diff --git a/Userland/Utilities/seq.cpp b/Userland/Utilities/seq.cpp index 848ab49bc9..72367a9d3c 100644 --- a/Userland/Utilities/seq.cpp +++ b/Userland/Utilities/seq.cpp @@ -6,10 +6,11 @@ #include <AK/Format.h> #include <AK/StdLibExtras.h> +#include <LibCore/System.h> +#include <LibMain/Main.h> #include <stdio.h> #include <stdlib.h> #include <string.h> -#include <unistd.h> const char* const g_usage = R"(Usage: seq [-h|--help] @@ -40,19 +41,14 @@ static double get_double(const char* name, const char* d_string, int* number_of_ return d; } -int main(int argc, const char* argv[]) +ErrorOr<int> serenity_main(Main::Arguments arguments) { - if (pledge("stdio", nullptr) < 0) { - perror("pledge"); - return 1; - } - if (unveil(nullptr, nullptr) < 0) { - perror("unveil"); - return 1; - } + TRY(Core::System::pledge("stdio")); + TRY(Core::System::unveil(nullptr, nullptr)); - for (int i = 1; i < argc; i++) { - if (strcmp(argv[i], "--help") == 0 || strcmp(argv[i], "-h") == 0) { + for (size_t i = 1; i < arguments.strings.size(); i++) { + if (arguments.strings[i] == "--help"sv || arguments.strings[i] == "-h") { + out("HELP"); print_usage(stdout); exit(0); } @@ -60,32 +56,32 @@ int main(int argc, const char* argv[]) double start = 1, step = 1, end = 1; int number_of_start_decimals = 0, number_of_step_decimals = 0, number_of_end_decimals = 0; - switch (argc) { + switch (arguments.strings.size()) { case 2: - end = get_double(argv[0], argv[1], &number_of_end_decimals); + end = get_double(arguments.argv[0], arguments.argv[1], &number_of_end_decimals); break; case 3: - start = get_double(argv[0], argv[1], &number_of_start_decimals); - end = get_double(argv[0], argv[2], &number_of_end_decimals); + start = get_double(arguments.argv[0], arguments.argv[1], &number_of_start_decimals); + end = get_double(arguments.argv[0], arguments.argv[2], &number_of_end_decimals); break; case 4: - start = get_double(argv[0], argv[1], &number_of_start_decimals); - step = get_double(argv[0], argv[2], &number_of_step_decimals); - end = get_double(argv[0], argv[3], &number_of_end_decimals); + start = get_double(arguments.argv[0], arguments.argv[1], &number_of_start_decimals); + step = get_double(arguments.argv[0], arguments.argv[2], &number_of_step_decimals); + end = get_double(arguments.argv[0], arguments.argv[3], &number_of_end_decimals); break; default: - warnln("{}: unexpected number of arguments", argv[0]); + warnln("{}: unexpected number of arguments", arguments.argv[0]); print_usage(stderr); return 1; } if (step == 0) { - warnln("{}: increment must not be 0", argv[0]); + warnln("{}: increment must not be 0", arguments.argv[0]); return 1; } if (__builtin_isnan(start) || __builtin_isnan(step) || __builtin_isnan(end)) { - warnln("{}: start, step, and end must not be NaN", argv[0]); + warnln("{}: start, step, and end must not be NaN", arguments.argv[0]); return 1; } |