Files
wmaker/WINGs/wapplication.c
T

203 lines
4.2 KiB
C
Raw Normal View History

1998-09-29 22:36:29 +00:00
#include <unistd.h>
#include "WINGsP.h"
2001-07-23 20:31:32 +00:00
#include "wconfig.h"
#include "X11/Xlocale.h"
1998-09-29 22:36:29 +00:00
extern void W_InitNotificationCenter(void);
struct W_Application WMApplication;
char *_WINGS_progname = NULL;
2004-10-12 21:28:27 +00:00
Bool
1998-09-29 22:36:29 +00:00
W_ApplicationInitialized(void)
{
return _WINGS_progname!=NULL;
}
void
WMInitializeApplication(char *applicationName, int *argc, char **argv)
{
int i;
2001-07-23 20:31:32 +00:00
1998-09-29 22:36:29 +00:00
assert(argc!=NULL);
assert(argv!=NULL);
assert(applicationName!=NULL);
2001-07-23 20:31:32 +00:00
setlocale(LC_ALL, "");
2001-07-23 20:31:32 +00:00
#ifdef I18N
if (getenv("NLSPATH"))
2004-10-12 21:28:27 +00:00
bindtextdomain("WINGs", getenv("NLSPATH"));
2001-07-23 20:31:32 +00:00
else
2004-10-12 21:28:27 +00:00
bindtextdomain("WINGs", LOCALEDIR);
bind_textdomain_codeset("WINGs", "UTF-8");
2001-07-23 20:31:32 +00:00
#endif
1998-09-29 22:36:29 +00:00
_WINGS_progname = argv[0];
1998-09-29 22:36:29 +00:00
WMApplication.applicationName = wstrdup(applicationName);
WMApplication.argc = *argc;
WMApplication.argv = wmalloc((*argc+1)*sizeof(char*));
for (i=0; i<*argc; i++) {
2004-10-12 21:28:27 +00:00
WMApplication.argv[i] = wstrdup(argv[i]);
1998-09-29 22:36:29 +00:00
}
WMApplication.argv[i] = NULL;
1998-09-29 22:36:29 +00:00
/* initialize notification center */
W_InitNotificationCenter();
}
void
WMSetResourcePath(char *path)
{
if (WMApplication.resourcePath)
2004-10-12 21:28:27 +00:00
wfree(WMApplication.resourcePath);
1998-09-29 22:36:29 +00:00
WMApplication.resourcePath = wstrdup(path);
}
char*
WMGetApplicationName()
{
return WMApplication.applicationName;
}
static char*
checkFile(char *path, char *folder, char *ext, char *resource)
{
char *ret;
int extralen;
2004-10-12 21:28:27 +00:00
extralen = (ext ? strlen(ext) : 0) + (folder ? strlen(folder) : 0) + 4;
1998-09-29 22:36:29 +00:00
ret = wmalloc(strlen(path)+strlen(resource)+extralen+8);
strcpy(ret, path);
if (folder) {
2004-10-12 21:28:27 +00:00
strcat(ret, "/");
strcat(ret, folder);
1998-09-29 22:36:29 +00:00
}
if (ext) {
2004-10-12 21:28:27 +00:00
strcat(ret, "/");
strcat(ret, ext);
1998-09-29 22:36:29 +00:00
}
strcat(ret, "/");
strcat(ret, resource);
2004-10-12 21:28:27 +00:00
1998-09-29 22:36:29 +00:00
if (access(ret, F_OK)!=0) {
2004-10-12 21:28:27 +00:00
wfree(ret);
ret = NULL;
1998-09-29 22:36:29 +00:00
}
return ret;
}
char*
WMPathForResourceOfType(char *resource, char *ext)
{
char *path = NULL;
char *tmp, *appdir;
int i;
2004-10-12 21:28:27 +00:00
/*
1998-09-29 22:36:29 +00:00
* Paths are searched in this order:
* - resourcePath/ext
* - argv[0]/ext
* - GNUSTEP_USER_ROOT/Applications/ApplicationName.app/ext
* - ~/GNUstep/Applications/ApplicationName.app/ext
* - GNUSTEP_LOCAL_ROOT/Applications/ApplicationName.app/ext
* - /usr/local/GNUstep/Applications/ApplicationName.app/ext
* - GNUSTEP_SYSTEM_ROOT/Applications/ApplicationName.app/ext
* - /usr/GNUstep/Applications/ApplicationName.app/ext
1998-09-29 22:36:29 +00:00
*/
2004-10-12 21:28:27 +00:00
1998-09-29 22:36:29 +00:00
if (WMApplication.resourcePath) {
2004-10-12 21:28:27 +00:00
path = checkFile(WMApplication.resourcePath, NULL, ext, resource);
if (path)
return path;
1998-09-29 22:36:29 +00:00
}
if (WMApplication.argv[0]) {
2004-10-12 21:28:27 +00:00
tmp = wstrdup(WMApplication.argv[0]);
i = strlen(tmp);
while (i > 0 && tmp[i]!='/')
i--;
tmp[i] = 0;
if (i>0) {
path = checkFile(tmp, NULL, ext, resource);
} else {
path = NULL;
}
wfree(tmp);
if (path)
return path;
1998-09-29 22:36:29 +00:00
}
2004-10-12 21:28:27 +00:00
appdir = wmalloc(strlen(WMApplication.applicationName)+20);
sprintf(appdir, "Applications/%s.app", WMApplication.applicationName);
1998-09-29 22:36:29 +00:00
if (getenv("GNUSTEP_USER_ROOT")) {
2004-10-12 21:28:27 +00:00
path = checkFile(getenv("GNUSTEP_USER_ROOT"), appdir, ext, resource);
if (path) {
wfree(appdir);
return path;
}
1998-09-29 22:36:29 +00:00
}
2004-10-12 21:28:27 +00:00
1998-09-29 22:36:29 +00:00
tmp = wusergnusteppath();
if (tmp) {
2004-10-12 21:28:27 +00:00
path = checkFile(tmp, appdir, ext, resource);
if (path) {
wfree(appdir);
return path;
}
1998-09-29 22:36:29 +00:00
}
2004-10-12 21:28:27 +00:00
1998-09-29 22:36:29 +00:00
if (getenv("GNUSTEP_LOCAL_ROOT")) {
2004-10-12 21:28:27 +00:00
path = checkFile(getenv("GNUSTEP_LOCAL_ROOT"), appdir, ext, resource);
if (path) {
wfree(appdir);
return path;
}
1998-09-29 22:36:29 +00:00
}
2004-10-12 21:28:27 +00:00
1998-09-29 22:36:29 +00:00
path = checkFile("/usr/local/GNUstep", appdir, ext, resource);
if (path) {
2004-10-12 21:28:27 +00:00
wfree(appdir);
return path;
1998-09-29 22:36:29 +00:00
}
2004-10-12 21:28:27 +00:00
1998-09-29 22:36:29 +00:00
if (getenv("GNUSTEP_SYSTEM_ROOT")) {
2004-10-12 21:28:27 +00:00
path = checkFile(getenv("GNUSTEP_SYSTEM_ROOT"), appdir, ext, resource);
if (path) {
wfree(appdir);
return path;
}
1998-09-29 22:36:29 +00:00
}
path = checkFile("/usr/GNUstep", appdir, ext, resource);
if (path) {
2004-10-12 21:28:27 +00:00
wfree(appdir);
return path;
1998-09-29 22:36:29 +00:00
}
2004-10-12 21:28:27 +00:00
1998-09-29 22:36:29 +00:00
return NULL;
}