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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
|
#include <stdio.h>
#include <string.h>
#include <limits.h>
#include <libgen.h>
#include "main.h"
#ifdef WINE_ENABLED
#include "wine.h"
#endif
#ifdef DXVK_ENABLED
#include "dxvk.h"
#endif
#ifdef LUTRIS_ENABLED
#include "lutris.h"
#endif
#include "common.h"
#include "config.h"
#ifdef WINE_ENABLED
// if something fails
// we need to free the new argv
char** nargv;
static void free_nargv() { free(nargv); }
#endif
static const struct Command main_commands[] = {
#ifdef WINE_ENABLED
{ .name = "wine", .func = winecmd, .description = "manage wine versions" },
#endif
#ifdef DXVK_ENABLED
{ .name = "dxvk", .func = dxvk, .description = "manage DXVK versions" },
#endif
#ifdef LUTRIS_ENABLED
{ .name = "lutris", .func = lutris, .description = "run lutris instraller"},
#endif
{ .name = "env", .func = main_env, .description = "show some information about polecat" },
};
static const struct Flag main_flags[] = {
{ .name = "help", .variant = TWO, .returns = 1, .func = main_help, .description = "show this message"},
{ .name = "version", .variant = BOTH, .returns = 1, .func = main_version, .description = "prints the program version"}
};
COMMAND_GROUP(main)
{
#ifdef WINE_ENABLED
char* arg0 = basename(argv[0]);
if (!strncmp(WINE_PREFIX, arg0, strlen(WINE_PREFIX)))
{
int nargc = argc + 3;
nargv = malloc((size_t)(nargc+1) * sizeof(char*));
nargv[0] = argv[0];
nargv[1] = "wine";
nargv[2] = "run";
nargv[3] = arg0 + strlen(WINE_PREFIX);
for (int i = 1; i < argc; ++i) nargv[3+i] = argv[i];
nargv[nargc] = NULL;
argc = nargc;
argv = nargv;
/* we cannot free nargv before the body parsed it
* and we cannot free it after because the body
* returns, so call this at exit to free the leak
*/
atexit(free_nargv);
}
#endif
COMMAND_GROUP_BODY(main)
}
COMMAND(main, env)
{
char buffer[PATH_MAX];
printf("user-Agent:\t\t%s\n", USER_AGENT);
getConfigDir(buffer, sizeof(buffer));
printf("config dir\t\t%s\n", buffer);
getDataDir(buffer, sizeof(buffer));
printf("data dir\t\t%s\n", buffer);
return EXIT_SUCCESS;
}
COMMAND(main, version)
{
puts(VERSION);
return EXIT_SUCCESS;
}
COMMAND_HELP(main, "")
|