From 06ee4b66d02cc51c075a5bb3b0f053c1725ac37f Mon Sep 17 00:00:00 2001 From: ronak69 Date: Sun, 6 Aug 2023 06:20:48 +0000 Subject: [PATCH] Userland: Add aliases to the macro in BuggieBox Before, the `ENUMERATE_UTILITIES` macro only included utilities, and all the aliases to the utilities were explicitly handled. This patch combines utilities and aliases into one macro. This has the benefit of being able to do operations involving both utilities and aliases without having to choose which group to operate on first. Currently, aliases are mixed with utilities while maintaining alphabetical sort. --- Userland/BuggieBox/main.cpp | 75 +++++++++++++++++++------------------ 1 file changed, 39 insertions(+), 36 deletions(-) diff --git a/Userland/BuggieBox/main.cpp b/Userland/BuggieBox/main.cpp index d951d7ea3b..5621ae4cdd 100644 --- a/Userland/BuggieBox/main.cpp +++ b/Userland/BuggieBox/main.cpp @@ -9,40 +9,48 @@ #include #include -#define ENUMERATE_UTILITIES(E) \ - E(cat) \ - E(checksum) \ - E(chmod) \ - E(chown) \ - E(cp) \ - E(df) \ - E(env) \ - E(file) \ - E(find) \ - E(id) \ - E(less) \ - E(ln) \ - E(ls) \ - E(lsblk) \ - E(mkdir) \ - E(mknod) \ - E(mount) \ - E(mv) \ - E(ps) \ - E(rm) \ - E(sh) \ - E(rmdir) \ - E(tail) \ - E(tree) \ - E(umount) \ - E(uname) \ +#define ENUMERATE_UTILITIES(E, ALIAS) \ + E(cat) \ + E(checksum) \ + E(chmod) \ + E(chown) \ + E(cp) \ + E(df) \ + E(env) \ + E(file) \ + E(find) \ + E(id) \ + E(less) \ + E(ln) \ + E(ls) \ + E(lsblk) \ + ALIAS(md5sum, checksum) \ + E(mkdir) \ + E(mknod) \ + E(mount) \ + E(mv) \ + E(ps) \ + E(rm) \ + E(rmdir) \ + E(sh) \ + ALIAS(sha1sum, checksum) \ + ALIAS(sha256sum, checksum) \ + ALIAS(sha512sum, checksum) \ + ALIAS(Shell, sh) \ + E(tail) \ + E(tree) \ + E(umount) \ + E(uname) \ E(uniq) // Declare the entrypoints of all the tools that we delegate to. +// Some tools have additional aliases that we skip in the declarations. // Relying on `decltype(serenity_main)` ensures that we always stay consistent with the `serenity_main` signature. #define DECLARE_ENTRYPOINT(name) decltype(serenity_main) name##_main; -ENUMERATE_UTILITIES(DECLARE_ENTRYPOINT) +#define SKIP(alias, name) +ENUMERATE_UTILITIES(DECLARE_ENTRYPOINT, SKIP) #undef DECLARE_ENTRYPOINT +#undef SKIP static void fail() { @@ -61,15 +69,10 @@ struct Runner { static constexpr Runner s_runners[] = { #define RUNNER_ENTRY(name) { #name##sv, name##_main }, - ENUMERATE_UTILITIES(RUNNER_ENTRY) +#define ALIAS_RUNNER_ENTRY(alias, name) { #alias##sv, name##_main }, + ENUMERATE_UTILITIES(RUNNER_ENTRY, ALIAS_RUNNER_ENTRY) #undef RUNNER_ENTRY - - // Some tools have additional aliases. - { "md5sum"sv, checksum_main }, - { "sha1sum"sv, checksum_main }, - { "sha256sum"sv, checksum_main }, - { "sha512sum"sv, checksum_main }, - { "Shell"sv, sh_main }, +#undef ALIAS_RUNNER_ENTRY }; static ErrorOr run_program(Main::Arguments arguments, LexicalPath const& runbase, bool& found_runner)