mirror of
https://github.com/RGBCube/serenity
synced 2025-05-14 09:34:59 +00:00
hexdump: Port to LibMain
This commit is contained in:
parent
02cb34a48a
commit
dbcccde062
2 changed files with 7 additions and 11 deletions
|
@ -7,6 +7,7 @@
|
|||
#include <AK/Array.h>
|
||||
#include <LibCore/ArgsParser.h>
|
||||
#include <LibCore/File.h>
|
||||
#include <LibMain/Main.h>
|
||||
#include <ctype.h>
|
||||
#include <string.h>
|
||||
|
||||
|
@ -18,7 +19,7 @@ enum class State {
|
|||
SkipPrint
|
||||
};
|
||||
|
||||
int main(int argc, char** argv)
|
||||
ErrorOr<int> serenity_main(Main::Arguments args)
|
||||
{
|
||||
Core::ArgsParser args_parser;
|
||||
const char* path = nullptr;
|
||||
|
@ -26,20 +27,14 @@ int main(int argc, char** argv)
|
|||
args_parser.add_positional_argument(path, "Input", "input", Core::ArgsParser::Required::No);
|
||||
args_parser.add_option(verbose, "Display all input data", "verbose", 'v');
|
||||
|
||||
args_parser.parse(argc, argv);
|
||||
args_parser.parse(args);
|
||||
|
||||
RefPtr<Core::File> file;
|
||||
|
||||
if (!path) {
|
||||
if (!path)
|
||||
file = Core::File::standard_input();
|
||||
} else {
|
||||
auto file_or_error = Core::File::open(path, Core::OpenMode::ReadOnly);
|
||||
if (file_or_error.is_error()) {
|
||||
warnln("Failed to open {}: {}", path, file_or_error.error());
|
||||
return 1;
|
||||
}
|
||||
file = file_or_error.value();
|
||||
}
|
||||
else
|
||||
file = TRY(Core::File::open(path, Core::OpenMode::ReadOnly));
|
||||
|
||||
auto print_line = [](u8* buf, size_t size) {
|
||||
VERIFY(size <= LINE_LENGTH_BYTES);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue