mirror of
https://github.com/gryf/wmaker.git
synced 2026-01-06 22:04:12 +01:00
WINGs: Simplify WMPathForResourceOfType()
Signed-off-by: Tamas TEVESZ <ice@extreme.hu>
This commit is contained in:
committed by
Carlos R. Mafra
parent
553464d965
commit
0d32a6d3b7
@@ -93,14 +93,16 @@ static char *checkFile(char *path, char *folder, char *ext, char *resource)
|
|||||||
|
|
||||||
char *WMPathForResourceOfType(char *resource, char *ext)
|
char *WMPathForResourceOfType(char *resource, char *ext)
|
||||||
{
|
{
|
||||||
char *path = NULL;
|
char *path, *tmp, *appdir;
|
||||||
char *tmp, *appdir;
|
|
||||||
int i;
|
int i;
|
||||||
|
size_t slen;
|
||||||
|
|
||||||
|
path = tmp = appdir = NULL;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Paths are searched in this order:
|
* Paths are searched in this order:
|
||||||
* - resourcePath/ext
|
* - resourcePath/ext
|
||||||
* - argv[0]/ext
|
* - dirname(argv[0])/ext
|
||||||
* - GNUSTEP_USER_ROOT/Applications/ApplicationName.app/ext
|
* - GNUSTEP_USER_ROOT/Applications/ApplicationName.app/ext
|
||||||
* - ~/GNUstep/Applications/ApplicationName.app/ext
|
* - ~/GNUstep/Applications/ApplicationName.app/ext
|
||||||
* - GNUSTEP_LOCAL_ROOT/Applications/ApplicationName.app/ext
|
* - GNUSTEP_LOCAL_ROOT/Applications/ApplicationName.app/ext
|
||||||
@@ -112,7 +114,7 @@ char *WMPathForResourceOfType(char *resource, char *ext)
|
|||||||
if (WMApplication.resourcePath) {
|
if (WMApplication.resourcePath) {
|
||||||
path = checkFile(WMApplication.resourcePath, NULL, ext, resource);
|
path = checkFile(WMApplication.resourcePath, NULL, ext, resource);
|
||||||
if (path)
|
if (path)
|
||||||
return path;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (WMApplication.argv[0]) {
|
if (WMApplication.argv[0]) {
|
||||||
@@ -126,58 +128,42 @@ char *WMPathForResourceOfType(char *resource, char *ext)
|
|||||||
} else {
|
} else {
|
||||||
path = NULL;
|
path = NULL;
|
||||||
}
|
}
|
||||||
wfree(tmp);
|
goto out;
|
||||||
if (path)
|
|
||||||
return path;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
appdir = wmalloc(strlen(WMApplication.applicationName) + 20);
|
slen = strlen(WMApplication.applicationName) + sizeof("Applications/.app");
|
||||||
sprintf(appdir, "Applications/%s.app", WMApplication.applicationName);
|
appdir = wmalloc(slen);
|
||||||
|
if (snprintf(appdir, slen, "Applications/%s.app", WMApplication.applicationName) >= slen)
|
||||||
|
goto out;
|
||||||
|
|
||||||
if (getenv("GNUSTEP_USER_ROOT")) {
|
|
||||||
path = checkFile(getenv("GNUSTEP_USER_ROOT"), appdir, ext, resource);
|
path = checkFile(getenv("GNUSTEP_USER_ROOT"), appdir, ext, resource);
|
||||||
if (path) {
|
if (path)
|
||||||
wfree(appdir);
|
goto out;
|
||||||
return path;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
tmp = wusergnusteppath();
|
path = checkFile(wusergnusteppath(), appdir, ext, resource);
|
||||||
if (tmp) {
|
if (path)
|
||||||
path = checkFile(tmp, appdir, ext, resource);
|
goto out;
|
||||||
if (path) {
|
|
||||||
wfree(appdir);
|
|
||||||
return path;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (getenv("GNUSTEP_LOCAL_ROOT")) {
|
|
||||||
path = checkFile(getenv("GNUSTEP_LOCAL_ROOT"), appdir, ext, resource);
|
path = checkFile(getenv("GNUSTEP_LOCAL_ROOT"), appdir, ext, resource);
|
||||||
if (path) {
|
if (path)
|
||||||
wfree(appdir);
|
goto out;
|
||||||
return path;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
path = checkFile("/usr/local/GNUstep", appdir, ext, resource);
|
path = checkFile("/usr/local/GNUstep", appdir, ext, resource);
|
||||||
if (path) {
|
if (path)
|
||||||
wfree(appdir);
|
goto out;
|
||||||
return path;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (getenv("GNUSTEP_SYSTEM_ROOT")) {
|
|
||||||
path = checkFile(getenv("GNUSTEP_SYSTEM_ROOT"), appdir, ext, resource);
|
path = checkFile(getenv("GNUSTEP_SYSTEM_ROOT"), appdir, ext, resource);
|
||||||
if (path) {
|
if (path)
|
||||||
wfree(appdir);
|
goto out;
|
||||||
return path;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
path = checkFile("/usr/GNUstep", appdir, ext, resource);
|
path = checkFile("/usr/GNUstep", appdir, ext, resource); /* falls through */
|
||||||
if (path) {
|
|
||||||
wfree(appdir);
|
out:
|
||||||
return path;
|
if (tmp)
|
||||||
}
|
wfree(tmp);
|
||||||
|
if (appdir)
|
||||||
|
wfree(appdir);
|
||||||
|
|
||||||
|
return path;
|
||||||
|
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user