Initial
This commit is contained in:
120
commctrl/fmtlines.cpp
Normal file
120
commctrl/fmtlines.cpp
Normal file
@@ -0,0 +1,120 @@
|
||||
#include <stdio.h>
|
||||
#include <commctrl/fmtlines.hpp>
|
||||
|
||||
DWORD FormatLines::hexasciiLines(Block<String> &lineStrings,GlobalData<BYTE> &globalData)
|
||||
{
|
||||
return hexasciiLines(lineStrings,&globalData[0],globalData.size());
|
||||
}
|
||||
|
||||
DWORD FormatLines::hexasciiLines(Block<String> &lineStrings,BYTE *pBuffer,DWORD byteCount)
|
||||
{
|
||||
Block<String> asciiLines;
|
||||
Block<String> hexLines;
|
||||
String tmpString;
|
||||
DWORD lineCount;
|
||||
|
||||
formatLines(asciiLines,pBuffer,byteCount,HexCharsPerLine,ASCIILine);
|
||||
formatLines(hexLines,pBuffer,byteCount,HexCharsPerLine,HexLine);
|
||||
lineCount=asciiLines.size();
|
||||
for(DWORD itemIndex=0;itemIndex<lineCount;itemIndex++)
|
||||
{
|
||||
tmpString=hexLines[itemIndex]+asciiLines[itemIndex];
|
||||
lineStrings.insert(&tmpString);
|
||||
}
|
||||
return lineCount;
|
||||
}
|
||||
|
||||
|
||||
DWORD FormatLines::formatLines(Block<String> &lineStrings,BYTE *pBuffer,DWORD byteCount,WORD charsPerLine,LineType lineType)
|
||||
{
|
||||
WORD charCount;
|
||||
String charString;
|
||||
String charLine;
|
||||
BYTE charByte;
|
||||
BYTE prevByte;
|
||||
|
||||
if(!byteCount||!pBuffer)return byteCount;
|
||||
charCount=0;
|
||||
for(DWORD itemIndex=0;itemIndex<byteCount;itemIndex++)
|
||||
{
|
||||
charByte=pBuffer[itemIndex];
|
||||
if(itemIndex&&(!(itemIndex%charsPerLine)))
|
||||
{
|
||||
if(HexLine==lineType)charLine.upper();
|
||||
lineStrings.insert(&charLine);
|
||||
*((char*)charLine)=0;
|
||||
charCount=0;
|
||||
}
|
||||
if(HexLine==lineType)::sprintf(charString,"%02x",charByte);
|
||||
else
|
||||
{
|
||||
if(isprint(charByte))::sprintf(charString,"%c",charByte);
|
||||
else charString=".";
|
||||
}
|
||||
charCount++;
|
||||
charLine+=charString;
|
||||
if(HexLine==lineType)charLine+=" ";
|
||||
}
|
||||
while(charCount<charsPerLine)
|
||||
{
|
||||
if(HexLine==lineType)charLine+="?? ";
|
||||
else charLine+="?";
|
||||
charCount++;
|
||||
}
|
||||
if(charLine.length())
|
||||
{
|
||||
if(HexLine==lineType)charLine.upper();
|
||||
lineStrings.insert(&charLine);
|
||||
}
|
||||
return lineStrings.size();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/*DWORD FormatLines::formatLines(Block<String> &lineStrings,GlobalData<BYTE> &globalData,WORD charsPerLine,LineType lineType)
|
||||
{
|
||||
DWORD byteCount(globalData.size());
|
||||
WORD charCount;
|
||||
String charString;
|
||||
String charLine;
|
||||
BYTE charByte;
|
||||
BYTE prevByte;
|
||||
|
||||
if(!byteCount)return byteCount;
|
||||
charCount=0;
|
||||
for(DWORD itemIndex=0;itemIndex<byteCount;itemIndex++)
|
||||
{
|
||||
charByte=globalData[itemIndex];
|
||||
if(itemIndex&&(!(itemIndex%charsPerLine)))
|
||||
{
|
||||
if(HexLine==lineType)charLine.upper();
|
||||
lineStrings.insert(&charLine);
|
||||
*((char*)charLine)=0;
|
||||
charCount=0;
|
||||
}
|
||||
if(HexLine==lineType)::sprintf(charString,"%02x",charByte);
|
||||
else
|
||||
{
|
||||
if(isprint(charByte))::sprintf(charString,"%c",charByte);
|
||||
else charString=".";
|
||||
}
|
||||
charCount++;
|
||||
charLine+=charString;
|
||||
if(HexLine==lineType)charLine+=" ";
|
||||
}
|
||||
while(charCount<charsPerLine)
|
||||
{
|
||||
if(HexLine==lineType)charLine+="?? ";
|
||||
else charLine+="?";
|
||||
charCount++;
|
||||
}
|
||||
if(charLine.length())
|
||||
{
|
||||
if(HexLine==lineType)charLine.upper();
|
||||
lineStrings.insert(&charLine);
|
||||
}
|
||||
return lineStrings.size();
|
||||
}*/
|
||||
Reference in New Issue
Block a user