const char* GenmeshAnimationPDLFactory::Load (iDocumentNode* node) { csRef<iSyntaxService> synsrv = csQueryRegistry<iSyntaxService> (type->object_reg); if (!synsrv) return "No iSyntaxService"; csRef<iDocumentNodeIterator> it = node->GetNodes (); while (it->HasNext ()) { csRef<iDocumentNode> child = it->Next (); if (child->GetType () != CS_NODE_ELEMENT) continue; const char* value = child->GetValue (); csStringID id = xmltokens.Request (value); if (id == XMLTOKEN_BUFFER) { // "New" style: a number of <buffer> tags it = node->GetNodes (); while (it->HasNext ()) { child = it->Next (); if (child->GetType () != CS_NODE_ELEMENT) continue; const char* value = child->GetValue (); csStringID id = xmltokens.Request (value); if (id != XMLTOKEN_BUFFER) { parseError.Format ("Unknown token %s", CS::Quote::Single (value)); return parseError; } const char* name = child->GetAttributeValue ("name"); if (!name || !*name) return "No 'name' attribute"; ColorBuffer buf; buf.name = type->strings->Request (name); const char* err = ParseBuffer (synsrv, buf, child); if (err != 0) return err; buffers.Push (buf); } buffers.ShrinkBestFit (); } else { // "Old" style: "color" buffer, at 'top level' ColorBuffer colors; colors.name = type->colorsID; const char* err = ParseBuffer (synsrv, colors, node); if (err != 0) return err; buffers.Push (colors); buffers.ShrinkBestFit (); } break; } return 0; }
int tga_t::Load(const char *name) { FILE *iFile = 0; byte *buffer = 0; uint fSize; if (!(iFile = fopen(name, "rb"))) return notFound; fSize = FileGetSize(iFile); if (!(buffer = new byte[fSize + 1])) { fclose(iFile); return badData; } fread(buffer, 1, fSize, iFile); fclose(iFile); int ret = ParseBuffer(buffer); delete [] buffer; return ret; }
void CommandParser::CheckPort() { if (port->available()) { int b = port->read(); //port->print((char)b); if ((b == '\r') || (b == '\n')) { // Parse line //port->println("Parsing buffer..."); //port->print("Buffer contains: "); port->println(buffer); delay(100); // Reset pointer bPtr = &buffer[0]; ParseBuffer(); } else { if (bPtr - &buffer[0] > MAX_LEN-2) { port->println("Buffer full"); bPtr = &buffer[0]; return; } // Add char to buffer *bPtr++ = (char)b; *bPtr = '\0'; } } else return; }
bool IniParser::ParseFile(const wxString& filename) { if (!wxFileExists(filename)) return false; // open file wxString buffer; wxFile file(filename); if (!file.IsOpened()) return false; int len = file.Length(); if(len==0) buffer.Clear(); else { char* buff = new char[len+1]; file.Read(buff, len); buff[len]='\0'; buffer = wxString(buff,wxConvUTF8); delete[] buff; } file.Close(); return ParseBuffer(buffer); }
void clsCMM::Input() { printf("[CMM] Input start\n"); ADDRESSEDPACKAGE package; while (1) { int nToRead = MAX_CMMBUFFER-m_nBuffer; int nRead = read(m_nsCMM, m_szBuffer+m_nBuffer, nToRead); if (nRead < 0) { nRead = 0; //read returns -1 on occassion of no byte read usleep(20000); continue; } m_nBuffer += nRead; #if (_DEBUG & DEBUGFLAG_CMM) printf("[CMM] ReadCommand, read byte %d, buffer size %d\n", nRead, m_nBuffer); #endif if (ParseBuffer(m_szBuffer, m_nBuffer, &package)) { ProcessPackage(&package); //analysis buffer to extrace telegraph package from it } usleep(20000); } }
void clsCMM::Listen() { //begin receive data struct sockaddr_in from; socklen_t fromlen = sizeof(from); ADDRESSEDPACKAGE package; printf("[CMM] Net started\n"); while (1) { int nRecv = ::recvfrom(m_socket, m_bufferNet, MAXSIZE_TELEGRAPH-m_nBufferNet, 0, (struct sockaddr *)&from, &fromlen); if (nRecv == -1) { printf("[CMM] socket disconnected.\n"); break; } // printf("[CMM] %d bytes received from %s\n", nRecv, inet_ntoa(from.sin_addr)); m_nBufferNet += nRecv; /* for (int i=0; i<m_nBufferNet; i++) { printf("%02x ", (unsigned char)m_bufferNet[i]); } printf("\n");*/ if (ParseBuffer(m_bufferNet, m_nBufferNet, &package)) { ProcessPackage(&package); //analysis buffer to extrace telegraph package from it } // usleep(20000); //so far only process packages from ground station } ::close(m_socket); }
/** ** Parse all session buffers */ int UpdateParser(void) { Session *session; int len; char *next; if (!Pool || !Pool->First) { // No connections return 0; } for (session = Pool->First; session; session = session->Next) { // Confirm full message. while ((next = strpbrk(session->Buffer, "\r\n"))) { *next++ = '\0'; if (*next == '\r' || *next == '\n') { ++next; } ParseBuffer(session); // Remove parsed message len = next - session->Buffer; memmove(session->Buffer, next, sizeof(session->Buffer) - len); session->Buffer[sizeof(session->Buffer) - len] = '\0'; } } return 0; }
/** Processes a file, if it contains valuable commands. The file is loaded into a buffer a is passed to <it>ParseBuffer</it>, where all commands will be extracted. */ void CStyleFile::ProcessFile() { CFile f; try { f.Open(m_Filename, CFile::modeRead); ULONGLONG l = f.GetLength(); CString text; f.Read(text.GetBuffer(l), l * sizeof(TCHAR)); text.ReleaseBuffer(); if (HasCommands(text)) { ParseBuffer(text); } } catch (CFileException& ex) { TRACE(_T("Error opening style file: %s\n"), ex); UNUSED_ALWAYS(ex); f.Close(); } f.Close(); }
CARCFile::CARCFile(const u8* _pBuffer, size_t _BufferSize) : m_pBuffer(NULL) , m_Initialized(false) { m_pBuffer = new u8[_BufferSize]; if (m_pBuffer) { memcpy(m_pBuffer, _pBuffer, _BufferSize); m_Initialized = ParseBuffer(); } }
FarXMLNode *ParseFile (const char *FileName, IFarXMLErrorSink *errorSink) { FarFile f; if (!f.OpenForRead (FileName)) return NULL; int fileSize = f.GetSize(); FarString xmlBuf; xmlBuf.SetLength (fileSize); f.Read (xmlBuf.GetBuffer(), fileSize); return ParseBuffer (xmlBuf, errorSink); }
CARCFile::CARCFile(const std::string& _rFilename, u32 offset) : m_pBuffer(NULL) , m_Initialized(false) { DiscIO::IBlobReader* pReader = DiscIO::CreateBlobReader(_rFilename.c_str()); if (pReader != NULL) { u64 FileSize = pReader->GetDataSize() - offset; m_pBuffer = new u8[(u32)FileSize]; pReader->Read(offset, FileSize, m_pBuffer); delete pReader; m_Initialized = ParseBuffer(); } }
void ComplexShapeOneCommand(HWND hWnd) { char* cmd; HWND hItem; hItem = GetDlgItem(hWnd, IDC_GCODE); int l = GetWindowTextLength(hItem) + 1; cmd = (char*)malloc(l); if (cmd) { GetWindowTextA(hItem, cmd, l); ParseBuffer(hWnd, cmd, l, doGcode); free(cmd); } }
void MP3FrameParser::Parse(const char* aBuffer, uint32_t aLength, int64_t aOffset) { MutexAutoLock mon(mLock); const uint8_t* buffer = reinterpret_cast<const uint8_t*>(aBuffer); int32_t length = aLength; int64_t offset = aOffset; // Got some data we have seen already. Skip forward to what we need. if (aOffset < mOffset) { buffer += mOffset - aOffset; length -= mOffset - aOffset; offset = mOffset; if (length <= 0) { return; } } // If there is a discontinuity in the input stream, reset the state of the // parsers so we don't get any partial headers. if (mOffset < aOffset) { if (!mID3Parser.IsParsed()) { // Only reset this if it hasn't finished yet. mID3Parser.Reset(); } mMP3Parser.Reset(); } uint32_t bytesRead = 0; if (NS_FAILED(ParseBuffer(buffer, length, offset, &bytesRead))) { return; } MOZ_ASSERT(length <= (int)bytesRead, "All bytes should have been consumed"); // Update next data offset mOffset = offset + bytesRead; // If we've parsed lots of data and we still have nothing, just give up. if (!mID3Parser.IsParsed() && !mNumFrames && mOffset > MAX_SKIPPED_BYTES) { mIsMP3 = NOT_MP3; } }
bool JMLParser::ParseFile( const char* fName ) { strcpy( m_FileName, fName ); FILE* fp = fopen( m_FileName, "rb" ); if (!fp) return false; fseek( fp, 0, SEEK_END ); int fileSize = ftell( fp ); fseek( fp, 0, SEEK_SET ); char* buf = new char[fileSize + 1]; fread( buf, fileSize, 1, fp ); fclose( fp ); buf[fileSize] = 0; ClearStringPool(); ParseBuffer( buf ); ClearStringPool(); delete []buf; return true; } // JMLParser::ParseFile
void signalstatus(int signo) { extern struct timeval HandlerTimeOld; extern struct timeval HandlerTimeCurrent; extern struct timeval Now; int iBytesRead = 0; gettimeofday(&Now, NULL); HandlerTimeCurrent = Now; tv_sub(&HandlerTimeCurrent,&HandlerTimeOld); HandlerTimeOld = Now; // printf("Time difference between calls: %ds %dus\n\r", HandlerTimeCurrent.tv_sec,HandlerTimeCurrent.tv_usec); if(ucPortOpened) // check if main() has opened the port already { iBytesRead = read(fd, pDataBuffer, 1024); // nonblocking (!) if(iBytesRead) ParseBuffer(pDataBuffer,iBytesRead); // feed some characters to the parser }; }
void ToDoListView::ParseFile(const wxString& filename) { if (!wxFileExists(filename)) return; wxString st; LoaderBase* fileBuffer = Manager::Get()->GetFileManager()->Load(filename, true); if (fileBuffer) { EncodingDetector encDetector(fileBuffer); if (encDetector.IsOK()) { st = encDetector.GetWxStr(); ParseBuffer(st, filename); } } else return; delete fileBuffer; }
int CWGDConn::OnRead() { u_long avail = 0; int nRet = ioctlsocket(m_pBaseSocket->GetSocket(), FIONREAD, &avail); if ( (nRet == SOCKET_ERROR) || (avail == 0) ) { OnClose(); return -1; } char szRcvBuf[8192] = { 0 }; int READ_BUF_SIZE = 8192; for (;;) { uint32_t free_buf_len = m_in_buf.GetAllocSize() - m_in_buf.GetWriteOffset(); if (free_buf_len < READ_BUF_SIZE) m_in_buf.Extend(READ_BUF_SIZE); int nRet = m_pBaseSocket->Recv(m_in_buf.GetBuffer() + m_in_buf.GetWriteOffset(), READ_BUF_SIZE); if (SOCKET_ERROR == nRet) { if ((WSAGetLastError() == WSAEINTR)) continue; else break; } m_in_buf.IncWriteOffset(nRet); } //这里一定要循环把所有的消息都处理掉 因为一次接受的数据可能包含了多个消息结构体 while (ParseBuffer(m_in_buf) != -1) { } return 0; }
size_t telProcessNetwork ( char *buf, size_t len ) { unsigned char szBuffer[dwBuffer + 8]; unsigned char* pszHead = szBuffer; unsigned char* pszTail = szBuffer; size_t Result; unsigned char* pszNewHead; if (1) { Result = len ; pszTail = (unsigned char *)buf ; pszHead = (unsigned char *)buf ; pszTail += Result; pszNewHead = pszHead; do { pszHead = pszNewHead; pszNewHead = ParseBuffer(pszHead, pszTail); } while ((pszNewHead != pszHead) && (pszNewHead < pszTail)); if ( pszNewHead >= pszTail ) { // Everything is okay and we will reset variables and continue pszTail = pszHead = szBuffer; } else { MoveMemory(szBuffer, pszNewHead, pszTail - pszNewHead); pszTail = szBuffer + (pszTail - pszNewHead); pszHead = szBuffer; } } return len; }
bool CWebserverRequest::ParseFile(const std::string filename,CStringList ¶ms) { char *file_buffer, *out_buffer; long file_length= 0,out_buffer_size = 0; int out_len = 0; FILE * fd; tmpstring = GetFileName("/",filename); if(tmpstring.length() > 0) { if((fd = fopen(tmpstring.c_str(),"r")) == NULL) { perror("Parse file open error"); return false; } // get filesize fseek(fd, 0, SEEK_END); file_length = ftell(fd); rewind(fd); file_buffer = new char[file_length]; // allocate buffer for file out_buffer_size = file_length + 2048; out_buffer = new char[out_buffer_size]; // allocate output buffer fread(file_buffer, file_length, 1, fd); // read file if((out_len = ParseBuffer(file_buffer, file_length, out_buffer, out_buffer_size, params)) > 0) SocketWriteData(out_buffer,out_len); fclose(fd); delete[] out_buffer; delete[] file_buffer; } return true; }
Formats::Chiptune::Container::Ptr Parse(const Binary::Container& rawData, Builder& target) { if (!FastCheck(rawData)) { return Formats::Chiptune::Container::Ptr(); } try { const std::size_t size = rawData.Size(); const uint8_t* const begin = static_cast<const uint8_t*>(rawData.Start()); const uint8_t* const end = begin + size; const Header& header = *safe_ptr_cast<const Header*>(begin); const uint_t frames = fromLE(header.Duration); target.SetFrames(frames); std::size_t usedBegin = size; std::size_t usedEnd = 0; for (uint_t reg = 0; reg != header.Buffers.size(); ++reg) { target.StartChannel(reg); const BufferDescription& buf = header.Buffers[reg]; const std::size_t offset = buf.GetAbsoluteOffset(reg); Require(offset < size); Stream stream(buf.SizeHi, begin + offset, end); ParseBuffer(frames, stream, target); usedBegin = std::min(usedBegin, offset); usedEnd = std::max<std::size_t>(usedEnd, stream.GetCursor() - begin); } const Binary::Container::Ptr subData = rawData.GetSubcontainer(0, usedEnd); return CreateCalculatingCrcContainer(subData, usedBegin, usedEnd - usedBegin); } catch (const std::exception&) { return Formats::Chiptune::Container::Ptr(); } }
NS_IMETHODIMP nsExpatDriver::ConsumeToken(nsScanner& aScanner, PRBool& aFlushTokens) { // We keep the scanner pointing to the position where Expat will start // parsing. nsScannerIterator currentExpatPosition; aScanner.CurrentPosition(currentExpatPosition); // This is the start of the first buffer that we need to pass to Expat. nsScannerIterator start = currentExpatPosition; start.advance(mExpatBuffered); // This is the end of the last buffer (at this point, more data could come in // later). nsScannerIterator end; aScanner.EndReading(end); PR_LOG(gExpatDriverLog, PR_LOG_DEBUG, ("Remaining in expat's buffer: %i, remaining in scanner: %i.", mExpatBuffered, Distance(start, end))); // We want to call Expat if we have more buffers, or if we know there won't // be more buffers (and so we want to flush the remaining data), or if we're // currently blocked and there's data in Expat's buffer. while (start != end || (mIsFinalChunk && !mMadeFinalCallToExpat) || (BlockedOrInterrupted() && mExpatBuffered > 0)) { PRBool noMoreBuffers = start == end && mIsFinalChunk; PRBool blocked = BlockedOrInterrupted(); const PRUnichar *buffer; PRUint32 length; if (blocked || noMoreBuffers) { // If we're blocked we just resume Expat so we don't need a buffer, if // there aren't any more buffers we pass a null buffer to Expat. buffer = nsnull; length = 0; #if defined(PR_LOGGING) || defined (DEBUG) if (blocked) { PR_LOG(gExpatDriverLog, PR_LOG_DEBUG, ("Resuming Expat, will parse data remaining in Expat's " "buffer.\nContent of Expat's buffer:\n-----\n%s\n-----\n", NS_ConvertUTF16toUTF8(currentExpatPosition.get(), mExpatBuffered).get())); } else { NS_ASSERTION(mExpatBuffered == Distance(currentExpatPosition, end), "Didn't pass all the data to Expat?"); PR_LOG(gExpatDriverLog, PR_LOG_DEBUG, ("Last call to Expat, will parse data remaining in Expat's " "buffer.\nContent of Expat's buffer:\n-----\n%s\n-----\n", NS_ConvertUTF16toUTF8(currentExpatPosition.get(), mExpatBuffered).get())); } #endif } else { buffer = start.get(); length = PRUint32(start.size_forward()); PR_LOG(gExpatDriverLog, PR_LOG_DEBUG, ("Calling Expat, will parse data remaining in Expat's buffer and " "new data.\nContent of Expat's buffer:\n-----\n%s\n-----\nNew " "data:\n-----\n%s\n-----\n", NS_ConvertUTF16toUTF8(currentExpatPosition.get(), mExpatBuffered).get(), NS_ConvertUTF16toUTF8(start.get(), length).get())); } PRUint32 consumed; ParseBuffer(buffer, length, noMoreBuffers, &consumed); if (consumed > 0) { nsScannerIterator oldExpatPosition = currentExpatPosition; currentExpatPosition.advance(consumed); // We consumed some data, we want to store the last line of data that // was consumed in case we run into an error (to show the line in which // the error occurred). // The length of the last line that Expat has parsed. XML_Size lastLineLength = XML_GetCurrentColumnNumber(mExpatParser); if (lastLineLength <= consumed) { // The length of the last line was less than what expat consumed, so // there was at least one line break in the consumed data. Store the // last line until the point where we stopped parsing. nsScannerIterator startLastLine = currentExpatPosition; startLastLine.advance(-((ptrdiff_t)lastLineLength)); CopyUnicodeTo(startLastLine, currentExpatPosition, mLastLine); } else { // There was no line break in the consumed data, append the consumed // data. AppendUnicodeTo(oldExpatPosition, currentExpatPosition, mLastLine); } } mExpatBuffered += length - consumed; if (BlockedOrInterrupted()) { PR_LOG(gExpatDriverLog, PR_LOG_DEBUG, ("Blocked or interrupted parser (probably for loading linked " "stylesheets or scripts).")); aScanner.SetPosition(currentExpatPosition, PR_TRUE); aScanner.Mark(); return mInternalState; } if (noMoreBuffers && mExpatBuffered == 0) { mMadeFinalCallToExpat = PR_TRUE; } if (NS_FAILED(mInternalState)) { if (XML_GetErrorCode(mExpatParser) != XML_ERROR_NONE) { NS_ASSERTION(mInternalState == NS_ERROR_HTMLPARSER_STOPPARSING, "Unexpected error"); // Look for the next newline after the last one we consumed nsScannerIterator lastLine = currentExpatPosition; while (lastLine != end) { length = PRUint32(lastLine.size_forward()); PRUint32 endOffset = 0; const PRUnichar *buffer = lastLine.get(); while (endOffset < length && buffer[endOffset] != '\n' && buffer[endOffset] != '\r') { ++endOffset; } mLastLine.Append(Substring(buffer, buffer + endOffset)); if (endOffset < length) { // We found a newline. break; } lastLine.advance(length); } HandleError(); } return mInternalState; } // Either we have more buffers, or we were blocked (and we'll flush in the // next iteration), or we should have emptied Expat's buffer. NS_ASSERTION(!noMoreBuffers || blocked || (mExpatBuffered == 0 && currentExpatPosition == end), "Unreachable data left in Expat's buffer"); start.advance(length); // It's possible for start to have passed end if we received more data // (e.g. if we spun the event loop in an inline script). Reload end now // to compensate. aScanner.EndReading(end); } aScanner.SetPosition(currentExpatPosition, PR_TRUE); aScanner.Mark(); PR_LOG(gExpatDriverLog, PR_LOG_DEBUG, ("Remaining in expat's buffer: %i, remaining in scanner: %i.", mExpatBuffered, Distance(currentExpatPosition, end))); return NS_SUCCEEDED(mInternalState) ? kEOF : NS_OK; }
// This function is what used to be telProcessNetwork (Paul Brannan 6/15/98) DWORD TTelnetHandler::Go(LPVOID pvParams) { NetParams *pParams = (NetParams *)pvParams; // No longer a need to copy pParams-> socket and create an instance // of TANSIParser (Paul Brannan 6/15/98) Console.sync(); // Sync with the parser so the cursor is positioned Parser.Init(); // Reset the parser (Paul Brannan 9/19/98) init(); // Turn on local echo (Paul Brannan 9/19/98) *pParams->bNetFinished = 0; char* pszHead = szBuffer; char* pszTail = szBuffer; while (!*pParams->bNetFinish) { // Get data from Socket *pParams->bNetPaused = 1; //Pause int Result = Network.ReadString(pszTail, (szBuffer + dwBuffer) - pszTail); // Speed up mouse by not going into loop (Paul Brannan 8/10/98) // while(*pParams->bNetPause && !*pParams->bNetFinish) *pParams->bNetPaused = 1; //Pause if(WaitForSingleObject(pParams->hPause, 0) == WAIT_OBJECT_0) WaitForSingleObject(pParams->hUnPause, INFINITE); *pParams->bNetPaused = 0; //UnPause if (Result <= 0 || Result > dwBuffer ){ break; } pszTail += Result; // Process the buffer char* pszNewHead = pszHead; do { // Speed up mouse by not going into loop (Paul Brannan 8/10/98) if(WaitForSingleObject(pParams->hPause, 0) == WAIT_OBJECT_0) { *pParams->bNetPaused = 1; WaitForSingleObject(pParams->hUnPause, INFINITE); *pParams->bNetPaused = 0; } pszHead = pszNewHead; pszNewHead = ParseBuffer(pszHead, pszTail); // Parse buffer } while ((pszNewHead != pszHead) && (pszNewHead < pszTail) && !*pParams->bNetFinish); pszHead = pszNewHead; // When we reach the end of the buffer, move contents to the // beginning of the buffer to get free space at the end. if (pszTail == (szBuffer + dwBuffer)) { memmove(szBuffer, pszHead, pszTail - pszHead); pszTail = szBuffer + (pszTail - pszHead); pszHead = szBuffer; } } SetEvent(pParams->hExit); printm(0, FALSE, MSG_TERMBYREM); *pParams->bNetPaused = 1; //Pause *pParams->bNetFinished = 1; return 0; }
void MP3FrameParser::Parse(const char* aBuffer, uint32_t aLength, int64_t aOffset) { MutexAutoLock mon(mLock); const uint8_t* buffer = reinterpret_cast<const uint8_t*>(aBuffer); const int64_t lastChunkEnd = mOffset + mBufferLength; if (aOffset + aLength <= lastChunkEnd) { // We already processed this fragment. return; } else if (aOffset < lastChunkEnd) { // mOffset is within the new fragment, shorten range. aLength -= lastChunkEnd - aOffset; buffer += lastChunkEnd - aOffset; aOffset = lastChunkEnd; } else if (aOffset > lastChunkEnd) { // Fragment comes after current position, store difference. mOffset += aOffset - lastChunkEnd; mSkippedBytes = 0; } if (mBufferLength > 0) { // We have some data which was left over from the last buffer we received. // Append to it, so that we have enough data to parse a complete header, and // try to parse it. uint32_t copyLength = std::min<size_t>(NS_ARRAY_LENGTH(mBuffer)-mBufferLength, aLength); memcpy(mBuffer+mBufferLength, buffer, copyLength*sizeof(*mBuffer)); // Caculate the offset of the data in the start of the buffer. int64_t streamOffset = mOffset - mBufferLength; uint32_t bufferLength = mBufferLength + copyLength; uint32_t bytesRead = 0; if (NS_FAILED(ParseBuffer(mBuffer, bufferLength, streamOffset, &bytesRead))) { return; } MOZ_ASSERT(bytesRead >= mBufferLength, "Parse should leave original buffer"); // Adjust the incoming buffer pointer/length so that it reflects that we may have // consumed data from buffer. uint32_t adjust = bytesRead - mBufferLength; aOffset += adjust; aLength -= adjust; mBufferLength = 0; } uint32_t bytesRead = 0; if (NS_FAILED(ParseBuffer(buffer, aLength, aOffset, &bytesRead))) { return; } mOffset += bytesRead; if (bytesRead < aLength) { // We have some data left over. Store trailing bytes in temporary buffer // to be parsed next time we receive more data. uint32_t trailing = aLength - bytesRead; MOZ_ASSERT(trailing < (NS_ARRAY_LENGTH(mBuffer)*sizeof(mBuffer[0]))); memcpy(mBuffer, buffer+(aLength-trailing), trailing); mBufferLength = trailing; } if (mOffset > mLength) { mLength = mOffset; } }
static struct membuf *GenerateLuaFile(const char *asp_path, const char *lua_path, char **error_message) { FILE *fp; struct stat asp_file_stat; const char *asp_content; const char *asp_content_begin_ptr; struct membuf *lua_content; size_t estimated_size; int lua_fd = -1; struct ParserData parser_data; if (error_message) *error_message = NULL; fp = fopen(asp_path, "rt"); if (fp == NULL) { if (error_message) *error_message = strdup(strerror(errno)); return NULL; } fstat(_fileno(fp), &asp_file_stat); asp_content = (const char *)mmap(NULL, asp_file_stat.st_size, PROT_READ, MAP_PRIVATE, _fileno(fp), 0); if (asp_content == NULL) { if (error_message) *error_message = strdup("mmap failed."); fclose(fp); return NULL; } // Check for BOM and skip if present asp_content_begin_ptr = asp_content; if (asp_file_stat.st_size >= 3) { if (strncmp(asp_content_begin_ptr, "\xEF\xBB\xBF", 3) == 0) asp_content_begin_ptr += 3; } if (lua_path != NULL) { FILE *lua_fp; lua_fp = fopen(lua_path, "wt"); if (lua_fp != NULL) { lua_fd = _dup(_fileno(lua_fp)); fclose(lua_fp); } } estimated_size = asp_file_stat.st_size * 4; lua_content = membuf_create(estimated_size, lua_fd, 0, 1); parser_data.buf = lua_content; parser_data.handler = WriteToBufferCallback; GenerateProlog(parser_data.handler, &parser_data); ParseBuffer(asp_content_begin_ptr, asp_file_stat.st_size, ParserEventHandler, &parser_data); GenerateEpilog(parser_data.handler, &parser_data); munmap(asp_content, asp_file_stat.st_size); fclose(fp); return lua_content; }
/* bool FIndexMemcClient::AppendFIndex(Ice::Long source, Ice::Int stype, Ice::Int actor, Ice::Long feedid, Ice::Long miniMerge) { MCE_INFO("FIndexMemcClient::AppendFIndex --> source:" << source << " stype:" << stype << " actor:" << actor << " feedid:" << feedid << " miniMerge:" << miniMerge); //cout << "FIndexMemcClient::AppendFIndex --> source:" << source << " stype:" << stype << " actor:" << actor << " feedid:" << feedid << endl; string key_str = GetKey(source, stype); if(key_str.empty()) { MCE_WARN("FIndexMemcClient::AppendFIndex --> source:" << source << " stype:" << stype); //cout << "FIndexMemcClient::AppendFIndex --> source:" << source << " stype:" << stype << endl; return false; } vector<string> keys; keys.push_back(key_str); pair<int, MemcachedClient*> cli = pool_.GetClient(source); if(!cli.second){ MCE_WARN("FIndexMemcClient::AppendFIndex --> MemcachedClient ptr is NULL! source:" << source); //cout << "FIndexMemcClient::AppendFIndex --> MemcachedClient ptr is NULL! source:" << source << endl; return false; } char value_arr[VALUE_ITEM_SIZE]; MemcValueItem mv; mv.actor=actor; mv.feedid=feedid; SetBuffer(value_arr,0,mv); map<string, string> res; map<string, int> flags; TimeStatFIndex ts; { IceUtil::Mutex::Lock lock(mutexs_[source % MUTEX_COUNT]); float cost_mem = 0.0; bool succ = cli.second->Get(keys, res, flags); cost_mem = ts.getTime(); ts.reset(); MCE_INFO("FIndexMemcClient::AppendFIndex --> key:" << key_str << "get time:" << cost_mem); //cout << "FIndexMemcClient::AppendFIndex --> key:" << key_str << "get time:" << cost_mem << endl; if(succ) { if(!res.size()) { MCE_INFO("FIndexMemcClient::AppendFIndex --> Get NULL. key:" << key_str); //这里没有判断没有取到的原因 //cout << "FIndexMemcClient::AppendFIndex --> Get NULL. key:" << key_str << endl; bool ret = AddFIndex(key_str, value_arr, cli.second); pool_.ReleaseClient(cli.first, cli.second); return ret; } } else { MCE_WARN("FIndexMemcClient::AppendFIndex --> Get failed! key:" << key_str); //cout << "FIndexMemcClient::AppendFIndex --> Get failed! key:" << key_str << endl; bool ret = AddFIndex(key_str, value_arr, cli.second); pool_.ReleaseClient(cli.first, cli.second); return ret; } map<string, string>::iterator mit = res.find(key_str); if(mit == res.end()) { MCE_WARN("FIndexMemcClient::AppendFIndex --> res has not key! key:" << key_str); pool_.ReleaseClient(cli.first, cli.second); return false; } else { size_t len = mit->second.size(); if(len >= VALUE_LIMIT) { // 超过50条,全部删除。 也可以改成LRU MCE_WARN("FIndexMemcClient::AppendFIndex --> value too long! len:" << len); bool ret = AddFIndex(key_str, value_arr, cli.second); pool_.ReleaseClient(cli.first, cli.second); return ret; } } int r = cli.second->Append(key_str, value_arr, sizeof(MemcValueItem), 0); cost_mem = ts.getTime(); MCE_INFO("FIndexMemcClient::AppendFIndex --> ret:" << r << " key_str:" << key_str << "append time:" << cost_mem); } //cout << "res:" << r << " key_str:" << key_str << std::endl; pool_.ReleaseClient(cli.first, cli.second); return 1; } */ FIndexMemcClient::FIValue FIndexMemcClient::GetFIndex(Ice::Long source, Ice::Int stype) { FIValue value; vector<string> keys; string key_str = GetKey(source, stype); if(key_str.empty()) { MCE_WARN("FIndexMemcClient::GetFIndex --> key_str is empty! source:" << source << " stype:" << stype); //cout << "FIndexMemcClient::GetFIndex --> key_str is empty! source:" << source << " stype:" << stype << endl; } keys.push_back(key_str); pair<int, MemcachedClient*> cli = pool_.GetClient(source); if(!cli.second){ MCE_WARN("FIndexMemcClient::GetFIndex --> MemcachedClient ptr is NULL! source:" << source); //cout << "FIndexMemcClient::GetFIndex --> MemcachedClient ptr is NULL! source:" << source << endl; return value ; } map<string, string> res; map<string, int> flags; TimeStatFIndex ts; float cost_mem = 0.0; bool succ = cli.second->Get(keys, res, flags); string ip = cli.second->GetIp(); cost_mem = ts.getTime(); ts.reset(); if(succ) { if(!res.size()) { MCE_INFO("FIndexMemcClient::GetFIndex --> Get NULL. key:" << key_str << " cost_total:" << cost_mem << " ip:" << ip); //cout << "FIndexMemcClient::GetFIndex --> Get NULL. key:" << key_str << endl; pool_.ReleaseClient(cli.first, cli.second); return value; } } else { MCE_WARN("FIndexMemcClient::GetFIndex --> Get failed! key:" << key_str << " cost_total:" << cost_mem << " ip:" << ip); //cout << "FIndexMemcClient::GetFIndex --> Get failed! key:" << key_str << endl; pool_.ReleaseClient(cli.first, cli.second); return value ; } if(cost_mem < 160) { MCE_INFO("FIndexMemcClient::GetFIndex --> key:" << key_str << " cost_total:" << cost_mem << " ip:" << ip); } else { MCE_WARN("FIndexMemcClient::GetFIndex --> key:" << key_str << " cost_total:" << cost_mem << " ip:" << ip); } //cout << "FIndexMemcClient::GetFIndex --> key:" << key_str << " time:" << cost_mem << endl; map<string, string>::iterator it = res.find(key_str); if(it != res.end()) { MCE_INFO("FIndexMemcClient::GetFIndex --> key:" << it->first << " value size:" << it->second.size()); //cout <<"FIndexMemcClient::GetFIndex --> key:" << it->first << " value size:" << it->second.size() << endl; const char * ptr = it->second.c_str(); size_t value_size = it->second.size(); bool succ = ParseBuffer(ptr, value_size, value); if(succ) { MCE_INFO("FIndexMemcClient::GetFIndex --> key:" << it->first << " vector size:" << value.size()); //cout << "FIndexMemcClient::GetFIndex --> key:" << it->first << " vector size:" << value.size() << endl; } else { MCE_WARN("FIndexMemcClient::GetFIndex --> ParseBuffer error. key:" << key_str); //cout << "FIndexMemcClient::GetFIndex --> ParseBuffer error. key:" << key_str << endl; } } else { MCE_WARN("FIndexMemcClient::GetFIndex --> res has not found key:" << key_str); //cout << "FIndexMemcClient::GetFIndex --> res has not found key:" << key_str << endl; } //string ip = cli.second->GetIp(); //cout << "ip:" << ip << endl; pool_.ReleaseClient(cli.first, cli.second); return value; }
void CSpellbookDlg::AddSpellBook(const char * pszFileName) { //open the spell book CSectionFile SpellBook; SpellBook.Open( CByakheeApp::GetDefaultDirectory() + pszFileName ); //read the title CString strTitle = SpellBook.GetSection( "TITLE" ); char * psTitle = strTitle.GetBuffer(); if( strTitle.IsEmpty() ) { //trim off path and extension, if there is one, and use that for the title char * psFileName; psFileName = (char*)malloc(sizeof(char)*strlen(pszFileName)); strcpy(psFileName, pszFileName); char* pszTemp = strrchr(psFileName, '\\'); if( pszTemp ) psFileName = ++pszTemp; pszTemp = strrchr(psFileName, '.' ); if( pszTemp ) *pszTemp = '\0'; strTitle = psFileName; } else { //find the end of the first line char* pszTemp = strchr( psTitle, '\r' ); char* pszTemp2 = strchr( psTitle, '\n' ); if( pszTemp != NULL || pszTemp2 != NULL ) { //find the one nearest to the end of the first line if( pszTemp == NULL ) pszTemp = pszTemp2; else if( pszTemp2 != NULL && pszTemp2 < pszTemp ) pszTemp = pszTemp2; //terminate it at that point *pszTemp = '\0'; CString strTemp = LPCSTR(psTitle); *pszTemp = '\n'; strTitle = strTemp; } } //read the rest of the spellbook (1D10 months, D6 SAN...) CString strContents = SpellBook.GetSection( "SPELLS" ); if( strContents.IsEmpty() ) return; //book was empty //add this book to the tree HTREEITEM hSpellBook = m_wndSpellList.InsertItem( strTitle, 1, 1 ); HTREEITEM hParent = hSpellBook; ExpandTreeItem( hSpellBook ); //read each line CParseBuffer ParseBuffer(strContents); while( ParseBuffer.IsEmpty() == FALSE ) { //add item CString strItem; switch( ParseBuffer.PeekNextChar() ) { case '*': hParent = hSpellBook; strItem = ParseBuffer.ExtractSurroundedString( '*', '*' ); if(strItem.IsEmpty() == FALSE ) hParent = m_wndSpellList.InsertItem( strItem, 0, 0, hParent ); break; default: //this default will generate a parse error if it's not a "", which will report an error in the spellbook case '\"': strItem = ParseBuffer.ExtractQuotedString(); if(strItem.IsEmpty() == FALSE ) m_wndSpellList.InsertItem( strItem, 2, 2, hParent ); break; } //skip over the rest of the line ParseBuffer.SkipToNextLine(); } }
void ToDoListView::ParseEditor(cbEditor* pEditor) { if (pEditor) ParseBuffer(pEditor->GetControl()->GetText(), pEditor->GetFilename()); }