diff options
author | Jan200101 <sentrycraft123@gmail.com> | 2020-12-16 16:35:10 +0100 |
---|---|---|
committer | Jan200101 <sentrycraft123@gmail.com> | 2020-12-16 16:35:10 +0100 |
commit | 1ca0317a351f3075b2ea0b9bb5e59ccb4bcb960b (patch) | |
tree | 4555aeb903071e2a12f66eff46fea403b716257d | |
parent | 7cfe6b1e6132e608fcc034bf97611e4b1eb57613 (diff) | |
download | polecat-1ca0317a351f3075b2ea0b9bb5e59ccb4bcb960b.tar.gz polecat-1ca0317a351f3075b2ea0b9bb5e59ccb4bcb960b.zip |
add more warning flags, correct syntax, add UNUSED macro, […]
- added -Wall -Wextra -pedantic to the compile options
- various syntax has been corrected:
- static is used before const
- correct integer types are used in for loops
- empty newlines are added
- every command has an argc and argv but some don't use them so they are marked as potentially unused if compiled on a GNUC compatible compiler
- mark JSONC variables as advanced so they do not show up as generic variables
-rw-r--r-- | CMakeLists.txt | 2 | ||||
-rw-r--r-- | README.md | 10 | ||||
-rw-r--r-- | cmake/FindJsonC.cmake | 2 | ||||
-rw-r--r-- | src/command.h | 6 | ||||
-rw-r--r-- | src/common.c | 4 | ||||
-rw-r--r-- | src/common.h | 10 | ||||
-rw-r--r-- | src/config.c | 2 | ||||
-rw-r--r-- | src/dxvk.c | 6 | ||||
-rw-r--r-- | src/dxvk.h | 2 | ||||
-rw-r--r-- | src/lutris.c | 24 | ||||
-rw-r--r-- | src/main.c | 4 | ||||
-rw-r--r-- | src/main.h | 2 | ||||
-rw-r--r-- | src/net.h | 2 | ||||
-rw-r--r-- | src/tar.h | 2 | ||||
-rw-r--r-- | src/wine.c | 6 | ||||
-rw-r--r-- | src/wine.h | 2 |
16 files changed, 48 insertions, 38 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 34f4763..805cf91 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -39,4 +39,6 @@ target_include_directories(${CMAKE_PROJECT_NAME} PUBLIC ${LIBCURL_INCLUDE_DIRS}) target_include_directories(${CMAKE_PROJECT_NAME} PUBLIC ${JSONC_INCLUDE_DIRS}) target_include_directories(${CMAKE_PROJECT_NAME} PUBLIC ${LIBARCHIVE_INCLUDE_DIRS}) +target_compile_options(${CMAKE_PROJECT_NAME} PRIVATE -Wall -Wextra -pedantic) + install(TARGETS ${CMAKE_PROJECT_NAME}) @@ -15,13 +15,15 @@ Installers are planned and on their way ### Fedora polecat is available as a [COPR repository](https://copr.fedorainfracloud.org/coprs/sentry/polecat/) -`sudo dnf copr enable sentry/polecat` -`sudo dnf install polecat` +``` +sudo dnf copr enable sentry/polecat +sudo dnf install polecat +``` ### Arch -polecat is available on the AUR -use your favorite AUR manager to install it +polecat is available on the [AUR](https://aur.archlinux.org/packages/polecat/) +## ## Dependencies diff --git a/cmake/FindJsonC.cmake b/cmake/FindJsonC.cmake index 028bb2f..cada971 100644 --- a/cmake/FindJsonC.cmake +++ b/cmake/FindJsonC.cmake @@ -33,7 +33,7 @@ find_library(JSONC_LIB include(FindPackageHandleStandardArgs) find_package_handle_standard_args(JsonC DEFAULT_MSG JSONC_LIB JSONC_INC) -mark_as_advanced(JSON_INC JSON_LIB) +mark_as_advanced(JSONC_INC JSONC_LIB) if(JSONC_FOUND) set(JSONC_INCLUDE_DIRS ${JSONC_INC}) diff --git a/src/command.h b/src/command.h index 9aeb07e..aeb4287 100644 --- a/src/command.h +++ b/src/command.h @@ -5,7 +5,7 @@ #include "common.h" #define COMMAND(GROUP, COMMAND)\ -int GROUP##_##COMMAND(int argc, char** argv) +int GROUP##_##COMMAND(UNUSED int argc, UNUSED char** argv) #define COMMAND_HELP(GROUP, MSG) \ @@ -24,9 +24,9 @@ int GROUP##_##COMMAND(int argc, char** argv) COMMAND_GROUP(GROUP) \ { \ if (argc > 1) \ - for (int i = 0; i < ARRAY_LEN(GROUP##_commands); ++i) \ + 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); \ return GROUP##_help(argc-1, argv+1); \ } -#endif
\ No newline at end of file +#endif diff --git a/src/common.c b/src/common.c index 7f91105..17edbd9 100644 --- a/src/common.c +++ b/src/common.c @@ -58,7 +58,7 @@ int makeDir(const char* path) char pathcpy[PATH_MAX]; char *index; - strncpy(pathcpy, path, PATH_MAX); // make a mutable copy of the path + strncpy(pathcpy, path, PATH_MAX-1); // make a mutable copy of the path for(index = pathcpy+1; *index; ++index) { @@ -126,4 +126,4 @@ int removeDir(const char *path) { r = rmdir(path); return r; -}
\ No newline at end of file +} diff --git a/src/common.h b/src/common.h index f376195..5916b99 100644 --- a/src/common.h +++ b/src/common.h @@ -28,9 +28,15 @@ #define USAGE_STR "Usage: " NAME #ifdef DEBUG -#define unreachable printf("unreachable code reached\n" __FILE__ ":L%i\n", __LINE__); exit(0); +#define UNREACHABLE printf("unreachable code reached\n" __FILE__ ":L%i\n", __LINE__); exit(0); #else -#define unreachable +#define UNREACHABLE +#endif + +#ifdef __GNUC__ +#define UNUSED __attribute__((__unused__)) +#else +#define UNUSED #endif struct MemoryStruct { diff --git a/src/config.c b/src/config.c index 318b196..85aaf40 100644 --- a/src/config.c +++ b/src/config.c @@ -49,4 +49,4 @@ void getDXVKDir(char* config, const size_t size) { getDataDir(config, size); strncat(config, "/dxvk", size - strlen(config) - 1); -}
\ No newline at end of file +} @@ -12,7 +12,7 @@ #include "tar.h" #include "config.h" -const static struct Command dxvk_commands[] = { +static const struct Command dxvk_commands[] = { { .name = "download", .func = dxvk_download, .description = "download and install a dxvk version" }, { .name = "remove", .func = dxvk_remove, .description = "remove a dxvk version" }, { .name = "list", .func = dxvk_list, .description = "list available dxvk versions" }, @@ -36,7 +36,7 @@ COMMAND(dxvk, download) char* choice = argv[1]; - for (int i = 0; i < json_object_array_length(runner); ++i) + for (size_t i = 0; i < json_object_array_length(runner); ++i) { value = json_object_array_get_idx(runner, i); json_object_object_get_ex(value, "tag_name", &temp); @@ -221,4 +221,4 @@ COMMAND(dxvk, installed) return 0; } -COMMAND_HELP(dxvk, " dxvk");
\ No newline at end of file +COMMAND_HELP(dxvk, " dxvk") @@ -13,4 +13,4 @@ COMMAND(dxvk, install); COMMAND(dxvk, installed); COMMAND(dxvk, help); -#endif
\ No newline at end of file +#endif diff --git a/src/lutris.c b/src/lutris.c index 5e213ff..a5f8ebd 100644 --- a/src/lutris.c +++ b/src/lutris.c @@ -8,7 +8,7 @@ #include "lutris.h" #include "net.h" -const static struct Command lutris_commands[] = { +static const struct Command lutris_commands[] = { #ifdef DEBUG { .name = "install", .func = lutris_install, .description = "install a lutris script" }, #endif @@ -93,7 +93,7 @@ COMMAND(lutris, install) break; default: - unreachable; + UNREACHABLE break; } } @@ -126,7 +126,7 @@ COMMAND(lutris, install) break; default: - unreachable; + UNREACHABLE break; } } @@ -155,7 +155,7 @@ COMMAND(lutris, info) if (installer.filecount) { puts("\nFiles:"); - for (int i = 0; i < installer.filecount; ++i) + for (size_t i = 0; i < installer.filecount; ++i) { printf("\t%s ->%s\n", installer.files[i]->filename, installer.files[i]->url); } @@ -165,13 +165,13 @@ COMMAND(lutris, info) { puts("\nDirectives:"); - for (int i = 0; i < installer.directivecount; ++i) + for (size_t i = 0; i < installer.directivecount; ++i) { printf("\t%s", keywordstr[installer.directives[i]->command]); if (installer.directives[i]->task != NO_TASK) printf(" %s", taskKeywordstr[installer.directives[i]->task]); - for (int j = 0; j < installer.directives[i]->size; ++j) + for (size_t j = 0; j < installer.directives[i]->size; ++j) { printf(" %s", installer.directives[i]->arguments[j]); } @@ -297,7 +297,7 @@ struct script_t lutris_getInstaller(char* installername) installer.filecount = json_object_array_length(files); installer.files = malloc(installer.filecount * sizeof(void*)); - for (int i = 0; i < installer.filecount; ++i) + for (size_t i = 0; i < installer.filecount; ++i) { struct json_object* file = json_object_array_get_idx(files, i); struct lh_entry* entry = json_object_get_object(file)->head; @@ -337,7 +337,7 @@ struct script_t lutris_getInstaller(char* installername) installer.directivecount = json_object_array_length(scriptinstall); installer.directives = malloc(installer.directivecount * sizeof(void*)); - for (int i = 0; i < installer.directivecount; ++i) + for (size_t i = 0; i < installer.directivecount; ++i) { struct json_object* step = json_object_array_get_idx(scriptinstall, i); struct json_object* directive; @@ -457,7 +457,7 @@ struct script_t lutris_getInstaller(char* installername) } installer.directives[i]->arguments = malloc(installer.directives[i]->size * sizeof(char*)); - for (int j = 0; j < installer.directives[i]->size; ++j) + for (size_t j = 0; j < installer.directives[i]->size; ++j) { str = json_object_get_string(options[j+offset]); installer.directives[i]->arguments[j] = malloc(strlen(str) * sizeof(char) +1); @@ -494,9 +494,9 @@ void lutris_freeInstaller(struct script_t* installer) if (installer->directives) { - for (int i = 0; i < installer->directivecount; ++i) + for (size_t i = 0; i < installer->directivecount; ++i) { - for (int j = 0; j < installer->directives[i]->size; ++j) + for (size_t j = 0; j < installer->directives[i]->size; ++j) { free(installer->directives[i]->arguments[j]); } @@ -509,7 +509,7 @@ void lutris_freeInstaller(struct script_t* installer) if (installer->files) { - for (int i = 0; i < installer->filecount; ++i) + for (size_t i = 0; i < installer->filecount; ++i) { free(installer->files[i]->filename); free(installer->files[i]->url); @@ -10,7 +10,7 @@ #include "common.h" #include "config.h" -const static struct Command main_commands[] = { +static const struct Command main_commands[] = { { .name = "wine", .func = wine, .description = "manage wine versions" }, { .name = "dxvk", .func = dxvk, .description = "manage DXVK versions" }, { .name = "lutris", .func = lutris, .description = "run lutris instraller"}, @@ -40,4 +40,4 @@ COMMAND(main, env) return 0; } -COMMAND_HELP(main, "")
\ No newline at end of file +COMMAND_HELP(main, "") @@ -6,4 +6,4 @@ COMMAND(main, env); COMMAND(main, help); -#endif
\ No newline at end of file +#endif @@ -7,4 +7,4 @@ size_t WriteMemoryCallback(void*, size_t, size_t, void*); struct MemoryStruct* downloadToRam(const char* URL); struct json_object* fetchJSON(const char*); -#endif
\ No newline at end of file +#endif @@ -5,4 +5,4 @@ void extract(const struct MemoryStruct* tar, const char* outputdir); -#endif
\ No newline at end of file +#endif @@ -15,7 +15,7 @@ #include "config.h" #include "common.h" -const static struct Command wine_commands[] = { +static const struct Command wine_commands[] = { { .name = "download", .func = wine_download, .description = "download and extract a wine versions" }, { .name = "remove", .func = wine_remove, .description = "remove a wine version" }, { .name = "list", .func = wine_list, .description = "list installable wine versions" }, @@ -45,7 +45,7 @@ COMMAND(wine, download) char* choice = argv[i]; - for (int i = 0; i < json_object_array_length(versions); ++i) + for (size_t i = 0; i < json_object_array_length(versions); ++i) { value = json_object_array_get_idx(versions, i); json_object_object_get_ex(value, "version", &temp); @@ -377,7 +377,7 @@ COMMAND(wine, env) return 0; } -COMMAND_HELP(wine, " wine"); +COMMAND_HELP(wine, " wine") enum wine_type_t check_wine_ver(char* winepath, size_t size) { @@ -25,4 +25,4 @@ COMMAND(wine, help); enum wine_type_t check_wine_ver(char*, size_t); -#endif
\ No newline at end of file +#endif |