Skip to content

Commit

Permalink
Add VARNAM_SYMBOLS_DIR env variable support
Browse files Browse the repository at this point in the history
  • Loading branch information
subins2000 committed Nov 27, 2020
1 parent a72df80 commit 7ddc7d8
Showing 1 changed file with 26 additions and 17 deletions.
43 changes: 26 additions & 17 deletions varnam.c
Original file line number Diff line number Diff line change
Expand Up @@ -217,14 +217,20 @@ static const char* symbolsFileSearchPath[] = {
const char*
varnam_find_symbols_file_directory()
{
char *tmp;
strbuf *user_path;
int i;

if (varnam_symbols_dir != NULL && is_directory(strbuf_to_s (varnam_symbols_dir))) {
return strbuf_to_s(varnam_symbols_dir);
}

char *env_symbols_dir = getenv("VARNAM_SYMBOLS_DIR");

if (env_symbols_dir != NULL) {
return env_symbols_dir;
}

char *tmp;
strbuf *user_path;
int i;

user_path = strbuf_init (20);

#if defined(WIN32) || defined(_WIN32) || defined(__WIN32)
Expand Down Expand Up @@ -304,6 +310,12 @@ make_directory (const char *dirName)
static strbuf*
find_learnings_file_path (const char *langCode)
{
char *env_symbols_dir = getenv("VARNAM_SUGGESTIONS_DIR");

if (env_symbols_dir != NULL) {
return env_symbols_dir;
}

char *tmp;
strbuf *path;

Expand All @@ -315,21 +327,18 @@ find_learnings_file_path (const char *langCode)
strbuf_addf (path, "%s\\varnam\\suggestions\\", tmp);
}
#else
tmp = getenv ("VARNAM_SUGGESTIONS_DIR");
tmp = getenv ("XDG_DATA_HOME");
if (tmp == NULL) {
tmp = getenv ("XDG_DATA_HOME");
if (tmp == NULL) {
tmp = getenv ("HOME");
if (tmp != NULL) {
strbuf_addf (path, "%s/.local/share/varnam/suggestions/", tmp);
}
}
else {
strbuf_addf (path, "%s/varnam/suggestions/", tmp);
}
tmp = getenv ("HOME");
if (tmp != NULL) {
strbuf_addf (path, "%s/.local/share/varnam/suggestions/", tmp);
}
else {
strbuf_addf (path, "%s/varnam/suggestions/", tmp);
}
}
else {
strbuf_addf (path, "%s/", tmp);
strbuf_addf (path, "%s/varnam/suggestions/", tmp);
}
#endif

Expand All @@ -347,7 +356,7 @@ find_learnings_file_path (const char *langCode)
}
}
}

strbuf_addf (path, "%s.vst.learnings", langCode);
return path;
}
Expand Down

0 comments on commit 7ddc7d8

Please sign in to comment.