diff --git a/Makefile b/Makefile index e75bda6..3bad87b 100644 --- a/Makefile +++ b/Makefile @@ -1,16 +1,19 @@ SOURCE := main.c opts.c directive.c file_utils.c error.c dictate.c remove_all.c SOURCE := $(addprefix source/, ${SOURCE}) -CFLAGS += -Wno-unused-label - ifeq (${DEBUG}, 1) + CPPFLAGS += -DDEBUG CFLAGS += -O0 -ggdb -Wall -Wpedantic CFLAGS += -fsanitize=address - CPPFLAGS += -DDEBUG + ifeq (${CC}, clang) + CFLAGS += -Weverything -Wno-switch-default -std=c23 -Wno-pre-c23-compat + endif else CFLAGS += -O3 -flto=auto -fomit-frame-pointer endif +CFLAGS += -Wno-unused-label + OUT := vimdir ${OUT}: ${SOURCE} diff --git a/source/directive.c b/source/directive.c index dfb4f81..599ec49 100644 --- a/source/directive.c +++ b/source/directive.c @@ -33,7 +33,7 @@ int path_cmp(const char * a, const char * b) { if (*b == '/' && *a != '\0') { return 1; } end: - return *(unsigned char *)a - *(unsigned char *)b; + return *(const unsigned char *)a - *(const unsigned char *)b; } static @@ -136,11 +136,11 @@ int init_directive_c(const char * const folder) { } int deinit_directive_c(void) { - for (int i = 0; i < entries.n; i++) { + for (size_t i = 0; i < entries.n; i++) { free(kv_A(entries, i).name); } - for (int i = 0; i < move_data.n; i++) { + for (size_t i = 0; i < move_data.n; i++) { move_data_t move = kv_A(move_data, i); free(move.orig_name); free(move.curt_name); @@ -156,10 +156,10 @@ int deinit_directive_c(void) { } int make_directive_file(FILE * f) { - for (int i = 0; i < entries.n; i++) { + for (size_t i = 0; i < entries.n; i++) { entry_t * entry = &kv_A(entries, i); // ID - fprintf(f, "%03d", + fprintf(f, "%03ld", i ); // Permissions @@ -354,7 +354,7 @@ int execute_directive_file(FILE * f) { } // Deletion - for (int i = 0; i < entries.n; i++) { + for (size_t i = 0; i < entries.n; i++) { entry_t * entry = &kv_A(entries, i); if (!entry->is_mentioned) { CHECK(mydelete(entry->name)); @@ -362,7 +362,7 @@ int execute_directive_file(FILE * f) { } // Swap (move) - for (int i = 0; i < move_data.n; i++) { + for (size_t i = 0; i < move_data.n; i++) { move_data_t move = kv_A(move_data, i); // NOTE: we could be overwritting here; // thats the behaviour the user would expect @@ -386,7 +386,7 @@ int execute_directive_file(FILE * f) { * Therefor, files waiting to be swapped (possessing a temporary name) are restored back * (if possible, if we run into another error, theres not much to do). */ - for (int i = 0; i < move_data.n; i++) { + for (size_t i = 0; i < move_data.n; i++) { move_data_t move = kv_A(move_data, i); if (!access(move.orig_name, F_OK)) { mymove(move.curt_name, move.orig_name); diff --git a/source/error.h b/source/error.h index d66c879..b032e99 100644 --- a/source/error.h +++ b/source/error.h @@ -21,10 +21,11 @@ enum { extern void errorn(int n, ...); extern void notice(const char * fmt, ...); -#define CHECK_OPEN(f, n, E) \ - if (!f) { \ - errorn(E_FILE_ACCESS, n); \ - E; \ - } +#define CHECK_OPEN(f, n, E) do { \ + if (!f) { \ + errorn(E_FILE_ACCESS, n); \ + E; \ + } \ + } while (0) #endif diff --git a/source/file_utils.c b/source/file_utils.c index f1f2d82..c472f2c 100644 --- a/source/file_utils.c +++ b/source/file_utils.c @@ -4,6 +4,7 @@ #include #include #include +#include #include #include #include @@ -70,7 +71,7 @@ int init_file_utils(bool is_dry_run, const char * custom_rm_) { return 0; } -int deinit_file_utis() { +int deinit_file_utis(void) { mytouch = NULL; mydelete = NULL; mychmod = NULL; diff --git a/source/file_utils.h b/source/file_utils.h index d77f142..f183b0e 100644 --- a/source/file_utils.h +++ b/source/file_utils.h @@ -3,9 +3,10 @@ #include #include +#include extern int init_file_utils(bool is_dry_run, const char * custom_rm_); -extern int deinit_file_utis(); +extern int deinit_file_utis(void); extern char * trim_trailing_slashes(char * path); diff --git a/source/main.c b/source/main.c index 54b713b..1672a41 100644 --- a/source/main.c +++ b/source/main.c @@ -4,6 +4,7 @@ #include #include #include +#include "global.h" #include "error.h" #include "opts.h" #include "directive.h" @@ -17,6 +18,7 @@ bool is_recursive = false; bool do_permissions = false; bool do_owner = false; +static int get_tmpfile_name(char * name_buffer) { #if DEBUG == 1 strcpy(name_buffer, "vimdir_test_file.vimdir"); @@ -32,6 +34,7 @@ int get_tmpfile_name(char * name_buffer) { #endif } +static int edit(const char * filename) { size_t cmd_len = strlen(editor) + sizeof(' ') + strlen(filename) + 1; char cmd[cmd_len]; @@ -67,7 +70,7 @@ signed main(int argc, char * * argv) { folder = trim_trailing_slashes(folder); create: - FILE * tmpfile; + FILE * tmpfile = NULL; char tmpfile_name[32]; CHECK(get_tmpfile_name(tmpfile_name));