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
)
70 if (!path
|| !resource
)
73 extralen
= (ext
? strlen(ext
) + 1 : 0) + (folder
? strlen(folder
) + 1 : 0) + 1;
74 slen
= strlen(path
) + strlen(resource
) + 1 + extralen
;
77 if (wstrlcpy(ret
, path
, slen
) >= slen
)
81 (wstrlcat(ret
, "/", slen
) >= slen
||
82 wstrlcat(ret
, folder
, slen
) >= slen
))
86 (wstrlcat(ret
, "/", slen
) >= slen
||
87 wstrlcat(ret
, ext
, slen
) >= slen
))
90 if (wstrlcat(ret
, "/", slen
) >= slen
||
91 wstrlcat(ret
, resource
, slen
) >= slen
)
94 if (access(ret
, F_OK
) != 0)
105 char *WMPathForResourceOfType(char *resource
, char *ext
)
107 char *path
, *tmp
, *appdir
;
111 path
= tmp
= appdir
= NULL
;
114 * Paths are searched in this order:
116 * - dirname(argv[0])/ext
117 * - GNUSTEP_USER_ROOT/Applications/ApplicationName.app/ext
118 * - ~/GNUstep/Applications/ApplicationName.app/ext
119 * - GNUSTEP_LOCAL_ROOT/Applications/ApplicationName.app/ext
120 * - /usr/local/GNUstep/Applications/ApplicationName.app/ext
121 * - GNUSTEP_SYSTEM_ROOT/Applications/ApplicationName.app/ext
122 * - /usr/GNUstep/Applications/ApplicationName.app/ext
125 if (WMApplication
.resourcePath
) {
126 path
= checkFile(WMApplication
.resourcePath
, NULL
, ext
, resource
);
131 if (WMApplication
.argv
[0]) {
132 tmp
= wstrdup(WMApplication
.argv
[0]);
134 while (i
> 0 && tmp
[i
] != '/')
138 path
= checkFile(tmp
, NULL
, ext
, resource
);
145 slen
= strlen(WMApplication
.applicationName
) + sizeof("Applications/.app");
146 appdir
= wmalloc(slen
);
147 if (snprintf(appdir
, slen
, "Applications/%s.app", WMApplication
.applicationName
) >= slen
)
150 path
= checkFile(getenv("GNUSTEP_USER_ROOT"), appdir
, ext
, resource
);
154 path
= checkFile(wusergnusteppath(), appdir
, ext
, resource
);
158 path
= checkFile(getenv("GNUSTEP_LOCAL_ROOT"), appdir
, ext
, resource
);
162 path
= checkFile("/usr/local/GNUstep", appdir
, ext
, resource
);
166 path
= checkFile(getenv("GNUSTEP_SYSTEM_ROOT"), appdir
, ext
, resource
);
170 path
= checkFile("/usr/GNUstep", appdir
, ext
, resource
); /* falls through */