Tell gettext that we want to have the messages in the UTF-8 encoding, to
[wmaker-crm.git] / WINGs / wapplication.c
blob2c53f3a14812b6b5d6a03cbadf3b4dc98ead76ae
3 #include <unistd.h>
5 #include "WINGsP.h"
7 #include "wconfig.h"
9 #include "X11/Xlocale.h"
12 extern void W_InitNotificationCenter(void);
15 struct W_Application WMApplication;
18 char *_WINGS_progname = NULL;
22 Bool
23 W_ApplicationInitialized(void)
25 return _WINGS_progname!=NULL;
29 void
30 WMInitializeApplication(char *applicationName, int *argc, char **argv)
32 int i;
34 assert(argc!=NULL);
35 assert(argv!=NULL);
36 assert(applicationName!=NULL);
38 /* // TODO: check if to move inside #ifdef I18N */
39 setlocale(LC_ALL, "");
41 #ifdef I18N
42 if (getenv("NLSPATH"))
43 bindtextdomain("WINGs", getenv("NLSPATH"));
44 else
45 bindtextdomain("WINGs", LOCALEDIR);
46 bind_textdomain_codeset("WINGs", "UTF-8");
47 #endif
49 _WINGS_progname = argv[0];
51 WMApplication.applicationName = wstrdup(applicationName);
52 WMApplication.argc = *argc;
54 WMApplication.argv = wmalloc((*argc+1)*sizeof(char*));
55 for (i=0; i<*argc; i++) {
56 WMApplication.argv[i] = wstrdup(argv[i]);
58 WMApplication.argv[i] = NULL;
60 /* initialize notification center */
61 W_InitNotificationCenter();
65 void
66 WMSetResourcePath(char *path)
68 if (WMApplication.resourcePath)
69 wfree(WMApplication.resourcePath);
70 WMApplication.resourcePath = wstrdup(path);
74 char*
75 WMGetApplicationName()
77 return WMApplication.applicationName;
81 static char*
82 checkFile(char *path, char *folder, char *ext, char *resource)
84 char *ret;
85 int extralen;
87 extralen = (ext ? strlen(ext) : 0) + (folder ? strlen(folder) : 0) + 4;
88 ret = wmalloc(strlen(path)+strlen(resource)+extralen+8);
89 strcpy(ret, path);
90 if (folder) {
91 strcat(ret, "/");
92 strcat(ret, folder);
94 if (ext) {
95 strcat(ret, "/");
96 strcat(ret, ext);
98 strcat(ret, "/");
99 strcat(ret, resource);
101 if (access(ret, F_OK)!=0) {
102 wfree(ret);
103 ret = NULL;
106 return ret;
110 char*
111 WMPathForResourceOfType(char *resource, char *ext)
113 char *path = NULL;
114 char *tmp, *appdir;
115 int i;
118 * Paths are searched in this order:
119 * - resourcePath/ext
120 * - argv[0]/ext
121 * - GNUSTEP_USER_ROOT/Apps/ApplicationName.app/ext
122 * - ~/GNUstep/Apps/ApplicationName.app/ext
123 * - GNUSTEP_LOCAL_ROOT/Apps/ApplicationName.app/ext
124 * - /usr/local/GNUstep/Apps/ApplicationName.app/ext
125 * - GNUSTEP_SYSTEM_ROOT/Apps/ApplicationName.app/ext
126 * - /usr/GNUstep/Apps/ApplicationName.app/ext
129 if (WMApplication.resourcePath) {
130 path = checkFile(WMApplication.resourcePath, NULL, ext, resource);
131 if (path)
132 return path;
135 if (WMApplication.argv[0]) {
136 tmp = wstrdup(WMApplication.argv[0]);
137 i = strlen(tmp);
138 while (i > 0 && tmp[i]!='/')
139 i--;
140 tmp[i] = 0;
141 if (i>0) {
142 path = checkFile(tmp, NULL, ext, resource);
143 } else {
144 path = NULL;
146 wfree(tmp);
147 if (path)
148 return path;
151 appdir = wmalloc(strlen(WMApplication.applicationName)+10);
152 sprintf(appdir, "Apps/%s.app", WMApplication.applicationName);
154 if (getenv("GNUSTEP_USER_ROOT")) {
155 path = checkFile(getenv("GNUSTEP_USER_ROOT"), appdir, ext, resource);
156 if (path) {
157 wfree(appdir);
158 return path;
162 tmp = wusergnusteppath();
163 if (tmp) {
164 path = checkFile(tmp, appdir, ext, resource);
165 if (path) {
166 wfree(appdir);
167 return path;
171 if (getenv("GNUSTEP_LOCAL_ROOT")) {
172 path = checkFile(getenv("GNUSTEP_LOCAL_ROOT"), appdir, ext, resource);
173 if (path) {
174 wfree(appdir);
175 return path;
179 path = checkFile("/usr/local/GNUstep", appdir, ext, resource);
180 if (path) {
181 wfree(appdir);
182 return path;
186 if (getenv("GNUSTEP_SYSTEM_ROOT")) {
187 path = checkFile(getenv("GNUSTEP_SYSTEM_ROOT"), appdir, ext, resource);
188 if (path) {
189 wfree(appdir);
190 return path;
194 path = checkFile("/usr/GNUstep", appdir, ext, resource);
195 if (path) {
196 wfree(appdir);
197 return path;
200 return NULL;