I discovered the static keyword
This commit is contained in:
+7
-3
@@ -1,5 +1,12 @@
|
||||
cmake_minimum_required(VERSION 3.10)
|
||||
|
||||
if(NOT CMAKE_BUILD_TYPE)
|
||||
set(CMAKE_BUILD_TYPE Release)
|
||||
endif()
|
||||
|
||||
set(CMAKE_CXX_FLAGS "-Wall -Wextra -pedantic -Werror -fsanitize=address")
|
||||
set(CMAKE_CXX_FLAGS_DEBUG "-g")
|
||||
set(CMAKE_CXX_FLAGS_RELEASE "-O2")
|
||||
|
||||
# generate the compile_commands for vscode / clang
|
||||
set(CMAKE_EXPORT_COMPILE_COMMANDS ON CACHE INTERNAL "")
|
||||
@@ -24,8 +31,6 @@ set(SOURCES
|
||||
# add the executable
|
||||
add_executable(ModManager src/main.c ${SOURCES})
|
||||
|
||||
add_compile_options(-Wall -Wextra -pedantic -Werror)
|
||||
|
||||
find_package(PkgConfig REQUIRED)
|
||||
pkg_search_module(GLIB REQUIRED glib-2.0)
|
||||
pkg_search_module(AUDIT REQUIRED audit)
|
||||
@@ -33,7 +38,6 @@ pkg_search_module(LIBXML REQUIRED libxml-2.0)
|
||||
|
||||
target_include_directories(ModManager PRIVATE ${GLIB_INCLUDE_DIRS} ${LIBXML_INCLUDE_DIRS} ${AUDIT_INCLUDE_DIRS})
|
||||
|
||||
add_compile_options(-fsanitize=address)
|
||||
add_link_options(-fsanitize=address)
|
||||
|
||||
target_link_libraries(ModManager ${GLIB_LDFLAGS})
|
||||
|
||||
+1
-1
@@ -8,7 +8,7 @@
|
||||
#include <glib.h>
|
||||
#include "file.h"
|
||||
|
||||
u_int32_t countSetBits(u_int32_t n) {
|
||||
static u_int32_t countSetBits(u_int32_t n) {
|
||||
// base case
|
||||
if (n == 0)
|
||||
return 0;
|
||||
|
||||
+10
-10
@@ -14,7 +14,7 @@
|
||||
#include "file.h"
|
||||
#include "libxml/globals.h"
|
||||
|
||||
int getInputCount(const char * input) {
|
||||
static int getInputCount(const char * input) {
|
||||
char buff[2];
|
||||
buff[1] = '\0';
|
||||
|
||||
@@ -40,21 +40,21 @@ int getInputCount(const char * input) {
|
||||
return elementCount;
|
||||
}
|
||||
|
||||
gint priorityCmp(gconstpointer a, gconstpointer b) {
|
||||
static gint priorityCmp(gconstpointer a, gconstpointer b) {
|
||||
const FOModFile_t * fileA = (const FOModFile_t *)a;
|
||||
const FOModFile_t * fileB = (const FOModFile_t *)b;
|
||||
|
||||
return fileA->priority - fileB->priority;
|
||||
}
|
||||
|
||||
void printfOptionsInOrder(FOModGroup_t group) {
|
||||
static void printfOptionsInOrder(FOModGroup_t group) {
|
||||
for(int i = 0; i < group.pluginCount; i++) {
|
||||
printf("%d, %s\n", i, group.plugins[i].name);
|
||||
printf("%s\n", group.plugins[i].description);
|
||||
}
|
||||
}
|
||||
|
||||
gint flagEqual(const FOModFlag_t * a, const FOModFlag_t * b) {
|
||||
static gint flagEqual(const FOModFlag_t * a, const FOModFlag_t * b) {
|
||||
int nameCmp = strcmp(a->name, b->name);
|
||||
if(nameCmp == 0) {
|
||||
if(strcmp(a->value, b->value) == 0)
|
||||
@@ -66,20 +66,20 @@ gint flagEqual(const FOModFlag_t * a, const FOModFlag_t * b) {
|
||||
return nameCmp;
|
||||
}
|
||||
|
||||
int stepCmpAsc(const void * stepA, const void * stepB) {
|
||||
static int stepCmpAsc(const void * stepA, const void * stepB) {
|
||||
const FOModStep_t * step1 = (const FOModStep_t *)stepA;
|
||||
const FOModStep_t * step2 = (const FOModStep_t *)stepB;
|
||||
return strcmp(step1->name, step2->name);
|
||||
}
|
||||
|
||||
int stepCmpDesc(const void * stepA, const void * stepB) {
|
||||
static int stepCmpDesc(const void * stepA, const void * stepB) {
|
||||
const FOModStep_t * step1 = (const FOModStep_t *)stepA;
|
||||
const FOModStep_t * step2 = (const FOModStep_t *)stepB;
|
||||
return 1 - strcmp(step1->name, step2->name);
|
||||
}
|
||||
|
||||
|
||||
void sortSteps(FOMod_t * fomod) {
|
||||
static void sortSteps(FOMod_t * fomod) {
|
||||
switch(fomod->stepOrder) {
|
||||
case ASC:
|
||||
qsort(fomod->steps, fomod->stepCount, sizeof(*fomod->steps), stepCmpAsc);
|
||||
@@ -93,19 +93,19 @@ void sortSteps(FOMod_t * fomod) {
|
||||
}
|
||||
}
|
||||
|
||||
int groupCmpAsc(const void * stepA, const void * stepB) {
|
||||
static int groupCmpAsc(const void * stepA, const void * stepB) {
|
||||
const FOModGroup_t * step1 = (const FOModGroup_t *)stepA;
|
||||
const FOModGroup_t * step2 = (const FOModGroup_t *)stepB;
|
||||
return strcmp(step1->name, step2->name);
|
||||
}
|
||||
|
||||
int groupCmpDesc(const void * stepA, const void * stepB) {
|
||||
static int groupCmpDesc(const void * stepA, const void * stepB) {
|
||||
const FOModGroup_t * step1 = (const FOModGroup_t *)stepA;
|
||||
const FOModGroup_t * step2 = (const FOModGroup_t *)stepB;
|
||||
return 1 - strcmp(step1->name, step2->name);
|
||||
}
|
||||
|
||||
void sortGroup(FOModGroup_t * group) {
|
||||
static void sortGroup(FOModGroup_t * group) {
|
||||
switch(group->order) {
|
||||
case ASC:
|
||||
qsort(group->plugins, group->pluginCount, sizeof(*group->plugins), groupCmpAsc);
|
||||
|
||||
+5
-5
@@ -3,7 +3,7 @@
|
||||
#include "string.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
GroupType_t getGroupType(const char * type) {
|
||||
static GroupType_t getGroupType(const char * type) {
|
||||
if(strcmp(type, "SelectAtLeastOne") == 0) {
|
||||
return AT_LEAST_ONE;
|
||||
} else if(strcmp(type, "SelectAtMostOne") == 0) {
|
||||
@@ -19,7 +19,7 @@ GroupType_t getGroupType(const char * type) {
|
||||
}
|
||||
}
|
||||
|
||||
TypeDescriptor_t getDescriptor(const char * descriptor) {
|
||||
static TypeDescriptor_t getDescriptor(const char * descriptor) {
|
||||
if(strcmp(descriptor, "Optional") == 0) {
|
||||
return OPTIONAL;
|
||||
} else if(strcmp(descriptor, "Required") == 0) {
|
||||
@@ -64,7 +64,7 @@ void freeGroup(FOModGroup_t * group) {
|
||||
group->pluginCount = 0;
|
||||
}
|
||||
|
||||
int parseConditionFlags(FOModPlugin_t * plugin, xmlNodePtr nodeElement) {
|
||||
static int parseConditionFlags(FOModPlugin_t * plugin, xmlNodePtr nodeElement) {
|
||||
xmlNodePtr flagNode = nodeElement->children;
|
||||
while(flagNode != NULL) {
|
||||
if(!validateNode(&flagNode, true, "flag", NULL)) {
|
||||
@@ -89,7 +89,7 @@ int parseConditionFlags(FOModPlugin_t * plugin, xmlNodePtr nodeElement) {
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int parseGroupFiles(FOModPlugin_t * plugin, xmlNodePtr nodeElement) {
|
||||
static int parseGroupFiles(FOModPlugin_t * plugin, xmlNodePtr nodeElement) {
|
||||
FOModFile_t * files = NULL;
|
||||
xmlNodePtr fileNode = nodeElement->children;
|
||||
while(fileNode != NULL) {
|
||||
@@ -123,7 +123,7 @@ int parseGroupFiles(FOModPlugin_t * plugin, xmlNodePtr nodeElement) {
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int parseNodeElement(FOModPlugin_t * plugin, xmlNodePtr nodeElement) {
|
||||
static int parseNodeElement(FOModPlugin_t * plugin, xmlNodePtr nodeElement) {
|
||||
if(xmlStrcmp(nodeElement->name, (const xmlChar *) "description") == 0) {
|
||||
plugin->description = freeAndDup(xmlNodeGetContent(nodeElement));
|
||||
} else if(xmlStrcmp(nodeElement->name, (const xmlChar *) "image") == 0) {
|
||||
|
||||
+6
-6
@@ -51,7 +51,7 @@ void freeFOMod(FOMod_t * fomod) {
|
||||
memset(fomod, 0, sizeof(FOMod_t));
|
||||
}
|
||||
|
||||
int parseVisibleNode(xmlNodePtr node, FOModStep_t * step) {
|
||||
static int parseVisibleNode(xmlNodePtr node, FOModStep_t * step) {
|
||||
xmlNodePtr requiredFlagsNode = node->children;
|
||||
|
||||
while (requiredFlagsNode != NULL) {
|
||||
@@ -76,7 +76,7 @@ int parseVisibleNode(xmlNodePtr node, FOModStep_t * step) {
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int parseOptionalFileGroup(xmlNodePtr node, FOModStep_t * step) {
|
||||
static int parseOptionalFileGroup(xmlNodePtr node, FOModStep_t * step) {
|
||||
xmlChar * optionOrder = xmlGetProp(node, (const xmlChar *)"order");
|
||||
step->optionOrder = getFOModOrder((char *)optionOrder);
|
||||
xmlFree(optionOrder);
|
||||
@@ -105,7 +105,7 @@ int parseOptionalFileGroup(xmlNodePtr node, FOModStep_t * step) {
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
FOModStep_t * parseInstallSteps(xmlNodePtr installStepsNode, int * stepCount) {
|
||||
static FOModStep_t * parseInstallSteps(xmlNodePtr installStepsNode, int * stepCount) {
|
||||
FOModStep_t * steps = NULL;
|
||||
*stepCount = 0;
|
||||
|
||||
@@ -146,7 +146,7 @@ FOModStep_t * parseInstallSteps(xmlNodePtr installStepsNode, int * stepCount) {
|
||||
return steps;
|
||||
}
|
||||
|
||||
int parseDependencies(xmlNodePtr node, FOModCondFile_t * condFile) {
|
||||
static int parseDependencies(xmlNodePtr node, FOModCondFile_t * condFile) {
|
||||
xmlNodePtr flagNode = node->children;
|
||||
|
||||
if(!validateNode(&flagNode, true, "flagDependency", NULL)) {
|
||||
@@ -167,7 +167,7 @@ int parseDependencies(xmlNodePtr node, FOModCondFile_t * condFile) {
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int parseFiles(xmlNodePtr node, FOModCondFile_t * condFile) {
|
||||
static int parseFiles(xmlNodePtr node, FOModCondFile_t * condFile) {
|
||||
xmlNodePtr filesNode = node->children;
|
||||
|
||||
|
||||
@@ -192,7 +192,7 @@ int parseFiles(xmlNodePtr node, FOModCondFile_t * condFile) {
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int parseConditionalInstalls(xmlNodePtr node, FOMod_t * fomod) {
|
||||
static int parseConditionalInstalls(xmlNodePtr node, FOMod_t * fomod) {
|
||||
xmlNodePtr patterns = node->children;
|
||||
if(patterns != NULL) {
|
||||
if(!validateNode(&patterns, true, "patterns", NULL)) {
|
||||
|
||||
+6
-7
@@ -9,7 +9,7 @@
|
||||
#include "main.h"
|
||||
#include "file.h"
|
||||
|
||||
int unzip(char * path, char * outdir) {
|
||||
static int unzip(char * path, char * outdir) {
|
||||
char * const args[] = {
|
||||
"unzip",
|
||||
"-LL", // to lowercase
|
||||
@@ -37,7 +37,7 @@ int unzip(char * path, char * outdir) {
|
||||
}
|
||||
}
|
||||
|
||||
int unrar(char * path, char * outdir) {
|
||||
static int unrar(char * path, char * outdir) {
|
||||
char * const args[] = {
|
||||
"unrar",
|
||||
"x",
|
||||
@@ -66,7 +66,7 @@ int unrar(char * path, char * outdir) {
|
||||
}
|
||||
|
||||
|
||||
int un7z(char * path, const char * outdir) {
|
||||
static int un7z(char * path, const char * outdir) {
|
||||
gchar * outParameter = g_strjoin("", "-o", outdir, NULL);
|
||||
|
||||
char * const args[] = {
|
||||
@@ -98,7 +98,7 @@ int un7z(char * path, const char * outdir) {
|
||||
}
|
||||
}
|
||||
|
||||
const char * extractLastPart(const char * filePath, const char delimeter) {
|
||||
static const char * extractLastPart(const char * filePath, const char delimeter) {
|
||||
const unsigned long length = strlen(filePath);
|
||||
long index = -1;
|
||||
for(long i= length - 1; i >= 0; i--) {
|
||||
@@ -112,15 +112,14 @@ const char * extractLastPart(const char * filePath, const char delimeter) {
|
||||
return &filePath[index];
|
||||
}
|
||||
|
||||
const char * extractExtension(const char * filePath) {
|
||||
static const char * extractExtension(const char * filePath) {
|
||||
return extractLastPart(filePath, '.');
|
||||
}
|
||||
|
||||
const char * extractFileName(const char * filePath) {
|
||||
static const char * extractFileName(const char * filePath) {
|
||||
return extractLastPart(filePath, '/');
|
||||
}
|
||||
|
||||
|
||||
int addMod(char * filePath, int appId) {
|
||||
int returnValue = EXIT_SUCCESS;
|
||||
|
||||
|
||||
+16
-16
@@ -20,11 +20,11 @@
|
||||
|
||||
GHashTable * gamePaths;
|
||||
|
||||
bool isRoot() {
|
||||
static bool isRoot() {
|
||||
return getuid() == 0;
|
||||
}
|
||||
|
||||
GList * listFilesInFolder(const char * path) {
|
||||
static GList * listFilesInFolder(const char * path) {
|
||||
GList * list = NULL;
|
||||
DIR *d;
|
||||
struct dirent *dir;
|
||||
@@ -42,17 +42,17 @@ GList * listFilesInFolder(const char * path) {
|
||||
return list;
|
||||
}
|
||||
|
||||
int noRoot() {
|
||||
static int noRoot() {
|
||||
printf("Don't run this argument as root\n");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
int needRoot() {
|
||||
static int needRoot() {
|
||||
printf("Root is needed to bind with the game files\n");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
int usage() {
|
||||
static int usage() {
|
||||
printf("Use --list-games or -l to list compatible games\n");
|
||||
printf("Use --add or -a <APPID> <FILENAME> to add a mod to a game\n");
|
||||
printf("Use --list-mods or -m <APPID> to list all mods for a game\n");
|
||||
@@ -66,7 +66,7 @@ int usage() {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
int validateAppId(const char * appIdStr) {
|
||||
static int validateAppId(const char * appIdStr) {
|
||||
char * strtoulSentinel;
|
||||
//strtoul set EINVAL(after C99) if the string is invalid
|
||||
unsigned long appid = strtoul(appIdStr, &strtoulSentinel, 10);
|
||||
@@ -90,7 +90,7 @@ int validateAppId(const char * appIdStr) {
|
||||
return (int)appid;
|
||||
}
|
||||
|
||||
int listGames(int argc, char **) {
|
||||
static int listGames(int argc, char **) {
|
||||
if(argc != 2) return usage();
|
||||
GList * gamesIds = g_hash_table_get_keys(gamePaths);
|
||||
GList * gamesIdsFirstPointer = gamesIds;
|
||||
@@ -107,7 +107,7 @@ int listGames(int argc, char **) {
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int add(int argc, char ** argv) {
|
||||
static int add(int argc, char ** argv) {
|
||||
if(argc != 4) return usage();
|
||||
const char * appIdStr = argv[2];
|
||||
|
||||
@@ -120,7 +120,7 @@ int add(int argc, char ** argv) {
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int listAllMods(int argc, char ** argv) {
|
||||
static int listAllMods(int argc, char ** argv) {
|
||||
if(argc != 3) return usage();
|
||||
char * appIdStr = argv[2];
|
||||
int appid = validateAppId(appIdStr);
|
||||
@@ -163,7 +163,7 @@ int listAllMods(int argc, char ** argv) {
|
||||
* this will just flag the mod as needed to be deployed
|
||||
* it's the deploying process that handle the rest
|
||||
*/
|
||||
int installAndUninstallMod(int argc, char ** argv, bool install) {
|
||||
static int installAndUninstallMod(int argc, char ** argv, bool install) {
|
||||
if(argc != 4) return usage();
|
||||
char * appIdStr = argv[2];
|
||||
int appid = validateAppId(appIdStr);
|
||||
@@ -238,7 +238,7 @@ exit:
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
int deploy(int argc, char ** argv) {
|
||||
static int deploy(int argc, char ** argv) {
|
||||
if(argc != 3) return usage();
|
||||
|
||||
char * appIdStr = argv[2];
|
||||
@@ -331,7 +331,7 @@ int deploy(int argc, char ** argv) {
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int setup(int argc, char ** argv) {
|
||||
static int setup(int argc, char ** argv) {
|
||||
if(argc != 3 ) return usage();
|
||||
const char * appIdStr = argv[2];
|
||||
int appid = validateAppId(appIdStr);
|
||||
@@ -381,7 +381,7 @@ int setup(int argc, char ** argv) {
|
||||
}
|
||||
|
||||
|
||||
int unbind(int argc, char ** argv) {
|
||||
static int unbind(int argc, char ** argv) {
|
||||
if(argc != 3 ) return usage();
|
||||
const char * appIdStr = argv[2];
|
||||
int appid = validateAppId(appIdStr);
|
||||
@@ -398,7 +398,7 @@ int unbind(int argc, char ** argv) {
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int removeMod(int argc, char ** argv) {
|
||||
static int removeMod(int argc, char ** argv) {
|
||||
if(argc != 4) return usage();
|
||||
const char * appIdStr = argv[2];
|
||||
int appid = validateAppId(appIdStr);
|
||||
@@ -440,7 +440,7 @@ int removeMod(int argc, char ** argv) {
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int fomod(int argc, char ** argv) {
|
||||
static int fomod(int argc, char ** argv) {
|
||||
if(argc != 4) return usage();
|
||||
char * appIdStr = argv[2];
|
||||
int appid = validateAppId(appIdStr);
|
||||
@@ -491,7 +491,7 @@ int fomod(int argc, char ** argv) {
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
int swapMod(int argc, char ** argv) {
|
||||
static int swapMod(int argc, char ** argv) {
|
||||
if(argc != 5) return usage();
|
||||
char * appIdStr = argv[2];
|
||||
int appid = validateAppId(appIdStr);
|
||||
|
||||
+1
-1
@@ -12,7 +12,7 @@ typedef struct Mod {
|
||||
char * name;
|
||||
} Mod_t;
|
||||
|
||||
gint compareOrder(const void * a, const void * b) {
|
||||
static gint compareOrder(const void * a, const void * b) {
|
||||
const Mod_t * ModA = a;
|
||||
const Mod_t * ModB = b;
|
||||
|
||||
|
||||
+3
-3
@@ -12,7 +12,7 @@
|
||||
|
||||
enum FieldIds { FIELD_PATH, FIELD_LABEL, FIELD_CONTENT_ID, FIELD_TOTAL_SIZE, FIELD_CLEAN_BYTES, FIELD_CORRUPTION, FIELD_APPS };
|
||||
|
||||
int getFiledId(const char * field) {
|
||||
static int getFiledId(const char * field) {
|
||||
//replace with a hash + switch
|
||||
if(strcmp(field, "path") == 0) {
|
||||
return FIELD_PATH;
|
||||
@@ -34,7 +34,7 @@ int getFiledId(const char * field) {
|
||||
}
|
||||
}
|
||||
|
||||
ValveLibraries_t * parseVDF(const char * path, size_t * size, int * status) {
|
||||
static ValveLibraries_t * parseVDF(const char * path, size_t * size, int * status) {
|
||||
FILE * fd = fopen(path, "r");
|
||||
char * line = NULL;
|
||||
size_t len = 0;
|
||||
@@ -166,7 +166,7 @@ exit:
|
||||
return libraries;
|
||||
}
|
||||
|
||||
void freeLibraries(ValveLibraries_t * libraries, int size) {
|
||||
static void freeLibraries(ValveLibraries_t * libraries, int size) {
|
||||
for(int i = 0; i < size; i++) {
|
||||
free(libraries[i].path);
|
||||
free(libraries[i].label);
|
||||
|
||||
Reference in New Issue
Block a user