8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
*
* See the file "license.terms" for information on usage and redistribution
* of this file, and for a DISCLAIMER OF ALL WARRANTIES.
*/
#include "tclInt.h"
#include "tclFileSystem.h"
static int NativeMatchType(Tcl_Interp *interp,
const char* nativeEntry, const char* nativeName,
Tcl_GlobTypeData *types);
/*
*---------------------------------------------------------------------------
*
* TclpFindExecutable --
*
* This function computes the absolute path name of the current
* application, given its argv[0] value. For Cygwin, argv[0] is
* ignored and the path is determined the same as under win32.
*
* Results:
* None.
*
* Side effects:
* The computed path name is stored as a ProcessGlobalValue.
*
*---------------------------------------------------------------------------
*/
#ifdef __CYGWIN__
void
TclpFindExecutable(
TCL_UNUSED(const char *) /*argv0*/)
{
size_t length;
wchar_t buf[PATH_MAX] = L"";
char name[PATH_MAX * 3 + 1];
GetModuleFileNameW(NULL, buf, PATH_MAX);
cygwin_conv_path(3, buf, name, sizeof(name));
length = strlen(name);
if ((length > 4) && !strcasecmp(name + length - 4, ".exe")) {
/* Strip '.exe' part. */
length -= 4;
}
TclSetObjNameOfExecutable(
Tcl_NewStringObj(name, length), NULL);
}
#else
void
TclpFindExecutable(
const char *argv0) /* The value of the application's argv[0]
* (native). */
{
|
>
>
>
>
>
>
|
<
|
|
>
>
>
>
>
>
|
>
|
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
*
* See the file "license.terms" for information on usage and redistribution
* of this file, and for a DISCLAIMER OF ALL WARRANTIES.
*/
#include "tclInt.h"
#include "tclFileSystem.h"
#if !defined(NO_DLFCN_H)
#include <dlfcn.h>
#endif
static int NativeMatchType(Tcl_Interp *interp,
const char* nativeEntry, const char* nativeName,
Tcl_GlobTypeData *types);
/*
*---------------------------------------------------------------------------
*
* TclpFindExecutable --
*
* This function computes the absolute path name of the current
* application, given its argv[0] value. For Cygwin, argv[0] is
* ignored and the path is determined the same as under win32.
*
* In the case of shared Tcl library, the absolute path name of the
* Tcl library is also determined.
*
* Results:
* None.
*
* Side effects:
* The computed path name(s) are stored as ProcessGlobalValue entries.
*
*---------------------------------------------------------------------------
*/
#ifdef __CYGWIN__
void
TclpFindExecutable(
TCL_UNUSED(const char *) /*argv0*/)
{
size_t length;
wchar_t buf[PATH_MAX] = L"";
char name[PATH_MAX * TCL_UTF_MAX + 1];
GetModuleFileNameW(NULL, buf, PATH_MAX);
cygwin_conv_path(3, buf, name, sizeof(name));
length = strlen(name);
if ((length > 4) && !strcasecmp(name + length - 4, ".exe")) {
/* Strip '.exe' part. */
length -= 4;
}
TclSetObjNameOfExecutable(Tcl_NewStringObj(name, length), NULL);
#if !defined(STATIC_BUILD)
HMODULE hModule = (HMODULE)TclWinGetTclInstance();
if (GetModuleFileNameW(hModule, buf, PATH_MAX) < PATH_MAX) {
cygwin_conv_path(3, buf, name, sizeof(name));
}
TclSetObjNameOfShlib(Tcl_NewStringObj(name, TCL_AUTO_LENGTH), NULL);
#endif
}
#else
void
TclpFindExecutable(
const char *argv0) /* The value of the application's argv[0]
* (native). */
{
|
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
|
p = "./";
} else {
p++;
}
}
TclNewObj(obj);
TclSetObjNameOfExecutable(obj, NULL);
goto done;
/*
* If the name starts with "/" then just store it
*/
gotName:
#ifdef DJGPP
if (name[1] == ':')
#else
if (name[0] == '/')
#endif
{
Tcl_ExternalToUtfDStringEx(NULL, NULL, name, TCL_INDEX_NONE,
TCL_ENCODING_PROFILE_TCL8, &utfName, NULL);
TclSetObjNameOfExecutable(Tcl_DStringToObj(&utfName), NULL);
goto done;
}
if (TclpGetCwd(NULL, &cwd) == NULL) {
TclNewObj(obj);
TclSetObjNameOfExecutable(obj, NULL);
goto done;
}
/*
* The name is relative to the current working directory. First strip off
* a leading "./", if any, then add the full path name of the current
* working directory.
*/
|
|
|
|
|
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
|
p = "./";
} else {
p++;
}
}
TclNewObj(obj);
TclSetObjNameOfExecutable(obj, NULL);
goto getShlibName;
/*
* If the name starts with "/" then just store it
*/
gotName:
#ifdef DJGPP
if (name[1] == ':')
#else
if (name[0] == '/')
#endif
{
Tcl_ExternalToUtfDStringEx(NULL, NULL, name, TCL_INDEX_NONE,
TCL_ENCODING_PROFILE_TCL8, &utfName, NULL);
TclSetObjNameOfExecutable(Tcl_DStringToObj(&utfName), NULL);
goto getShlibName;
}
if (TclpGetCwd(NULL, &cwd) == NULL) {
TclNewObj(obj);
TclSetObjNameOfExecutable(obj, NULL);
goto getShlibName;
}
/*
* The name is relative to the current working directory. First strip off
* a leading "./", if any, then add the full path name of the current
* working directory.
*/
|
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
|
TclDStringAppendDString(&buffer, &nameString);
Tcl_DStringFree(&nameString);
Tcl_ExternalToUtfDStringEx(NULL, NULL, Tcl_DStringValue(&buffer), TCL_INDEX_NONE,
TCL_ENCODING_PROFILE_TCL8, &utfName, NULL);
TclSetObjNameOfExecutable(Tcl_DStringToObj(&utfName), NULL);
done:
Tcl_DStringFree(&buffer);
}
#endif
/*
*----------------------------------------------------------------------
*
|
>
>
>
>
>
>
>
>
>
>
>
|
|
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
|
TclDStringAppendDString(&buffer, &nameString);
Tcl_DStringFree(&nameString);
Tcl_ExternalToUtfDStringEx(NULL, NULL, Tcl_DStringValue(&buffer), TCL_INDEX_NONE,
TCL_ENCODING_PROFILE_TCL8, &utfName, NULL);
TclSetObjNameOfExecutable(Tcl_DStringToObj(&utfName), NULL);
getShlibName:
#if !defined(STATIC_BUILD)
name = CFG_RUNTIME_LIBDIR "/" CFG_RUNTIME_DLLFILE;
# if !defined(NO_DLFCN_H)
Dl_info dlinfo;
if (dladdr((const void *)TclpFindExecutable, &dlinfo) && dlinfo.dli_fname) {
name = dlinfo.dli_fname;
}
# endif
TclSetObjNameOfShlib(Tcl_NewStringObj(name, TCL_AUTO_LENGTH), NULL);
#endif /* STATIC_BUILD */
Tcl_DStringFree(&buffer);
}
#endif
/*
*----------------------------------------------------------------------
*
|