From cb488b8f0c9534536d468dbefc2aaeb53a78bcf9 Mon Sep 17 00:00:00 2001 From: LuytenKy Date: Sat, 11 Apr 2026 11:27:03 +0300 Subject: [PATCH 01/13] Incorporate new files, and pre-code for handling boilerplate --- include/boilerplate_subsystem.h | 23 +++++++++++++++++++++++ include/def_type.h | 3 +++ include/table_boilerplates.h | 1 + src/boilerplate_subsystem.c | 0 src/file_subsystem.c | 1 - src/main.c | 1 - 6 files changed, 27 insertions(+), 2 deletions(-) create mode 100644 include/boilerplate_subsystem.h create mode 100644 include/table_boilerplates.h create mode 100644 src/boilerplate_subsystem.c diff --git a/include/boilerplate_subsystem.h b/include/boilerplate_subsystem.h new file mode 100644 index 0000000..1fd12ad --- /dev/null +++ b/include/boilerplate_subsystem.h @@ -0,0 +1,23 @@ +#pragma once + +#include +#include +#include +#include +#include +#include +#include + +#ifdef _WIN32 +#include +#define check_writable(p) (_access((p), 2) == 0) +#include +#else +#include +#define check_writable(p) (access((p), W_OK) == 0) +#endif + +#include "def_type.h" +#include "color.h" +#include "text_type.h" +#include "file_subsystem.h" \ No newline at end of file diff --git a/include/def_type.h b/include/def_type.h index 700dab6..7515d8b 100644 --- a/include/def_type.h +++ b/include/def_type.h @@ -19,6 +19,9 @@ typedef struct OP int dirs_created; int tables_created; int errors; + + /* For Boilerplates */ + int gen_boilerplate; } OP; /* ======================= diff --git a/include/table_boilerplates.h b/include/table_boilerplates.h new file mode 100644 index 0000000..7b9637e --- /dev/null +++ b/include/table_boilerplates.h @@ -0,0 +1 @@ +#pragma once \ No newline at end of file diff --git a/src/boilerplate_subsystem.c b/src/boilerplate_subsystem.c new file mode 100644 index 0000000..e69de29 diff --git a/src/file_subsystem.c b/src/file_subsystem.c index 89fde7c..b8b0e39 100644 --- a/src/file_subsystem.c +++ b/src/file_subsystem.c @@ -1,4 +1,3 @@ -/* file_subsystem.c */ #include #include #include diff --git a/src/main.c b/src/main.c index 2341152..2b5ec0c 100644 --- a/src/main.c +++ b/src/main.c @@ -1,4 +1,3 @@ -/* main.c */ #include #include #include From db62129ab233b34839944629da8305b3a726105f Mon Sep 17 00:00:00 2001 From: LuytenKy Date: Sat, 11 Apr 2026 11:46:18 +0300 Subject: [PATCH 02/13] update pull-request.yml --- .github/workflows/pull-request.yml | 46 +++++++++++------------------- 1 file changed, 16 insertions(+), 30 deletions(-) diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index 508fc72..89c2b2a 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -2,42 +2,28 @@ name: Build Check on: pull_request: permissions: - contents: write + contents: read jobs: build: strategy: matrix: platform: [ - {name: "Linux Debug", os: "ubuntu-22.04", ext: "tar.gz", config: "Debug"}, - {name: "Linux Release", os: "ubuntu-24.04", ext: "tar.gz", config: "Release"}, - {name: "Windows Debug", os: "windows-2022", ext: "zip", config: "Debug"}, - {name: "Windows Release", os: "windows-2022", ext: "zip", config: "Release"}, - {name: "macOS Debug", os: "macos-15", ext: "tar.gz", config: "Debug"}, - {name: "macOS Release", os: "macos-15", ext: "tar.gz", config: "Release"} + {name: "Linux Debug", os: "ubuntu-22.04", config: "Debug"}, + {name: "Linux Release", os: "ubuntu-24.04", config: "Release"}, + {name: "Windows Debug", os: "windows-2022", config: "Debug"}, + {name: "Windows Release", os: "windows-2022", config: "Release"}, + {name: "macOS Debug", os: "macos-15", config: "Debug"}, + {name: "macOS Release", os: "macos-15", config: "Release"} ] runs-on: ${{ matrix.platform.os }} name: ${{ matrix.platform.name }} steps: - - uses: actions/checkout@v4 - - name: Install macOS deps - if: runner.os == 'macOS' - run: brew install llvm - - name: Configure - run: cmake -B build -DCMAKE_BUILD_TYPE=${{ matrix.platform.config }} - - name: Build - working-directory: ./build - run: cmake --build . --config ${{ matrix.platform.config }} - - name: Package - shell: bash - run: | - mkdir -p build/install - cmake --install build --config ${{ matrix.platform.config }} --prefix build/install - cd build/install - if [ "${{ matrix.platform.ext }}" = "zip" ]; then - 7z a ../../fsminit-${{ matrix.platform.config }}-${{ matrix.platform.os }}.${{ matrix.platform.ext }} * - else - tar -czf ../../fsminit-${{ matrix.platform.config }}-${{ matrix.platform.os }}.${{ matrix.platform.ext }} . - fi - - uses: softprops/action-gh-release@v2 - with: - files: fsminit-${{ matrix.platform.config }}-${{ matrix.platform.os }}.* + - uses: actions/checkout@v4 + - name: Install macOS deps + if: runner.os == 'macOS' + run: brew install llvm + - name: Configure + run: cmake -B build -DCMAKE_BUILD_TYPE=${{ matrix.platform.config }} + - name: Build + working-directory: ./build + run: cmake --build . --config ${{ matrix.platform.config }} \ No newline at end of file From 50412cbe53146f4df3ace24516a5a558f6bd49f2 Mon Sep 17 00:00:00 2001 From: LuytenKy Date: Sat, 11 Apr 2026 12:29:52 +0300 Subject: [PATCH 03/13] Implement first function of the bunch --- include/boilerplate_subsystem.h | 24 +--------- include/def_type.h | 19 ++++++-- include/file_subsystem.h | 3 +- src/boilerplate_subsystem.c | 84 +++++++++++++++++++++++++++++++++ src/file_subsystem.c | 2 +- 5 files changed, 104 insertions(+), 28 deletions(-) diff --git a/include/boilerplate_subsystem.h b/include/boilerplate_subsystem.h index 1fd12ad..7b9637e 100644 --- a/include/boilerplate_subsystem.h +++ b/include/boilerplate_subsystem.h @@ -1,23 +1 @@ -#pragma once - -#include -#include -#include -#include -#include -#include -#include - -#ifdef _WIN32 -#include -#define check_writable(p) (_access((p), 2) == 0) -#include -#else -#include -#define check_writable(p) (access((p), W_OK) == 0) -#endif - -#include "def_type.h" -#include "color.h" -#include "text_type.h" -#include "file_subsystem.h" \ No newline at end of file +#pragma once \ No newline at end of file diff --git a/include/def_type.h b/include/def_type.h index 7515d8b..1fdbdc3 100644 --- a/include/def_type.h +++ b/include/def_type.h @@ -110,9 +110,22 @@ typedef struct FS_TABLES const char *name; } FS_TABLES; -/* ======================= - External Declarations - ======================= */ +typedef struct BPL_ENTRY +{ + const char *key; /* "-wep" or "weapons", etc... */ + const char **variants; /* array of boilerplate strings */ + size_t variant_count; +} BPL_ENTRY; + +typedef struct TABLE_FILE_LIST +{ + char **paths; + size_t count; +} TABLE_FILE_LIST; + + /* ======================= + External Declarations + ======================= */ extern const char *voice_subdirs[]; extern const size_t voice_subdirs_count; diff --git a/include/file_subsystem.h b/include/file_subsystem.h index 5032ad0..0bed0f1 100644 --- a/include/file_subsystem.h +++ b/include/file_subsystem.h @@ -6,4 +6,5 @@ void create_directories(OP *operation); void create_tbl_tables(OP *operation); void create_tbm_tables(OP *operation); void create_static_tables(OP *operation); -bool check_if_mod_structure_exists(const char *base_path); \ No newline at end of file +bool check_if_mod_structure_exists(const char *base_path); +bool path_is_dir(const char *path); \ No newline at end of file diff --git a/src/boilerplate_subsystem.c b/src/boilerplate_subsystem.c index e69de29..68a1b0f 100644 --- a/src/boilerplate_subsystem.c +++ b/src/boilerplate_subsystem.c @@ -0,0 +1,84 @@ +#include +#include +#include +#include +#include +#include +#include + +#ifdef _WIN32 +#include +#define check_writable(p) (_access((p), 2) == 0) +#define asprintf(buf, fmt, ...) _asprintf(buf, fmt, __VA_ARGS__) +static int _asprintf(char **ret, const char *format, ...) +{ + va_list ap; + int size; + va_start(ap, format); + size = vsnprintf(NULL, 0, format, ap); + va_end(ap); + if (size < 0) + return -1; + *ret = malloc(size + 1); + if (!*ret) + return -1; + va_start(ap, format); + size = vsnprintf(*ret, size + 1, format, ap); + va_end(ap); + return size; +} +#else +#include +#define check_writable(p) (access((p), W_OK) == 0) +#endif + +#include "def_type.h" +#include "color.h" +#include "text_type.h" +#include "file_subsystem.h" + +/* +check to see if the mod structure has generated successfuly, if so, +!!!(for now discard all of the unneeded data and focus only on the tables/ being present)!!! +*/ +bool verify_mod_structure(const char *base_path) +{ + if(is_dir_path(base_path)) + { + for (size_t i = 0; i < fs_dirs_count; i++) + { + char *dir_path = NULL; + if (asprintf(&dir_path, "%s/%s", base_path, fs_dirs[i].name) == -1) + return false; + + bool exists = path_is_dir(dir_path); + free(dir_path); + if(!exists) + { + return false; + } + } + return true; + } + else + { + return false; + } +} + +TABLE_FILE_LIST *verify_tables_directory(const char *base_path_tables) +{ + /* Verify and collect the tables from the "tables/" directory and return them */ +} + +const BPL_ENTRY *find_boilderplate(const char *filename) +{ + /* strip path and extension, extract key */ + /* linear search through bpl_table[] */ + /* return matching entry or NULL if not found */ +} + +void write_to_tables(const BPL_ENTRY *entry, const char *filepath, OP *operation) +{ + +} \ No newline at end of file diff --git a/src/file_subsystem.c b/src/file_subsystem.c index b8b0e39..9fe23a4 100644 --- a/src/file_subsystem.c +++ b/src/file_subsystem.c @@ -146,7 +146,7 @@ const size_t static_tables_count = 1; File & Directory Creation ===================================== */ -static bool path_is_dir(const char *path) +bool path_is_dir(const char *path) { struct stat st; if (stat(path, &st) != 0) From 83f4ba5ac1badf044a165178713cc136918efa2a Mon Sep 17 00:00:00 2001 From: LuytenKy Date: Sat, 11 Apr 2026 12:50:47 +0300 Subject: [PATCH 04/13] Finalize functions, only one remaining --- include/def_type.h | 4 + src/boilerplate_subsystem.c | 143 ++++++++++++++++++++++++++++++++++-- src/main.c | 4 - 3 files changed, 141 insertions(+), 10 deletions(-) diff --git a/include/def_type.h b/include/def_type.h index 1fdbdc3..2987c2e 100644 --- a/include/def_type.h +++ b/include/def_type.h @@ -3,6 +3,10 @@ #include #include +#ifndef PATH_MAX +#define PATH_MAX 4096 +#endif + /* ======================= CLI Option Structure ======================= */ diff --git a/src/boilerplate_subsystem.c b/src/boilerplate_subsystem.c index 68a1b0f..1e8a8b0 100644 --- a/src/boilerplate_subsystem.c +++ b/src/boilerplate_subsystem.c @@ -5,6 +5,7 @@ #include #include #include +#include #ifdef _WIN32 #include @@ -43,7 +44,7 @@ check to see if the mod structure has generated successfuly, if so, */ bool verify_mod_structure(const char *base_path) { - if(is_dir_path(base_path)) + if (is_dir_path(base_path)) { for (size_t i = 0; i < fs_dirs_count; i++) { @@ -66,16 +67,146 @@ bool verify_mod_structure(const char *base_path) } } -TABLE_FILE_LIST *verify_tables_directory(const char *base_path_tables) +/* Verify and collect the tables from the "tables/" directory and return them */ +TABLE_FILE_LIST *verify_tables_directory(const char *base_path_tables, bool verification_mod_struct) { - /* Verify and collect the tables from the "tables/" directory and return them */ + TABLE_FILE_LIST *tfl = malloc(sizeof(TABLE_FILE_LIST)); + if (!tfl) + return NULL; + + tfl->paths = NULL; + tfl->count = 0; + + if (!verification_mod_struct || !path_is_dir(base_path_tables)) + { + return tfl; // Empty list if not verifying + } + + DIR *dir = opendir(base_path_tables); + if (!dir) + { + perror("opendir"); + free(tfl); + return NULL; + } + + struct dirent *entry; + char full_path[PATH_MAX]; + size_t capacity = 16; // Initial array capacity + + tfl->paths = malloc(capacity * sizeof(char *)); + if (!tfl->paths) + { + closedir(dir); + free(tfl); + return NULL; + } + + while ((entry = readdir(dir)) != NULL) + { + if (strcmp(entry->d_name, ".") == 0 || strcmp(entry->d_name, "..") == 0) + { + continue; + } + + // Optional: Check if regular file (not dir/subdir) using stat + struct stat st; + snprintf(full_path, sizeof(full_path), "%s/%s", base_path_tables, entry->d_name); + if (stat(full_path, &st) == 0 && S_ISREG(st.st_mode)) + { // Only files + if (tfl->count >= capacity) + { + capacity *= 2; + char **new_paths = realloc(tfl->paths, capacity * sizeof(char *)); + if (!new_paths) + { + // Cleanup on realloc fail + for (size_t j = 0; j < tfl->count; j++) + free(tfl->paths[j]); + free(tfl->paths); + closedir(dir); + free(tfl); + return NULL; + } + tfl->paths = new_paths; + } + + tfl->paths[tfl->count] = strdup(full_path); + if (!tfl->paths[tfl->count]) + { + // Cleanup on strdup fail + for (size_t j = 0; j < tfl->count; j++) + free(tfl->paths[j]); + free(tfl->paths); + closedir(dir); + free(tfl); + return NULL; + } + tfl->count++; + } + } + + closedir(dir); + return tfl; +} + +static char *strip_path_ext(const char *filename) +{ + const char *base = strrchr(filename, '/'); + if (!base) + base = filename; + else + base++; + + char *dot = strrchr(base, '.'); + if (!dot) + dot = base + strlen(base); + + size_t len = dot - base; + char *key = malloc(len + 1); + if (key) + { + strncpy(key, base, len); + key[len] = '\0'; + } + return key; } +/* strip path and extension, extract key */ +/* linear search through bpl_table[] */ +/* return matching entry or NULL if not found */ const BPL_ENTRY *find_boilderplate(const char *filename) { - /* strip path and extension, extract key */ - /* linear search through bpl_table[] */ - /* return matching entry or NULL if not found */ + char *key = strip_path_ext(filename); + if (!key) + return NULL; + + // Linear search through fs_tables + for (size_t i = 0; i < fs_tables_count; i++) + { + // Check 1: Exact match with base_name (e.g., "weapons.tbl" -> "weapons") + if (strcmp(key, fs_tables[i].base_name) == 0) + { + free(key); + // Assuming parallel bpl_table alignment + // return &bpl_table[i]; not yet implemented + } + + // Check 2: Ends with modular suffix (e.g., "mymod-wep.tbm" -> ends with "wep") + const char *suffix = fs_tables[i].modular_suffix + 1; // Skip "-", get "wep" + size_t suffix_len = strlen(suffix); + size_t key_len = strlen(key); + + if (key_len >= suffix_len && + strcmp(key + key_len - suffix_len, suffix) == 0) + { + free(key); + // return &bpl_table[i]; not yet implemented + } + } + + free(key); + return NULL; } void write_to_tables(const BPL_ENTRY *entry, const char *filepath, OP *operation) diff --git a/src/main.c b/src/main.c index 2b5ec0c..d209ed0 100644 --- a/src/main.c +++ b/src/main.c @@ -12,10 +12,6 @@ #include #endif -#ifndef PATH_MAX -#define PATH_MAX 4096 -#endif - #include "version.h" #include "def_type.h" #include "file_subsystem.h" From 46a2e27602fcdb1ad2aa35fdfea275bc4c031afd Mon Sep 17 00:00:00 2001 From: LuytenKy Date: Sat, 11 Apr 2026 12:58:08 +0300 Subject: [PATCH 05/13] partial implementation of write_to_tables --- src/boilerplate_subsystem.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/boilerplate_subsystem.c b/src/boilerplate_subsystem.c index 1e8a8b0..87c55c1 100644 --- a/src/boilerplate_subsystem.c +++ b/src/boilerplate_subsystem.c @@ -211,5 +211,25 @@ const BPL_ENTRY *find_boilderplate(const char *filename) void write_to_tables(const BPL_ENTRY *entry, const char *filepath, OP *operation) { + FILE *fp; + if(!check_writable(filepath)) + { + fprintf(stderr, "%s%sError:%s Target path is not writable: %s\n", + TEX_BOLD, COL_RED, COL_RESET, operation->path); + return; + } + fp = fopen(filepath, "a"); + if(!fp) + { + perror("fopen"); + return; + } + + /* + * This is where we will write to tables using their file paths + * since BPL_ENTRY's bpl_table[] has not yet been implemented, this function will remain as is. + */ + + fclose(fp); } \ No newline at end of file From 1918fb05c40f7aa8a5e04332c6ca8e63f1e88cc8 Mon Sep 17 00:00:00 2001 From: LuytenKy Date: Sat, 11 Apr 2026 16:09:27 +0300 Subject: [PATCH 06/13] corrections and first parameters for testing --- include/boilerplate_subsystem.h | 17 ++++++++++++- src/boilerplate_subsystem.c | 42 +++++++++++++-------------------- 2 files changed, 33 insertions(+), 26 deletions(-) diff --git a/include/boilerplate_subsystem.h b/include/boilerplate_subsystem.h index 7b9637e..5709d62 100644 --- a/include/boilerplate_subsystem.h +++ b/include/boilerplate_subsystem.h @@ -1 +1,16 @@ -#pragma once \ No newline at end of file +#pragma once + +#include "def_type.h" + +/* Boilerplate string literals */ +static const char *bpl_wep_primary = + "#Primary Weapons\n" + "$Name: placeholder\n" + "#End\n"; + +/* Boilerplate table — key matches base_name for .tbl or suffix for .tbm */ +static const BPL_ENTRY bpl_table[] = { + {"weapons", (const char *[]){bpl_wep_primary}, 1}, +}; + +static const size_t bpl_table_count = 1; \ No newline at end of file diff --git a/src/boilerplate_subsystem.c b/src/boilerplate_subsystem.c index 87c55c1..5ac691f 100644 --- a/src/boilerplate_subsystem.c +++ b/src/boilerplate_subsystem.c @@ -37,6 +37,7 @@ static int _asprintf(char **ret, const char *format, ...) #include "color.h" #include "text_type.h" #include "file_subsystem.h" +#include "boilerplate_subsystem.h" /* check to see if the mod structure has generated successfuly, if so, @@ -44,7 +45,7 @@ check to see if the mod structure has generated successfuly, if so, */ bool verify_mod_structure(const char *base_path) { - if (is_dir_path(base_path)) + if (path_is_dir(base_path)) { for (size_t i = 0; i < fs_dirs_count; i++) { @@ -68,7 +69,7 @@ bool verify_mod_structure(const char *base_path) } /* Verify and collect the tables from the "tables/" directory and return them */ -TABLE_FILE_LIST *verify_tables_directory(const char *base_path_tables, bool verification_mod_struct) +TABLE_FILE_LIST *verify_tables_directory(const char *base_path_tables) { TABLE_FILE_LIST *tfl = malloc(sizeof(TABLE_FILE_LIST)); if (!tfl) @@ -77,9 +78,10 @@ TABLE_FILE_LIST *verify_tables_directory(const char *base_path_tables, bool veri tfl->paths = NULL; tfl->count = 0; - if (!verification_mod_struct || !path_is_dir(base_path_tables)) + if (!path_is_dir(base_path_tables)) { - return tfl; // Empty list if not verifying + free(tfl); + return NULL; } DIR *dir = opendir(base_path_tables); @@ -92,7 +94,7 @@ TABLE_FILE_LIST *verify_tables_directory(const char *base_path_tables, bool veri struct dirent *entry; char full_path[PATH_MAX]; - size_t capacity = 16; // Initial array capacity + size_t capacity = 16; tfl->paths = malloc(capacity * sizeof(char *)); if (!tfl->paths) @@ -105,22 +107,18 @@ TABLE_FILE_LIST *verify_tables_directory(const char *base_path_tables, bool veri while ((entry = readdir(dir)) != NULL) { if (strcmp(entry->d_name, ".") == 0 || strcmp(entry->d_name, "..") == 0) - { continue; - } - // Optional: Check if regular file (not dir/subdir) using stat struct stat st; snprintf(full_path, sizeof(full_path), "%s/%s", base_path_tables, entry->d_name); if (stat(full_path, &st) == 0 && S_ISREG(st.st_mode)) - { // Only files + { if (tfl->count >= capacity) { capacity *= 2; char **new_paths = realloc(tfl->paths, capacity * sizeof(char *)); if (!new_paths) { - // Cleanup on realloc fail for (size_t j = 0; j < tfl->count; j++) free(tfl->paths[j]); free(tfl->paths); @@ -134,7 +132,6 @@ TABLE_FILE_LIST *verify_tables_directory(const char *base_path_tables, bool veri tfl->paths[tfl->count] = strdup(full_path); if (!tfl->paths[tfl->count]) { - // Cleanup on strdup fail for (size_t j = 0; j < tfl->count; j++) free(tfl->paths[j]); free(tfl->paths); @@ -175,40 +172,35 @@ static char *strip_path_ext(const char *filename) /* strip path and extension, extract key */ /* linear search through bpl_table[] */ /* return matching entry or NULL if not found */ -const BPL_ENTRY *find_boilderplate(const char *filename) +const BPL_ENTRY *find_boilerplate(const char *filename) { char *key = strip_path_ext(filename); if (!key) return NULL; - // Linear search through fs_tables - for (size_t i = 0; i < fs_tables_count; i++) + for (size_t i = 0; i < bpl_table_count; i++) { - // Check 1: Exact match with base_name (e.g., "weapons.tbl" -> "weapons") - if (strcmp(key, fs_tables[i].base_name) == 0) + if (strcmp(key, bpl_table[i].key) == 0) { free(key); - // Assuming parallel bpl_table alignment - // return &bpl_table[i]; not yet implemented + return &bpl_table[i]; } - // Check 2: Ends with modular suffix (e.g., "mymod-wep.tbm" -> ends with "wep") - const char *suffix = fs_tables[i].modular_suffix + 1; // Skip "-", get "wep" - size_t suffix_len = strlen(suffix); + /* Check if key ends with the suffix (for .tbm files) */ + size_t suffix_len = strlen(bpl_table[i].key); size_t key_len = strlen(key); if (key_len >= suffix_len && - strcmp(key + key_len - suffix_len, suffix) == 0) + strcmp(key + key_len - suffix_len, bpl_table[i].key) == 0) { free(key); - // return &bpl_table[i]; not yet implemented + return &bpl_table[i]; } } free(key); return NULL; } - void write_to_tables(const BPL_ENTRY *entry, const char *filepath, OP *operation) { FILE *fp; @@ -219,7 +211,7 @@ void write_to_tables(const BPL_ENTRY *entry, const char *filepath, OP *operation TEX_BOLD, COL_RED, COL_RESET, operation->path); return; } - fp = fopen(filepath, "a"); + fp = fopen(filepath, "w"); if(!fp) { perror("fopen"); From ca0e774add10abad59a1342ca7814406721979ef Mon Sep 17 00:00:00 2001 From: LuytenKy Date: Sat, 11 Apr 2026 16:49:07 +0300 Subject: [PATCH 07/13] the first test worked somehow --- CMakeLists.txt | 2 +- include/boilerplate_subsystem.h | 25 ++++++++---- include/table_boilerplates.h | 1 - src/boilerplate_subsystem.c | 16 +++++--- src/main.c | 71 +++++++++++++++++++++++++++++++-- 5 files changed, 95 insertions(+), 20 deletions(-) delete mode 100644 include/table_boilerplates.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 2614e42..9413218 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,7 +8,7 @@ endif() set(CMAKE_EXPORT_COMPILE_COMMANDS ON) # More reliable source listing (avoids globbing issues) -set(SRCS src/main.c src/file_subsystem.c) +set(SRCS src/main.c src/file_subsystem.c src/boilerplate_subsystem.c ) add_executable(FSMINIT ${SRCS}) target_include_directories(FSMINIT PRIVATE include) diff --git a/include/boilerplate_subsystem.h b/include/boilerplate_subsystem.h index 5709d62..b852447 100644 --- a/include/boilerplate_subsystem.h +++ b/include/boilerplate_subsystem.h @@ -2,15 +2,24 @@ #include "def_type.h" -/* Boilerplate string literals */ -static const char *bpl_wep_primary = - "#Primary Weapons\n" - "$Name: placeholder\n" - "#End\n"; +/* Boilerplate string literals. Use macros so they remain constant expressions. */ +#define BPL_WEP_PRIMARY \ + "#Primary Weapons\n" \ + "$Name: placeholder\n" \ + "#End\n" + +/* Helper array using the macro directly (no variable in the initializer) */ +static const char *bpl_wep_primary_variants[] = { + BPL_WEP_PRIMARY}; /* Boilerplate table — key matches base_name for .tbl or suffix for .tbm */ static const BPL_ENTRY bpl_table[] = { - {"weapons", (const char *[]){bpl_wep_primary}, 1}, -}; + {"weapons", bpl_wep_primary_variants, 1}}; + +static const size_t bpl_table_count = sizeof(bpl_table) / sizeof(bpl_table[0]); -static const size_t bpl_table_count = 1; \ No newline at end of file +/* Public functions */ +bool verify_mod_structure(const char *base_path); +TABLE_FILE_LIST *verify_tables_directory(const char *base_path_tables); +const BPL_ENTRY *find_boilerplate(const char *filename); +void write_to_tables(const BPL_ENTRY *entry, const char *filepath, OP *operation); \ No newline at end of file diff --git a/include/table_boilerplates.h b/include/table_boilerplates.h deleted file mode 100644 index 7b9637e..0000000 --- a/include/table_boilerplates.h +++ /dev/null @@ -1 +0,0 @@ -#pragma once \ No newline at end of file diff --git a/src/boilerplate_subsystem.c b/src/boilerplate_subsystem.c index 5ac691f..1fc33ca 100644 --- a/src/boilerplate_subsystem.c +++ b/src/boilerplate_subsystem.c @@ -155,7 +155,7 @@ static char *strip_path_ext(const char *filename) else base++; - char *dot = strrchr(base, '.'); + const char *dot = strrchr(base, '.'); if (!dot) dot = base + strlen(base); @@ -201,6 +201,7 @@ const BPL_ENTRY *find_boilerplate(const char *filename) free(key); return NULL; } + void write_to_tables(const BPL_ENTRY *entry, const char *filepath, OP *operation) { FILE *fp; @@ -218,10 +219,13 @@ void write_to_tables(const BPL_ENTRY *entry, const char *filepath, OP *operation return; } - /* - * This is where we will write to tables using their file paths - * since BPL_ENTRY's bpl_table[] has not yet been implemented, this function will remain as is. - */ - + if (entry && entry->variants){ + for (size_t i = 0; i < entry->variant_count; i++) + { + if (entry->variants[i]){ + fprintf(fp, "%s\n", entry->variants[i]); + } + } + } fclose(fp); } \ No newline at end of file diff --git a/src/main.c b/src/main.c index d209ed0..d1dcbc9 100644 --- a/src/main.c +++ b/src/main.c @@ -17,6 +17,7 @@ #include "file_subsystem.h" #include "text_type.h" #include "color.h" +#include "boilerplate_subsystem.h" bool g_color_enabled = false; @@ -45,6 +46,7 @@ int main(int argc, char *argv[]) operation.prefix = NULL; operation.debug = 0; operation.dry_run = 0; + operation.gen_boilerplate = 0; if (strcmp(argv[1], "-help") == 0) { @@ -98,7 +100,6 @@ int main(int argc, char *argv[]) return 1; } - int start_index = is_stdm ? 3 : 4; if (is_stdmc && operation.table_type && strcmp(operation.table_type, "-tbm") == 0) { if (argc < 5) @@ -112,15 +113,45 @@ int main(int argc, char *argv[]) return 1; } operation.prefix = argv[4]; - start_index = 5; } - for (int i = start_index; i < argc; ++i) + int arg_idx = is_stdm ? 3 : 4; + for (int i = arg_idx; i < argc; ++i) { - if (strcmp(argv[i], "-debug") == 0) + if (strcmp(argv[i], "-bpl") == 0) + { + operation.gen_boilerplate = 1; + } + else if (!operation.table_type && + (strcmp(argv[i], "-tbl") == 0 || strcmp(argv[i], "-tbm") == 0)) + { + operation.table_type = argv[i]; + } + else if (operation.table_type && strcmp(operation.table_type, "-tbm") == 0 && + !operation.prefix) + { + if (strlen(argv[i]) > 32) + { + fprintf(stderr, "%s%sError:%s Prefix too long (max 32 chars)\n", + TEX_BOLD, COL_RED, COL_RESET); + return 1; + return 1; + } + operation.prefix = argv[i]; + } + else if (strcmp(argv[i], "-debug") == 0) + { operation.debug = 1; + } else if (strcmp(argv[i], "-dry-run") == 0) + { operation.dry_run = 1; + } + else + { + fprintf(stderr, "Unknown argument: %s\n", argv[i]); + return 1; + } } if (operation.debug) @@ -165,6 +196,38 @@ int main(int argc, char *argv[]) } } + if (operation.table_type && operation.gen_boilerplate) + { + printf("%sWriting boilerplate to tables...%s%s\n", TEX_BOLD, COL_MAGENTA, COL_RESET); + + char *tables_path = NULL; + if (asprintf(&tables_path, "%s/tables", operation.path) == -1) + { + operation.errors++; + } + else + { + TABLE_FILE_LIST *tables = verify_tables_directory(tables_path); + if (tables) + { + for (size_t i = 0; i < tables->count; i++) + { + const BPL_ENTRY *entry = find_boilerplate(tables->paths[i]); + if (entry) + { + write_to_tables(entry, tables->paths[i], &operation); + } + } + // Cleanup + for (size_t i = 0; i < tables->count; i++) + free(tables->paths[i]); + free(tables->paths); + free(tables); + } + free(tables_path); + } + } + printf("\n%s%s--- Summary ---%s\n", TEX_BOLD, COL_CYAN, COL_RESET); printf(" %sDirectories:%s %s%d%s\n", TEX_BOLD, COL_RESET, COL_GREEN, operation.dirs_created, COL_RESET); printf(" %sTables:%s %s%d%s\n", TEX_BOLD, COL_RESET, COL_GREEN, operation.tables_created, COL_RESET); From 410b29ccd339bdb2c8089f3f1a31d15e95d6ad6e Mon Sep 17 00:00:00 2001 From: LuytenKy Date: Sat, 11 Apr 2026 17:16:57 +0300 Subject: [PATCH 08/13] massive overhaul and Windows handling --- include/boilerplate_subsystem.h | 9 +- src/boilerplate_subsystem.c | 140 +++++++++++++++++++++++++++----- src/main.c | 35 +++----- 3 files changed, 135 insertions(+), 49 deletions(-) diff --git a/include/boilerplate_subsystem.h b/include/boilerplate_subsystem.h index b852447..359da32 100644 --- a/include/boilerplate_subsystem.h +++ b/include/boilerplate_subsystem.h @@ -8,16 +8,17 @@ "$Name: placeholder\n" \ "#End\n" -/* Helper array using the macro directly (no variable in the initializer) */ +/* Helper array */ static const char *bpl_wep_primary_variants[] = { BPL_WEP_PRIMARY}; -/* Boilerplate table — key matches base_name for .tbl or suffix for .tbm */ +/* Boilerplate table — keys must match base_name for .tbl and modular_suffix for .tbm */ static const BPL_ENTRY bpl_table[] = { - {"weapons", bpl_wep_primary_variants, 1}}; + {"weapons", bpl_wep_primary_variants, 1}, // for weapons.tbl + {"-wep", bpl_wep_primary_variants, 1} // for XXX‑wep.tbm +}; static const size_t bpl_table_count = sizeof(bpl_table) / sizeof(bpl_table[0]); - /* Public functions */ bool verify_mod_structure(const char *base_path); TABLE_FILE_LIST *verify_tables_directory(const char *base_path_tables); diff --git a/src/boilerplate_subsystem.c b/src/boilerplate_subsystem.c index 1fc33ca..fdd1505 100644 --- a/src/boilerplate_subsystem.c +++ b/src/boilerplate_subsystem.c @@ -5,11 +5,15 @@ #include #include #include -#include #ifdef _WIN32 #include +#include + +// check if path is writable #define check_writable(p) (_access((p), 2) == 0) + +// Windows asprintf wrapper #define asprintf(buf, fmt, ...) _asprintf(buf, fmt, __VA_ARGS__) static int _asprintf(char **ret, const char *format, ...) { @@ -28,8 +32,90 @@ static int _asprintf(char **ret, const char *format, ...) va_end(ap); return size; } + +// Windows directory ENTRIES +struct dirent +{ + char d_name[260]; +}; + +typedef long long DIR; + +// _findfirst / _findnext wrapper to behave like opendir/readdir +DIR *opendir(const char *dirname) +{ + char pattern[PATH_MAX + 4]; + snprintf(pattern, sizeof(pattern), "%s/*", dirname); + long handle = _findfirst(pattern, &((struct _finddata_t){0})); + return handle != -1L ? (DIR *)handle : NULL; +} + +struct dirent *readdir(DIR *dir) +{ + static struct _finddata_t entry; + static struct dirent de; + static long handle; + + if (dir == NULL) + return NULL; + + handle = (long)dir; + + if (handle == 0) + return NULL; + + if (handle == -1L) + return NULL; + + // First call + if (handle == (long)dir && _findfirst != 0) + { + handle = _findfirst((const char *)_findfirst, &entry); + if (handle == -1) + return NULL; + } + else + { + // Subsequent calls + if (_findnext(handle, &entry) != 0) + return NULL; + } + + strcpy(de.d_name, entry.name); + return &de; +} + +int closedir(DIR *dir) +{ + if (dir == NULL) + return -1; + long handle = (long)dir; + if (handle == 0 || handle == -1L) + return -1; + _findclose(handle); + return 0; +} + +// is a path a directory (Windows) +int path_is_dir(const char *path) +{ + struct _stat st; + if (_stat(path, &st) != 0) + return 0; + return (st.st_mode & _S_IFDIR) != 0; +} + +// realpath / normalize path if needed +const char *path_real(const char *path) +{ + // just a placeholder; on Windows you can use _fullpath if you want + return path; +} + #else #include +#include + #define check_writable(p) (access((p), W_OK) == 0) #endif @@ -40,8 +126,8 @@ static int _asprintf(char **ret, const char *format, ...) #include "boilerplate_subsystem.h" /* -check to see if the mod structure has generated successfuly, if so, -!!!(for now discard all of the unneeded data and focus only on the tables/ being present)!!! +Check to see if the mod structure has been generated successfully, if so, +focus only on the tables/ directory being present. */ bool verify_mod_structure(const char *base_path) { @@ -55,13 +141,13 @@ bool verify_mod_structure(const char *base_path) bool exists = path_is_dir(dir_path); free(dir_path); - if(!exists) + if (!exists) { return false; } } return true; - } + } else { return false; @@ -87,7 +173,6 @@ TABLE_FILE_LIST *verify_tables_directory(const char *base_path_tables) DIR *dir = opendir(base_path_tables); if (!dir) { - perror("opendir"); free(tfl); return NULL; } @@ -160,21 +245,32 @@ static char *strip_path_ext(const char *filename) dot = base + strlen(base); size_t len = dot - base; - char *key = malloc(len + 1); - if (key) + char *full = malloc(len + 1); + if (full) { - strncpy(key, base, len); - key[len] = '\0'; + strncpy(full, base, len); + full[len] = '\0'; } - return key; + return full; +} + +// Given "XXX‑wep", returns "wep" +static char *strip_prefix(const char *key) +{ + const char *dash = strchr(key, '-'); + if (!dash) + return strdup(key); + return strdup(dash); } -/* strip path and extension, extract key */ -/* linear search through bpl_table[] */ -/* return matching entry or NULL if not found */ const BPL_ENTRY *find_boilerplate(const char *filename) { - char *key = strip_path_ext(filename); + char *full = strip_path_ext(filename); + if (!full) + return NULL; + + char *key = strip_prefix(full); + free(full); if (!key) return NULL; @@ -186,7 +282,7 @@ const BPL_ENTRY *find_boilerplate(const char *filename) return &bpl_table[i]; } - /* Check if key ends with the suffix (for .tbm files) */ + /* Optional: allow suffix matching if you want .tbm entries to be themselves */ size_t suffix_len = strlen(bpl_table[i].key); size_t key_len = strlen(key); @@ -206,26 +302,30 @@ void write_to_tables(const BPL_ENTRY *entry, const char *filepath, OP *operation { FILE *fp; - if(!check_writable(filepath)) + if (!check_writable(filepath)) { fprintf(stderr, "%s%sError:%s Target path is not writable: %s\n", TEX_BOLD, COL_RED, COL_RESET, operation->path); return; } + fp = fopen(filepath, "w"); - if(!fp) + if (!fp) { perror("fopen"); return; } - if (entry && entry->variants){ + if (entry && entry->variants) + { for (size_t i = 0; i < entry->variant_count; i++) { - if (entry->variants[i]){ + if (entry->variants[i]) + { fprintf(fp, "%s\n", entry->variants[i]); } } } + fclose(fp); } \ No newline at end of file diff --git a/src/main.c b/src/main.c index d1dcbc9..c0e059f 100644 --- a/src/main.c +++ b/src/main.c @@ -63,8 +63,9 @@ int main(int argc, char *argv[]) "2. : Target directory\n" "3. <-tbl/-tbm> : Table type (stdmc only)\n" "4. : Required for -tbm\n" - "5. [-debug] : Log to log.txt\n" - "6. [-dry-run] : Simulate only\n"); + "5. [-bpl] : Write boilerplate to tables\n" + "6. [-debug] : Log to log.txt\n" + "7. [-dry-run] : Simulate only\n"); return 0; } @@ -88,7 +89,7 @@ int main(int argc, char *argv[]) fprintf(stderr, "%s%sUsage:%s -stdm [-debug] [-dry-run]\n", TEX_BOLD, COL_YELLOW, COL_RESET); else - fprintf(stderr, "%s%sUsage:%s -stdmc <-tbl/-tbm> [prefix] [-debug] [-dry-run]\n", + fprintf(stderr, "%s%sUsage:%s -stdmc <-tbl/-tbm> [prefix] [-bpl] [-debug] [-dry-run]\n", TEX_BOLD, COL_YELLOW, COL_RESET); return 1; } @@ -100,6 +101,7 @@ int main(int argc, char *argv[]) return 1; } + int start_index = is_stdm ? 3 : 4; if (is_stdmc && operation.table_type && strcmp(operation.table_type, "-tbm") == 0) { if (argc < 5) @@ -113,32 +115,15 @@ int main(int argc, char *argv[]) return 1; } operation.prefix = argv[4]; + start_index = 5; } - int arg_idx = is_stdm ? 3 : 4; - for (int i = arg_idx; i < argc; ++i) + for (int i = start_index; i < argc; ++i) { if (strcmp(argv[i], "-bpl") == 0) { operation.gen_boilerplate = 1; } - else if (!operation.table_type && - (strcmp(argv[i], "-tbl") == 0 || strcmp(argv[i], "-tbm") == 0)) - { - operation.table_type = argv[i]; - } - else if (operation.table_type && strcmp(operation.table_type, "-tbm") == 0 && - !operation.prefix) - { - if (strlen(argv[i]) > 32) - { - fprintf(stderr, "%s%sError:%s Prefix too long (max 32 chars)\n", - TEX_BOLD, COL_RED, COL_RESET); - return 1; - return 1; - } - operation.prefix = argv[i]; - } else if (strcmp(argv[i], "-debug") == 0) { operation.debug = 1; @@ -196,10 +181,8 @@ int main(int argc, char *argv[]) } } - if (operation.table_type && operation.gen_boilerplate) + if (operation.table_type && operation.gen_boilerplate && operation.dry_run == 0) { - printf("%sWriting boilerplate to tables...%s%s\n", TEX_BOLD, COL_MAGENTA, COL_RESET); - char *tables_path = NULL; if (asprintf(&tables_path, "%s/tables", operation.path) == -1) { @@ -210,6 +193,8 @@ int main(int argc, char *argv[]) TABLE_FILE_LIST *tables = verify_tables_directory(tables_path); if (tables) { + printf("%sWriting boilerplate to tables...%s%s\n", TEX_BOLD, COL_MAGENTA, COL_RESET); + for (size_t i = 0; i < tables->count; i++) { const BPL_ENTRY *entry = find_boilerplate(tables->paths[i]); From 6e6621302d923ed105cce5a2400fed82156c9e25 Mon Sep 17 00:00:00 2001 From: LuytenKy Date: Sat, 11 Apr 2026 17:19:45 +0300 Subject: [PATCH 09/13] I hate you Windows --- src/boilerplate_subsystem.c | 95 +++++++------------------------------ 1 file changed, 17 insertions(+), 78 deletions(-) diff --git a/src/boilerplate_subsystem.c b/src/boilerplate_subsystem.c index fdd1505..457285a 100644 --- a/src/boilerplate_subsystem.c +++ b/src/boilerplate_subsystem.c @@ -6,9 +6,23 @@ #include #include +// --- Common portability definitions (outside _WIN32) --- +// Must be defined before any code that uses PATH_MAX / S_ISREG etc. +#ifndef PATH_MAX +#define PATH_MAX 4096 +#endif + +#ifndef S_ISREG +#define S_ISREG(m) (((m) & _S_IFMT) == _S_IFREG) +#endif +#ifndef S_ISDIR +#define S_ISDIR(m) (((m) & _S_IFMT) == _S_IFDIR) +#endif + #ifdef _WIN32 #include #include +#include // check if path is writable #define check_writable(p) (_access((p), 2) == 0) @@ -33,84 +47,9 @@ static int _asprintf(char **ret, const char *format, ...) return size; } -// Windows directory ENTRIES -struct dirent -{ - char d_name[260]; -}; - -typedef long long DIR; - -// _findfirst / _findnext wrapper to behave like opendir/readdir -DIR *opendir(const char *dirname) -{ - char pattern[PATH_MAX + 4]; - snprintf(pattern, sizeof(pattern), "%s/*", dirname); - long handle = _findfirst(pattern, &((struct _finddata_t){0})); - return handle != -1L ? (DIR *)handle : NULL; -} - -struct dirent *readdir(DIR *dir) -{ - static struct _finddata_t entry; - static struct dirent de; - static long handle; - - if (dir == NULL) - return NULL; - - handle = (long)dir; - - if (handle == 0) - return NULL; - - if (handle == -1L) - return NULL; - - // First call - if (handle == (long)dir && _findfirst != 0) - { - handle = _findfirst((const char *)_findfirst, &entry); - if (handle == -1) - return NULL; - } - else - { - // Subsequent calls - if (_findnext(handle, &entry) != 0) - return NULL; - } - - strcpy(de.d_name, entry.name); - return &de; -} - -int closedir(DIR *dir) -{ - if (dir == NULL) - return -1; - long handle = (long)dir; - if (handle == 0 || handle == -1L) - return -1; - _findclose(handle); - return 0; -} - -// is a path a directory (Windows) -int path_is_dir(const char *path) -{ - struct _stat st; - if (_stat(path, &st) != 0) - return 0; - return (st.st_mode & _S_IFDIR) != 0; -} - -// realpath / normalize path if needed -const char *path_real(const char *path) -{ - // just a placeholder; on Windows you can use _fullpath if you want - return path; -} +// --- Windows‑only stuff (opendir / readdir / closedir / path_is_dir) --- +// ... (keep your Windows opendir / readdir / closedir / path_is_dir here) +// ... #else #include From edc9c2fb0693710758ac8ea4d554edacb4063a11 Mon Sep 17 00:00:00 2001 From: LuytenKy Date: Sat, 11 Apr 2026 17:22:17 +0300 Subject: [PATCH 10/13] Windows again --- src/boilerplate_subsystem.c | 86 ++++++++++++++++++++++++++++++++----- 1 file changed, 76 insertions(+), 10 deletions(-) diff --git a/src/boilerplate_subsystem.c b/src/boilerplate_subsystem.c index 457285a..a594c05 100644 --- a/src/boilerplate_subsystem.c +++ b/src/boilerplate_subsystem.c @@ -6,8 +6,8 @@ #include #include -// --- Common portability definitions (outside _WIN32) --- -// Must be defined before any code that uses PATH_MAX / S_ISREG etc. +// --- common portability definitions --- + #ifndef PATH_MAX #define PATH_MAX 4096 #endif @@ -15,14 +15,15 @@ #ifndef S_ISREG #define S_ISREG(m) (((m) & _S_IFMT) == _S_IFREG) #endif -#ifndef S_ISDIR -#define S_ISDIR(m) (((m) & _S_IFMT) == _S_IFDIR) -#endif + +// --- Windows-specific wrappers --- #ifdef _WIN32 + #include #include #include +#include // check if path is writable #define check_writable(p) (_access((p), 2) == 0) @@ -47,15 +48,80 @@ static int _asprintf(char **ret, const char *format, ...) return size; } -// --- Windows‑only stuff (opendir / readdir / closedir / path_is_dir) --- -// ... (keep your Windows opendir / readdir / closedir / path_is_dir here) -// ... +// --- DIR / opendir / readdir / closedir for Windows --- +// Must be visible before verify_tables_directory + +struct dirent +{ + char d_name[260]; +}; + +typedef long long DIR; + +DIR *opendir(const char *dirname) +{ + char pattern[PATH_MAX + 4]; + snprintf(pattern, sizeof(pattern), "%s/*", dirname); + long handle = _findfirst(pattern, &((struct _finddata_t){0})); + return handle != -1L ? (DIR *)handle : NULL; +} + +struct dirent *readdir(DIR *dir) +{ + static struct _finddata_t entry; + static struct dirent de; + static long handle; + + if (dir == NULL) + return NULL; + + handle = (long)dir; + if (handle == 0 || handle == -1L) + return NULL; + + if (handle == (long)dir && _findfirst != 0) + { + handle = _findfirst((const char *)_findfirst, &entry); + if (handle == -1) + return NULL; + } + else + { + if (_findnext(handle, &entry) != 0) + return NULL; + } + + strcpy(de.d_name, entry.name); + return &de; +} + +int closedir(DIR *dir) +{ + if (dir == NULL) + return -1; + long handle = (long)dir; + if (handle == 0 || handle == -1L) + return -1; + _findclose(handle); + return 0; +} + +// --- end of Windows opendir/readdir/closedir --- + +int path_is_dir(const char *path) +{ + struct _stat st; + if (_stat(path, &st) != 0) + return 0; + return (st.st_mode & _S_IFDIR) != 0; +} + +#else // not _WIN32 → Linux -#else #include #include - #define check_writable(p) (access((p), W_OK) == 0) + #endif #include "def_type.h" From bfe520674da854b2d4b9c171da362e05e1965a77 Mon Sep 17 00:00:00 2001 From: LuytenKy Date: Sat, 11 Apr 2026 17:25:29 +0300 Subject: [PATCH 11/13] Windows yet again --- src/main.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/src/main.c b/src/main.c index c0e059f..f3c9a68 100644 --- a/src/main.c +++ b/src/main.c @@ -1,17 +1,48 @@ #include #include #include +#include // for va_list / va_start / va_end #include #include #ifdef _WIN32 #include #include + #define isatty _isatty + +// Windows asprintf wrapper +#define asprintf(buf, fmt, ...) _asprintf(buf, fmt, __VA_ARGS__) +static int _asprintf(char **ret, const char *format, ...) +{ + va_list ap; + int size; + va_start(ap, format); + size = vsnprintf(NULL, 0, format, ap); + va_end(ap); + if (size < 0) + return -1; + *ret = malloc(size + 1); + if (!*ret) + return -1; + va_start(ap, format); + size = vsnprintf(*ret, size + 1, format, ap); + va_end(ap); + return size; +} + #else #include #endif +#include "version.h" +#include "def_type.h" +#include "file_subsystem.h" +#include "text_type.h" +#include "color.h" +#include "boilerplate_subsystem.h" + + #include "version.h" #include "def_type.h" #include "file_subsystem.h" From df5644d9d030f8bf4e32a1c60a0d9e5b2b91bd61 Mon Sep 17 00:00:00 2001 From: LuytenKy Date: Sat, 11 Apr 2026 17:28:15 +0300 Subject: [PATCH 12/13] Windows once more --- src/boilerplate_subsystem.c | 22 ++-------------------- 1 file changed, 2 insertions(+), 20 deletions(-) diff --git a/src/boilerplate_subsystem.c b/src/boilerplate_subsystem.c index a594c05..9474e4a 100644 --- a/src/boilerplate_subsystem.c +++ b/src/boilerplate_subsystem.c @@ -6,8 +6,6 @@ #include #include -// --- common portability definitions --- - #ifndef PATH_MAX #define PATH_MAX 4096 #endif @@ -16,16 +14,12 @@ #define S_ISREG(m) (((m) & _S_IFMT) == _S_IFREG) #endif -// --- Windows-specific wrappers --- - #ifdef _WIN32 - #include #include #include #include -// check if path is writable #define check_writable(p) (_access((p), 2) == 0) // Windows asprintf wrapper @@ -48,9 +42,6 @@ static int _asprintf(char **ret, const char *format, ...) return size; } -// --- DIR / opendir / readdir / closedir for Windows --- -// Must be visible before verify_tables_directory - struct dirent { char d_name[260]; @@ -106,17 +97,7 @@ int closedir(DIR *dir) return 0; } -// --- end of Windows opendir/readdir/closedir --- - -int path_is_dir(const char *path) -{ - struct _stat st; - if (_stat(path, &st) != 0) - return 0; - return (st.st_mode & _S_IFDIR) != 0; -} - -#else // not _WIN32 → Linux +#else #include #include @@ -130,6 +111,7 @@ int path_is_dir(const char *path) #include "file_subsystem.h" #include "boilerplate_subsystem.h" + /* Check to see if the mod structure has been generated successfully, if so, focus only on the tables/ directory being present. From af95c29ae45b2207cf8bbf0d011bd32c7984b7ae Mon Sep 17 00:00:00 2001 From: LuytenKy Date: Sun, 12 Apr 2026 15:43:23 +0300 Subject: [PATCH 13/13] remove duplicate include block --- src/main.c | 8 -------- 1 file changed, 8 deletions(-) diff --git a/src/main.c b/src/main.c index f3c9a68..4285dd9 100644 --- a/src/main.c +++ b/src/main.c @@ -35,14 +35,6 @@ static int _asprintf(char **ret, const char *format, ...) #include #endif -#include "version.h" -#include "def_type.h" -#include "file_subsystem.h" -#include "text_type.h" -#include "color.h" -#include "boilerplate_subsystem.h" - - #include "version.h" #include "def_type.h" #include "file_subsystem.h"