#include "l2su.h" #include "command.h" #include "macros.h" #include #include #include #include struct tag_l2_state_t l2_state = { 0 }; int l2_launcher_init(void) { /* find paths (set up l2_state.paths) */ /* create folders if they don't exist */ /* look for config path */ if (!(l2_state.paths.config = l2_launcher_find_config_path())) { fputs("fatal: Could not decide on a configuration directory! Please define " PROJECT_NAME_UPPER "_CONFIG to a sensible value.\n", stderr); return 1; } if (!(l2_state.paths.data = l2_launcher_find_data_path())) { fputs("fatal: Could not decide on a data directory! Please define " PROJECT_NAME_UPPER "_DATA to a sensible value.\n", stderr); return 1; } printf("Using configuration path: %s\n", l2_state.paths.config); printf("Using data path: %s\n", l2_state.paths.data); if (l2_launcher_mkdir_parents(l2_state.paths.config) < 0) { fprintf(stderr, "fatal: Could not create config directory: %s\n", strerror(errno)); return 1; } if (l2_launcher_mkdir_parents(l2_state.paths.data) < 0) { fprintf(stderr, "fatal: Could not create data directory: %s\n", strerror(errno)); return 1; } return 0; } int main(int argc, char **argv) { int status = l2_launcher_init(); if (status != 0) return EXIT_FAILURE; if (argc == 0 || !argv || !*argv) { fputs("weird: no program name!\n", stderr); return EXIT_FAILURE; } struct l2_parseinfo parseinfo; unsigned parseres = l2_cmd_parse_command(argv + 1, &parseinfo); if (parseres != CMD_PARSE_SUCCESS) { fputs("failed to parse command\n", stderr); return EXIT_FAILURE; } unsigned res = (*parseinfo.proc)(parseinfo.ctx, parseinfo.argv); l2_cmd_free_ctx(parseinfo.ctx); return res == CMD_RESULT_SUCCESS ? EXIT_SUCCESS : EXIT_FAILURE; }