penguins  1.0.0
main.c
Go to the documentation of this file.
1 #include "arguments.h"
2 #include "autonomous.h"
3 #include "interactive.h"
4 #include "penguins-version.h"
5 #include <stdio.h> // IWYU pragma: keep
6 
7 int main(int argc, char* argv[]) {
8  if (argc <= 1) {
9 #ifdef INTERACTIVE_MODE
10  return run_interactive_mode();
11 #else
12  fprintf(stderr, "The app has been compiled without the interactive mode!\n");
13  return EXIT_INTERNAL_ERROR;
14 #endif
15  }
16 
17  Arguments args;
18  char* prog_name = argc > 0 ? argv[0] : "penguins";
19  if (!parse_arguments(&args, argc, argv)) {
20  print_usage(prog_name);
21  return EXIT_INTERNAL_ERROR;
22  }
23 
24  if (args.action == ACTION_ARG_PRINT_HELP) {
25  print_usage(prog_name);
26  } else if (args.action == ACTION_ARG_PRINT_VERSION) {
27  fprintf(stderr, "%s v%s\n", prog_name, PENGUINS_VERSION_STRING);
28  } else if (args.action == ACTION_ARG_INTERACTIVE) {
29 #ifdef INTERACTIVE_MODE
30  return run_interactive_mode();
31 #else
32  fprintf(stderr, "The app has been compiled without the interactive mode!\n");
33  return EXIT_INTERNAL_ERROR;
34 #endif
35  } else {
36 #ifdef AUTONOMOUS_MODE
37  return run_autonomous_mode(&args);
38 #else
39  fprintf(stderr, "The app has been compiled without the autonomous mode!\n");
40  return EXIT_INTERNAL_ERROR;
41 #endif
42  }
43 
44  return EXIT_OK;
45 }
bool parse_arguments(Arguments *result, int argc, char *argv[])
Definition: arguments.c:36
void print_usage(const char *prog_name)
Definition: arguments.c:20
The command-line argument parser.
@ ACTION_ARG_PRINT_VERSION
Definition: arguments.h:15
@ ACTION_ARG_PRINT_HELP
Definition: arguments.h:14
@ ACTION_ARG_INTERACTIVE
Definition: arguments.h:16
int run_autonomous_mode(const Arguments *args)
Definition: autonomous.c:24
The autonomous-mode machine interface.
@ EXIT_INTERNAL_ERROR
Definition: autonomous.h:20
@ EXIT_OK
Definition: autonomous.h:17
int run_interactive_mode(void)
Definition: interactive.c:133
The interactive-mode text user interface.
int main(int argc, char *argv[])
Definition: main.c:7
ActionArg action
Definition: arguments.h:31