2021-11-22 14:44:54 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2021, Andreas Kling <kling@serenityos.org>
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <AK/Format.h>
|
|
|
|
#include <AK/StringView.h>
|
|
|
|
#include <AK/Vector.h>
|
|
|
|
#include <LibMain/Main.h>
|
2021-11-22 15:00:53 +00:00
|
|
|
#include <string.h>
|
2022-01-28 12:33:59 +00:00
|
|
|
#include <time.h>
|
2021-11-22 14:44:54 +00:00
|
|
|
|
2022-03-19 17:06:56 +00:00
|
|
|
namespace Main {
|
|
|
|
|
|
|
|
static int s_return_code_for_errors = 1;
|
|
|
|
|
|
|
|
int return_code_for_errors()
|
|
|
|
{
|
|
|
|
return s_return_code_for_errors;
|
|
|
|
}
|
|
|
|
|
|
|
|
void set_return_code_for_errors(int code)
|
|
|
|
{
|
|
|
|
s_return_code_for_errors = code;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2021-11-22 14:44:54 +00:00
|
|
|
int main(int argc, char** argv)
|
|
|
|
{
|
2022-01-28 12:33:59 +00:00
|
|
|
tzset();
|
|
|
|
|
2021-11-22 14:44:54 +00:00
|
|
|
Vector<StringView> arguments;
|
|
|
|
arguments.ensure_capacity(argc);
|
|
|
|
for (int i = 0; i < argc; ++i)
|
2022-07-11 19:53:29 +00:00
|
|
|
arguments.unchecked_append({ argv[i], strlen(argv[i]) });
|
2021-11-22 14:44:54 +00:00
|
|
|
|
|
|
|
auto result = serenity_main({
|
|
|
|
.argc = argc,
|
|
|
|
.argv = argv,
|
2021-11-22 21:10:22 +00:00
|
|
|
.strings = arguments.span(),
|
2021-11-22 14:44:54 +00:00
|
|
|
});
|
|
|
|
if (result.is_error()) {
|
2021-11-22 15:00:53 +00:00
|
|
|
auto error = result.release_error();
|
2021-12-23 16:05:09 +00:00
|
|
|
warnln("\033[31;1mRuntime error\033[0m: {}", error);
|
2022-10-09 21:23:23 +00:00
|
|
|
#ifdef AK_OS_SERENITY
|
2021-12-20 18:48:44 +00:00
|
|
|
dbgln("\033[31;1mExiting with runtime error\033[0m: {}", error);
|
2021-12-22 04:51:23 +00:00
|
|
|
#endif
|
2022-03-19 17:06:56 +00:00
|
|
|
return Main::return_code_for_errors();
|
2021-11-22 14:44:54 +00:00
|
|
|
}
|
|
|
|
return result.value();
|
|
|
|
}
|