📄 txtwindw.cpp
字号:
}/////////////////////////////////////////////////////////////////////////////// Method:// TextWindowBase::string_to_double(_CHAR* pBuf, BOOL& didErrorOccur,// ULONG32& ulIntegerPart, ULONG32& ulDecimalPart)//// Purpose:// Converts a _CHAR* buffer into a double value. //// Returns:// returns the LONG32 value as converted from buf. // The referenced value, didErrorOccur, is set to FALSE, and the returned// value is set to 0L, if an error occurred.//double TextWindowBase::string_to_double(_CHAR* pBuf, BOOL& didErrorOccur, ULONG32& ulIntegerPart, ULONG32& ulDecimalPart){ didErrorOccur = FALSE; if(pBuf) { ULONG32 bufLen = strlen(pBuf); if(!bufLen) { didErrorOccur = TRUE; return 0.0; } ulIntegerPart = 0L; ulDecimalPart = 0L; double fRetval = 0.0; BOOL bStartQuoteWasFound = FALSE; BOOL bEndQuoteWasFound = FALSE; //This function is in parsing.cpp|h: if(lookForStartAndEndQuotesOfString(pBuf, bufLen, bStartQuoteWasFound, bEndQuoteWasFound)) { if(bEndQuoteWasFound) { pBuf[bufLen-1] = '\0'; bufLen--; } if(bStartQuoteWasFound) { pBuf++; bufLen--; } HX_ASSERT(strlen(pBuf) == bufLen); if(!bufLen) { didErrorOccur = TRUE; return 0.0; } } _CHAR* pBufHigh = pBuf; _CHAR* pBufLow = NULL; _CHAR* pBufDot = NULL; //look for decimal point (don't use strchr() because _CHAR // may not be same size as char*: _CHAR* pBufTmp = pBuf; for (ULONG32 ulcnt=0L; ulcnt<bufLen; ulcnt++, pBufTmp++) { if('.' == *pBufTmp) { *pBufTmp = '\0'; pBufLow = pBufTmp+1; pBufDot = pBufTmp; break; } }#if defined(_CHARsizeInBytesIs1) if(pBufHigh && *pBufHigh) { ulIntegerPart = (ULONG32)atol(pBufHigh); } if(pBufLow && *pBufLow) { ulDecimalPart = (ULONG32)atol(pBufLow); }#else if(pBufHigh && *pBufHigh) { ulIntegerPart = (ULONG32)_wtol(pBufHigh); } if(pBufLow && *pBufLow) { ulDecimalPart = (ULONG32)_wtol(pBufLow); }#endif if(bEndQuoteWasFound) { //restore the ending char: bufLen++; pBuf[bufLen-1] = '\"'; } if(pBufDot) { //restore the decimal point: *pBufDot = '.'; } fRetval = double(ulIntegerPart); if(ulDecimalPart && strlen(pBufLow)) { fRetval += double(ulDecimalPart) / double(strlen(pBufLow)); } return (fRetval); } didErrorOccur = TRUE; return 0L;}/////////////////////////////////////////////////////////////////////////////// Method:// TextWindowBase::string_to_BOOL(// _CHAR* pBuf, ULONG32 bufLen, BOOL& didErrorOccur)//// Purpose:// Converts a _CHAR* buffer into a BOOL value. //// Returns:// returns the BOOL value as converted from buf. // The referenced value, didErrorOccur, is set to FALSE, and the returned// value is set to FALSE, if an error occurred//BOOL TextWindowBase::string_to_BOOL( _CHAR* pBuf, ULONG32 bufLen, BOOL& didErrorOccur){ didErrorOccur = FALSE; if(pBuf) { BOOL bRetVal = FALSE; BOOL bStartQuoteWasFound = FALSE; BOOL bEndQuoteWasFound = FALSE; //This function is in parsing.cpp|h: if(lookForStartAndEndQuotesOfString(pBuf, bufLen, bStartQuoteWasFound, bEndQuoteWasFound)) { HX_ASSERT(bStartQuoteWasFound || bEndQuoteWasFound); if(bEndQuoteWasFound) { pBuf[bufLen-1] = '\0'; bufLen--; } if(bStartQuoteWasFound) { pBuf++; bufLen--; convertToUpperCase(pBuf, bufLen); } HX_ASSERT(strlen(pBuf) == bufLen); } if(!stringCompare(pBuf, bufLen, "TRUE", 4) || !stringCompare(pBuf, bufLen, "YES", 3) || !stringCompare(pBuf, bufLen, "USE", 3) || !stringCompare(pBuf, bufLen, "1", 1)) { bRetVal = TRUE; } else if(!stringCompare(pBuf, bufLen, "FALSE", 5) || !stringCompare(pBuf, bufLen, "NO", 2) || !stringCompare(pBuf, bufLen, "IGNORE", 6) || !stringCompare(pBuf, bufLen, "0", 1)) { bRetVal = FALSE; } if(bEndQuoteWasFound) { //restore the ending char: bufLen++; pBuf[bufLen-1] = '\"'; } return bRetVal; } didErrorOccur = TRUE; return (!didErrorOccur);}/////////////////////////////////////////////////////////////////////////////// Method:// TextWindowBase::parseHeaderTag(// _CHAR* pHeaderTagBuf, ULONG32 headerTagBufLen// , RTFileFormatMarkupParsingMajorVersion)//// Purpose:// Takes <"WINDOW [someString]"> in pHeaderTagBuf & parses the <WINDOW ..>// tag values out of "[someString]" and places those values in the// TextWindow's associated variables and then creates the window as// specified by these values.//// NOTE: parameter 2 is same as strlen(parameter 1) but parameter 1 is// assumed to have a terminating '\0' char at the end, i.e., there // should be one more char in it than parameter 2 states.//// Returns:// returns FALSE if pColorName contains an invalid hex value://BOOL TextWindowBase::parseHeaderTag( _CHAR* pHeaderTagBuf, ULONG32 headerTagBufLen , ULONG32 ulRTFileFormatMarkupParsingMajorVersion , ULONG32 ulRTFileFormatMarkupParsingMinorVersion){ ULONG32 tokenNameStartIndex=0, tokenNameEndIndex=0; ULONG32 tokenValueStartIndex=0, tokenValueEndIndex=0; ULONG32 indexOfEqualsSign=0, dummyVal=0; _CHAR tempCharName, tempCharVal; if(!pHeaderTagBuf || headerTagBufLen<1) { return FALSE; } //First go until you find "WINDOW" tokenNameStartIndex = 0; tokenNameStartIndex = skipSpacesTabsAndNewlineChars(pHeaderTagBuf, headerTagBufLen, tokenNameStartIndex); if(tokenNameStartIndex==headerTagBufLen) { return FALSE; //no text was found except spaces, tabs, newline chars. } tokenNameEndIndex = findNextSpaceTabOrNewLineChar( pHeaderTagBuf, headerTagBufLen, tokenNameStartIndex, indexOfEqualsSign, //Pre-<WINDOW> tag text is always assumed to be us-ascii: CHARSET__us_ascii); tempCharName = pHeaderTagBuf[tokenNameEndIndex]; pHeaderTagBuf[tokenNameEndIndex] = '\0'; convertToUpperCase(&pHeaderTagBuf[tokenNameStartIndex], tokenNameEndIndex-tokenNameStartIndex); if(stringCompare( &pHeaderTagBuf[tokenNameStartIndex], tokenNameEndIndex-tokenNameStartIndex, "WINDOW", 6)) { return FALSE; } pHeaderTagBuf[tokenNameEndIndex] = tempCharName; //Restore the orig char. tokenNameStartIndex = tokenNameEndIndex;//Start next token at prev end. //Find all <WINDOW ..> tag values, e.g. WIDTH=50, and fill in *this's // appropriate fields, most of which are this->textWinAttrib's // data members: do { tokenNameStartIndex = skipSpacesTabsAndNewlineChars(pHeaderTagBuf, headerTagBufLen, tokenNameStartIndex); if(tokenNameStartIndex==headerTagBufLen) { /* No more text was found except spaces, tabs, newline chars, * so quit: */ break; } tokenNameEndIndex = findNextSpaceTabOrNewLineChar( pHeaderTagBuf, headerTagBufLen, tokenNameStartIndex, indexOfEqualsSign, //In-tag text is always us-ascii: CHARSET__us_ascii);#if defined(SHOW_CODE_CHANGE_MESSAGES)#pragma message("EH- in "__FILE__", if tokenValueStartIndex pts to \", \ then increment it by 1 and search for closing \" and set \ tokenValueEndIndex to that.")#endif if(indexOfEqualsSign < headerTagBufLen) { //An '=' was found before a space,tab, or newline, so break the // token into name and value buffers: if(indexOfEqualsSign+1 == tokenNameEndIndex) { /* Need to skip spaces...etc. to find where value part of * tag starts: */ tokenValueStartIndex = skipSpacesTabsAndNewlineChars( pHeaderTagBuf, headerTagBufLen, indexOfEqualsSign+1); if(tokenValueStartIndex==headerTagBufLen) { /* No more text was found except spaces, tabs, * newline chars, so quit: */ break; } tokenValueEndIndex = findNextSpaceTabOrNewLineChar( pHeaderTagBuf, headerTagBufLen, tokenValueStartIndex, dummyVal, //In-tag text is always us-ascii: CHARSET__us_ascii); } else { tokenValueStartIndex = indexOfEqualsSign+1; tokenValueEndIndex = tokenNameEndIndex; } tokenNameEndIndex = indexOfEqualsSign; if(tokenNameEndIndex == tokenNameStartIndex) { //Entire token starts with '=', so ignore it as invalid token // and move on to find next token: tokenNameStartIndex = tokenNameEndIndex = tokenValueEndIndex; continue; } } else { if(tokenNameEndIndex == headerTagBufLen) { break; //no '=' found so token was invalid & no more exist. } /* Find equals sign and value that follows it; need to skip * spaces...etc. to find where value part of tag starts: */ indexOfEqualsSign = skipSpacesTabsAndNewlineChars(pHeaderTagBuf, headerTagBufLen, tokenNameEndIndex); if(indexOfEqualsSign==headerTagBufLen) { /* No more text was found except spaces, tabs, * newline chars, so quit: */ break; } if(pHeaderTagBuf[indexOfEqualsSign] != '=') { /* '=' not next char found so token is invalid; start next * token here: */ tokenNameStartIndex = tokenNameEndIndex = indexOfEqualsSign; continue; } tokenValueStartIndex = skipSpacesTabsAndNewlineChars( pHeaderTagBuf, headerTagBufLen, indexOfEqualsSign+1); while(tokenValueStartIndex<headerTagBufLen && pHeaderTagBuf[tokenValueStartIndex] == '=') { tokenValueStartIndex = skipSpacesTabsAndNewlineChars( pHeaderTagBuf, headerTagBufLen, tokenValueStartIndex+1); } if(tokenValueStartIndex == headerTagBufLen) { /* No more text was found except '=', spaces, tabs, * newlines, so quit: */ break; } tokenValueEndIndex = findNextSpaceTabOrNewLineChar(pHeaderTagBuf, headerTagBufLen, tokenValueStartIndex, dummyVal, //In-tag text is always us-ascii: CHARSET__us_ascii); } /* Now, create a NULL-terminated, uppercase string out of the * token name: */ tempCharName = pHeaderTagBuf[tokenNameEndIndex]; pHeaderTagBuf[tokenNameEndIndex] = '\0'; convertToUpperCase(&pHeaderTagBuf[tokenNameStartIndex], tokenNameEndIndex-tokenNameStartIndex); /* Next, create a NULL-terminated, uppercase string out of the * token value: */ tempCharVal = pHeaderTagBuf[tokenValueEndIndex]; pHeaderTagBuf[tokenValueEndIndex] = '\0'; convertToUpperCase(&pHeaderTagBuf[tokenValueStartIndex], tokenValueEndIndex-tokenValueStartIndex); ULONG32 tokenValueBufLen = tokenValueEndIndex - tokenValueStartIndex; //Ignore erroneous '/' at end of window tag, e.g.: <window n="v"/> if(tokenValueBufLen >= 4 && '\"' == pHeaderTagBuf[tokenValueEndIndex-2] && '/' == pHeaderTagBuf[tokenValueEndIndex-1] ) { tokenValueBufLen--; pHeaderTagBuf[tokenValueEndIndex-1] = '\0'; } //Added the following to fix bug where value's len, // not name's len, was being used in stringCompares(), below: ULONG32 tokenNameBufLen = tokenNameEndIndex - tokenNameStartIndex; switch(pHeaderTagBuf[tokenNameStartIndex]) { case 'B': if(!stringCompare( &pHeaderTagBuf[tokenNameStartIndex], tokenNameBufLen, "BACKGROUND", 10)) { setBackgroundColor(&pHeaderTagBuf[tokenValueStartIndex], tokenValueBufLen); } else if(!stringCompare( &pHeaderTagBuf[tokenNameStartIndex], tokenNameBufLen, "BGCOLOR", 7)) { setBackgroundColor(&pHeaderTagBuf[tokenValueStartIndex], tokenValueBufLen); } break; case 'C': if(!stringCompare( &pHeaderTagBuf[tokenNameStartIndex], tokenNameBufLen, "CRAWLRATE", 9)) { setCrawlRate(&pHeaderTagBuf[tokenValueStartIndex], tokenValueBufLen); } break; case 'D': if(!stringCompare( &pHeaderTagBuf[tokenNameStartIndex], tokenNameBufLen, "DEBUG", 5)) {#if defined(_DEBUG) setDebugFlags(&pHeaderTagBuf[tokenValueStartIndex], tokenValueBufLen);#endif } else if(!stringCompare( &pHeaderTagBuf[tokenNameStartIndex], tokenNameBufLen, "DURATION", 8)) { UINT32 ulDuration = 0; if(convertTimeStringToULONG32( &pHeaderTagBuf[tokenValueStartIndex], tokenValueBufLen, ulDuration)) { m_ulDuration = ulDuration; } } break; case 'E': if(!stringCompare( &pHeaderTagBuf[tokenNameStartIndex], tokenNameBufLen, "ENDTIME", 7)) { UINT32 ulDuration = 0; if(convertTimeStringToULONG32( &pHeaderTagBuf[tokenValueStartIndex], tokenValueBufLen, ulDuration)) { m_ulDuration = ulDuration; } } else if(!stringCompare( &pHeaderTagBuf[tokenNameStartIndex], tokenNameBufLen, "EXTRASPACES", 11)) { //Only perform this if FF version is new enough, // (assuming renderer will never be older unless // user chooses to ignore auto-update): if(ulRTFileFormatMarkupParsingMajorVersion > 0 || ulRTFileFormatMarkupParsingMinorVersion > 1) { SetExtraSpacesHandling( &pHeaderTagBuf[tokenValueStartIndex], tokenValueBufLen); } } break; case 'H': if(!stringCompare( &pHeaderTagBuf[tokenNameStartIndex],
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -