Skip to content

Commit d107ea5

Browse files
authored
Merge pull request #9 from ccassise/small-cleanup
Small cleanup
2 parents f2fb6af + 3cd234d commit d107ea5

12 files changed

Lines changed: 49 additions & 112 deletions

File tree

CMakeLists.txt

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,47 @@ set(
77

88
project(
99
wowpkg
10-
VERSION 0.3.0
10+
VERSION 0.3.1
1111
DESCRIPTION "A CLI World of Warcraft addon manager"
1212
LANGUAGES C
1313
)
1414

15-
set(CMAKE_C_STANDARD 11)
15+
set(WOWPKG_C_STANDARD 11)
1616

1717
option(WOWPKG_ENABLE_SANITIZERS "Build with or without sanitizers" OFF)
1818
option(WOWPKG_ENABLE_TESTS "Build tests" OFF)
1919
option(WOWPKG_USE_DEVELOPMENT_PATHS "Determines what paths will be used to find some files" OFF)
2020

21+
# Compiler flags that enable warnings.
22+
set(WFLAGS)
23+
24+
# Mainly used for Windows. Adds extra optimization flags when building for
25+
# release builds. These flags get added to WFLAGS.
26+
set(WFLAGS_RELEASE)
27+
28+
# Linker flags.
29+
set(LDFLAGS)
30+
31+
# Mainly used for Windows. Adds extra optimization linker flags for release
32+
# builds. These flags get added to LDFLAGS.
33+
set(LDFLAGS_RELEASE)
34+
35+
# Sanitizer flags.
36+
set(SANSFLAGS)
37+
38+
# Path to catalog directory in project.
39+
set(WOWPKG_CATALOG_PATH)
40+
41+
# Includes all compile time defines.
42+
set(WOWPKG_DEFINES)
43+
44+
# List of libraries that will be linked to targets.
45+
set(WOWPKG_LIBS)
46+
47+
# Path to user files for project. This location is where the program will search
48+
# for user config files and is where it will save user specific data.
49+
set(WOWPKG_USER_FILE_DIR)
50+
2151
if (WOWPKG_ENABLE_TESTS AND NOT WOWPKG_USE_DEVELOPMENT_PATHS)
2252
message(WARNING "[${PROJECT_NAME}] enabling tests without using development paths may cause tests to fail")
2353
endif()
@@ -41,7 +71,7 @@ if (MSVC)
4171
set(LDFLAGS_RELEASE /DEBUG /INCREMENTAL:NO /OPT:REF /OPT:ICF)
4272
set(LDFLAGS "$<$<CONFIG:Release>:${LDFLAGS_RELEASE}>")
4373

44-
# Alot of the functions suggested by this are not available on other
74+
# A lot of the functions suggested by this are not available on other
4575
# systems -- so just ignore the warnings.
4676
set(WOWPKG_DEFINES _CRT_SECURE_NO_WARNINGS)
4777
else()
@@ -84,9 +114,9 @@ if (WOWPKG_ENABLE_SANITIZERS)
84114

85115
-fsanitize=address
86116
-fsanitize=undefined
87-
-fno-sanitize-recover=all
88117
-fsanitize=float-divide-by-zero
89118
-fsanitize=float-cast-overflow
119+
-fno-sanitize-recover=all
90120
-fno-sanitize=null
91121
-fno-sanitize=alignment
92122
)
@@ -156,7 +186,6 @@ if (WIN32)
156186
install(FILES ${PROJECT_SOURCE_DIR}/build/src/Release/cjson.dll DESTINATION bin)
157187
install(FILES ${PROJECT_SOURCE_DIR}/build/src/Release/libcurl.dll DESTINATION bin)
158188
install(FILES ${PROJECT_SOURCE_DIR}/build/src/Release/zlib1.dll DESTINATION bin)
159-
install(FILES ${PROJECT_SOURCE_DIR}/build/src/Release/wowpkg.pdb DESTINATION bin)
160189
endif()
161190

162191
set(CPACK_VERBATIM_VARIABLES true)

src/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ target_link_libraries(wowpkg PRIVATE ${WOWPKG_LIBS})
55
target_compile_options(wowpkg PRIVATE ${WFLAGS})
66
target_link_options(wowpkg PRIVATE ${LDFLAGS})
77
target_compile_definitions(wowpkg PRIVATE ${WOWPKG_DEFINES})
8+
set_target_properties(wowpkg PROPERTIES C_STANDARD ${WOWPKG_C_STANDARD})

src/addon.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,6 @@ static int move_filename(const char *restrict srcdir, const char *restrict destd
118118
return ADDON_ENAMETOOLONG;
119119
}
120120

121-
// TODO: If this fails should check if errno is EXDEV and if so it should
122-
// copy the directory and then delete.
123121
if (os_rename(src, dest) != 0) {
124122
return ADDON_EINTERNAL;
125123
}

src/command.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -110,14 +110,14 @@ int cmd_help(Context *ctx, int argc, const char *argv[], FILE *stream)
110110
UNUSED(argv);
111111

112112
fprintf(stream, "Example usage:\n");
113-
fprintf(stream, "\twowpkg info ADDON...\n");
114-
fprintf(stream, "\twowpkg install ADDON...\n");
115-
fprintf(stream, "\twowpkg list\n");
116-
fprintf(stream, "\twowpkg outdated\n");
117-
fprintf(stream, "\twowpkg remove ADDON...\n");
118-
fprintf(stream, "\twowpkg search TEXT\n");
119-
fprintf(stream, "\twowpkg update [ADDON...]\n");
120-
fprintf(stream, "\twowpkg upgrade [ADDON...]\n");
113+
fprintf(stream, "\t" WOWPKG_NAME " info ADDON...\n");
114+
fprintf(stream, "\t" WOWPKG_NAME " install ADDON...\n");
115+
fprintf(stream, "\t" WOWPKG_NAME " list\n");
116+
fprintf(stream, "\t" WOWPKG_NAME " outdated\n");
117+
fprintf(stream, "\t" WOWPKG_NAME " remove ADDON...\n");
118+
fprintf(stream, "\t" WOWPKG_NAME " search TEXT\n");
119+
fprintf(stream, "\t" WOWPKG_NAME " update [ADDON...]\n");
120+
fprintf(stream, "\t" WOWPKG_NAME " upgrade [ADDON...]\n");
121121

122122
return 0;
123123
}

src/config.c

Lines changed: 0 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
1-
#include <stdio.h>
21
#include <stdlib.h>
32

4-
#include <cjson/cJSON.h>
5-
63
#include "config.h"
74
#include "ini.h"
8-
#include "osapi.h"
95
#include "osstring.h"
106

117
Config *config_create(void)
@@ -28,56 +24,6 @@ void config_free(Config *cfg)
2824
free(cfg);
2925
}
3026

31-
int config_from_json(Config *cfg, const char *json_str)
32-
{
33-
int err = 0;
34-
35-
cJSON *json = cJSON_Parse(json_str);
36-
if (json == NULL) {
37-
err = -1;
38-
goto cleanup;
39-
}
40-
41-
cJSON *addons_path = cJSON_GetObjectItemCaseSensitive(json, "addons_path");
42-
if (addons_path == NULL || !cJSON_IsString(addons_path)) {
43-
err = -1;
44-
goto cleanup;
45-
}
46-
47-
cfg->addons_path = strdup(addons_path->valuestring);
48-
49-
cleanup:
50-
cJSON_Delete(json);
51-
52-
return err;
53-
}
54-
55-
char *config_to_json(Config *cfg)
56-
{
57-
int err = 0;
58-
char *result = NULL;
59-
60-
cJSON *json = cJSON_CreateObject();
61-
if (json == NULL) {
62-
err = -1;
63-
goto cleanup;
64-
}
65-
66-
if (cJSON_AddStringToObject(json, "addons_path", cfg->addons_path) == NULL) {
67-
err = -1;
68-
goto cleanup;
69-
}
70-
71-
cleanup:
72-
if (err == 0) {
73-
result = cJSON_PrintUnformatted(json);
74-
}
75-
76-
cJSON_Delete(json);
77-
78-
return result;
79-
}
80-
8127
int config_load(Config *cfg, const char *path)
8228
{
8329
INI *ini = ini_open(path);

src/config.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,4 @@ Config *config_create(void);
1414
*/
1515
void config_free(Config *cfg);
1616

17-
int config_from_json(Config *cfg, const char *json);
18-
char *config_to_json(Config *cfg);
19-
2017
int config_load(Config *cfg, const char *path);

src/list.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@ void list_remove(List *l, ListNode *node)
9595

9696
void list_sort(List *l, ListCompareFn cmp)
9797
{
98+
// Based on Simon Tatham's Mergesort For Linked List.
99+
// https://www.chiark.greenend.org.uk/~sgtatham/algorithms/listsort.html
98100
size_t insize = 1;
99101

100102
while (1) {

src/osapi.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,7 @@ char *os_mkdtemp(char *template);
128128

129129
/**
130130
* Attempts to get the temp directory for the current OS. If no value was found
131-
* then it returns the current working directory ".". This functions promises
132-
* that, at least at the time of the call, the directory exists.
131+
* then it returns the current working directory ".".
133132
*
134133
* WARNING: The returned string may be statically allocated and as such shall
135134
* not be modified. Future calls of this function may change the contents of

src/zipper.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
#include <stdbool.h>
21
#include <stdio.h>
3-
#include <sys/stat.h>
2+
3+
#include <minizip/unzip.h>
44

55
#include "osapi.h"
66
#include "osstring.h"

src/zipper.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
#pragma once
22

3-
#include <minizip/unzip.h>
4-
53
enum {
64
ZIPPER_OK = 0,
75

0 commit comments

Comments
 (0)