diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml deleted file mode 100644 index 6ee9f64..0000000 --- a/.github/workflows/ci.yaml +++ /dev/null @@ -1,62 +0,0 @@ -# This file is part of MCA-Selector-lite, -# and is licensed under GPL-2.0-only. -# Copyright (C)2025 quinnthepigeon@proton.me Quinn -# For further information, view COPYING and CONTRIBUTORS -# at: www.github.com/thepigeongenerator/mcaselector-lite -name: CI -on: - push: - branches: [main] - -jobs: - compile-and-test: - strategy: - fail-fast: false # disable fail fast, so feedback is provided for all matrix combinations - matrix: - include: - - os: ubuntu-latest - cc: cc - - os: ubuntu-24.04-arm - cc: cc - - os: windows-latest - cc: gcc - - os: windows-11-arm - cc: gcc - # - os: macos-latest - # cc: cc - env: - CC: ${{matrix.cc}} - runs-on: ${{matrix.os}} - steps: - - uses: actions/checkout@v5 - with: - submodules: true - fetch-depth: 1 - - - name: "Linux: install deps" - if: runner.os == 'Linux' - run: | - sudo apt update - sudo apt install -y libwayland-dev libxkbcommon-dev xorg-dev cmake xxd - - - name: get submodule hash - id: get-hash - run: echo "HASH=$(git submodule | sha1sum | cut -d' ' -f1)" >$GITHUB_OUTPUT - shell: bash - - - uses: actions/cache@v4 - id: cache-deps - with: - path: lib/obj/ - # I swear to god, if runner.arch displays x64 for x86_64, I will eat a potato. - # note: it is... fucking shit. - key: ${{runner.os}}_${{runner.arch}}-lib/obj-${{steps.get-hash.outputs.HASH}} - restore-keys: ${{runner.os}}_${{runner.arch}}-lib/obj- - - - run: make -Bj libs - if: steps.cache-deps.outputs.cache-hit != 'true' && runner.os != 'Windows' - - run: make -Bj2 libs # compile fewer cores, to save memory. - if: steps.cache-deps.outputs.cache-hit != 'true' && runner.os == 'Windows' - - - run: make -j all - - run: make -j check diff --git a/docs/README.md b/docs/README.md index 545e65a..2549112 100644 --- a/docs/README.md +++ b/docs/README.md @@ -7,8 +7,6 @@ A from-scratch rewrite of [mcaselector](https://github.com/Querz/mcaselector) in [![licence](https://img.shields.io/github/license/thepigeongenerator/mcaselector-lite.svg)](https://github.com/thepigeongenerator/mcaselector-lite/blob/main/LICENSE) [![issues](https://img.shields.io/github/issues/thepigeongenerator/mcaselector-lite.svg)](https://github.com/thepigeongenerator/mcaselector-lite/issues/) -[![CI-status](https://github.com/thepigeongenerator/mcaselector-lite/actions/workflows/ci.yaml/badge.svg)](https://github.com/thepigeongenerator/mcaselector-lite/actions/workflows/ci.yaml) - ## what does it do MCA selector lite is a tool used to edit [region files](https://minecraft.wiki/w/Region_file_format) of your [Minecraft java](https://minecraft.wiki/w/Java_Edition) worlds. This is useful for reducing world size, general world management, perhaps copying chunks from one world to another or various other administrative tasks. diff --git a/src/io/conf.c b/src/io/conf.c index 7506648..231dab6 100644 --- a/src/io/conf.c +++ b/src/io/conf.c @@ -22,7 +22,9 @@ static const char *strmat(const char *s1, const char *s2) return s1; } -int conf_getkeyval(const char *restrict buf, const char *const restrict *restrict keys, int klen, const char *restrict *restrict out) +int conf_getkeyval(const char *restrict buf, + const char *const restrict *restrict keys, int klen, + const char *restrict *restrict out) { const char *tmp = NULL; diff --git a/test/main.c b/test/main.c deleted file mode 100644 index 7e8bf91..0000000 --- a/test/main.c +++ /dev/null @@ -1,57 +0,0 @@ -/* This file is part of MCA-Selector-lite, - * and is licensed under GPL-2.0-only. - * Copyright (C)2025 quinnthepigeon@proton.me Quinn - * For further information, view COPYING and CONTRIBUTORS - * at: www.github.com/thepigeongenerator/mcaselector-lite */ -#include -#include - -#include "test.h" -#include "test_conf.h" - -int main(void) -{ - assert_true(-3 >> 5 == -1); // checking for arithmetic shift, rather than logical shift - assert_true(sizeof(u8) == 1); - assert_true(sizeof(u16) == 2); - assert_true(sizeof(u32) == 4); - assert_true(sizeof(u64) == 8); - assert_true(sizeof(f32) == 4); - assert_true(sizeof(f64) == 8); - assert_true(sizeof(usize) == sizeof(size_t)); - test_conf_procbuf("key=val", "key", "val", 0); - test_conf_procbuf("sometxt", "sometxt", "", CONF_ESYNTAX); - test_conf_procbuf("# comment", "", "", CONF_ENODAT); - test_conf_procbuf("", "", "", CONF_ENODAT); - test_conf_procbuf("\n", "", "", CONF_ENODAT); - test_conf_procbuf("\r\n", "", "", CONF_ENODAT); - test_conf_procbuf("k=v\na", "k", "v", 0); - test_conf_procbuf("k=v\r\na", "k", "v", 0); - test_conf_getpat(); - - struct conf_entry opts[] = { - {"key0", NULL, 0}, - {"key1", NULL, 0}, - {"key2", NULL, 0} - }; - test_conf_matchopt(opts, 3, "key0", 0); - test_conf_matchopt(opts, 3, "key1", 1); - test_conf_matchopt(opts, 3, "key2", 2); - test_conf_matchopt(opts, 3, "key3", -1); - - test_conf_procval_int("42", 42, CONF_I32); - test_conf_procval_int("-42", (u32)-42, CONF_I32); - test_conf_procval_int("4294967295", UINT32_MAX, CONF_U32); - test_conf_procval_int("9223372036854775807", INT64_MAX, CONF_I64); - test_conf_procval_int("256", 255, CONF_U8); - - // TODO: write more tests for float parsing - test_conf_procval_f32("0.0", 0.0f); - test_conf_procval_f32("3.14159", 3.14159f); - test_conf_procval_f32("3.1428571428", 22.0f / 7.0f); - test_conf_procval_f32("-5.0", -5.0f); - - /* return 1 if there were failed tests. */ - printf("test results: (%u/%u)\n", test_okay, test_okay + test_fail); - return !!test_fail; -} diff --git a/test/test.c b/test/test.c deleted file mode 100644 index c81af6c..0000000 --- a/test/test.c +++ /dev/null @@ -1,23 +0,0 @@ -/* This file is part of MCA-Selector-lite, - * and is licensed under GPL-2.0-only. - * Copyright (C)2025 quinnthepigeon@proton.me Quinn - * For further information, view COPYING and CONTRIBUTORS - * at: www.github.com/thepigeongenerator/mcaselector-lite */ -#include "test.h" - -#include "../src/types.h" - -uint test_okay = 0; -uint test_fail = 0; - -int test_process(int res, const char *restrict file, uint ln, const char *restrict function, const char *restrict expression) -{ - const char *status = res ? - "[\033[32;1m OK \033[0m]" : - "[\033[31;1m FAIL \033[0m]"; - test_okay += !!res; - test_fail += !res; - - printf("%s\t%s:%u-%s\t-> %s\n", status, file, ln, function, expression); - return res; -} diff --git a/test/test.h b/test/test.h deleted file mode 100644 index 0fe24f0..0000000 --- a/test/test.h +++ /dev/null @@ -1,19 +0,0 @@ -/* This file is part of MCA-Selector-lite, - * and is licensed under GPL-2.0-only. - * Copyright (C)2025 quinnthepigeon@proton.me Quinn - * For further information, view COPYING and CONTRIBUTORS - * at: www.github.com/thepigeongenerator/mcaselector-lite */ -#pragma once -#include - -#include "../src/types.h" - -extern uint test_okay; -extern uint test_fail; - -/* Prints the result `res` of a test. - * Returns `res` back, for ease of chaining. */ -int test_process(int res, const char *restrict file, uint ln, const char *restrict function, const char *restrict expression); - -#define assert_true(expr) test_process((expr), __FILE__, __LINE__, __func__, #expr) -#define assert_false(expr) assert_true(!(expr)) diff --git a/test/test_conf.c b/test/test_conf.c deleted file mode 100644 index 37defb4..0000000 --- a/test/test_conf.c +++ /dev/null @@ -1,144 +0,0 @@ -/* This file is part of MCA-Selector-lite, - * and is licensed under GPL-2.0-only. - * Copyright (C)2025 quinnthepigeon@proton.me Quinn - * For further information, view COPYING and CONTRIBUTORS - * at: www.github.com/thepigeongenerator/mcaselector-lite */ -#include "test_conf.h" - -#include -#include - -#include "../src/types.h" -#include "../src/util/conf.h" -#include "test.h" - -void test_conf_procbuf(const char *restrict buf, const char *restrict expect_key, const char *restrict expect_val, int expect_return) -{ - usize len = strlen(buf) + 1; - char k[len], v[len]; - *k = '\0', *v = '\0'; - (void)(assert_true(conf_procbuf(buf, k, v, len) == expect_return) && - assert_true(!strcmp(k, expect_key)) && - assert_true(!strcmp(v, expect_val))); -} - -void test_conf_matchopt(struct conf_entry *opts, usize optc, const char *restrict key, int expect_index) -{ - usize idx = opts - conf_matchopt(opts, optc, key); - idx = (ssize)idx < 0 ? -idx : idx; - int i = idx < optc ? (int)idx : -1; - assert_true(i == expect_index); -} - -void test_conf_procval_int(const char *val, u64 expect_value, int type) -{ - u8 out[sizeof(u64)] = {0}; - assert_true(!conf_procval(&(struct conf_entry){NULL, out, type}, val)); - assert_true(memcmp(out, &expect_value, sizeof(u64)) == 0); -} - -void test_conf_procval_f32(const char *val, f32 expect_value) -{ - u8 out[4]; - f32 result; - conf_procval(&(struct conf_entry){NULL, out, CONF_F32}, val); - memcpy(&result, out, 4); - assert_true(fabsf(expect_value - result) < 1e-9f); -} - -void test_procval_str(void) -{ - char *out = NULL; - (void)(assert_true(!conf_procval(&(struct conf_entry){NULL, (void *)&out, CONF_STR}, "here comes the sowon")) && - assert_false(strcmp("here comes the sowon", out))); - free(out); -} - -void test_procval_str_predef(void) -{ - char *out = strdup("owo"); - (void)(assert_true(!conf_procval(&(struct conf_entry){NULL, (void *)&out, CONF_STR}, "i leak if I don't free")) && - assert_true(!strcmp("i leak if I don't free", out))); - free(out); -} - -void test_procval_fstr(void) -{ - char buf[16]; - struct conf_fstr str = {sizeof(buf), buf}; - (void)(assert_true(!conf_procval(&(struct conf_entry){NULL, &str, CONF_FSTR}, "hewwoo wowld")) && - assert_true(!strcmp(str.out, "hewwoo wowld"))); -} - -void test_procval_fstr_trunc(void) -{ - char buf[8]; - struct conf_fstr str = {sizeof(buf), buf}; - (void)(assert_true(!conf_procval(&(struct conf_entry){NULL, &str, CONF_FSTR}, "hewwooo wowld")) && - assert_true(!strcmp(str.out, "hewwooo"))); -} - -void test_procval_eparse(void) -{ - i32 out; - assert_true(conf_procval(&(struct conf_entry){NULL, &out, CONF_I32}, "owo") == CONF_EPARSE); -} - -void test_conf_getpat(void) -{ - char *path; -#if defined(__linux__) - /* test without setting environment variables. */ - unsetenv("XDG_CONFIG_HOME"); - unsetenv("HOME"); - path = conf_getpat("/mypath"); - assert_true(path == NULL); - free(path); - - /* test with setting HOME. */ - setenv("HOME", "/home/test", 1); - path = conf_getpat("/mypath"); - assert_true(path != NULL && strcmp(path, "/home/test/.config/mypath") == 0); - free(path); - conf_getpat("/mypath"); - - /* test with setting XDG_CONFIG_HOME. */ - setenv("XDG_CONFIG_HOME", "/etc/xdg", 1); - path = conf_getpat("/mypath"); - assert_true(path != NULL && strcmp(path, "/etc/xdg/mypath") == 0); - free(path); -#elif defined(__APPLE__) - /* test without setting environment variables. */ - unsetenv("HOME"); - path = conf_getpat("/mypath"); - assert_true(path == NULL); - free(path); - - /* test with setting HOME. */ - setenv("HOME", "/home/test", 1); - path = conf_getpat("/mypath"); - assert_true(path != NULL && strcmp(path, "/home/test/Library/Application Support/mypath") == 0); - free(path); -#elif defined(_WIN32) || defined(_WIN64) || defined(__CYGWIN__) - /* test without setting environment variables. */ - _putenv("APPDATA="); - _putenv("USERPROFILE="); - path = conf_getpat("\\mypath"); - assert_true(path == NULL); - free(path); - - /* test with setting USERPROFILE */ - _putenv("USERPROFILE=C:\\Users\\test"); - path = conf_getpat("\\mypath"); - assert_true(path != NULL && strcmp(path, "C:\\Users\\test\\AppData\\Roaming\\mypath") == 0); - free(path); - - /* test with setting APPDATA */ - _putenv("APPDATA=C:\\Users\\test\\AppData\\Roaming"); - path = conf_getpat("\\mypath"); - assert_true(path != NULL && strcmp(path, "C:\\Users\\test\\AppData\\Roaming\\mypath") == 0); - free(path); -#else - assert_fail("unsupported operating system; no tests have been written."); -#endif -} diff --git a/test/test_conf.h b/test/test_conf.h deleted file mode 100644 index 1e953f9..0000000 --- a/test/test_conf.h +++ /dev/null @@ -1,22 +0,0 @@ -/* This file is part of MCA-Selector-lite, - * and is licensed under GPL-2.0-only. - * Copyright (C)2025 quinnthepigeon@proton.me Quinn - * For further information, view COPYING and CONTRIBUTORS - * at: www.github.com/thepigeongenerator/mcaselector-lite */ -#pragma once - -#include "../src/types.h" -#include "../src/util/conf.h" - -void test_conf_procbuf(const char *restrict buf, const char *restrict expect_key, const char *restrict expect_val, int expect_return); -void test_conf_matchopt(struct conf_entry *restrict opts, usize optc, const char *restrict key, int expect_index); -void test_conf_procval_int(const char *val, u64 expect_value, int type); -void test_conf_procval_f32(const char *val, f32 expect_value); -void test_conf_procval_fstr(const char *val, u64 expect_value, int type); -void test_conf_procval_str(const char *val, u64 expect_value, int type); -void test_procval_str(void); -void test_procval_str_predef(void); -void test_procval_fstr(void); -void test_procval_fstr_trunc(void); -void test_procval_eparse(void); -void test_conf_getpat(void);