void MarkupTextManager::GetVariableValue(StringId name, char* buffer, int bufferSize) { StrCpy(buffer,""); const RegisteredVariable* variable=FindRegisteredVariable(name); if (!variable) { return; } if (variable->intValue) { if (*variable->intValue!=0) { SNPrintF(buffer,bufferSize,"%d",*(variable->intValue)); } } else if (variable->stringIdValue) { if (variable->stringIdValue->GetString()!=0) { SNPrintF(buffer,bufferSize,"%s",variable->stringIdValue->GetString()); } } }
void MarkupTextManager::GetVariableValue(StringId name, int index, char* buffer, int bufferSize) { StrCpy(buffer,""); const RegisteredVariable* variable=FindRegisteredVariable(name); if (!variable) { return; } if (variable->intArray) { if (index>=0 && index<variable->intArray->GetItemCount() && variable->intArray->Get(index)!=0) { SNPrintF(buffer,bufferSize,"%d",variable->intArray->Get(index)); } } else if (variable->stringIdArray) { if (index>=0 && index<variable->stringIdArray->GetItemCount() && variable->stringIdArray->Get(index)!=0) { SNPrintF(buffer,bufferSize,"%s",variable->stringIdArray->Get(index).GetString()); } } }
int OS::StackWalk(Vector<OS::StackFrame> frames) { int frames_size = frames.length(); void** addresses = NewArray<void*>(frames_size); int frames_count = backtrace(addresses, frames_size); char** symbols; symbols = backtrace_symbols(addresses, frames_count); if (symbols == NULL) { DeleteArray(addresses); return kStackWalkError; } for (int i = 0; i < frames_count; i++) { frames[i].address = addresses[i]; // Format a text representation of the frame based on the information // available. SNPrintF(MutableCStrVector(frames[i].text, kStackWalkMaxTextLen), "%s", symbols[i]); // Make sure line termination is in place. frames[i].text[kStackWalkMaxTextLen - 1] = '\0'; } DeleteArray(addresses); free(symbols); return frames_count; }
const char* AssetEnumerator::GetSubdirectoryName(int index) { if (directory_) { const char* dirname=directory_->GetSubdirectory(index); int size=StrLen(directory_->GetPath())+StrLen(dirname)+2; if (!nameBuffer_ || nameBufferSize_<size) { if (nameBuffer_) { delete nameBuffer_; } nameBufferSize_=size; nameBuffer_=new char[nameBufferSize_]; } SNPrintF(nameBuffer_,nameBufferSize_,"%s/%s",directory_->GetPath(), dirname); return nameBuffer_; } if (archiveDirectory_) { return archiveDirectory_->GetSubdirectory(index).GetString(); } return 0; }
AudioFormat_YM::AudioFormat_YM(const Asset& asset): ymFile_(0), chunkStart_(0), chunkEnd_(0) { if (asset.Open()) { int size=asset.GetSize(); unsigned char* buffer=static_cast<unsigned char*>(Malloc(size)); asset.Read(buffer,size); asset.Close(); ymFile_=new CYmMusic(); ymFile_->loadMemory(buffer,size); ymFile_->setLoopMode(true); ymFile_->play(); Free(buffer); } // Report missing file #ifdef _DEBUG else { const char* filename=asset.GetFilename().GetString(); if (filename) { char errorMessage[1024]; SNPrintF(errorMessage,1024,"File not found: %s",filename); Assert(false,errorMessage); } else { Assert(false,"An asset could not be accessed."); } } #endif }
void Bitmap_RLE8::Load(const Asset& asset) { if (asset.Open()) { char header[8]; asset.Read(header,8); if (StrNCmp(header,"PIXRLE8B",8)==0) { int version=0; asset.Read(&version); if (version==0) { int celCount=0; asset.Read(&celCount); if (celCount>=1) { ReadFromAsset(&asset); } } } else if (StrNCmp(header,"PIXIE_RL",8)==0) { char c; asset.Read(&c); int version=0; asset.Read(&version); if (version==0) { int celCount=0; asset.Read(&celCount); if (celCount>=1) { ReadFromAsset(&asset); } } } else { Assert(false,"Invalid RLE header"); } } // Report missing file #ifdef _DEBUG else { const char* filename=asset.GetFilename().GetString(); if (filename) { char errorMessage[1024]; SNPrintF(errorMessage,1024,"File not found: %s",filename); Assert(false,errorMessage); } else { Assert(false,"An asset could not be accessed."); } } #endif }
void HTTP::Update(float deltaTime) { for (int i=0; i<requests_.GetItemCount(); i++) { Request* request=requests_.Get(i); // Process the request depending on its current status switch (request->status) { case Status_Connecting: { if (request->connection && request->connection->IsConnected()) { // Define the template for HTTP Get header const char* headerGet="GET %s HTTP/1.0\r\nHost: %s:%d\r\n\r\n"; const char* headerPost="POST %s HTTP/1.0\r\nHost: %s:%d\r\nContent-Length: %d\r\n\r\n"; const char* header=0; if (request->usingGetMethod) { header=headerGet; } else { header=headerPost; } // Calculate maximum length of request string int maxLength=StrLen(header)+StrLen(request->requestString)+StrLen(request->connection->GetAddress())+10; // Build request string char* requestString=new char[maxLength]; SNPrintF(requestString,maxLength,header,request->requestString,request->connection->GetAddress(),request->connection->GetPort(),request->postData.GetSize()); // Send HTTP request request->connection->SendData(requestString,StrLen(requestString)); if (!request->usingGetMethod) { request->connection->SendData(request->postData.GetPointer(),request->postData.GetSize()); } // Release request string delete[] requestString; // Change request status to wait for result request->status=Status_Pending; } } break; case Status_Pending: { // Are there any data to receive? if (request->connection && request->connection->GetReceivedDataSize()>0) { // Is this the first chunk of data we receive? bool firstChunk=false; if (request->receivedData.GetSize()==0) { firstChunk=true; } // Receive the data (will be added to the end of the buffer) request->connection->GetReceivedData(&request->receivedData); // If this is the first chunk we receive, we need to process the header if (firstChunk) { // Check Status Line char* statusLine=static_cast<char*>(request->receivedData.GetPointer()); // Get header size int headerSize=0; const char* headerEnd=StrStr(statusLine,"\r\n\r\n"); if (headerEnd) { headerEnd+=4; headerSize=(int)(headerEnd-statusLine); } // Extract httpVersion char httpVersion[256]; const char* ptr=StrChr(statusLine,' '); StrNCpy(httpVersion,statusLine,Min((int)(ptr-statusLine),255)); httpVersion[ptr-statusLine]=0; ptr++; // Extract statusCode char statusCode[256]; const char* ptr2=StrChr(ptr,' '); StrNCpy(statusCode,ptr,Min((int)(ptr2-ptr),255)); statusCode[ptr2-ptr]=0; ptr2++; // Extract reasonPhrase char reasonPhrase[256]; const char* ptr3=StrStr(ptr2,"\r\n"); StrNCpy(reasonPhrase,ptr2,Min((int)(ptr3-ptr2),255)); reasonPhrase[ptr3-ptr2]=0; ptr3++; // Extract contentLength char contentLengthStr[256]; StrCpy(contentLengthStr,"0"); const char* ptr4=StrStr(ptr3,"Content-Length: "); if (ptr4) { ptr4+=16; const char* ptr5=StrStr(ptr4,"\r\n"); StrNCpy(contentLengthStr,ptr4,Min((int)(ptr5-ptr4),255)); contentLengthStr[ptr5-ptr4]=0; } char contentTypeStr[256]; StrCpy(contentTypeStr,""); const char* ptr6=StrStr(ptr3,"Content-Type: "); if (ptr6) { ptr6+=14; const char* ptr7=StrStr(ptr6,"\r\n"); StrNCpy(contentTypeStr,ptr6,Min((int)(ptr7-ptr6),255)); contentTypeStr[ptr7-ptr6]=0; } // Check status int status=StringToInt(statusCode); int contentLength=StringToInt(contentLengthStr); StringId contentType=StringId(contentTypeStr); if (status!=200 || contentLength==0 || contentType==StringId("")) { request->status=Status_Failed; } else { request->headerLength=headerSize; request->contentType=contentType; request->contentLength=contentLength; } } // Check for dropped connection if (!request->connection->IsConnected()) { request->status=Status_Failed; } // Check if we've received the whole resource if (request->status!=Status_Failed && request->receivedData.GetSize()==(unsigned int)request->contentLength+request->headerLength) { request->status=Status_Completed; if (request->resource) { delete request->resource; } char* data=static_cast<char*>(request->receivedData.GetPointer()); data+=request->headerLength; StaticBuffer buffer(data,request->contentLength); request->resource=new HTTP_Resource(request->handle,request->contentType,buffer); } } } break; } if (request->status==Status_Connecting || request->status==Status_Pending) { // Increase the elapsed time request->elapsedTime_+=deltaTime; if (request->timeOut_>0.0f && request->elapsedTime_>request->timeOut_) { request->status=Status_TimedOut; } } } }