Пример #1
0
void KprDebugMachineEchoItem(KprDebugMachine self, int theView, char* path, int line, char* name, char* value)
{
	KprDebug debug = self->debug;
	xsMachine* the = debug->the;

	if (xsTypeOf(debug->behavior) == xsUndefinedType) goto bail;
	{
		xsTry {
			xsVar(0) = xsAccess(debug->behavior);
			xsVar(1) = xsGet(xsVar(0), xsID(self->address));
			xsVar(2) = xsNewInstanceOf(xsObjectPrototype);
			if (path)
				xsNewHostProperty(xsVar(2), xsID("path"), xsString(path), xsDefault, xsDontScript);
			if (line >= 0)
				xsNewHostProperty(xsVar(2), xsID("line"), xsInteger(line), xsDefault, xsDontScript);
			if (name)
				xsNewHostProperty(xsVar(2), xsID("name"), xsString(name), xsDefault, xsDontScript);
			if (value)
				xsNewHostProperty(xsVar(2), xsID("value"), xsString(value), xsDefault, xsDontScript);
			if (xsFindResult(xsVar(1), xsID_push)) {
				(void)xsCallFunction1(xsResult, xsVar(1), xsVar(2));
			}
		}
		xsCatch {
		}
	}
bail:
	return;
}
Пример #2
0
void patchGrammar(xsMachine* the)
{
	xsVars(1);
	xsVar(0) = xsGet(xsGlobal, xsID_Grammar);
	xsNewHostProperty(xsVar(0), xsID_nameToID, xsNewHostFunction(Grammar_nameToID, 1), xsDontEnum, xsDontScript);
	xsNewHostProperty(xsVar(0), xsID_parse, xsNewHostFunction(xs_parse, 1), xsDontEnum, xsDontScript);
	xsNewHostProperty(xsVar(0), xsID_stringify, xsNewHostFunction(xs_serialize, 1), xsDontEnum, xsDontScript);
}
Пример #3
0
FskErr KprApplicationNew(KprApplication* it, char* url, char* id, Boolean breakOnStart, Boolean breakOnExceptions)
{
	KprCoordinatesRecord coordinates = { kprLeftRight, kprTopBottom, 0, 0, 0, 0, 0, 0 };
	xsAllocation allocation = {
		2 * 1024 * 1024,
		1024 * 1024,
		64 * 1024,
		8 * 1024,
		2048,
		16000,
		1993
	};
	FskErr err = kFskErrNone;
	KprApplication self;
	
	bailIfError(FskMemPtrNewClear(sizeof(KprApplicationRecord), it));
	self = *it;
	FskInstrumentedItemNew(self, NULL, &KprApplicationInstrumentation);
	self->dispatch = &KprApplicationDispatchRecord;
	self->flags = kprContainer | kprClip | kprVisible;
	KprContentInitialize((KprContent)self, &coordinates, NULL, NULL);
	bailIfError(KprURLMerge(gShell->url, url, &self->url));	
	if (id) {
		self->id = FskStrDoCopy(id);	
		bailIfNULL(self->id);
	}
	self->the = xsAliasMachine(&allocation, gShell->root, self->url, self);
	if (!self->the) 
		BAIL(kFskErrMemFull);
	FskInstrumentedItemSendMessageNormal(self, kprInstrumentedContentCreateMachine, self);
	xsBeginHost(self->the);
	xsResult = xsNewHostFunction(KPR_include, 1);
	xsSet(xsResult, xsID("uri"), xsString(self->url));
	xsNewHostProperty(xsGlobal, xsID("include"), xsResult, xsDontDelete | xsDontSet, xsDontScript | xsDontDelete | xsDontSet);
	xsResult = xsNewHostFunction(KPR_require, 1);
	xsSet(xsResult, xsID("uri"), xsString(self->url));
	xsNewHostProperty(xsGlobal, xsID("require"), xsResult, xsDontDelete | xsDontSet, xsDontScript | xsDontDelete | xsDontSet);
	xsResult = xsNewInstanceOf(xsGet(xsGet(xsGlobal, xsID("KPR")), xsID("application")));
	self->slot = xsResult;
	xsSetHostData(xsResult, self);
	(void)xsCall1(xsGet(xsGlobal, xsID("Object")), xsID("seal"), xsResult);
	xsNewHostProperty(xsGlobal, xsID("application"), xsResult, xsDontDelete | xsDontSet, xsDontScript | xsDontDelete | xsDontSet);
	xsNewHostProperty(xsGlobal, xsID("shell"), xsNull, xsDontDelete | xsDontSet, xsDontScript | xsDontDelete | xsDontSet);
	if (breakOnStart)
		xsDebugger();
    if (breakOnExceptions)
		(void)xsCall1(xsGet(xsGet(xsGlobal, xsID("xs")), xsID("debug")), xsID("setBreakOnException"), xsBoolean(breakOnExceptions));
	(void)xsCall1(xsGlobal, xsID("include"), xsString(self->url));
	xsEndHost(self->the);
	KprContentChainPrepend(&gShell->applicationChain, self, 0, NULL);
bail:
	return err;
}
Пример #4
0
void KPR_canvas_get_size(xsMachine *the)
{
	KprCanvas self = xsGetHostData(xsThis);
	xsResult = xsNewInstanceOf(xsObjectPrototype);
	if (self->cnv) {
		FskRectangleRecord bounds;
		FskBitmapGetBounds(FskGetCanvasBitmap(self->cnv), &bounds);
		xsNewHostProperty(xsResult, xsID_width, xsInteger(bounds.width), xsDefault, xsDontScript);
		xsNewHostProperty(xsResult, xsID_height, xsInteger(bounds.height), xsDefault, xsDontScript);
	}
	else if (self->shell) {
		KprShellAdjust(self->shell);
		xsNewHostProperty(xsResult, xsID_width, xsInteger(self->bounds.width), xsDefault, xsDontScript);
		xsNewHostProperty(xsResult, xsID_height, xsInteger(self->bounds.height), xsDefault, xsDontScript);
	}
}
Пример #5
0
void KPR_canvasRenderingContext2D_pickHitRegion(xsMachine *the)
{
	FskCanvas2dContext	ctx			= xsGetHostData(xsThis);
	xsNumberValue		x			= xsToNumber(xsArg(0)),
						y			= xsToNumber(xsArg(1));
	const char			*id			= NULL,
						*control	= NULL;

	if (kFskErrNone == FskCanvas2dPickHitRegion(ctx, x, y, &id, &control)) {
		xsResult = xsNewInstanceOf(xsObjectPrototype);
		if (id)			xsNewHostProperty(xsResult, xsID("id"),      xsString((char*)id),      xsDefault, xsDontScript);	// TODO: Would we send a mouse event to the id?
		if (control)	xsNewHostProperty(xsResult, xsID("control"), xsString((char*)control), xsDefault, xsDontScript);	// TODO: We should call the control directly.
	}
	else {
		// How do we indicate failure? xsResult = NULL;
	}
}
Пример #6
0
void KPR_debug_get_machines(xsMachine *the)
{
	KprDebug self = xsGetHostData(xsThis);
	KprDebugMachine machine = NULL;
	xsEnterSandbox();
	xsVars(1);
	{
		xsResult = xsNewInstanceOf(xsArrayPrototype);
		for (machine = self->machine; machine; machine = machine->next) {
			xsVar(0) = xsNewInstanceOf(xsObjectPrototype);
			xsNewHostProperty(xsVar(0), xsID("address"), xsString(machine->address), xsDefault, xsDontScript);
			if (machine->title)
				xsNewHostProperty(xsVar(0), xsID("title"), xsString(machine->title), xsDefault, xsDontScript);
			xsCall1(xsResult, xsID_push, xsVar(0));
		}
	}
	xsLeaveSandbox();
}
Пример #7
0
void KPR_Message_patch(xsMachine* the)
{
	xsResult = xsGet(xsGlobal, xsID("Message"));
	xsNewHostProperty(xsResult, xsID("BUFFER"), xsString("BUFFER"), xsDontDelete | xsDontSet, xsDontScript | xsDontDelete | xsDontSet);
	xsNewHostProperty(xsResult, xsID("CHUNK"), xsString("CHUNK"), xsDontDelete | xsDontSet, xsDontScript | xsDontDelete | xsDontSet);
	xsNewHostProperty(xsResult, xsID("DOM"), xsString("DOM"), xsDontDelete | xsDontSet, xsDontScript | xsDontDelete | xsDontSet);
	xsNewHostProperty(xsResult, xsID("JSON"), xsString("JSON"), xsDontDelete | xsDontSet, xsDontScript | xsDontDelete | xsDontSet);
	xsNewHostProperty(xsResult, xsID("TEXT"), xsString("TEXT"), xsDontDelete | xsDontSet, xsDontScript | xsDontDelete | xsDontSet);
	xsNewHostProperty(xsResult, xsID("URI"), xsNewHostFunction(KPR_Message_URI, 1), xsDefault, xsDontScript);
	xsNewHostProperty(xsResult, xsID("cancelReferrer"), xsNewHostFunction(KPR_Message_cancelReferrer, 1), xsDefault, xsDontScript);
	xsNewHostProperty(xsResult, xsID("notify"), xsNewHostFunction(KPR_Message_notify, 1), xsDefault, xsDontScript);
}
Пример #8
0
void KPR_application_get_size(xsMachine *the)
{
	KprContainer container = xsGetHostData(xsThis);
	Boolean horizontal = true;
	SInt32 left = 0;
	SInt32 width = 0;
	SInt32 right = 0;
	Boolean vertical = true;
	SInt32 top = 0;
	SInt32 height = 0;
	SInt32 bottom = 0;
	while (container) {
		if (horizontal) {
			if ((container->coordinates.horizontal & kprWidth)) {
				width = container->coordinates.width - left - right;
				horizontal = false;
				if (!vertical)
					break;
			}
			else {
				left += container->coordinates.left;
				right += container->coordinates.right;
			}
		}
		if (vertical) {
			if ((container->coordinates.vertical & kprHeight)) {
				height = container->coordinates.height - top - bottom;
				vertical = false;
				if (!horizontal)
					break;
			}
			else {
				top += container->coordinates.top;
				bottom += container->coordinates.bottom;
			}
		}
		container = container->container;
	}
	xsResult = xsNewInstanceOf(xsObjectPrototype);
	xsNewHostProperty(xsResult, xsID_width, xsInteger(width), xsDefault, xsDontScript);
	xsNewHostProperty(xsResult, xsID_height, xsInteger(height), xsDefault, xsDontScript);
}
Пример #9
0
void KprDebugMachineEchoView(KprDebugMachine self, int theView, char* theName, char* theValue)
{
	KprDebug debug = self->debug;
	xsMachine* the = debug->the;

	// FskDebugStr("%s: %d - %s = %s", __FUNCTION__, theView, theName, theValue);
	if (xsTypeOf(debug->behavior) == xsUndefinedType) goto bail;
	{
		xsTry {
			xsVar(0) = xsAccess(debug->behavior);
			xsVar(1) = xsGet(xsVar(0), xsID(self->address));
			xsVar(2) = xsNewInstanceOf(xsObjectPrototype);
			xsNewHostProperty(xsVar(2), xsID("name"), xsString(theName), xsDefault, xsDontScript);
			xsNewHostProperty(xsVar(2), xsID("value"), xsString(theValue), xsDefault, xsDontScript);
			if (xsFindResult(xsVar(1), xsID_push)) {
				(void)xsCallFunction1(xsResult, xsVar(1), xsVar(2));
			}
		}
		xsCatch {
		}
	}
bail:
	return;
}
Пример #10
0
void KPR_parseURI(xsMachine *the)
{
	xsStringValue url = xsToString(xsArg(0));
	KprURLPartsRecord parts;
	xsStringValue target;
	char c;
	xsThrowIfFskErr(FskMemPtrNew(FskStrLen(url) + 1, &target));
	FskStrCopy(target, url);
	KprURLSplit(target, &parts);
	xsResult = xsNewInstanceOf(xsObjectPrototype);
	if (parts.scheme) {
		c = *(parts.scheme + parts.schemeLength);
		*(parts.scheme + parts.schemeLength) = 0;
		xsNewHostProperty(xsResult, xsID_scheme, xsString(parts.scheme), xsDefault, xsDontScript);
		*(parts.scheme + parts.schemeLength) = c;
	}
	if (parts.authority) {
		c = *(parts.authority + parts.authorityLength);
		*(parts.authority + parts.authorityLength) = 0;
		xsNewHostProperty(xsResult, xsID_authority, xsString(parts.authority), xsDefault, xsDontScript);
		*(parts.authority + parts.authorityLength) = c;
	}
	if (parts.path) {
		c = *(parts.path + parts.pathLength);
		*(parts.path + parts.pathLength) = 0;
		xsNewHostProperty(xsResult, xsID_path, xsString(parts.path), xsDefault, xsDontScript);
		*(parts.path + parts.pathLength) = c;
	}
	if (parts.name) {
		c = *(parts.name + parts.nameLength);
		*(parts.name + parts.nameLength) = 0;
		xsNewHostProperty(xsResult, xsID_name, xsString(parts.name), xsDefault, xsDontScript);
		*(parts.name + parts.nameLength) = c;
	}
	if (parts.query) {
		c = *(parts.query + parts.queryLength);
		*(parts.query + parts.queryLength) = 0;
		xsNewHostProperty(xsResult, xsID_query, xsString(parts.query), xsDefault, xsDontScript);
		*(parts.query + parts.queryLength) = c;
	}
	if (parts.fragment) {
		c = *(parts.fragment + parts.fragmentLength);
		*(parts.fragment + parts.fragmentLength) = 0;
		xsNewHostProperty(xsResult, xsID_fragment, xsString(parts.fragment), xsDefault, xsDontScript);
		*(parts.fragment + parts.fragmentLength) = c;
	}
	FskMemPtrDispose(target);
}
Пример #11
0
void KprDebugMachineLockView(KprDebugMachine self, int theView)
{
	KprDebug debug = self->debug;
	xsMachine* the = debug->the;

	// FskDebugStr("%s: %d", __FUNCTION__, theView);
	if (xsTypeOf(debug->behavior) == xsUndefinedType) goto bail;
	{
		xsTry {
			xsVar(0) = xsAccess(debug->behavior);
			if (xsHasOwn(xsVar(0), xsID(self->address)))
				xsDelete(xsVar(0), xsID(self->address));
			xsVar(1) = xsNewInstanceOf(xsArrayPrototype);
			xsNewHostProperty(xsVar(0), xsID(self->address), xsVar(1), xsDefault, xsDontScript);
		}
		xsCatch {
		}
	}
bail:
	return;
}
Пример #12
0
void KprDebugMachineEchoProperty(KprDebugMachine self, int theView, int column, char* flags, char* name, char* value)
{
	KprDebug debug = self->debug;
	xsMachine* the = debug->the;

	// FskDebugStr("%s: %d - %s = %s", __FUNCTION__, theView, theName, theValue);
	if (xsTypeOf(debug->behavior) == xsUndefinedType) goto bail;
	{
		xsTry {
			xsVar(0) = xsAccess(debug->behavior);
			xsVar(1) = xsGet(xsVar(0), xsID(self->address));
			xsVar(2) = xsNewInstanceOf(xsObjectPrototype);
			xsNewHostProperty(xsVar(2), xsID("column"), xsInteger(column), xsDefault, xsDontScript);
			flags[4] = 0;
			xsNewHostProperty(xsVar(2), xsID("flags"), xsString(flags + 1), xsDefault, xsDontScript);
			if (flags[0] == ' ')
				xsNewHostProperty(xsVar(2), xsID("state"), xsInteger(0), xsDefault, xsDontScript);
			else if (flags[0] == '+')
				xsNewHostProperty(xsVar(2), xsID("state"), xsInteger(1), xsDefault, xsDontScript);
			else if (flags[0] == '-')
				xsNewHostProperty(xsVar(2), xsID("state"), xsInteger(2), xsDefault, xsDontScript);
			else
				xsNewHostProperty(xsVar(2), xsID("state"), xsInteger(0), xsDefault, xsDontScript);
			if (name)
				xsNewHostProperty(xsVar(2), xsID("name"), xsString(name), xsDefault, xsDontScript);
			if (value)
				xsNewHostProperty(xsVar(2), xsID("value"), xsString(value), xsDefault, xsDontScript);
			if (xsFindResult(xsVar(1), xsID_push)) {
				(void)xsCallFunction1(xsResult, xsVar(1), xsVar(2));
			}
		}
		xsCatch {
		}
	}
bail:
	return;
}
Пример #13
0
void KprFILEServiceInvoke(KprService service UNUSED, KprMessage message)
{
	FskErr err = kFskErrNone;
	char* path = NULL;
	FskFileInfo info;
	FskDirectoryIterator iterator = NULL;
	char* pathName = NULL;
	char* sniff = NULL;
	FskFile fref = NULL;
	char *name = NULL;
	if (KprMessageContinue(message)) {
		if (!message->method || FskStrCompare(message->method, "GET")) {
			bailIfError(KprURLToPath(message->url, &path));
			bailIfError(FskFileGetFileInfo(path, &info));
			if (kFskDirectoryItemIsDirectory == info.filetype) {
				unsigned char buffer[4096];
				UInt32 itemType;
				double date;
				UInt32 size;
				xsBeginHostSandboxCode(gFILEService.machine, NULL);
				{
					xsVars(3);
					{
						xsTry {
							xsVar(0) = xsGet(xsGlobal, xsID("Files"));
							xsResult = xsNewInstanceOf(xsArrayPrototype);
							bailIfError(FskDirectoryIteratorNew(path, &iterator, 0));
							while (kFskErrNone == FskDirectoryIteratorGetNext(iterator, &name, &itemType)) {
								if (name[0] == '.') {
									FskMemPtrDisposeAt(&name);
									continue;
								}
								if (kFskDirectoryItemIsFile == itemType) {
									pathName = FskStrDoCat(path, name);
									bailIfError(FskFileGetFileInfo(pathName, &info));
									bailIfError(FskFileOpen(pathName, kFskFilePermissionReadOnly, &fref));
									bailIfError(FskFileRead(fref, sizeof(buffer), buffer, &size));
									FskFileClose(fref);
									fref = NULL;
									if (kFskErrNone == FskMediaPlayerSniffForMIME(buffer, size, NULL, pathName, &sniff)) {
									}
									else if (kFskErrNone == FskImageDecompressSniffForMIME(buffer, size, NULL, pathName, &sniff)) {
									}
									FskMemPtrDispose(pathName);
									pathName = NULL;
								}
								xsVar(1) = xsNewInstanceOf(xsObjectPrototype);
								xsNewHostProperty(xsVar(1), xsID("name"), xsString(name), xsDefault, xsDontScript);
								xsNewHostProperty(xsVar(1), xsID("path"), xsString(name), xsDefault, xsDontScript);
								FskStrCopy((char*)buffer, message->url);
								FskStrCat((char*)buffer, name);
								if (kFskDirectoryItemIsDirectory == itemType) {
									xsVar(2) = xsGet(xsVar(0), xsID("directoryType"));
									FskStrCat((char*)buffer, "/");
								}
								else if (kFskDirectoryItemIsFile == itemType) {
									xsVar(2) = xsGet(xsVar(0), xsID("fileType"));
									if (info.fileModificationDate > info.fileCreationDate)
										date = info.fileModificationDate * 1000.0;	
									else
										date = info.fileCreationDate * 1000.0;
									xsNewHostProperty(xsVar(1), xsID("date"), xsNumber(date), xsDefault, xsDontScript);
									xsNewHostProperty(xsVar(1), xsID("size"), xsNumber(info.filesize), xsDefault, xsDontScript);
									if (sniff) {
										xsNewHostProperty(xsVar(1), xsID("mime"), xsString(sniff), xsDefault, xsDontScript);
										FskMemPtrDispose(sniff);
										sniff = NULL;
									}
								}
								else
									xsVar(2) = xsGet(xsVar(0), xsID("linkType"));
								xsNewHostProperty(xsVar(1), xsID("type"), xsVar(2), xsDefault, xsDontScript);
								xsNewHostProperty(xsVar(1), xsID("url"), xsString((char*)buffer), xsDefault, xsDontScript);
								(void)xsCall1(xsResult, xsID("push"), xsVar(1));
								FskMemPtrDisposeAt(&name);
							}
							xsResult = xsCall1(xsGet(xsGlobal, xsID("JSON")), xsID("stringify"), xsResult);
							message->response.body = FskStrDoCopy(xsToString(xsResult));
							message->response.size = FskStrLen(message->response.body);
							KprMessageTransform(message, gFILEService.machine);
						}
						xsCatch {
						}
					}
				}
				xsEndHostSandboxCode();
			}
			else if (kFskDirectoryItemIsFile == info.filetype) {
Пример #14
0
void KPR_shell_splitError(xsMachine* the)
{
	xsStringValue string, p, q;
	char c;
	xsIndex ids[4];
	size_t offsets[4], lengths[4];
	int i;
	xsVars(1);
	string = p = xsToString(xsArg(0));
	ids[0] = xsID_path;
	offsets[0] = p - string;
	c = *p;
	if (c == '/')
		p = FskStrChr(p, ':');
	else if (('A' <= c) && (c <= 'Z') && (*(p + 1) == ':'))
		p = FskStrChr(p + 2, ':');
	else
		goto bail;
	if (!p) goto bail;
	ids[1] = xsID_line;
	q = p - 1;
	c = *q;
	if (c == ')') {
		q--;
		while ((q > string) && ((c = *q)) && ('0' <= c) && (c <= '9'))
			q--;
		if (c != '(') goto bail;
		lengths[0] = q - string;
		offsets[1] = q + 1 - string;
		lengths[1] = (p - q) - 2;
	}
	else {
		lengths[0] = p - string;
		p++;
		offsets[1] = p - string;
		while (((c = *p)) && ('0' <= c) && (c <= '9'))
			p++;
		if (c != ':') goto bail;
		lengths[1] = (p - string) - offsets[1];
	}
	p++;
	c  = *p;
	if (('0' <= c) && (c <= '9')) {
		p++;
		while (((c = *p)) && ('0' <= c) && (c <= '9'))
			p++;
		if (c != ':') goto bail;
		p++;
		c  = *p;
	}
	if (c != ' ') goto bail;
	p++;
	ids[2] = xsID_kind;
	offsets[2] = p - string;
	p = FskStrChr(p, ':');
	if (!p) goto bail;
	lengths[2] = (p - string) - offsets[2];
	p++;
	c = *p;
	if (c != ' ') goto bail;
	p++;
	ids[3] = xsID_reason;
	offsets[3] = p - string;
	lengths[3] = FskStrLen(p);
	xsResult = xsNewInstanceOf(xsObjectPrototype);
	for (i = 0; i < 4; i++) {
		xsVar(0) = xsStringBuffer(NULL, lengths[i]);
		string = xsToString(xsArg(0));
		FskMemCopy(xsToString(xsVar(0)), string + offsets[i], lengths[i]);
		xsNewHostProperty(xsResult, ids[i], xsVar(0), xsDefault, xsDontScript);
	}
bail:
	return;
}
Пример #15
0
void KPR_shell_execute(xsMachine* the)
{
	xsStringValue application = NULL;
	xsStringValue command = NULL;
	xsStringValue directory = NULL;
	xsStringValue environment = NULL;
	xsStringValue string;
	xsIntegerValue length;
	KprShellExec exec = NULL;
	STARTUPINFO si;
	SECURITY_ATTRIBUTES sa; 
	xsVars(5);
	xsTry {
		application = getenv("COMSPEC");
		if (!application)
			xsThrowIfFskErr(kFskErrOperationFailed);
		
		string = xsToString(xsArg(0));
		length = FskStrLen(string) + 1;
		xsThrowIfFskErr(FskMemPtrNew(3 + length, &command));
		memcpy(command, "/c ", 3);
		memcpy(command + 3, string, length);

		if (xsFindString(xsArg(1), xsID_directory, &string)) {
			length = FskStrLen(string) + 1;
			xsThrowIfFskErr(FskMemPtrNew(length, &directory));
			memcpy(directory, string, length);
		}
		if (xsFindResult(xsArg(1), xsID_environment)) {
			xsIntegerValue total = 0, length;
			xsVar(1) = xsEnumerate(xsResult);
			for (;;) {
				xsVar(2) = xsCall0(xsVar(1), xsID("next"));
				xsVar(3) = xsGet(xsVar(2), xsID("done"));
				if (xsTest(xsVar(3)))
					break;
				xsVar(3) = xsGet(xsVar(2), xsID("value"));
				xsVar(4) = xsGetAt(xsResult, xsVar(3));
				total += FskStrLen(xsToString(xsVar(3)));
				total++;
				total += FskStrLen(xsToString(xsVar(4)));
				total++;
			}
			total++;
			xsThrowIfFskErr(FskMemPtrNew(total, &environment));
			total = 0;
			xsVar(1) = xsEnumerate(xsResult);
			for (;;) {
				xsVar(2) = xsCall0(xsVar(1), xsID("next"));
				xsVar(3) = xsGet(xsVar(2), xsID("done"));
				if (xsTest(xsVar(3)))
					break;
				xsVar(3) = xsGet(xsVar(2), xsID("value"));
				xsVar(4) = xsGetAt(xsResult, xsVar(3));
				string = xsToString(xsVar(3));
				length = FskStrLen(string);
				memcpy(environment + total, string, length);
				total += length;
				environment[total++] = '=';
				string = xsToString(xsVar(4));
				length = FskStrLen(string);
				memcpy(environment + total, string, length);
				total += length;
				environment[total++] = 0;
			}
			environment[total++] = 0;
		}
		
		xsThrowIfFskErr(FskMemPtrNewClear(sizeof(KprShellExecRecord), &exec));
		xsVar(0) = xsNewHostObject(KPR_shell_execute_destructor);
		exec->the = the;
		exec->slot = xsVar(0);
		xsSetHostData(xsVar(0), exec);
		
		xsResult = xsNewHostFunction(KPR_shell_execute_cancel, 0);
		xsNewHostProperty(xsVar(0), xsID_cancel, xsResult, xsDefault, xsDontDelete | xsDontEnum | xsDontSet);
		if (xsFindResult(xsArg(1), xsID_callback)) {
			xsNewHostProperty(xsVar(0), xsID_callback, xsResult, xsDefault, xsDontDelete | xsDontEnum | xsDontSet);
		}
		else {
			xsNewHostProperty(xsVar(0), xsID_callback, xsNull, xsDefault, xsDontDelete | xsDontEnum | xsDontSet);
		}
		if (xsFindResult(xsArg(1), xsID_stderr)) {
			xsNewHostProperty(xsVar(0), xsID_stderr, xsResult, xsDefault, xsDontDelete | xsDontEnum | xsDontSet);
		}
		else {
			xsNewHostProperty(xsVar(0), xsID_stderr, xsNull, xsDefault, xsDontDelete | xsDontEnum | xsDontSet);
		}
		if (xsFindResult(xsArg(1), xsID_stdout)) {
			xsNewHostProperty(xsVar(0), xsID_stdout, xsResult, xsDefault, xsDontDelete | xsDontEnum | xsDontSet);
		}
		else {
			xsNewHostProperty(xsVar(0), xsID_stdout, xsNull, xsDefault, xsDontDelete | xsDontEnum | xsDontSet);
		}
		
		sa.nLength = sizeof(SECURITY_ATTRIBUTES); 
		sa.bInheritHandle = TRUE; 
		sa.lpSecurityDescriptor = NULL; 
		if (!CreatePipe(&(exec->hReadPipe), &(exec->hWritePipe), &sa, 0))
			xsThrowIfFskErr(kFskErrOperationFailed);
		if (!SetHandleInformation(exec->hReadPipe, HANDLE_FLAG_INHERIT, 0))
			xsThrowIfFskErr(kFskErrOperationFailed);
		ZeroMemory(&si, sizeof(si));
		si.cb = sizeof(STARTUPINFO); 
		si.hStdError = exec->hWritePipe;
		si.hStdOutput = exec->hWritePipe;
		si.hStdInput = GetStdHandle(STD_INPUT_HANDLE);
		si.dwFlags = STARTF_USESTDHANDLES;
		if (!CreateProcess(application, command, NULL, NULL, TRUE, CREATE_NO_WINDOW, environment, directory, &si, &(exec->pi)))
			xsThrowIfFskErr(kFskErrOperationFailed);
			
		xsRemember(exec->slot);
		exec->usage++;
		FskThreadPostCallback(KprHTTPGetThread(), (FskThreadCallback)KPR_shell_execute_async, exec, NULL, NULL, NULL);
		FskMemPtrDispose(environment);
		FskMemPtrDispose(directory);
		FskMemPtrDispose(command);
	}
	xsCatch {
		if (exec) {
			if (exec->pi.hProcess)
				CloseHandle(exec->pi.hProcess);
			if (exec->pi.hThread)
				CloseHandle(exec->pi.hThread);
			if (exec->hWritePipe)
				CloseHandle(exec->hWritePipe);
			if (exec->hReadPipe)
				CloseHandle(exec->hReadPipe);
			FskMemPtrDispose(exec);
		}
		FskMemPtrDispose(environment);
		FskMemPtrDispose(directory);
		FskMemPtrDispose(command);
		xsThrow(xsException);
	}
}
Пример #16
0
void KPR_Shell_patch(xsMachine* the)
{
	xsVars(1);
	xsResult = xsGet(xsGlobal, xsID("system"));
	xsVar(0) = xsNewInstanceOf(xsObjectPrototype);
	xsNewHostProperty(xsVar(0), xsID("arrow"), xsInteger(kFskCursorArrow), xsDefault, xsDontScript);
	xsNewHostProperty(xsVar(0), xsID("aliasArrow"), xsInteger(kFskCursorAliasArrow), xsDefault, xsDontScript);
	xsNewHostProperty(xsVar(0), xsID("copyArrow"), xsInteger(kFskCursorCopyArrow), xsDefault, xsDontScript);
	xsNewHostProperty(xsVar(0), xsID("wait"), xsInteger(kFskCursorWait), xsDefault, xsDontScript);
	xsNewHostProperty(xsVar(0), xsID("iBeam"), xsInteger(kFskCursorIBeam), xsDefault, xsDontScript);
	xsNewHostProperty(xsVar(0), xsID("notAllowed"), xsInteger(kFskCursorNotAllowed), xsDefault, xsDontScript);
	xsNewHostProperty(xsVar(0), xsID("resize"), xsInteger(kFskCursorResizeAll), xsDefault, xsDontScript);
	xsNewHostProperty(xsVar(0), xsID("resizeEW"), xsInteger(kFskCursorResizeLeftRight), xsDefault, xsDontScript);
	xsNewHostProperty(xsVar(0), xsID("resizeNS"), xsInteger(kFskCursorResizeTopBottom), xsDefault, xsDontScript);
	xsNewHostProperty(xsVar(0), xsID("resizeNESW"), xsInteger(kFskCursorResizeNESW), xsDefault, xsDontScript);
	xsNewHostProperty(xsVar(0), xsID("resizeNWSE"), xsInteger(kFskCursorResizeNWSE), xsDefault, xsDontScript);			
	xsNewHostProperty(xsVar(0), xsID("link"), xsInteger(kFskCursorLink), xsDefault, xsDontScript);			
	xsNewHostProperty(xsVar(0), xsID("resizeColumn"), xsInteger(kFskCursorResizeColumn), xsDefault, xsDontScript);			
	xsNewHostProperty(xsVar(0), xsID("resizeRow"), xsInteger(kFskCursorResizeRow), xsDefault, xsDontScript);			
	xsNewHostProperty(xsResult, xsID("cursors"), xsVar(0), xsDefault, xsDontScript);
}