From 3c0fae06b5ae2c59bacd2e3d6a1033f864cd368e Mon Sep 17 00:00:00 2001 From: Jan200101 Date: Thu, 17 Dec 2020 15:03:27 +0100 Subject: replace gnu style quoting with normal quoting, comment command macros, … - gnu style quoting (`text') has been replaced with normal quoting ('text') - the command macros defined in command.h have been commented to explain how they are intended to be used and why they are how they - the macro that generates the command group function now prints a message if the given command has not been found (this probably needs to be extended to the other commands to be consistent) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/command.h | 41 ++++++++++++++++++++++++++++++++++++++--- src/dxvk.c | 14 +++++++------- src/lutris.c | 2 +- src/wine.c | 35 ++++++++++++++++++----------------- 4 files changed, 64 insertions(+), 28 deletions(-) (limited to 'src') diff --git a/src/command.h b/src/command.h index aeb4287..b45f8b9 100644 --- a/src/command.h +++ b/src/command.h @@ -4,10 +4,27 @@ #include #include "common.h" -#define COMMAND(GROUP, COMMAND)\ -int GROUP##_##COMMAND(UNUSED int argc, UNUSED char** argv) +/* + * the current command system polecat uses is simple and depends on + * int (*)(int, char**) function pointers, exactly the same as main + * because keeping track of all of those is rather tedious making + * macros was an easier solution to get rid of the redundancy + * for the sake of less readability. + * argc and argv are marked as UNUSED (defined in common.h) + * because the functions defined using this macro might not + * actually use either of them so this is required to + * supress warnings + */ +#define COMMAND(GROUP, COMMAND) \ + int GROUP##_##COMMAND(UNUSED int argc, UNUSED char** argv) +/* + * all help functions in polecat look the same invoking the print_help + * helper function defined in common.c with the command groups list + * of available commands. + * This also exists to reduce redundancy. + */ #define COMMAND_HELP(GROUP, MSG) \ COMMAND(GROUP, help) \ { \ @@ -16,16 +33,34 @@ int GROUP##_##COMMAND(UNUSED int argc, UNUSED char** argv) return 0; \ } +/* + * This is the same as the COMMAND macro except dedicated to the actual + * command group name, which is the thing called from the actual main + * function. + */ #define COMMAND_GROUP(GROUP) \ - int GROUP(int argc, char** argv) \ + int GROUP(int argc, char** argv) +/* + * the main command group function is only suppose to find given command + * by the name and then invoke it. + * + * If the desired command is not found we should tell the user that. + * + * If no command is provided we should just print the list of commands by + * calling the groups help command. + */ #define COMMAND_GROUP_FUNC(GROUP) \ COMMAND_GROUP(GROUP) \ { \ if (argc > 1) \ + { \ for (unsigned long i = 0; i < ARRAY_LEN(GROUP##_commands); ++i) \ if (!strcmp(GROUP##_commands[i].name, argv[1])) return GROUP##_commands[i].func(argc-1, argv+1); \ + fprintf(stderr, NAME ": '%s' is not a command\n", argv[1]); \ + return 0; \ + } \ return GROUP##_help(argc-1, argv+1); \ } diff --git a/src/dxvk.c b/src/dxvk.c index 65af7c5..3fb24cc 100644 --- a/src/dxvk.c +++ b/src/dxvk.c @@ -81,7 +81,7 @@ COMMAND(dxvk, download) } else { - fprintf(stderr, "Could not find `%s'\n", choice); + fprintf(stderr, "Could not find '%s'\n", choice); } json_object_put(runner); @@ -89,7 +89,7 @@ COMMAND(dxvk, download) } else { - fprintf(stderr, USAGE_STR " dxvk download \n\nversions are obtained via `" NAME " dxvk list'\n"); + fprintf(stderr, USAGE_STR " dxvk download \n\nversions are obtained via '" NAME " dxvk list'\n"); } return 0; } @@ -109,7 +109,7 @@ COMMAND(dxvk, remove) if (!isDir(dxvkpath)) { - fprintf(stderr, "`%s' is not an downloaded DXVK version\n", dxvkver); + fprintf(stderr, "'%s' is not an downloaded DXVK version\n", dxvkver); return 0; } @@ -126,7 +126,7 @@ COMMAND(dxvk, remove) return retval; } - fprintf(stderr, USAGE_STR " dxvk remove \n\nInstalled dxvk versions can be obtained by using `" NAME " dxvk list-installed\n"); + fprintf(stderr, USAGE_STR " dxvk remove \n\nInstalled dxvk versions can be obtained by using '" NAME " dxvk list-installed\n"); return 0; } @@ -167,7 +167,7 @@ COMMAND(dxvk, install) if (!isDir(dxvkpath)) { - fprintf(stderr, "`%s' is not an downloaded DXVK version\n", dxvkver); + fprintf(stderr, "'%s' is not an downloaded DXVK version\n", dxvkver); return 0; } @@ -181,13 +181,13 @@ COMMAND(dxvk, install) } else { - fprintf(stderr, "cannot find the setup script for `%s'\n", dxvkver); + fprintf(stderr, "cannot find the setup script for '%s'\n", dxvkver); } } else { - fprintf(stderr, "Specify a what DXVK version to install.\nUse `" NAME " dxvk list-installed' to list available versions\n"); + fprintf(stderr, "Specify a what DXVK version to install.\nUse '" NAME " dxvk list-installed' to list available versions\n"); } diff --git a/src/lutris.c b/src/lutris.c index a5f8ebd..b53ebda 100644 --- a/src/lutris.c +++ b/src/lutris.c @@ -182,7 +182,7 @@ COMMAND(lutris, info) } else { - printf("Couldn't find an installer by the name `%s'\n", argv[1]); + printf("Couldn't find an installer by the name '%s'\n", argv[1]); } lutris_freeInstaller(&installer); diff --git a/src/wine.c b/src/wine.c index a905c91..c37f7bd 100644 --- a/src/wine.c +++ b/src/wine.c @@ -87,7 +87,7 @@ COMMAND(wine, download) } else { - fprintf(stderr, "Could not find `%s'\n", choice); + fprintf(stderr, "Could not find '%s'\n", choice); } } @@ -96,7 +96,7 @@ COMMAND(wine, download) } else { - fprintf(stderr, USAGE_STR " wine download [versions]\n\nversions are obtained via `" NAME " wine list'\n"); + fprintf(stderr, USAGE_STR " wine download [versions]\n\nversions are obtained via '" NAME " wine list'\n"); } return 0; } @@ -129,7 +129,7 @@ COMMAND(wine, remove) // if it still doesn't exist tell this wine version is not installed if (!isDir(winepath)) { - fprintf(stderr, "`%s' is not an installed wine version\n", winever); + fprintf(stderr, "'%s' is not an installed wine version\n", winever); return 0; } } @@ -147,7 +147,7 @@ COMMAND(wine, remove) return retval; } - fprintf(stderr, USAGE_STR " wine remove \n\nInstalled wine versions can be obtained by using `" NAME " wine list-installed\n"); + fprintf(stderr, USAGE_STR " wine remove \n\nInstalled wine versions can be obtained by using '" NAME " wine list-installed\n"); return 0; } @@ -194,7 +194,7 @@ COMMAND(wine, run) if (!isDir(winepath)) { - // if the wine version does not exist try appending the system arch e.g. x86_64 + // try appending the system arch to find the wine version struct utsname buffer; if (!uname(&buffer)) @@ -203,11 +203,11 @@ COMMAND(wine, run) strncat(winepath, buffer.machine, sizeof(winepath) - strlen(winepath) - 1); } - // if it still doesn't exist tell this wine version is not installed + // if we still cannot find anything tell the user and exit if (!isDir(winepath)) { - fprintf(stderr, "`%s' is not an installed wine version\n", winever); - return 0; + fprintf(stderr, "'%s' is not an installed wine version\n", winever); + return 1; } } @@ -223,7 +223,7 @@ COMMAND(wine, run) default: #ifdef DEBUG - fprintf(stderr, "Couldn't find figure out if this `%s' is Wine or Proton, defaulting to Wine\n", winever); + fprintf(stderr, "Couldn't find figure out if this '%s' is Wine or Proton, defaulting to Wine\n", winever); #endif winebinloc = WINEBIN; break; @@ -235,6 +235,7 @@ COMMAND(wine, run) { for (int i = 2; i < argc; ++i) { + // make sure the passed arguments are in quotes so spaces don't cause problems strncat(winepath, " \"", sizeof(winepath) - strlen(winepath) - 1); strncat(winepath, argv[i], sizeof(winepath) - strlen(winepath) - 1); strncat(winepath, "\"", sizeof(winepath) - strlen(winepath) - 1); @@ -244,12 +245,12 @@ COMMAND(wine, run) } else { - fprintf(stderr, "cannot find wine for `%s'\n", winever); + fprintf(stderr, "cannot find wine for '%s'\n", winever); } } - fprintf(stderr, "Specify a what wine version to run.\nUse `" NAME " wine list-installed' to list available versions\n"); + fprintf(stderr, "Specify a what wine version to run.\nUse '" NAME " wine list-installed' to list available versions\n"); return 0; } @@ -312,7 +313,7 @@ COMMAND(wine, env) // if it still doesn't exist tell this wine version is not installed if (!isDir(winepath)) { - fprintf(stderr, "`%s' is not an installed wine version\n", winever); + fprintf(stderr, "'%s' is not an installed wine version\n", winever); return 0; } } @@ -329,7 +330,7 @@ COMMAND(wine, env) default: #ifdef DEBUG - fprintf(stderr, "Couldn't find figure out if this `%s' is Wine or Proton, defaulting to Wine", winever); + fprintf(stderr, "Couldn't find figure out if this '%s' is Wine or Proton, defaulting to Wine", winever); #endif winebinloc = WINEBIN; break; @@ -345,7 +346,7 @@ COMMAND(wine, env) printf("To add a wine installation to your PATH\n" "you have to eval the output.\n\n"); if (!fish_env) - printf("$ eval `polecat wine env %s`\n", winever); + printf("$ eval 'polecat wine env %s'\n", winever); else printf("$ eval (polecat wine fish-env %s)\n", winever); } @@ -360,17 +361,17 @@ COMMAND(wine, env) printf("set PATH %s $PATH\n", winepath); } } - //printf("PATH=\"%s\"\n# Run this code in your Terminal\n# by running eval `%s`", newpath, argv[0]); + //printf("PATH=\"%s\"\n# Run this code in your Terminal\n# by running eval '%s'", newpath, argv[0]); } else { - fprintf(stderr, "cannot find wine for `%s'\n", winever); + fprintf(stderr, "cannot find wine for '%s'\n", winever); } } else { - fprintf(stderr, "Specify a what wine version to run.\nUse `" NAME " wine list-installed' to list available versions\n"); + fprintf(stderr, "Specify a what wine version to run.\nUse '" NAME " wine list-installed' to list available versions\n"); } -- cgit v1.2.3