3 #include <X11/Xlocale.h>
8 extern void W_InitNotificationCenter(void);
10 struct W_Application WMApplication
;
12 char *_WINGS_progname
= NULL
;
14 Bool
W_ApplicationInitialized(void)
16 return _WINGS_progname
!= NULL
;
19 void WMInitializeApplication(char *applicationName
, int *argc
, char **argv
)
25 assert(applicationName
!= NULL
);
27 setlocale(LC_ALL
, "");
30 if (getenv("NLSPATH"))
31 bindtextdomain("WINGs", getenv("NLSPATH"));
33 bindtextdomain("WINGs", LOCALEDIR
);
34 bind_textdomain_codeset("WINGs", "UTF-8");
37 _WINGS_progname
= argv
[0];
39 WMApplication
.applicationName
= wstrdup(applicationName
);
40 WMApplication
.argc
= *argc
;
42 WMApplication
.argv
= wmalloc((*argc
+ 1) * sizeof(char *));
43 for (i
= 0; i
< *argc
; i
++) {
44 WMApplication
.argv
[i
] = wstrdup(argv
[i
]);
46 WMApplication
.argv
[i
] = NULL
;
48 /* initialize notification center */
49 W_InitNotificationCenter();
52 void WMSetResourcePath(char *path
)
54 if (WMApplication
.resourcePath
)
55 wfree(WMApplication
.resourcePath
);
56 WMApplication
.resourcePath
= wstrdup(path
);
59 char *WMGetApplicationName()
61 return WMApplication
.applicationName
;
64 static char *checkFile(char *path
, char *folder
, char *ext
, char *resource
)
69 extralen
= (ext
? strlen(ext
) : 0) + (folder
? strlen(folder
) : 0) + 4;
70 ret
= wmalloc(strlen(path
) + strlen(resource
) + extralen
+ 8);
81 strcat(ret
, resource
);
83 if (access(ret
, F_OK
) != 0) {
91 char *WMPathForResourceOfType(char *resource
, char *ext
)
98 * Paths are searched in this order:
101 * - GNUSTEP_USER_ROOT/Applications/ApplicationName.app/ext
102 * - ~/GNUstep/Applications/ApplicationName.app/ext
103 * - GNUSTEP_LOCAL_ROOT/Applications/ApplicationName.app/ext
104 * - /usr/local/GNUstep/Applications/ApplicationName.app/ext
105 * - GNUSTEP_SYSTEM_ROOT/Applications/ApplicationName.app/ext
106 * - /usr/GNUstep/Applications/ApplicationName.app/ext
109 if (WMApplication
.resourcePath
) {
110 path
= checkFile(WMApplication
.resourcePath
, NULL
, ext
, resource
);
115 if (WMApplication
.argv
[0]) {
116 tmp
= wstrdup(WMApplication
.argv
[0]);
118 while (i
> 0 && tmp
[i
] != '/')
122 path
= checkFile(tmp
, NULL
, ext
, resource
);
131 appdir
= wmalloc(strlen(WMApplication
.applicationName
) + 20);
132 sprintf(appdir
, "Applications/%s.app", WMApplication
.applicationName
);
134 if (getenv("GNUSTEP_USER_ROOT")) {
135 path
= checkFile(getenv("GNUSTEP_USER_ROOT"), appdir
, ext
, resource
);
142 tmp
= wusergnusteppath();
144 path
= checkFile(tmp
, appdir
, ext
, resource
);
151 if (getenv("GNUSTEP_LOCAL_ROOT")) {
152 path
= checkFile(getenv("GNUSTEP_LOCAL_ROOT"), appdir
, ext
, resource
);
159 path
= checkFile("/usr/local/GNUstep", appdir
, ext
, resource
);
165 if (getenv("GNUSTEP_SYSTEM_ROOT")) {
166 path
= checkFile(getenv("GNUSTEP_SYSTEM_ROOT"), appdir
, ext
, resource
);
173 path
= checkFile("/usr/GNUstep", appdir
, ext
, resource
);