String XmlParser::ReadComment(bool next) { if(!IsComment()) throw XmlError("Comment expected"); String h = tagtext; if(next) Next(); return h; }
std::map<std::string, ResModelLoader::ObjTankObject> ResModelLoader::m_LoadObjTankObjects( const std::vector<std::string>::iterator first, const std::vector<std::string>::iterator last) { std::map<std::string, ObjTankObject> result; VertexesBag v_bag; FacesBag f_bag; std::string previous_name; FLOATING x, y, z, s, t; unsigned v0, t0, n0, v1, t1, n1, v2, t2, n2; auto lineIt = first; while (lineIt != last) { std::string current_name; if (IsObject(*lineIt, current_name)) { if (!previous_name.empty()) { result[previous_name] = m_BuildObjTankObject(v_bag, f_bag); f_bag.Clear(); } previous_name = current_name; } else if (IsVertex(*lineIt, x, y, z)) { v_bag.vertexes.emplace_back(x, y, z); } else if (IsNormal(*lineIt, x, y, z)) { v_bag.normals.emplace_back(x, y, z); } else if (IsTexCoord(*lineIt, s, t)) { v_bag.tex_coords.emplace_back(s, t); } else if (IsFace3(*lineIt, v0, t0, n0, v1, t1, n1, v2, t2, n2)) { f_bag.faces3.emplace_back(v0, t0, n0); f_bag.faces3.emplace_back(v1, t1, n1); f_bag.faces3.emplace_back(v2, t2, n2); } else if (IsFace2(*lineIt, v0, n0, v1, n1, v2, n2)) { f_bag.faces2.emplace_back(v0, n0); f_bag.faces2.emplace_back(v1, n1); f_bag.faces2.emplace_back(v2, n2); } else if (IsSmoothing(*lineIt) || IsComment(*lineIt)) { // NULL; } ++lineIt; } // Write last object. result[previous_name] = m_BuildObjTankObject(v_bag, f_bag); return result; }
void cbStyledTextCtrl::DoBraceCompletion(const wxChar& ch) { const int pos = GetCurrentPos(); const int style = GetStyleAt(pos); if (IsComment(style) || IsComment(GetStyleAt(pos - 2))) return; // do nothing if (ch == wxT('\'') || ch == wxT('"')) { if (GetCharAt(pos) == ch) { DeleteBack(); CharRight(); } else if (!IsString(GetStyleAt(pos - 2)) && !IsCharacter(GetStyleAt(pos - 2))) InsertText(pos, ch); return; // done } if (IsString(style) || IsCharacter(style)) return; // do nothing const wxString opBraces(wxT("([{")); const int opBraceIdx = opBraces.Find(ch); const wxString clBraces(wxT(")]}")); const int clBraceIdx = clBraces.Find(ch); if ( (opBraceIdx != wxNOT_FOUND) || (clBraceIdx != wxNOT_FOUND) ) { if ( GetCharAt(pos) == ch ) { DeleteBack(); CharRight(); } else if (opBraceIdx != wxNOT_FOUND) { int nextPos = pos; while ( wxIsspace(GetCharAt(nextPos)) && (nextPos < GetLength()) ) ++nextPos; if ( ((wxChar)GetCharAt(nextPos) != clBraces[opBraceIdx]) || (BraceMatch(nextPos) != wxNOT_FOUND) ) { InsertText(pos, clBraces[opBraceIdx]); } } } }
void TFunctionScanner::ReadFunctionArgs(const TChar*& text) { SkipWhiteSpace(text); if (*text == '(') { while (*text != ')') { if (IsString(text)) SkipString(text); else if (IsComment(text)) SkipComment(text); else NextChar(text); } NextChar(text); fScanState = kFunctionArgs; } else { while (1) { TChar ch = *text; if (IsString(text)) SkipString(text); else if (IsComment(text)) SkipComment(text); else { NextChar(text); if (ch == ';') { fScanState = kTopLevel; break; } } } } }
bool cbStyledTextCtrl::AllowTabSmartJump() { const int pos = GetCurrentPos(); if (pos == wxSCI_INVALID_POSITION) return false; const int style = GetStyleAt(pos); if (IsString(style) || IsCharacter(style) || IsComment(style) || IsPreprocessor(style)) return !m_tabSmartJump; return true; }
bool ContextPhp::IsCommentOrString(long pos) { int style = GetCtrl().GetStyleAt(pos); return IsComment(pos) || style == wxSTC_H_DOUBLESTRING || style == wxSTC_H_SINGLESTRING || style == wxSTC_H_SGML_DOUBLESTRING || style == wxSTC_H_SGML_SIMPLESTRING || style == wxSTC_HJ_DOUBLESTRING || style == wxSTC_HJ_SINGLESTRING || style == wxSTC_HJ_STRINGEOL || style == wxSTC_HJA_DOUBLESTRING || style == wxSTC_HJA_SINGLESTRING || style == wxSTC_HJA_STRINGEOL || style == wxSTC_HB_STRING || style == wxSTC_HBA_STRING || style == wxSTC_HBA_STRINGEOL || style == wxSTC_HP_STRING || style == wxSTC_HPA_STRING || style == wxSTC_HPA_CHARACTER || style == wxSTC_HPHP_HSTRING || style == wxSTC_HPHP_SIMPLESTRING; }
BOOL BIniFile::LoadFile(const char *const fileName) { BZ_CHECK_C_STRING_RETURN_BOOL(fileName); std::ifstream fileIn(fileName); if (!fileIn) { assert(false); return FALSE; } char buffer[LINE_BUFFER_SIZE]; bool getSeg = false; size_t nBufLen = 0; int nAssPos = 0; while (!fileIn.eof()) { fileIn.getline(buffer, LINE_BUFFER_SIZE); if ((!getSeg) && (!IsSegment(buffer))) { continue; } if (IsComment(buffer)) { continue; } if (IsSegment(buffer)) { BSegmentNode seg; getSeg = true; nBufLen = strlen(buffer); buffer[nBufLen - 1] = '\0'; seg.m_bssSeg = BSimpleString(buffer + 1); m_segArray.push_back(seg); continue; } if (-1 != (nAssPos = IsKeyNode(buffer))) { BKeyNode key; buffer[nAssPos] = '\0'; key.m_bssKey = BSimpleString(buffer); key.m_bssValue = BSimpleString(buffer + nAssPos + 1); m_segArray.back().AddKey(key); continue; } } fileIn.close(); return TRUE; }
void ConfigInfo::ParseLine(string line, char delimiter) { if (!IsComment(line, "#")) { int length = line.length(); int index = line.find(delimiter, 0); if (index > 0) { string param = line.substr(0, index); string value = line.substr(index + 1, length - 1 - index); if (IsValidParam(param)) { param_set.insert(pair<string, string>(param, value)); } } } }
/* IScanner */ static inline int ParseCommentLine(struct IParse *parse) { ParseSkip(parse); if (!IsComment(parse)) { return 0; } int code = 0; while ((code = ParseRead(parse)) != -1) { if (IsNewline(code)) { return 1; } } return 1; }
asETokenClass asCTokenizer::ParseToken(const char *source, size_t sourceLength, size_t &tokenLength, eTokenType &tokenType) const { if( IsWhiteSpace(source, sourceLength, tokenLength, tokenType) ) return asTC_WHITESPACE; if( IsComment(source, sourceLength, tokenLength, tokenType) ) return asTC_COMMENT; if( IsConstant(source, sourceLength, tokenLength, tokenType) ) return asTC_VALUE; if( IsIdentifier(source, sourceLength, tokenLength, tokenType) ) return asTC_IDENTIFIER; if( IsKeyWord(source, sourceLength, tokenLength, tokenType) ) return asTC_KEYWORD; // If none of the above this is an unrecognized token // We can find the length of the token by advancing // one step and trying to identify a token there tokenType = ttUnrecognizedToken; tokenLength = 1; return asTC_UNKNOWN; }
int asCTokenizer::ParseToken() { if( IsWhiteSpace() ) return 0; if( IsComment() ) return 0; if( IsConstant() ) return 0; if( IsIdentifier() ) return 0; if( IsKeyWord() ) return 0; // If none of the above this is an unrecognized token // We can find the length of the token by advancing // one step and trying to identify a token there tokenType = ttUnrecognizedToken; tokenLength = 1; return -1; }
BOOL MYIniReadTools::InsertKeyAndValue( CString strTmpValue, vector<INIKEYINFO> &st ) { CString strKey; CString strValue; CString strComment; if(IsKeyAndValue(strTmpValue)||IsComment(strTmpValue)) { GetKeyAndValue(strKey,strValue,strComment,strTmpValue); INIKEYINFO stInfo; stInfo.strKey=strKey; stInfo.strValue=strValue; stInfo.strComment=strComment; st.push_back(stInfo); return TRUE; } return FALSE; }
// Main recursive parsing function bool wxSimpleHtmlParser::ParseHtml(wxSimpleHtmlTag* parent) { while (!Eof()) { EatWhitespace(); if (IsComment()) { ParseComment(); } else if (IsDirective()) { wxSimpleHtmlTag* tag = ParseDirective(); if (tag) parent->AppendTag(tag); } else if (IsTagClose()) { wxSimpleHtmlTag* tag = ParseTagClose(); if (tag) parent->AppendTag(tag); } else if (IsTagStartBracket(GetChar(m_pos))) { wxSimpleHtmlTag* tag = ParseTagHeader(); if (tag) parent->AppendTag(tag); } else { // Just a text string wxString text; ParseText(text); wxSimpleHtmlTag* tag = new wxSimpleHtmlTag(wxT("TEXT"), wxSimpleHtmlTag_Text); tag->SetText(text); parent->AppendTag(tag); } } return TRUE; }
static DWORD DJReplaceNameValuePair( PSTR pszFilePath, PSTR pszName, PSTR pszValue ) { DWORD ceError = ERROR_SUCCESS; PSTR pszTmpPath = NULL; PSTR pszFinalPath = NULL; FILE* fpSrc = NULL; FILE* fpDst = NULL; regex_t rx; CHAR szRegExp[256]; CHAR szBuf[1024+1]; BOOLEAN bRemoveFile = FALSE; memset(&rx, 0, sizeof(rx)); ceError = CTGetFileTempPath( pszFilePath, &pszFinalPath, &pszTmpPath); BAIL_ON_CENTERIS_ERROR(ceError); sprintf(szRegExp, "^[[:space:]]*%s[[:space:]]*=.*$", pszName); if (regcomp(&rx, szRegExp, REG_EXTENDED) < 0) { ceError = LW_ERROR_REGEX_COMPILE_FAILED; BAIL_ON_CENTERIS_ERROR(ceError); } if ((fpSrc = fopen(pszFinalPath, "r")) == NULL) { ceError = LwMapErrnoToLwError(errno); BAIL_ON_CENTERIS_ERROR(ceError); } if ((fpDst = fopen(pszTmpPath, "w")) == NULL) { ceError = LwMapErrnoToLwError(errno); BAIL_ON_CENTERIS_ERROR(ceError); } bRemoveFile = TRUE; while (1) { if (fgets(szBuf, 1024, fpSrc) == NULL) { if (feof(fpSrc)) { break; } else { ceError = LwMapErrnoToLwError(errno); BAIL_ON_CENTERIS_ERROR(ceError); } } if (!IsComment(szBuf) && !regexec(&rx, szBuf, (size_t)0, NULL, 0)) { if (fprintf(fpDst, "%s=%s\n", pszName, pszValue) < 0) { ceError = LwMapErrnoToLwError(errno); BAIL_ON_CENTERIS_ERROR(ceError); } } else { if (fputs(szBuf, fpDst) == EOF) { ceError = LwMapErrnoToLwError(errno); BAIL_ON_CENTERIS_ERROR(ceError); } } } fclose(fpSrc); fpSrc = NULL; fclose(fpDst); fpDst = NULL; ceError = CTSafeReplaceFile(pszFinalPath, pszTmpPath); BAIL_ON_CENTERIS_ERROR(ceError); bRemoveFile = FALSE; error: if (fpSrc) fclose(fpSrc); if (fpDst) fclose(fpDst); regfree(&rx); if (bRemoveFile) CTRemoveFile(pszTmpPath); CT_SAFE_FREE_STRING(pszTmpPath); CT_SAFE_FREE_STRING(pszFinalPath); return ceError; }
Long CModelScript::SubmitAllTranslation() { SizeT LogicalLine, PhysicalLine, LineSize, BufferSize; WChar LineBuffer[0x1000]; PWChar pText, pEnd; PVoid pvBuffer; CFileDisk file; // Long Result; // Result = SaveTranslation(); // if (SCR_FAILED(Result)) // return Result; if (!file.Open( m_ScriptPath, file.FILE_ACCESS_READ | file.FILE_ACCESS_WRITE, file.FILE_SHAREMODE_READ, file.FILE_OPEN_EXIST)) { return SCR_ERROR_IO_FAILED_OPEN; } BufferSize = file.GetSize(); pvBuffer = m_mem.Alloc(BufferSize); if (pvBuffer == NULL) return SCR_ERROR_OUT_OF_MEMORY; if (!file.Read(pvBuffer)) { m_mem.Free(pvBuffer); return SCR_ERROR_IO_FAILED_READ; } pText = (PWChar)pvBuffer; if (*pText != BOM_UTF16_LE) { m_mem.Free(pvBuffer); return SCR_ERROR_INVALID_ENCODING; } file.Seek(file.FILE_SEEK_BEGIN, 2); pEnd = (PWChar)((PByte)pvBuffer + BufferSize); SScriptText *pOrigText, *pTransText; ++pText; pOrigText = &m_VecTextOrigianl[0]; pTransText = &m_VecTextTranslation[0]; LogicalLine = 0; PhysicalLine = 0; while (pText < pEnd) { LineSize = sizeof(LineBuffer); pText = PeekLine(pText, pEnd, LineBuffer, &LineSize); if (pText == NULL) break; ++PhysicalLine; LogicalLine += !IsComment(LineBuffer); lstrcatW(LineBuffer, L"\r\n"); if (LineSize == 0 || IsComment(LineBuffer) || IsControlSentance(LineBuffer)) { file.Write(LineBuffer, LineSize + 4); continue; } if (PhysicalLine != pTransText->PhysicalLine || LogicalLine != pTransText->LogicalLine) { ; } LineSize = 0; if (!pTransText->VoiceName.IsEmpty() && pTransText->VoiceName != L"") LineSize = wsprintfW(LineBuffer, L"%s,", (PWChar)pTransText->VoiceName); else if (!pOrigText->VoiceName.IsEmpty() && pOrigText->VoiceName != L"") LineSize = wsprintfW(LineBuffer, L"%s,", (PWChar)pOrigText->VoiceName); if (pTransText->CharNameIndex != -1) LineSize += wsprintfW(LineBuffer + LineSize, L"%s,", GetCharNameTranslationByIndex(pTransText->CharNameIndex)); LineSize += wsprintfW(LineBuffer + LineSize, L"%s\r\n", (PWChar)pTransText->Text); file.Write(LineBuffer, LineSize * sizeof(*LineBuffer)); ++pOrigText; ++pTransText; } m_mem.Free(pvBuffer); file.SetEndOfFile(); DeleteTranslationFile(); m_VecTextOrigianl = m_VecTextTranslation; m_VecCharNameOriginal = m_VecCharNameTranslation; return SCR_ERROR_SUCCESS; }
Long CModelScript::ParseScriptWorker(PVoid pvBuffer, SizeT BufferSize) { SizeT LogicalLine, PhysicalLine, LineSize; WChar ch, LineBuffer[0x1000]; PWChar pBuffer, pText, pEnd; pText = (PWChar)pvBuffer; pEnd = (PWChar)((PByte)pvBuffer + BufferSize); if (*pText != BOM_UTF16_LE) return SCR_ERROR_INVALID_ENCODING; SScriptText ScrText; m_VecCharNameOriginal.clear(); m_VecTextOrigianl.clear(); ++pText; LogicalLine = 0; PhysicalLine = 0; while (pText < pEnd) { LineSize = sizeof(LineBuffer); pText = PeekLine(pText, pEnd, LineBuffer, &LineSize); if (pText == NULL) break; ++PhysicalLine; if (LineSize == 0) { ++LogicalLine; continue; } if (IsComment(LineBuffer)) continue; ++LogicalLine; if (IsControlSentance(LineBuffer)) continue; ScrText.Text = L""; ScrText.CharNameIndex = -1; ScrText.VoiceName = L""; ScrText.LogicalLine = LogicalLine; ScrText.PhysicalLine = PhysicalLine; LineSize /= sizeof(*pText); pBuffer = LineBuffer + LineSize - 1; while (pBuffer > LineBuffer) { ch = *pBuffer; if (ch == ',') { *pBuffer++ = 0; break; } --pBuffer; } ScrText.Text = pBuffer--; if (pBuffer >= LineBuffer) { while (pBuffer > LineBuffer) { ch = *pBuffer; if (ch == ',') { *pBuffer++ = 0; break; } --pBuffer; } ScrText.CharNameIndex = FindCharName(pBuffer--); } if (pBuffer >= LineBuffer) { while (pBuffer > LineBuffer) { ch = *pBuffer; if (ch == ',') { ++pBuffer; break; } --pBuffer; } ScrText.VoiceName = pBuffer; } m_VecTextOrigianl.push_back(ScrText); } return SCR_ERROR_SUCCESS; }
__checkReturn size_t LoadCache( __inout IPAddressMap & f_cache, __in_z char const * const f_szFileName ) { FILE *finf = OpenFile( f_szFileName ); if( !finf ) { // some error, abort return 0; } size_t nItems( 0 ); size_t const knLineLength( 8192 ); char szLine[ knLineLength + 1 ]; while( fgets( szLine, knLineLength, finf ) ) { if( IsComment( szLine ) ) { continue; } int ip1; int ip2; int ip3; int ip4; if( !ReadIP( szLine, ip1, ip2, ip3, ip4 )) { continue; } char const szDelimiters[] = "\t "; char *next_token = 0; char const *pTok = strtok_s( szLine, szDelimiters, &next_token ); if( pTok ) { PackedIP const recordIP( PackIP( static_cast<char >(ip1 & 0xff), static_cast<char >(ip2 & 0xff), static_cast<char >(ip3 & 0xff), static_cast<char >(ip4 & 0xff) ) ); bool const bIsBlockedIp( IsBlockedIp( recordIP ) ); PackedIP const ip( bIsBlockedIp ? BlockedIP() : recordIP ); for( pTok = strtok_s( 0, szDelimiters, &next_token ); pTok; pTok = strtok_s( 0, szDelimiters, &next_token ) ) { if( IsComment( pTok ) ) { break; } std::string const sHostName( CleanHostName( pTok ) ); // skip blanks if( sHostName.empty() ) { continue; } // skip localhost if( sHostName == "localhost" ) { continue; } bool bFound( false ); if( !bIsBlockedIp ) { // Perform search IPAddressMap::const_iterator const itLower( f_cache.lower_bound( ip ) ); IPAddressMap::const_iterator const itUpper( f_cache.upper_bound( ip ) ); for( IPAddressMap::const_iterator itItem( itLower ); itUpper != itItem; ++itItem ) { if( itItem->second == sHostName ) { bFound = true; break; } } } else { // Blocked IP with no . if( std::string::npos == sHostName.find(".")) { continue; } } if( !bFound ) { (void)f_cache.insert( IPAddressMap::value_type( ip, sHostName ) ); ++nItems; } } } } fclose( finf ); return nItems; }
bool SimpleParser::Read() { int c; int mode=0; //0 whitespace/idle, 1 comment, 2 token, 3 punct string str; while((c=in.peek()) != EOF) { if(!in) { cerr<<"Error while reading characters!"<<endl; return false; } switch(mode) { case 0: if(IsSpace(c)) { //continue } else if(IsComment(c)) mode=1; else if(IsToken(c)) { str+=c; mode=2; } else if(IsPunct(c)) { str+=c; mode=3; } else { cerr<<"Illegal character "<<(char)c<<endl; return false; } break; case 1: //comment if(c=='\n') mode=0; break; case 2: //reading tokens if(IsToken(c)) {str+=c;} else { Result res=InputToken(str); if(res == Stop) return true; else if(res == Error) { cerr<<"Error on token "<<str.c_str()<<endl; return false; } str.erase(); if(c == '\n') { Result res=InputEndLine(); if(res==Stop) return true; else if(res == Error) { cerr<<"Error on endline at line "<<lineno<<endl; return false; } lineno++; mode=0; } else if(IsSpace(c)) mode=0; else if(IsComment(c)) mode=1; else if(IsPunct(c)) { str+=c; mode=3; } else { cerr<<"Illegal character "<<(char)c<<endl; return false; } } break; case 3: if(IsPunct(c)) {str+=c;} else { Result res=InputPunct(str); if(res == Stop) return true; else if(res == Error) { cerr<<"Error on token "<<str.c_str()<<endl; return false; } str.erase(); if(IsSpace(c)) mode=0; else if(IsComment(c)) mode=1; else if(IsToken(c)) { str+=c; mode=2; } else { cerr<<"Illegal character "<<(char)c<<endl; return false; } } break; } if(c == '\n') { Result res=InputEndLine(); if(res==Stop) return true; else if(res == Error) { cerr<<"Error on endline at line "<<lineno<<endl; return false; } lineno++; } c = in.get(); } if(!str.empty()) { Result res=InputToken(str); if(res == Stop) return true; else if(res == Error) { cerr<<"Error on token "<<str.c_str()<<endl; return false; } else { cerr<<"Incomplete read at EOF, string "<<str.c_str()<<endl; return false; } } in.get(); assert(!in); return true; }
TInt CRfsScript::ParseNextCommandL( CRfsCommand* aCommand ) { const TDesC* commands[ KRfsNumberOfCommands ] = { &KRfsCommand1, &KRfsCommand2, &KRfsCommand3, &KRfsCommand4, &KRfsCommand5, &KRfsCommand6, &KRfsCommand7, &KRfsCommand8 }; TInt startIndex; TInt endIndex; FOREVER { // check if index is beyond the descriptor already if ( iIndex >= iLength ) { return KRfsEndOfScript; } // go to the beginning of the "command word" startIndex = iIndex; SkipSpace( startIndex ); // go to the end of the "command word" endIndex = startIndex; FindEnd( endIndex ); if ( endIndex - startIndex > 0 && !IsComment( startIndex ) ) { break; } // if the line is commented out, skip it iIndex = NextLine( startIndex ); } // create TPtrC to the "command word" TPtrC command( &iScript[ startIndex ], endIndex - startIndex ); TRfsCommandId commandId( ERfsCommandUnknown ); // determine the command id for ( TInt i = 0; i < KRfsNumberOfCommands ; i++ ) { if ( !command.CompareF( *( commands[ i ] ) ) ) { commandId = (TRfsCommandId)i; break; } } TInt ret( KErrGeneral ); // returns this if there is a syntax error in line if ( commandId != ERfsCommandUnknown ) { TInt numberOfParams( 0 ); TInt start = endIndex; FOREVER { TBool quotes( EFalse ); SkipSpace( start, "es ); TInt end = start; if ( FindEnd( end, quotes ) ) { if ( end - start > 0 && !IsComment( start) ) { numberOfParams++; start = end; continue; } } break; } if ( VerifyNumberOfParameters( commandId, numberOfParams ) ) { // set command information if the command parameter has been given if ( aCommand ) { TPtrC* params = new( ELeave ) TPtrC[ numberOfParams ]; // fetch parameter information for ( TInt i = 0; i < numberOfParams ; i++ ) { TInt paramStart = endIndex; TBool quotes( EFalse ); SkipSpace( paramStart, "es ); TInt paramEnd = paramStart; FindEnd( paramEnd, quotes ); TInt realStart( paramStart ); TInt realEnd( paramEnd ); if ( quotes ) { realStart++; realEnd--; } params[ i ].Set( &iScript[ realStart ], realEnd - realStart ); endIndex = paramEnd; } // aCommand gets ownership of paramStarts and paramLengths aCommand->Set( commandId, numberOfParams, params ); } iIndex = NextLine ( endIndex ); ret = KErrNone; } }
NOXREF void TextMessageParse(unsigned char *pMemFile, int fileSize) { NOXREFCHECK; char buf[512]; char trim[512]; char *pCurrentText; char *pNameHeap; char currentName[512]; char nameHeap[NAME_HEAP_SIZE]; int lastNamePos; int mode; int lineNumber; int filePos; int lastLinePos; int messageCount; client_textmessage_t textMessages[MAX_MESSAGES]; int i; int nameHeapSize; int textHeapSize; int messageSize; int nameOffset; lastNamePos = 0; lineNumber = 0; filePos = 0; lastLinePos = 0; messageCount = 0; mode = MSGFILE_NAME; while (memfgets(pMemFile, fileSize, &filePos, buf, 512) != NULL) { if(messageCount >= MAX_MESSAGES) Sys_Error("%s: messageCount >= MAX_MESSAGES", __func__); TrimSpace(buf, trim); switch (mode) { case MSGFILE_NAME: { if (IsComment(trim)) break; if (ParseDirective(trim)) break; if (IsStartOfText(trim)) { mode = MSGFILE_TEXT; pCurrentText = (char *)(pMemFile + filePos); break; } if (IsEndOfText(trim)) { Con_DPrintf("Unexpected '}' found, line %d\n", lineNumber); return; } Q_strncpy(currentName, trim, 511); currentName[511] = 0; break; } case MSGFILE_TEXT: { if (IsEndOfText(trim)) { int length = Q_strlen(currentName); if (lastNamePos + length > sizeof(nameHeap)) { Con_DPrintf("Error parsing file! length > %i bytes\n", sizeof(nameHeap)); return; } Q_strcpy(nameHeap + lastNamePos, currentName); pMemFile[lastLinePos - 1] = 0; textMessages[messageCount] = gMessageParms; textMessages[messageCount].pName = nameHeap + lastNamePos; lastNamePos += Q_strlen(currentName) + 1; textMessages[messageCount].pMessage = pCurrentText; messageCount++; mode = MSGFILE_NAME; break; } if (IsStartOfText(trim)) { Con_DPrintf("Unexpected '{' found, line %d\n", lineNumber); return; } break; } } lineNumber++; lastLinePos = filePos; } Con_DPrintf("Parsed %d text messages\n", messageCount); nameHeapSize = lastNamePos; textHeapSize = 0; for (i = 0; i < messageCount; i++) textHeapSize += Q_strlen(textMessages[i].pMessage) + 1; messageSize = (messageCount * sizeof(client_textmessage_t)); gMessageTable = (client_textmessage_t *)Mem_Malloc(textHeapSize + nameHeapSize + messageSize); Q_memcpy(gMessageTable, textMessages, messageSize); pNameHeap = ((char *)gMessageTable) + messageSize; Q_memcpy(pNameHeap, nameHeap, nameHeapSize); nameOffset = pNameHeap - gMessageTable[0].pName; pCurrentText = pNameHeap + nameHeapSize; for (i = 0; i < messageCount; i++) { gMessageTable[i].pName += nameOffset; Q_strcpy(pCurrentText, gMessageTable[i].pMessage); gMessageTable[i].pMessage = pCurrentText; pCurrentText += Q_strlen(pCurrentText) + 1; } gMessageTableCount = messageCount; }
static int AddPatternFromFile(char* fileName, int mark) { int cflags; int eflags; char pattern[MAX_PATTERN_LEN] = {0}; char line[MAX_LINE_LEN] = {0}; char proto[MAX_PROTO_LEN] = {0}; char* preprocessed = NULL; int rc = 0; char* pos = pattern; int protoLen = 0; int patternLen = 0; enum{protocol, kpattern/*, userspace*/} state = protocol; FILE* theFile = fopen(fileName, "r"); if (theFile == NULL) { fprintf(stderr, "Could't read the file: %s\n", fileName); return 0; } cflags = REG_EXTENDED | REG_ICASE | REG_NOSUB; eflags = 0; while (fgets(line, MAX_LINE_LEN, theFile)) { if (IsComment(line)) { continue; } if (state == protocol) { memcpy(proto, line, strlen(line) -1); state = kpattern; continue; } if (state == kpattern) { memcpy(pattern, line, strlen(line) - 1); continue; } } protoLen = strlen(proto); patternLen = strlen(pattern); struct Pattern* newPattern = (struct Pattern*)malloc(sizeof(struct Pattern)); newPattern->cflags = cflags; newPattern->eflags = eflags; newPattern->mark = mark; newPattern->name = (char*)malloc(protoLen + 1); memset(newPattern->name, 0, protoLen + 1); strcpy(newPattern->name, proto); newPattern->pattern_string = (char*)malloc(patternLen + 1); memset(newPattern->pattern_string, 0, patternLen + 1); strcpy(newPattern->pattern_string, pattern); preprocessed = PreprocessRegex(newPattern->pattern_string); rc = regcomp(&newPattern->preg, preprocessed, newPattern->cflags); if (rc != 0) { fprintf(stderr, "error compiling %s -- %s", newPattern->name, newPattern->pattern_string); exit(1); } AddPattern(newPattern); return 1; }
bool TFunctionScanner::ReadFunctionBody(const TChar*& text) { bool result = false; SkipWhiteSpace(text); if (*text == ':') { // special case constructors NextChar(text); SkipWhiteSpace(text); while (*text != '{') { if (IsString(text)) SkipString(text); else if (IsComment(text)) SkipComment(text); else NextChar(text); } } else { // skip "const", "throws", etc. // also handle K&R style function definitions while (isalnum(*text) || *text == '_') { while (isalnum(*text) || *text == '_') NextChar(text); SkipWhiteSpace(text); // for K&R support (pointer, function and array type arguments) while (*text == '*' || *text == ';' || *text == ',' || *text == '[' || *text == ']' || *text == '(' || *text == ')') { NextChar(text); SkipWhiteSpace(text); } } } if (*text == '{') { NextChar(text); int bracketDepth = 1; while (bracketDepth > 0) { // need to do this to process comments correctly SkipWhiteSpace(text); TChar ch = *text; if (IsString(text)) { SkipString(text); continue; // don't call NextChar() since SkipString() already did } else if (ch == '{') ++bracketDepth; else if (ch == '}') --bracketDepth; NextChar(text); } result = true; } else if (*text != ';') NextChar(text); fScanState = kTopLevel; return result; }
string_view Node::GetText() const { if(IsComment() || IsText() || IsWhitespace() || IsComment()) return string_view { impl->data->v.text.text }; throw NotATextualElementException(); }
void cbStyledTextCtrl::HighlightRightBrace() { if (m_bracePosition == wxSCI_INVALID_POSITION) return; int pos = GetCurrentPos(); if (pos == wxSCI_INVALID_POSITION) return; const static wxColour caretForeground = GetCaretForeground(); const static int caretWidth = GetCaretWidth(); const int curLine = GetCurrentLine(); const int len = GetLength(); if (m_tabSmartJump && (curLine == LineFromPosition(m_bracePosition))) { SetIndicatorCurrent(s_indicHighlight); const int indPos = GetLineIndentPosition(curLine); IndicatorClearRange(indPos, GetLineEndPosition(curLine)-indPos); do { if (pos >= len) break; wxString cur((wxChar)GetCharAt(pos)); if (cur == _T("\n")) break; int style = GetStyleAt(pos); if (IsComment(style)) continue; if (IsString(style) || IsCharacter(style)) { const int nextOne = (pos == len) ? GetStyleAt(pos) : GetStyleAt(pos + 1); if (IsCharacter(nextOne) || IsString(nextOne)) continue; } if (s_rightBrace.Contains(cur)) { SetCaretForeground(wxColour(255, 0, 0)); SetCaretWidth(caretWidth + 1); IndicatorSetForeground(s_indicHighlight, wxColour(80, 236, 120)); IndicatorSetStyle(s_indicHighlight, wxSCI_INDIC_HIGHLIGHT); #ifndef wxHAVE_RAW_BITMAP IndicatorSetUnder(s_indicHighlight, true); #endif SetIndicatorCurrent(s_indicHighlight); IndicatorFillRange(pos, 1); m_bracePosition = pos + 1; return; } } while (++pos); } m_bracePosition = wxSCI_INVALID_POSITION; m_lastPosition = wxSCI_INVALID_POSITION; m_tabSmartJump = false; SetIndicatorCurrent(s_indicHighlight); IndicatorClearRange(0, len); SetCaretForeground(caretForeground); SetCaretWidth(caretWidth); }
void TextMessageParse( byte *pMemFile, int fileSize ) { char buf[512], trim[512]; char *pCurrentText=0, *pNameHeap; char currentName[512], nameHeap[ NAME_HEAP_SIZE ]; int lastNamePos; int mode = MSGFILE_NAME; // Searching for a message name int lineNumber, filePos, lastLinePos; int messageCount; client_textmessage_t textMessages[ MAX_MESSAGES ]; int i, nameHeapSize, textHeapSize, messageSize, nameOffset; lastNamePos = 0; lineNumber = 0; filePos = 0; lastLinePos = 0; messageCount = 0; CharacterSetBuild( &g_WhiteSpace, " \r\n\t" ); while( memfgets( pMemFile, fileSize, &filePos, buf, 512 ) != NULL ) { if(messageCount>=MAX_MESSAGES) { Sys_Error("tmessage::TextMessageParse : messageCount>=MAX_MESSAGES"); } TrimSpace( buf, trim ); switch( mode ) { case MSGFILE_NAME: if ( IsComment( trim ) ) // Skip comment lines break; if ( ParseDirective( trim ) ) // Is this a directive "$command"?, if so parse it and break break; if ( IsStartOfText( trim ) ) { mode = MSGFILE_TEXT; pCurrentText = (char*)(pMemFile + filePos); break; } if ( IsEndOfText( trim ) ) { Con_DPrintf("Unexpected '}' found, line %d\n", lineNumber ); return; } strcpy( currentName, trim ); break; case MSGFILE_TEXT: if ( IsEndOfText( trim ) ) { int length = strlen(currentName); // Save name on name heap if ( lastNamePos + length > 8192 ) { Con_DPrintf("Error parsing file!\n" ); return; } strcpy( nameHeap + lastNamePos, currentName ); // Terminate text in-place in the memory file (it's temporary memory that will be deleted) pMemFile[ lastLinePos - 1 ] = 0; // Save name/text on heap textMessages[ messageCount ] = gMessageParms; textMessages[ messageCount ].pName = nameHeap + lastNamePos; lastNamePos += strlen(currentName) + 1; textMessages[ messageCount ].pMessage = pCurrentText; messageCount++; // Reset parser to search for names mode = MSGFILE_NAME; break; } if ( IsStartOfText( trim ) ) { Con_DPrintf("Unexpected '{' found, line %d\n", lineNumber ); return; } break; } lineNumber++; lastLinePos = filePos; if ( messageCount >= MAX_MESSAGES ) { Con_Printf("WARNING: TOO MANY MESSAGES IN TITLES.TXT, MAX IS %d\n", MAX_MESSAGES ); break; } } Con_DPrintf("Parsed %d text messages\n", messageCount ); nameHeapSize = lastNamePos; textHeapSize = 0; for ( i = 0; i < messageCount; i++ ) textHeapSize += strlen( textMessages[i].pMessage ) + 1; messageSize = (messageCount * sizeof(client_textmessage_t)); // Must malloc because we need to be able to clear it after initialization gMessageTable = (client_textmessage_t *)malloc( textHeapSize + nameHeapSize + messageSize ); // Copy table over memcpy( gMessageTable, textMessages, messageSize ); // Copy Name heap pNameHeap = ((char *)gMessageTable) + messageSize; memcpy( pNameHeap, nameHeap, nameHeapSize ); nameOffset = pNameHeap - gMessageTable[0].pName; // Copy text & fixup pointers pCurrentText = pNameHeap + nameHeapSize; for ( i = 0; i < messageCount; i++ ) { gMessageTable[i].pName += nameOffset; // Adjust name pointer (parallel buffer) strcpy( pCurrentText, gMessageTable[i].pMessage ); // Copy text over gMessageTable[i].pMessage = pCurrentText; pCurrentText += strlen( pCurrentText ) + 1; } #if _DEBUG if ( (pCurrentText - (char *)gMessageTable) != (textHeapSize + nameHeapSize + messageSize) ) Con_Printf("Overflow text message buffer!!!!!\n"); #endif gMessageTableCount = messageCount; }