From 6ce0f6c77fd3ad9ea74f8af2a73809584c103fbb Mon Sep 17 00:00:00 2001 From: tomcw Date: Wed, 13 Aug 2014 22:03:33 +0100 Subject: [PATCH] Split some of Debugger_parser.h into Util_Text.h (now Util_MemoryTextFile.cpp isn't dependent on any Debugger headers --- ApplewinExpress9.00.vcproj | 4 + source/Debugger/Debugger_Parser.h | 222 +++--------------------------- source/Util_MemoryTextFile.cpp | 5 +- source/Util_Text.h | 166 ++++++++++++++++++++++ 4 files changed, 195 insertions(+), 202 deletions(-) create mode 100644 source/Util_Text.h diff --git a/ApplewinExpress9.00.vcproj b/ApplewinExpress9.00.vcproj index 7602586d..5a4dd4d8 100644 --- a/ApplewinExpress9.00.vcproj +++ b/ApplewinExpress9.00.vcproj @@ -354,6 +354,10 @@ RelativePath=".\source\Util_MemoryTextFile.h" > + + pStart)) - { - pSrc--; - } - return pSrc; - } - -inline const char* SkipUntilChar ( const char *pSrc, const char nDelim ) - { - while (pSrc && (*pSrc)) - { - if (*pSrc == nDelim) - break; - pSrc++; - } - return pSrc; - } - -inline const char* SkipUntilEOL ( const char *pSrc ) - { - // EOL delims: NULL, LF, CR - while (pSrc && (*pSrc)) - { - if ((*pSrc == CHAR_LF) || (*pSrc == CHAR_CR)) - { - break; - } - pSrc++; - } - return pSrc; - } - -inline const char* SkipUntilTab ( const char *pSrc) - { - while (pSrc && (*pSrc)) - { - if (*pSrc == CHAR_TAB) - { - break; - } - pSrc++; - } - return pSrc; - } - -inline const char* SkipUntilToken ( const char *pSrc, const TokenTable_t *aTokens, const int nTokens, ArgToken_e *pToken_ ) - { - if ( pToken_) - *pToken_ = NO_TOKEN; - - while (pSrc && (*pSrc)) - { - if (ParserFindToken( pSrc, aTokens, nTokens, pToken_ )) - return pSrc; - - pSrc++; - } - return pSrc; - } - -inline const char* SkipUntilWhiteSpace ( const char *pSrc ) - { - while (pSrc && (*pSrc)) - { - if ((*pSrc == CHAR_SPACE) || (*pSrc == CHAR_TAB)) - { - break; - } - pSrc++; - } - return pSrc; - } - -inline const char* SkipUntilWhiteSpaceReverse ( const char *pSrc, const char *pStart ) - { - while (pSrc && (pSrc > pStart)) - { - if ((*pSrc == CHAR_SPACE) || (*pSrc == CHAR_TAB)) - { - break; - } - pSrc--; - } - return pSrc; - } - - -/* - const TCHAR* SkipEOL ( const TCHAR *pSrc ); - const TCHAR* SkipWhiteSpace ( const TCHAR *pSrc ); - const TCHAR* SkipWhiteSpaceReverse ( const TCHAR *pSrc, const TCHAR *pStart ); - const TCHAR* SkipUntilChar ( const TCHAR *pSrc, const TCHAR nDelim ); - const TCHAR* SkipUntilEOL ( const TCHAR *pSrc ); - const TCHAR* SkipUntilToken ( const TCHAR *pSrc, const TokenTable_t *aTokens, const int nTokens, ArgToken_e *pToken_ ); - const TCHAR* SkipUntilWhiteSpace ( const TCHAR *pSrc ); - const TCHAR* SkipUntilWhiteSpaceReverse ( const TCHAR *pSrc, const TCHAR *pStart ); - const TCHAR* SkipUntilTab ( const TCHAR *pSrc); -*/ - - const TCHAR * FindTokenOrAlphaNumeric ( const TCHAR *pSrc, const TokenTable_t *aTokens, const int nTokens, ArgToken_e * pToken_ ); -// TextRemoveWhiteSpaceReverse - int RemoveWhiteSpaceReverse ( char *pSrc ); -// TextExpandTabsToSpaces - void TextConvertTabsToSpaces( TCHAR *pDeTabified_, LPCTSTR pText, const int nDstSize, int nTabStop = 0 ); - - -/** Assumes text are valid hex digits! -//=========================================================================== */ -inline BYTE TextConvert2CharsToByte ( char *pText ) - { - BYTE n = ((pText[0] <= '@') ? (pText[0] - '0') : (pText[0] - 'A' + 10)) << 4; - n += ((pText[1] <= '@') ? (pText[1] - '0') : (pText[1] - 'A' + 10)) << 0; - return n; - } - -//=========================================================================== -inline bool TextIsHexChar( char nChar ) - { - if ((nChar >= '0') && (nChar <= '9')) - return true; - - if ((nChar >= 'A') && (nChar <= 'F')) - return true; - - if ((nChar >= 'a') && (nChar <= 'f')) - return true; - - return false; - } - - -//=========================================================================== -inline bool TextIsHexByte( char *pText ) - { - if (TextIsHexChar( pText[0] ) && - TextIsHexChar( pText[1] )) - return true; - - return false; - } - -//=========================================================================== -inline bool TextIsHexString ( LPCSTR pText ) - { - while (*pText) - { - if (! TextIsHexChar( *pText )) - return false; - - pText++; - } - return true; - } - #endif diff --git a/source/Util_MemoryTextFile.cpp b/source/Util_MemoryTextFile.cpp index 041d1ca3..3b2b4f69 100644 --- a/source/Util_MemoryTextFile.cpp +++ b/source/Util_MemoryTextFile.cpp @@ -22,8 +22,11 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "StdAfx.h" +#include +using namespace std; -#include "Debugger\Debug.h" // Debugger_Parser.h: SkipUntilEOL(), EatEOL(), CHAR_CR, CHAR_LF +#include "Util_Text.h" +#include "Util_MemoryTextFile.h" // MemoryTextFile _________________________________________________________________________________ diff --git a/source/Util_Text.h b/source/Util_Text.h new file mode 100644 index 00000000..dab267d4 --- /dev/null +++ b/source/Util_Text.h @@ -0,0 +1,166 @@ + +#define CHAR_LF '\x0D' +#define CHAR_CR '\x0A' +#define CHAR_SPACE ' ' +#define CHAR_TAB '\t' +#define CHAR_QUOTE_DOUBLE '"' +#define CHAR_QUOTE_SINGLE '\'' +#define CHAR_ESCAPE '\x1B' + +// Text Util +/* +inline const char* SkipEOL ( const char *pSrc ) + { + while (pSrc && ((*pSrc == CHAR_LF) || (*pSrc == CHAR_CR))) + if (pSrc) + { + pSrc++; + } + return pSrc; + } +*/ + +inline const char* EatEOL ( const char *pSrc ) + { + if (pSrc) + { + if (*pSrc == CHAR_LF) + pSrc++; + + if (*pSrc == CHAR_CR) + pSrc++; + } + return pSrc; + } + +inline const char* SkipWhiteSpace ( const char *pSrc ) + { + while (pSrc && ((*pSrc == CHAR_SPACE) || (*pSrc == CHAR_TAB))) + { + pSrc++; + } + return pSrc; + } + +inline const char* SkipWhiteSpaceReverse ( const char *pSrc, const char *pStart ) + { + while (pSrc && ((*pSrc == CHAR_SPACE) || (*pSrc == CHAR_TAB)) && (pSrc > pStart)) + { + pSrc--; + } + return pSrc; + } + +inline const char* SkipUntilChar ( const char *pSrc, const char nDelim ) + { + while (pSrc && (*pSrc)) + { + if (*pSrc == nDelim) + break; + pSrc++; + } + return pSrc; + } + +inline const char* SkipUntilEOL ( const char *pSrc ) + { + // EOL delims: NULL, LF, CR + while (pSrc && (*pSrc)) + { + if ((*pSrc == CHAR_LF) || (*pSrc == CHAR_CR)) + { + break; + } + pSrc++; + } + return pSrc; + } + +inline const char* SkipUntilTab ( const char *pSrc) + { + while (pSrc && (*pSrc)) + { + if (*pSrc == CHAR_TAB) + { + break; + } + pSrc++; + } + return pSrc; + } + +inline const char* SkipUntilWhiteSpace ( const char *pSrc ) + { + while (pSrc && (*pSrc)) + { + if ((*pSrc == CHAR_SPACE) || (*pSrc == CHAR_TAB)) + { + break; + } + pSrc++; + } + return pSrc; + } + +inline const char* SkipUntilWhiteSpaceReverse ( const char *pSrc, const char *pStart ) + { + while (pSrc && (pSrc > pStart)) + { + if ((*pSrc == CHAR_SPACE) || (*pSrc == CHAR_TAB)) + { + break; + } + pSrc--; + } + return pSrc; + } + + + +/** Assumes text are valid hex digits! +//=========================================================================== */ +inline BYTE TextConvert2CharsToByte ( char *pText ) + { + BYTE n = ((pText[0] <= '@') ? (pText[0] - '0') : (pText[0] - 'A' + 10)) << 4; + n += ((pText[1] <= '@') ? (pText[1] - '0') : (pText[1] - 'A' + 10)) << 0; + return n; + } + +//=========================================================================== +inline bool TextIsHexChar( char nChar ) + { + if ((nChar >= '0') && (nChar <= '9')) + return true; + + if ((nChar >= 'A') && (nChar <= 'F')) + return true; + + if ((nChar >= 'a') && (nChar <= 'f')) + return true; + + return false; + } + + +//=========================================================================== +inline bool TextIsHexByte( char *pText ) + { + if (TextIsHexChar( pText[0] ) && + TextIsHexChar( pText[1] )) + return true; + + return false; + } + +//=========================================================================== +inline bool TextIsHexString ( LPCSTR pText ) + { + while (*pText) + { + if (! TextIsHexChar( *pText )) + return false; + + pText++; + } + return true; + }