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

00001 /*
00002 Copyright (c) 1997-2010 Nokia Corporation and/or its subsidiary(-ies). All rights reserved.
00003 
00004 Redistribution and use in source and binary forms, with or without
00005 modification, are permitted provided that the following conditions are met:
00006 
00007 * Redistributions of source code must retain the above copyright notice, this
00008   list of conditions and the following disclaimer.
00009 * Redistributions in binary form must reproduce the above copyright notice,
00010   this list of conditions and the following disclaimer in the documentation
00011   and/or other materials provided with the distribution.
00012 * Neither the name of Nokia Corporation nor the names of its contributors
00013   may be used to endorse or promote products derived from this software
00014   without specific prior written permission.
00015 
00016 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00017 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00018 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00019 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
00020 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00021 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
00022 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00023 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00024 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00025 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00026 
00027 Description:  
00028 */
00029 
00030 
00031 _LIT(KTxtTwoSpaces,"  ");
00032 _LIT(KTxtThreeSpaces,"   ");
00033 _LIT(KTxtTwoSpaceStar,"   * ");
00034 _LIT(KTxtOneSpaceStar," *");
00035 _LIT(KFormat1,"%S\n");
00036 
00037 inline void hexDump(const TDesC8& aBuffer,TInt32& aAddress,TInt32& aOffset,TDes& aOutput)
00038         {
00039         TBuf<35> hexView;
00040         TBuf<16> charView;
00041         TBuf<8> hexAddress;
00042         TBuf<2> hexChar;
00043 
00044         // calculate number of leading spaces due to 16-bit boundaries
00045         TInt numLeadingSpaces = aAddress % 16;
00046 
00047         for (TInt count=0; count<16; count++)
00048                 {
00049                         // print space between quartets of hex values
00050                         if (count==4 || count==8 || count==12) hexView.Append(' ');
00051 
00052                         // display the character/hex-val or a space depending on 16-bit boundary
00053                         if (count < (numLeadingSpaces)) 
00054                                 {
00055                                 hexView.AppendFormat(KTxtTwoSpaces);
00056                                 charView.Append(' ');
00057                                 }
00058                         else
00059                                 {
00060                                 TInt curChar = (count - numLeadingSpaces) + aOffset;
00061                                                 // calculate which element of the descriptor to display
00062                                 if (curChar < aBuffer.Size())           // check to see if end of buffer has been exceeded
00063                                         {
00064                                         // Ensure hex-format of number is 2 chars long
00065                                         hexChar.Zero();
00066                                         hexChar.AppendNumUC(aBuffer[curChar],EHex);
00067                                         if (hexChar.Length() < 2) hexView.Append('0');
00068                                         hexView.Append(hexChar);
00069 
00070                                         if (aBuffer[curChar] > 31 && aBuffer[curChar] != 127) charView.Append(aBuffer[curChar]);
00071                                         else charView.Append('.');
00072                                         }
00073                                 else
00074                                         {
00075                                         hexView.AppendFormat(KTxtTwoSpaces);
00076                                         charView.Append(' ');
00077                                         }
00078                                 }
00079                 }
00080 
00081         // Set the length of aOutput to zero (ie. reset the output buffer)
00082         aOutput.Zero();
00083 
00084         // calculate the 16-bit block address to display
00085         TInt32 prtAddress = aAddress - numLeadingSpaces;
00086         hexAddress.AppendNumUC(prtAddress,EHex);
00087         for (TInt preZeroCount=0; preZeroCount < (8-hexAddress.Length()); preZeroCount++)
00088                 aOutput.Append('0');
00089         aOutput.Append(hexAddress);
00090         aOutput.AppendFormat(KTxtThreeSpaces);
00091         
00092         // display hex-values and characters
00093         aOutput.Append(hexView);
00094         aOutput.AppendFormat(KTxtTwoSpaceStar);
00095         aOutput.Append(charView);
00096         aOutput.AppendFormat(KTxtOneSpaceStar);
00097 
00098         // update the address and offset for the descriptor
00099         aAddress += 16 - numLeadingSpaces;
00100         aOffset += 16 - numLeadingSpaces;
00101         }
00102         
00103 void printBuffer(TInt32 aAddress,const TDesC8& aBuffer)
00104         {
00105         TInt32 offset = 0;
00106         TBuf<80> outputLine;
00107         while (offset < aBuffer.Size())
00108                 {
00109                 hexDump(aBuffer,aAddress,offset,outputLine);
00110                 console->Printf(KFormat1, &outputLine);
00111                 }
00112         }

Generated by  doxygen 1.6.2