46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
-
+
-
|
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(
TclSetObjNameOfExecutable(Tcl_NewStringObj(name, length), NULL);
Tcl_NewStringObj(name, length), NULL);
}
#else
void
TclpFindExecutable(
const char *argv0) /* The value of the application's argv[0]
* (native). */
{
|
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
|
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
|
-
+
|
TclDStringClear(&buffer);
if (p != name) {
Tcl_DStringAppend(&buffer, name, p - name);
if (p[-1] != '/') {
TclDStringAppendLiteral(&buffer, "/");
}
}
name = Tcl_DStringAppend(&buffer, argv0, TCL_INDEX_NONE);
name = Tcl_DStringAppend(&buffer, argv0, TCL_AUTO_LENGTH);
/*
* INTL: The following calls to access() and stat() should not be
* converted to Tclp routines because they need to operate on native
* strings directly.
*/
|
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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
|
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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
|
-
+
-
-
-
+
-
+
-
+
-
-
|
if (name[1] == ':')
#else
if (name[0] == '/')
#endif
{
encoding = Tcl_GetEncoding(NULL, NULL);
Tcl_ExternalToUtfDStringEx(NULL, encoding, name, TCL_INDEX_NONE, TCL_ENCODING_PROFILE_TCL8, &utfName, NULL);
TclSetObjNameOfExecutable(
TclSetObjNameOfExecutable(Tcl_DStringToObj(&utfName), encoding);
Tcl_NewStringObj(Tcl_DStringValue(&utfName), TCL_INDEX_NONE), encoding);
Tcl_DStringFree(&utfName);
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.
*/
if ((name[0] == '.') && (name[1] == '/')) {
name += 2;
}
Tcl_DStringInit(&nameString);
Tcl_DStringAppend(&nameString, name, TCL_INDEX_NONE);
Tcl_DStringAppend(&nameString, name, TCL_AUTO_LENGTH);
Tcl_DStringFree(&buffer);
Tcl_UtfToExternalDStringEx(NULL, NULL, Tcl_DStringValue(&cwd),
Tcl_DStringLength(&cwd), TCL_ENCODING_PROFILE_TCL8, &buffer, NULL);
if (Tcl_DStringValue(&cwd)[Tcl_DStringLength(&cwd) -1] != '/') {
if (Tcl_DStringValue(&cwd)[Tcl_DStringLength(&cwd) - 1] != '/') {
TclDStringAppendLiteral(&buffer, "/");
}
Tcl_DStringFree(&cwd);
TclDStringAppendDString(&buffer, &nameString);
Tcl_DStringFree(&nameString);
encoding = Tcl_GetEncoding(NULL, NULL);
Tcl_ExternalToUtfDStringEx(NULL, encoding, Tcl_DStringValue(&buffer), TCL_INDEX_NONE,
TCL_ENCODING_PROFILE_TCL8, &utfName, NULL);
TclSetObjNameOfExecutable(
TclSetObjNameOfExecutable(Tcl_DStringToObj(&utfName), encoding);
Tcl_NewStringObj(Tcl_DStringValue(&utfName), TCL_INDEX_NONE), encoding);
Tcl_DStringFree(&utfName);
done:
Tcl_DStringFree(&buffer);
}
#endif
/*
|
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
|
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
|
-
+
|
}
utfname = Tcl_DStringValue(&utfDs);
if (Tcl_StringCaseMatch(utfname, pattern, 0)) {
int typeOk = 1;
if (types != NULL) {
Tcl_DStringSetLength(&ds, nativeDirLen);
native = Tcl_DStringAppend(&ds, entryPtr->d_name, TCL_INDEX_NONE);
native = Tcl_DStringAppend(&ds, entryPtr->d_name, TCL_AUTO_LENGTH);
matchResult = NativeMatchType(interp, native,
entryPtr->d_name, types);
typeOk = (matchResult == 1);
}
if (typeOk) {
Tcl_ListObjAppendElement(interp, resultPtr,
TclNewFSPathObj(pathPtr, utfname,
|