void xscAppend1(txMachine* the, txByte theValue) { xsBuffer* aBuffer = xsGetContext(the); xscGrowBuffer(the, aBuffer, 1); *(aBuffer->current) = theValue; aBuffer->current++; }
void KPR_Message_URI(xsMachine* the) { char* url = NULL; xsThrowIfFskErr(KprMessageURL(xsGetContext(the), xsToString(xsArg(0)), &url)); xsResult = xsString(url); FskMemPtrDispose(url); }
void xscAppend(txMachine* the, txByte* theData, txSize theSize) { xsBuffer* aBuffer = xsGetContext(the); xscGrowBuffer(the, aBuffer, theSize); memmove(aBuffer->current, theData, theSize); aBuffer->current += theSize; }
void xscDeleteBuffer(txMachine* the) { xsBuffer* aBuffer = xsGetContext(the); if (aBuffer) { if (aBuffer->bottom) c_free(aBuffer->bottom); if (aBuffer->symbols) c_free(aBuffer->symbols); c_free(aBuffer); xsSetContext(the, NULL); } }
void xscAppendString(txMachine* the, txString theString) { txID aLength = strlen(theString) + 1; xsBuffer* aBuffer = xsGetContext(the); xscGrowBuffer(the, aBuffer, aLength+1+stringCommandOffset); *(aBuffer->current) = XS_STRING; aBuffer->current++; #if mxStringLength mxEncode2(aBuffer->current, aLength); #endif memmove(aBuffer->current, theString, aLength); aBuffer->current += aLength; }
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 xscAppend8(txMachine* the, txNumber theValue) { xsBuffer* aBuffer = xsGetContext(the); xscGrowBuffer(the, aBuffer, 8); mxEncode8(aBuffer->current, theValue); }
void xscAppend4(txMachine* the, txInteger theValue) { xsBuffer* aBuffer = xsGetContext(the); xscGrowBuffer(the, aBuffer, 4); mxEncode4(aBuffer->current, theValue); }
void xscAppend2(txMachine* the, txID theValue) { xsBuffer* aBuffer = xsGetContext(the); xscGrowBuffer(the, aBuffer, 2); mxEncode2(aBuffer->current, theValue); }
void xscBuildSymbols(txMachine* the) { xsBuffer* aBuffer = xsGetContext(the); xsSymbolsData* data = NULL; FILE* aFile = NULL; txInteger aSize; txString aString = NULL; txID aCount; txID anID; txSlot* aSymbol; txSize aModulo; txSlot* result; txID anIndex; txByte* aCode; txInteger aLength; txBoolean failed; static char* prefix = "#define xsID_"; static char* suffix = " (the->code["; txInteger prefixLength = c_strlen(prefix); txInteger suffixLength = c_strlen(suffix); mxTry(the) { data = c_calloc(1, sizeof(xsSymbolsData)); xsElseError(data); xsVar(1) = xsCat2(xsVar(0), xsString(".h")); aFile = fopen(xsToString(xsVar(1)), "rb"); if (aFile) { fseek(aFile, 0, SEEK_END); aSize = ftell(aFile); rewind(aFile); aString = c_malloc(aSize + 1); xsElseError(aString); fread(aString, 1, aSize, aFile); aString[aSize] = 0; fclose(aFile); aFile = C_NULL; } aCount = 0; if (aString) { txString p = c_strstr(aString, prefix), q; while (p) { p += prefixLength; q = c_strstr(p, suffix); q += suffixLength; anID = c_strtol(q, &p, 10); if (aCount <= anID) aCount = anID + 1; p = c_strstr(p, prefix); } } if (aCount < the->symbolCount) aCount = the->symbolCount; data->symbolCount = aCount; data->symbolIndex = 0; data->symbolArray = c_calloc(aCount, sizeof(txSlot*)); xsElseError(data->symbolArray); data->symbolModulo = the->symbolModulo; data->symbolTable = c_calloc(the->symbolModulo, sizeof(txSlot*)); xsElseError(data->symbolTable); if (aString) { txString p = c_strstr(aString, prefix), q; while (p) { p += prefixLength; q = c_strstr(p, suffix); *q = 0; aSymbol = fxNewSymbolC(the, p); aModulo = aSymbol->value.symbol.sum % data->symbolModulo; q += suffixLength; anID = c_strtol(q, &p, 10); xscBuildSymbol(the, data, aSymbol, anID, aModulo); data->symbolIndex = anID + 1; p = c_strstr(p, prefix); } c_free(aString); aString = C_NULL; } aCount = the->symbolIndex; anID = 0; for (anIndex = 0; anIndex < aCount; anIndex++) { aSymbol = the->symbolArray[anIndex]; if (aSymbol->flag & XS_TO_C_FLAG) { aModulo = aSymbol->value.symbol.sum % data->symbolModulo; result = data->symbolTable[aModulo]; while (result != C_NULL) { if (result->value.symbol.sum == aSymbol->value.symbol.sum) #if mxCmpStr if (result->value.symbol.string == aSymbol->value.symbol.string) #endif break; result = result->next; } if (result == C_NULL) { while (data->symbolArray[anID]) anID++; xscBuildSymbol(the, data, aSymbol, anID, aModulo); if (data->symbolIndex <= anID) data->symbolIndex = anID + 1; } } } aCount = data->symbolIndex; anIndex = 0; while (anID < aCount) { while ((anID < aCount) && data->symbolArray[anID]) anID++; if (anID < aCount) { char aName[16]; sprintf(aName, "@%d", anIndex); aSymbol = fxNewSymbolC(the, aName); aModulo = aSymbol->value.symbol.sum % data->symbolModulo; xscBuildSymbol(the, data, aSymbol, anID, aModulo); } } aCode = aBuffer->bottom; xscBuildSymbolsCode(the, data, aCode); aCount = data->symbolIndex; aSize = 2; for (anIndex = 0; anIndex < aCount; anIndex++) aSize += strlen(data->symbolArray[anIndex]->value.symbol.string) + symbolEncodeLength + 1; aBuffer->symbols = c_malloc(aSize); xsElseError(aBuffer->symbols); aBuffer->symbolsSize = aSize; aCode = aBuffer->symbols; mxEncode2(aCode, aCount); for (anIndex = 0; anIndex < aCount; anIndex++) { aString = data->symbolArray[anIndex]->value.symbol.string; aLength = strlen(aString) + 1; memcpy(aCode, aString, aLength); aCode += aLength; #if mxUseApHash mxEncode4(aCode,data->symbolArray[anIndex]->value.symbol.sum); #endif } aString = C_NULL; failed = 0; } mxCatch(the) { failed = 1; } if (data) { if (data->symbolTable) c_free(data->symbolTable); if (data->symbolArray) { aCount = data->symbolIndex; for (anIndex = 0; anIndex < aCount; anIndex++) c_free(data->symbolArray[anIndex]); c_free(data->symbolArray); } if (aString) c_free(aString); if (aFile) fclose(aFile); c_free(data); } if (failed) xsThrow(xsException); }