1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
#include "l2su.h"
#include "command.h"
#include "macros.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
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;
}
|