find exe path

This commit is contained in:
tildearrow 2024-06-18 18:00:22 -05:00
parent e3e9d2bbe6
commit 36cb12acb8

View file

@ -116,7 +116,8 @@ char localeDir[4096];
const char* localeDirs[]={
"locale",
"../po/locale",
".." DIR_SEPARATOR_STR "share" DIR_SEPARATOR_STR "locale",
".." DIR_SEPARATOR_STR "po" DIR_SEPARATOR_STR "locale",
#ifdef LOCALE_DIR
LOCALE_DIR,
#endif
@ -124,6 +125,15 @@ const char* localeDirs[]={
};
#endif
bool getExePath(char* argv0, char* exePath, size_t maxSize) {
if (argv0==NULL) return false;
if (realpath(argv0,exePath)==NULL) return false;
char* lastChar=strrchr(exePath,DIR_SEPARATOR);
if (lastChar==NULL) return false;
*lastChar=0;
return true;
}
TAParamResult pHelp(String) {
printf("usage: furnace [params] [filename]\n"
"you may specify the following parameters:\n");
@ -566,9 +576,22 @@ int main(int argc, char** argv) {
}
#endif
char exePath[4096];
#ifdef ANDROID
memset(exePath,0,4096);
#else
if (!getExePath(argv[0],exePath,4096)) memset(exePath,0,4096);
#endif
bool textDomainBound=false;
for (int i=0; localeDirs[i]; i++) {
strncpy(localeDir,localeDirs[i],4095);
if (exePath[0]!=0 && localeDirs[i][0]!=DIR_SEPARATOR) {
strncpy(localeDir,exePath,4095);
strncat(localeDir,DIR_SEPARATOR_STR,4095);
strncat(localeDir,localeDirs[i],4095);
} else {
strncpy(localeDir,localeDirs[i],4095);
}
logV("bind text domain: %s",localeDir);
if (!dirExists(localeDir)) continue;
if ((localeRet=TA_BINDTEXTDOMAIN("furnace",localeDir))==NULL) {