Initial
This commit is contained in:
66
as68hc11/FMTLINES.CPP
Normal file
66
as68hc11/FMTLINES.CPP
Normal file
@@ -0,0 +1,66 @@
|
||||
#include <as68hc11/fmtlines.hpp>
|
||||
#include <common/stdio.hpp>
|
||||
|
||||
DWORD FormatLines::hexasciiLines(Block<String> &lineStrings,GlobalData<BYTE> &globalData)
|
||||
{
|
||||
Block<String> asciiLines;
|
||||
Block<String> hexLines;
|
||||
String tmpString;
|
||||
DWORD lineCount;
|
||||
|
||||
formatLines(asciiLines,globalData,HexCharsPerLine,ASCIILine);
|
||||
formatLines(hexLines,globalData,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,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