~profzoom/ubuntu/quantal/wmaker/bug-1079925

« back to all changes in this revision

Viewing changes to WINGs/wapplication.c

  • Committer: Bazaar Package Importer
  • Author(s): Marcelo E. Magallon
  • Date: 2004-11-10 14:05:30 UTC
  • Revision ID: james.westby@ubuntu.com-20041110140530-qpd66b5lm38x7apk
Tags: upstream-0.91.0
ImportĀ upstreamĀ versionĀ 0.91.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
 
 
3
#include <unistd.h>
 
4
 
 
5
#include "WINGsP.h"
 
6
 
 
7
#include "wconfig.h"
 
8
 
 
9
#include "X11/Xlocale.h"
 
10
 
 
11
 
 
12
extern void W_InitNotificationCenter(void);
 
13
 
 
14
 
 
15
struct W_Application WMApplication;
 
16
 
 
17
 
 
18
char *_WINGS_progname = NULL;
 
19
 
 
20
 
 
21
 
 
22
Bool
 
23
W_ApplicationInitialized(void)
 
24
{
 
25
    return _WINGS_progname!=NULL;
 
26
}
 
27
 
 
28
 
 
29
void
 
30
WMInitializeApplication(char *applicationName, int *argc, char **argv)
 
31
{
 
32
    int i;
 
33
 
 
34
    assert(argc!=NULL);
 
35
    assert(argv!=NULL);
 
36
    assert(applicationName!=NULL);
 
37
 
 
38
    setlocale(LC_ALL, "");
 
39
 
 
40
#ifdef I18N
 
41
    if (getenv("NLSPATH"))
 
42
        bindtextdomain("WINGs", getenv("NLSPATH"));
 
43
    else
 
44
        bindtextdomain("WINGs", LOCALEDIR);
 
45
    bind_textdomain_codeset("WINGs", "UTF-8");
 
46
#endif
 
47
 
 
48
    _WINGS_progname = argv[0];
 
49
 
 
50
    WMApplication.applicationName = wstrdup(applicationName);
 
51
    WMApplication.argc = *argc;
 
52
 
 
53
    WMApplication.argv = wmalloc((*argc+1)*sizeof(char*));
 
54
    for (i=0; i<*argc; i++) {
 
55
        WMApplication.argv[i] = wstrdup(argv[i]);
 
56
    }
 
57
    WMApplication.argv[i] = NULL;
 
58
 
 
59
    /* initialize notification center */
 
60
    W_InitNotificationCenter();
 
61
}
 
62
 
 
63
 
 
64
void
 
65
WMSetResourcePath(char *path)
 
66
{
 
67
    if (WMApplication.resourcePath)
 
68
        wfree(WMApplication.resourcePath);
 
69
    WMApplication.resourcePath = wstrdup(path);
 
70
}
 
71
 
 
72
 
 
73
char*
 
74
WMGetApplicationName()
 
75
{
 
76
    return WMApplication.applicationName;
 
77
}
 
78
 
 
79
 
 
80
static char*
 
81
checkFile(char *path, char *folder, char *ext, char *resource)
 
82
{
 
83
    char *ret;
 
84
    int extralen;
 
85
 
 
86
    extralen = (ext ? strlen(ext) : 0) + (folder ? strlen(folder) : 0) + 4;
 
87
    ret = wmalloc(strlen(path)+strlen(resource)+extralen+8);
 
88
    strcpy(ret, path);
 
89
    if (folder) {
 
90
        strcat(ret, "/");
 
91
        strcat(ret, folder);
 
92
    }
 
93
    if (ext) {
 
94
        strcat(ret, "/");
 
95
        strcat(ret, ext);
 
96
    }
 
97
    strcat(ret, "/");
 
98
    strcat(ret, resource);
 
99
 
 
100
    if (access(ret, F_OK)!=0) {
 
101
        wfree(ret);
 
102
        ret = NULL;
 
103
    }
 
104
 
 
105
    return ret;
 
106
}
 
107
 
 
108
 
 
109
char*
 
110
WMPathForResourceOfType(char *resource, char *ext)
 
111
{
 
112
    char *path = NULL;
 
113
    char *tmp, *appdir;
 
114
    int i;
 
115
 
 
116
    /*
 
117
     * Paths are searched in this order:
 
118
     * - resourcePath/ext
 
119
     * - argv[0]/ext
 
120
     * - GNUSTEP_USER_ROOT/Applications/ApplicationName.app/ext
 
121
     * - ~/GNUstep/Applications/ApplicationName.app/ext
 
122
     * - GNUSTEP_LOCAL_ROOT/Applications/ApplicationName.app/ext
 
123
     * - /usr/local/GNUstep/Applications/ApplicationName.app/ext
 
124
     * - GNUSTEP_SYSTEM_ROOT/Applications/ApplicationName.app/ext
 
125
     * - /usr/GNUstep/Applications/ApplicationName.app/ext
 
126
     */
 
127
 
 
128
    if (WMApplication.resourcePath) {
 
129
        path = checkFile(WMApplication.resourcePath, NULL, ext, resource);
 
130
        if (path)
 
131
            return path;
 
132
    }
 
133
 
 
134
    if (WMApplication.argv[0]) {
 
135
        tmp = wstrdup(WMApplication.argv[0]);
 
136
        i = strlen(tmp);
 
137
        while (i > 0 && tmp[i]!='/')
 
138
            i--;
 
139
        tmp[i] = 0;
 
140
        if (i>0) {
 
141
            path = checkFile(tmp, NULL, ext, resource);
 
142
        } else {
 
143
            path = NULL;
 
144
        }
 
145
        wfree(tmp);
 
146
        if (path)
 
147
            return path;
 
148
    }
 
149
 
 
150
    appdir = wmalloc(strlen(WMApplication.applicationName)+20);
 
151
    sprintf(appdir, "Applications/%s.app", WMApplication.applicationName);
 
152
 
 
153
    if (getenv("GNUSTEP_USER_ROOT")) {
 
154
        path = checkFile(getenv("GNUSTEP_USER_ROOT"), appdir, ext, resource);
 
155
        if (path) {
 
156
            wfree(appdir);
 
157
            return path;
 
158
        }
 
159
    }
 
160
 
 
161
    tmp = wusergnusteppath();
 
162
    if (tmp) {
 
163
        path = checkFile(tmp, appdir, ext, resource);
 
164
        if (path) {
 
165
            wfree(appdir);
 
166
            return path;
 
167
        }
 
168
    }
 
169
 
 
170
    if (getenv("GNUSTEP_LOCAL_ROOT")) {
 
171
        path = checkFile(getenv("GNUSTEP_LOCAL_ROOT"), appdir, ext, resource);
 
172
        if (path) {
 
173
            wfree(appdir);
 
174
            return path;
 
175
        }
 
176
    }
 
177
 
 
178
    path = checkFile("/usr/local/GNUstep", appdir, ext, resource);
 
179
    if (path) {
 
180
        wfree(appdir);
 
181
        return path;
 
182
    }
 
183
 
 
184
 
 
185
    if (getenv("GNUSTEP_SYSTEM_ROOT")) {
 
186
        path = checkFile(getenv("GNUSTEP_SYSTEM_ROOT"), appdir, ext, resource);
 
187
        if (path) {
 
188
            wfree(appdir);
 
189
            return path;
 
190
        }
 
191
    }
 
192
 
 
193
    path = checkFile("/usr/GNUstep", appdir, ext, resource);
 
194
    if (path) {
 
195
        wfree(appdir);
 
196
        return path;
 
197
    }
 
198
 
 
199
    return NULL;
 
200
}
 
201
 
 
202