Main.cpp 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. /*
  2. * Copyright (c) 2021, Andreas Kling <kling@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include <AK/Format.h>
  7. #include <AK/StringView.h>
  8. #include <AK/Vector.h>
  9. #include <LibMain/Main.h>
  10. #include <string.h>
  11. #include <time.h>
  12. namespace Main {
  13. static int s_return_code_for_errors = 1;
  14. int return_code_for_errors()
  15. {
  16. return s_return_code_for_errors;
  17. }
  18. void set_return_code_for_errors(int code)
  19. {
  20. s_return_code_for_errors = code;
  21. }
  22. }
  23. int main(int argc, char** argv)
  24. {
  25. tzset();
  26. Vector<StringView> arguments;
  27. arguments.ensure_capacity(argc);
  28. for (int i = 0; i < argc; ++i)
  29. arguments.unchecked_append({ argv[i], strlen(argv[i]) });
  30. auto result = serenity_main({
  31. .argc = argc,
  32. .argv = argv,
  33. .strings = arguments.span(),
  34. });
  35. if (result.is_error()) {
  36. auto error = result.release_error();
  37. warnln("\033[31;1mRuntime error\033[0m: {}", error);
  38. #ifdef __serenity__
  39. dbgln("\033[31;1mExiting with runtime error\033[0m: {}", error);
  40. #endif
  41. return Main::return_code_for_errors();
  42. }
  43. return result.value();
  44. }