Skip to content

Commit

Permalink
Move default config to function + github workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
btrkeks committed May 3, 2024
1 parent 69d715e commit de17ffc
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 28 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
61 changes: 34 additions & 27 deletions src/settings.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down Expand Up @@ -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 =
Expand Down

0 comments on commit de17ffc

Please sign in to comment.