From de17ffcee379de8a4652afe51cc64e33f2c0c926 Mon Sep 17 00:00:00 2001 From: butterkeks Date: Fri, 3 May 2024 22:14:31 +0200 Subject: [PATCH] Move default config to function + github workflow --- .github/workflows/ci.yml | 2 +- src/settings.c | 61 ++++++++++++++++++++++------------------ 2 files changed, 35 insertions(+), 28 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7fb5d5a..f4af2a8 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -6,7 +6,7 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - run: sudo add-apt-repository -y ppa:ubuntu-toolchain-r/test - run: sudo apt-get update diff --git a/src/settings.c b/src/settings.c index 977833b..1636a37 100644 --- a/src/settings.c +++ b/src/settings.c @@ -9,35 +9,40 @@ #include "settings.h" #include "util.h" -static settings const default_cfg = { - .general.sort = 0, - .general.dictSortOrder = NULL, - .general.dbpth = NULL, // Set by set_runtime_defaults() - .general.nukeWhitespaceLookup = 1, - .general.mecab = 0, - .general.substringSearch = 1, - // - .anki.enabled = 0, - .anki.deck = NULL, // Don't even try to guess - .anki.notetype = "Japanese sentences", - .anki.fieldnames = (char *[]){"SentKanji", "VocabKanji", "VocabFurigana", "VocabDef", "Notes"}, - .anki.numFields = 0, - .anki.copySentence = 1, - .anki.nukeWhitespaceSentence = 1, - .anki.fieldMapping = (u32[]){3, 4, 7, 6, 8}, - .anki.checkExisting = 0, - // - .popup.width = 600, - .popup.height = 400, - .popup.margin = 5, - // - .pron.displayButton = 0, - .pron.onStart = 0, - .pron.dirPath = NULL, // Don't guess -}; -settings cfg = default_cfg; +settings cfg = {0}; bool print_cfg = false; +static settings get_default_cfg(void) { + settings default_cfg = { + .general.sort = 0, + .general.dictSortOrder = NULL, + .general.dbpth = NULL, // Set by set_runtime_defaults() + .general.nukeWhitespaceLookup = 1, + .general.mecab = 0, + .general.substringSearch = 1, + // + .anki.enabled = 0, + .anki.deck = NULL, // Don't even try to guess + .anki.notetype = "Japanese sentences", + .anki.fieldnames = + (char *[]){"SentKanji", "VocabKanji", "VocabFurigana", "VocabDef", "Notes"}, + .anki.numFields = 0, + .anki.copySentence = 1, + .anki.nukeWhitespaceSentence = 1, + .anki.fieldMapping = (u32[]){3, 4, 7, 6, 8}, + .anki.checkExisting = 0, + // + .popup.width = 600, + .popup.height = 400, + .popup.margin = 5, + // + .pron.displayButton = 0, + .pron.onStart = 0, + .pron.dirPath = NULL, // Don't guess + }; + return default_cfg; +} + static void set_runtime_defaults(void) { if (!cfg.general.dbpth) { cfg.general.dbpth = @@ -248,6 +253,8 @@ static void read_pronunciation(GKeyFile *kf) { } void read_user_settings(int fieldmapping_max) { + cfg = get_default_cfg(); // TODO: Put this to the end and only set missing values + g_autoptr(GKeyFile) kf = g_key_file_new(); GError *error = NULL; _drop_(frees8) s8 cfgpth =