examples/Base/MemMan/Cleanup/HeaderFile/EUHEXDMP.H

00001 // Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
00002 // All rights reserved.
00003 // This component and the accompanying materials are made available
00004 // under the terms of "Eclipse Public License v1.0"
00005 // which accompanies this distribution, and is available
00006 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
00007 //
00008 // Initial Contributors:
00009 // Nokia Corporation - initial contribution.
00010 //
00011 // Contributors:
00012 //
00013 // Description:
00014 //
00015 
00016 _LIT(KTxtTwoSpaces,"  ");
00017 _LIT(KTxtThreeSpaces,"   ");
00018 _LIT(KTxtTwoSpaceStar,"   * ");
00019 _LIT(KTxtOneSpaceStar," *");
00020 _LIT(KFormat1,"%S\n");
00021 
00022 inline void hexDump(const TDesC8& aBuffer,TInt32& aAddress,TInt32& aOffset,TDes& aOutput)
00023         {
00024         TBuf<35> hexView;
00025         TBuf<16> charView;
00026         TBuf<8> hexAddress;
00027         TBuf<2> hexChar;
00028 
00029         // calculate number of leading spaces due to 16-bit boundaries
00030         TInt numLeadingSpaces = aAddress % 16;
00031 
00032         for (TInt count=0; count<16; count++)
00033                 {
00034                         // print space between quartets of hex values
00035                         if (count==4 || count==8 || count==12) hexView.Append(' ');
00036 
00037                         // display the character/hex-val or a space depending on 16-bit boundary
00038                         if (count < (numLeadingSpaces)) 
00039                                 {
00040                                 hexView.AppendFormat(KTxtTwoSpaces);
00041                                 charView.Append(' ');
00042                                 }
00043                         else
00044                                 {
00045                                 TInt curChar = (count - numLeadingSpaces) + aOffset;
00046                                                 // calculate which element of the descriptor to display
00047                                 if (curChar < aBuffer.Size())           // check to see if end of buffer has been exceeded
00048                                         {
00049                                         // Ensure hex-format of number is 2 chars long
00050                                         hexChar.Zero();
00051                                         hexChar.AppendNumUC(aBuffer[curChar],EHex);
00052                                         if (hexChar.Length() < 2) hexView.Append('0');
00053                                         hexView.Append(hexChar);
00054 
00055                                         if (aBuffer[curChar] > 31 && aBuffer[curChar] != 127) charView.Append(aBuffer[curChar]);
00056                                         else charView.Append('.');
00057                                         }
00058                                 else
00059                                         {
00060                                         hexView.AppendFormat(KTxtTwoSpaces);
00061                                         charView.Append(' ');
00062                                         }
00063                                 }
00064                 }
00065 
00066         // Set the length of aOutput to zero (ie. reset the output buffer)
00067         aOutput.Zero();
00068 
00069         // calculate the 16-bit block address to display
00070         TInt32 prtAddress = aAddress - numLeadingSpaces;
00071         hexAddress.AppendNumUC(prtAddress,EHex);
00072         for (TInt preZeroCount=0; preZeroCount < (8-hexAddress.Length()); preZeroCount++)
00073                 aOutput.Append('0');
00074         aOutput.Append(hexAddress);
00075         aOutput.AppendFormat(KTxtThreeSpaces);
00076         
00077         // display hex-values and characters
00078         aOutput.Append(hexView);
00079         aOutput.AppendFormat(KTxtTwoSpaceStar);
00080         aOutput.Append(charView);
00081         aOutput.AppendFormat(KTxtOneSpaceStar);
00082 
00083         // update the address and offset for the descriptor
00084         aAddress += 16 - numLeadingSpaces;
00085         aOffset += 16 - numLeadingSpaces;
00086         }
00087         
00088 void printBuffer(TInt32 aAddress,const TDesC8& aBuffer)
00089         {
00090         TInt32 offset = 0;
00091         TBuf<80> outputLine;
00092         while (offset < aBuffer.Size())
00093                 {
00094                 hexDump(aBuffer,aAddress,offset,outputLine);
00095                 console->Printf(KFormat1, &outputLine);
00096                 }
00097         }

Generated by  doxygen 1.6.2