aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/CMakeLists.txt5
-rw-r--r--src/defines.h4
-rw-r--r--src/lutris.c99
-rw-r--r--src/lutris.h74
-rw-r--r--src/lutris/array.h5
-rw-r--r--src/lutris/enum.h5
-rw-r--r--src/lutris/keyword.h12
-rw-r--r--src/lutris/runner.h11
-rw-r--r--src/lutris/task.h5
-rw-r--r--src/main.c2
-rw-r--r--src/net.c2
-rw-r--r--src/wine.c40
-rw-r--r--src/wine.h16
13 files changed, 144 insertions, 136 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 16d1b5e..e2eef6c 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -10,6 +10,11 @@ set(SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/dxvk.h
${CMAKE_CURRENT_SOURCE_DIR}/lutris.c
${CMAKE_CURRENT_SOURCE_DIR}/lutris.h
+ ${CMAKE_CURRENT_SOURCE_DIR}/lutris/array.h
+ ${CMAKE_CURRENT_SOURCE_DIR}/lutris/enum.h
+ ${CMAKE_CURRENT_SOURCE_DIR}/lutris/keyword.h
+ ${CMAKE_CURRENT_SOURCE_DIR}/lutris/runner.h
+ ${CMAKE_CURRENT_SOURCE_DIR}/lutris/task.h
${CMAKE_CURRENT_SOURCE_DIR}/main.c
${CMAKE_CURRENT_SOURCE_DIR}/main.h
${CMAKE_CURRENT_SOURCE_DIR}/net.c
diff --git a/src/defines.h b/src/defines.h
index 115ddf0..5b37427 100644
--- a/src/defines.h
+++ b/src/defines.h
@@ -27,8 +27,8 @@
#define USAGE_STR "Usage: " NAME
-#ifdef DEBUG
-#define UNREACHABLE printf("unreachable code reached\n" __FILE__ ":L%i\n", __LINE__); exit(0);
+#ifndef NDEBUG
+#define UNREACHABLE printf("!!!UNREACHABLE CODE REACHED!!!\n" __FILE__ ":L%i\n", __LINE__); exit(0);
#else
#define UNREACHABLE
#endif
diff --git a/src/lutris.c b/src/lutris.c
index 26d8bb6..abef447 100644
--- a/src/lutris.c
+++ b/src/lutris.c
@@ -9,6 +9,8 @@
#include "lutris.h"
#include "net.h"
+#define PERCENT_SPACE "%20"
+
static const struct Command lutris_commands[] = {
{ .name = "info", .func = lutris_info, .description = "show information about a lutris script" },
{ .name = "install", .func = lutris_install, .description = "install a lutris script" },
@@ -174,35 +176,35 @@ COMMAND(lutris, install)
switch(installer.directives[i]->command)
{
- case MOVE:
+ case move:
// TODO
break;
- case MERGE:
+ case merge:
// TODO
break;
- case EXTRACT:
+ case extract:
// TODO
break;
- case COPY:
+ case copy:
// TODO
break;
- case CHMODX:
+ case chmodx:
chmod(installer.directives[i]->arguments[0], S_IXUSR);
break;
- case EXECUTE:
+ case execute:
// TODO
break;
- case WRITE_FILE:
- case WRITE_JSON:
+ case write_file:
+ case write_json:
// TODO
break;
- case WRITE_CONFIG:
+ case write_config:
// TODO
break;
- case INPUT_MENU:
+ case input_menu:
installer.variablecount++;
installer.variables = realloc(installer.variables, installer.variablecount * sizeof(void*));
installer.variables[installer.variablecount-1] = malloc(sizeof(struct list_t));
@@ -211,11 +213,11 @@ COMMAND(lutris, install)
installer.variables[installer.variablecount-1]->value.str = installer.directives[i]->arguments[1];
break;
- case INSERT_DISC:
+ case insert_disc:
// TODO
break;
- case TASK:
+ case task:
parseVar(&installer.directives[i]->arguments[0], installer.variables, installer.variablecount);
#ifndef _WIN32 // TODO
@@ -223,15 +225,15 @@ COMMAND(lutris, install)
#endif
switch(installer.directives[i]->task)
{
- case WINEEXEC:
+ case wineexec:
printf("WINEEXEC\n");
break;
- case WINETRICKS:
+ case winetricks:
printf("WINETRICKS\n");
break;
- case CREATE_PREFIX:
+ case create_prefix:
printf("CREATE_PREFIX\n");
#ifndef _WIN32 // TODO
setenv("WINEDEBUG", "-all", 1);
@@ -242,25 +244,26 @@ COMMAND(lutris, install)
#endif
break;
- case SET_REGEDIT:
+ case set_regedit:
printf("SET_REGEDIT\n");
break;
- case WINEKILL:
+ case winekill:
printf("WINEKILL\n");
break;
case TASKKEYWORDMAX:
- case NO_TASK:
+ UNREACHABLE
+ case no_task:
break;
- case UNKNOWN_TASK:
+ case unknown_task:
printf("Unknown Task\n");
break;
}
break;
- case UNKNOWN_DIRECTIVE:
+ case unknown_keyword:
puts("Unknown directive\nIf you see this please report it with your system information and steps to reproduce this.");
break;
@@ -357,7 +360,7 @@ COMMAND(lutris, info)
{
printf("\t%s", keywordstr[installer.directives[i]->command]);
- if (installer.directives[i]->task != NO_TASK) printf(" %s", taskKeywordstr[installer.directives[i]->task]);
+ if (installer.directives[i]->task != no_task) printf(" %s", taskKeywordstr[installer.directives[i]->task]);
for (size_t j = 0; j < installer.directives[i]->size; ++j)
{
@@ -414,15 +417,13 @@ void lutris_escapeString(char* str, size_t size)
case ';':
case '=':
// since dest and src overlap we need a non overlapping solution
- memmove(str, str+1, (size_t)(tail-str-1));
+ memmove(str, str+1, (size_t)(tail-str));
break;
case ' ':
// spaces are special and need to be encoded
memmove(str+3, str+1, (size_t)(tail-str-3));
- str[0] = '%';
- str[1] = '2';
- str[2] = '0';
+ memcpy(str, PERCENT_SPACE, strlen(PERCENT_SPACE));
str += 3;
if (str >= tail) str[3] = '\0';
break;
@@ -439,7 +440,7 @@ struct script_t lutris_getInstaller(char* installername)
struct script_t installer;
installer.name = NULL;
installer.version = NULL;
- installer.runner = UNKNOWN_RUNNER;
+ installer.runner = unknown_runner;
installer.description = NULL;
installer.notes = NULL;
installer.wine = NULL;
@@ -474,7 +475,7 @@ struct script_t lutris_getInstaller(char* installername)
if(json_object_object_get_ex(slug, "script", &script))
{
{
- struct json_object* name, *version, *runner, *description, *notes, *wine, *winever;
+ struct json_object* name, *version, *runner, *description, *notes, *winever;
const char* namestr, *versionstr, *runnerstr, *descriptionstr, *notesstr, *winestr;
json_object_object_get_ex(slug, "name", &name);
@@ -514,8 +515,8 @@ struct script_t lutris_getInstaller(char* installername)
strcpy(installer.notes, notesstr);
}
- json_object_object_get_ex(script, "wine", &wine);
- json_object_object_get_ex(wine, "version", &winever);
+ json_object_object_get_ex(script, "wine", &winever);
+ json_object_object_get_ex(winever, "version", &winever);
if (winever)
{
winestr = json_object_get_string(winever);
@@ -590,8 +591,8 @@ struct script_t lutris_getInstaller(char* installername)
installer.directives[i] = malloc(sizeof(struct directive_t));
installer.directives[i]->size = 0;
- installer.directives[i]->command = UNKNOWN_DIRECTIVE;
- installer.directives[i]->task = NO_TASK;
+ installer.directives[i]->command = unknown_keyword;
+ installer.directives[i]->task = no_task;
for (int l = 0; l < KEYWORDMAX; ++l)
{
@@ -600,36 +601,36 @@ struct script_t lutris_getInstaller(char* installername)
struct json_object* options[5];
switch (l)
{
- case MOVE:
- case COPY:
- case MERGE:
+ case move:
+ case copy:
+ case merge:
json_object_object_get_ex(directive, "src", &options[0]);
json_object_object_get_ex(directive, "dst", &options[1]);
installer.directives[i]->size = 2;
break;
- case EXTRACT:
+ case extract:
json_object_object_get_ex(directive, "file", &options[0]);
installer.directives[i]->size = 1;
break;
- case CHMODX:
+ case chmodx:
options[0] = directive;
installer.directives[i]->size = 1;
break;
- case EXECUTE:
+ case execute:
if(!json_object_object_get_ex(directive, "command", &options[0])) json_object_object_get_ex(directive, "file", &options[0]);
installer.directives[i]->size = 1;
break;
- case WRITE_FILE:
+ case write_file:
json_object_object_get_ex(directive, "file", &options[0]);
json_object_object_get_ex(directive, "content", &options[1]);
installer.directives[i]->size = 2;
break;
- case WRITE_CONFIG:
+ case write_config:
json_object_object_get_ex(directive, "file", &options[0]);
json_object_object_get_ex(directive, "section", &options[1]);
json_object_object_get_ex(directive, "key", &options[2]);
@@ -637,25 +638,25 @@ struct script_t lutris_getInstaller(char* installername)
installer.directives[i]->size = 4;
break;
- case WRITE_JSON:
+ case write_json:
json_object_object_get_ex(directive, "file", &options[0]);
json_object_object_get_ex(directive, "data", &options[1]);
installer.directives[i]->size = 2;
break;
- case INPUT_MENU:
+ case input_menu:
json_object_object_get_ex(directive, "id", &options[0]);
json_object_object_get_ex(directive, "preselect", &options[1]);
json_object_object_get_ex(directive, "description", &options[2]);
installer.directives[i]->size = 3;
break;
- case INSERT_DISC:
+ case insert_disc:
json_object_object_get_ex(directive, "requires", &options[0]);
installer.directives[i]->size = 1;
break;
- case TASK:
+ case task:
json_object_object_get_ex(directive, "name", &options[0]);
const char* name = json_object_get_string(options[0]);
for (int k = 0; k < TASKKEYWORDMAX; ++k)
@@ -664,25 +665,25 @@ struct script_t lutris_getInstaller(char* installername)
{
switch(k)
{
- case WINEEXEC:
+ case wineexec:
json_object_object_get_ex(directive, "prefix", &options[1]);
json_object_object_get_ex(directive, "executable", &options[2]);
installer.directives[i]->size = 2;
break;
- case WINETRICKS:
+ case winetricks:
json_object_object_get_ex(directive, "prefix", &options[1]);
json_object_object_get_ex(directive, "app", &options[2]);
installer.directives[i]->size = 2;
break;
- case CREATE_PREFIX:
- case WINEKILL:
+ case create_prefix:
+ case winekill:
json_object_object_get_ex(directive, "prefix", &options[1]);
installer.directives[i]->size = 1;
break;
- case SET_REGEDIT:
+ case set_regedit:
json_object_object_get_ex(directive, "prefix", &options[1]);
json_object_object_get_ex(directive, "path", &options[2]);
json_object_object_get_ex(directive, "key", &options[3]);
@@ -700,7 +701,7 @@ struct script_t lutris_getInstaller(char* installername)
const char* str;
uint8_t offset = 0;
- if (installer.directives[i]->task != NO_TASK)
+ if (installer.directives[i]->task != no_task)
{
offset = 1;
}
diff --git a/src/lutris.h b/src/lutris.h
index abd56f7..074cebd 100644
--- a/src/lutris.h
+++ b/src/lutris.h
@@ -6,78 +6,42 @@
#define VARIABLESIGN '$'
+#include "lutris/enum.h"
enum keyword_t {
- MOVE = 0,
- MERGE,
- EXTRACT,
- COPY,
- CHMODX,
- EXECUTE,
- WRITE_FILE,
- WRITE_CONFIG,
- WRITE_JSON,
- INPUT_MENU,
- INSERT_DISC,
- TASK,
+ #include "lutris/keyword.h"
KEYWORDMAX,
- UNKNOWN_DIRECTIVE
-};
-
-static const char keywordstr[KEYWORDMAX][0xF] = {
- "move",
- "merge",
- "extract",
- "copy",
- "chmodx",
- "execute",
- "write_file",
- "write_config",
- "write_json",
- "input_menu",
- "insert-disc",
- "task",
+ unknown_keyword
};
enum task_t {
- WINEEXEC = 0,
- WINETRICKS,
- CREATE_PREFIX,
- SET_REGEDIT,
- WINEKILL,
+ #include "lutris/task.h"
TASKKEYWORDMAX,
- NO_TASK,
- UNKNOWN_TASK
-};
-
-static const char taskKeywordstr[TASKKEYWORDMAX][0xF] =
-{
- "wineexec",
- "winetricks",
- "create_prefix",
- "set_regedit",
- "winekill",
+ no_task,
+ unknown_task
};
enum runner_t {
- UNKNOWN_RUNNER,
- WINE,
- LINUX,
+ #include "lutris/runner.h"
RUNNERMAX
};
-/*
- * a list of all available runners could be fetched from lutris
- * but we keep a local copy of all supported runners
- * to reduce the amount of API calls needed
- */
+#include "lutris/array.h"
+static const char keywordstr[KEYWORDMAX][0xF] = {
+ #include "lutris/keyword.h"
+};
+
+
+static const char taskKeywordstr[TASKKEYWORDMAX][0xF] =
+{
+ #include "lutris/task.h"
+};
+
static const char runnerStr[RUNNERMAX][0xF] =
{
- "unknown",
- "wine",
- "linux",
+ #include "lutris/runner.h"
};
diff --git a/src/lutris/array.h b/src/lutris/array.h
new file mode 100644
index 0000000..ac1da1c
--- /dev/null
+++ b/src/lutris/array.h
@@ -0,0 +1,5 @@
+#ifdef CREATE_ENUM
+#undef CREATE_ENUM
+#endif
+
+#define CREATE_ENUM(x) #x, \ No newline at end of file
diff --git a/src/lutris/enum.h b/src/lutris/enum.h
new file mode 100644
index 0000000..2b91def
--- /dev/null
+++ b/src/lutris/enum.h
@@ -0,0 +1,5 @@
+#ifdef CREATE_ENUM
+#undef CREATE_ENUM
+#endif
+
+#define CREATE_ENUM(x) x, \ No newline at end of file
diff --git a/src/lutris/keyword.h b/src/lutris/keyword.h
new file mode 100644
index 0000000..c98f855
--- /dev/null
+++ b/src/lutris/keyword.h
@@ -0,0 +1,12 @@
+CREATE_ENUM(move)
+CREATE_ENUM(merge)
+CREATE_ENUM(extract)
+CREATE_ENUM(copy)
+CREATE_ENUM(chmodx)
+CREATE_ENUM(execute)
+CREATE_ENUM(write_file)
+CREATE_ENUM(write_config)
+CREATE_ENUM(write_json)
+CREATE_ENUM(input_menu)
+CREATE_ENUM(insert_disc)
+CREATE_ENUM(task) \ No newline at end of file
diff --git a/src/lutris/runner.h b/src/lutris/runner.h
new file mode 100644
index 0000000..b5373c2
--- /dev/null
+++ b/src/lutris/runner.h
@@ -0,0 +1,11 @@
+CREATE_ENUM(unknown_runner)
+CREATE_ENUM(wine)
+#ifdef linux
+#define _linux linux
+#undef linux
+#endif
+CREATE_ENUM(linux)
+#ifdef _linux
+#define linux _linux
+#undef _linux
+#endif \ No newline at end of file
diff --git a/src/lutris/task.h b/src/lutris/task.h
new file mode 100644
index 0000000..8a208df
--- /dev/null
+++ b/src/lutris/task.h
@@ -0,0 +1,5 @@
+CREATE_ENUM(wineexec)
+CREATE_ENUM(winetricks)
+CREATE_ENUM(create_prefix)
+CREATE_ENUM(set_regedit)
+CREATE_ENUM(winekill) \ No newline at end of file
diff --git a/src/main.c b/src/main.c
index 8a17e37..9c1eef8 100644
--- a/src/main.c
+++ b/src/main.c
@@ -19,7 +19,7 @@ static void free_nargv() { free(nargv); }
static const struct Command main_commands[] = {
#ifndef _WIN32
- { .name = "wine", .func = wine, .description = "manage wine versions" },
+ { .name = "wine", .func = winecmd, .description = "manage wine versions" },
#endif
{ .name = "dxvk", .func = dxvk, .description = "manage DXVK versions" },
{ .name = "lutris", .func = lutris, .description = "run lutris instraller"},
diff --git a/src/net.c b/src/net.c
index d5c3034..0996d79 100644
--- a/src/net.c
+++ b/src/net.c
@@ -92,7 +92,7 @@ struct MemoryStruct* downloadToRam(const char* URL, int progress)
{
free(chunk->memory);
free(chunk);
-#ifdef DEBUG
+#ifndef NDEBUG
printf("HTTP Error %li\n", http_code);
#endif
chunk = NULL;
diff --git a/src/wine.c b/src/wine.c
index 830f9ee..cf3bc7e 100644
--- a/src/wine.c
+++ b/src/wine.c
@@ -14,24 +14,24 @@
#include "config.h"
#include "common.h"
-static const struct Command wine_commands[] = {
- { .name = "download", .func = wine_download, .description = "download and extract a wine versions" },
- { .name = "env", .func = wine_env, .description = "add wine to your PATH in a POSIX shell"},
- { .name = "env-fish", .func = wine_env, .description = "add wine to your PATH in the fish shell"},
- { .name = "list", .func = wine_list, .description = "list installable wine versions" },
- { .name = "list-installed", .func = wine_installed, .description = "list already installed wine versions" },
- { .name = "remove", .func = wine_remove, .description = "remove a wine version" },
- { .name = "run", .func = wine_run, .description = "run an installed wine version" },
+static const struct Command winecmd_commands[] = {
+ { .name = "download", .func = winecmd_download, .description = "download and extract a wine versions" },
+ { .name = "env", .func = winecmd_env, .description = "add wine to your PATH in a POSIX shell"},
+ { .name = "env-fish", .func = winecmd_env, .description = "add wine to your PATH in the fish shell"},
+ { .name = "list", .func = winecmd_list, .description = "list installable wine versions" },
+ { .name = "list-installed", .func = winecmd_installed, .description = "list already installed wine versions" },
+ { .name = "remove", .func = winecmd_remove, .description = "remove a wine version" },
+ { .name = "run", .func = winecmd_run, .description = "run an installed wine version" },
};
-static const struct Flag wine_flags[] = {
- { .name = "help", .variant = TWO, .returns = 1, .func = wine_help, .description = "show this message"},
+static const struct Flag winecmd_flags[] = {
+ { .name = "help", .variant = TWO, .returns = 1, .func = winecmd_help, .description = "show this message"},
{ .name = "no-net", .variant = TWO, .returns = 0, .func = set_no_net, .description = "run commands without commitment"}
};
-COMMAND_GROUP_FUNC(wine)
+COMMAND_GROUP_FUNC(winecmd)
-COMMAND(wine, download)
+COMMAND(winecmd, download)
{
if (argc >= 2)
{
@@ -107,7 +107,7 @@ COMMAND(wine, download)
}
-COMMAND(wine, remove)
+COMMAND(winecmd, remove)
{
if (argc == 2)
{
@@ -158,7 +158,7 @@ COMMAND(wine, remove)
return EXIT_SUCCESS;
}
-COMMAND(wine, list)
+COMMAND(winecmd, list)
{
struct json_object* runner = fetchJSON(WINE_API);
@@ -185,7 +185,7 @@ COMMAND(wine, list)
return EXIT_SUCCESS;
}
-COMMAND(wine, run)
+COMMAND(winecmd, run)
{
if (argc > 1)
{
@@ -228,7 +228,7 @@ COMMAND(wine, run)
break;
default:
- #ifdef DEBUG
+ #ifndef NDEBUG
fprintf(stderr, "Couldn't find figure out if this '%s' is Wine or Proton, defaulting to Wine\n", winever);
#endif
winebinloc = WINEBIN;
@@ -254,7 +254,7 @@ COMMAND(wine, run)
return EXIT_SUCCESS;
}
-COMMAND(wine, installed)
+COMMAND(winecmd, installed)
{
char winedir[PATH_MAX];
getWineDir(winedir, sizeof(winedir));
@@ -289,7 +289,7 @@ COMMAND(wine, installed)
return EXIT_SUCCESS;
}
-COMMAND(wine, env)
+COMMAND(winecmd, env)
{
if (argc > 1)
{
@@ -335,7 +335,7 @@ COMMAND(wine, env)
break;
default:
- #ifdef DEBUG
+ #ifndef NDEBUG
fprintf(stderr, "Couldn't find figure out if this '%s' is Wine or Proton, defaulting to Wine", winever);
#endif
winebinloc = WINEBIN;
@@ -382,7 +382,7 @@ COMMAND(wine, env)
return EXIT_SUCCESS;
}
-COMMAND_HELP(wine, " wine")
+COMMAND_HELP(winecmd, " wine")
enum wine_type_t check_wine_ver(char* winepath, size_t size)
{
diff --git a/src/wine.h b/src/wine.h
index 30cc697..9b382df 100644
--- a/src/wine.h
+++ b/src/wine.h
@@ -14,14 +14,14 @@ enum wine_type_t {
WINE_PROTON
};
-COMMAND_GROUP(wine);
-COMMAND(wine, download);
-COMMAND(wine, remove);
-COMMAND(wine, list);
-COMMAND(wine, run);
-COMMAND(wine, installed);
-COMMAND(wine, env);
-COMMAND(wine, help);
+COMMAND_GROUP(winecmd);
+COMMAND(winecmd, download);
+COMMAND(winecmd, remove);
+COMMAND(winecmd, list);
+COMMAND(winecmd, run);
+COMMAND(winecmd, installed);
+COMMAND(winecmd, env);
+COMMAND(winecmd, help);
enum wine_type_t check_wine_ver(char*, size_t);