From 16aeb8b51da818b2e31c41f7f5aa171f5ccdc0af Mon Sep 17 00:00:00 2001 From: itskarudo Date: Sat, 12 Feb 2022 11:08:44 +0100 Subject: kill: Parse CLI arguments using Arguments.strings The previous implementation used argv and LibC to parse arguments, it now uses the Arguments.strings interface to do so. --- Userland/Utilities/kill.cpp | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) (limited to 'Userland/Utilities') diff --git a/Userland/Utilities/kill.cpp b/Userland/Utilities/kill.cpp index ab31f4b2b4..194e43b922 100644 --- a/Userland/Utilities/kill.cpp +++ b/Userland/Utilities/kill.cpp @@ -12,7 +12,6 @@ #include #include #include -#include #include static void print_usage_and_exit() @@ -27,9 +26,9 @@ ErrorOr serenity_main(Main::Arguments arguments) TRY(Core::System::pledge("stdio proc")); int argc = arguments.argc; - char** argv = arguments.argv; + auto strings = arguments.strings; - if (argc == 2 && !strcmp(argv[1], "-l")) { + if (argc == 2 && strings[1] == "-l") { for (size_t i = 0; i < NSIG; ++i) { if (i && !(i % 5)) outln(""); @@ -45,29 +44,29 @@ ErrorOr serenity_main(Main::Arguments arguments) int pid_argi = 1; if (argc == 3) { pid_argi = 2; - if (argv[1][0] != '-') + if (strings[1][0] != '-') print_usage_and_exit(); Optional number; - if (isalpha(argv[1][1])) { - int value = getsignalbyname(&argv[1][1]); + if (isalpha(strings[1][1])) { + int value = getsignalbyname(&strings[1][1]); if (value >= 0 && value < NSIG) number = value; } if (!number.has_value()) - number = StringView(&argv[1][1]).to_uint(); + number = strings[1].substring_view(1, 1).to_uint(); if (!number.has_value()) { - warnln("'{}' is not a valid signal name or number", &argv[1][1]); + warnln("'{}' is not a valid signal name or number", &strings[1][1]); return 2; } signum = number.value(); } - auto pid_opt = String(argv[pid_argi]).to_int(); + auto pid_opt = strings[pid_argi].to_int(); if (!pid_opt.has_value()) { - warnln("'{}' is not a valid PID", argv[pid_argi]); + warnln("'{}' is not a valid PID", strings[pid_argi]); return 3; } pid_t pid = pid_opt.value(); -- cgit v1.2.3