Annotation of mstools/mfc/src/dumpcont.cpp, revision 1.1

1.1     ! root        1: // This is a part of the Microsoft Foundation Classes C++ library. 
        !             2: // Copyright (C) 1992 Microsoft Corporation 
        !             3: // All rights reserved. 
        !             4: //  
        !             5: // This source code is only intended as a supplement to the 
        !             6: // Microsoft Foundation Classes Reference and Microsoft 
        !             7: // QuickHelp documentation provided with the library. 
        !             8: // See these sources for detailed information regarding the 
        !             9: // Microsoft Foundation Classes product. 
        !            10: 
        !            11: #ifdef _WINDOWS
        !            12: #include "afxwin.h"
        !            13: #else
        !            14: #include "afx.h"
        !            15: #endif
        !            16: #pragma hdrstop
        !            17: 
        !            18: #include <stdarg.h>
        !            19: 
        !            20: #ifdef AFX_CORE_SEG
        !            21: #pragma code_seg(AFX_CORE_SEG)
        !            22: #endif
        !            23: 
        !            24: #ifdef _DEBUG
        !            25: // string for asserts in collections
        !            26: char BASED_CODE _afxSzAfxColl[] = "afxcoll.h";
        !            27: char BASED_CODE _afxSzAfxWinInl[] = "afxwin.inl";
        !            28: char BASED_CODE _afxSzAfxInl[] = "afx.inl";
        !            29: #endif
        !            30: 
        !            31: #ifdef _DEBUG
        !            32: #undef THIS_FILE
        !            33: static char BASED_CODE THIS_FILE[] = __FILE__;
        !            34: #endif
        !            35: 
        !            36: extern "C" BOOL afxTraceEnabled = 0;
        !            37: 
        !            38: #ifdef _WINDOWS
        !            39: extern "C" int afxTraceFlags = 0;
        !            40: #endif
        !            41: 
        !            42: /////////////////////////////////////////////////////////////////////////////
        !            43: // Diagnostic Stream output
        !            44: 
        !            45: // buffer size for potentially large outputs
        !            46: #define nLocalBuf 512
        !            47: 
        !            48: #ifdef _DEBUG
        !            49: 
        !            50: extern "C" void CDECL 
        !            51: AfxTrace(const char* pszFormat, ...)
        !            52: {
        !            53:        int nBuf;
        !            54:        char szBuffer[nLocalBuf];
        !            55:        va_list args;
        !            56:        va_start(args, pszFormat);
        !            57: 
        !            58:        nBuf = vsprintf(szBuffer, pszFormat, args);
        !            59:        ASSERT(nBuf < nLocalBuf);
        !            60: 
        !            61: #ifdef _WINDOWS
        !            62:        if ((afxTraceFlags & 1) && (AfxGetApp() != NULL))
        !            63:                afxDump << AfxGetAppName() << ": ";
        !            64: #endif
        !            65: 
        !            66:        afxDump << szBuffer;
        !            67: }
        !            68: 
        !            69: #endif // DEBUG
        !            70: 
        !            71: 
        !            72: void 
        !            73: CDumpContext::OutputString(const char FAR* lpsz)
        !            74: {
        !            75:        if (!afxTraceEnabled)
        !            76:                return;
        !            77: #ifdef _WINDOWS
        !            78:        if (m_pFile == NULL)
        !            79:                ::OutputDebugString(lpsz);
        !            80:        else
        !            81: #endif
        !            82:                m_pFile->Write(lpsz, _fstrlen(lpsz));
        !            83: }
        !            84: 
        !            85: CDumpContext::CDumpContext(CFile* pFile)
        !            86: {
        !            87:        if (m_pFile)
        !            88:                ASSERT_VALID(pFile);
        !            89: 
        !            90:        m_pFile = pFile;
        !            91:        m_nDepth = 0;
        !            92: }
        !            93: 
        !            94: void CDumpContext::Flush()
        !            95: {
        !            96:        if (m_pFile)
        !            97:                m_pFile->Flush();
        !            98: }
        !            99: 
        !           100: CDumpContext&
        !           101: CDumpContext::operator<<(const char FAR* lpsz)
        !           102: {
        !           103:        if (lpsz == NULL)
        !           104:                return *this;
        !           105: 
        !           106: #ifdef _WINDOWS
        !           107:        if (m_pFile == NULL)
        !           108:        {
        !           109:                char szBuffer[nLocalBuf];
        !           110:                char FAR* lpBuf = szBuffer;
        !           111: 
        !           112:                while (*lpsz)
        !           113:                {
        !           114:                        if (lpBuf > szBuffer + sizeof(szBuffer) - 3)
        !           115:                        {
        !           116:                                *lpBuf = '\0';
        !           117:                                OutputString(szBuffer);
        !           118:                                lpBuf = szBuffer;
        !           119:                        }
        !           120:                        if (*lpsz == '\n')
        !           121:                                *lpBuf++ = '\r';
        !           122:                        *lpBuf++ = *lpsz++;
        !           123:                }
        !           124:                *lpBuf = '\0';
        !           125:                OutputString(szBuffer);
        !           126:                return *this;
        !           127:        }
        !           128: #endif
        !           129:        m_pFile->Write(lpsz, _fstrlen(lpsz));
        !           130:        return *this;
        !           131: }
        !           132: 
        !           133: CDumpContext&
        !           134: CDumpContext::operator<<(BYTE by)
        !           135: {
        !           136:        char szBuffer[32];
        !           137: 
        !           138:        sprintf(szBuffer, "%d", (int)by);
        !           139:        OutputString(szBuffer);
        !           140: 
        !           141:        return *this;
        !           142: }
        !           143: 
        !           144: CDumpContext&
        !           145: CDumpContext::operator<<(WORD w)
        !           146: {
        !           147:        char szBuffer[32];
        !           148: 
        !           149:        sprintf(szBuffer, "%u", (UINT) w);
        !           150:        OutputString(szBuffer);
        !           151: 
        !           152:        return *this;
        !           153: }
        !           154: 
        !           155: CDumpContext&
        !           156: CDumpContext::operator<<(UINT u)
        !           157: {
        !           158:        char szBuffer[32];
        !           159: 
        !           160:        sprintf(szBuffer, "%u", u);
        !           161:        OutputString(szBuffer);
        !           162: 
        !           163:        return *this;
        !           164: }
        !           165: 
        !           166: CDumpContext&
        !           167: CDumpContext::operator<<(LONG l)
        !           168: {
        !           169:        char szBuffer[32];
        !           170: 
        !           171:        sprintf(szBuffer, "%ld", l);
        !           172:        OutputString(szBuffer);
        !           173: 
        !           174:        return *this;
        !           175: }
        !           176: 
        !           177: CDumpContext&
        !           178: CDumpContext::operator<<(DWORD dw)
        !           179: {
        !           180:        char szBuffer[32];
        !           181: 
        !           182:        sprintf(szBuffer, "%lu", dw);
        !           183:        OutputString(szBuffer);
        !           184: 
        !           185:        return *this;
        !           186: }
        !           187: 
        !           188: CDumpContext&
        !           189: CDumpContext::operator<<(int n)
        !           190: {
        !           191:        char szBuffer[32];
        !           192: 
        !           193:        sprintf(szBuffer, "%d", n);
        !           194:        OutputString(szBuffer);
        !           195: 
        !           196:        return *this;
        !           197: }
        !           198: 
        !           199: CDumpContext&
        !           200: CDumpContext::operator<<(const CObject* pOb)
        !           201: {
        !           202:        if (pOb == NULL)
        !           203:                *this << "NULL";
        !           204:        else
        !           205:        {
        !           206:                ASSERT_VALID(pOb);
        !           207:                pOb->Dump(*this);
        !           208:        }
        !           209:        return *this;
        !           210: }
        !           211: 
        !           212: CDumpContext&
        !           213: CDumpContext::operator<<(const CObject& ob)
        !           214: {
        !           215:        return *this << &ob;
        !           216: }
        !           217: 
        !           218: #ifdef _NEARDATA
        !           219: CDumpContext&
        !           220: CDumpContext::operator<<(const void NEAR* np)
        !           221: {
        !           222:        char szBuffer[32];
        !           223: 
        !           224:        // prefix a pointer with "$" and print in hex
        !           225:        sprintf(szBuffer, "$%X", (WORD)np);
        !           226:        OutputString(szBuffer);
        !           227: 
        !           228:        return *this;
        !           229: }
        !           230: #endif //_NEARDATA
        !           231: 
        !           232: CDumpContext&
        !           233: CDumpContext::operator<<(const void FAR* lp)
        !           234: {
        !           235:        char szBuffer[32];
        !           236: 
        !           237:        // prefix a pointer with "$" and print in hex
        !           238:        sprintf(szBuffer, "$%lX", (LONG)lp);
        !           239:        OutputString(szBuffer);
        !           240: 
        !           241:        return *this;
        !           242: }
        !           243: 
        !           244: /////////////////////////////////////////////////////////////////////////////
        !           245: // Formatted output
        !           246: 
        !           247: void CDumpContext::HexDump(const char* pszLine, BYTE* pby, int nBytes, int nWidth)
        !           248: /*
        !           249:   -- do a simple hex-dump (8 per line) to a CDumpContext
        !           250:   --  the "pszLine" is a string to print at the start of each line
        !           251:          (%lx should be used to expand the current address)
        !           252: */
        !           253: {
        !           254:        ASSERT(nBytes > 0);
        !           255:        ASSERT(nWidth > 0);
        !           256: 
        !           257:        int nRow = 0;
        !           258:        char szBuffer[32];
        !           259: 
        !           260:        while (nBytes--)
        !           261:        {
        !           262:                if (nRow == 0)
        !           263:                {
        !           264:                        sprintf(szBuffer, pszLine, pby);
        !           265:                        *this << szBuffer;
        !           266:                }
        !           267: 
        !           268:                sprintf(szBuffer, " %02X", *pby++);
        !           269:                *this << szBuffer;
        !           270: 
        !           271:                if (++nRow >= nWidth)
        !           272:                {
        !           273:                        *this << "\n";
        !           274:                        nRow = 0;
        !           275:                }
        !           276:        }
        !           277:        if (nRow != 0)
        !           278:                *this << "\n";
        !           279: }
        !           280: 
        !           281: /////////////////////////////////////////////////////////////////////////////

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.