void KPR_path2D_bezierCurveTo(xsMachine *the) { FskCanvas2dPath path = xsGetHostData(xsThis); xsNumberValue cp1x = xsToNumber(xsArg(0)); xsNumberValue cp1y = xsToNumber(xsArg(1)); xsNumberValue cp2x = xsToNumber(xsArg(2)); xsNumberValue cp2y = xsToNumber(xsArg(3)); xsNumberValue x = xsToNumber(xsArg(4)); xsNumberValue y = xsToNumber(xsArg(5)); FskCanvas2dPathBezierCurveTo(NULL, path, cp1x, cp1y, cp2x, cp2y, x, y); }
void KPR_Message(xsMachine* the) { xsStringValue url = NULL; KprMessage self = NULL; xsTry { xsThrowIfFskErr(KprMessageURL(xsGetContext(the), xsToString(xsArg(0)), &url)); xsThrowIfFskErr(KprMessageNew(&self, url)); xsSetHostData(xsThis, self); FskInstrumentedItemSendMessageDebug(self, kprInstrumentedMessageConstruct, self); self->usage++; // host FskMemPtrDispose(url); } xsCatch { FskMemPtrDispose(url); xsThrow(xsException); } }
void xs_tftpd_connect(xsMachine *the) { int s; void *instance; xsVars(1); xsGet(xsVar(0), xsArg(0), xsID("nativeSocket")); s = xsToInteger(xsVar(0)); instance = tftpd_connect(s, the, &xsThis); if (instance == NULL) { xsSetBoolean(xsResult, 0); return; } xsSetHostData(xsThis, instance); xsSetBoolean(xsResult, 1); }
void kprGrammar_countLines(xsMachine* the) { char* aString; char c; int i = 0; aString = xsToString(xsArg(0)); while ((c = *aString)) { if (c <= 0x20) { if (c == 0x0A) i++; } else break; aString++; } xsResult = xsInteger(i); }
void kpr2jsLoad(xsMachine* the) { char* aPath; FILE* aFile = NULL; xsTry { aPath = xsToString(xsArg(0)); aFile = fopen(aPath, "r"); xsElseError(aFile); xsResult = xsParse(aFile, (xsGetter)fgetc, aPath, 1, xsSourceFlag | xsDebugFlag); fclose(aFile); } xsCatch { if (aFile) fclose(aFile); xsThrow(xsException); } }
void xs_env_next(xsMachine *the) { char *p = xsGetHostData(xsThis); char *pattern = xsToInteger(xsArgc) > 0 ? xsToString(xsArg(0)) : NULL; while (*p != '\0') { char *name = p; p += strlen(p) + 1; p += strlen(p) + 1; if (pattern == NULL || *pattern == '\0' || strncmp(name, pattern, strlen(pattern)) == 0) { xsSetString(xsResult, name); xsSetHostData(xsThis, p); return; } } xsSetNull(xsResult); }
void xs_i2c_readByteDataSMB(xsMachine *the) { xsI2C i2c = xsGetHostData(xsThis); FskErr err; UInt8 command = (UInt8)xsToInteger(xsArg(0)); UInt8 byte; DBG_I2C("xs_i2c_readByteDataSMB Reading byte from %u\n", reg); xsThrowIfNULL(i2c); FskPinI2CSetAddress(i2c->pin, i2c->address); err = FskPinI2CReadDataByte(i2c->pin, command, &byte); xsThrowDiagnosticIfFskErr(err, "I2C readByteDataSMB register %d failed %s.", (int)command, i2c->diagnosticID); xsResult = xsInteger(byte); }
void KPR_system_set_backGesture(xsMachine *the) { FskErr err = kFskErrNone; char* path = NULL; char* pathName = NULL; FskFile file = NULL; char* data = xsToString(xsArg(0)); xsIntegerValue size = FskStrLen(data); #if MINITV pathName = TOUCHD_CONF; // system("/etc/init.d/touchd.sh stop"); #else bailIfError(FskDirectoryGetSpecialPath(kFskDirectorySpecialTypeApplicationPreference, true, NULL, &path)); pathName = FskStrDoCat(path, "touchd.conf"); bailIfNULL(pathName); #endif err = FskFileOpen(pathName, kFskFilePermissionReadWrite, &file); if (kFskErrFileNotFound == err) { bailIfError(FskFileCreate(pathName)); err = FskFileOpen(pathName, kFskFilePermissionReadWrite, &file); } else { FskInt64 zero = 0; err = FskFileSetSize(file, &zero); } bailIfError(err); bailIfError(FskFileWrite(file, size, data, NULL)); bail: FskFileClose(file); #if MINITV int pipe = open(TOUCH_PIPE, O_WRONLY | O_NONBLOCK); if (pipe >= 0) { char data = 1; write(pipe, &data, 1); close(pipe); } // system("/etc/init.d/touchd.sh start"); #endif if (path) { FskMemPtrDispose(path); FskMemPtrDispose(pathName); } xsThrowIfFskErr(err); }
void xs_parse(xsMachine* the) { xsIntegerValue c = xsToInteger(xsArgc); xsVars(2); if (c < 1) xsSyntaxError("no buffer"); xsVar(0) = xsGet(xsGet(xsGlobal, xsID_xs), xsID_infoset); if (c > 3) xsVar(1) = xsCall3(xsVar(0), xsID_scan, xsArg(0), xsArg(2), xsArg(3)); else if (c > 2) xsVar(1) = xsCall2(xsVar(0), xsID_scan, xsArg(0), xsArg(2)); else if (c > 1) xsVar(1) = xsCall1(xsVar(0), xsID_scan, xsArg(0)); else xsVar(1) = xsCall1(xsVar(0), xsID_scan, xsArg(0)); if (c > 1) xsResult = xsCall2(xsVar(0), xsID_parse, xsVar(1), xsArg(1)); else xsResult = xsCall1(xsVar(0), xsID_parse, xsVar(1)); }
void KPR_canvasRenderingContext2D_isPointInPath(xsMachine *the) { FskCanvas2dContext ctx = xsGetHostData(xsThis); FskCanvas2dPath path = NULL; SInt32 fillRule = kFskCanvas2dFillRuleNonZero; int numArgs = xsToInteger(xsArgc); xsNumberValue x, y; if (xsIsInstanceOf(xsArg(0), xsGet(xsGet(xsGlobal, xsID_KPR), xsID("path2D")))) { /* ctx.isPointInPath(path, x, y) */ path = xsGetHostData(xsArg(0)); x = xsToNumber(xsArg(1)); y = xsToNumber(xsArg(2)); if (numArgs > 3) fillRule = GetFillRule(xsToString(xsArg(3))); /* ctx.isPointInPath(path, x, y, fillRule) */ } else { /* ctx.isPointInPath(x, y) */ x = xsToNumber(xsArg(0)); y = xsToNumber(xsArg(1)); if (numArgs > 2) fillRule = GetFillRule(xsToString(xsArg(2))); /* ctx.isPointInPath(x, y, fillRule) */ } xsResult = xsBoolean(FskCanvas2dIsPointInPathFill(ctx, path, x, y, fillRule)); }
void xs_i2c_readWordDataSMB(xsMachine *the) { xsI2C i2c = xsGetHostData(xsThis); UInt8 command = (UInt8)xsToInteger(xsArg(0)); FskErr err; UInt16 val; DBG_I2C("xs_i2c_readWordDataSMB Call SMB to register %d\n", command); xsThrowIfNULL(i2c); FskPinI2CSetAddress(i2c->pin, i2c->address); err = FskPinI2CReadDataWord(i2c->pin, command, &val); //@@ if (! (i2c->address == 0x36) ) xsTraceDiagnostic("I2C readWordDataSMB register %d failed %s.", (int)reg, i2c->diagnosticID); xsThrowDiagnosticIfFskErr(err, "I2C readWordDataSMB register %d failed %s.", (int)command, i2c->diagnosticID); xsResult = xsInteger(val); }
void xs_i2c_writeBlock(xsMachine* the) { FskErr err; xsI2C i2c = xsGetHostData(xsThis); int argc = xsToInteger(xsArgc), i; UInt8 buffer[32], *bufPtr = buffer; xsThrowIfNULL(i2c); DBG_I2C("xs_i2c_writeBlock\n"); for (i = 0; i < argc; i++) bufPtr = writeOne(the, i2c, &xsArg(i), bufPtr, buffer + sizeof(buffer)); FskPinI2CSetAddress(i2c->pin, i2c->address); err = FskPinI2CWriteBytes(i2c->pin, bufPtr - buffer, buffer); xsThrowDiagnosticIfFskErr(err, "I2C FskI2CWriteBlock failed with error %s %s.", FskInstrumentationGetErrorString(err), i2c->diagnosticID); }
void xsToolIsKPR(xsMachine* the) { char* aPath; FILE* aFile = NULL; size_t aSize = 1024; char aBuffer[1024]; aPath = xsToString(xsArg(0)); aFile = fopen(aPath, "r"); xsElseError(aFile); aSize = fread(aBuffer, 1, aSize, aFile); if (aSize) { aBuffer[aSize - 1] = 0; xsResult = (strstr(aBuffer, "xmlns=\"http://www.kinoma.com/kpr/1\"") && !strstr(aBuffer, "<application") && !strstr(aBuffer, "<device")) ? xsTrue : xsFalse; } else xsResult = xsFalse; fclose(aFile); }
void KPR_system_setClipboardText(xsMachine* the) { HWND window = (HWND)FskWindowGetNativeWindow(gShell->window); xsStringValue string, src, buffer, dst; char c; xsIntegerValue length; HGLOBAL data; if (OpenClipboard(window)) { EmptyClipboard(); if (xsToInteger(xsArgc) > 0) { string = xsToString(xsArg(0)); src = string; length = 0; while ((c = *src++)) { length++; if (c == 10) length++; } length++; if (FskMemPtrNew(length, &buffer) == kFskErrNone) { src = string; dst = buffer; while ((c = *src++)) { if (c == 10) *dst++ = 13; *dst++ = c; } *dst = 0; length = MultiByteToWideChar(CP_UTF8, 0, buffer, -1, NULL, 0); data = GlobalAlloc(GMEM_MOVEABLE, 2 * length); if (data) { MultiByteToWideChar(CP_UTF8, 0, buffer, -1, (LPWSTR)GlobalLock(data), length); GlobalUnlock(data); SetClipboardData(CF_UNICODETEXT, data); } FskMemPtrDispose(buffer); } } CloseClipboard(); } }
void xsToolInsertProperty(xsMachine* the) { xsStringValue aString; xsIntegerValue aSum; aString = xsToString(xsArg(0)); aSum = 0; while(*aString != 0) { aSum = (aSum << 1) + *aString++; } aSum &= 0x7FFFFFFF; xsResult = gxProperties[aSum % mxPropertyModulo]; if (xsTypeOf(xsResult) == xsReferenceType) (void)xsCall3(xsResult, xsID("insertProperty"), xsArg(0), xsArg(1), xsArg(2)); else { gxProperties[aSum % mxPropertyModulo] = xsArg(1); xsSet(xsArg(1), xsID("qualifiedName"), xsArg(0)); } }
void xs_wdt_start(xsMachine *the) { int index = xsToInteger(xsArg(0)); WDT_Config_Type cfg; cfg.timeoutVal = index; cfg.mode = WDT_MODE_RESET; cfg.resetPulseLen = WDT_RESET_PULSE_LEN_2; WDT_Init(&cfg); CLK_ModuleClkEnable(CLK_WDT); #if defined(CONFIG_CPU_MW300) /* For 88MW300, APB1 bus runs at 50MHz whereas for 88MC200 it runs at * 25MHz, hence following clk divider is added to keep timeout same. */ CLK_ModuleClkDivider(CLK_WDT, 1); #endif WDT_Enable(); wdt_enable = 1; }
void xs_dbg_report(xsMachine *the) { if (xsToInteger(xsArgc) > 0 && xsTest(xsArg(0))) { /* silence - return the memory use */ xsMemoryUse slot, chunk; xsReportMemoryUse(the, &slot, &chunk); xsVars(1); xsResult = xsNewInstanceOf(xsObjectPrototype); xsSetInteger(xsVar(0), chunk.current); xsSet(xsResult, xsID("chunk"), xsVar(0)); xsSetInteger(xsVar(0), slot.current); xsSet(xsResult, xsID("slot"), xsVar(0)); } else { #if mxMC mc_mstats(true); #endif xsReportMemoryUse(the, NULL, NULL); } }
void KPR_canvasRenderingContext2D_isPointInPathStroke(xsMachine *the) { FskCanvas2dContext ctx = xsGetHostData(xsThis); FskCanvas2dPath path = NULL; xsNumberValue x, y; if (xsIsInstanceOf(xsArg(0), xsGet(xsGet(xsGlobal, xsID_KPR), xsID("path2D")))) { /* ctx.isPointInPathStroke(path, x, y) */ path = xsGetHostData(xsArg(0)); x = xsToNumber(xsArg(1)); y = xsToNumber(xsArg(2)); } else { /* ctx.isPointInPathStroke(x, y) */ x = xsToNumber(xsArg(0)); y = xsToNumber(xsArg(1)); } xsResult = xsBoolean(FskCanvas2dIsPointInPathStroke(ctx, path, x, y)); }
void KPR_system_networkInterfaceIndexToName(xsMachine* the) { SInt32 index = xsToInteger(xsArg(0)); PIP_ADAPTER_ADDRESSES pAddresses = NULL, pAddress; ULONG flags = GAA_FLAG_INCLUDE_PREFIX; ULONG family = AF_INET; ULONG outBufLen = sizeof(IP_ADAPTER_ADDRESSES); BAIL_IF_ERR(FskMemPtrNewClear(outBufLen, &pAddresses)); if (GetAdaptersAddresses(family, flags, NULL, pAddresses, &outBufLen) == ERROR_BUFFER_OVERFLOW) { FskMemPtrDispose(pAddresses); BAIL_IF_ERR(FskMemPtrNewClear(outBufLen, &pAddresses)); } if (GetAdaptersAddresses(family, flags, NULL, pAddresses, &outBufLen) == NO_ERROR) { for (pAddress = pAddresses; pAddress; pAddress = pAddress->Next) if (pAddress->IfIndex == index) break; } if (pAddress) xsResult = xsString(pAddress->AdapterName); bail: FskMemPtrDispose(pAddresses); return; }
void KPR_canvasRenderingContext2D_putImageData(xsMachine *the) { FskCanvas2dContext ctx = xsGetHostData(xsThis); FskCanvas2dImageData data = xsGetHostData(xsArg(0)); xsNumberValue dx = xsToNumber(xsArg(1)); xsNumberValue dy = xsToNumber(xsArg(2)); xsNumberValue dirtyX, dirtyY, dirtyWidth, dirtyHeight; if (xsToInteger(xsArgc) > 6) { dirtyX = xsToNumber(xsArg(3)); dirtyY = xsToNumber(xsArg(4)); dirtyWidth = xsToNumber(xsArg(5)); dirtyHeight = xsToNumber(xsArg(6)); } else { dirtyX = 0; dirtyY = 0; dirtyWidth = data->width; dirtyHeight = data->height; } FskCanvas2dPutImageData(ctx, data, dx, dy, dirtyX, dirtyY, dirtyWidth, dirtyHeight); }
void KPR_WebSocketClient(xsMachine* the) { FskErr err; xsIntegerValue c = xsToInteger(xsArgc); KPR_WebSocketClientRecord *self = NULL; KprWebSocketEndpoint endpoint = NULL; bailIfError(FskMemPtrNewClear(sizeof(KPR_WebSocketClientRecord), &self)); xsThrowIfFskErr(KprWebSocketEndpointNew(&endpoint, self)); endpoint->openCallback = KPR_WebSocketClient_onOpen; endpoint->closeCallback = KPR_WebSocketClient_onClose; endpoint->textCallback = KPR_WebSocketClient_onTextMessage; endpoint->binaryCallback = KPR_WebSocketClient_onBinaryMessage; endpoint->errorCallback = KPR_WebSocketClient_onError; self->endpoint = endpoint; self->the = the; self->slot = xsThis; self->code = the->code; xsSetHostData(self->slot, self); // xsCall1(xsGet(xsGlobal, xsID_Object), xsID_seal, self->slot); if (c >= 1) { bailIfError(KprWebSocketEndpointConnect(endpoint, xsToString(xsArg(0)), NULL)); } xsRemember(self->slot); return; bail: KprWebSocketEndpointDispose(endpoint); FskMemPtrDispose(self); xsThrowIfFskErr(err); }
void KPR_debug_toggle(xsMachine *the) { KprDebug self = xsGetHostData(xsThis); KprDebugMachine machine = NULL; int command = mxNoCommand; char* path = NULL; char* value = NULL; xsIntegerValue c = xsToInteger(xsArgc); if ((c >= 4) && (xsTypeOf(xsArg(0)) == xsStringType) && (xsTypeOf(xsArg(1)) == xsIntegerType) && (xsTypeOf(xsArg(3)) == xsStringType)) { char* address = xsToString(xsArg(0)); command = xsToInteger(xsArg(1)); if (xsTypeOf(xsArg(2)) == xsStringType) path = FskStrDoCopy(xsToString(xsArg(2))); value = FskStrDoCopy(xsToString(xsArg(3))); machine = KprDebugFindMachine(self, address); } if (machine && ((command == mxLocalsView) || (command == mxGlobalsView) || (command == mxGrammarsView)) && value) KprDebugMachineDispatchCommand(machine, command, path, value, 0); else xsThrowIfFskErr(kFskErrInvalidParameter); FskMemPtrDispose(value); FskMemPtrDispose(path); }
void kpr2jsMakePath(xsMachine* the) { char aPath[1024]; int aLength; char* aString; aPath[0] = 0; if (xsTypeOf(xsArg(0)) == xsStringType) { aString = xsToString(xsArg(0)); aLength = strlen(aString); if (aLength > 0) { strcat(aPath, aString); if (aPath[aLength - 1] != mxSeparator) { aPath[aLength] = mxSeparator; aPath[aLength + 1] = 0; } } } if (xsTypeOf(xsArg(1)) == xsStringType) { aString = xsToString(xsArg(1)); strcat(aPath, aString); } if (xsTypeOf(xsArg(2)) == xsStringType) { aString = xsToString(xsArg(2)); aLength = strlen(aString); if (aLength > 0) { if (aString[0] != '.') strcat(aPath, "."); strcat(aPath, aString); } } #if mxWindows aString = aPath; while (*aString) { if (*aString == '/') *aString = '\\'; aString++; } #endif xsResult = xsString(aPath); }
void Zeroconf_Advertisement(xsMachine *the) { KprZeroconfAdvertisement self = NULL; char* serviceType = xsToString(xsArg(0)); char* servicName = xsToString(xsArg(1)); int servicPort = xsToInteger(xsArg(2)); xsIntegerValue c = xsToInteger(xsArgc); FskAssociativeArray txt = NULL; if ((c > 3) && xsIsInstanceOf(xsArg(3), xsObjectPrototype)) { xsVars(2); xsEnterSandbox(); fxPush(xsArg(3)); fxRunForIn(the); txt = FskAssociativeArrayNew(); for (xsVar(0) = fxPop(); xsTypeOf(xsVar(0)) != xsNullType; xsVar(0) = fxPop()) { if (xsTypeOf(xsVar(0)) == xsStringType) { xsVar(1) = xsGetAt(xsArg(3), xsVar(0)); if (!xsIsInstanceOf(xsVar(1), xsObjectPrototype)) { char* name = xsToString(xsVar(0)); char* value = xsToString(xsVar(1)); FskAssociativeArrayElementSetString(txt, name, value); } } } xsLeaveSandbox(); } xsThrowIfFskErr(KprZeroconfAdvertisementNew(&self, serviceType, servicName, servicPort, txt)); xsSetHostData(xsResult, self); self->registeredCallback = Zeroconf_advertisement_registeredCallback; self->unregisteredCallback = Zeroconf_advertisement_unregisteredCallback; self->the = the; self->slot = xsResult; self->code = the->code; self->behavior = xsUndefined; xsRemember(self->slot); }
void KPR_mqttclient_connect(xsMachine* the) { KPR_MQTTClientRecord *self = xsGetHostData(xsThis); char *host; UInt16 port; KprMQTTClientConnectOptions options; if (xsToInteger(xsArgc) != 10) xsThrowIfFskErr(kFskErrParameterError); host = xsToString(xsArg(0)); port = xsToInteger(xsArg(1)); options.isSecure = xsToBoolean(xsArg(2)); options.keepAlive = xsToInteger(xsArg(3)); options.username = xsTest(xsArg(4)) ? xsToString(xsArg(4)) : NULL; options.password = xsTest(xsArg(5)) ? xsToString(xsArg(5)) : NULL; options.willIsRetained = false; options.willQualityOfService = 0; options.willTopic = NULL; options.willPayload = NULL; options.willPayloadLength = 0; if (xsTest(xsArg(6))) { options.willTopic = xsToString(xsArg(6)); options.willQualityOfService = xsToInteger(xsArg(7)); options.willIsRetained = xsToBoolean(xsArg(8)); if (xsTest(xsArg(9))) { if (isArrayBuffer(xsArg(9))) { options.willPayload = xsToArrayBuffer(xsArg(9)); options.willPayloadLength = xsGetArrayBufferLength(xsArg(9)); } else { options.willPayload = xsToString(xsArg(9)); options.willPayloadLength = FskStrLen(options.willPayload); } } } xsThrowIfFskErr(KprMQTTClientConnect(self->client, host, port, &options)); }
void xs_x509_decodeSubjectKeyId(xsMachine *the) { UInt32 sz = xsToInteger(xsGet(xsArg(0), xsID("length"))); unsigned char *p = xsGetHostData(xsArg(0)), *endp = p + sz, *endTBS, *endEXT, *extnID, *spki, *spk; int l, extnIDLen, spkLen; static UInt8 id_ce_ski[] = {2 * 40 + 5, 29, 14}; /* [2, 5, 29, 14] */ #define getTag() (p < endp ? (int)*p++ : -1) #define getBerLen() _getBerLen(&p, endp) #define nextTag() (getTag(), l = getBerLen(), p += l) if (getTag() != 0x30) return; if ((l = getBerLen()) < 0) return; if (p + l > endp) return; /* TBSCertficate */ if (getTag() != 0x30) return; if ((l = getBerLen()) < 0) return; if ((endTBS = p + l) > endp) return; if (*p & 0x80) { /* EXPLICT Version */ p++; nextTag(); } nextTag(); /* serialNumber */ nextTag(); /* signature */ nextTag(); /* issuer */ nextTag(); /* validity */ nextTag(); /* subject */ spki = p; /* subjectPublicKeyInfo */ nextTag(); /* OPTIONAL */ while (p < endTBS) { int tag = getTag(); if ((l = getBerLen()) < 0) return; switch (tag & 0x1f) { case 1: /* issuerUniqueID */ case 2: /* subjectUniqueID */ p += l; continue; /* goto the next tag */ case 3: /* extensions */ break; /* fall thru */ default: return; } /* must be a SEQUENCE of [1..MAX] */ if (getTag() != 0x30) return; if ((l = getBerLen()) < 0) return; endEXT = p + l; while (p < endEXT) { /* must be a SEQUENCE of {extnID, critical, extnValue} */ if (getTag() != 0x30) return; if ((l = getBerLen()) < 0) return; /* extnID: OBJECT ID */ if (getTag() != 0x06) return; if ((extnIDLen = getBerLen()) < 0) return; extnID = p; p += extnIDLen; /* critical: BOOLEAN */ if (*p == 0x01) nextTag(); /* extnValue: OCTET STRING */ if (getTag() != 0x04) return; if ((l = getBerLen()) < 0) return; if (extnIDLen == sizeof(id_ce_ski) && FskMemCompare(extnID, id_ce_ski, extnIDLen) == 0) { /* SKI: OCTET STRING */ if (getTag() != 0x04) return; l = getBerLen(); xsResult = xsNew1(xsGlobal, xsID("Chunk"), xsInteger(l)); FskMemCopy(xsGetHostData(xsResult), p, l); return; } p += l; } } { /* * Couldn't find Subject Key Identifier. Make up the ID from the Subject Public Key */ struct sha1 sha1; p = spki; if (getTag() != 0x30) return; /* should be a SEQUENCE */ l = getBerLen(); /* skip AlgorithmIdentifier */ nextTag(); if (getTag() != 0x03) return; /* should be a BIT STRING */ spkLen = getBerLen(); spk = p; xsResult = xsNew1(xsGlobal, xsID("Chunk"), xsInteger(SHA1_DGSTSIZE)); sha1_create(&sha1); sha1_update(&sha1, spk, spkLen); sha1_fin(&sha1, xsGetHostData(xsResult)); } }
void console_log(xsMachine* the) { xsIntegerValue c = xsToInteger(xsArgc), i; xsBooleanValue space = 0; xsVars(4); console_log_depth++; for (i = 0; i < c; i++) { if (space) fprintf(stdout, " "); else space = 1; switch (xsTypeOf(xsArg(i))) { case xsUndefinedType: case xsNullType: case xsBooleanType: case xsIntegerType: case xsNumberType: fprintf(stdout, "%s", xsToString(xsArg(i))); break; case xsSymbolType: xsResult = xsCall1(xsGlobal, xsID("String"), xsArg(i)); fprintf(stdout, "%s", xsToString(xsResult)); break; case xsStringType: case xsStringXType: if ((console_log_depth == 1) && (i == 0)) fprintf(stdout, "%s", xsToString(xsArg(i))); else fprintf(stdout, "'%s'", xsToString(xsArg(i))); break; case xsReferenceType: if (console_log_depth < 3) { xsBooleanValue comma = 0; if (xsHas(xsArg(i), xsID("length"))) { xsIntegerValue length = xsToInteger(xsGet(xsArg(i), xsID("length"))), index; fprintf(stdout, "["); for (index = 0; index < length; index++) { if (comma) fprintf(stdout, ","); else comma = 1; fprintf(stdout, " "); if (xsHas(xsArg(i), (xsIndex)index)) { xsVar(1) = xsGet(xsArg(i), (xsIndex)index); fxPush(xsVar(1)); fxPushCount(the, 1); fxPush(xsThis); fxPush(xsFunction); fxCall(the); } } fprintf(stdout, " ]"); } else { fprintf(stdout, "{"); xsVar(0) = xsEnumerate(xsArg(i)); for (;;) { xsVar(1) = xsCall0(xsVar(0), xsID("next")); if (xsTest(xsGet(xsVar(1), xsID("done")))) break; xsVar(2) = xsGet(xsVar(1), xsID("value")); xsVar(3) = xsGetAt(xsArg(i), xsVar(2)); if (comma) fprintf(stdout, ","); else comma = 1; fprintf(stdout, " %s: ", xsToString(xsVar(2))); fxPush(xsVar(3)); fxPushCount(the, 1); fxPush(xsThis); fxPush(xsFunction); fxCall(the); } fprintf(stdout, " }"); } } else fprintf(stdout, "%s", xsToString(xsArg(i))); break; } } console_log_depth--; if (!console_log_depth) fprintf(stdout, "\n"); }
void process_getenv(xsMachine* the) { xsStringValue result = getenv(xsToString(xsArg(0))); if (result) xsResult = xsString(result); }
void print(xsMachine* the) { fprintf(stdout, "%s\n", xsToString(xsArg(0))); }
void kpr2jsOpenFile(xsMachine* the) { FILE* aFile = fopen(xsToString(xsArg(0)), "w"); xsElseError(aFile); xsSetHostData(xsThis, aFile); }