1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 00:07:36 +00:00

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.
This commit is contained in:
ronak69 2023-08-06 06:20:48 +00:00 committed by Tim Schumacher
parent debf38ee9d
commit 06ee4b66d0

View file

@ -9,40 +9,48 @@
#include <LibMain/Main.h> #include <LibMain/Main.h>
#include <Userland/Shell/Shell.h> #include <Userland/Shell/Shell.h>
#define ENUMERATE_UTILITIES(E) \ #define ENUMERATE_UTILITIES(E, ALIAS) \
E(cat) \ E(cat) \
E(checksum) \ E(checksum) \
E(chmod) \ E(chmod) \
E(chown) \ E(chown) \
E(cp) \ E(cp) \
E(df) \ E(df) \
E(env) \ E(env) \
E(file) \ E(file) \
E(find) \ E(find) \
E(id) \ E(id) \
E(less) \ E(less) \
E(ln) \ E(ln) \
E(ls) \ E(ls) \
E(lsblk) \ E(lsblk) \
E(mkdir) \ ALIAS(md5sum, checksum) \
E(mknod) \ E(mkdir) \
E(mount) \ E(mknod) \
E(mv) \ E(mount) \
E(ps) \ E(mv) \
E(rm) \ E(ps) \
E(sh) \ E(rm) \
E(rmdir) \ E(rmdir) \
E(tail) \ E(sh) \
E(tree) \ ALIAS(sha1sum, checksum) \
E(umount) \ ALIAS(sha256sum, checksum) \
E(uname) \ ALIAS(sha512sum, checksum) \
ALIAS(Shell, sh) \
E(tail) \
E(tree) \
E(umount) \
E(uname) \
E(uniq) E(uniq)
// Declare the entrypoints of all the tools that we delegate to. // 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. // 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; #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 DECLARE_ENTRYPOINT
#undef SKIP
static void fail() static void fail()
{ {
@ -61,15 +69,10 @@ struct Runner {
static constexpr Runner s_runners[] = { static constexpr Runner s_runners[] = {
#define RUNNER_ENTRY(name) { #name##sv, name##_main }, #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 #undef RUNNER_ENTRY
#undef ALIAS_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 },
}; };
static ErrorOr<int> run_program(Main::Arguments arguments, LexicalPath const& runbase, bool& found_runner) static ErrorOr<int> run_program(Main::Arguments arguments, LexicalPath const& runbase, bool& found_runner)