Check-in [d80c88cee0]
Overview
Comment:Added debugging system and ability to free absolute path
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: d80c88cee07554ab2de27f3ec8306bd8fbe938b413ea6925f61635a77d3729c7
User & Date: rkeene on 2019-09-16 19:45:18
Other Links: manifest | tags
Context
2019-09-16
19:48
Updated ignores check-in: 6e4375539e user: rkeene tags: trunk
19:45
Added debugging system and ability to free absolute path check-in: d80c88cee0 user: rkeene tags: trunk
19:31
Mark more things as requiring Tcl 8.7 check-in: e4bde431db user: rkeene tags: trunk
Changes

Modified Makefile from [de04821f8d] to [f9aa6c59be].

1
2
3
4
5
6
7
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
CPPFLAGS := -I. -DUSE_TCL_STUBS=1 -DXVFS_MODE_FLEXIBLE
CFLAGS   := -fPIC -g3 -ggdb3 -Wall
LDFLAGS  :=
LIBS     := -ltclstub8.6
TCLSH    := tclsh

all: example.so

example.c: $(shell find example -type f) $(shell find lib -type f) xvfs.c.rvt xvfs-create Makefile
	./xvfs-create --directory example --name example > example.c.new
	mv example.c.new example.c

example.o: example.c xvfs-core.h xvfs-core.c Makefile
	$(CC) $(CPPFLAGS) $(CFLAGS) -o example.o -c example.c

example.so: example.o Makefile
	$(CC) $(CFLAGS) $(LDFLAGS) -shared -o example.so example.o $(LIBS)









test: example.so
	rm -f __test__.tcl
	echo 'if {[catch { load ./example.so Xvfs_example; source //xvfs:/example/main.tcl }]} { puts stderr $$::errorInfo; exit 1 }; exit 0' > __test__.tcl
	$(GDB) $(TCLSH) __test__.tcl
	rm -f __test__.tcl

clean:

	rm -f example.c example.c.new
	rm -f example.so example.o
	rm -f __test__.tcl

distclean: clean

.PHONY: all clean distclean test
|

















>
>
>
>
>
>
>
>



|



>







1
2
3
4
5
6
7
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
CPPFLAGS := -I. -DUSE_TCL_STUBS=1 -DXVFS_MODE_FLEXIBLE -DXVFS_DEBUG
CFLAGS   := -fPIC -g3 -ggdb3 -Wall
LDFLAGS  :=
LIBS     := -ltclstub8.6
TCLSH    := tclsh

all: example.so

example.c: $(shell find example -type f) $(shell find lib -type f) xvfs.c.rvt xvfs-create Makefile
	./xvfs-create --directory example --name example > example.c.new
	mv example.c.new example.c

example.o: example.c xvfs-core.h xvfs-core.c Makefile
	$(CC) $(CPPFLAGS) $(CFLAGS) -o example.o -c example.c

example.so: example.o Makefile
	$(CC) $(CFLAGS) $(LDFLAGS) -shared -o example.so example.o $(LIBS)

# xvfs-create-standalone is a standalone (i.e., no external dependencies
# like lib/minirivet, xvfs-core.c, etc) version of "xvfs-create"
xvfs-create-standalone: $(shell find lib -type f) xvfs-create xvfs-core.c xvfs-core.h xvfs.c.rvt
	rm -f xvfs-create-standalone.new xvfs-create-standalone
	./xvfs-create --dump-tcl --remove-debug > xvfs-create-standalone.new
	chmod +x xvfs-create-standalone.new
	mv xvfs-create-standalone.new xvfs-create-standalone

test: example.so
	rm -f __test__.tcl
	echo 'if {[catch { load ./example.so Xvfs_example; source //xvfs:/example/main.tcl }]} { puts stderr $$::errorInfo; exit 1 }; exit 0' > __test__.tcl
	$(GDB) $(TCLSH) __test__.tcl $(TCL_TEST_ARGS)
	rm -f __test__.tcl

clean:
	rm -f xvfs-create-standalone.new xvfs-create-standalone
	rm -f example.c example.c.new
	rm -f example.so example.o
	rm -f __test__.tcl

distclean: clean

.PHONY: all clean distclean test

Modified xvfs-core.c from [7f58a650f6] to [bf348346aa].

1
2
3
4
5
6
7














8
9
10
11
12
13
14
#include <xvfs-core.h>
#include <string.h>
#include <sys/stat.h>
#include <errno.h>
#include <fcntl.h>
#include <tcl.h>















#if defined(XVFS_MODE_FLEXIBLE) || defined(XVFS_MODE_SERVER)
#define XVFS_INTERNAL_SERVER_MAGIC "\xD4\xF3\x05\x96\x25\xCF\xAF\xFE"
#define XVFS_INTERNAL_SERVER_MAGIC_LEN 8

struct xvfs_tclfs_server_info {
	char magic[XVFS_INTERNAL_SERVER_MAGIC_LEN];
	int (*registerProc)(Tcl_Interp *interp, struct Xvfs_FSInfo *fsInfo);







>
>
>
>
>
>
>
>
>
>
>
>
>
>







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include <xvfs-core.h>
#include <string.h>
#include <sys/stat.h>
#include <errno.h>
#include <fcntl.h>
#include <tcl.h>

#ifdef XVFS_DEBUG
#include <stdio.h> /* Needed for XVFS_DEBUG_PRINTF */
static int xvfs_debug_depth = 0;
#define XVFS_DEBUG_PRINTF(fmt, ...) fprintf(stderr, "[XVFS:DEBUG:%-30s:%4i] %s" fmt "\n", __func__, __LINE__, "                                                                                " + (80 - (xvfs_debug_depth * 4)), __VA_ARGS__)
#define XVFS_DEBUG_PUTS(str) XVFS_DEBUG_PRINTF("%s", str);
#define XVFS_DEBUG_ENTER { xvfs_debug_depth++; XVFS_DEBUG_PUTS("Entered"); }
#define XVFS_DEBUG_LEAVE { XVFS_DEBUG_PUTS("Returning"); xvfs_debug_depth--; }
#else /* XVFS_DEBUG */
#define XVFS_DEBUG_PRINTF(fmt, ...) /**/
#define XVFS_DEBUG_PUTS(str) /**/
#define XVFS_DEBUG_ENTER /**/
#define XVFS_DEBUG_LEAVE /**/
#endif /* XVFS_DEBUG */

#if defined(XVFS_MODE_FLEXIBLE) || defined(XVFS_MODE_SERVER)
#define XVFS_INTERNAL_SERVER_MAGIC "\xD4\xF3\x05\x96\x25\xCF\xAF\xFE"
#define XVFS_INTERNAL_SERVER_MAGIC_LEN 8

struct xvfs_tclfs_server_info {
	char magic[XVFS_INTERNAL_SERVER_MAGIC_LEN];
	int (*registerProc)(Tcl_Interp *interp, struct Xvfs_FSInfo *fsInfo);
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
75
76
77



78
79
80
81
82
83
84
	struct Xvfs_FSInfo *fsInfo;
	Tcl_Obj            *mountpoint;
};

/*
 * Internal Core Utilities
 */
static const char *xvfs_relativePath(Tcl_Obj *path, struct xvfs_tclfs_instance_info *info) {
	Tcl_Obj *currentDirectory;
	const char *pathStr, *rootStr;
	const char *pathFinal;
	int pathLen, rootLen;


	rootStr = Tcl_GetStringFromObj(info->mountpoint, &rootLen);
	pathStr = Tcl_GetStringFromObj(path, &pathLen);

	if (pathStr[0] != '/') {
		currentDirectory = Tcl_FSGetCwd(NULL);
		Tcl_IncrRefCount(currentDirectory);

		/* XXX:TODO: Free this */
		path = Tcl_ObjPrintf("%s/%s", Tcl_GetString(currentDirectory), pathStr);
		Tcl_IncrRefCount(path);
		Tcl_DecrRefCount(currentDirectory);


















		pathStr = Tcl_GetStringFromObj(path, &pathLen);
	}


	if (pathLen < rootLen) {



		return(NULL);
	}

	if (memcmp(pathStr, rootStr, rootLen) != 0) {



		return(NULL);
	}

	if (pathLen == rootLen) {



		return("");
	}

	/* XXX:TODO: Should this use the native OS path separator ? */
	if (pathStr[rootLen] != '/') {



		return(NULL);
	}

	pathFinal = pathStr + rootLen + 1;
	pathLen  -= rootLen + 1;

	if (pathLen == 1 && memcmp(pathFinal, ".", 1) == 0) {



		return("");
	}

	while (pathLen >= 2 && memcmp(pathFinal, "./", 2) == 0) {
		pathFinal += 2;
		pathLen   -= 2;
	}




	return(pathFinal);
}

static const char *xvfs_perror(int xvfs_error) {
	if (xvfs_error >= 0) {
		return("Not an error");
	}







|

|
|
<
>

<
|
>




<



>
>
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
|
>


>
>
>




>
>
>




>
>
>





>
>
>







>
>
>








>
>
>







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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
	struct Xvfs_FSInfo *fsInfo;
	Tcl_Obj            *mountpoint;
};

/*
 * Internal Core Utilities
 */
static Tcl_Obj *xvfs_absolutePath(Tcl_Obj *path) {
	Tcl_Obj *currentDirectory;
	const char *pathStr;


	XVFS_DEBUG_ENTER;


	pathStr = Tcl_GetString(path);

	if (pathStr[0] != '/') {
		currentDirectory = Tcl_FSGetCwd(NULL);
		Tcl_IncrRefCount(currentDirectory);


		path = Tcl_ObjPrintf("%s/%s", Tcl_GetString(currentDirectory), pathStr);
		Tcl_IncrRefCount(path);
		Tcl_DecrRefCount(currentDirectory);
	} else {
		Tcl_IncrRefCount(path);
	}

	XVFS_DEBUG_PRINTF("Converted path \"%s\" to absolute path: \"%s\"", pathStr, Tcl_GetString(path));

	XVFS_DEBUG_LEAVE;
	return(path);
}

static const char *xvfs_relativePath(Tcl_Obj *path, struct xvfs_tclfs_instance_info *info) {
	const char *pathStr, *rootStr;
	const char *pathFinal;
	int pathLen, rootLen;

	XVFS_DEBUG_ENTER;

	rootStr = Tcl_GetStringFromObj(info->mountpoint, &rootLen);
	pathStr = Tcl_GetStringFromObj(path, &pathLen);

	XVFS_DEBUG_PRINTF("Finding relative path of \"%s\" from \"%s\" ...", pathStr, rootStr);

	if (pathLen < rootLen) {
		XVFS_DEBUG_PUTS("... none possible (length)");

		XVFS_DEBUG_LEAVE;
		return(NULL);
	}

	if (memcmp(pathStr, rootStr, rootLen) != 0) {
		XVFS_DEBUG_PUTS("... none possible (prefix differs)");

		XVFS_DEBUG_LEAVE;
		return(NULL);
	}

	if (pathLen == rootLen) {
		XVFS_DEBUG_PUTS("... short circuit: \"\"");

		XVFS_DEBUG_LEAVE;
		return("");
	}

	/* XXX:TODO: Should this use the native OS path separator ? */
	if (pathStr[rootLen] != '/') {
		XVFS_DEBUG_PUTS("... none possible (no seperator)");

		XVFS_DEBUG_LEAVE;
		return(NULL);
	}

	pathFinal = pathStr + rootLen + 1;
	pathLen  -= rootLen + 1;

	if (pathLen == 1 && memcmp(pathFinal, ".", 1) == 0) {
		XVFS_DEBUG_PUTS("... short circuit: \".\" -> \"\"");

		XVFS_DEBUG_LEAVE;
		return("");
	}

	while (pathLen >= 2 && memcmp(pathFinal, "./", 2) == 0) {
		pathFinal += 2;
		pathLen   -= 2;
	}

	XVFS_DEBUG_PRINTF("... relative path: \"%s\"", pathFinal);

	XVFS_DEBUG_LEAVE;
	return(pathFinal);
}

static const char *xvfs_perror(int xvfs_error) {
	if (xvfs_error >= 0) {
		return("Not an error");
	}
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
174
175
176
177
178
179
180


181
182
183

184
185
186
187
188



189
190
191
192
193
194
195
static Tcl_Channel xvfs_tclfs_openChannel(Tcl_Obj *path, struct xvfs_tclfs_instance_info *instanceInfo) {
	struct xvfs_tclfs_channel_id *channelInstanceData;
	Tcl_Channel channel;
	Tcl_StatBuf fileInfo;
	Tcl_Obj *channelName;
	int statRet;




	statRet = instanceInfo->fsInfo->getStatProc(Tcl_GetString(path), &fileInfo);
	if (statRet < 0) {



		return(NULL);
	}

	channelInstanceData = (struct xvfs_tclfs_channel_id *) Tcl_Alloc(sizeof(*channelInstanceData));
	channelInstanceData->currentOffset = 0;
	channelInstanceData->eofMarked = 0;
	channelInstanceData->queuedEvents = 0;
	channelInstanceData->closed = 0;
	channelInstanceData->channel = NULL;

	channelName = Tcl_ObjPrintf("xvfs0x%llx", (unsigned long long) channelInstanceData);
	if (!channelName) {


		Tcl_Free((char *) channelInstanceData);


		return(NULL);
	}
	Tcl_IncrRefCount(channelName);

	channelInstanceData->fsInstanceInfo = instanceInfo;
	channelInstanceData->fileSize = fileInfo.st_size;
	channelInstanceData->path = path;
	Tcl_IncrRefCount(path);

	channel = Tcl_CreateChannel(&xvfs_tclfs_channelType, Tcl_GetString(channelName), channelInstanceData, TCL_READABLE);
	Tcl_DecrRefCount(channelName);
	if (!channel) {


		Tcl_DecrRefCount(path);
		Tcl_Free((char *) channelInstanceData);


		return(NULL);
	}

	channelInstanceData->channel = channel;




	return(channel);
}

static int xvfs_tclfs_closeChannel(ClientData channelInstanceData_p, Tcl_Interp *interp);
static int xvfs_tclfs_closeChannelEvent(Tcl_Event *event_p, int flags) {
	struct xvfs_tclfs_channel_id *channelInstanceData;
	struct xvfs_tclfs_channel_event *event;







>
>
>


>
>
>












>
>


>












>
>



>





>
>
>







195
196
197
198
199
200
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
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
static Tcl_Channel xvfs_tclfs_openChannel(Tcl_Obj *path, struct xvfs_tclfs_instance_info *instanceInfo) {
	struct xvfs_tclfs_channel_id *channelInstanceData;
	Tcl_Channel channel;
	Tcl_StatBuf fileInfo;
	Tcl_Obj *channelName;
	int statRet;

	XVFS_DEBUG_ENTER;
	XVFS_DEBUG_PRINTF("Opening file \"%s\" ...", Tcl_GetString(path));

	statRet = instanceInfo->fsInfo->getStatProc(Tcl_GetString(path), &fileInfo);
	if (statRet < 0) {
		XVFS_DEBUG_PRINTF("... failed: %s", xvfs_perror(statRet));

		XVFS_DEBUG_LEAVE;
		return(NULL);
	}

	channelInstanceData = (struct xvfs_tclfs_channel_id *) Tcl_Alloc(sizeof(*channelInstanceData));
	channelInstanceData->currentOffset = 0;
	channelInstanceData->eofMarked = 0;
	channelInstanceData->queuedEvents = 0;
	channelInstanceData->closed = 0;
	channelInstanceData->channel = NULL;

	channelName = Tcl_ObjPrintf("xvfs0x%llx", (unsigned long long) channelInstanceData);
	if (!channelName) {
		XVFS_DEBUG_PUTS("... failed");

		Tcl_Free((char *) channelInstanceData);

		XVFS_DEBUG_LEAVE;
		return(NULL);
	}
	Tcl_IncrRefCount(channelName);

	channelInstanceData->fsInstanceInfo = instanceInfo;
	channelInstanceData->fileSize = fileInfo.st_size;
	channelInstanceData->path = path;
	Tcl_IncrRefCount(path);

	channel = Tcl_CreateChannel(&xvfs_tclfs_channelType, Tcl_GetString(channelName), channelInstanceData, TCL_READABLE);
	Tcl_DecrRefCount(channelName);
	if (!channel) {
		XVFS_DEBUG_PUTS("... failed");

		Tcl_DecrRefCount(path);
		Tcl_Free((char *) channelInstanceData);

		XVFS_DEBUG_LEAVE;
		return(NULL);
	}

	channelInstanceData->channel = channel;

	XVFS_DEBUG_PRINTF("... ok (%p)", channelInstanceData);

	XVFS_DEBUG_LEAVE;
	return(channel);
}

static int xvfs_tclfs_closeChannel(ClientData channelInstanceData_p, Tcl_Interp *interp);
static int xvfs_tclfs_closeChannelEvent(Tcl_Event *event_p, int flags) {
	struct xvfs_tclfs_channel_id *channelInstanceData;
	struct xvfs_tclfs_channel_event *event;
204
205
206
207
208
209
210



211
212
213
214
215


216
217
218
219
220
221
222
223
224

225
226
227
228
229
230



231
232
233
234
235
236
237
	return(1);
}

static int xvfs_tclfs_closeChannel(ClientData channelInstanceData_p, Tcl_Interp *interp) {
	struct xvfs_tclfs_channel_id *channelInstanceData;
	struct xvfs_tclfs_channel_event *event;




	channelInstanceData = (struct xvfs_tclfs_channel_id *) channelInstanceData_p;

	channelInstanceData->closed = 1;

	if (channelInstanceData->queuedEvents != 0) {


		event = (struct xvfs_tclfs_channel_event *) Tcl_Alloc(sizeof(*event));
		event->tcl.proc = xvfs_tclfs_closeChannelEvent;
		event->tcl.nextPtr = NULL;
		event->channelInstanceData = channelInstanceData;

		channelInstanceData->queuedEvents++;

		Tcl_QueueEvent((Tcl_Event *) event, TCL_QUEUE_TAIL);


		return(0);
	}

	Tcl_DecrRefCount(channelInstanceData->path);
	Tcl_Free((char *) channelInstanceData);




	return(0);
}

static int xvfs_tclfs_readChannel(ClientData channelInstanceData_p, char *buf, int bufSize, int *errorCodePtr) {
	struct xvfs_tclfs_channel_id *channelInstanceData;
	const unsigned char *data;
	Tcl_WideInt offset, length;







>
>
>





>
>









>






>
>
>







268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
	return(1);
}

static int xvfs_tclfs_closeChannel(ClientData channelInstanceData_p, Tcl_Interp *interp) {
	struct xvfs_tclfs_channel_id *channelInstanceData;
	struct xvfs_tclfs_channel_event *event;

	XVFS_DEBUG_ENTER;
	XVFS_DEBUG_PRINTF("Closing channel %p ...", channelInstanceData_p);

	channelInstanceData = (struct xvfs_tclfs_channel_id *) channelInstanceData_p;

	channelInstanceData->closed = 1;

	if (channelInstanceData->queuedEvents != 0) {
		XVFS_DEBUG_PUTS("... queued");

		event = (struct xvfs_tclfs_channel_event *) Tcl_Alloc(sizeof(*event));
		event->tcl.proc = xvfs_tclfs_closeChannelEvent;
		event->tcl.nextPtr = NULL;
		event->channelInstanceData = channelInstanceData;

		channelInstanceData->queuedEvents++;

		Tcl_QueueEvent((Tcl_Event *) event, TCL_QUEUE_TAIL);

		XVFS_DEBUG_LEAVE;
		return(0);
	}

	Tcl_DecrRefCount(channelInstanceData->path);
	Tcl_Free((char *) channelInstanceData);

	XVFS_DEBUG_PUTS("... ok");

	XVFS_DEBUG_LEAVE;
	return(0);
}

static int xvfs_tclfs_readChannel(ClientData channelInstanceData_p, char *buf, int bufSize, int *errorCodePtr) {
	struct xvfs_tclfs_channel_id *channelInstanceData;
	const unsigned char *data;
	Tcl_WideInt offset, length;
383
384
385
386
387
388
389

390






391


392


393

394

395

396
397
398
399
400
401
402






403
404
405
406

407


408
409



410
411
412
413
414
415
416
417

418

419
420















421
422
423
424
425





426
427
428
429
430





431
432
433
434





435
436
437
438
439
440
441
442


443
444

445

446
447



448
449
450




451









452
453
454
455
456
457








458
459
460



461
462
463
464



465
466
467
468
469



470
471
472
473
474



475
476
477
478
479
480



481
482
483
484
485



486
487
488
489
490
491



492
493
494
495
496

497
498





499
500
501
502





503
504
505

506




507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523










524
525
526




527
528
529
530

531
532
533
534
535
536




537
538
539
540

541
542
543
544
545
546
547
}

/*
 * Internal Tcl_Filesystem functions, with the appropriate instance info
 */
static int xvfs_tclfs_pathInFilesystem(Tcl_Obj *path, ClientData *dataPtr, struct xvfs_tclfs_instance_info *instanceInfo) {
	const char *relativePath;








	relativePath = xvfs_relativePath(path, instanceInfo);


	if (!relativePath) {


		return(-1);

	}



	return(TCL_OK);
}

static int xvfs_tclfs_stat(Tcl_Obj *path, Tcl_StatBuf *statBuf, struct xvfs_tclfs_instance_info *instanceInfo) {
	const char *pathStr;
	int retval;







	pathStr = xvfs_relativePath(path, instanceInfo);

	retval = instanceInfo->fsInfo->getStatProc(pathStr, statBuf);
	if (retval < 0) {

		retval = -1;


	}




	return(retval);
}

static int xvfs_tclfs_access(Tcl_Obj *path, int mode, struct xvfs_tclfs_instance_info *instanceInfo) {
	const char *pathStr;
	Tcl_StatBuf fileInfo;
	int statRetVal;


	pathStr = xvfs_relativePath(path, instanceInfo);


	if (mode & W_OK) {















		return(-1);
	}

	statRetVal = instanceInfo->fsInfo->getStatProc(pathStr, &fileInfo);
	if (statRetVal < 0) {





		return(-1);
	}

	if (mode & X_OK) {
		if (!(fileInfo.st_mode & 040000)) {





			return(-1);
		}
	}






	return(0);
}

static Tcl_Obj *xvfs_tclfs_listVolumes(struct xvfs_tclfs_instance_info *instanceInfo) {
	return(NULL);
}

static Tcl_Channel xvfs_tclfs_openFileChannel(Tcl_Interp *interp, Tcl_Obj *path, int mode, int permissions, struct xvfs_tclfs_instance_info *instanceInfo) {


	const char *pathStr;


	pathStr = xvfs_relativePath(path, instanceInfo);


	if (mode & O_WRONLY) {



		return(NULL);
	}





	return(xvfs_tclfs_openChannel(Tcl_NewStringObj(pathStr, -1), instanceInfo));









}

static int xvfs_tclfs_verifyType(Tcl_Obj *path, Tcl_GlobTypeData *types, struct xvfs_tclfs_instance_info *instanceInfo) {
	const char *pathStr;
	Tcl_StatBuf fileInfo;
	int statRetVal;









	statRetVal = xvfs_tclfs_stat(path, &fileInfo, instanceInfo);
	if (statRetVal != 0) {



		return(0);
	}

	if (!types) {



		return(1);
	}

	if (types->perm != TCL_GLOB_PERM_RONLY) {
		if (types->perm & (TCL_GLOB_PERM_W | TCL_GLOB_PERM_HIDDEN)) {



			return(0);
		}

		if ((types->perm & TCL_GLOB_PERM_X) == TCL_GLOB_PERM_X) {
			if (!(fileInfo.st_mode & 040000)) {



				return(0);
			}
		}
	}

	if (types->type & (TCL_GLOB_TYPE_BLOCK | TCL_GLOB_TYPE_CHAR | TCL_GLOB_TYPE_PIPE | TCL_GLOB_TYPE_SOCK | TCL_GLOB_TYPE_LINK)) {



		return(0);
	}

	if ((types->type & TCL_GLOB_TYPE_DIR) == TCL_GLOB_TYPE_DIR) {
		if (!(fileInfo.st_mode & 040000)) {



			return(0);
		}
	}

	if ((types->type & TCL_GLOB_TYPE_FILE) == TCL_GLOB_TYPE_FILE) {
		if (!(fileInfo.st_mode & 0100000)) {



			return(0);
		}
	}

	if ((types->type & TCL_GLOB_TYPE_MOUNT) == TCL_GLOB_TYPE_MOUNT) {

		pathStr = xvfs_relativePath(path, instanceInfo);
		if (!pathStr) {





			return(0);
		}

		if (strlen(pathStr) != 0) {





			return(0);
		}
	}






	return(1);
}

static int xvfs_tclfs_matchInDir(Tcl_Interp *interp, Tcl_Obj *resultPtr, Tcl_Obj *path, const char *pattern, Tcl_GlobTypeData *types, struct xvfs_tclfs_instance_info *instanceInfo) {
	const char *pathStr;
	const char **children, *child;
	Tcl_WideInt childrenCount, idx;
	Tcl_Obj *childObj;
	int tclRetVal;

	if (pattern == NULL) {
		if (xvfs_tclfs_verifyType(path, types, instanceInfo)) {
			return(TCL_OK);
		}

		return(TCL_ERROR);
	}











	pathStr = xvfs_relativePath(path, instanceInfo);
	if (!pathStr) {




		if (interp) {
			Tcl_SetResult(interp, (char *) xvfs_perror(XVFS_RV_ERR_ENOENT), NULL);
		}


		return(TCL_ERROR);
	}

	childrenCount = 0;
	children = instanceInfo->fsInfo->getChildrenProc(pathStr, &childrenCount);
	if (childrenCount < 0) {




		if (interp) {
			Tcl_SetResult(interp, (char *) xvfs_perror(childrenCount), NULL);
		}


		return(TCL_ERROR);
	}

	for (idx = 0; idx < childrenCount; idx++) {
		child = children[idx];

		if (!Tcl_StringMatch(child, pattern)) {







>

>
>
>
>
>
>

>
>

>
>
|
>
|
>

>
|






>
>
>
>
>
>




>

>
>


>
>
>








>
|
>


>
>
>
>
>
>
>
>
>
>
>
>
>
>
>





>
>
>
>
>





>
>
>
>
>




>
>
>
>
>



<
<
<
<

>
>


>
|
>


>
>
>



>
>
>
>
|
>
>
>
>
>
>
>
>
>






>
>
>
>
>
>
>
>



>
>
>




>
>
>





>
>
>





>
>
>






>
>
>





>
>
>






>
>
>





>


>
>
>
>
>




>
>
>
>
>


|
>
|
>
>
>
>

















>
>
>
>
>
>
>
>
>
>



>
>
>
>




>
|





>
>
>
>




>







456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568




569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
}

/*
 * Internal Tcl_Filesystem functions, with the appropriate instance info
 */
static int xvfs_tclfs_pathInFilesystem(Tcl_Obj *path, ClientData *dataPtr, struct xvfs_tclfs_instance_info *instanceInfo) {
	const char *relativePath;
	int retval;

	XVFS_DEBUG_ENTER;

	XVFS_DEBUG_PRINTF("Checking to see if path \"%s\" is in the filesystem ...", Tcl_GetString(path));

	path = xvfs_absolutePath(path);

	relativePath = xvfs_relativePath(path, instanceInfo);

	retval = TCL_OK;
	if (!relativePath) {
		retval = -1;
	}

	Tcl_DecrRefCount(path);

	XVFS_DEBUG_PRINTF("... %s", retval == -1 ? "no" : "yes");

	XVFS_DEBUG_LEAVE;
	return(retval);
}

static int xvfs_tclfs_stat(Tcl_Obj *path, Tcl_StatBuf *statBuf, struct xvfs_tclfs_instance_info *instanceInfo) {
	const char *pathStr;
	int retval;

	XVFS_DEBUG_ENTER;

	XVFS_DEBUG_PRINTF("Getting stat() on \"%s\" ...", Tcl_GetString(path));

	path = xvfs_absolutePath(path);

	pathStr = xvfs_relativePath(path, instanceInfo);

	retval = instanceInfo->fsInfo->getStatProc(pathStr, statBuf);
	if (retval < 0) {
		XVFS_DEBUG_PRINTF("... failed: %s", xvfs_perror(retval));
		retval = -1;
	} else {
		XVFS_DEBUG_PUTS("... ok");
	}

	Tcl_DecrRefCount(path);

	XVFS_DEBUG_LEAVE;
	return(retval);
}

static int xvfs_tclfs_access(Tcl_Obj *path, int mode, struct xvfs_tclfs_instance_info *instanceInfo) {
	const char *pathStr;
	Tcl_StatBuf fileInfo;
	int statRetVal;

	XVFS_DEBUG_ENTER;

	XVFS_DEBUG_PRINTF("Getting access(..., %i) on \"%s\" ...", mode, Tcl_GetString(path));

	if (mode & W_OK) {
		XVFS_DEBUG_PUTS("... no (not writable)");

		XVFS_DEBUG_LEAVE;
		return(-1);
	}

	path = xvfs_absolutePath(path);

	pathStr = xvfs_relativePath(path, instanceInfo);
	if (!pathStr) {
		XVFS_DEBUG_PUTS("... no (not in our path)");

		Tcl_DecrRefCount(path);

		XVFS_DEBUG_LEAVE;
		return(-1);
	}

	statRetVal = instanceInfo->fsInfo->getStatProc(pathStr, &fileInfo);
	if (statRetVal < 0) {
		XVFS_DEBUG_PUTS("... no (not statable)");

		Tcl_DecrRefCount(path);

		XVFS_DEBUG_LEAVE;
		return(-1);
	}

	if (mode & X_OK) {
		if (!(fileInfo.st_mode & 040000)) {
			XVFS_DEBUG_PUTS("... no (not a directory and X_OK specified)");

			Tcl_DecrRefCount(path);

			XVFS_DEBUG_LEAVE;
			return(-1);
		}
	}

	Tcl_DecrRefCount(path);

	XVFS_DEBUG_PUTS("... ok");

	XVFS_DEBUG_LEAVE;
	return(0);
}





static Tcl_Channel xvfs_tclfs_openFileChannel(Tcl_Interp *interp, Tcl_Obj *path, int mode, int permissions, struct xvfs_tclfs_instance_info *instanceInfo) {
	Tcl_Channel retval;
	Tcl_Obj *pathRel;
	const char *pathStr;

	XVFS_DEBUG_ENTER;

	XVFS_DEBUG_PRINTF("Asked to open(\"%s\", %x)...", Tcl_GetString(path), mode);

	if (mode & O_WRONLY) {
		XVFS_DEBUG_PUTS("... failed (asked to open for writing");

		XVFS_DEBUG_LEAVE;
		return(NULL);
	}

	path = xvfs_absolutePath(path);

	pathStr = xvfs_relativePath(path, instanceInfo);

	pathRel = Tcl_NewStringObj(pathStr, -1);

	Tcl_DecrRefCount(path);

	XVFS_DEBUG_PUTS("... done, passing off to channel handler");

	retval = xvfs_tclfs_openChannel(pathRel, instanceInfo);

	XVFS_DEBUG_LEAVE;
	return(retval);
}

static int xvfs_tclfs_verifyType(Tcl_Obj *path, Tcl_GlobTypeData *types, struct xvfs_tclfs_instance_info *instanceInfo) {
	const char *pathStr;
	Tcl_StatBuf fileInfo;
	int statRetVal;

	XVFS_DEBUG_ENTER;

	if (types) {
		XVFS_DEBUG_PRINTF("Asked to verify the existence and type of \"%s\" matches type=%i and perm=%i ...", Tcl_GetString(path), types->type, types->perm);
	} else {
		XVFS_DEBUG_PRINTF("Asked to verify the existence \"%s\" ...", Tcl_GetString(path));
	}

	statRetVal = xvfs_tclfs_stat(path, &fileInfo, instanceInfo);
	if (statRetVal != 0) {
		XVFS_DEBUG_PUTS("... no (cannot stat)");

		XVFS_DEBUG_LEAVE;
		return(0);
	}

	if (!types) {
		XVFS_DEBUG_PUTS("... yes");

		XVFS_DEBUG_LEAVE;
		return(1);
	}

	if (types->perm != TCL_GLOB_PERM_RONLY) {
		if (types->perm & (TCL_GLOB_PERM_W | TCL_GLOB_PERM_HIDDEN)) {
			XVFS_DEBUG_PUTS("... no (checked for writable or hidden, not supported)");

			XVFS_DEBUG_LEAVE;
			return(0);
		}

		if ((types->perm & TCL_GLOB_PERM_X) == TCL_GLOB_PERM_X) {
			if (!(fileInfo.st_mode & 040000)) {
				XVFS_DEBUG_PUTS("... no (checked for executable but not a directory)");

				XVFS_DEBUG_LEAVE;
				return(0);
			}
		}
	}

	if (types->type & (TCL_GLOB_TYPE_BLOCK | TCL_GLOB_TYPE_CHAR | TCL_GLOB_TYPE_PIPE | TCL_GLOB_TYPE_SOCK | TCL_GLOB_TYPE_LINK)) {
		XVFS_DEBUG_PUTS("... no (checked for block, char, pipe, sock, or link, not supported)");

		XVFS_DEBUG_LEAVE;
		return(0);
	}

	if ((types->type & TCL_GLOB_TYPE_DIR) == TCL_GLOB_TYPE_DIR) {
		if (!(fileInfo.st_mode & 040000)) {
			XVFS_DEBUG_PUTS("... no (checked for directory but not a directory)");

			XVFS_DEBUG_LEAVE;
			return(0);
		}
	}

	if ((types->type & TCL_GLOB_TYPE_FILE) == TCL_GLOB_TYPE_FILE) {
		if (!(fileInfo.st_mode & 0100000)) {
			XVFS_DEBUG_PUTS("... no (checked for file but not a file)");

			XVFS_DEBUG_LEAVE;
			return(0);
		}
	}

	if ((types->type & TCL_GLOB_TYPE_MOUNT) == TCL_GLOB_TYPE_MOUNT) {
		path = xvfs_absolutePath(path);
		pathStr = xvfs_relativePath(path, instanceInfo);
		if (!pathStr) {
			XVFS_DEBUG_PUTS("... no (checked for mount but not able to resolve path)");

			Tcl_DecrRefCount(path);

			XVFS_DEBUG_LEAVE;
			return(0);
		}

		if (strlen(pathStr) != 0) {
			XVFS_DEBUG_PUTS("... no (checked for mount but not our top-level directory)");

			Tcl_DecrRefCount(path);

			XVFS_DEBUG_LEAVE;
			return(0);
		}

		Tcl_DecrRefCount(path);
	}

	XVFS_DEBUG_PUTS("... yes");

	XVFS_DEBUG_LEAVE;
	return(1);
}

static int xvfs_tclfs_matchInDir(Tcl_Interp *interp, Tcl_Obj *resultPtr, Tcl_Obj *path, const char *pattern, Tcl_GlobTypeData *types, struct xvfs_tclfs_instance_info *instanceInfo) {
	const char *pathStr;
	const char **children, *child;
	Tcl_WideInt childrenCount, idx;
	Tcl_Obj *childObj;
	int tclRetVal;

	if (pattern == NULL) {
		if (xvfs_tclfs_verifyType(path, types, instanceInfo)) {
			return(TCL_OK);
		}

		return(TCL_ERROR);
	}

	XVFS_DEBUG_ENTER;

	path = xvfs_absolutePath(path);

	if (types) {
		XVFS_DEBUG_PRINTF("Checking for files matching %s in \"%s\" and type=%i and perm=%i ...", pattern, Tcl_GetString(path), types->type, types->perm);
	} else {
		XVFS_DEBUG_PRINTF("Checking for files matching %s in \"%s\" ...", pattern, Tcl_GetString(path));
	}

	pathStr = xvfs_relativePath(path, instanceInfo);
	if (!pathStr) {
		XVFS_DEBUG_PUTS("... error (not in our VFS)");

		Tcl_DecrRefCount(path);

		if (interp) {
			Tcl_SetResult(interp, (char *) xvfs_perror(XVFS_RV_ERR_ENOENT), NULL);
		}

		XVFS_DEBUG_LEAVE;
		return(TCL_OK);
	}

	childrenCount = 0;
	children = instanceInfo->fsInfo->getChildrenProc(pathStr, &childrenCount);
	if (childrenCount < 0) {
		XVFS_DEBUG_PRINTF("... error: %s", xvfs_perror(childrenCount));

		Tcl_DecrRefCount(path);

		if (interp) {
			Tcl_SetResult(interp, (char *) xvfs_perror(childrenCount), NULL);
		}

		XVFS_DEBUG_LEAVE;
		return(TCL_ERROR);
	}

	for (idx = 0; idx < childrenCount; idx++) {
		child = children[idx];

		if (!Tcl_StringMatch(child, pattern)) {
558
559
560
561
562
563
564




565
566
567
568





569
570
571
572
573
574
575
			continue;
		}

		tclRetVal = Tcl_ListObjAppendElement(interp, resultPtr, childObj);
		Tcl_DecrRefCount(childObj);

		if (tclRetVal != TCL_OK) {




			return(tclRetVal);
		}
	}






	return(TCL_OK);
}
#endif /* XVFS_MODE_SERVER || XVFS_MODE_STANDALONE || XVFS_MODE_FLEIXBLE */

#if defined(XVFS_MODE_STANDALONE) || defined(XVFS_MODE_FLEXIBLE)
/*
 * Tcl_Filesystem handlers for the standalone implementation







>
>
>
>




>
>
>
>
>







770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
			continue;
		}

		tclRetVal = Tcl_ListObjAppendElement(interp, resultPtr, childObj);
		Tcl_DecrRefCount(childObj);

		if (tclRetVal != TCL_OK) {
			XVFS_DEBUG_PUTS("... error (lappend)");
			Tcl_DecrRefCount(path);

			XVFS_DEBUG_LEAVE;
			return(tclRetVal);
		}
	}

	Tcl_DecrRefCount(path);

	XVFS_DEBUG_PRINTF("... ok (returning items: %s)", Tcl_GetString(resultPtr));

	XVFS_DEBUG_LEAVE;
	return(TCL_OK);
}
#endif /* XVFS_MODE_SERVER || XVFS_MODE_STANDALONE || XVFS_MODE_FLEIXBLE */

#if defined(XVFS_MODE_STANDALONE) || defined(XVFS_MODE_FLEXIBLE)
/*
 * Tcl_Filesystem handlers for the standalone implementation
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
	return(xvfs_tclfs_stat(path, statBuf, &xvfs_tclfs_standalone_info));
}

static int xvfs_tclfs_standalone_access(Tcl_Obj *path, int mode) {
	return(xvfs_tclfs_access(path, mode, &xvfs_tclfs_standalone_info));
}

static Tcl_Obj *xvfs_tclfs_standalone_listVolumes(void) {
	return(xvfs_tclfs_listVolumes(&xvfs_tclfs_standalone_info));
}

static Tcl_Channel xvfs_tclfs_standalone_openFileChannel(Tcl_Interp *interp, Tcl_Obj *path, int mode, int permissions) {
	return(xvfs_tclfs_openFileChannel(interp, path, mode, permissions, &xvfs_tclfs_standalone_info));
}

static int xvfs_tclfs_standalone_matchInDir(Tcl_Interp *interp, Tcl_Obj *resultPtr, Tcl_Obj *pathPtr, const char *pattern, Tcl_GlobTypeData *types) {
	return(xvfs_tclfs_matchInDir(interp, resultPtr, pathPtr, pattern, types, &xvfs_tclfs_standalone_info));
}







<
<
<
<







804
805
806
807
808
809
810




811
812
813
814
815
816
817
	return(xvfs_tclfs_stat(path, statBuf, &xvfs_tclfs_standalone_info));
}

static int xvfs_tclfs_standalone_access(Tcl_Obj *path, int mode) {
	return(xvfs_tclfs_access(path, mode, &xvfs_tclfs_standalone_info));
}





static Tcl_Channel xvfs_tclfs_standalone_openFileChannel(Tcl_Interp *interp, Tcl_Obj *path, int mode, int permissions) {
	return(xvfs_tclfs_openFileChannel(interp, path, mode, permissions, &xvfs_tclfs_standalone_info));
}

static int xvfs_tclfs_standalone_matchInDir(Tcl_Interp *interp, Tcl_Obj *resultPtr, Tcl_Obj *pathPtr, const char *pattern, Tcl_GlobTypeData *types) {
	return(xvfs_tclfs_matchInDir(interp, resultPtr, pathPtr, pattern, types, &xvfs_tclfs_standalone_info));
}
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
	xvfs_tclfs_standalone_fs.filesystemSeparatorProc    = NULL;
	xvfs_tclfs_standalone_fs.statProc                   = xvfs_tclfs_standalone_stat;
	xvfs_tclfs_standalone_fs.accessProc                 = xvfs_tclfs_standalone_access;
	xvfs_tclfs_standalone_fs.openFileChannelProc        = xvfs_tclfs_standalone_openFileChannel;
	xvfs_tclfs_standalone_fs.matchInDirectoryProc       = xvfs_tclfs_standalone_matchInDir;
	xvfs_tclfs_standalone_fs.utimeProc                  = NULL;
	xvfs_tclfs_standalone_fs.linkProc                   = NULL;
	xvfs_tclfs_standalone_fs.listVolumesProc            = xvfs_tclfs_standalone_listVolumes;
	xvfs_tclfs_standalone_fs.fileAttrStringsProc        = NULL;
	xvfs_tclfs_standalone_fs.fileAttrsGetProc           = NULL;
	xvfs_tclfs_standalone_fs.fileAttrsSetProc           = NULL;
	xvfs_tclfs_standalone_fs.createDirectoryProc        = NULL;
	xvfs_tclfs_standalone_fs.removeDirectoryProc        = NULL;
	xvfs_tclfs_standalone_fs.deleteFileProc             = NULL;
	xvfs_tclfs_standalone_fs.copyFileProc               = NULL;







|







866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
	xvfs_tclfs_standalone_fs.filesystemSeparatorProc    = NULL;
	xvfs_tclfs_standalone_fs.statProc                   = xvfs_tclfs_standalone_stat;
	xvfs_tclfs_standalone_fs.accessProc                 = xvfs_tclfs_standalone_access;
	xvfs_tclfs_standalone_fs.openFileChannelProc        = xvfs_tclfs_standalone_openFileChannel;
	xvfs_tclfs_standalone_fs.matchInDirectoryProc       = xvfs_tclfs_standalone_matchInDir;
	xvfs_tclfs_standalone_fs.utimeProc                  = NULL;
	xvfs_tclfs_standalone_fs.linkProc                   = NULL;
	xvfs_tclfs_standalone_fs.listVolumesProc            = NULL;
	xvfs_tclfs_standalone_fs.fileAttrStringsProc        = NULL;
	xvfs_tclfs_standalone_fs.fileAttrsGetProc           = NULL;
	xvfs_tclfs_standalone_fs.fileAttrsSetProc           = NULL;
	xvfs_tclfs_standalone_fs.createDirectoryProc        = NULL;
	xvfs_tclfs_standalone_fs.removeDirectoryProc        = NULL;
	xvfs_tclfs_standalone_fs.deleteFileProc             = NULL;
	xvfs_tclfs_standalone_fs.copyFileProc               = NULL;

Modified xvfs-create from [58057edf98] to [a04cb49093].

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

package require minirivet

set mode "run"
if {[lindex $argv 0] == "--dump-tcl"} {
	set mode "dump-tcl"
}





















switch -- $mode {
	"run" {
		::minirivet::parse $template
	}
	"dump-tcl" {
		set xvfs_tcl [file join $sourceDirectory lib xvfs xvfs.tcl]
		set xvfs_core_h [file join $sourceDirectory xvfs-core.h]
		set xvfs_core_c [file join $sourceDirectory xvfs-core.c]

		set cleanup {
			"#include <xvfs-core.h>" ""
			"#include <xvfs-core.c>" ""
		}

		set core_header_data ""
		append core_header_data [string map $cleanup [read [open $xvfs_core_h]]] "\n"
		append core_header_data [string map $cleanup [read [open $xvfs_core_c]]] "\n"





		puts "#! /usr/bin/env tclsh"
		puts ""
		puts [read [open $xvfs_tcl]]
		puts ""
		puts [list puts -nonewline $core_header_data]
		puts ""







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>


















>
>
>
>







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

package require minirivet

set mode "run"
if {[lindex $argv 0] == "--dump-tcl"} {
	set mode "dump-tcl"
}

proc remove_debug {input} {
	set output [list]

	set lastLine -
	foreach line [split $input "\n"] {
		if {[string match -nocase "*XVFS_DEBUG*" $line]} {
			continue
		}

		if {$lastLine eq "" && $line eq ""} {
			continue
		}

		set lastLine $line
		lappend output $line
	}

	return [join $output "\n"]
}

switch -- $mode {
	"run" {
		::minirivet::parse $template
	}
	"dump-tcl" {
		set xvfs_tcl [file join $sourceDirectory lib xvfs xvfs.tcl]
		set xvfs_core_h [file join $sourceDirectory xvfs-core.h]
		set xvfs_core_c [file join $sourceDirectory xvfs-core.c]

		set cleanup {
			"#include <xvfs-core.h>" ""
			"#include <xvfs-core.c>" ""
		}

		set core_header_data ""
		append core_header_data [string map $cleanup [read [open $xvfs_core_h]]] "\n"
		append core_header_data [string map $cleanup [read [open $xvfs_core_c]]] "\n"

		if {[lsearch -exact $argv "--remove-debug"] != -1} {
			set core_header_data [remove_debug $core_header_data]
		}

		puts "#! /usr/bin/env tclsh"
		puts ""
		puts [read [open $xvfs_tcl]]
		puts ""
		puts [list puts -nonewline $core_header_data]
		puts ""